I've followed this link to set up nasm debugging in VS Code on Linux. It is working fine, register values are getting updated when I'm stepping through the code.
I would like to display user defined variables in the watch window and have them updated as I step through the code. So, if I have
section .data
hello db 'Hello, World!',0
I would like to see this variable in the watch window, the same way I, for example, see user defined array variables when writing a C program. I have tried googling the solution and asked ChatGPT but didn't find any solution. I've tried to add it in multiple ways: hello
, hello, <length>
, hello[length]
but every time it is displayed hello:<blank>
.
Is this possible? Also, please don't recommend alternatives like SASM, I would like to use VS Code only, if possible.
Edit: Started gdb from cmd and got:
info variables
: variable listed under non-debugging symbols (other ones being __bss_start
, _edata
, _end
)
info symbol <name>
: <name>
has unknown type; cast it to its declared type
info symbol (char[])<name>
: evaluation requires the program to have a function malloc
info symbol (char*)<name>
: no symbol matches (char*)<name>
info symbol <address>
: <name>
in section .data
of <program path>
(same thing with *(char*)<address>
)
info symbol *(char*)<name>
: cannot access memory address (different address than the one listed on info variables
)
After a sleepless night, I think I finally found the solution. One disclaimer, I've switched to AT&T syntax (GAS), I like it more.
I've created a new VS Code project, installed Makefile tools extension, created a source file sample.s
and a following makefile:
AS = as
LD = ld
ASFLAGS = -g --64 --gstabs
TARGET = sample
SRC = sample.s
all: $(TARGET)
$(TARGET): $(SRC)
$(AS) $(ASFLAGS) -o $(TARGET).o $(SRC)
$(LD) -m elf_x86_64 -o $(TARGET) $(TARGET).o
.PHONY: clean run
clean:
rm -f $(TARGET) $(TARGET).o
run: $(TARGET)
./$(TARGET)
In the makefile tools extension, build target
is set to all
and launch target
is set to sample
.
After placing the breakpoint and running the debugger, I put the variable to the watch window
in the following format:
(char*)0x402000, 15
where the 0x402000
is the address of symbol. Lenght is less than 15 but it doesn't matter.
In this way, the whole array is displayed, with its values and indices. I've also tried to change one of the values in the array and it gets updated and displayed properly.
@rioV8 Thank you very much for your help.