diff options
author | Tim Newsome <tim@sifive.com> | 2022-04-25 08:05:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 08:05:08 -0700 |
commit | 4f37484c91fe97c9cca7e0ca6cfe98c63c365a12 (patch) | |
tree | 219a00d051dd3500e5006a7737aca3188846e615 | |
parent | 2285a9083adf587507aa12802ce0ff763628ce9e (diff) | |
download | riscv-tests-4f37484c91fe97c9cca7e0ca6cfe98c63c365a12.zip riscv-tests-4f37484c91fe97c9cca7e0ca6cfe98c63c365a12.tar.gz riscv-tests-4f37484c91fe97c9cca7e0ca6cfe98c63c365a12.tar.bz2 |
Add EbreakTest. (#380)
* Add EbreakTest.
Confirm correct behavior when somebody bakes an ebreak instruction into
their code.
* Forgot to commit ebreak.c
-rwxr-xr-x | debug/gdbserver.py | 31 | ||||
-rw-r--r-- | debug/programs/ebreak.c | 31 |
2 files changed, 62 insertions, 0 deletions
diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 96ba326..c75267d 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -1735,6 +1735,37 @@ class VectorTest(GdbSingleHartTest): assertIn("_exit", output) assertEqual(self.gdb.p("status"), 0) +class EbreakTest(GdbSingleHartTest): + """Test that we work correctly when somebody puts an ebreak directly into + their code.""" + compile_args = ("programs/ebreak.c", ) + + def setup(self): + self.gdb.load() + self.gdb.b("_exit") + + def test(self): + # Should hit ebreak in the code. + output = self.gdb.c() + assertIn("ebreak", output) + ebreak_pc = self.gdb.p("$pc") + + # Simple resume, we should hit the same ebreak again. + output = self.gdb.c() + assertIn("ebreak", output) + assertEqual(ebreak_pc, self.gdb.p("$pc")) + + # Test getting past the ebreak by changing the PC. + for _ in range(2): + self.gdb.p("$pc=$pc+4") + output = self.gdb.c() + assertIn("ebreak", output) + assertEqual(ebreak_pc, self.gdb.p("$pc")) + + self.gdb.p("$pc=$pc+4") + output = self.gdb.c() + assertIn("_exit", output) + class FreeRtosTest(GdbTest): def early_applicable(self): return self.target.freertos_binary diff --git a/debug/programs/ebreak.c b/debug/programs/ebreak.c new file mode 100644 index 0000000..466c4e7 --- /dev/null +++ b/debug/programs/ebreak.c @@ -0,0 +1,31 @@ +#include <stdint.h> + +void ebreak() +{ + asm volatile("ebreak"); +} + +unsigned int fib(unsigned int n) +{ + if (n == 0) { + return 0; + } + + unsigned int a = 0; + unsigned int b = 1; + + for (unsigned int i = 1; i < n; i++) { + unsigned int next = a + b; + a = b; + b = next; + ebreak(); + } + + return b; +} + +int main() +{ +begin: + fib(4); +} |