Patchwork [v4] Add GDB qAttached support

login
register
mail settings
Submitter Jan Kiszka
Date March 14, 2013, 7:51 p.m.
Message ID <51422A3D.7000308@siemens.com>
Download mbox | patch
Permalink /patch/227791/
State New
Headers show

Comments

Jan Kiszka - March 14, 2013, 7:51 p.m.
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.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

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(-)
Jesse Larrew - March 14, 2013, 9:07 p.m.
On 03/14/2013 02:51 PM, Jan Kiszka wrote:
> 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.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
> 
> 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(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index e414ad9..9daee86 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -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.

>  #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;
> 

Reviewed-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com>

Jesse Larrew
Software Engineer, KVM Team
IBM Linux Technology Center
Phone: (512) 973-2052 (T/L: 363-2052)
jlarrew@linux.vnet.ibm.com
Fabien Chouteau - March 15, 2013, 12:02 p.m.
On 03/14/2013 10:07 PM, Jesse Larrew wrote:
> On 03/14/2013 02:51 PM, Jan Kiszka wrote:
>> 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.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>
>> 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(-)
>>
>> diff --git a/gdbstub.c b/gdbstub.c
>> index e414ad9..9daee86 100644
>> --- a/gdbstub.c
>> +++ b/gdbstub.c
>> @@ -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.

Right, since we drop reconfigurability, this is more appropriate.
Fabien Chouteau - March 19, 2013, 10:37 a.m.
On 03/15/2013 01:02 PM, Fabien Chouteau wrote:
> On 03/14/2013 10:07 PM, Jesse Larrew wrote:
>> On 03/14/2013 02:51 PM, Jan Kiszka wrote:
>>> 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.
>>>
>>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>>> ---
>>>
>>> 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(-)
>>>
>>> diff --git a/gdbstub.c b/gdbstub.c
>>> index e414ad9..9daee86 100644
>>> --- a/gdbstub.c
>>> +++ b/gdbstub.c
>>> @@ -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.
> 
> 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,
Jan Kiszka - May 1, 2013, 2:18 p.m.
On 2013-03-14 20:51, Jan Kiszka wrote:
> 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

> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
> 
> 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(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index e414ad9..9daee86 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -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;
>  
>

Patch

diff --git a/gdbstub.c b/gdbstub.c
index e414ad9..9daee86 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -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;