[PATCH] Fix locus on C structs with forward declaration
Jakub Jelinek
jakub@redhat.com
Thu Sep 17 14:50:00 GMT 2009
Hi!
Unlike C++, in C DW_TAG_structure_type contains ATM the locus of the first
forward declaration (if any), rather than the real definition. The latter
is usually more useful for debugger purposes.
Fixed thusly. Bootstrapped/regtested on i686-linux and bootstrapped on
x86_64-linux, ok for trunk?
2009-09-17 Jakub Jelinek <jakub@redhat.com>
* c-decl.c (finish_struct): Adjust DECL_SOURCE_LOCATION of
TYPE_STUB_DECL.
* gcc.dg/debug/dwarf2/struct-loc1.c: New test.
--- gcc/c-decl.c.jj 2009-09-16 09:06:29.000000000 +0200
+++ gcc/c-decl.c 2009-09-17 11:53:09.000000000 +0200
@@ -6859,6 +6859,11 @@ finish_struct (location_t loc, tree t, t
}
C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
+ /* Update type location to the one of the definition, instead of e.g.
+ a forward declaration. */
+ if (TYPE_STUB_DECL (t))
+ DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
+
/* Finish debugging output for this type. */
rest_of_type_compilation (t, toplevel);
--- gcc/testsuite/gcc.dg/debug/dwarf2/struct-loc1.c.jj 2009-09-17 12:13:14.000000000 +0200
+++ gcc/testsuite/gcc.dg/debug/dwarf2/struct-loc1.c 2009-09-17 12:17:42.000000000 +0200
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O0 -dA -fno-merge-debug-strings" } */
+
+struct foo;
+struct foo *obj;
+struct foo
+{
+ int x;
+};
+
+int
+main ()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler "DW_TAG_structure_type\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"foo\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0x)?6\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */
Jakub
More information about the Gcc-patches
mailing list