Skip to contentSkip to conversation

Add GDB qAttached support

PATCH In review Fabien Chouteau 3 participants 8 messages Mar 5, 2013 – Mar 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add GDB qAttached support

With this patch GDB will issue a "detach" command at the end of a debugging session instead of a "kill". This behavior can be inverted with the new option -gdb-not-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              |   13 ++++++++++++-
 include/exec/gdbstub.h |    2 ++
 qemu-options.hx        |    7 +++++++
 vl.c                   |    3 +++
 4 files changed, 24 insertions(+), 1 deletion(-)
gdbstub.c +12 -1
index e414ad9..c0686a9 100644
@@ -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,9 @@
 #include "qemu/sockets.h"
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
+#include "exec/gdbstub.h"
+
+static bool gdb_attached = true;
 
 #ifndef TARGET_CPU_MEMORY_RW_DEBUG
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
@@ -2491,6 +2493,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 +3061,8 @@ int gdbserver_start(const char *device)
     return 0;
 }
 #endif
+
+void gdb_set_attached(bool attached)
+{
+    gdb_attached = attached;
+}
include/exec/gdbstub.h +2 -0
index ba20afa..b2d3b13 100644
@@ -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_attached(bool attached);
+
 #endif
qemu-options.hx +7 -0
index 6f9334a..026d3eb 100644
@@ -2988,6 +2988,13 @@ property must be set.  These objects are placed in the
 '/objects' path.
 ETEXI
 
+DEF("gdb-not-attached", 0, QEMU_OPTION_gdb_not_attached,
+    "-gdb-not-attached\n"
+    "                Do not set Gdb remote server in attached mode.\n"
+    "                When exiting debugging session, Gdb will send a 'kill'\n"
+    "                command instead of a 'detach'.\n",
+    QEMU_ARCH_ALL)
+
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
 @end table
vl.c +3 -0
index c03edf1..ccd7405 100644
@@ -3815,6 +3815,9 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_gdb_not_attached:
+                gdb_set_attached(false);
+                break;
             default:
                 os_parse_cmd_args(popt->index, optarg);
             }
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/2 Revert "gdbstub: Do not kill target in system emulation mode"

This reverts commit 00e94dbc7fd0110b0555d59592b004333adfb4b8.

---
 gdbstub.c |    2 --
 1 file changed, 2 deletions(-)
gdbstub.c +0 -2
index c0686a9..22078df 100644
@@ -2181,11 +2181,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
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] Revert "gdbstub: Do not kill target in system emulation mode"

Quoted 1 line · Fabien Chouteau

This reverts commit 00e94dbc7fd0110b0555d59592b004333adfb4b8.

Should also tell us why (by pointing to the other commit e.g.).

Will give this a try ASAP!

Thanks,
Jan

Quoted 23 lines
---
 gdbstub.c |    2 --
 1 file changed, 2 deletions(-)
gdbstub.c +0 -2
index c0686a9..22078df 100644
@@ -2181,11 +2181,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 · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] Revert "gdbstub: Do not kill target in system emulation mode"

Quoted 5 lines · Jan Kiszka
Quoted 1 line · Fabien Chouteau

This reverts commit 00e94dbc7fd0110b0555d59592b004333adfb4b8.

Should also tell us why (by pointing to the other commit e.g.).

Yea, I should have put them together.

Quoted 2 lines

Will give this a try ASAP!

Thanks,

Signature · 1 line
Fabien Chouteau
#4 lore raw
In reply to Fabien Chouteau
Quoted 39 lines · Fabien Chouteau

With this patch GDB will issue a "detach" command at the end of a debugging session instead of a "kill". This behavior can be inverted with the new option -gdb-not-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              |   13 ++++++++++++-
 include/exec/gdbstub.h |    2 ++
 qemu-options.hx        |    7 +++++++
 vl.c                   |    3 +++
 4 files changed, 24 insertions(+), 1 deletion(-)
