Author: florian
Date: Fri Aug 15 22:01:13 2014
New Revision: 14293
Log:
Change VG_(get_filename_linenum) to return filename and directory
name in static buffers. Fix call sites.
Modified:
branches/BUF_REMOVAL/cachegrind/cg_main.c
branches/BUF_REMOVAL/callgrind/debug.c
branches/BUF_REMOVAL/callgrind/dump.c
branches/BUF_REMOVAL/callgrind/fn.c
branches/BUF_REMOVAL/callgrind/global.h
branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c
branches/BUF_REMOVAL/coregrind/m_scheduler/scheduler.c
branches/BUF_REMOVAL/include/pub_tool_debuginfo.h
Modified: branches/BUF_REMOVAL/cachegrind/cg_main.c
==============================================================================
--- branches/BUF_REMOVAL/cachegrind/cg_main.c (original)
+++ branches/BUF_REMOVAL/cachegrind/cg_main.c Fri Aug 15 22:01:13 2014
@@ -30,14 +30,12 @@
*/
#include "pub_tool_basics.h"
-#include "pub_tool_vki.h"
#include "pub_tool_debuginfo.h"
#include "pub_tool_libcbase.h"
#include "pub_tool_libcassert.h"
#include "pub_tool_libcfile.h"
#include "pub_tool_libcprint.h"
#include "pub_tool_libcproc.h"
-#include "pub_tool_machine.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
#include "pub_tool_oset.h"
@@ -58,7 +56,6 @@
#define DEBUG_CG 0
#define MIN_LINE_SIZE 16
-#define FILE_LEN VKI_PATH_MAX
/*------------------------------------------------------------*/
/*--- Options ---*/
@@ -212,21 +209,20 @@
/*--- CC table operations ---*/
/*------------------------------------------------------------*/
-static void get_debug_info(Addr instr_addr, HChar dir[FILE_LEN],
- HChar file[FILE_LEN],
+static void get_debug_info(Addr instr_addr, HChar **dir,
+ HChar **file,
HChar **fn, UInt* line)
{
Bool found_dirname;
Bool found_file_line = VG_(get_filename_linenum)(
instr_addr,
- file, FILE_LEN,
- dir, FILE_LEN, &found_dirname,
+ file, dir, &found_dirname,
line
);
Bool found_fn = VG_(get_fnname)(instr_addr, fn);
if (!found_file_line) {
- VG_(strcpy)(file, "???");
+ *file = (HChar *)"???"; // FIXME: constification
*line = 0;
}
if (!found_fn) {
@@ -250,12 +246,12 @@
// Returns a pointer to the line CC, creates a new one if necessary.
static LineCC* get_lineCC(Addr origAddr)
{
- HChar file[FILE_LEN], dir[FILE_LEN], *fn;
+ HChar *file, *dir, *fn;
UInt line;
CodeLoc loc;
LineCC* lineCC;
- get_debug_info(origAddr, dir, file, &fn, &line);
+ get_debug_info(origAddr, &dir, &file, &fn, &line);
// Form an absolute pathname if a directory is available
HChar absfile[VG_(strlen)(dir) + 1 + VG_(strlen)(file) + 1];
Modified: branches/BUF_REMOVAL/callgrind/debug.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/debug.c (original)
+++ branches/BUF_REMOVAL/callgrind/debug.c Fri Aug 15 22:01:13 2014
@@ -373,7 +373,7 @@
/* dump out an address with source info if available */
void CLG_(print_addr)(Addr addr)
{
- HChar fl_buf[FILENAME_LEN], dir_buf[FILENAME_LEN];
+ HChar *fl_buf, *dir_buf;
HChar *fn_buf;
const HChar* obj_name;
DebugInfo* di;
@@ -384,7 +384,7 @@
return;
}
- CLG_(get_debug_info)(addr, dir_buf, fl_buf, &fn_buf, &ln, &di);
+ CLG_(get_debug_info)(addr, &dir_buf, &fl_buf, &fn_buf, &ln, &di);
if (VG_(strcmp)(fn_buf,"???")==0)
VG_(printf)("%#lx", addr);
Modified: branches/BUF_REMOVAL/callgrind/dump.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/dump.c (original)
+++ branches/BUF_REMOVAL/callgrind/dump.c Fri Aug 15 22:01:13 2014
@@ -440,8 +440,8 @@
static /* __inline__ */
Bool get_debug_pos(BBCC* bbcc, Addr addr, AddrPos* p)
{
- HChar file[FILENAME_LEN];
- HChar dir[FILENAME_LEN];
+ HChar *file;
+ HChar *dir;
Bool found_file_line, found_dirname;
int cachepos = addr % DEBUG_CACHE_SIZE;
@@ -453,12 +453,12 @@
}
else {
found_file_line = VG_(get_filename_linenum)(addr,
- file, FILENAME_LEN,
- dir, FILENAME_LEN,
+ &file,
+ &dir,
&found_dirname,
&(p->line));
if (!found_file_line) {
- VG_(strcpy)(file, "???");
+ file = (HChar *)"???"; // FIXME: constification
p->line = 0;
}
if (! found_dirname) {
Modified: branches/BUF_REMOVAL/callgrind/fn.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/fn.c (original)
+++ branches/BUF_REMOVAL/callgrind/fn.c Fri Aug 15 22:01:13 2014
@@ -424,8 +424,8 @@
Bool CLG_(get_debug_info)(Addr instr_addr,
- HChar dir[FILENAME_LEN],
- HChar file[FILENAME_LEN],
+ HChar **dir,
+ HChar **file,
HChar **fn_name, UInt* line_num,
DebugInfo** pDebugInfo)
{
@@ -441,8 +441,8 @@
}
found_file_line = VG_(get_filename_linenum)(instr_addr,
- file, FILENAME_LEN,
- dir, FILENAME_LEN,
+ file,
+ dir,
&found_dirname,
&line);
found_fn = VG_(get_fnname)(instr_addr,
@@ -454,7 +454,7 @@
if (!found_file_line && !found_fn) {
CLG_(stat).no_debug_BBs++;
- VG_(strcpy)(file, "???");
+ *file = (HChar *)"???"; // FIXME: constification
*fn_name = (HChar *)"???"; // FIXME: constification
if (line_num) *line_num=0;
result = False;
@@ -470,7 +470,7 @@
} else /*(!found_file_line && found_fn)*/ {
CLG_(stat).fn_name_debug_BBs++;
- VG_(strcpy)(file, "???");
+ *file = (HChar *)"???"; // FIXME: constification
if (line_num) *line_num=0;
}
@@ -493,7 +493,7 @@
*/
fn_node* CLG_(get_fn_node)(BB* bb)
{
- HChar filename[FILENAME_LEN], dirname[FILENAME_LEN], *fnname;
+ HChar *filename, *dirname, *fnname;
DebugInfo* di;
UInt line_num;
fn_node* fn;
@@ -507,7 +507,7 @@
* the BB according to debug information
*/
CLG_(get_debug_info)(bb_addr(bb),
- dirname, filename, &fnname, &line_num, &di);
+ &dirname, &filename, &fnname, &line_num, &di);
if (0 == VG_(strcmp)(fnname, "???")) {
int p;
@@ -538,7 +538,7 @@
if (0 == VG_(strcmp)(fnname, "vgPlain___libc_freeres_wrapper")
&& exit_bb) {
CLG_(get_debug_info)(bb_addr(exit_bb),
- dirname, filename, &fnname, &line_num, &di);
+ &dirname, &filename, &fnname, &line_num, &di);
CLG_DEBUG(1, "__libc_freeres_wrapper renamed to _exit\n");
}
Modified: branches/BUF_REMOVAL/callgrind/global.h
==============================================================================
--- branches/BUF_REMOVAL/callgrind/global.h (original)
+++ branches/BUF_REMOVAL/callgrind/global.h Fri Aug 15 22:01:13 2014
@@ -721,8 +721,8 @@
void CLG_(init_eventsets)(void);
/* from main.c */
-Bool CLG_(get_debug_info)(Addr, HChar dirname[FILENAME_LEN],
- HChar filename[FILENAME_LEN],
+Bool CLG_(get_debug_info)(Addr, HChar **dirname,
+ HChar **filename,
HChar **fn_name, UInt*, DebugInfo**);
void CLG_(collectBlockInfo)(IRSB* bbIn, UInt*, UInt*, Bool*);
void CLG_(set_instrument_state)(const HChar*,Bool);
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 Fri Aug 15 22:01:13 2014
@@ -1953,14 +1953,15 @@
See prototype for detailed description of behaviour.
*/
Bool VG_(get_filename_linenum) ( Addr a,
- /*OUT*/HChar* filename, Int n_filename,
- /*OUT*/HChar* dirname, Int n_dirname,
+ /*OUT*/HChar** filename,
+ /*OUT*/HChar** dirname,
/*OUT*/Bool* dirname_available,
/*OUT*/UInt* lineno )
{
DebugInfo* si;
Word locno;
UInt fndn_ix;
+ const HChar *fname, *dname;
vg_assert( (dirname == NULL && dirname_available == NULL)
||
@@ -1970,24 +1971,35 @@
if (si == NULL) {
if (dirname_available) {
*dirname_available = False;
- *dirname = 0;
+ *dirname[0] = 0;
}
+ // filename used to be an HChar [] and it was not initialised along
+ // this path. Not good.
+ // Nowadays, filename is a HChar ** and we initialise it to NULL here
+ // to find executions along which the filename array was read
+ // uninitialised or (even worse) expected to keep its value past this
+ // function invocation.
+ *filename = NULL;
return False;
}
+ static HChar *fbuf, *dbuf;
+ static SizeT fbuf_siz, dbuf_siz;
+
fndn_ix = ML_(fndn_ix)(si, locno);
- VG_(strncpy_safely)(filename,
- ML_(fndn_ix2filename) (si, fndn_ix),
- n_filename);
+
+ fname = ML_(fndn_ix2filename) (si, fndn_ix);
+ grow_buffer_for_string(&fbuf, &fbuf_siz, fname);
+ *filename = VG_(strcpy)(fbuf, fname);
+
*lineno = si->loctab[locno].lineno;
if (dirname) {
/* caller wants directory info too .. */
- vg_assert(n_dirname > 0);
- VG_(strncpy_safely)(dirname,
- ML_(fndn_ix2dirname) (si, fndn_ix),
- n_dirname);
- *dirname_available = *dirname != 0;
+ dname = ML_(fndn_ix2dirname) (si, fndn_ix);
+ grow_buffer_for_string(&dbuf, &dbuf_siz, dname);
+ *dirname = VG_(strcpy)(dbuf, dname);
+ *dirname_available = *dirname[0] != 0;
}
return True;
@@ -2124,9 +2136,8 @@
static HChar *buf_fn;
static HChar *buf_obj;
- static HChar buf_srcloc[BUF_LEN];
- static HChar buf_dirname[BUF_LEN];
- buf_srcloc[0] = buf_dirname[0] = 0;
+ static HChar *buf_srcloc;
+ static HChar *buf_dirname;
Bool know_dirinfo = False;
Bool know_fnname;
@@ -2161,8 +2172,8 @@
// The source for the highest level is in the loctab entry.
know_srcloc = VG_(get_filename_linenum)(
eip,
- buf_srcloc, BUF_LEN,
- buf_dirname, BUF_LEN, &know_dirinfo,
+ &buf_srcloc,
+ &buf_dirname, &know_dirinfo,
&lineno
);
} else {
@@ -2174,23 +2185,20 @@
know_dirinfo = False;
// The fndn_ix and lineno for the caller of the inlined fn is in cur_inl.
if (cur_inl->fndn_ix == 0) {
- VG_(snprintf) (buf_srcloc, BUF_LEN, "???");
+ buf_srcloc = (HChar *)"???"; // FIXME: constification
} else {
FnDn *fndn = VG_(indexEltNumber) (iipc->di->fndnpool,
cur_inl->fndn_ix);
if (fndn->dirname) {
- VG_(snprintf) (buf_dirname, BUF_LEN, "%s", fndn->dirname);
+ buf_dirname = (HChar *)fndn->dirname; // FIXME: constification
know_dirinfo = True;
}
- VG_(snprintf) (buf_srcloc, BUF_LEN, "%s", fndn->filename);
+ buf_srcloc = (HChar *)fndn->filename; // FIXME: constification
}
lineno = cur_inl->lineno;
know_srcloc = True;
}
- buf_srcloc [ sizeof(buf_srcloc)-1 ] = 0;
- buf_dirname[ sizeof(buf_dirname)-1 ] = 0;
-
if (VG_(clo_xml)) {
Bool human_readable = True;
Modified: branches/BUF_REMOVAL/coregrind/m_scheduler/scheduler.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_scheduler/scheduler.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_scheduler/scheduler.c Fri Aug 15 22:01:13 2014
@@ -1949,24 +1949,29 @@
case VG_USERREQ__MAP_IP_TO_SRCLOC: {
Addr ip = arg[1];
HChar* buf64 = (HChar*)arg[2];
+ HChar* buf; // points to null-terminated string of unknown length
VG_(memset)(buf64, 0, 64);
UInt linenum = 0;
Bool ok = VG_(get_filename_linenum)(
- ip, &buf64[0], 50, NULL, 0, NULL, &linenum
+ ip, &buf, NULL, NULL, &linenum
);
if (ok) {
+ /* Backward compatibility */
+
/* Find the terminating zero in the first 50 bytes. */
UInt i;
for (i = 0; i < 50; i++) {
- if (buf64[i] == 0)
+ if (buf[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);
+ if (i == 50) {
+ // The returned filename is too long. Truncate it just like
+ // the old implementation of VG_(get_filename_linenum)
+ // would have done.
+ buf[49] = 0;
+ }
+ VG_(sprintf)(buf64, "%s:%u", buf, linenum);
} else {
buf64[0] = 0;
}
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 Fri Aug 15 22:01:13 2014
@@ -53,17 +53,21 @@
optionally directory name. filename and linenum may not be NULL.
dirname may be NULL, meaning that the caller does not want
directory name info, in which case dirname_available must also be
- NULL. If dirname is non-null, directory info is written to it, if
+ NULL. If dirname is non-null, directory info is written to *dirname, if
it is available; if not available, '\0' is written to the first
byte. In either case *dirname_available is set to indicate whether
or not directory information was available.
+ filename and dirname are allocated in static strings and will be
+ overwritten in the next invocation. Callers need to copy the strings
+ if they are needed.
+
Returned value indicates whether any filename/line info could be
found. */
extern Bool VG_(get_filename_linenum)
( Addr a,
- /*OUT*/HChar* filename, Int n_filename,
- /*OUT*/HChar* dirname, Int n_dirname,
+ /*OUT*/HChar** filename,
+ /*OUT*/HChar** dirname,
/*OUT*/Bool* dirname_available,
/*OUT*/UInt* linenum );
|