8

How do I debug assembly code? I'm on Linux and have gdb handy. I know I can watch registers. What are some methods for debugging assembly code?

Scott
  • 5,135
  • 12
  • 57
  • 74

3 Answers3

5

You can of course use breakpoints just as with C or any other compiled language, too. This article describes the process of debugging an assembly program a bit.

unwind
  • 391,730
  • 64
  • 469
  • 606
4

Using the "disassemble" gdb command you can see the assembly code that is about to be executed. This, in conjunction with watching registers, can give you insight into what the CPU is really doing.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
1

Of course you can use nm command with a parameter of executable elf file, it will shows you the available labels with address. From this you can set a breakpoint on a specific address, then execute a single instruction by using "si" debug command.

Mohanraj
  • 4,056
  • 2
  • 22
  • 24
  • You can get symbol -> address info from within GDB, and getting addresses outside the context of a running process doesn't even work for PIE executables that can use ASLR. (gdb disables ASLR by default for processes you start from inside gdb, but you can attach to an already running process and still get symbols.) Anyway, you can `disas my_func` and then set a breakpoint at an address inside the function, all from within GDB. – Peter Cordes May 21 '18 at 23:31