public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/12385] New: Full debug info not emitted for C++ classes with external virtual functions
@ 2003-09-24  7:56 sgjohnston at yahoo dot com
  2003-09-25 21:43 ` [Bug debug/12385] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: sgjohnston at yahoo dot com @ 2003-09-24  7:56 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12385

           Summary: Full debug info not emitted for C++ classes with
                    external virtual functions
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sgjohnston at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org,sgjohnston at yahoo dot
                    com
 GCC build triplet: gcc-3.4-20030917
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

If a C++ class has a vtable, and at least one of the virtual functions is not
defined within the comp unit (ie it's external), then the full debug info for
that class is not emitted. Instead, the die for the class is partly emitted,
with the DW_AT_declaration tag. This can cause confusion in gdb, if namespaces
are used, because gdb tried to look externally to the comp unit to find the full
definition. If the same class name appears in more than one namespace, then
infinite recursion can result (this happens with classes in gtkmm).

Example:

class ObjectBase
{
public:
  virtual void test();
  void test2();
  int i;
};

void ObjectBase::test2()
{
  i = 123;
}

int main()
{
  ObjectBase obj1;
  obj1.test();
}

Emits the following for class ObjectBase:

 <1><61>: Abbrev Number: 2 (DW_TAG_structure_type)
     DW_AT_sibling     : <a9>	
     DW_AT_name        : (indirect string, offset: 0x0): ObjectBase	
     DW_AT_declaration : 1	
 <2><6b>: Abbrev Number: 3 (DW_TAG_subprogram)
     DW_AT_sibling     : <99>	
     DW_AT_external    : 1	
     DW_AT_name        : test2	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 10	
     DW_AT_MIPS_linkage_name: _ZN10ObjectBase5test2Ev	
     DW_AT_declaration : 1	
 <3><92>: Abbrev Number: 4 (DW_TAG_formal_parameter)
     DW_AT_type        : <a9>	
     DW_AT_artificial  : 1	
 <2><99>: Abbrev Number: 5 (DW_TAG_subprogram)
     DW_AT_external    : 1	
     DW_AT_name        : (indirect string, offset: 0x0): ObjectBase	
     DW_AT_artificial  : 1	
     DW_AT_declaration : 1	
 <3><a1>: Abbrev Number: 4 (DW_TAG_formal_parameter)
     DW_AT_type        : <a9>	
     DW_AT_artificial  : 1

ObjectBase::test() is not emitted, nor are the artifical operator=() methods,
etc. Also, ObjectBase is noted a declaration. If no virtual functions are
present, then the full class is emitted as expected.

This behaviour happens because a class with a vtable is not written out until
the end of the comp unit, when the vtables are written. When the decision is
made to write out the vtables, is for some reason the vtable is not written,
then the class's debug info is also not written, and just the dies that have
been collected through usage are included in the class. 

This behaviour was more pronounced in gcc 3.2.2, and I thought I had a fix...
but 3.4 is very different in this area, and I can't see a similar fix. The fix I
had for 3.2.2, for what it's worth, was:

*** decl2.c	2003-09-23 23:38:10.000000000 -0700
--- decl2-patch.c	2003-09-23 23:36:58.000000000 -0700
*************** finish_vtable_vardecl (t, data)
*** 2464,2480 ****
        if (flag_syntax_only)
  	TREE_ASM_WRITTEN (vars) = 1;
  
-       /* Since we're writing out the vtable here, also write the debug 
- 	 info.  */
-       note_debug_info_needed (ctype);
- 
        return 1;
      }
  
!   /* If the references to this class' vtables were optimized away, still
!      emit the appropriate debugging information.  See dfs_debug_mark.  */
!   if (DECL_COMDAT (vars)
!       && CLASSTYPE_DEBUG_REQUESTED (ctype))
      note_debug_info_needed (ctype);
  
    return 0;
--- 2464,2478 ----
        if (flag_syntax_only)
  	TREE_ASM_WRITTEN (vars) = 1;
  
        return 1;
      }
  
!   /* If vtable is external, or if the references to this class' vtables
!      were optimized away, still emit the appropriate debugging information.
!      See dfs_debug_mark.  */
!   if (DECL_NEEDED_P (vars) ||
!       (DECL_COMDAT (vars)
!        && CLASSTYPE_DEBUG_REQUESTED (ctype)))
      note_debug_info_needed (ctype);
  
    return 0;
-----------------

Thanks for any help
Stuart


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/12385] Full debug info not emitted for C++ classes with external virtual functions
  2003-09-24  7:56 [Bug debug/12385] New: Full debug info not emitted for C++ classes with external virtual functions sgjohnston at yahoo dot com
@ 2003-09-25 21:43 ` pinskia at gcc dot gnu dot org
  2003-09-26  7:04 ` sgjohnston at yahoo dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-09-25 21:43 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12385



------- Additional Comments From pinskia at gcc dot gnu dot org  2003-09-25 21:30 -------
I want to say this is gdb bug (but I have not looked at the dwarf-2 standard to confirm this).

What version of gdb gets confused?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/12385] Full debug info not emitted for C++ classes with external virtual functions
  2003-09-24  7:56 [Bug debug/12385] New: Full debug info not emitted for C++ classes with external virtual functions sgjohnston at yahoo dot com
  2003-09-25 21:43 ` [Bug debug/12385] " pinskia at gcc dot gnu dot org
