This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] .debug_macinfo support


This patch adds support for generating .debug_macinfo.

This particular implementation writes out the entries on the fly. I
also have one that defers outputting all the macro info till we output
everything else (IE till dwarf2out_finish), in case we find some
problem caused by outputting on the fly (the only thing that comes to
mind is whether the file number index will be right when we aren't
using GAS's dwarf2 line info support).

For some reason, the lineno variable isn't correct when we go to do
debug_* (I guess it's because of when we call push_srcloc or
something), which is why i changed it to explicitly get the current
line number again when calling them.

I also fixed what looks like an obvious bug in -g option decoding
while I  was in here (Unless someone disagrees it's either obvious, or
a bug, in which case, it won't be committed as part of this patch if
this patch is approved)

If you said "-g3 -gdwarf-2" or "-g3 -ggdb" or "-g1 -ggdb" (IE set the
level, then changed the debug format), the level would reset back to
2.

This doesn't make much sense, and for the record, I almost always was
putting the -g3 or -g1 switch before -gdwarf-2, and had no clue this
meant it had no effect.

I changed it to only reset the level to 2 if it was 0 (which means you
hadn't specified a level specifically, in which case, we are supposed
to default to 2).

So now -gdwarf-2 -gstabs will use STABS at level 2, -gdwarf-2 will use
DWARF-2 at level 2, -g3 -gdwarf-2 will use DWARF-2 at level 3, and
-gdwarf-2 -g3 will use DWARF-2 at level 3.

Before,
-g3 -gdwarf-2 would use DWARF-2 at level 2.

--Dan



2001-05-23  Daniel Berlin  <dan@cgsoftware.com>

	* c-lex.c (cb_file_change): Pass line number to
	debug_start_source_file. 
	(cb_define): Pass correct line number, and macro name, to
	debug_define. 
	(cb_undefine): Pass correct line number to debug_undef.

	* toplev.c (debug_start_source_file): Add line number to
	parameters. Pass it along to dwarf2out_start_source_file.
	(debug_define): Add macro name to parameters. Pass it along to
	dwarf2out_define. 
	(decode_g_option): Stop resetting debug level back to normal when
	we change debug formats, unless the current level is
	none. (Before, -g3 -gdwarf-2 would use debug level 2, rather than
	3).
	
	* toplev.h (debug_start_source_file): Add line number to
	parameters.
	(debug_define): Add macro name to parameters.
	
	* dwarf2out.h (dwarf2out_define): Add macro name to parameters.
	(dwarf2out_start_source_file): Add line number to parameters.

	* dwarf2out.c (dwarf2out_start_source_file): Add line number to
	parameters.
	Output debug_macinfo data for starting file if requested. 
	(dwarf2out_end_source_file): Output debug_macinfo data for ending
	file if requested.
	(dwarf2out_define): Add macro name to function parameters.
	Output debug_macinfo data for defining a macro if requested.
	(dwarf2out_undef): Output debug_macinfo data for undefining a
	macro if requested.
	(DEBUG_MACINFO_SECTION): New. DWARF2 macro info section name.
	(DEBUG_MACINFO_SECTION_LABEL): New. DWARF2 macro info section label.
	(macinfo_section_label): New. DWARF2 macro info section label.
	(dwarf2out_init): If we want macro info, output the start label
	for the section.
	(dwarf2out_finish): If we want macro info, add a DW_AT_macro_info
	attribute to the compilation unit die pointing to the macro info.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-lex.c,v
retrieving revision 1.140
diff -c -3 -p -w -B -b -r1.140 c-lex.c
*** c-lex.c	2001/05/22 11:02:15	1.140
--- c-lex.c	2001/05/23 19:52:11
*************** cb_file_change (pfile, fc)
*** 253,259 ****
  	  lineno = fc->from.lineno;
  	  push_srcloc (fc->to.filename, 1);
  	  input_file_stack->indent_level = indent_level;
! 	  debug_start_source_file (fc->to.filename);
  #ifndef NO_IMPLICIT_EXTERN_C
  	  if (c_header_level)
  	    ++c_header_level;
--- 253,259 ----
  	  lineno = fc->from.lineno;
  	  push_srcloc (fc->to.filename, 1);
  	  input_file_stack->indent_level = indent_level;
! 	  debug_start_source_file (fc->from.lineno, fc->to.filename);
  #ifndef NO_IMPLICIT_EXTERN_C
  	  if (c_header_level)
  	    ++c_header_level;
*************** cb_define (pfile, node)
*** 338,344 ****
       cpp_reader *pfile;
       cpp_hashnode *node;
  {
!   debug_define (lineno, (const char *) cpp_macro_definition (pfile, node));
  }
  
  /* #undef callback for DWARF and DWARF2 debug info.  */
--- 338,344 ----
       cpp_reader *pfile;
       cpp_hashnode *node;
  {
!   debug_define (cpp_get_line (parse_in)->line,  (const char *)NODE_NAME (node), (const char *) cpp_macro_definition (pfile, node));
  }
  
  /* #undef callback for DWARF and DWARF2 debug info.  */
*************** cb_undef (pfile, node)
*** 347,353 ****
       cpp_reader *pfile ATTRIBUTE_UNUSED;
       cpp_hashnode *node;
  {
!   debug_undef (lineno, (const char *) NODE_NAME (node));
  }
  
  /* Parse a '\uNNNN' or '\UNNNNNNNN' sequence.
--- 347,353 ----
       cpp_reader *pfile ATTRIBUTE_UNUSED;
       cpp_hashnode *node;
  {
!   debug_undef (cpp_get_line (parse_in)->line, (const char *) NODE_NAME (node));
  }
  
  /* Parse a '\uNNNN' or '\UNNNNNNNN' sequence.
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.460
diff -c -3 -p -w -B -b -r1.460 toplev.c
*** toplev.c	2001/05/20 06:26:37	1.460
--- toplev.c	2001/05/23 19:52:16
*************** static int
*** 4227,4233 ****
  decode_g_option (arg)
       const char *arg;
  {
!   unsigned level;
    /* A lot of code assumes write_symbols == NO_DEBUG if the
       debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
       of what debugging type has been selected).  This records the
--- 4267,4273 ----
  decode_g_option (arg)
       const char *arg;
  {
!   static unsigned level=0;
    /* A lot of code assumes write_symbols == NO_DEBUG if the
       debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
       of what debugging type has been selected).  This records the
*************** decode_g_option (arg)
*** 4271,4277 ****
  	  if (*p)
  	    level = read_integral_parameter (p, 0, max_debug_level + 1);
  	  else
! 	    level = 2;
  
  	  if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
  	    {
--- 4311,4317 ----
  	  if (*p)
  	    level = read_integral_parameter (p, 0, max_debug_level + 1);
  	  else
! 	    level = (level == 0) ? 2 : level;
  
  	  if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
  	    {
*************** print_switch_values (file, pos, max, ind
*** 5124,5130 ****
  /* Record the beginning of a new source file, named FILENAME.  */
  
  void
! debug_start_source_file (filename)
       register const char *filename ATTRIBUTE_UNUSED;
  {
  #ifdef DBX_DEBUGGING_INFO
--- 5164,5171 ----
  /* Record the beginning of a new source file, named FILENAME.  */
  
  void
! debug_start_source_file (lineno, filename)
!      register unsigned int lineno ATTRIBUTE_UNUSED;
       register const char *filename ATTRIBUTE_UNUSED;
  {
  #ifdef DBX_DEBUGGING_INFO
*************** debug_start_source_file (filename)
*** 5138,5144 ****
  #endif /* DWARF_DEBUGGING_INFO  */
  #ifdef DWARF2_DEBUGGING_INFO
    if (write_symbols == DWARF2_DEBUG)
!     dwarf2out_start_source_file (filename);
  #endif /* DWARF2_DEBUGGING_INFO  */
  #ifdef SDB_DEBUGGING_INFO
    if (write_symbols == SDB_DEBUG)
--- 5179,5185 ----
  #endif /* DWARF_DEBUGGING_INFO  */
  #ifdef DWARF2_DEBUGGING_INFO
    if (write_symbols == DWARF2_DEBUG)
!     dwarf2out_start_source_file (lineno, filename);
  #endif /* DWARF2_DEBUGGING_INFO  */
  #ifdef SDB_DEBUGGING_INFO
    if (write_symbols == SDB_DEBUG)
*************** debug_end_source_file (lineno)
*** 5177,5185 ****
     initial whitespace, #, whitespace, directive-name, whitespace part.  */
  
  void
! debug_define (lineno, buffer)
!      register unsigned lineno ATTRIBUTE_UNUSED;
!      register const char *buffer ATTRIBUTE_UNUSED;
  {
  #ifdef DWARF_DEBUGGING_INFO
    if (write_symbols == DWARF_DEBUG)
--- 5218,5227 ----
     initial whitespace, #, whitespace, directive-name, whitespace part.  */
  
  void
! debug_define (lineno, macname, buffer)
!      register unsigned lineno;
!      register const char *macname;
!      register const char *buffer;
  {
  #ifdef DWARF_DEBUGGING_INFO
    if (write_symbols == DWARF_DEBUG)
*************** debug_define (lineno, buffer)
*** 5187,5193 ****
  #endif /* DWARF_DEBUGGING_INFO  */
  #ifdef DWARF2_DEBUGGING_INFO
    if (write_symbols == DWARF2_DEBUG)
!     dwarf2out_define (lineno, buffer);
  #endif /* DWARF2_DEBUGGING_INFO  */
  }
  
--- 5229,5235 ----
  #endif /* DWARF_DEBUGGING_INFO  */
  #ifdef DWARF2_DEBUGGING_INFO
    if (write_symbols == DWARF2_DEBUG)
!     dwarf2out_define (lineno, macname, buffer);
  #endif /* DWARF2_DEBUGGING_INFO  */
  }
  
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.h,v
retrieving revision 1.62
diff -c -3 -p -w -B -b -r1.62 toplev.h
*** toplev.h	2001/05/20 06:26:41	1.62
--- toplev.h	2001/05/23 19:52:16
*************** extern int read_integral_parameter	PARAM
*** 37,45 ****
  extern int count_error			PARAMS ((int));
  extern void strip_off_ending		PARAMS ((char *, int));
  extern void print_time			PARAMS ((const char *, long));
! extern void debug_start_source_file	PARAMS ((const char *));
  extern void debug_end_source_file	PARAMS ((unsigned));
! extern void debug_define		PARAMS ((unsigned, const char *));
  extern void debug_undef			PARAMS ((unsigned, const char *));
  extern int debug_ignore_block		PARAMS ((union tree_node *));
  extern const char *trim_filename	PARAMS ((const char *));
--- 37,45 ----
  extern int count_error			PARAMS ((int));
  extern void strip_off_ending		PARAMS ((char *, int));
  extern void print_time			PARAMS ((const char *, long));
! extern void debug_start_source_file	PARAMS ((unsigned, const char *));
  extern void debug_end_source_file	PARAMS ((unsigned));
! extern void debug_define		PARAMS ((unsigned, const char *, const char *));
  extern void debug_undef			PARAMS ((unsigned, const char *));
  extern int debug_ignore_block		PARAMS ((union tree_node *));
  extern const char *trim_filename	PARAMS ((const char *));
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.273
diff -c -3 -p -w -B -b -r1.273 dwarf2out.c
*** dwarf2out.c	2001/05/21 23:30:51	1.273
--- dwarf2out.c	2001/05/23 19:52:24
*************** static int file_info_cmp		PARAMS ((const
*** 3609,3615 ****
  #ifndef DEBUG_LOC_SECTION_LABEL
  #define DEBUG_LOC_SECTION_LABEL		"Ldebug_loc"
  #endif
! 
  /* Definitions of defaults for formats and names of various special
     (artificial) labels which may be generated within this file (when the -g
     options is used and DWARF_DEBUGGING_INFO is in effect.
--- 3610,3618 ----
  #ifndef DEBUG_LOC_SECTION_LABEL
  #define DEBUG_LOC_SECTION_LABEL		"Ldebug_loc"
  #endif
! #ifndef DEBUG_MACINFO_SECTION_LABEL
! #define DEBUG_MACINFO_SECTION_LABEL     "Ldebug_macinfo"
! #endif
  /* Definitions of defaults for formats and names of various special
     (artificial) labels which may be generated within this file (when the -g
     options is used and DWARF_DEBUGGING_INFO is in effect.
*************** static char text_section_label[MAX_ARTIF
*** 3621,3626 ****
--- 3624,3630 ----
  static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
+ static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
  #ifndef TEXT_END_LABEL
  #define TEXT_END_LABEL		"Letext"
*************** dwarf2out_line (filename, line)
*** 11226,11232 ****
     of the .debug_macinfo section.  At present, unimplemented.  */
  
  void
! dwarf2out_start_source_file (filename)
       register const char *filename ATTRIBUTE_UNUSED;
  {
    if (flag_eliminate_dwarf2_dups)
--- 11230,11237 ----
     of the .debug_macinfo section.  At present, unimplemented.  */
  
  void
! dwarf2out_start_source_file (lineno, filename)
!      register unsigned int lineno ATTRIBUTE_UNUSED;
       register const char *filename ATTRIBUTE_UNUSED;
  {
    if (flag_eliminate_dwarf2_dups)
*************** dwarf2out_start_source_file (filename)
*** 11235,11240 ****
--- 11240,11252 ----
        dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
        add_AT_string (bincl_die, DW_AT_name, filename);
      }
+   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
+     {
+       ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
+       dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
+       dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno);
+       dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started");
+     }
  }
  
  /* Record the end of a source file, for later output
*************** dwarf2out_end_source_file ()
*** 11248,11253 ****
--- 11260,11270 ----
        /* Record the end of the file for break_out_includes.  */
        new_die (DW_TAG_GNU_EINCL, comp_unit_die);
      }
+   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
+     {
+       ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
+       dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
+     }
  }
  
  /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
*************** dwarf2out_end_source_file ()
*** 11255,11271 ****
     initial whitespace, #, whitespace, directive-name, whitespace part.  */
  
  void
! dwarf2out_define (lineno, buffer)
       register unsigned lineno ATTRIBUTE_UNUSED;
       register const char *buffer ATTRIBUTE_UNUSED;
  {
    static int initialized = 0;
    if (!initialized)
      {
!       dwarf2out_start_source_file (primary_filename);
        initialized = 1;
      }
  }
  
  /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
     the tail part of the directive line, i.e. the part which is past the
--- 11272,11299 ----
     initial whitespace, #, whitespace, directive-name, whitespace part.  */
  
  void
! dwarf2out_define (lineno, macname, buffer)
       register unsigned lineno ATTRIBUTE_UNUSED;
+      register const char *macname ATTRIBUTE_UNUSED;
       register const char *buffer ATTRIBUTE_UNUSED;
  {
    static int initialized = 0;
+   char *tempstr;
    if (!initialized)
      {
!       dwarf2out_start_source_file (0, primary_filename);
        initialized = 1;
      }
+   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
+     {
+       tempstr = alloca (strlen (macname) + strlen (buffer) + 1);
+       sprintf (tempstr, "%s%s", macname, buffer);
+       ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
+       dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
+       dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
+       dw2_asm_output_nstring (tempstr, -1, "The macro");
      }
+ }
  
  /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
     the tail part of the directive line, i.e. the part which is past the
*************** dwarf2out_undef (lineno, buffer)
*** 11276,11282 ****
--- 11304,11317 ----
       register unsigned lineno ATTRIBUTE_UNUSED;
       register const char *buffer ATTRIBUTE_UNUSED;
  {
+   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
+     {
+       ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
+       dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
+       dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
+       dw2_asm_output_nstring (buffer, -1, "The macro");
      }
+ }
  
  /* Set up for Dwarf output at the start of compilation.  */
  
*************** dwarf2out_init (asm_out_file, main_input
*** 11358,11363 ****
--- 11394,11406 ----
    ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
    ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
    ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
+   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
+     {
+       ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
+       ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
+ 				   DEBUG_MACINFO_SECTION_LABEL, 0);
+       ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
+     }
  }
  
  /* Output stuff that dwarf requires at the end of every file,
*************** dwarf2out_finish ()
*** 11448,11457 ****
    add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
  		     debug_line_section_label);
  
! #if 0 /* unimplemented */
!   if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
!     add_AT_unsigned (die, DW_AT_macro_info, 0);
! #endif
  
    /* Output all of the compilation units.  We put the main one last so that
       the offsets are available to output_pubnames.  */
--- 11491,11498 ----
    add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
  		     debug_line_section_label);
  
