summaryrefslogtreecommitdiff
path: root/gdb-helpers
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-26 19:46:30 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-29 21:44:58 -0700
commit5d1c30d11f2f8f1dcf2c1d823a1b0c174dc53495 (patch)
tree32fc8cd29dc780cc9b1fc18aa62f1fd08aadb7bb /gdb-helpers
parentae589ef489c4e8406ea33a7c41c7eb22fd57c27c (diff)
gdb-helpers/libcr.py: Fixes for running on actual ARM
Diffstat (limited to 'gdb-helpers')
-rw-r--r--gdb-helpers/libcr.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/gdb-helpers/libcr.py b/gdb-helpers/libcr.py
index e2e24a8..0509387 100644
--- a/gdb-helpers/libcr.py
+++ b/gdb-helpers/libcr.py
@@ -39,6 +39,19 @@ def gdb_setjmp() -> GdbJmpBuf:
def gdb_longjmp(buf: GdbJmpBuf) -> None:
"""Our own in-Python GDB-specific implementation of `longjmp()`"""
+ if (
+ ("sp" in buf.registers)
+ and ("msp" in buf.registers)
+ and ("psp" in buf.registers)
+ and ("control" in buf.registers)
+ ):
+ # On ARM, 'sp' is an alias for either 'msp' or 'psp'
+ # (depending on 'control'&(1<<1)). We must set all 3 before
+ # fussing with 'xPSR' or frames, or GDB will get upset at us
+ # about "Invalid state".
+ gdb.execute(f"set $sp = {buf.registers['sp']}", to_string=True)
+ gdb.execute(f"set $msp = {buf.registers['msp']}")
+ gdb.execute(f"set $psp = {buf.registers['psp']}")
for reg, val in buf.registers.items():
gdb.execute(f"set ${reg} = {val}")
buf.frame.select()
@@ -101,7 +114,11 @@ class CrCoroutine:
cr_env = self.env
if self.cid == self.cr_globals.coroutine_running:
cr_env = saved_env
- assert cr_env
+ if not cr_env:
+ raise gdb.GdbError(
+ f"GDB does not have a saved execution environment for coroutine {self.id}. "
+ + "This can happen if the coroutine has not run for as long as GDB has been attached."
+ )
gdb_longjmp(cr_env)
try:
@@ -179,8 +196,11 @@ class CrListCommand(gdb.Command):
)
def _pretty_frame(self, cr: CrCoroutine, from_tty: bool) -> str:
- with cr.active():
- full = gdb.execute("frame", from_tty=from_tty, to_string=True)
+ try:
+ with cr.active():
+ full = gdb.execute("frame", from_tty=from_tty, to_string=True)
+ except Exception as e:
+ full = "#1 err: " + str(e)
line = full.split("\n", maxsplit=1)[0]
return line.split(maxsplit=1)[1]