The GDB start
command sets a breakpoint at the start of main
, and then runs your program. Presumably your program doesn't have a main
symbol.
Read the error message carefully, it says Function "main" not defined.
The breakpoint at _start
is already set; if that was the problem you'd have seen the prompt after that command, and wouldn't have seen a numeric address. (Try it with b xyz
or b printf
.)
You're looking for the run
command, which just runs the program without looking for any symbols in it.
Use help start
and help run
in GDB to see what they do.
Or the online docs: https://sourceware.org/gdb/onlinedocs/gdb/Starting.html
run
: just start the program, no new breakpoints added.
start
: set a one-time breakpoint in main
before run
. Useful for compiled C/C++, or hand-written asm that defines a main
and uses the standard CRT startup files. This is what you tried to use.
starti
: stop at the first asm instruction of the process. Especially useful for a PIE executable without symbols, where the entry-point numeric address isn't known until after ASLR chooses it, if you run it with ASLR enabled. (The GDB default behaviour is to disable ASLR).
starti
is a relatively recent feature; before that one common hack was to use b *0
, which leads to an error right after the process starts, before any instructions execute. Stopping at the first machine code instruction in GDB