From 150a10e8841f012645b77d1a6eb10d25dbf89b56 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 8 Dec 2024 18:08:27 -0700 Subject: GDB fixes --- gdb-helpers/libcr.py | 11 ++++++++++- libcr/coroutine.c | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gdb-helpers/libcr.py b/gdb-helpers/libcr.py index c07b679..3ffafce 100644 --- a/gdb-helpers/libcr.py +++ b/gdb-helpers/libcr.py @@ -26,6 +26,14 @@ def gdb_unregister_unwinder( gdb.invalidate_cached_frames() +def gdb_is_on_os() -> bool: + try: + gdb.execute("info proc", to_string=True) + return True + except gdb.error: + return False + + class gdb_JmpBuf: """Our own in-Python GDB-specific implementation of `jmp_buf`""" @@ -105,7 +113,8 @@ class CrGlobals: self._breakpoint.enabled = True gdb.execute(f"call (void)cr_gdb_readjmp({env_ptr_expr})") self._breakpoint.enabled = False - gdb.execute("queue-signal SIGWINCH") + if gdb_is_on_os(): + gdb.execute("queue-signal SIGWINCH") return self._breakpoint.env def _on_cont(self, event: gdb.Event) -> None: diff --git a/libcr/coroutine.c b/libcr/coroutine.c index a947ae9..7392b6c 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -635,6 +635,12 @@ void coroutine_main(void) { assert(saved); assert(!cr_is_in_intrhandler()); coroutine_running = 0; +#if CONFIG_COROUTINE_GDB + /* Some pointless call to prevent cr_gdb_readjmp() from + * getting pruned out of the firmware image. */ + if (coroutine_table[0].state != CR_NONE) + cr_gdb_readjmp(&coroutine_table[0].env); +#endif while (coroutine_cnt) { cid_t next; while ( !((next = coroutine_ringbuf_pop())) ) { -- cgit v1.2.3-2-g168b