aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-09-24 22:45:00 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-09-24 22:45:00 +0200
commit54cf703d13bddbe81e15858b1bfdb7111a3f56de (patch)
tree5d6d58483c063efd2ec9b55abdc65918f9a19d96
parent052f73e4e5c7f6266bf80f392ac593046e2d8d2c (diff)
downloadfbos-54cf703d13bddbe81e15858b1bfdb7111a3f56de.tar.gz
fbos-54cf703d13bddbe81e15858b1bfdb7111a3f56de.zip
Load debug symbols on the gdb target
Load the debug symbols into the gdb session by simply passing the executable file into gdb directly. Moreover, allow users of the gdb target to provide an extra variable so to pass extra flags to gdb. Moreover, this commit comes with other small cleanups on the Makefile, like a proper ABI specifier, Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
-rw-r--r--Makefile27
-rw-r--r--README.md34
2 files changed, 41 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 611ee48..df82342 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
##
-# By default everything is silent. If you want to change this behavior, simply
+# By default everything is silent. If you want to change this behavior simply
# assign V=1 when calling make.
V =
@@ -21,14 +21,19 @@ CC = $(CROSS_COMPILE)gcc$(CC_SUFFIX)
LD = $(CROSS_COMPILE)ld
QEMU ?= qemu-system-riscv64
-ISA ?= rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd_zba_zbb
-CCFLAGS = -march=$(ISA) -Iinclude/ -mabi=lp64
-CCFLAGS += -Werror -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual -Winit-self \
- -Wmissing-include-dirs -Wredundant-decls -Wshadow -Wsign-conversion \
- -Wswitch-default -Wundef -Wunreachable-code -Wmissing-noreturn
-LDFLAGS = -Iinclude/ -static -nostdlib -melf64lriscv -z noexecstack
-QEMU_FLAGS ?=
-QEMU_BIOS ?=
+ISA ?= rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd_zba_zbb
+CCFLAGS = -march=$(ISA) -Iinclude/ -mabi=lp64d
+CCFLAGS += -Werror -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual -Winit-self \
+ -Wmissing-include-dirs -Wredundant-decls -Wshadow -Wsign-conversion \
+ -Wswitch-default -Wundef -Wunreachable-code -Wmissing-noreturn
+LDFLAGS = -Iinclude/ -static -nostdlib -melf64lriscv -z noexecstack
+
+##
+# Optional parameters for QEMU and gdb.
+
+QEMU_FLAGS ?=
+QEMU_BIOS ?=
+GDB_EXTRA_FLAGS ?=
##
# You can pass an optional `DEBUG` variable to manipulate the build type. This
@@ -74,7 +79,7 @@ $(KRNL): $(OBJ) $(LINKER).S
$(Q) $(CC) $(CCFLAGS) -c $< -o $@
.PHONY: qemu
-qemu:
+qemu: $(KRNL)
ifeq ($(strip $(QEMU_BIOS)),)
$(Q) $(QEMU) $(QEMU_FLAGS) -machine virt -kernel $(KRNL) -nographic
else
@@ -83,7 +88,7 @@ endif
.PHONY: gdb
gdb:
- $(Q) gdb --command utils/init.gdb
+ $(Q) gdb --command utils/init.gdb $(GDB_EXTRA_FLAGS) $(KRNL)
.PHONY: clean
clean:
diff --git a/README.md b/README.md
index da92c98..5833b55 100644
--- a/README.md
+++ b/README.md
@@ -63,15 +63,17 @@ $ make ARCH=riscv CROSS_COMPILE=<your-cross-compile> PLATFORM=generic
With that simply set the `QEMU_BIOS` environment variable with the full path of
the resulting `fw_dynamic.bin` file.
-Now make sure that you have the version that is able to emulate a RISC-V system.
-After that, simply run:
+Now make sure that you have a QEMU version that is able to emulate a RISC-V
+system. After that, simply run:
```
$ make qemu
```
-The `qemu` target can be paired with the `DEBUG` parameter that you can pass to
-make. Hence, you can also call it like so:
+This will open up QEMU in `-nographic` mode (hence the serial output will be
+simply redirected to stdout), and you will be able to see the whole thing
+working. Moreover, the `qemu` target can be paired with the `DEBUG` parameter
+that you can pass to make. Hence, you can also call it like so:
```
$ make qemu DEBUG=1
@@ -83,19 +85,33 @@ This will make QEMU wait for a GDB connection. On another terminal then type:
$ make gdb
```
-Now you have a debugging session for this kernel. If you want to skip ahead,
-notice that the kernel starts at `PAGE_OFFSET` (see `include/fbos/mm.h`). Hence,
-upon starting the GDB session you can simply type:
+Now you have a debugging session for this kernel with debug symbols loaded.
+Hence, upon starting the GDB session you can simply type:
```
-# 0x80200000 is the current value of PAGE_OFFSET.
-(gdb) break *0x80200000
+(gdb) break _start
(gdb) continue
```
From there you are already out of firmware code and right into the kernel.
+Moreover, you can also pass the `GDB_EXTRA_FLAGS` variable to the `make gdb`
+target. This way you can pass extra parameters to gdb, such as:
+
+```
+$ make gdb GDB_EXTRA_FLAGS="-tui"
+```
+
+And now you have started a GDB session with a nice TUI interface.
## Special thanks to
SUSE for organizing [Hack Week 24](https://hackweek.opensuse.org/24/projects).
This project was mainly developed during this time.
+
+I have also taken lots of valuable input by reading [Popovic's
+blog](https://popovicu.com/), so thanks a lot for writing such clear articles on
+a rather obscure topic. In a similar way, I have also taken the time to read a
+lot of code from the Linux Kernel. My understanding of both RISC-V and the Linux
+Kernel itself has vastly improved with this exercise, so I'd also like to take
+the chance to be grateful to the many people who have contributed to this vast
+undertaking that is the Linux Kernel.