@ 2003-09-26  7:04 ` sgjohnston at yahoo dot com
  2003-10-10 14:18 ` drow at gcc dot gnu dot org
  2004-01-10  6:26 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: sgjohnston at yahoo dot com @ 2003-09-26  7:04 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12385



------- Additional Comments From sgjohnston at yahoo dot com  2003-09-26 05:19 -------
This happens with gdb 5.3. I agree that gdb should never end up in an infinite
recursion, that's definately a bug... although that specifically only happens in
an esoteric situation with namespaces. But I still think the dwarf2 output is
incorrect (or maybe less than optimal?) based on two factors:

1. if no virtual functions are present, gcc behaves perfectly and emits the full
class.
2. if virual functions are present, then there are circumstances where parts of
the class would never have debugging info emitted, depending on compilation unit
structure. for example:

file1.cc:

class C {
   virtual void fn1();
   virtual void fn2();
};

C::fn1() {stuff...}

file2.cc:

class C {
   virtual void fn1();
   virtual void fn2();
};

C::fn2() {stuff...}

As far as I can tell, no dies would be emitted for fn1 or fn2 (or any of the
implicit functions like operator=()). Given that the class has been fully
defined between the two files, at the least the two files output should contain
all the dies between them. I actually think it's better (and neccesary for gdb!)
for the entire class die to be written with each file, as it is if no virtual
functions are used.

I looked brieflt at the dwarf2 standard, it says that AT_declaration should be
set if a structure is incomplete. I'm not sure what the definition of incomplete
is here... I'll look more carefully at it shortly.

Thanks
Stuart


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/12385] Full debug info not emitted for C++ classes with external virtual functions
  2003-09-24  7:56 [Bug debug/12385] New: Full debug info not emitted for C++ classes with external virtual functions sgjohnston at yahoo dot com
  2003-09-25 21:43 ` [Bug debug/12385] " pinskia at gcc dot gnu dot org
  2003-09-26  7:04 ` sgjohnston at yahoo dot com
