I have a program written in assembly that crashes with a segmentation fault. (The code is irrelevant, but is here.)
My question is how to debug an assembly language program with GDB?
When I try running it in GDB and perform a backtrace, I get no meaningful information. (Just hex offsets.)
How can I debug the program?
(I’m using NASM on Ubuntu, by the way if that somehow helps.)
I would just load it directly into
gdband step through it instruction by instruction, monitoring all registers and memory contents as you go.I’m sure I’m not telling you anything you don’t know there but the program seems simple enough to warrant this sort of approach. I would leave fancy debugging tricks like backtracking (and even breakpoints) for more complex code.
As to the specific problem (code paraphrased below):
You appear to be just pushing 5 on to the stack followed by the address of that 5 in memory (
v_0). I’m pretty certain you’re going to need to push the address of the format string at some point if you want to callprintf. It’s not going to take to kindly to being given a rogue format string.It’s likely that your:
should be:
and I’m assuming that there’s more code after that call to
printfthat you just left off as unimportant (otherwise you’ll be going off to never-never land when it returns).