2

When debugging C code with gdb, I often have to find where things are first declared, whether a type (structure) or a variable. According to this answer ( GDB: break if variable equal value ) it might not be possible in gdb. Is this true?

If it's not possible in gdb, are there other strategies? I have often used grep, but this fails if there are too many results.

Community
  • 1
  • 1
Gerhard
  • 1,925
  • 3
  • 15
  • 24

1 Answers1

3

I often have to find where things are first declared, whether a type (structure) or a variable.

Declared or defined (What is the difference between a definition and a declaration?)? If defined then these commands are available:

Examining the Symbol Table (https://sourceware.org/gdb/onlinedocs/gdb/Symbols.html#Symbols) (if compiled with -g):

info types regexp lists all source files where a type is defined.

info variables regexp - prints the names and data types of all variables (except for local variables) whose names contain a match for regular expression regexp.

Community
  • 1
  • 1
  • Thanks for the suggestion. I can see where this would be helpful at times, although of course this doesn't tell me where things are first defined. I suppose it's not possible. – Gerhard Jan 15 '14 at 01:57