public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Disassembly improvements
@ 2013-10-10 13:14 Abid, Hafiz
  2013-10-10 13:34 ` Pedro Alves
  2013-10-11 21:34 ` Doug Evans
  0 siblings, 2 replies; 19+ messages in thread
From: Abid, Hafiz @ 2013-10-10 13:14 UTC (permalink / raw)
  To: Pedro Alves <palves@redhat.com> (palves@redhat.com)
  Cc: gdb-patches, Mirza, Taimoor

[-- Attachment #1: Type: text/plain, Size: 854 bytes --]

Hi Pedro,
I am attaching the patch that was mentioned in the following thread. I resurrected it from our internal repo, did a bit of manual testing and run the regression suite without any problem. It basically reads memory from the target in a buffer in gdb_disassembly and tries to use this buffer in dis_asm_read_memory instead of reading from the target. This saves us on repeated memory read calls. The problem was noted when eclipse was trying to fill its disassembly view.
https://sourceware.org/ml/gdb-patches/2013-10/msg00221.html

Regards,
Abid

2013-10-10  Taimoor Mirza  <taimoor_mirza@mentor.com>

	* disasm.c (DIS_BUF_SIZE): New define.
	(dis_asm_read_memory): Read from the disassembly buffer instead
	of target memory directly.
	(gdb_disassembly): Fill the disassembly buffer with a chunk of
	the memory to disassemble.



[-- Attachment #2: disasm.patch --]
[-- Type: application/octet-stream, Size: 2939 bytes --]

diff --git a/gdb/disasm.c b/gdb/disasm.c
index e643c2d..daedc98 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -42,11 +42,62 @@ struct dis_line_entry
   CORE_ADDR end_pc;
 };
 
+/* Size of the disassembly memory buffer.  */
+#define DIS_BUF_SIZE 1024
+
 /* Like target_read_memory, but slightly different parameters.  */
 static int
 dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
 		     struct disassemble_info *info)
 {
+  /* Assume the disassembler always read memory forwards.  If we
+     failed to read a buffer line in a previous call, assume we're
+     reading close to the end of a mapped page or section, and so it's
+     useless to keep retrying reading that buffer line.  Simply
+     fallback to reading directly from target memory.  */
+  if (info->buffer_length > 0)
+    {
+      while (len)
+	{
+	  if (memaddr >= info->buffer_vma
+	      && memaddr < info->buffer_vma + info->buffer_length)
+	    {
+	      unsigned int offset = (memaddr - info->buffer_vma);
+	      unsigned int l = min (len, info->buffer_length - offset);
+
+	      memcpy (myaddr, info->buffer + offset, l);
+
+	      memaddr += l;
+	      myaddr += l;
+	      len -= l;
+
+	      if (len == 0)
+		return 0;
+	    }
+	  else
+	    {
+	      int rval;
+	      unsigned int len = info->buffer_length;
+
+	      /* Try fetching a new buffer line from the target.  */
+
+	      /* If we fail reading memory halfway, we'll have clobbered
+		 the buffer, so don't trust it anymore, even on fail.  */
+	      info->buffer_length = 0;
+	      rval = target_read_memory (memaddr, info->buffer, len);
+	      if (rval == 0)
+		{
+		  info->buffer_vma = memaddr;
+		  info->buffer_length = len;
+		}
+	      else
+		{
+		  /* Read from target memory directly from now on.  */
+		  break;
+		}
+	    }
+	}
+    }
   return target_read_memory (memaddr, myaddr, len);
 }
 
@@ -415,6 +466,10 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
   struct symtab *symtab = NULL;
   struct linetable_entry *le = NULL;
   int nlines = -1;
+  int buff_size = DIS_BUF_SIZE;
+  int req_size = high - low;
+  int err = 0;
+  gdb_byte *pbuffer = NULL;
 
   /* Assume symtab is valid for whole PC range.  */
   symtab = find_pc_symtab (low);
@@ -425,6 +480,23 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
       le = symtab->linetable->item;
       nlines = symtab->linetable->nitems;
     }
+  if (req_size < buff_size)
+    buff_size = req_size;
+
+  if (req_size > 0)
+    {
+      /* Allocate buffer and read memory region in buffer.  */
+      pbuffer = xmalloc (buff_size);
+      make_cleanup (xfree, pbuffer);
+      err = target_read_memory (low, pbuffer, buff_size);
+      if (err == 0)
+	{
+	  di.buffer = pbuffer;
+	  di.buffer_length = buff_size;
+	  di.buffer_vma = low;
+	}
+    }
+
 
   if (!(flags & DISASSEMBLY_SOURCE) || nlines <= 0
       || symtab == NULL || symtab->linetable == NULL)

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2013-10-25  7:56 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-10 13:14 [patch] Disassembly improvements Abid, Hafiz
2013-10-10 13:34 ` Pedro Alves
2013-10-10 13:57   ` Abid, Hafiz
2013-10-10 14:52     ` Pedro Alves
2013-10-10 15:13       ` Pedro Alves
2013-10-11 16:45         ` Abid, Hafiz
2013-10-11 21:12           ` Pedro Alves
2013-10-11 21:34 ` Doug Evans
2013-10-14  9:37   ` Abid, Hafiz
2013-10-14 14:42   ` Pedro Alves
2013-10-16  1:16     ` Doug Evans
2013-10-16  7:53       ` Yao Qi
2013-10-16 12:08         ` Pedro Alves
2013-10-16 13:23           ` Yao Qi
2013-10-18 10:24           ` Yao Qi
2013-10-18 18:25             ` Pedro Alves
2013-10-19  1:55               ` Yao Qi
2013-10-25  7:56                 ` Doug Evans
2013-10-16 12:02       ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).