Dominik 'Disconnect3d' Czarnota <[email protected]> writes:

> This commit adds support for the `qGDBServerVersion` packet to the qemu
> gdbstub  which could be used by clients to detect the QEMU version
> (and, e.g., use a workaround for known bugs).
>
> This packet is not documented/standarized by GDB but it was implemented
> by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
>
> This has been implemented by Patryk, who I included in Co-authored-by
> and who asked me to send the patch.
>
> [0] https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
> [1] https://github.com/pwndbg/pwndbg/issues/2648
>
> Co-authored-by: Patryk 'patryk4815' Sondej <[email protected]>
> Signed-off-by: Dominik 'Disconnect3d' Czarnota
> <[email protected]>

Hmm:

cc -m64 -Ilibuser.a.p -I. -I../.. -Iqapi -Itrace -Iui -Iui/shader 
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
-fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g 
-fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined 
-Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 
-Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs 
-Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local 
-Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings 
-Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem 
/home/alex/lsrc/qemu.git/linux-headers -isystem linux-headers -iquote . -iquote 
/home/alex/lsrc/qemu.git -iquote /home/alex/lsrc/qemu.git/include -iquote 
/home/alex/lsrc/qemu.git/host/include/x86_64 -iquote 
/home/alex/lsrc/qemu.git/host/include/generic -iquote 
/home/alex/lsrc/qemu.git/tcg/i386 -pthread -mcx16 -msse2 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common 
-fwrapv -ftrivial-auto-var-init=zero -fzero-call-used-regs=used-gpr -fPIE 
-DCONFIG_USER_ONLY -DCOMPILING_SYSTEM_VS_USER -MD -MQ 
libuser.a.p/gdbstub_gdbstub.c.o -MF libuser.a.p/gdbstub_gdbstub.c.o.d -o 
libuser.a.p/gdbstub_gdbstub.c.o -c ../../gdbstub/gdbstub.c
../../gdbstub/gdbstub.c: In function ‘handle_query_gdb_server_version’:
../../gdbstub/gdbstub.c:1603:74: error: implicit declaration of function 
‘target_name’ [-Werror=implicit-function-declaration]
 1603 |     g_string_printf(gdbserver_state.str_buf, 
"name:qemu-%s;version:%s;", target_name(), QEMU_VERSION);
      |                                                                         
 ^~~~~~~~~~~
../../gdbstub/gdbstub.c:1603:74: error: nested extern declaration of 
‘target_name’ [-Werror=nested-externs]
../../gdbstub/gdbstub.c:1603:46: error: format ‘%s’ expects argument of type 
‘char *’, but argument 3 has type ‘int’ [-Werror=format=]
 1603 |     g_string_printf(gdbserver_state.str_buf, 
"name:qemu-%s;version:%s;", target_name(), QEMU_VERSION);
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~ 
 ~~~~~~~~~~~~~
      |                                                                         
 |
      |                                                                         
 int
cc1: all warnings being treated as errors

where did target_name() come from and/or go to?

> ---
>  gdbstub/gdbstub.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
> index 282e13e163..8d616a7f52 100644
> --- a/gdbstub/gdbstub.c
> +++ b/gdbstub/gdbstub.c
> @@ -1582,6 +1582,16 @@ static void handle_query_threads(GArray *params, void 
> *user_ctx)
>      gdbserver_state.query_cpu = 
> gdb_next_attached_cpu(gdbserver_state.query_cpu);
>  }
>  
> +static void handle_query_gdb_server_version(GArray *params, void *user_ctx)
> +{
> +#if defined(CONFIG_USER_ONLY)
> +    g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;", 
> target_name(), QEMU_VERSION);
> +#else
> +    g_string_printf(gdbserver_state.str_buf, 
> "name:qemu-system-%s;version:%s;", target_name(), QEMU_VERSION);
> +#endif
> +    gdb_put_strbuf();
> +}
> +
>  static void handle_query_first_threads(GArray *params, void *user_ctx)
>  {
>      gdbserver_state.query_cpu = gdb_first_attached_cpu();
> @@ -1827,6 +1837,10 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = {
>          .handler = handle_query_threads,
>          .cmd = "sThreadInfo",
>      },
> +    {
> +        .handler = handle_query_gdb_server_version,
> +        .cmd = "GDBServerVersion",
> +    },
>      {
>          .handler = handle_query_first_threads,
>          .cmd = "fThreadInfo",

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro

Reply via email to