find type definition in gdb

Hi all!

This is a question regarding the gdb command 'info types', which can tell where a type is defined in source code.

For example, in gdb if I type 'info types mytype' in the following program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//main.cpp
#include <iostream>

struct mytype
{
  const static bool value = false;
};
   
int
main()
{
    //mytype tip;    //if I remove this comment, it works
    std::cout << mytype::value << std::endl;
    return 0;
}


gdb does not find any matching in the source for type 'mytype'.

But if I remove comment in line 12, gdb finds the type definition and outputs this:

1
2
3
4
All types matching regular expression "mytype":

File main.cpp:
mytype;


It seems to me that in order to gdb to find where a type is defined, you have to declare a variable of that type.

Is it possible to find where a type is defined in gdb without declaring a variable of that type?

Thanks a lot!
try compiling with this flag
man wrote:
-fno-eliminate-unused-debug-types
Normally, when producing DWARF output, GCC avoids producing debug symbol output
for types that are nowhere used in the source file being compiled. Sometimes
it is useful to have GCC emit debugging information for all types declared in a
compilation unit, regardless of whether or not they are actually used in that
compilation unit, for example if, in the debugger, you want to cast a value to
a type that is not actually used in your program (but is declared). More
often, however, this results in a significant amount of wasted space.

Topic archived. No new replies allowed.