This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH -- stabs and macro define/undef


Support for reading and interpreting macro define and undefine lines
recorded in dwarf2 debug info was added to GDB awhile ago.

The following patch adds support for this to gdb when it's in STABS
rather than DWARF2.

(The GCC part of this was posted a week ago to gcc-patches.  And has
so far been met by total and complete silence.  I'll give 'em another
week before I ping 'em.)

The new STABS entries are N_MAC_DEFINE and N_MAC_UNDEF.  The STABS
implementation borrows heavily from the DWARF2 implementation.

ChangeLog entries --

include/aout:

2006-10-13  David Taylor  <dtaylor@emc.com>

	* stab.def: Add __define_stab entries for N_MAC_DEFINE and
	N_MAC_UNDEF.

gdb:

2006-10-13  David Taylor  <dtaylor@emc.com>

	* dwarf2read.c (parse_macro_definition):  Make non static.
	* macrotab.h (parse_macro_definition):  Declare it.
	* dbxread.c (dbxread_macro_start_file): New function.
	(process_one_symbol): Call dbx_macro_start_file and
	parse_macro_definition.

actual patch:

Index: gdb/dbxread.c
===================================================================
RCS file: /cvs/src/src/gdb/dbxread.c,v
retrieving revision 1.81
diff -u -p -r1.81 dbxread.c
--- gdb/dbxread.c	17 Dec 2005 22:33:59 -0000	1.81
+++ gdb/dbxread.c	13 Oct 2006 19:25:57 -0000
@@ -54,6 +54,7 @@
 #include "stabsread.h"
 #include "gdb-stabs.h"
 #include "demangle.h"
+#include "macrotab.h"
 #include "complaints.h"
 #include "cp-abi.h"
 
@@ -2628,6 +2629,27 @@ read_ofile_symtab (struct partial_symtab
 }
 
 
+static struct macro_source_file *
+dbxread_macro_start_file(char *name, int line,
+			 struct macro_source_file *macro_source_file,
+			 struct objfile *objfile)
+{
+/* We don't create a macro table for this compilation unit
+     at all until we actually get a filename.  */
+  if (! pending_macros)
+    pending_macros = new_macro_table (&objfile->objfile_obstack,
+                                      objfile->macro_cache);
+
+  if (! macro_source_file)
+    /* If we have no current file, then this must be the start_file
+       directive for the compilation unit's main source file.  */
+    macro_source_file = macro_set_main (pending_macros, name);
+  else
+    macro_source_file = macro_include (macro_source_file, line, name);
+
+  return (macro_source_file);
+}
+
 /* This handles a single symbol from the symbol-file, building symbols
    into a GDB symtab.  It takes these arguments and an implicit argument.
 
@@ -2675,6 +2697,9 @@ process_one_symbol (int type, int desc, 
      N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers.  */
   static int function_stab_type = 0;
 
+  /* The source file that we are currently processing macros from.  */
+  static struct macro_source_file *macro_source_file;
+
   if (!block_address_function_relative)
     {
       /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
@@ -2891,7 +2916,18 @@ no enclosing block"));
       /* Null name means this just marks the end of text for this .o
          file.  Don't start a new symtab in this case.  */
       if (*name == '\000')
-	break;
+	{
+	  macro_source_file = NULL;
+	  break;
+	}
+      else
+	/* NOTE: we do not need to worry about patching this in the
+	   ``patch things up'' above (the issue of multiple N_SO's) as
+	   GCC is the only compiler that generates macro debug
+	   information in stabs and it does not do multiple
+	   N_SO's.  */
+	macro_source_file = dbxread_macro_start_file (name, desc,
+						      macro_source_file, objfile);
 
       if (block_address_function_relative)
 	function_start_offset = 0;
@@ -2914,10 +2950,13 @@ no enclosing block"));
       push_subfile ();
       add_new_header_file (name, valu);
       start_subfile (name, current_subfile->dirname);
+      macro_source_file = dbxread_macro_start_file (name, desc,
+						    macro_source_file, objfile);
       break;
 
     case N_EINCL:
       start_subfile (pop_subfile (), current_subfile->dirname);
+      macro_source_file = macro_source_file->included_by; 
       break;
 
     case N_EXCL:
@@ -3199,6 +3238,16 @@ no enclosing block"));
     case N_ENDM:		/* Solaris 2: End of module.  */
     case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
       break;
+
+    case N_MAC_DEFINE:
+      /* macro_source_file == ?, line# == desc, body == name */
+      parse_macro_definition (macro_source_file, desc, name);
+      break;
+
+    case N_MAC_UNDEF:
+      /* macro_source_file == ?, line# == desc, body == name */
+      macro_undef (macro_source_file, desc, name);
+      break;
     }
 
   /* '#' is a GNU C extension to allow one symbol to refer to another
Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.204
diff -u -p -r1.204 dwarf2read.c
--- gdb/dwarf2read.c	6 Oct 2006 20:42:02 -0000	1.204
+++ gdb/dwarf2read.c	13 Oct 2006 19:25:58 -0000
@@ -9110,7 +9110,7 @@ consume_improper_spaces (const char *p, 
 }
 
 
-static void
+void
 parse_macro_definition (struct macro_source_file *file, int line,
                         const char *body)
 {
Index: gdb/macrotab.h
===================================================================
RCS file: /cvs/src/src/gdb/macrotab.h,v
retrieving revision 1.5
diff -u -p -r1.5 macrotab.h
--- gdb/macrotab.h	17 Dec 2005 22:34:01 -0000	1.5
+++ gdb/macrotab.h	13 Oct 2006 19:25:58 -0000
@@ -300,5 +300,10 @@ struct macro_source_file *(macro_definit
                             const char *name,
                             int *definition_line));
 
+/* A thin veneer on top of macro_define_object / macro_define_function.
+   Called by dwarf_decode_macros (dwarf2read.c) and process_one_symbol
+   (dbxread.c) */
+void parse_macro_definition (struct macro_source_file *file, int line,
+			     const char *body);
 
 #endif /* MACROTAB_H */
Index: include/aout/stab.def
===================================================================
RCS file: /cvs/src/src/include/aout/stab.def,v
retrieving revision 1.4
diff -u -p -r1.4 stab.def
--- include/aout/stab.def	10 May 2005 10:21:09 -0000	1.4
+++ include/aout/stab.def	13 Oct 2006 19:26:00 -0000
@@ -63,6 +63,9 @@ __define_stab (N_NSYMS, 0x32, "NSYMS")
 /* "No DST map for sym: name, ,0,type,ignored"  according to Ultrix V4.0. */
 __define_stab (N_NOMAP, 0x34, "NOMAP")
 
+/* GNU extension.  Macro define.  */
+__define_stab(N_MAC_DEFINE, 0x36, "MAC_DEFINE")
+
 /* New stab from Solaris 2.  Like N_SO, but for the object file.  Two in
    a row provide the build directory and the relative path of the .o from it.
    Solaris2 uses this to avoid putting the stabs info into the linked
@@ -70,6 +73,9 @@ __define_stab (N_NOMAP, 0x34, "NOMAP")
    reads the real stabs directly from the .o files instead.  */
 __define_stab (N_OBJ, 0x38, "OBJ")
 
+/* GNU extension.  Macro undefine.  */
+__define_stab(N_MAC_UNDEF, 0x3a, "MAC_UNDEF")
+
 /* New stab from Solaris 2.  Options for the debugger, related to the
    source language for this module.  E.g. whether to use ANSI
    integral promotions or traditional integral promotions.  */

p.s. as of the middle of last month, there's now a copyright
assignment on file for EMC (covering GCC, GDB, and BINUTILS).  And it
only took 3 years, 8 months, and 28 days to accomplish.  But, who's
counting?  And aren't lawyers wonderful?

p.p.s. hopefully this will only be the first of several patches over
the coming months as I gradually untangle our changes and submit them
one at a time.

--
David Taylor
dtaylor@emc.com


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