Skip to contentSkip to conversation

Add GDB qAttached support

PATCH In review Fabien Chouteau 5 participants 15 messages Mar 12, 2013 – May 1, 2013

lore
Share & tools
lore
#0 lore raw

v3 cover Add GDB qAttached support

v3:
- split 'Add GDB qAttached support' and 'New option -gdb-opts'

Fabien Chouteau (3):
Add GDB qAttached support
Revert "gdbstub: Do not kill target in system emulation mode" New option -gdb-opts

 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
#1 lore raw

PATCH v3 1/3 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.

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 |   10 ++++++++++
 1 file changed, 10 insertions(+)
gdbstub.c +10 -0
index e414ad9..70d54ce 100644
@@ -42,6 +42,12 @@
 #include "sysemu/kvm.h"
 #include "qemu/bitops.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,
                                          uint8_t *buf, int len, int is_write)
@@ -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;
 
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v4 1/1 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.

Based on original version by Fabien Chouteau.

---

As Fabien dropped his attempt to make this configurable, let's preserve the value of exposing this feature to gdb statically.

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +10 -0
index e414ad9..9daee86 100644
@@ -42,6 +42,12 @@
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
 
+#ifdef CONFIG_USER_ONLY
+#define GDB_ATTACHED "0"
+#else
+#define GDB_ATTACHED "1"
+#endif
+
 #ifndef TARGET_CPU_MEMORY_RW_DEBUG
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
                                          uint8_t *buf, int len, int is_write)
@@ -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);
+            break;
+        }
         /* Unrecognised 'q' command.  */
         goto unknown_command;
 
Signature · 1 line
1.7.3.4
Reviewed-by on v4 1/1
#3 lore raw
Quoted 23 lines · Jan Kiszka

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.

Based on original version by Fabien Chouteau.

---

As Fabien dropped his attempt to make this configurable, let's preserve the value of exposing this feature to gdb statically.

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +0 -0
index e414ad9..9daee86 100644

gdbstub.c line 50

Quoted 9 lines
gdbstub.c +6 -0
@@ -42,6 +42,12 @@
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
 
+#ifdef CONFIG_USER_ONLY
+#define GDB_ATTACHED "0"
+#else
+#define GDB_ATTACHED "1"
+#endif
+

Yes, I like the #define better.

Quoted 4 lines
gdbstub.c +0 -0
 #ifndef TARGET_CPU_MEMORY_RW_DEBUG
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
                                          uint8_t *buf, int len, int is_write)

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

Quoted 10 lines
gdbstub.c +4 -0
@@ -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);
+            break;
+        }
         /* Unrecognised 'q' command.  */
         goto unknown_command;
 

Jesse Larrew
Software Engineer, KVM Team
IBM Linux Technology Center
Phone: (512) 973-2052 (T/L: 363-2052)
[email protected]

#4 lore raw
Quoted 27 lines · Jesse Larrew
Quoted 26 lines · Jan Kiszka

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.

Based on original version by Fabien Chouteau.

---

As Fabien dropped his attempt to make this configurable, let's preserve the value of exposing this feature to gdb statically.

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +0 -0
index e414ad9..9daee86 100644
@@ -42,6 +42,12 @@
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
 
Quoted 8 lines

gdbstub.c line 50

Quoted 6 lines
gdbstub.c +6 -0
+#ifdef CONFIG_USER_ONLY
+#define GDB_ATTACHED "0"
+#else
+#define GDB_ATTACHED "1"
+#endif
+

Yes, I like the #define better.

Right, since we drop reconfigurability, this is more appropriate.

Signature · 1 line
Fabien Chouteau
#5 lore raw
Quoted 37 lines · Fabien Chouteau
Quoted 27 lines · Jesse Larrew
Quoted 26 lines · Jan Kiszka

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.

Based on original version by Fabien Chouteau.

---

As Fabien dropped his attempt to make this configurable, let's preserve the value of exposing this feature to gdb statically.

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +0 -0
index e414ad9..9daee86 100644
@@ -42,6 +42,12 @@
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
 
Quoted 8 lines

