OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: QEMU / GDB long mode workaround
PostPosted: Wed Apr 24, 2019 4:00 pm 
Offline

Joined: Wed Apr 24, 2019 3:20 pm
Posts: 1
This page describes different methods to work around GDB not handling the transition to long mode:
https://wiki.osdev.org/QEMU_and_GDB_in_long_mode

The patch offered there works for latest GDB (8.2.1) with a very slight modification:
Code:
--- gdb/remote.c        2019-04-25 00:49:04.238196076 +0300
+++ gdb/remote.c        2019-04-25 00:49:08.038221311 +0300
@@ -8035,8 +8035,23 @@

   /* Further sanity checks, with knowledge of the architecture.  */
   if (buf_len > 2 * rsa->sizeof_g_packet)
-    error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
-            "bytes): %s"), rsa->sizeof_g_packet, buf_len / 2, rs->buf);
+  {
+    warning (_("Assuming long-mode change. [Remote 'g' packet reply is too long: %s]"), rs->buf);
+    rsa->sizeof_g_packet = buf_len ;
+    for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
+    {
+      if (rsa->regs[i].pnum == -1)
+        continue;
+      if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
+        rsa->regs[i].in_g_packet = 0;
+      else
+        rsa->regs[i].in_g_packet = 1;
+    }
+   
+    // HACKFIX: Make sure at least the lower half of EIP is set correctly, so the proper
+    // breakpoint is recognized (and triggered).
+    rsa->regs[8].offset = 16*8;
+  }

   /* 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

Code:
cd gdb/gdb-8.2.1
patch -p0 < gdb-longmode.patch


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group