This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH RFA] Disambiguate class scoped types for gdb (stabs only)
- From: Kevin Buettner <kevinb at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: kevinb at redhat dot com
- Date: Tue, 21 May 2002 17:20:29 -0700
- Subject: [PATCH RFA] Disambiguate class scoped types for gdb (stabs only)
GDB's ``ptype'' command is unable to disambiguate class scoped types
from other types of the same name. When using stabs, it turns out
that there was no way for GDB to differentiate these type names
without additional information.
The patch below augments stabs produced by "gcc -gstabs -ggdb" to have
class name qualifiers on class scoped types. The mechanism used is
consistent with the approach documented in
http://sources.redhat.com/gdb/onlinedocs/stabs_7.html#SEC54
Here's an example of some stabs entries (for enums) produced by gcc
without the patch:
.stabs "FFF:t(0,27)=eff_c:0,gg_c:1,hh_c:2,;",128,0,2,0
.stabs "EEE:t(0,28)=exx_c:0,yy_c:1,zz_c:2,;",128,0,12,0
.stabs "EEE:t(0,29)=esub1_c:0,sub2_c:1,sub3_c:2,;",128,0,26,0
And here is what they look like with the patch:
.stabs "FFF:t(0,27)=eff_c:0,gg_c:1,hh_c:2,;",128,0,2,0
.stabs "Foo::EEE:t(0,28)=exx_c:0,yy_c:1,zz_c:2,;",128,0,12,0
.stabs "Foo::Sub::EEE:t(0,29)=esub1_c:0,sub2_c:1,sub3_c:2,;",128,0,26,0
These correspond to the enum declarations in the following code snippet:
enum FFF { ff_c, gg_c, hh_c };
class Foo
{
public:
enum EEE { xx_c, yy_c, zz_c };
EEE e0;
FFF e1;
class Sub
{
public:
int a;
enum EEE { sub1_c, sub2_c, sub3_c };
EEE e0;
} i;
};
I have tested this patch against a recent gcc snapshot and see no
regressions. I don't have write access to the gcc respository, so
whoever approves this change will need to check it in as well.
Finally, I wish to thank Alexandre Oliva and Jim Wilson for reviewing
and suggesting improvements to an earlier version of this patch.
Kevin
* dbxout.c (dbxout_class_name_qualifiers): New function.
(dbxout_symbol): Output class/struct qualifiers for a .stabs entry.
Index: dbxout.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/dbxout.c,v
retrieving revision 1.122
diff -u -p -r1.122 dbxout.c
--- dbxout.c 11 May 2002 10:47:00 -0000 1.122
+++ dbxout.c 21 May 2002 23:49:04 -0000
@@ -308,6 +308,7 @@ static void print_int_cst_octal PARAMS
static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
static void print_wide_int PARAMS ((HOST_WIDE_INT));
static void dbxout_type_name PARAMS ((tree));
+static void dbxout_class_name_qualifiers PARAMS ((tree));
static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
static void dbxout_symbol_name PARAMS ((tree, const char *, int));
static void dbxout_prepare_symbol PARAMS ((tree));
@@ -1827,6 +1828,33 @@ dbxout_type_name (type)
fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
CHARS (IDENTIFIER_LENGTH (t));
}
+
+/* Output leading leading struct or class names needed for qualifying
+ type whose scope is limited to a struct or class. */
+
+static void
+dbxout_class_name_qualifiers (decl)
+ tree decl;
+{
+ tree context = decl_type_context (decl);
+
+ if (context != NULL_TREE
+ && TREE_CODE(context) == RECORD_TYPE
+ && TYPE_NAME (context) != 0
+ && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
+ || (DECL_NAME (TYPE_NAME (context)) != 0)))
+ {
+ tree name = TYPE_NAME (context);
+
+ if (TREE_CODE (name) == TYPE_DECL)
+ {
+ dbxout_class_name_qualifiers (name);
+ name = DECL_NAME (name);
+ }
+ fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
+ CHARS (IDENTIFIER_LENGTH (name) + 2);
+ }
+}
/* Output a .stabs for the symbol defined by DECL,
which must be a ..._DECL node in the normal namespace.
@@ -1968,9 +1996,17 @@ dbxout_symbol (decl, local)
dbxout_finish_symbol (NULL_TREE);
}
+ /* Output .stabs (or whatever) and leading double quote. */
+ fprintf (asmfile, "%s\"", ASM_STABS_OP);
+
+ if (use_gnu_debug_info_extensions)
+ {
+ /* Output leading class/struct qualifiers. */
+ dbxout_class_name_qualifiers (decl);
+ }
+
/* Output typedef name. */
- fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
- IDENTIFIER_POINTER (DECL_NAME (decl)));
+ fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
/* Short cut way to output a tag also. */
if ((TREE_CODE (type) == RECORD_TYPE