@@ -1746,6 +1746,12 @@ static void handle_query_qemu_supported(GArray *params, void *user_ctx)
gdb_put_strbuf();
}
+static void handle_query_qemu_pid(GArray *params, void *user_ctx)
+{
+ g_string_printf(gdbserver_state.str_buf, "F%x", getpid());
+ gdb_put_strbuf();
+}
+
static const GdbCmdParseEntry gdb_gen_query_set_common_table[] = {
/* Order is important if has same prefix */
{
@@ -1902,6 +1908,10 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = {
.handler = handle_query_qemu_supported,
.cmd = "qemu.Supported",
},
+ {
+ .handler = handle_query_qemu_pid,
+ .cmd = "qemu.Pid",
+ },
#ifndef CONFIG_USER_ONLY
{
.handler = gdb_handle_query_qemu_phy_mem_mode,
This patch adds support for the `qqemu.Pid` packet to the qemu gdbstub which can be used by clients to get the QEMU process PID. This is useful for plugins like Pwndbg [0] or gdb-pt-dump in order to inspect the QEMU process memory through the /proc/self/{maps,mem} interfaces. Without this feature, they have to rely on doing an unreliable pgrep/ps output processing. This patch has been developed by Patryk, who I included in the Co-authored-by and who asked me to send the patch. [0] https://github.com/pwndbg/pwndbg [1] https://github.com/martinradev/gdb-pt-dump Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com> Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com> --- gdbstub/gdbstub.c | 10 ++++++++++ 1 file changed, 10 insertions(+)