Jason Xu 9c5c2813a0 Update QEMU command in all README and Makefile пре 2 година
..
Makefile 426205e2a3 Added makefiles for LLVM Clang пре 5 година
Makefile.clang 9c5c2813a0 Update QEMU command in all README and Makefile пре 2 година
Makefile.gcc 9c5c2813a0 Update QEMU command in all README and Makefile пре 2 година
OLVASSEL.md 9c5c2813a0 Update QEMU command in all README and Makefile пре 2 година
README.md 9c5c2813a0 Update QEMU command in all README and Makefile пре 2 година
dbg.c 823040a6bf New tutorials пре 6 година
dbg.h 823040a6bf New tutorials пре 6 година
disasm.h 426205e2a3 Added makefiles for LLVM Clang пре 5 година
gpio.h 823040a6bf New tutorials пре 6 година
kernel8.img 86c25a03ae Updated links пре 3 година
link.ld 823040a6bf New tutorials пре 6 година
main.c 823040a6bf New tutorials пре 6 година
mbox.c 214885df63 compute the mailbox cmd only once пре 6 година
mbox.h 823040a6bf New tutorials пре 6 година
sprintf.c 823040a6bf New tutorials пре 6 година
sprintf.h 823040a6bf New tutorials пре 6 година
start.S ea4691947c Improve comments wrt stack setup пре 3 година
uart.c c59ad439f4 Enable UART0 FIFOs пре 3 година
uart.h 823040a6bf New tutorials пре 6 година

README.md

Tutorial 13 - Debugger

Let's rock by implementing an interactive debugger in our exception handler! :-) Now that we have printf(), it shouldn't be hard. (For a more roboust multiplatform library, see mini debugger.)

$ qemu-system-aarch64 -M raspi3b -kernel kernel8.img -serial stdio
Synchronous: Breakpoint instruction
> x
0007FFF0: 13 60 09 00  00 00 00 00  24 10 20 3F  00 00 00 00  .`......$. ?....
> i x30 x30+64
00080804: D2800000      movz      x0, #0x0
00080808: 94003D1C      bl        0x8FC78
0008080C: 94003ECF      bl        0x90348
00080810: D69F03E0      eret
00080814: D503201F        27 x nop
>

Dbg.h, dbg.c

A very minimal and simple debugger (~300 lines in C).

breakpoint a newly defined keyword. We can use this anywhere in our code where we want to invoke the debugger

dbg_decodeexc() similar to exc_handler in tutorial 11, decodes the cause of the exception and prints it

dbg_getline() yep, another low level library we're missing. We need a way to allow the user to edit command line and return it as a string when he/she presses Enter. A minimal implementation, as usual

dbg_getoffs() this function parses the command line for arguments. Accepts hex, decimal number in "register+/-offset" format

dbg_main() the main loop of the debugger.

Disasm.h

Because it's small (~64k), yet supports all ARMv8.2 instructions, only depends on sprintf() (which we have now), I decided to use the Universal Disassembler for this tutorial. If you don't want to compile a disassembler into your debugger, simply set the DISASSEMBLER define 0 in top of dbg.c.

Start

Our _vector table looks different. We have to save registers in memory with dbg_saveregs, print out the cause of the exception, and call our mini-debugger's main loop.

Main

We'll test our shiny new breakpoint keyword in C.