Reputation: 107
I have written an assembly program that, for testing purposes, just exits. The code is as follows:
section .text
_global start
_start:
mov eax, 1
mov ebx, 0
int 0x80
The program is obviously in 32-bit; however, I am using 1 64-bit processor and operating system, so I compiled it (using nasm) and linked it as follows:
nasm -f elf exit.asm
ld -m elf_i386 -s -o exit exit.o
debugging the program with gdb, I can't list the code since there are no debugging symbols.
(gdb) list
No symbol table is loaded. Use the "file" command.
In using gcc, you can use the options -ggdb to load the symbols while compiling a c file. but since I don't how to use gcc to compile 32-bit assembly for 64-bit machines (I have searched this but can't find a solution,) I am forced to use ld. can I load the debugging symbols using ld? sorry for the long question and the excess information. Thanks in advance.
Upvotes: 4
Views: 6738
Reputation: 92966
Debugging information is generated by nasm
when you pass -g
. Additionally, you also need to specify what type of debugging information you want (typically dwarf), which is done with the -F
switch. So to assemble your file, write
nasm -f elf -F dwarf -g file.asm
then link without -s
to preserve the symbol table and debugging information:
ld -m elf_i386 -o file file.o
Upvotes: 8
Reputation: 3119
The -s
switch tells ld to "strip" the debugging info. Lose that!
Upvotes: 4