From 3cb567d0b1bfbbbe91b1c1f2f4cb4200ba97b4e3 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 26 Sep 2023 00:39:18 +0200 Subject: [PATCH] GDB: support an empty initial thread list on Genode Fixes #5005 --- repos/ports/ports/gdb.hash | 2 +- .../noux-pkg/gdb/patches/first_inferior.patch | 41 +++++++++++++++++++ repos/ports/src/noux-pkg/gdb/patches/series | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 repos/ports/src/noux-pkg/gdb/patches/first_inferior.patch diff --git a/repos/ports/ports/gdb.hash b/repos/ports/ports/gdb.hash index d04d577889..8531140294 100644 --- a/repos/ports/ports/gdb.hash +++ b/repos/ports/ports/gdb.hash @@ -1 +1 @@ -a8c8d04deda7e71e478139c13462d27372f61df3 +e87f5f493b158db5eef0add1064352076a2143bf diff --git a/repos/ports/src/noux-pkg/gdb/patches/first_inferior.patch b/repos/ports/src/noux-pkg/gdb/patches/first_inferior.patch new file mode 100644 index 0000000000..ae537c9ac5 --- /dev/null +++ b/repos/ports/src/noux-pkg/gdb/patches/first_inferior.patch @@ -0,0 +1,41 @@ +first_inferior.patch + +Detect the creation of the first inferior if it doesn't exist yet +when GDB connects to the debug monitor and make sure that its pid +is sent in 'Hg' commands even if no thread is selected, to get +the memory map of the correct inferior with the 'info mem' +command. + +diff --git a/gdb/remote.c b/gdb/remote.c +index b5db0c0..f36d4a9 100644 +--- a/gdb/remote.c ++++ b/gdb/remote.c +@@ -2908,6 +2908,9 @@ remote_target::set_thread (ptid_t ptid, int gen) + xsnprintf (buf, endbuf - buf, "0"); + else if (ptid == minus_one_ptid) + xsnprintf (buf, endbuf - buf, "-1"); ++ else if (ptid == null_ptid) ++ write_ptid (buf, endbuf, ptid_t (current_inferior()->pid, ++ ptid.lwp(), ptid.tid())); + else + write_ptid (buf, endbuf, ptid); + putpkt (rs->buf); +@@ -5007,9 +5010,16 @@ remote_target::start_remote_1 (int from_tty, int extended_p) + + if (thread_count (this) == 0) + { +- if (!extended_p) ++ if (!extended_p) { + error (_("The target is not running (try extended-remote?)")); +- return false; ++ return false; ++ } ++ ++ /* Accept remote events to be able to detect the first thread. */ ++ if (target_can_async_p ()) ++ target_async (true); ++ ++ return true; + } + + /* Report all signals during attach/startup. */ diff --git a/repos/ports/src/noux-pkg/gdb/patches/series b/repos/ports/src/noux-pkg/gdb/patches/series index 131a5b8d26..659a510dd6 100644 --- a/repos/ports/src/noux-pkg/gdb/patches/series +++ b/repos/ports/src/noux-pkg/gdb/patches/series @@ -7,3 +7,4 @@ gdbserver_genode.patch call_dummy_location.patch non_stop.patch memory_map.patch +first_inferior.patch