Delegate to target_ops->beneath for TARGET_OBJECT_RAW_MEMORY
authorYao Qi <yao@codesourcery.com>
Wed, 27 Nov 2013 10:01:05 +0000 (18:01 +0800)
committerYao Qi <yao@codesourcery.com>
Fri, 29 Nov 2013 13:32:03 +0000 (21:32 +0800)
GDB on x86_64-linux is unable to disassemble on core-file target.

$ ./gdb ./testsuite/gdb.base/corefile
(gdb) core-file ./testsuite/gdb.base/corefile.core
(gdb) disassemble main
Dump of assembler code for function main:
   0x0000000000400976 <+0>: Cannot access memory at address 0x400976

However, it works if we turn code-cache off.

(gdb) set code-cache off
(gdb) disassemble main,+4
Dump of assembler code from 0x400976 to 0x40097a:
   0x0000000000400976 <main+0>: push   %rbp
   0x0000000000400977 <main+1>: mov    %rsp,%rbp
End of assembler dump.

When code-cache is off, GDB will iterate target_ops from top to bottom
and call to_xfer_partial.  When current_target is "core", it will call
to_xfer_partial of target "exec", which reads the contents for
disassemble.  However, dcache uses TARGET_OBJECT_RAW_MEMORY to read,
but target_xfer_partial doesn't delegate requests to beneath for
TARGET_OBJECT_RAW_MEMORY.

This patch factors out the iteration from top to bottom to a new
function, raw_memory_xfer_partial, and use it for
TARGET_OBJECT_RAW_MEMORY.

Regression tested on x86_64-linux.

gdb:

2013-11-29  Yao Qi  <yao@codesourcery.com>
    Pedro Alves  <palves@redhat.com>

* dcache.c (dcache_read_line): Use current_target.beneath
instead of &current_target.
* target.c (memory_xfer_partial_1): Factor code out to ...
(raw_memory_xfer_partial): ... it.  New function.
(target_xfer_partial): Call raw_memory_xfer_partial if OBJECT
is TARGET_OBJECT_RAW_MEMORY.

gdb/ChangeLog
gdb/dcache.c
gdb/target.c

index 6eef295cbdd1df0dab8266dcbde5dea7e1fd5b50..e86f5c3397d92046bdf28fe93524dc0b6a6fe452 100644 (file)
@@ -1,3 +1,13 @@
+2013-11-29  Yao Qi  <yao@codesourcery.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * dcache.c (dcache_read_line): Use current_target.beneath
+       instead of &current_target.
+       * target.c (memory_xfer_partial_1): Factor code out to ...
+       (raw_memory_xfer_partial): ... it.  New function.
+       (target_xfer_partial): Call raw_memory_xfer_partial if OBJECT
+       is TARGET_OBJECT_RAW_MEMORY.
+
 2013-11-28  Doug Evans  <xdje42@gmail.com>
 
        * breakpoint.h (gdbpy_breakpoint_object): Renamed from
index ea2b73230cadbc946a370e9eb769eb56982624be..12d1a4b9c2478b68a3ce62b1e422c0d91ad7f25c 100644 (file)
@@ -336,8 +336,8 @@ dcache_read_line (DCACHE *dcache, struct dcache_block *db)
          len     -= reg_len;
          continue;
        }
-      
-      res = target_read (&current_target, TARGET_OBJECT_RAW_MEMORY,
+
+      res = target_read (current_target.beneath, TARGET_OBJECT_RAW_MEMORY,
                         NULL, myaddr, memaddr, reg_len);
       if (res < reg_len)
        return 0;
index cc6194b3ba7b182a3499076b3d61d6a9c01e34f8..6c72e702a39227192fa5ed8be0a94d9a5602448d 100644 (file)
@@ -1398,6 +1398,35 @@ memory_xfer_live_readonly_partial (struct target_ops *ops,
   return 0;
 }
 
+/* Read memory from more than one valid target.  A core file, for
+   instance, could have some of memory but delegate other bits to
+   the target below it.  So, we must manually try all targets.  */
+
+static LONGEST
+raw_memory_xfer_partial (struct target_ops *ops, void *readbuf,
+                        const void *writebuf, ULONGEST memaddr, LONGEST len)
+{
+  LONGEST res;
+
+  do
+    {
+      res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
+                                 readbuf, writebuf, memaddr, len);
+      if (res > 0)
+       break;
+
+      /* We want to continue past core files to executables, but not
+        past a running target's memory.  */
+      if (ops->to_has_all_memory (ops))
+       break;
+
+      ops = ops->beneath;
+    }
+  while (ops != NULL);
+
+  return res;
+}
+
 /* Perform a partial memory transfer.
    For docs see target.h, to_xfer_partial.  */
 
@@ -1571,26 +1600,8 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
      to_xfer_partial is enough; if it doesn't recognize an object
      it will call the to_xfer_partial of the next target down.
      But for memory this won't do.  Memory is the only target
-     object which can be read from more than one valid target.
-     A core file, for instance, could have some of memory but
-     delegate other bits to the target below it.  So, we must
-     manually try all targets.  */
-
-  do
-    {
-      res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
-                                 readbuf, writebuf, memaddr, reg_len);
-      if (res > 0)
-       break;
-
-      /* We want to continue past core files to executables, but not
-        past a running target's memory.  */
-      if (ops->to_has_all_memory (ops))
-       break;
-
-      ops = ops->beneath;
-    }
-  while (ops != NULL);
+     object which can be read from more than one valid target.  */
+  res = raw_memory_xfer_partial (ops, readbuf, writebuf, memaddr, reg_len);
 
   /* Make sure the cache gets updated no matter what - if we are writing
      to the stack.  Even if this write is not tagged as such, we still need
@@ -1702,18 +1713,14 @@ target_xfer_partial (struct target_ops *ops,
       || object == TARGET_OBJECT_CODE_MEMORY)
     retval = memory_xfer_partial (ops, object, readbuf,
                                  writebuf, offset, len);
-  else
+  else if (object == TARGET_OBJECT_RAW_MEMORY)
     {
-      enum target_object raw_object = object;
-
-      /* If this is a raw memory transfer, request the normal
-        memory object from other layers.  */
-      if (raw_object == TARGET_OBJECT_RAW_MEMORY)
-       raw_object = TARGET_OBJECT_MEMORY;
-
-      retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf,
-                                    writebuf, offset, len);
+      /* Request the normal memory object from other layers.  */
+      retval = raw_memory_xfer_partial (ops, readbuf, writebuf, offset, len);
     }
+  else
+    retval = ops->to_xfer_partial (ops, object, annex, readbuf,
+                                  writebuf, offset, len);
 
   if (targetdebug)
     {
This page took 0.036069 seconds and 4 git commands to generate.