gdbstub.c +3 -1
index e414ad9..c0686a9 100644
@@ -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,9 @@
 #include "qemu/sockets.h"
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
+#include "exec/gdbstub.h"
+
+static bool gdb_attached = true;
 
 #ifndef TARGET_CPU_MEMORY_RW_DEBUG
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,

gdbstub.c static int gdb_handle_packet(GDBState *s, const char *line_buf) · line 2499

Quoted 7 lines
gdbstub.c +4 -0
@@ -2491,6 +2493,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;
+        }

This works as expected for system mode, but now inverts the behaviour for user mode - that's unexpected and not ok.

Quoted 28 lines
gdbstub.c +5 -0
         /* Unrecognised 'q' command.  */
         goto unknown_command;
 
@@ -3055,3 +3061,8 @@ int gdbserver_start(const char *device)
     return 0;
 }
 #endif
+
+void gdb_set_attached(bool attached)
+{
+    gdb_attached = attached;
+}
include/exec/gdbstub.h +2 -0
index ba20afa..b2d3b13 100644
@@ -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_attached(bool attached);
+
 #endif
qemu-options.hx +0 -0
index 6f9334a..026d3eb 100644

qemu-options.hx property must be set. These objects are placed in the · line 2997

Quoted 10 lines
qemu-options.hx +7 -0
@@ -2988,6 +2988,13 @@ property must be set.  These objects are placed in the
 '/objects' path.
 ETEXI
 
+DEF("gdb-not-attached", 0, QEMU_OPTION_gdb_not_attached,
+    "-gdb-not-attached\n"
+    "                Do not set Gdb remote server in attached mode.\n"
+    "                When exiting debugging session, Gdb will send a 'kill'\n"
+    "                command instead of a 'detach'.\n",
+    QEMU_ARCH_ALL)
+

First of all, why do we need this configurable? In which use cases do you want attached mode for user emulation or kill mode for system emulation/virtualization?

Then, if you can convince us that such a switch is useful, a new top-level command line option is still a no-go. We already have -gdb, so this would have to become an option to it.

In any case, I would suggest to add static attached mode first (enabled for system, disable for user), revert my patch and then, optionally, propose an attached mode control.

Jan

#5 lore raw
Quoted 12 lines · Jan Kiszka

gdbstub.c static int gdb_handle_packet(GDBState *s, const char *line_buf) · line 2499

Quoted 8 lines
gdbstub.c +4 -0
@@ -2491,6 +2493,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;
+        }

This works as expected for system mode, but now inverts the behaviour for user mode - that's unexpected and not ok.

OK, I can change the default value for user mode.

Quoted 8 lines
Quoted 8 lines
qemu-options.hx +0 -0
index 6f9334a..026d3eb 100644
@@ -2988,6 +2988,13 @@ property must be set.  These objects are placed in the
 '/objects' path.
 ETEXI
 
Quoted 12 lines

qemu-options.hx property must be set. These objects are placed in the · line 2997

Quoted 7 lines
qemu-options.hx +7 -0
+DEF("gdb-not-attached", 0, QEMU_OPTION_gdb_not_attached,
+    "-gdb-not-attached\n"
+    "                Do not set Gdb remote server in attached mode.\n"
+    "                When exiting debugging session, Gdb will send a 'kill'\n"
+    "                command instead of a 'detach'.\n",
+    QEMU_ARCH_ALL)
+

First of all, why do we need this configurable? In which use cases do you want attached mode for user emulation or kill mode for system emulation/virtualization?

It's more convenient for us, we expect QEMU to terminate at the end of debugging session because we do not run big systems/kernels but short test programs. It used to be the default behavior of QEMU, and our test-suites, IDE, developers and users are expecting this.

Quoted 4 lines

Then, if you can convince us that such a switch is useful, a new top-level command line option is still a no-go. We already have -gdb, so this would have to become an option to it.

Something like:

