diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-27 15:27:52 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-29 21:46:26 -0700 |
commit | 9eaa70ddf2e5c50503b5e135b52b39ac7ae6f089 (patch) | |
tree | e6b29ee637d8f8eab54939fcd932af6bcce6beb1 /gdb-helpers | |
parent | 5d1c30d11f2f8f1dcf2c1d823a1b0c174dc53495 (diff) |
gdb-helpers/libcr.py: Use fewer breakpoints
They're at a premium on the RP2040.
Diffstat (limited to 'gdb-helpers')
-rw-r--r-- | gdb-helpers/libcr.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/gdb-helpers/libcr.py b/gdb-helpers/libcr.py index 0509387..dbe7ec8 100644 --- a/gdb-helpers/libcr.py +++ b/gdb-helpers/libcr.py @@ -71,6 +71,12 @@ class CrGlobals: self.coroutines = [CrCoroutine(self, i + 1) for i in range(num)] self.breakpoints = [] + def delete(self) -> None: + self.coroutines = [] + for b in self.breakpoints: + b.delete() + self.breakpoints = [] + def is_valid_cid(self, cid: int) -> bool: return 0 < cid and cid <= len(self.coroutines) @@ -127,19 +133,26 @@ class CrCoroutine: gdb_longjmp(saved_env) -class CrYieldBreakpoint(gdb.Breakpoint): +class CrSetJmpBreakpoint(gdb.Breakpoint): cr_globals: CrGlobals - def __init__(self, cr_globals: CrGlobals, function: str) -> None: + def __init__(self, cr_globals: CrGlobals) -> None: self.cr_globals = cr_globals cr_globals.breakpoints += [self] - super().__init__(function=function, type=gdb.BP_BREAKPOINT, internal=True) # type: ignore + super().__init__(function="_cr_plat_setjmp_pre", type=gdb.BP_BREAKPOINT, internal=True) # type: ignore def stop(self) -> bool: - if self.cr_globals.is_valid_cid(self.cr_globals.coroutine_running): - self.cr_globals.coroutines[self.cr_globals.coroutine_running - 1].env = ( - gdb_setjmp() + if bool(gdb.parse_and_eval("env == &coroutine_add_env")): + cid = self.cr_globals.coroutine_running + elif bool(gdb.parse_and_eval("env == &coroutine_main_env")): + cid = 0 + else: + idx = gdb.parse_and_eval( + "( ((char*)env)-((char *)&coroutine_table)) / sizeof(coroutine_table[0])" ) + cid = int(idx) + 1 + if self.cr_globals.is_valid_cid(cid): + self.cr_globals.coroutines[cid - 1].env = gdb_setjmp() return False @@ -255,9 +268,7 @@ class CrApplyCommand(gdb.Command): def cr_initialize() -> None: cr_globals = CrGlobals() - CrYieldBreakpoint(cr_globals, "_cr_yield") - CrYieldBreakpoint(cr_globals, "cr_begin") - CrYieldBreakpoint(cr_globals, "coroutine_add_with_stack_size") + CrSetJmpBreakpoint(cr_globals) CrCommand(cr_globals) CrListCommand(cr_globals) @@ -266,7 +277,8 @@ def cr_initialize() -> None: def cr_on_new_objfile(event: gdb.Event) -> None: if any( - objfile.lookup_static_symbol("cr_plat_longjmp") for objfile in gdb.objfiles() + objfile.lookup_static_symbol("_cr_plat_setjmp_pre") + for objfile in gdb.objfiles() ): print("Initializing libcr integration...") cr_initialize() |