diff options
-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); +} |