1

In release version, when debugging, sometimes there's no debug information files, in this case, there's no convenient way to b main to start at main function.

So how can I let gdb break at the entry of the program, either the _start entry point or the C style main function?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119
  • use `readelf` to find the address of the entry point, and use `b *0x...` – Peter Cordes Sep 26 '16 at 03:09
  • I knew I'd already answered this before. google for your question title found it as the second hit (after this question). (But SO search didn't find it as easily, so I guess I won't downvote, and leave it as a signpost for future searches). – Peter Cordes Sep 26 '16 at 03:12
  • `_start` isn't specific to AT&T syntax. `global _start` / `_start:` is what you do in NASM, as well, since it's the linker that looks for that symbol name by default. – Peter Cordes Sep 26 '16 at 03:13
  • One other possibility If you have dynamically linked against the _C_ runtime then you could break at __libc_start_main with `break __libc_start_main` this will get you reasonably close to the function `main` even if you didn't build with any debug information. – Michael Petch Sep 26 '16 at 03:20
  • 2
    Any an addendum to Peter's answer (that he linked your question to) you don't need to use `objdump` or `readelf` to get the entry point. You can get GDB to display it with `info file` inside _GDB_ – Michael Petch Sep 26 '16 at 03:23
  • 1
    Also: You can and should include debug symbols in optimized binaries. `-g` doesn't lead to slower code in any way. You can even generate a core dump from a stripped binary, and debug it with the symbols from the unstripped binary. (So you can ship stripped binaries and still make use of stack backtraces. Or better, ship debug symbols as an optional package so people can create useful backtraces for you. This is what Debian/Ubuntu packages like `xserver-xorg-core-dbg` are for.) – Peter Cordes Sep 26 '16 at 03:42

0 Answers0