![]() |
gdb for assembly language
Hi. I'm fairly new with assembly language (using nasm on ubuntu 64bit) and I'm having some trouble using gdb for debugging.
Right now I have a sandbox asm file that I put code into just to test to see how registers and stuff change in gdb before I try writing an actual program. This isn't a program I need help with I just want to know why gdb is responding like it is. (lines 1-8 are just comments) Code:
9 SECTION .data ; Section containing initialized data Code:
(gdb) break 23 Only on line 26 can I successfully add a break Code:
(gdb) break 26 Code:
(gdb) b 28 Also I am assembling with `nasm -f elf64 -g -F stabs sandbox.asm' (The book I am working from is for 32bit but I am on a 64bit cpu) but when I try to run `$ gdb -tui sandbox' it won't show the source code, I have to open the source code in a separate terminal and work from those line numbers. However when I try `ddd sandbox' ddd will open sandbox.asm in it's source code window. Any help would be appreciated, Thanks. |
Just in case anyone was interested, I realized the problem was that I had forgotten that when setting a breakpoint at say line 26, the debugger stops execution at line 25!
The segfaults are caused I think by add, xchg and `mov ax,067FEh' (I just copied these straight from the book I'm reading) And the reason gdb isn't stopping at the breakpoints I'm setting and instead just runs straight through the program, is because gdb just gives the illusion that it is debugging with the source code, but it is instead working off machine code. Therefore `nops' need to be added, Code:
... |
I have a moderate amount of experience with gdb, but solely with C source.
Your second comment mentions line 26, but your original comment cites line 23 which should be before the fault. I can understand that for assembly it doesn't follow the source file lines. And then it seems to accept the setting of a breakpoint... Why do you say it won't print out those source lines? They should be easier to see because when they show in the debugger in assembly, they're obviously matching 100% what your file shows. You can use 'b' as opposed with typing out 'break'. You can use 'l' to 'list' the area in your source near or about where it thinks the program counter presently is located, or near a source line. Like you can just type 'l' or 'list' or you can also type 'l 25' or 'list 25' and that should show you source line #25, but for C code is where I'm more familiar. Listing the source doesn't work? |
In my experience, which is limited, gdb isn't terribly assembler friendly. Still, I took your code, removed the nop since it shouldn't be necessary, and compiled it with yasm and it worked as expected. I use yasm, and with yasm, to use gdb you have to indicate a debugging format. i.e.
Code:
yasm -f elf64 -g dwarf2 -l forum_test1.lst -o forum_test1.o forum_test1.asm I then linked with ld. There are two debugging formats dwarf and stabs but I think dwarf has mostly replaced stabs. |
All times are GMT -5. The time now is 06:43 AM. |