Skip to contentSkip to conversation

Add GDB qAttached support

PATCH Superseded Jan Kiszka 3 participants 8 messages Jul 17, 2013 – Mar 12, 2014

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

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.

Based on original version by Fabien Chouteau.

---
 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +10 -0
index 0ee82a9..bc626f5 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)
@@ -2504,6 +2510,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
author
#1 lore raw

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

The requirements described in this patch are implemented by "Add GDB qAttached support".

This reverts commit 00e94dbc7fd0110b0555d59592b004333adfb4b8.

---
 gdbstub.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
gdbstub.c +0 -2
index bc626f5..8c632ab 100644
@@ -2198,11 +2198,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.3.4
author
#2 lore raw

PATCH v2 1/2 Add GDB qAttached support

In reply to 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.

---

v2: Rebase over master

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +10 -0
index 35ca7c2..4a6cc51 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
+
 static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
                                          uint8_t *buf, int len, bool is_write)
 {
@@ -2489,6 +2495,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
#3 lore raw

Am 26.07.2013 20:26, schrieb Jan Kiszka:

Quoted 1 line

With this patch QEMU handles qAttached request from gdb. When QEMU

"With this patch" is always weird to read in Git history, also a "gdbstub: " prefix would've been nice for consistency.

Quoted 7 lines

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.

If this is based on code by Fabien, shouldn't it carry his Signed-off-by before yours?

Since "GDB stub" is in "Odd Fixes" state, maybe just step up as maintainer and send a pull like for SLIRP? :)

Cheers,
Andreas

Quoted 38 lines

---

v2: Rebase over master

 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +10 -0
index 35ca7c2..4a6cc51 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
+
 static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
                                          uint8_t *buf, int len, bool is_write)
 {
@@ -2489,6 +2495,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 · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#4 lore raw
Quoted 5 lines · Andreas Färber

Am 26.07.2013 20:26, schrieb Jan Kiszka:

Quoted 1 line

With this patch QEMU handles qAttached request from gdb. When QEMU

"With this patch" is always weird to read in Git history, also a "gdbstub: " prefix would've been nice for consistency.

Yes, will rephrase this.

Quoted 11 lines
Quoted 8 lines

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.

If this is based on code by Fabien, shouldn't it carry his Signed-off-by before yours?

Need to check how similar our versions actually are, if I can reuse his signed-off or if I changed it (in that case it's not appropriate to keep the original signed-off - according to my understanding).

Quoted 3 lines

Since "GDB stub" is in "Odd Fixes" state, maybe just step up as maintainer and send a pull like for SLIRP? :)

Oh, I can surely send a pull, but I can't handle another maintainership properly. Slirp already became a stepchild...

Thanks for looking into this.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#5 lore raw
Quoted 10 lines · Jan Kiszka
Quoted 5 lines · Andreas Färber

Am 26.07.2013 20:26, schrieb Jan Kiszka:

Quoted 1 line

Based on original version by Fabien Chouteau.

If this is based on code by Fabien, shouldn't it carry his Signed-off-by before yours?

Need to check how similar our versions actually are, if I can reuse his signed-off or if I changed it (in that case it's not appropriate to keep the original signed-off - according to my understanding).

If there's still some of Fabien's code in there then as I understand it the usual approach is to retain his authorship and Signed-off-by:, and then follow that with "[you: summary of your changes]" and then your signed-off-by. See for instance commit f19e00d77 where I did a fair amount of rework on a patch originally submitted by Alex.

If you have significantly or totally rewritten the code then you can give the patch your own author and signed-off-by, and acknowledge that somebody else found the problem or suggested the general approach for a fix with a Reported-by: or Suggested-by: tag.

Where exactly the line between the two lies is a judgement call.

This is really about making sure we give credit where due (and conversely that we don't silently attribute later changes to an original author who might not agree with them). (The legal audit trail aspect is satisfied even without the original author's signoff provided that original work was under a suitable license; this is for instance how signoffs work for big chunks of other-project code we import like the binutils disassemblers, libvixl, etc.)

thanks
-- PMM

author
#6 lore raw
In reply to Jan Kiszka
Quoted 33 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.

---
 gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gdbstub.c +6 -0
index 0ee82a9..bc626f5 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)

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

Quoted 10 lines
gdbstub.c +4 -0
@@ -2504,6 +2510,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;
 

Peter, could you pick up these two almost trivial long-pending patches? They still apply and are still useful. If you prefer that I repost them, just let me know.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#7 lore raw
Quoted 3 lines · Jan Kiszka

Peter, could you pick up these two almost trivial long-pending patches? They still apply and are still useful. If you prefer that I repost them, just let me know.

I don't really want to apply more patches directly than I absolutely have to, because it basically obliges me to do a full review and functionality test of those patches...

thanks
-- PMM