From 4dc88ed87c3aeae13726aae7f8505eebec927f36 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Tue, 15 Mar 2022 20:56:42 +0100 Subject: [PATCH] Add debug target --- Makefile | 15 +++++++++++---- debug.gdb | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 debug.gdb diff --git a/Makefile b/Makefile index d2c8aaf..8559ad6 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ CROSS=aarch64-linux-gnu- CC=$(CROSS)gcc LD=$(CROSS)ld CFLAGS=-Wall -Wextra -ffreestanding -march=armv8-a+crc -mcpu=cortex-a53 +DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer -fno-inline LDSCRIPT=rpi3.ld OBJS=crt0.o uart.o hello.o @@ -13,20 +14,26 @@ csrc=$(wildcard *.c) cobj=$(csrc:%.c=%.o) deps=$(csrc:%.c=%.d) $(gasmsrc:%.S=%.d) -all:kernel.bin +KERNEL=kernel.bin + +all:$(KERNEL) kernel.elf: $(cobj) $(gasmobj) $(LDSCRIPT) - $(LD) $(LDFLAGS) -o $@ $(cobj) $(gasmobj) -T$(LDSCRIPT) -Map kernel.map + $(LD) $(LDFLAGS) -o $@ $(gasmobj) $(cobj) -T$(LDSCRIPT) -Map kernel.map -kernel.bin: kernel.elf +$(KERNEL): kernel.elf $(CROSS)objcopy -O binary $< $@ clean: rm -rf $(cobj) $(gasmobj) $(deps) *.bin *.elf *.map -run: kernel.bin +run: $(KERNEL) qemu-system-aarch64 -machine raspi3b -kernel $< +debug: CFLAGS += $(DEBUG_FLAGS) +debug: CXXFLAGS += $(DEBUG_FLAGS) +debug:$(KERNEL) + aarch64-linux-gnu-gdb -q -x debug.gdb ifneq ($(MAKECMDGOALS),clean) diff --git a/debug.gdb b/debug.gdb new file mode 100644 index 0000000..d63e10d --- /dev/null +++ b/debug.gdb @@ -0,0 +1,3 @@ +#add-symbol-file kernel.map +file kernel.elf +target remote | qemu-system-aarch64 -machine raspi3b -S -gdb stdio -kernel kernel.bin