From: Julian Seward Date: Fri, 20 Aug 2010 18:22:07 +0000 (+0000) Subject: Add a new client request, VALGRIND_MAP_IP_TO_SRCLOC, so that clients X-Git-Tag: svn/VALGRIND_3_6_0~186 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3195fb3d5d6b27d4eb08b802c3f424445166a503;p=thirdparty%2Fvalgrind.git Add a new client request, VALGRIND_MAP_IP_TO_SRCLOC, so that clients can query their own debug info. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11269 --- diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 4716cf48e4..9723403167 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -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. diff --git a/include/valgrind.h b/include/valgrind.h index 0f5b376624..df6868e0ab 100644 --- a/include/valgrind.h +++ b/include/valgrind.h @@ -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