I use a fresh install of Ubuntu 22.04, nasm 2.15.05 and gdb 12.1.
Is there anything that has to be done different to be able see the source when debugging x64-Assembly?
The same steps that worked for x86-Assembly do not work for x64-Assembly.
Here is a short breakdown:
x86/helloWorld.asm
section .data
msg: db 'Hello, World!',0 ; define string as label
section .text
global start ; must be declared for linker
start: ; entry point
mov eax, 4 ; system call number (sys_write)
mov ebx, 1 ; file descriptor (stdout)
mov ecx, msg ; message
mov edx, 13 ; message length
int 0x80 ; call kernel
mov eax, 1 ; system call number (sys_exit)
int 0x80 ; call kernel
I assemble and link that using following commands:
nasm -f elf32 -g -F dwarf helloWorld.asm
ld -m elf_i386 -e start -o helloWorld helloWorld.o
I start gdb: gdb helloWorld
In gdb I set a breakpoint:
(gdb) break helloWorld.asm:9
Breakpoint 1 at 0x8049000: file helloWorld.asm, line 9.
I use lay n
to get to the layout that is a split of regs/src on top and cmd at bottom.
As expected, regs is unavailable and in src is the content of helloWorld.asm.
Nice.
x64/helloWorld.asm
section .data
msg: db 'Hello, World!',0 ; define string as label
section .bss
section .text
global start ; must be declared for linker
start: ; entry point
mov rax, 1 ; system call number (sys_write)
mov rdi, 1 ; file descriptor (stdout)
mov rsi, msg ; message
mov rdx, 13 ; message length
syscall ; call kernel
mov rax, 60 ; system call number (sys_exit)
mov rdi, 0 ; 0 = success exit code
syscall ; call kernel
I assemble and link that using following commands:
nasm -f elf64 -g -F dwarf helloWorld.asm
ld -m elf_x86_64 -e start -o helloWorld helloWorld.o
I start gdb: gdb helloWorld
In gdb I set a breakpoint:
(gdb) break helloWorld.asm:9
No line 9 in file "helloWorld.asm".
Make breakpoint pending on future shared library load? (y or [n])
I use lay n
to get to the layout that is a split of regs/src on top and cmd at bottom.
Regs is unavailable and [ No Source Available ]
.
When I enter (gdb) list
, the source becomes available until the next step I do in the program.
Architecture seems to be fine as well:
(gdb) show architecture
The target architecture is set to "auto" (currently "i386:x86-64").
So why does gdb tell me that my source file is a future shared library and why does the source view not work properly?
What can I do to fix that?
I already tried:
- Using a fresh install of gdb and Linux
- Checked if sources are available to gdb when debugging x64 (they are; helloWorld and helloWorld.asm)
- Set the file manually (changed nothing)
I expected:
- To be able to debug without any inconveniences
2