This project demonstrates a simple assembly program using NASM, focusing on creating an executable with and without debugging symbols. It also covers how to verify the presence of debug information and how to run the executable in GDB for debugging purposes.
To assemble the code with debugging information, use the following command:
nasm -f elf64 -g -F dwarf main.asm -o main.o- -f elf64: Specifies the output format as 64-bit ELF.
- -g: Includes debug information in the output file.
- -F dwarf: Specifies the DWARF format for the debug information.
- main.s: The input assembly source file.
- -o main.o: Specifies the name of the output object file.
To assemble the code without debugging information, use the following command:
nasm -f elf64 -o main.o main.asm- -f elf64: Specifies the output format as 64-bit ELF.
- main.asm: The input assembly source file.
- -o main.o: Specifies the name of the output object file.
To verify the presence of debugging sections in the object file, use the readelf or objdump command.
Using readelf
readelf -S main.oLook for sections like .debug_info, .debug_abbrev, .debug_line, etc. If these sections are present, it indicates that debugging information is included.
Using llvm-objdump
llvm-objdump -d main.oThis command also lists the sections in the object file, allowing you to verify the presence of debug information.
Linking the Object File To link the object file and create the executable, use the following command:
ld -o main main.oThis command creates an executable named main from the object file main.o.
Running the Executable To run the executable, simply use:
./mainOr build the project with Just(Justfile) by running::
just buildAssembles and links the source file to create the executable.
Run the project:
just runBuilds the project if necessary and then runs the executable.
Clean the project:
just cleanRemoves the object and executable files.
Default action:
justExecutes the build rule by default.
Running GDB Debugger
To run the GDB debugger, ensure that the code is assembled with debugging information and use the following command:
gdb mainOnce inside GDB, you can set breakpoints, run the program, and inspect variables.
Example GDB Session
Set a Breakpoint:
(gdb) break main.asm:13Run the Program:
(gdb) runInspect Registers:
(gdb) info registersStep Through Instructions:
(gdb) stepDisassemble Code:
(gdb) disassembleBy following these steps, you can effectively build, verify, link, and run your assembly code with or without debugging symbols. Running the GDB debugger with debugging symbols allows for a detailed inspection and debugging of your code.