!   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
!     add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
    
    /* Output all of the compilation units.  We put the main one last so that
       the offsets are available to output_pubnames.  */
Index: dwarf2out.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.h,v
retrieving revision 1.12
diff -c -3 -p -w -B -b -r1.12 dwarf2out.h
*** dwarf2out.h	2001/03/28 11:03:50	1.12
--- dwarf2out.h	2001/05/23 19:52:24
*************** Boston, MA 02111-1307, USA.  */
*** 21,29 ****
  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 ((const char *));
  extern void dwarf2out_end_source_file 	PARAMS ((void));
  
  extern void dwarf2out_begin_block	PARAMS ((unsigned));
--- 21,29 ----
  extern void dwarf2out_init 		PARAMS ((FILE *, const char *));
  extern void dwarf2out_finish		PARAMS ((void));
  
! extern void dwarf2out_define		PARAMS ((unsigned, const char *, const char *));
  extern void dwarf2out_undef 		PARAMS ((unsigned, const char *));
! extern void dwarf2out_start_source_file	PARAMS ((unsigned, const char *));
  extern void dwarf2out_end_source_file 	PARAMS ((void));
  
  extern void dwarf2out_begin_block	PARAMS ((unsigned));
Index: java/jcf-parse.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/jcf-parse.c,v
retrieving revision 1.85
diff -c -3 -p -w -B -b -r1.85 jcf-parse.c
*** jcf-parse.c	2001/05/21 21:37:36	1.85
--- jcf-parse.c	2001/05/23 19:52:25
*************** parse_class_file ()
*** 771,777 ****
  
    input_filename = DECL_SOURCE_FILE (TYPE_NAME (current_class));
    lineno = 0;
!   debug_start_source_file (input_filename);
    init_outgoing_cpool ();
  
    /* Currently we always have to emit calls to _Jv_InitClass when
--- 771,777 ----
  
    input_filename = DECL_SOURCE_FILE (TYPE_NAME (current_class));
    lineno = 0;
!   debug_start_source_file (lineno, input_filename);
    init_outgoing_cpool ();
  
    /* Currently we always have to emit calls to _Jv_InitClass when



-- 
"I like to go to art museums and name the untitled paintings...
Boy With Pail...  Kitten On Fire.
"-Steven Wright


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]