]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
callgrind: Use directory in debug info when available
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Mon, 17 Sep 2007 12:52:10 +0000 (12:52 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Mon, 17 Sep 2007 12:52:10 +0000 (12:52 +0000)
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

NEWS
callgrind/dump.c
callgrind/fn.c

diff --git a/NEWS b/NEWS
index ab7e296319d4bc8405a84a2aa384127f5088c532..ddf6945b3485dc1d93b42909f7e1a77a0f1a74ab 100644 (file)
--- 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:
 
index a46a180fc8750d48603825e1f988663a79c874f7..dd445e274244fac7e2280e2723399e552e024015 100644 (file)
@@ -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;
 }
 
 
index e8108f46bb561aee7382113b20abd59cfcb13850..75b142d8bad3a91d71536c302d0e189f113ae572 100644 (file)
@@ -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;
    }