|
From: <sv...@va...> - 2014-08-10 09:53:39
|
Author: florian
Date: Sun Aug 10 09:53:30 2014
New Revision: 14255
Log:
Change VG_(get_filename) to return the filename in a dynamically
allocated buffer that will be overwritten in the next allocation.
Fix callsite.
Modified:
branches/BUF_REMOVAL/coregrind/m_addrinfo.c
branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c
branches/BUF_REMOVAL/include/pub_tool_debuginfo.h
Modified: branches/BUF_REMOVAL/coregrind/m_addrinfo.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_addrinfo.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_addrinfo.c Sun Aug 10 09:53:30 2014
@@ -282,10 +282,9 @@
tnr_else_tid (ai->Addr.Stack.tinfo),
xpost );
if (ai->Addr.Stack.frameNo != -1 && ai->Addr.Stack.IP != 0) {
-#define FLEN 256
HChar *fn;
Bool hasfn;
- HChar file[FLEN];
+ HChar *file;
Bool hasfile;
UInt linenum;
Bool haslinenum;
@@ -298,24 +297,21 @@
else
haslinenum = False;
- hasfile = VG_(get_filename)(ai->Addr.Stack.IP, file, FLEN);
- if (hasfile && haslinenum) {
- HChar strlinenum[10];
- VG_(snprintf) (strlinenum, 10, ":%d", linenum);
- VG_(strncat) (file, strlinenum,
- FLEN - VG_(strlen)(file) - 1);
- }
+ hasfile = VG_(get_filename)(ai->Addr.Stack.IP, &file);
+
+ HChar strlinenum[32] = ""; // large enough
+ if (hasfile && haslinenum)
+ VG_(sprintf)(strlinenum, ":%d", linenum);
hasfn = VG_(get_fnname)(ai->Addr.Stack.IP, &fn);
if (hasfn || hasfile)
- VG_(emit)( "%sin frame #%d, created by %s (%s)%s\n",
+ VG_(emit)( "%sin frame #%d, created by %s (%s%s)%s\n",
xpre,
ai->Addr.Stack.frameNo,
hasfn ? fn : "???",
- hasfile ? file : "???",
+ hasfile ? file : "???", strlinenum,
xpost );
-#undef FLEN
}
break;
Modified: branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c Sun Aug 10 09:53:30 2014
@@ -1900,8 +1900,11 @@
return NULL;
}
-/* Map a code address to a filename. Returns True if successful. */
-Bool VG_(get_filename)( Addr a, HChar* filename, Int n_filename )
+/* Map a code address to a filename. Returns True if successful. In that
+ case *filename points to a dynamically allocated buffer that holds the
+ nul-terminated filename. Note, that this buffer will be overwritten in
+ the next invocation, so callers need to copy the string if so needed. */
+Bool VG_(get_filename)( Addr a, HChar** filename )
{
DebugInfo* si;
Word locno;
@@ -1909,14 +1912,26 @@
FnDn* fndn;
search_all_loctabs ( a, &si, &locno );
- if (si == NULL)
+ if (si == NULL) {
+ *filename = NULL;
return False;
+ }
fndn_ix = ML_(fndn_ix) (si, locno);
if (fndn_ix == 0)
- VG_(strncpy_safely)(filename, "???", n_filename);
+ *filename = (HChar *)"???"; // FIXME: constification
else {
+ static SizeT bufsiz = 0;
+ static HChar *buf = NULL;
+ SizeT need;
fndn = VG_(indexEltNumber) (si->fndnpool, fndn_ix);
- VG_(strncpy_safely)(filename, fndn->filename, n_filename);
+ need = VG_(strlen)(fndn->filename) + 1;
+ if (need < 256) need = 256;
+ if (need > bufsiz) {
+ bufsiz = need;
+ buf = ML_(dinfo_realloc)("get_filename", buf, bufsiz);
+ }
+ VG_(strcpy)(buf, fndn->filename);
+ *filename = buf;
}
return True;
}
Modified: branches/BUF_REMOVAL/include/pub_tool_debuginfo.h
==============================================================================
--- branches/BUF_REMOVAL/include/pub_tool_debuginfo.h (original)
+++ branches/BUF_REMOVAL/include/pub_tool_debuginfo.h Sun Aug 10 09:53:30 2014
@@ -43,7 +43,7 @@
returns False. VG_(get_fnname) always
demangles C++ function names. VG_(get_fnname_w_offset) is the
same, except it appends "+N" to symbol names to indicate offsets. */
-extern Bool VG_(get_filename) ( Addr a, HChar* filename, Int n_filename );
+extern Bool VG_(get_filename) ( Addr a, HChar** filename );
extern Bool VG_(get_fnname) ( Addr a, HChar** fnname );
extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
extern Bool VG_(get_fnname_w_offset)
|