I have a simple C++ program that calls some NASM code:
main.cpp:
#include <iostream>
extern "C" int foo();
int main() {
std::cout << "The result is: " << foo() << std::endl;
return 0;
}
foo.asm:
bits 64
global foo
section .text
foo:
mov rax, 123
inc rax
ret
I can compile everything with CMake
cmake_minimum_required (VERSION 3.15)
project (assembly-x64 LANGUAGES CXX ASM_NASM)
# old school CMAKE to handle NASM formats
if(WIN32)
set(CMAKE_ASM_NASM_FLAGS_DEBUG "-g -F cv8")
set(CMAKE_ASM_NASM_OBJECT_FORMAT win64)
elseif(APPLE)
set(CMAKE_ASM_NASM_FLAGS_DEBUG "-g -F dwarf")
set(CMAKE_ASM_NASM_OBJECT_FORMAT macho64)
else()
set(CMAKE_ASM_NASM_FLAGS_DEBUG "-g -F dwarf")
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
endif()
add_executable(assembly-x64)
target_compile_features(assembly-x64 PUBLIC cxx_std_17)
target_sources(assembly-x64 PRIVATE main.cpp foo.asm)
and I get the correct result. However, I'd like to be able to debug the assembly code just like I would the C++ code. I can create a breakpoint on the foo
function (not using the GUI though), but it doesn't show me the corresponding source location when it pauses. Is there a way around that issue? I'd like to be able to watch registers, etc. Not sure if it's possible in VS code.