lukmac
lukmac

Reputation: 191

gdb: how does it get the information of the executable?

We can set breakpoint at a func, hence gdb knows the entrance and exit address of a certain function. But how does it get this information? Does it uses DWARF or readelf for the executable, if yes, how? Thanks

Upvotes: 1

Views: 227

Answers (2)

chill
chill

Reputation: 16888

A function is described in DWARF with a DIE (debugging information entry) with tag DW_TAG_subroutine. The DIE has attributes DW_AT_low_pc and DW_AT_high_pc, which give the bounds of the function.

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213596

GDB uses multiple "signals":

  • It reads the symbol table.
  • It may apply heuristics to skip past function prolog (usually you don't want to stop in a function prolog, as call parameters may not have yet been set up, and will look "funny" if printed).
  • If available, it also reads debug info (which could be DWARF, STABS, or something else depending on the platform and the compiler).

Generally GDB will not call into "external" readelf executable -- it contains all the smarts to read the info directly.

If you want to know exactly how this is done, read the source.

Upvotes: 1

Related Questions