I am trying to learn the x86 assembly language, and would like to set up a little environment to do it efficiently. For that I have written some simple code (factorial, fibonnaci,etc...), added a main.c for testing and a Makefile to compile.
But I was never able to debug my code with gdb, no matter what flags I have tried...
Here is the code of facto.asm
global fact
section .text
fact:
push rbx
mov rcx, rdi
xor rax, rax
xor rbx, rbx
inc rax
inc rbx
loop:
mov rdx, rbx
mul rdx
inc rbx
dec rcx
jnz loop
pop rbx
ret
The Makefile:
EXE := facto
BIN := $(EXE).o
ASM := $(EXE).asm
SRC := main
all: $(EXE)
$(BIN): $(ASM)
nasm -f elf64 -gdwarf $(ASM) -o $(BIN)
$(EXE): $(SRC).c $(BIN)
gcc -no-pie -g $(SRC).c $(BIN) -o $(EXE)
.PHONY: clean
clean:
$(RM) *.o
$(RM) $(EXE)
And finally the main.c in which I am doing the tests:
#include <stdio.h>
extern int fact();
int main(void)
{
size_t res = fact(5);
printf("%zu\n",res);
}
When running GDB and trying to "skip" into the assembler code, it just does not get in there and goes directly to the printf, even though I have set the -g flag for gcc and -gdwarf for nasm. Furthermore I am manually setting a break on that line with b.
What is it that I am missing? I would be glad for any clues!
If this can help by any means,I am currently working on an arch linux machine.
Thanks in advance!