gdbstub.c line 50

Quoted 6 lines
gdbstub.c +6 -0
+#ifdef CONFIG_USER_ONLY
+#define GDB_ATTACHED "0"
+#else
+#define GDB_ATTACHED "1"
+#endif
+

Yes, I like the #define better.

Quoted 3 lines

Right, since we drop reconfigurability, this is more appropriate.

Looks like we have a consensus. Anthony can you please apply this patch and the revert (patch 2/3)?

Thanks in advance,

Signature · 1 line
Fabien Chouteau
#6 lore raw
In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka

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.

Based on original version by Fabien Chouteau.

Ping for this and the revert of "gdbstub: Do not kill target in system emulation mode".

Jan

Quoted 38 lines

---

As Fabien dropped his attempt to make this configurable, let's preserve the value of exposing this feature to gdb statically.

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +10 -0
index e414ad9..9daee86 100644
@@ -42,6 +42,12 @@
 #include "sysemu/kvm.h"
 #include "qemu/bitops.h"
 
+#ifdef CONFIG_USER_ONLY
+#define GDB_ATTACHED "0"
+#else
+#define GDB_ATTACHED "1"
+#endif
+
 #ifndef TARGET_CPU_MEMORY_RW_DEBUG
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
                                          uint8_t *buf, int len, int is_write)
@@ -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);
+            break;
+        }
         /* Unrecognised 'q' command.  */
         goto unknown_command;
 
#7 lore raw

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

In reply to Fabien Chouteau

The 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
index 70d54ce..0e94311 100644
@@ -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
Reviewed-by on v3 2/3
#8 lore raw

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

Quoted 17 lines · Fabien Chouteau

The 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 -0
index 70d54ce..0e94311 100644
@@ -2185,11 +2185,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
             goto unknown_command;

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

Quoted 10 lines
gdbstub.c +0 -2
         }
     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();

Provided that v4 of "Add GDB qAttached support" is applied prior to this.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
#9 lore raw

PATCH v3 3/3 New option -gdb-opts

In reply to Fabien Chouteau

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".

---
 gdbstub.c              |   28 +++++++++++++++++++++++++++-
 include/exec/gdbstub.h |    2 ++
 qemu-options.hx        |   17 +++++++++++++++++
 vl.c                   |    3 +++
 4 files changed, 49 insertions(+), 1 deletion(-)
gdbstub.c +27 -1
index 0e94311..ee57124 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,7 @@
 #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 */
@@ -3063,3 +3063,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
index ba20afa..86fc18b 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_opts(const char *opts_str);
+
 #endif
qemu-options.hx +17 -0
index cd76f2a..49a480f 100644
@@ -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
index 154f7ba..cce96b6 100644
@@ -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
#10 lore raw

Re: [Qemu-devel] [PATCH V3 3/3] New option -gdb-opts

Quoted 8 lines · Fabien Chouteau

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".

--gdb-opts complements existing --gdb. You need to use both for full control.

I figure you do this because you can't extend --gdb, as its argument is in legacy character device syntax, not QemuOpts.

We had similar cases before, and solved them differently: create a more general option, then make the old one sugar for the new one.

For instance, --monitor and --qmp are sugar for --mon. Desugaring code is in monitor_parse().

#11 lore raw

Re: [Qemu-devel] [PATCH V3 3/3] New option -gdb-opts

Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Fabien Chouteau

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".

Quoted 8 lines
Quoted 1 line

--gdb-opts complements existing --gdb. You need to use both for full control.

I figure you do this because you can't extend --gdb, as its argument is in legacy character device syntax, not QemuOpts.

That's right, maybe we can do some string manipulations to handle this case.

-gdb tcp::1234,attached=off

find ',attached={on|off}' and remove it from the string.

Quoted 6 lines

We had similar cases before, and solved them differently: create a more general option, then make the old one sugar for the new one.

For instance, --monitor and --qmp are sugar for --mon. Desugaring code is in monitor_parse().

Something like:

-chardev socket,id=gdb1,host=localhost,port=1234,server,nowait,nodelay -gdb-remote chardev=gdb1,attached=off

