]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a new client request, VALGRIND_MAP_IP_TO_SRCLOC, so that clients
authorJulian Seward <jseward@acm.org>
Fri, 20 Aug 2010 18:22:07 +0000 (18:22 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 20 Aug 2010 18:22:07 +0000 (18:22 +0000)
can query their own debug info.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11269

coregrind/m_scheduler/scheduler.c
include/valgrind.h

index 4716cf48e40ab65718cd8d1a327a744cca58b3f9..9723403167a2ae0b673d00997d8161d2cb4814f0 100644 (file)
@@ -1546,6 +1546,35 @@ void do_client_request ( ThreadId tid )
          SET_CLREQ_RETVAL( tid, 0 );     /* return value is meaningless */
          break;
 
+      case VG_USERREQ__MAP_IP_TO_SRCLOC: {
+         Addr   ip    = arg[1];
+         UChar* buf64 = (UChar*)arg[2];
+
+         VG_(memset)(buf64, 0, 64);
+         UInt linenum = 0;
+         Bool ok = VG_(get_filename_linenum)(
+                      ip, &buf64[0], 50, NULL, 0, NULL, &linenum
+                   );
+         if (ok) {
+            /* Find the terminating zero in the first 50 bytes. */
+            UInt i;
+            for (i = 0; i < 50; i++) {
+               if (buf64[i] == 0)
+                  break;
+            }
+            /* We must find a zero somewhere in 0 .. 49.  Else
+               VG_(get_filename_linenum) is not properly zero
+               terminating. */
+            vg_assert(i < 50);
+            VG_(sprintf)(&buf64[i], ":%u", linenum);
+         } else {
+            buf64[0] = 0;
+         }
+
+         SET_CLREQ_RETVAL( tid, 0 ); /* return value is meaningless */
+         break;
+      }
+
       case VG_USERREQ__MALLOCLIKE_BLOCK:
       case VG_USERREQ__FREELIKE_BLOCK:
          // Ignore them if the addr is NULL;  otherwise pass onto the tool.
index 0f5b376624533ac26529d1942ef6df2ffa8f698d..df6868e0ab09c172a5f8f7aef8b2b16b863f586a 100644 (file)
@@ -4159,7 +4159,10 @@ typedef
           VG_USERREQ__STACK_CHANGE     = 0x1503,
 
           /* Wine support */
-          VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601
+          VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,
+
+          /* Querying of debug info. */
+          VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701
    } Vg_ClientRequest;
 
 #if !defined(__GNUC__)
@@ -4524,6 +4527,17 @@ VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
                                fd, ptr, total_size, delta, 0);    \
    }
 
+/* Map a code address to a source file name and line number.  buf64
+   must point to a 64-byte buffer in the caller's address space.  The
+   result will be dumped in there and is guaranteed to be zero
+   terminated.  If no info is found, the first byte is set to zero. */
+#define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64)                    \
+   {unsigned int _qzz_res;                                        \
+    VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
+                               VG_USERREQ__MAP_IP_TO_SRCLOC,      \
+                               addr, buf64, 0, 0, 0);             \
+   }
+
 
 #undef PLAT_x86_linux
 #undef PLAT_amd64_linux