From: Josef Weidendorfer Date: Mon, 17 Sep 2007 12:52:10 +0000 (+0000) Subject: callgrind: Use directory in debug info when available X-Git-Tag: svn/VALGRIND_3_3_0~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99590836165265aca277eac8b56515e83cfe1ee6;p=thirdparty%2Fvalgrind.git callgrind: Use directory in debug info when available Prepend the file name of a source file with the directory if that is available. This not only gets rid of problems with the same file name used in different paths of a project, but lets the annotation work out of the box without having to specify any source directory. Works both with callgrind_annotate and KCachegrind without any changes there. Inspired by Nick's change to cachegrind doing the same thing in r6839 (and gets rid of a FIXME in the source) git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6850 --- diff --git a/NEWS b/NEWS index ab7e296319..ddf6945b34 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,9 @@ Other user-visible changes: This means that the -I option to 'cg_annotate' should not be needed in most cases. It also means it can correctly handle the case where two source files in different directories have the same name. + The same is true for Callgrind and callgrind_annotate, respectively. + The benefits also apply to KCachegrind, without any further change + (ie. in most cases there is no configuration of source directories needed). Developer-visible changes: diff --git a/callgrind/dump.c b/callgrind/dump.c index a46a180fc8..dd445e2742 100644 --- a/callgrind/dump.c +++ b/callgrind/dump.c @@ -438,27 +438,36 @@ static __inline__ Bool get_debug_pos(BBCC* bbcc, Addr addr, AddrPos* p) { Char file[FILENAME_LEN]; - Bool res; + Char dir[FILENAME_LEN]; + Bool found_file_line, found_dirname; int cachepos = addr % DEBUG_CACHE_SIZE; if (debug_cache_addr[cachepos] == addr) { p->line = debug_cache_line[cachepos]; p->file = debug_cache_file[cachepos]; - res = debug_cache_info[cachepos]; + found_file_line = debug_cache_info[cachepos]; } else { - res = VG_(get_filename_linenum)(addr, - file, FILENAME_LEN, - NULL, 0, NULL, //FIXME - &(p->line)); - if (!res) { + found_file_line = VG_(get_filename_linenum)(addr, + file, FILENAME_LEN, + dir, FILENAME_LEN, + &found_dirname, + &(p->line)); + if (!found_file_line) { VG_(strcpy)(file, "???"); p->line = 0; } + if (found_dirname) { + // +1 for the '/'. + CLG_ASSERT(VG_(strlen)(dir) + VG_(strlen)(file) + 1 < FILENAME_LEN); + VG_(strcat)(dir, "/"); // Append '/' + VG_(strcat)(dir, file); // Append file to dir + VG_(strcpy)(file, dir); // Move dir+file to file + } p->file = CLG_(get_file_node)(bbcc->bb->obj, file); - debug_cache_info[cachepos] = res; + debug_cache_info[cachepos] = found_file_line; debug_cache_addr[cachepos] = addr; debug_cache_line[cachepos] = p->line; debug_cache_file[cachepos] = p->file; @@ -472,7 +481,7 @@ Bool get_debug_pos(BBCC* bbcc, Addr addr, AddrPos* p) addr, bb_addr(bbcc->bb), bbcc->cxt->fn[0]->name, p->file->name, p->line); - return res; + return found_file_line; } diff --git a/callgrind/fn.c b/callgrind/fn.c index e8108f46bb..75b142d8ba 100644 --- a/callgrind/fn.c +++ b/callgrind/fn.c @@ -364,11 +364,12 @@ fn_node* get_fn_node_inseg(SegInfo* si, Bool CLG_(get_debug_info)(Addr instr_addr, - Char filename[FILENAME_LEN], + Char file[FILENAME_LEN], Char fn_name[FN_NAME_LEN], UInt* line_num, SegInfo** pSegInfo) { - Bool found1, found2, result = True; + Bool found_file_line, found_fn, found_dirname, result = True; + Char dir[FILENAME_LEN]; UInt line; CLG_DEBUG(6, " + get_debug_info(%p)\n", instr_addr); @@ -379,32 +380,41 @@ Bool CLG_(get_debug_info)(Addr instr_addr, // for generated code in anonymous space, pSegInfo is 0 } - found1 = VG_(get_filename_linenum)(instr_addr, - filename, FILENAME_LEN, - NULL, 0, NULL, // FIXME: add dirnames! - &line); - found2 = VG_(get_fnname)(instr_addr, - fn_name, FN_NAME_LEN); + found_file_line = VG_(get_filename_linenum)(instr_addr, + file, FILENAME_LEN, + dir, FILENAME_LEN, + &found_dirname, + &line); + found_fn = VG_(get_fnname)(instr_addr, + fn_name, FN_NAME_LEN); + + if (found_dirname) { + // +1 for the '/'. + CLG_ASSERT(VG_(strlen)(dir) + VG_(strlen)(file) + 1 < FILENAME_LEN); + VG_(strcat)(dir, "/"); // Append '/' + VG_(strcat)(dir, file); // Append file to dir + VG_(strcpy)(file, dir); // Move dir+file to file + } - if (!found1 && !found2) { + if (!found_file_line && !found_fn) { CLG_(stat).no_debug_BBs++; - VG_(strcpy)(filename, "???"); + VG_(strcpy)(file, "???"); VG_(strcpy)(fn_name, "???"); if (line_num) *line_num=0; result = False; - } else if ( found1 && found2) { + } else if ( found_file_line && found_fn) { CLG_(stat).full_debug_BBs++; if (line_num) *line_num=line; - } else if ( found1 && !found2) { + } else if ( found_file_line && !found_fn) { CLG_(stat).file_line_debug_BBs++; VG_(strcpy)(fn_name, "???"); if (line_num) *line_num=line; - } else /*(!found1 && found2)*/ { + } else /*(!found_file_line && found_fn)*/ { CLG_(stat).fn_name_debug_BBs++; - VG_(strcpy)(filename, "???"); + VG_(strcpy)(file, "???"); if (line_num) *line_num=0; }