Add GDB qAttached support
cover Add GDB qAttached support
Fabien Chouteau (2):
Add GDB qAttached support
Revert "gdbstub: Do not kill target in system emulation mode"
gdbstub.c | 40 +++++++++++++++++++++++++++++++++++++--- include/exec/gdbstub.h | 2 ++ qemu-options.hx | 17 +++++++++++++++++ vl.c | 3 +++ 4 files changed, 59 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 Add GDB qAttached support
With this patch QEMU handles qAttached request from gdb. When QEMU replies 1, GDB sends a "detach" command at the end of a debugging session otherwise GDB sends "kill".
The default value for qAttached is 1 on system emulation and 0 on user emulation.
We introduce a new command line option. It's a generic option to customize the gdb server:
-gdb-opts [attached=on|off]
The only parameter for now is "attached".
This patch implements the requirement described in Jan Kiszka's patch:
"gdbstub: Do not kill target in system emulation mode". The patch can therefore be reverted.
--- gdbstub.c | 38 +++++++++++++++++++++++++++++++++++++- include/exec/gdbstub.h | 2 ++ qemu-options.hx | 17 +++++++++++++++++ vl.c | 3 +++ 4 files changed, 59 insertions(+), 1 deletion(-)
gdbstub.c +37 -1
@@ -32,7 +32,6 @@#include "monitor/monitor.h" #include "char/char.h" #include "sysemu/sysemu.h" -#include "exec/gdbstub.h" #endif #define MAX_PACKET_LENGTH 4096
@@ -41,6 +40,13 @@#include "qemu/sockets.h" #include "sysemu/kvm.h" #include "qemu/bitops.h" +#include "exec/gdbstub.h" + +#ifdef CONFIG_USER_ONLY +static bool gdb_attached;/* false */ +#else +static bool gdb_attached = true; +#endif #ifndef TARGET_CPU_MEMORY_RW_DEBUG static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
@@ -2491,6 +2497,10 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) break; }#endif +if (strncmp (p,"Attached" ,8 ) ==0 ) { +put_packet (s, gdb_attached ?"1" :"0" ); +break ; + }/* Unrecognised 'q' command. */ goto unknown_command;
@@ -3055,3 +3065,29 @@ int gdbserver_start(const char *device) return 0; }#endif + +static QemuOptsList qemu_gdb_opts = { + .name ="gdb" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_gdb_opts.head), + .desc = { + { + .name ="attached" , + .type =QEMU_OPT_BOOL , + }, + {/* end of list */ } + }, +}; + +void gdb_set_opts (const char *opts_str) +{ +QemuOpts *opts; + + opts =qemu_opts_parse (&qemu_gdb_opts, opts_str,0 ); +if (!opts) { +exit (1 ); + } + + gdb_attached =qemu_opt_get_bool (opts,"attached" , gdb_attached); + +qemu_opts_del (opts); +}
include/exec/gdbstub.h +2 -0
@@ -50,4 +50,6 @@ int gdbserver_start(const char *port);/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */ extern const char *const xml_builtin[][2 ]; +void gdb_set_opts (const char *opts_str); +#endif
qemu-options.hx +17 -0
@@ -2505,6 +2505,23 @@ within gdb and establish the connection via a pipe: @end example ETEXI +DEF("gdb-opts", HAS_ARG, QEMU_OPTION_gdb_opts, \ + "-gdb-opts attached=on|off\n"\ + " options for the gdb remote server\n", QEMU_ARCH_ALL) +STEXI +@item -gdb-opts @var{dev} +@findex -gdb-opts +Set options for the gdb remote server: +@table @option +@item attached=on|off: + +When 'on' (default), gdb sends a 'detach' command at the end of debugging +session, otherwise gdb sends a 'kill' command. + +@end table + +ETEXI + DEF("s", 0, QEMU_OPTION_s, \ "-s shorthand for -gdb tcp::" DEFAULT_GDBSTUB_PORT "\n", QEMU_ARCH_ALL)
vl.c +3 -0
@@ -3251,6 +3251,9 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_gdb:add_device_config (DEV_GDB , optarg);break ; +case QEMU_OPTION_gdb_opts: +gdb_set_opts (optarg); +break ;case QEMU_OPTION_L : data_dir = optarg;break ;
Signature · 1 line
1.7.9.5
Quoted 9 lines · Fabien Chouteau
With this patch QEMU handles qAttached request from gdb. When QEMU replies 1, GDB sends a "detach" command at the end of a debugging session otherwise GDB sends "kill".
The default value for qAttached is 1 on system emulation and 0 on user emulation.
We introduce a new command line option. It's a generic option to customize the gdb server:
Again, please factor this out into a separate patch so that qAttached can be merged independently (and we stop warning the gdb users incorrectly about killing the target on quit).
Quoted 2 lines
-gdb-opts [attached=on|off]
This will still trigger additional discussions as it's still a new top-level command line switch.
I think it is possible to merge chardev-unrelated options into the parameter that -gdb takes and filter them out before handing the rest over to the chardev layer.
Jan
Quoted 136 lines
The only parameter for now is "attached".
This patch implements the requirement described in Jan Kiszka's patch:
"gdbstub: Do not kill target in system emulation mode". The patch can therefore be reverted.Signed-off-by Fabien Chouteau <[email protected]>--- gdbstub.c | 38 +++++++++++++++++++++++++++++++++++++- include/exec/gdbstub.h | 2 ++ qemu-options.hx | 17 +++++++++++++++++ vl.c | 3 +++ 4 files changed, 59 insertions(+), 1 deletion(-)gdbstub.c +37
-1@@ -32,7 +32,6 @@#include "monitor/monitor.h" #include "char/char.h" #include "sysemu/sysemu.h" -#include "exec/gdbstub.h" #endif #define MAX_PACKET_LENGTH 4096@@ -41,6 +40,13 @@#include "qemu/sockets.h" #include "sysemu/kvm.h" #include "qemu/bitops.h" +#include "exec/gdbstub.h" + +#ifdef CONFIG_USER_ONLY +static bool gdb_attached;/* false */ +#else +static bool gdb_attached = true; +#endif #ifndef TARGET_CPU_MEMORY_RW_DEBUG static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,@@ -2491,6 +2497,10 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) break; }#endif +if (strncmp (p,"Attached" ,8 ) ==0 ) { +put_packet (s, gdb_attached ?"1" :"0" ); +break ; + }/* Unrecognised 'q' command. */ goto unknown_command;@@ -3055,3 +3065,29 @@ int gdbserver_start(const char *device) return 0; }#endif + +static QemuOptsList qemu_gdb_opts = { + .name ="gdb" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_gdb_opts.head), + .desc = { + { + .name ="attached" , + .type =QEMU_OPT_BOOL , + }, + {/* end of list */ } + }, +}; + +void gdb_set_opts (const char *opts_str) +{ +QemuOpts *opts; + + opts =qemu_opts_parse (&qemu_gdb_opts, opts_str,0 ); +if (!opts) { +exit (1 ); + } + + gdb_attached =qemu_opt_get_bool (opts,"attached" , gdb_attached); + +qemu_opts_del (opts); +}include/exec/gdbstub.h +2
-0@@ -50,4 +50,6 @@ int gdbserver_start(const char *port);/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */ extern const char *const xml_builtin[][2 ]; +void gdb_set_opts (const char *opts_str); +#endif qemu-options.hx +17
-0@@ -2505,6 +2505,23 @@ within gdb and establish the connection via a pipe: @end example ETEXI +DEF("gdb-opts", HAS_ARG, QEMU_OPTION_gdb_opts, \ + "-gdb-opts attached=on|off\n"\ + " options for the gdb remote server\n", QEMU_ARCH_ALL) +STEXI +@item -gdb-opts @var{dev} +@findex -gdb-opts +Set options for the gdb remote server: +@table @option +@item attached=on|off: + +When 'on' (default), gdb sends a 'detach' command at the end of debugging +session, otherwise gdb sends a 'kill' command. + +@end table + +ETEXI + DEF("s", 0, QEMU_OPTION_s, \ "-s shorthand for -gdb tcp::" DEFAULT_GDBSTUB_PORT "\n", QEMU_ARCH_ALL)vl.c +3
-0@@ -3251,6 +3251,9 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_gdb:add_device_config (DEV_GDB , optarg);break ; +case QEMU_OPTION_gdb_opts: +gdb_set_opts (optarg); +break ;case QEMU_OPTION_L : data_dir = optarg;break ;
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
PATCH 2/2 Revert "gdbstub: Do not kill target in system emulation mode"
In reply to Fabien ChouteauThe requirements described in this patch are implemented by "Add GDB qAttached support".
This reverts commit 00e94dbc7fd0110b0555d59592b004333adfb4b8.
--- gdbstub.c | 2 -- 1 file changed, 2 deletions(-)
gdbstub.c +0 -2
@@ -2185,11 +2185,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) goto unknown_command; }case 'k' : -#ifdef CONFIG_USER_ONLY /* Kill the target */ fprintf (stderr,"\nQEMU: Terminated via GDBstub\n" );exit (0 ); -#endif case 'D' :/* Detach packet */ gdb_breakpoint_remove_all ();
Signature · 1 line
1.7.9.5