This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFA] Debug hooks
- To: gcc-patches at gcc dot gnu dot org
- Subject: [RFA] Debug hooks
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Mon, 9 Jul 2001 22:11:10 +0100
This patch starts adding debug hooks to GCC to produce debug output.
With just this beginning, conditional compilation only goes down a
bit, but everything in the future will be a large win. It should make
it easier to add new debug formats in future, and makes the heavily
conditionally compiled code in e.g. toplev.c much easier to read.
With a bit more work, I hope to get rid of sdbout.h, dwarfout.h,
dwarfout2.h and dbxout.h altogether.
Bootstrapping x86 Linux, now on stage 3 with no new warnings. OK to
commit?
Neil.
* Makefile.in (toplev.o, sdbout.o, dbxout.o, dwarfout.o,
dwarf2out.o): Depend on debug.h, wrap long lines.
* dbxout.c: Include debug.h.
(dbx_debug_hooks): New.
(dbxout_init): Make static, take just 2 args.
(dbxout_finish): Make static.
* dbxout.h (dbxout_init, dbxout_finish): Delete.
* debug.h: New file.
* dwarf2out.c: Include debug.h.
(dwarf2_debug_hooks): New.
(dwarf2out_init): Make static.
(dwarf2out_finish): Make static, take 2 args.
* dwarf2out.h (dwarf2out_init, dwarf2out_finish): Delete.
* dwarfout.c: Include debug.h.
(dwarf_debug_hooks): New.
(dwarfout_init): Make static.
(dwarfout_finish): Make static, take 2 args.
* dwarfout.h (dwarfout_init, dwarfout_finish): Delete.
* sdbout.c: Include debug.h.
(sdb_debug_hooks): New.
(sdbout_init): Make static, take 2 args.
(sdbout_finish): New.
* sdbout.h (sdbout_init): Delete.
* toplev.c: Include debug.h.
(debug_hooks): New.
(compile_file): Set deubg_hooks based on command line options.
Use the hooks rather than conditional compilation.
* doc/tm.texi: Fix markup.
============================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in 2001/07/09 19:42:26 1.693
+++ gcc/Makefile.in 2001/07/09 20:50:56
@@ -1339,7 +1339,7 @@ diagnostic.o : diagnostic.c diagnostic.h
$(GGC_H) input.h $(INSN_ATTR_H) insn-config.h toplev.h intl.h
toplev.o : toplev.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) function.h \
flags.h input.h $(INSN_ATTR_H) xcoffout.h output.h diagnostic.h \
- insn-config.h intl.h $(RECOG_H) Makefile toplev.h dwarfout.h \
+ debug.h insn-config.h intl.h $(RECOG_H) Makefile toplev.h dwarfout.h \
dwarf2out.h sdbout.h dbxout.h $(EXPR_H) hard-reg-set.h $(BASIC_BLOCK_H) \
graph.h $(LOOP_H) except.h $(REGS_H) $(TIMEVAR_H) $(lang_options_files) \
ssa.h $(PARAMS_H) $(TM_P_H) reload.h dwarf2asm.h
@@ -1391,17 +1391,18 @@ explow.o : explow.c $(CONFIG_H) $(SYSTEM
optabs.o : optabs.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) flags.h \
insn-config.h $(EXPR_H) $(RECOG_H) reload.h \
toplev.h $(GGC_H) real.h $(TM_P_H) except.h
-dbxout.o : dbxout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) flags.h $(REGS_H) \
- insn-config.h reload.h gstab.h xcoffout.h output.h dbxout.h toplev.h \
- $(TM_P_H)
-sdbout.o : sdbout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) flags.h except.h \
+dbxout.o : dbxout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) flags.h \
+ $(REGS_H) debug.h $(TM_P_H) \
+ insn-config.h reload.h gstab.h xcoffout.h output.h dbxout.h toplev.h
+sdbout.o : sdbout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) flags.h \
function.h $(EXPR_H) output.h hard-reg-set.h $(REGS_H) real.h \
insn-config.h $(OBSTACK_H) xcoffout.h c-pragma.h ggc.h \
- sdbout.h toplev.h $(TM_P_H)
+ sdbout.h toplev.h $(TM_P_H) except.h debug.h
dwarfout.o : dwarfout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) dwarf.h \
- flags.h insn-config.h reload.h output.h toplev.h dwarfout.h $(TM_P_H)
+ flags.h insn-config.h reload.h output.h toplev.h dwarfout.h $(TM_P_H) \
+ debug.h
dwarf2out.o : dwarf2out.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) dwarf2.h \
- flags.h insn-config.h reload.h output.h diagnostic.h \
+ debug.h flags.h insn-config.h reload.h output.h diagnostic.h \
hard-reg-set.h $(REGS_H) $(EXPR_H) toplev.h dwarf2out.h varray.h \
$(GGC_H) except.h dwarf2asm.h $(TM_P_H)
dwarf2asm.o : dwarf2asm.c $(CONFIG_H) $(SYSTEM_H) flags.h $(RTL_H) $(TREE_H) \
============================================================
Index: gcc/dbxout.c
--- gcc/dbxout.c 2001/06/08 18:12:54 1.87
+++ gcc/dbxout.c 2001/07/09 20:51:00
@@ -82,6 +82,7 @@ Boston, MA 02111-1307, USA. */
#include "toplev.h"
#include "tm_p.h"
#include "ggc.h"
+#include "debug.h"
#ifdef XCOFF_DEBUGGING_INFO
#include "xcoffout.h"
@@ -283,6 +284,8 @@ static int current_sym_nchars;
#define CONTIN do { } while (0)
#endif
+static void dbxout_init PARAMS ((FILE *, const char *));
+static void dbxout_finish PARAMS ((FILE *, const char *));
#if defined(ASM_OUTPUT_SECTION_NAME)
static void dbxout_function_end PARAMS ((void));
#endif
@@ -306,6 +309,13 @@ static void dbxout_finish_symbol PARAMS
static void dbxout_block PARAMS ((tree, int, tree));
static void dbxout_really_begin_function PARAMS ((tree));
+/* The target debug structure. */
+struct gcc_debug_hooks dbx_debug_hooks =
+{
+ dbxout_init,
+ dbxout_finish
+};
+
#if defined(ASM_OUTPUT_SECTION_NAME)
static void
dbxout_function_end ()
@@ -332,13 +342,13 @@ dbxout_function_end ()
/* At the beginning of compilation, start writing the symbol table.
Initialize `typevec' and output the standard data types of C. */
-void
-dbxout_init (asm_file, input_file_name, syms)
+static void
+dbxout_init (asm_file, input_file_name)
FILE *asm_file;
const char *input_file_name;
- tree syms;
{
char ltext_label_name[100];
+ tree syms = getdecls ();
asmfile = asm_file;
@@ -535,7 +545,7 @@ dbxout_source_line (file, filename, line
Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
to do nothing. */
-void
+static void
dbxout_finish (file, filename)
FILE *file ATTRIBUTE_UNUSED;
const char *filename ATTRIBUTE_UNUSED;
============================================================
Index: gcc/dbxout.h
--- gcc/dbxout.h 2000/02/29 23:33:48 1.7
+++ gcc/dbxout.h 2001/07/09 20:51:00
@@ -18,9 +18,6 @@ along with GNU CC; see the file COPYING.
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-extern void dbxout_init PARAMS ((FILE *, const char *, tree));
-extern void dbxout_finish PARAMS ((FILE *, const char *));
-
extern void dbxout_start_new_source_file PARAMS ((const char *));
extern void dbxout_resume_previous_source_file PARAMS ((void));
============================================================
Index: gcc/debug.h
--- /dev/null Tue May 5 13:32:27 1998
+++ gcc/debug.h Mon Jul 9 13:51:00 2001
@@ -0,0 +1,36 @@
+/* Debug hooks for GCC.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef GCC_DEBUG_H
+#define GCC_DEBUG_H
+
+/* This structure contains hooks for the debug information output
+ functions, accessed through the global instance debug_hooks set in
+ toplev.c according to command line options. */
+struct gcc_debug_hooks
+{
+ /* Initialise debug output to FILE. MAIN_FILENAME is the name of
+ the main input file. */
+ void (* init) PARAMS ((FILE * file, const char *main_filename));
+
+ /* Output debug symbols to FILE. */
+ void (* finish) PARAMS ((FILE * file, const char *main_filename));
+};
+
+extern struct gcc_debug_hooks *debug_hooks;
+
+#endif /* !GCC_DEBUG_H */
============================================================
Index: gcc/dwarf2out.c
--- gcc/dwarf2out.c 2001/07/06 11:38:41 1.282
+++ gcc/dwarf2out.c 2001/07/09 20:51:30
@@ -57,6 +57,7 @@ Boston, MA 02111-1307, USA. */
#include "md5.h"
#include "tm_p.h"
#include "diagnostic.h"
+#include "debug.h"
/* DWARF2 Abbreviation Glossary:
CFA = Canonical Frame Address
@@ -231,6 +232,8 @@ static unsigned current_funcdef_fde;
/* Forward declarations for functions defined in this file. */
+static void dwarf2out_init PARAMS ((FILE *, const char *));
+static void dwarf2out_finish PARAMS ((FILE *, const char *));
static char *stripattributes PARAMS ((const char *));
static const char *dwarf_cfi_name PARAMS ((unsigned));
static dw_cfi_ref new_cfi PARAMS ((void));
@@ -360,7 +363,15 @@ expand_builtin_dwarf_fp_regnum ()
#ifndef INCOMING_FRAME_SP_OFFSET
#define INCOMING_FRAME_SP_OFFSET 0
#endif
+
+/* The target debug structure. */
+struct gcc_debug_hooks dwarf2_debug_hooks =
+{
+ dwarf2out_init,
+ dwarf2out_finish
+};
+
/* Return a pointer to a copy of the section string name S with all
attributes stripped off, and an asterisk prepended (for assemble_name). */
@@ -11356,7 +11367,7 @@ dwarf2out_undef (lineno, buffer)
/* Set up for Dwarf output at the start of compilation. */
-void
+static void
dwarf2out_init (asm_out_file, main_input_filename)
register FILE *asm_out_file;
register const char *main_input_filename;
@@ -11446,8 +11457,10 @@ dwarf2out_init (asm_out_file, main_input
/* Output stuff that dwarf requires at the end of every file,
and generate the DWARF-2 debugging info. */
-void
-dwarf2out_finish ()
+static void
+dwarf2out_finish (asm_out_file, input_filename)
+ register FILE *asm_out_file;
+ register const char *input_filename ATTRIBUTE_UNUSED;
{
limbo_die_node *node, *next_node;
dw_die_ref die;
============================================================
Index: gcc/dwarf2out.h
--- gcc/dwarf2out.h 2001/07/04 17:55:18 1.13
+++ gcc/dwarf2out.h 2001/07/09 20:51:30
@@ -18,9 +18,6 @@ along with GNU CC; see the file COPYING.
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-extern void dwarf2out_init PARAMS ((FILE *, const char *));
-extern void dwarf2out_finish PARAMS ((void));
-
extern void dwarf2out_define PARAMS ((unsigned, const char *));
extern void dwarf2out_undef PARAMS ((unsigned, const char *));
extern void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
============================================================
Index: gcc/dwarfout.c
--- gcc/dwarfout.c 2001/05/21 03:14:29 1.86
+++ gcc/dwarfout.c 2001/07/09 20:51:50
@@ -577,6 +577,7 @@ Boston, MA 02111-1307, USA. */
#include "dwarfout.h"
#include "toplev.h"
#include "tm_p.h"
+#include "debug.h"
/* IMPORTANT NOTE: Please see the file README.DWARF for important details
regarding the GNU implementation of Dwarf. */
@@ -786,6 +787,8 @@ static int in_class;
/* Forward declarations for functions defined in this file. */
+static void dwarfout_init PARAMS ((FILE *, const char *));
+static void dwarfout_finish PARAMS ((FILE *, const char *));
static const char *dwarf_tag_name PARAMS ((unsigned));
static const char *dwarf_attr_name PARAMS ((unsigned));
static const char *dwarf_stack_op_name PARAMS ((unsigned));
@@ -1358,6 +1361,13 @@ static void retry_incomplete_types PARAM
#endif
+/* The target debug structure. */
+struct gcc_debug_hooks dwarf_debug_hooks =
+{
+ dwarfout_init,
+ dwarfout_finish
+};
+
/************************ general utility functions **************************/
static inline int
@@ -6166,7 +6176,7 @@ dwarfout_undef (lineno, buffer)
/* Set up for Dwarf output at the start of compilation. */
-void
+static void
dwarfout_init (asm_out_file, main_input_filename)
register FILE *asm_out_file;
register const char *main_input_filename;
@@ -6356,8 +6366,10 @@ dwarfout_init (asm_out_file, main_input_
/* Output stuff that dwarf requires at the end of every file. */
-void
-dwarfout_finish ()
+static void
+dwarfout_finish (asm_out_file, main_input_filename)
+ register FILE *asm_out_file;
+ register const char *main_input_filename ATTRIBUTE_UNUSED;
{
char label[MAX_ARTIFICIAL_LABEL_BYTES];
============================================================
Index: gcc/dwarfout.h
--- gcc/dwarfout.h 2000/11/08 02:18:00 1.7
+++ gcc/dwarfout.h 2001/07/09 20:51:50
@@ -18,9 +18,6 @@ along with GNU CC; see the file COPYING.
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-extern void dwarfout_init PARAMS ((FILE *, const char *));
-extern void dwarfout_finish PARAMS ((void));
-
extern void dwarfout_define PARAMS ((unsigned, const char *));
extern void dwarfout_undef PARAMS ((unsigned, const char *));
extern void dwarfout_file_scope_decl PARAMS ((tree , int));
============================================================
Index: gcc/sdbout.c
--- gcc/sdbout.c 2001/05/01 01:58:32 1.43
+++ gcc/sdbout.c 2001/07/09 20:51:54
@@ -57,6 +57,7 @@ AT&T C compiler. From the example below
#include "ggc.h"
#include "tm_p.h"
#include "gsyms.h"
+#include "debug.h"
/* 1 if PARM is passed to this function in memory. */
@@ -91,6 +92,8 @@ extern tree current_function_decl;
#include "sdbout.h"
+static void sdbout_init PARAMS ((FILE *, const char *));
+static void sdbout_finish PARAMS ((FILE *, const char *));
static char *gen_fake_label PARAMS ((void));
static int plain_type PARAMS ((tree));
static int template_name_p PARAMS ((tree));
@@ -287,7 +290,13 @@ static struct sdb_file *current_file;
#endif /* MIPS_DEBUGGING_INFO */
-
+/* The target debug structure. */
+struct gcc_debug_hooks sdb_debug_hooks =
+{
+ sdbout_init,
+ sdbout_finish
+};
+
#if 0
/* return the tag identifier for type
@@ -1607,11 +1616,10 @@ sdbout_resume_previous_source_file ()
/* Set up for SDB output at the start of compilation. */
-void
-sdbout_init (asm_file, input_file_name, syms)
+static void
+sdbout_init (asm_file, input_file_name)
FILE *asm_file ATTRIBUTE_UNUSED;
const char *input_file_name ATTRIBUTE_UNUSED;
- tree syms ATTRIBUTE_UNUSED;
{
#ifdef MIPS_DEBUGGING_INFO
current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
@@ -1621,7 +1629,7 @@ sdbout_init (asm_file, input_file_name,
#ifdef RMS_QUICK_HACK_1
tree t;
- for (t = syms; t; t = TREE_CHAIN (t))
+ for (t = getdecls (); t; t = TREE_CHAIN (t))
if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
&& !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
sdbout_symbol (t, 0);
@@ -1630,6 +1638,15 @@ sdbout_init (asm_file, input_file_name,
#ifdef SDB_ALLOW_FORWARD_REFERENCES
ggc_add_tree_root (&anonymous_types, 1);
#endif
+}
+
+/* Hook called from toplev.c; do nothing. */
+
+static void
+sdbout_finish (asm_file, input_file_name)
+ FILE *asm_file ATTRIBUTE_UNUSED;
+ const char *main_file_name ATTRIBUTE_UNUSED;
+{
}
#endif /* SDB_DEBUGGING_INFO */
============================================================
Index: gcc/sdbout.h
--- gcc/sdbout.h 2000/06/06 12:08:44 1.6
+++ gcc/sdbout.h 2001/07/09 20:51:54
@@ -18,8 +18,6 @@ along with GNU CC; see the file COPYING.
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-extern void sdbout_init PARAMS ((FILE *, const char *, tree));
-
extern void sdbout_begin_function PARAMS ((int));
extern void sdbout_end_function PARAMS ((int));
============================================================
Index: gcc/toplev.c
--- gcc/toplev.c 2001/07/09 19:42:26 1.479
+++ gcc/toplev.c 2001/07/09 20:52:11
@@ -66,6 +66,7 @@ Boston, MA 02111-1307, USA. */
#include "reload.h"
#include "dwarf2asm.h"
#include "integrate.h"
+#include "debug.h"
#ifdef DWARF_DEBUGGING_INFO
#include "dwarfout.h"
@@ -225,6 +226,15 @@ const char *dump_base_name;
extern int target_flags;
+/* Debug hooks - dependent upon command line options. */
+
+extern struct gcc_debug_hooks dbx_debug_hooks;
+extern struct gcc_debug_hooks sdb_debug_hooks;
+extern struct gcc_debug_hooks dwarf_debug_hooks;
+extern struct gcc_debug_hooks dwarf2_debug_hooks;
+
+struct gcc_debug_hooks *debug_hooks;
+
/* Describes a dump file. */
struct dump_file_info
@@ -2281,6 +2291,24 @@ compile_file (name)
#endif
} /* ! flag_syntax_only */
+ /* Set up the debug hooks based on write_symbols. */
+#if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
+ if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
+ debug_hooks = dbx_debug_hooks;
+#endif
+#ifdef SDB_DEBUGGING_INFO
+ if (write_symbols == SDB_DEBUG)
+ debug_hooks = sdb_debug_hooks;
+#endif
+#ifdef DWARF_DEBUGGING_INFO
+ if (write_symbols == DWARF_DEBUG)
+ debug_hooks = dwarf_debug_hooks;
+#endif
+#ifdef DWARF2_DEBUGGING_INFO
+ if (write_symbols == DWARF2_DEBUG)
+ debug_hooks = dwarf2_debug_hooks;
+#endif
+
#ifndef ASM_OUTPUT_SECTION_NAME
if (flag_function_sections)
{
@@ -2309,26 +2337,12 @@ compile_file (name)
/* If dbx symbol table desired, initialize writing it
and output the predefined types. */
timevar_push (TV_SYMOUT);
-#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
- if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
- dbxout_init (asm_out_file, main_input_filename, getdecls ());
-#endif
-#ifdef SDB_DEBUGGING_INFO
- if (write_symbols == SDB_DEBUG)
- sdbout_init (asm_out_file, main_input_filename, getdecls ());
-#endif
-#ifdef DWARF_DEBUGGING_INFO
- if (write_symbols == DWARF_DEBUG)
- dwarfout_init (asm_out_file, main_input_filename);
-#endif
#ifdef DWARF2_UNWIND_INFO
if (dwarf2out_do_frame ())
dwarf2out_frame_init ();
#endif
-#ifdef DWARF2_DEBUGGING_INFO
- if (write_symbols == DWARF2_DEBUG)
- dwarf2out_init (asm_out_file, main_input_filename);
-#endif
+ if (debug_hooks)
+ (*debug_hooks.init) (asm_out_file, main_input_filename);
timevar_pop (TV_SYMOUT);
/* Initialize yet another pass. */
@@ -2401,25 +2415,13 @@ compile_file (name)
/* Do dbx symbols. */
timevar_push (TV_SYMOUT);
-#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
- if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
- dbxout_finish (asm_out_file, main_input_filename);
-#endif
-
-#ifdef DWARF_DEBUGGING_INFO
- if (write_symbols == DWARF_DEBUG)
- dwarfout_finish ();
-#endif
-
#ifdef DWARF2_UNWIND_INFO
if (dwarf2out_do_frame ())
dwarf2out_frame_finish ();
#endif
-#ifdef DWARF2_DEBUGGING_INFO
- if (write_symbols == DWARF2_DEBUG)
- dwarf2out_finish ();
-#endif
+ if (debug_hooks)
+ (*debug_hooks.finish) (asm_out_file, main_input_filename);
timevar_pop (TV_SYMOUT);
/* Output some stuff at end of file if nec. */
============================================================
Index: gcc/doc/tm.texi
--- gcc/doc/tm.texi 2001/07/09 06:17:25 1.31
+++ gcc/doc/tm.texi 2001/07/09 20:52:41
@@ -5982,8 +5982,7 @@ the character @samp{;} is treated as a l
@end table
@deftypevr {Target Hook} {const char *} TARGET_ASM_OPEN_PAREN
-@end deftypevr
-@deftypevr {Target Hook} {const char *} TARGET_ASM_CLOSE_PAREN
+@deftypevrx {Target Hook} {const char *} TARGET_ASM_CLOSE_PAREN
These target hooks are C string constants, describing the syntax in the
assembler for grouping arithmetic expressions. If not overridden, they
default to normal parentheses, which is correct for most assemblers.