1

I'm trying to use gdb to debug my assembly subroutine, but was having trouble trying to determine where exactly the program reaches a segfault.

I run it until it reaches the segfault, then use the 'where' command, which gives me this:

0x00010e40 in swapChars()

Is there a way for me to figure out exactly what line the segfault occurred at in my subroutine?

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • `x/i $pc` will show the current instruction. You can also ask for more context if needed, see the help. You don't need debug info for this. – Jester May 18 '17 at 11:53

2 Answers2

1

Is there a way for me to figure out exactly what line the segfault occurred at in my subroutine?

Yes: you need to compile your program with debugging info (the output you provided shows that you likely haven't).

Usually that's as simple as adding -g to CFLAGS.

Sometimes programs lack debug info because there is a stray -s (strip debug info) flag on the link line.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

In gdb, use the command 'layout asm' and it will switch to a view of the assembly code. Then you should be able to see exactly which instruction caused the fault.

Rob Gardner
  • 201
  • 1
  • 4