BSchlinker
BSchlinker

Reputation: 3481

Debugging information not included with -g

Currently attempting to debug with KDbg / gdb the source code for Towers of Hanoi from http://www.kernelthread.com/projects/hanoi//html/asm.html (great resource)

Since I wanted to review how the stack is used within this problem, I assembled it with NASM and used GCC to link it. However, I noticed that in KDbg, the current point of execution was not updating (i.e, I could not tell where I was within the file). Since KDbg relies on gdb, I ran the code within gdb to see if I experienced similar issues.

If I set a breakpoint on line #30 in the program (which is a line within the main function), I get the following:

(gdb) break 30
Breakpoint 2 at 0x804840b: file hanoi.asm, line 30.
(gdb) next
Single stepping until exit from function main,
which has no line number information.

I'm currently compiling the assembly with the following little script I've written (I should probably migrate to a make file, but this has been working up until now)

bschlinker@net1develop02:~/.scripts$ cat asmgcc
# /usr/bin/sh

nasm -f elf -g -F stabs $1.asm -l $1.lst
gcc -g $1.o -o $1

I just migrated from CentOS to Ubuntu, so I'm not sure if this is an OS environment issue I'm not familiar with, or another issue.

As always, thanks in advance for any assistance.

Upvotes: 1

Views: 838

Answers (2)

Violette
Violette

Reputation: 71

You can assemble with as -o tmp.o something.s && ld -s -o something tmp.o && rm tmp.o. In gdb just display/8i *$eip (or rip if 64 bit), it will display 8 instructions after instruction pointer with every step. So you don't need debugging info at all ;-)

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213526

Try -F dwarf instead of -F stabs.

Upvotes: 2

Related Questions