0

I am learning NASM x64 and searched for debugger. Not only did I try gdb, but SASM also. Unfortunately, they are both not viable options for me(*). According to the issue (see comments section), it is possible to do debug NASM in Qt Creator. But i can't hit any breakpoints and see register values, for example.

Here my setup is:

  1. CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
enable_language(ASM_NASM)
project(untitled LANGUAGES C ASM_NASM)

SET(CMAKE_BUILD_TYPE Debug)
set(CMAKE_ASM_NASM_FLAGS_DEBUG "-g -F dwarf")
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_LINK_EXECUTABLE "ld <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> \
<FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")

add_executable(untilted main.c lab.asm)
set_target_properties(untilted PROPERTIES NASM_OBJ_FORMAT elf64)
  1. main.c
extern void asm_main();

int main()
{
    asm_main();
    return 0;
}
  1. lab.asm
bits 64

SYS_WRITE equ 1
STDOUT equ 1
NEW_LINE_CHARACTER equ 10

section .data
msg: db "Hello, World", NEW_LINE_CHARACTER, 0 ; length is 13
section .text
global asm_main
asm_main:
    xor rax, rax
    mov rax, SYS_WRITE
    mov rdi, STDOUT
    mov rsi, msg
    mov rdx, 13
    syscall
    ret
  1. Debugging main.c and i hit breakpoint
  2. Can't hit breakpoint in lab.asm

So that's it. As you can see my build configuration is set to Debug(left down corner). So I would really appreciate any help with this issue.

*P.S yeah, probably, i am to lazy and not hardcore enough to use gdb 'cause i once did a lab in 600 lines in NASM and it was good but at the same time bad experience( it is better to learn c++ metaprogramming i dunno). Besides, it is a bit difficult to study and work when a russian drone or rocket can fly into your house, but as a ukrainian zoomer i am used to that kind of crap. I know that nobody asked to tell you that story, but i just want to finish my second year at university with systems programming done and be alive.

  • What version of NASM are you using? NASM 2.16.0 fixed a bug with generating debug info which could explain source lines not being matched up to correct addresses in the machine code, see [GDB does not load source lines from NASM](https://stackoverflow.com/a/72700945) – Peter Cordes Feb 14 '23 at 00:50

0 Answers0