Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are there debugging options for ld

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.

like image 423
Dark Eagle Avatar asked Oct 30 '25 06:10

Dark Eagle


2 Answers

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
like image 101
fuz Avatar answered Oct 31 '25 20:10

fuz


The -s switch tells ld to "strip" the debugging info. Lose that!

like image 26
Frank Kotler Avatar answered Oct 31 '25 20:10

Frank Kotler