1

When I type the command maint info symtabs I get following output:

{ objfile /home/jokoi/NOTE/Linux/MEMORY/c_file/testalloc ((struct objfile *) 0x563c7d6a9320)
  { ((struct compunit_symtab *) 0x563c7d703da0)
    debugformat DWARF 2
    producer GNU C17 9.3.0 -mtune=generic -march=x86-64 -g -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection
    dirname /home/jokoi/NOTE/Linux/MEMORY/c_file
    blockvector ((struct blockvector *) 0x563c7d7523d0)
    { symtab testalloc.c ((struct symtab *) 0x563c7d703e20)
      fullname /home/jokoi/NOTE/Linux/MEMORY/c_file/testalloc.c
      linetable ((struct linetable *) 0x563c7d752400)
    }
    { symtab /usr/lib/gcc/x86_64-linux-gnu/9/include/stddef.h ((struct symtab *) 0x563c7d703e50)
      fullname (null)
      linetable ((struct linetable *) 0x0)
    }
    { symtab /usr/include/x86_64-linux-gnu/bits/types.h ((struct symtab *) 0x563c7d703e80)
      fullname (null)
      linetable ((struct linetable *) 0x0)
    }
    { symtab /usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h ((struct symtab *) 0x563c7d703eb0)
      fullname (null)
      linetable ((struct linetable *) 0x0)
    }
......
}

What's the meaning of addresses starting with 0x563c7d7.
When I tried examining it I was told Cannot access memory at address 0x563c7dc94330

Could any body tell me how can I use this address to examine the symtab structure in my GDB?

Employed Russian
  • 199,314
  • 34
  • 295
  • 362

1 Answers1

2

Could any body tell me how can I use this address to examine the symtab structure in my GDB?

The maint set of commands are for GDB maintainers (i.e. people who maintain or debug GDB itself).

The addresses printed are addresses in the GDB process, they don't have anything to do with the inferior process (the one being debugged by GDB).

When I tried examining it I was told Cannot access memory at address 0x563c7dc94330.

The examine command examines the addresses in the inferior process. The address in maint info is the address in the GDB process itself. To examine that address, you would attach GDB to the GDB process. That is, the process hierarchy will be: GDB (A) debugs GDB (B) which debugs your testalloc process (C). In (B) you would issue the maint info command, and then use (A) to examine the contents of symtab in (B).

I recommend keeping (A) and (B) in separate terminals, so it's clearer which copy of the GDB you are interacting with.

Update:

how can I import the "struct symtab", I can only examine this area of memory in hex format.

Usually developers build a version of gdb with debug info (this is default with ./configure && make), and debug that version.

It's possible to "import" the definition of struct symtab without rebuilding the entire GDB, but that would complicate already complicated debugging session, so I don't recommend doing that.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thank you for your detailed answer! It does work in GDB(A) (gdb) x/4xg (0x55efb9beae60) 0x55efb9beae60: 0x000055efb9beae90 0x000055efb9bead80 0x55efb9beae70: 0x0000000000000000 0x000055efb9c027e0 (gdb) p (char *) 0x000055efb9c027e0 $21 = 0x55efb9c027e0 "/usr/include/x86_64-linux-gnu/bits/types.h" One more question, how can I import the "struct symtab", I can only examine this area of memory in hex format. – Citi-Vincent Sep 21 '21 at 05:02
  • @ワタナベハルキ I've updated the answer. – Employed Russian Sep 21 '21 at 05:42