|
From: <sv...@va...> - 2007-09-17 12:52:11
|
Author: weidendo
Date: 2007-09-17 13:52:10 +0100 (Mon, 17 Sep 2007)
New Revision: 6850
Log:
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)
Modified:
trunk/NEWS
trunk/callgrind/dump.c
trunk/callgrind/fn.c
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2007-09-17 09:54:57 UTC (rev 6849)
+++ trunk/NEWS 2007-09-17 12:52:10 UTC (rev 6850)
@@ -30,6 +30,9 @@
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:
Modified: trunk/callgrind/dump.c
===================================================================
--- trunk/callgrind/dump.c 2007-09-17 09:54:57 UTC (rev 6849)
+++ trunk/callgrind/dump.c 2007-09-17 12:52:10 UTC (rev 6850)
@@ -438,27 +438,36 @@
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 @@
addr, bb_addr(bbcc->bb), bbcc->cxt->fn[0]->name,
p->file->name, p->line);
- return res;
+ return found_file_line;
}
Modified: trunk/callgrind/fn.c
===================================================================
--- trunk/callgrind/fn.c 2007-09-17 09:54:57 UTC (rev 6849)
+++ trunk/callgrind/fn.c 2007-09-17 12:52:10 UTC (rev 6850)
@@ -364,11 +364,12 @@
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 @@
// 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 (!found1 && !found2) {
+ 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 (!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;
}
|