-gdb dev[,attached=on|off] wait for gdb connection on 'dev'

This will not fit nicely in the current option because 'dev' is a chardev descriptor. I will have to add 'attached' in the list of chardev opts, which is not correct. Or do some nasty strings manipulation.

Maybe this:

-gdb-opts attached=on|off

We can extend it latter if more options are needed.

Quoted 4 lines

In any case, I would suggest to add static attached mode first (enabled for system, disable for user), revert my patch and then, optionally, propose an attached mode control.

Mode control is not optional for me.

Regards,

Signature · 1 line
Fabien Chouteau
#6 lore raw
Quoted 37 lines · Fabien Chouteau
Quoted 12 lines · Jan Kiszka

gdbstub.c static int gdb_handle_packet(GDBState *s, const char *line_buf) · line 2499

Quoted 8 lines
gdbstub.c +4 -0
@@ -2491,6 +2493,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;
+        }

This works as expected for system mode, but now inverts the behaviour for user mode - that's unexpected and not ok.

OK, I can change the default value for user mode.

Quoted 8 lines
Quoted 8 lines
qemu-options.hx +0 -0
index 6f9334a..026d3eb 100644
@@ -2988,6 +2988,13 @@ property must be set.  These objects are placed in the
 '/objects' path.
 ETEXI
 
Quoted 12 lines

qemu-options.hx property must be set. These objects are placed in the · line 2997

Quoted 7 lines
qemu-options.hx +7 -0
+DEF("gdb-not-attached", 0, QEMU_OPTION_gdb_not_attached,
+    "-gdb-not-attached\n"
+    "                Do not set Gdb remote server in attached mode.\n"
+    "                When exiting debugging session, Gdb will send a 'kill'\n"
+    "                command instead of a 'detach'.\n",
+    QEMU_ARCH_ALL)
+

First of all, why do we need this configurable? In which use cases do you want attached mode for user emulation or kill mode for system emulation/virtualization?

Quoted 4 lines

It's more convenient for us, we expect QEMU to terminate at the end of debugging session because we do not run big systems/kernels but short test programs. It used to be the default behavior of QEMU, and our test-suites, IDE, developers and users are expecting this.

And it's not possible to replace 'q' with 'k' in your gdb control scripts? That gives you a well-defined behaviour, and we don't need to tweak QEMU, specifically its command line, for this special case.

Jan

#7 lore raw
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Fabien Chouteau
Quoted 20 lines · Jan Kiszka
Quoted 5 lines
qemu-options.hx +0 -0
index 6f9334a..026d3eb 100644

qemu-options.hx property must be set. These objects are placed in the · line 2997

Quoted 10 lines
qemu-options.hx +7 -0
@@ -2988,6 +2988,13 @@ property must be set.  These objects are placed in the
 '/objects' path.
 ETEXI
 
+DEF("gdb-not-attached", 0, QEMU_OPTION_gdb_not_attached,
+    "-gdb-not-attached\n"
+    "                Do not set Gdb remote server in attached mode.\n"
+    "                When exiting debugging session, Gdb will send a 'kill'\n"
+    "                command instead of a 'detach'.\n",
+    QEMU_ARCH_ALL)
+

First of all, why do we need this configurable? In which use cases do you want attached mode for user emulation or kill mode for system emulation/virtualization?

Quoted 7 lines
Quoted 4 lines

It's more convenient for us, we expect QEMU to terminate at the end of debugging session because we do not run big systems/kernels but short test programs. It used to be the default behavior of QEMU, and our test-suites, IDE, developers and users are expecting this.

And it's not possible to replace 'q' with 'k' in your gdb control scripts?

It's not just in a script or two, as I said it's test-suites, IDE, developers and users.

Quoted 3 lines

That gives you a well-defined behaviour, and we don't need to tweak QEMU, specifically its command line, for this special case.

I don't understand the issue with this new option.

Regards,

Signature · 1 line
Fabien Chouteau