@ 2003-10-10 14:18 ` drow at gcc dot gnu dot org
  2004-01-10  6:26 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: drow at gcc dot gnu dot org @ 2003-10-10 14:18 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12385


drow at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2003-10-10 14:18:00
               date|                            |


------- Additional Comments From drow at gcc dot gnu dot org  2003-10-10 14:17 -------
Right now debug information would be emitted in file1.cc for your last
testcase.  I think it's tied to the vtable; the vtable is emitted with the
class's "key function" which is fn1 in this case.

On the other hand I don't think tying debug output to vtable emission makes
a whole lot of sense.  Consider:
library.h:
class f1
{
  public: virtual int bar();
};

library.cc:
#include "library.h"
int f1::bar() { return 2; }

app.cc:
#include "lib.h"

int main()
{
  f1 bat;
  return 2 + bat.bar();
}

Try it.  Build lib.cc with -shared and app.cc with -g.  No debug info for
the class is emitted even though we ought to be able to see the local variable:
(gdb) ptype bat
type = struct C {
    <incomplete type>
}

This shows up debugging libstdc++ all the time.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/12385] Full debug info not emitted for C++ classes with external virtual functions
  2003-09-24  7:56 [Bug debug/12385] New: Full debug info not emitted for C++ classes with external virtual functions sgjohnston at yahoo dot com
                   ` (2 preceding siblings ...)
  2003-10-10 14:18 ` drow at gcc dot gnu dot org
@ 2004-01-10  6:26 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-10  6:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-10 06:26 -------
Some more discussion about this problem: <http://gcc.gnu.org/ml/gcc/2004-01/
msg00117.html> (and no it looks like you took the same stance as your email).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
   Last reconfirmed|2003-10-10 14:18:00         |2004-01-10 06:26:17
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12385


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/12385] Full debug info not emitted for C++ classes with external virtual functions
       [not found] <bug-12385-4@http.gcc.gnu.org/bugzilla/>
@ 2024-01-23 15:38 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-23 15:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12385

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |13.2.0
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I see now with GCC 13.2 (with GCC 7.5 'test' is missing):

 <1><29>: Abbrev Number: 2 (DW_TAG_class_type)
    <2a>   DW_AT_name        : (indirect string, offset: 0xe4): ObjectBase
    <2e>   DW_AT_declaration : 1
    <2e>   DW_AT_sibling     : <0x85>
 <2><32>: Abbrev Number: 3 (DW_TAG_subprogram)
    <33>   DW_AT_external    : 1
    <33>   DW_AT_name        : (indirect string, offset: 0xa4): test
    <37>   DW_AT_decl_file   : 1
    <38>   DW_AT_decl_line   : 4
    <39>   DW_AT_decl_column : 16
    <3a>   DW_AT_linkage_name: (indirect string, offset: 0x88):
_ZN10ObjectBase4testEv
    <3e>   DW_AT_virtuality  : 1        (virtual)
    <3f>   DW_AT_vtable_elem_location: 2 byte block: 10 0       (DW_OP_constu:
0)
    <42>   DW_AT_containing_type: <0x29>
    <46>   DW_AT_accessibility: 1       (public)
    <47>   DW_AT_declaration : 1
    <47>   DW_AT_object_pointer: <0x4f>
    <4b>   DW_AT_sibling     : <0x55>
 <3><4f>: Abbrev Number: 4 (DW_TAG_formal_parameter)
    <50>   DW_AT_type        : <0x85>
    <54>   DW_AT_artificial  : 1
 <3><54>: Abbrev Number: 0
 <2><55>: Abbrev Number: 5 (DW_TAG_subprogram)
    <56>   DW_AT_external    : 1
    <56>   DW_AT_name        : (indirect string, offset: 0xe4): ObjectBase
    <5a>   DW_AT_linkage_name: (indirect string, offset: 0xae):
_ZN10ObjectBaseC4Ev
    <5e>   DW_AT_artificial  : 1
    <5e>   DW_AT_accessibility: 1       (public)
    <5f>   DW_AT_declaration : 1
    <5f>   DW_AT_object_pointer: <0x67>
    <63>   DW_AT_sibling     : <0x6d>
 <3><67>: Abbrev Number: 4 (DW_TAG_formal_parameter)
    <68>   DW_AT_type        : <0x85>
    <6c>   DW_AT_artificial  : 1
 <3><6c>: Abbrev Number: 0
 <2><6d>: Abbrev Number: 6 (DW_TAG_subprogram)
    <6e>   DW_AT_external    : 1
    <6e>   DW_AT_name        : (indirect string, offset: 0x14): test2
    <72>   DW_AT_decl_file   : 1
    <73>   DW_AT_decl_line   : 9
    <74>   DW_AT_decl_column : 6
    <75>   DW_AT_linkage_name: (indirect string, offset: 0xcc):
_ZN10ObjectBase5test2Ev
    <79>   DW_AT_accessibility: 1       (public)
    <7a>   DW_AT_declaration : 1
    <7a>   DW_AT_object_pointer: <0x7e>
 <3><7e>: Abbrev Number: 4 (DW_TAG_formal_parameter)
    <7f>   DW_AT_type        : <0x85>
    <83>   DW_AT_artificial  : 1
 <3><83>: Abbrev Number: 0
 <2><84>: Abbrev Number: 0

so both functions are there and so is the CTOR.  Thus fixed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-23 15:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-24  7:56 [Bug debug/12385] New: Full debug info not emitted for C++ classes with external virtual functions sgjohnston at yahoo dot com
2003-09-25 21:43 ` [Bug debug/12385] " pinskia at gcc dot gnu dot org
2003-09-26  7:04 ` sgjohnston at yahoo dot com
2003-10-10 14:18 ` drow at gcc dot gnu dot org
2004-01-10  6:26 ` pinskia at gcc dot gnu dot org
     [not found] <bug-12385-4@http.gcc.gnu.org/bugzilla/>
2024-01-23 15:38 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).