diff options
author | Tim Newsome <tim@sifive.com> | 2016-06-30 18:57:24 -0700 |
---|---|---|
committer | Tim Newsome <tim@sifive.com> | 2016-07-19 11:24:25 -0700 |
commit | 3ed5afdc5b7e2c32bc6facf410c8fa091dd55470 (patch) | |
tree | 736738c27c4366d2583b93ea91eb8710b7995a1a /debug | |
parent | a8f4c20794b4eff8089f7fedb2d1bb4eff0a08d4 (diff) | |
download | riscv-tests-3ed5afdc5b7e2c32bc6facf410c8fa091dd55470.zip riscv-tests-3ed5afdc5b7e2c32bc6facf410c8fa091dd55470.tar.gz riscv-tests-3ed5afdc5b7e2c32bc6facf410c8fa091dd55470.tar.bz2 |
I think I've finally got malloc working right.
Now gdb can call functions and change strings.
Diffstat (limited to 'debug')
-rwxr-xr-x | debug/gdbserver.py | 17 | ||||
-rw-r--r-- | debug/programs/debug.c | 7 | ||||
-rwxr-xr-x | debug/programs/entry.S | 6 | ||||
-rwxr-xr-x | debug/targets/m2gl_m2s/link.lds | 6 | ||||
-rwxr-xr-x | debug/targets/spike/link.lds | 5 |
5 files changed, 27 insertions, 14 deletions
diff --git a/debug/gdbserver.py b/debug/gdbserver.py index d250853..0f5c28e 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -169,20 +169,27 @@ class DebugTest(DeleteServer): self.gdb.load() self.gdb.b("_exit") - def exit(self): + def exit(self, expected_result = 0xc86455d4): output = self.gdb.c() self.assertIn("Breakpoint", output) - #TODO self.assertIn("_exit", output) - #TODO self.assertEqual(self.gdb.p("status"), 0xc86455d4) - # Use a0 until gdb can resolve "status" - self.assertEqual(self.gdb.p("$a0") & 0xffffffff, 0xc86455d4) + self.assertIn("_exit", output) + self.assertEqual(self.gdb.p("status"), expected_result) def test_function_call(self): + self.gdb.b("main:start") + self.gdb.c() text = "Howdy, Earth!" gdb_length = self.gdb.p('strlen("%s")' % text) self.assertEqual(gdb_length, len(text)) self.exit() + def test_change_string(self): + text = "This little piggy went to the market." + self.gdb.b("main:start") + self.gdb.c() + self.gdb.p('fox = "%s"' % text) + self.exit(0x43b497b8) + def test_turbostep(self): """Single step a bunch of times.""" self.gdb.command("p i=0"); diff --git a/debug/programs/debug.c b/debug/programs/debug.c index 2010eaa..20b1cdc 100644 --- a/debug/programs/debug.c +++ b/debug/programs/debug.c @@ -1,11 +1,10 @@ #include <stdio.h> #include <string.h> #include <stdint.h> +#include <stdlib.h> unsigned int crc32a(uint8_t *message, unsigned int size); -char __malloc_start[512]; - void rot13(char *buf) { while (*buf) { @@ -28,8 +27,12 @@ size_t strlen(const char *buf) return len; } +extern void *__malloc_freelist; + int main() { + __malloc_freelist = 0; + volatile int i = 0; int j = 0; char *fox = "The quick brown fox jumps of the lazy dog."; diff --git a/debug/programs/entry.S b/debug/programs/entry.S index 480b404..80904cd 100755 --- a/debug/programs/entry.S +++ b/debug/programs/entry.S @@ -3,7 +3,7 @@ #include "encoding.h" -#define STACK_SIZE 128 +#define STACK_SIZE 512 #ifdef __riscv64 # define LREG ld @@ -124,9 +124,9 @@ trap_entry: addi sp, sp, 32*REGBYTES mret - .bss + // Fill the stack with data so we can see if it was overrun. .align 4 stack_bottom: - .skip STACK_SIZE + .fill STACK_SIZE/4, 4, 0x22446688 stack_top: #endif diff --git a/debug/targets/m2gl_m2s/link.lds b/debug/targets/m2gl_m2s/link.lds index a922b41..1dbb99c 100755 --- a/debug/targets/m2gl_m2s/link.lds +++ b/debug/targets/m2gl_m2s/link.lds @@ -13,7 +13,7 @@ SECTIONS .data : { *(.data) } .sdata : { - _gp = .; + _gp = . + 0x800; *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*) *(.sdata .sdata.* .gnu.linkonce.s.*) @@ -26,7 +26,9 @@ SECTIONS } .bss : { *(.bss) } + __malloc_start = .; + . = . + 512; + /* End of uninitalized data segement */ _end = .; - _heap_end = .; } diff --git a/debug/targets/spike/link.lds b/debug/targets/spike/link.lds index 029a332..52e4472 100755 --- a/debug/targets/spike/link.lds +++ b/debug/targets/spike/link.lds @@ -28,8 +28,9 @@ SECTIONS } .bss : { *(.bss) } + __malloc_start = .; + . = . + 512; + /* End of uninitalized data segement */ _end = .; - _heap_end = .; } - |