You still need two options for full control.

Regards,

Signature · 1 line
Fabien Chouteau
#12 lore raw

Re: [Qemu-devel] [PATCH V3 3/3] New option -gdb-opts

Quoted 19 lines · Fabien Chouteau
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Fabien Chouteau

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".

Quoted 8 lines
Quoted 1 line

--gdb-opts complements existing --gdb. You need to use both for full control.

I figure you do this because you can't extend --gdb, as its argument is in legacy character device syntax, not QemuOpts.

Quoted 5 lines

That's right, maybe we can do some string manipulations to handle this case.

-gdb tcp::1234,attached=off

find ',attached={on|off}' and remove it from the string.

That way is madness :)

Quoted 12 lines
Quoted 6 lines

We had similar cases before, and solved them differently: create a more general option, then make the old one sugar for the new one.

For instance, --monitor and --qmp are sugar for --mon. Desugaring code is in monitor_parse().

Something like:

(quoted diff) +0 -2
-chardev socket,id=gdb1,host=localhost,port=1234,server,nowait,nodelay
-gdb-remote chardev=gdb1,attached=off
Quoted 1 line

You still need two options for full control.

Yes, but following precedence is good. Our command line is inconsistent enough as it is. Just my two cents.

#13 lore raw

Re: [Qemu-devel] [PATCH V3 3/3] New option -gdb-opts

Quoted 21 lines · Markus Armbruster
Quoted 19 lines · Fabien Chouteau
Quoted 17 lines · Markus Armbruster
Quoted 8 lines · Fabien Chouteau

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".

--gdb-opts complements existing --gdb. You need to use both for full control.

I figure you do this because you can't extend --gdb, as its argument is in legacy character device syntax, not QemuOpts.

Quoted 7 lines
Quoted 5 lines

That's right, maybe we can do some string manipulations to handle this case.

-gdb tcp::1234,attached=off

find ',attached={on|off}' and remove it from the string.

That way is madness :)

Come on, you've seen worse ;)

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

We had similar cases before, and solved them differently: create a more general option, then make the old one sugar for the new one.

For instance, --monitor and --qmp are sugar for --mon. Desugaring code is in monitor_parse().

Something like:

Quoted 8 lines
Quoted 4 lines
(quoted diff) +0 -2
-chardev socket,id=gdb1,host=localhost,port=1234,server,nowait,nodelay
-gdb-remote chardev=gdb1,attached=off

You still need two options for full control.

Yes, but following precedence is good. Our command line is inconsistent enough as it is. Just my two cents.

Fair enough, lets forget about the option this is too much work. I'll just tweak the sources on our branch.

Regards,

Signature · 1 line
Fabien Chouteau
#14 lore raw

Re: [Qemu-devel] [PATCH V3 3/3] New option -gdb-opts

Quoted 24 lines · Fabien Chouteau
Quoted 23 lines · Markus Armbruster
Quoted 21 lines · Fabien Chouteau
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Fabien Chouteau

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".

Quoted 8 lines
Quoted 1 line

--gdb-opts complements existing --gdb. You need to use both for full control.

I figure you do this because you can't extend --gdb, as its argument is in legacy character device syntax, not QemuOpts.

That's right, maybe we can do some string manipulations to handle this case.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

-gdb tcp::1234,attached=off

find ',attached={on|off}' and remove it from the string.

That way is madness :)

Come on, you've seen worse ;)

Seen? Perpetrated! Stared madness in the eye, decided not to come back for more ;)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

We had similar cases before, and solved them differently: create a more general option, then make the old one sugar for the new one.

For instance, --monitor and --qmp are sugar for --mon. Desugaring code is in monitor_parse().

Something like:

(quoted diff) +0 -2
-chardev socket,id=gdb1,host=localhost,port=1234,server,nowait,nodelay
-gdb-remote chardev=gdb1,attached=off
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

You still need two options for full control.

Yes, but following precedence is good. Our command line is inconsistent enough as it is. Just my two cents.

Fair enough, lets forget about the option this is too much work. I'll just tweak the sources on our branch.

Pity.