From 785af6b747ac18875256a009b7fee747375e8a1e Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 19 Apr 2021 12:16:50 +0200 Subject: [PATCH] added more documentation about debuggin tools --- docs/debugging.md | 15 ++++++++++++--- examples/fibs.asm | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/debugging.md b/docs/debugging.md index 37e82f6..b54af5c 100644 --- a/docs/debugging.md +++ b/docs/debugging.md @@ -14,6 +14,7 @@ main: addi s2, zero, 56 ; last storage index addi t0, zero, 1 ; t0 = F_{i} addi t1, zero, 1 ; t1 = F_{i+1} + ebreak ; launch debugger loop: sw t0, fibs(s1) ; save add t2, t1, t0 ; t2 = F_{i+2} @@ -21,14 +22,14 @@ loop: addi t1, t2, 0 ; t1 = t2 addi s1, s1, 4 ; increment storage pointer blt s1, s2, loop ; loop as long as we did not reach array length - ; exit gracefully ebreak ; launch debugger + ; exit gracefully addi a0, zero, 0 addi a7, zero, 93 scall ; exit with code 0 ``` -This calculates the fibonacci sequence and stores it in memory at `fibs`. After it calculated all fibonacci numbers, it +This calculates the fibonacci sequence and stores it in memory at `fibs`. before and after it calculated all fibonacci numbers, it uses the `ebreak` instruction to open the debugger. Let's run it and see what happens: ``` @@ -41,7 +42,7 @@ Debug instruction encountered at 0x00000143 In this interactive session, you have access to the cpu, registers, memory and syscall interface. You can look into everything, and most common tasks should have helper methods for them. -Available objects are: +**Available objects are:** * `mem`: (aka `mmu` or `memory`) * `dump(address, fmt='hex', max_rows=10, group=4, bytes_per_row=16, all=False`: @@ -58,6 +59,14 @@ Available objects are: * `cpu`: * The CPU has the `pc` attribute and `cycle` attribute. Others won't be useful in this context. +**Available helpers are:** + +* `dump(regs | addr)` dumps either registers or memory address +* `cont(verbose=True)` continue execution (verbose prints each executed instruction) +* `step()` run the next instruction +* `ins()` get current instruction (this reference is mutable, if you want to edit your code on the fly) + + Example: ![debuggin the fibs program](debug-session.png) \ No newline at end of file diff --git a/examples/fibs.asm b/examples/fibs.asm index 70f8faf..6038c17 100644 --- a/examples/fibs.asm +++ b/examples/fibs.asm @@ -10,6 +10,7 @@ main: addi s2, zero, 56 ; last storage index addi t0, zero, 1 ; t0 = F_{i} addi t1, zero, 1 ; t1 = F_{i+1} + ebreak ; launch debugger loop: sw t0, fibs(s1) ; save add t2, t1, t0 ; t2 = F_{i+2}