This is the mail archive of the gcc@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]
Other format: [Raw text]

When to emit C++ debug info?


Consider this little testcase:

namespace b_std
{
  class b_ostream {
  public:
    int foo;
    virtual void bar();
    b_ostream& operator << (const char *);
  };

  extern b_ostream b_cout;
}

int main()
{
  b_std::b_cout << "Hello world";
}

The question arises, what debug information should be emitted for this?  The
answer turns out to be, we emit (-gdwarf-2) only three DIEs: the compilation
unit, the function main, and the base type "int".  We used (gcc 3.2 or so)
to emit some other DIEs also:

 <1><42>: Abbrev Number: 4 (DW_TAG_structure_type)
     DW_AT_name        : (indirect string, offset: 0x0): b_ostream      
     DW_AT_declaration : 1      
 <1><48>: Abbrev Number: 5 (DW_TAG_variable)
     DW_AT_name        : (indirect string, offset: 0x39): b_cout        
     DW_AT_decl_file   : 1      
     DW_AT_decl_line   : 10     
     DW_AT_MIPS_linkage_name: (indirect string, offset: 0x62): _ZN5b_std6b_coutE
     DW_AT_type        : <42>   
     DW_AT_external    : 1      
     DW_AT_declaration : 1      

i.e. only "declarations" of b_ostream and b_cout.

I have to think, though, that we need to emit _more_ rather than less. 
b_cout is used in this compilation unit, so shouldn't we emit debug
information for it (and thus for its type)?  The debug information is keyed
to the vtable at the moment.

I believe there's a PR about this, in which I think I took the opposite
stance, but practicality has made me reconsider.  If libstdc++, or some
other C++ library, is provided by your vendor without debugging information
we will never emit debug info for the type of a class implemented in that
library, since its vtable is never emitte in code which uses the library.

This means that, even now that GDB can handle trivial uses of namespace
information, real-world examples are pretty much useless.  I was working on
a very old GDB PR saying that we couldn't resolve ostream::operator<< from
the GDB prompt, and when I went to reproduce it I couldn't get GCC to emit
debug information describing ostream at all.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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