This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Remotely attached GDB to QEMU panics on x86-64 arch

The problem comes when trying to remotely attach GDB to QEMU on i386:x86-64
architecture. On remote initialization GDB requests a 'g' packet. At this
point QEMU has not started the CPU yet , so it is still not in x86-64 mode.
It sends 'g' response with 32 bit registers. GDB sees that the response is
smaller than registered in records (rsa->sizeof_g_packet), so it
updates them accordingly.
After QEMU starts the CPU, it eventually changes the architecture to x86-64
and the next 'g' packet panics GDB with error:
    Remote 'g' packet reply is too long: <printed buffer>
This patch is the workaround I am using. It lets GDB to change records
both ways - up and down, instead of down only.
I am not sure why there is such restriction, but if the solution is
not acceptable,
let me know the correct way of fixing it.

How to reproduce (on Linux kernel):
  qemu-system-x86_64 -hda /dev/zero -kernel bzImage -s -S
  (gdb) file vmlinux
  (gdb) target remote localhost:1234
  (gdb) set architecture i386:x86-64:intel
  (gdb) break kernel_init
  (gdb) c
Remote 'g' packet reply is too long:

2012-03-03    Arvydas Sidorenko    <>

    * gdb/remote.c (process_g_packet):
        Allow change 'g' packet record both ways - up and down,
        instead of down only.

--- a/gdb/remote.c	2012-03-03 18:12:34.745832996 +0100
+++ b/gdb/remote.c	2012-03-03 18:12:28.144833161 +0100
@@ -5820,21 +5820,21 @@ process_g_packet (struct regcache *regca

   buf_len = strlen (rs->buf);

-  /* Further sanity checks, with knowledge of the architecture.  */
-  if (buf_len > 2 * rsa->sizeof_g_packet)
+  /* Further sanity checks */
+  if (buf_len > MAX_REMOTE_PACKET_SIZE)
     error (_("Remote 'g' packet reply is too long: %s"), rs->buf);

   /* Save the size of the packet sent to us by the target.  It is used
      as a heuristic when determining the max size of packets that the
      target can safely receive.  */
-  if (rsa->actual_register_packet_size == 0)
+  if (rsa->actual_register_packet_size != buf_len)
     rsa->actual_register_packet_size = buf_len;

-  /* If this is smaller than we guessed the 'g' packet would be,
+  /* If this is not equal to what we guessed the 'g' packet would be,
      update our records.  A 'g' reply that doesn't include a register's
      value implies either that the register is not available, or that
      the 'p' packet must be used.  */
-  if (buf_len < 2 * rsa->sizeof_g_packet)
+  if (buf_len != 2 * rsa->sizeof_g_packet)
       rsa->sizeof_g_packet = buf_len / 2;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]