]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge revisions 14255, 14293, and 14294 from the BUF_REMOVAL branch to trunk.
authorFlorian Krohm <florian@eich-krohm.de>
Mon, 27 Oct 2014 12:06:35 +0000 (12:06 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Mon, 27 Oct 2014 12:06:35 +0000 (12:06 +0000)
The functions VG_(get_filename) and VG_(get_filename_lineno) now return
a pointer to filename and directory name instead of copying them into
buffers passed in from the caller.
The returned strings are persistent as long as the DebugInfo to which
they belong is not discarded. The caller therefore needs to stash them
away as needed.
Function VG_(strncpy_safely) has been removed as it is no longer needed.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14668

cachegrind/cg_main.c
callgrind/debug.c
callgrind/dump.c
callgrind/fn.c
callgrind/global.h
coregrind/m_addrinfo.c
coregrind/m_debuginfo/debuginfo.c
coregrind/m_libcbase.c
coregrind/m_scheduler/scheduler.c
include/pub_tool_debuginfo.h
include/pub_tool_libcbase.h

index 10e562e4cc5c561d27f50b8afa0eeb0abd6a5c9c..6f8cfd202ef7034b64a863552b82bf0e5484c628 100644 (file)
 */
 
 #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"
@@ -57,8 +55,6 @@
 /* Set to 1 for very verbose debugging */
 #define DEBUG_CG 0
 
-#define FILE_LEN              VKI_PATH_MAX
-
 /*------------------------------------------------------------*/
 /*--- Options                                              ---*/
 /*------------------------------------------------------------*/
@@ -211,21 +207,19 @@ static HChar* get_perm_string(const HChar* s)
 /*--- CC table operations                                  ---*/
 /*------------------------------------------------------------*/
 
-static void get_debug_info(Addr instr_addr, HChar dir[FILE_LEN],
-                           HChar file[FILE_LEN],
-                           const HChar **fn, UInt* line)
+static void get_debug_info(Addr instr_addr, const HChar **dir,
+                           const HChar **file, const 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 = "???";
       *line = 0;
    }
    if (!found_fn) {
@@ -245,13 +239,12 @@ static void get_debug_info(Addr instr_addr, HChar dir[FILE_LEN],
 // 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];
-   const HChar *fn;
+   const HChar *fn, *file, *dir;
    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];
index 2acdd6f9543389c91470659b54580e19c7c51d2a..2ef21fd01741b3e76fdb28a47d040a7a0d09cc97 100644 (file)
@@ -373,9 +373,7 @@ void CLG_(print_bbcc_cost)(int s, BBCC* bbcc)
 /* dump out an address with source info if available */
 void CLG_(print_addr)(Addr addr)
 {
-    HChar fl_buf[FILENAME_LEN];
-    HChar dir_buf[FILENAME_LEN];
-    const HChar *fn_buf;
+    const HChar *fn_buf, *fl_buf, *dir_buf;
     const HChar* obj_name;
     DebugInfo* di;
     UInt ln, i=0, opos=0;
@@ -385,7 +383,7 @@ void CLG_(print_addr)(Addr addr)
        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);
index 0f750afee3092d31b51e306e19e262c472d1d49e..8a4f8fa283ddb7ef0fc39c8447730d3761c871b7 100644 (file)
@@ -427,8 +427,7 @@ void init_debug_cache(void)
 static /* __inline__ */
 Bool get_debug_pos(BBCC* bbcc, Addr addr, AddrPos* p)
 {
-    HChar file[FILENAME_LEN];
-    HChar dir[FILENAME_LEN];
+    const HChar *file, *dir;
     Bool found_file_line, found_dirname;
 
     int cachepos = addr % DEBUG_CACHE_SIZE;
@@ -440,12 +439,12 @@ Bool get_debug_pos(BBCC* bbcc, Addr addr, AddrPos* p)
     }
     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 = "???";
            p->line = 0;
        }
        p->file    = CLG_(get_file_node)(bbcc->bb->obj, dir, file);
index fe3342ffcd5ee9446bd0e97b680019be80ad1581..b6dff08ded38906374886f34a734aee6b62a0d09 100644 (file)
@@ -424,8 +424,8 @@ fn_node* get_fn_node_inseg(DebugInfo* di,
 
 
 Bool CLG_(get_debug_info)(Addr instr_addr,
-                          HChar dir[FILENAME_LEN],
-                          HChar file[FILENAME_LEN],
+                          const HChar **dir,
+                          const HChar **file,
                           const HChar **fn_name, UInt* line_num,
                           DebugInfo** pDebugInfo)
 {
@@ -441,15 +441,15 @@ Bool CLG_(get_debug_info)(Addr instr_addr,
    }
 
    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, fn_name);
 
    if (!found_file_line && !found_fn) {
      CLG_(stat).no_debug_BBs++;
-     VG_(strcpy)(file, "???");
+     *file = "???";
      *fn_name = "???";
      if (line_num) *line_num=0;
      result = False;
@@ -465,7 +465,7 @@ Bool CLG_(get_debug_info)(Addr instr_addr,
 
    } else  /*(!found_file_line &&  found_fn)*/ {
      CLG_(stat).fn_name_debug_BBs++;
-     VG_(strcpy)(file, "???");
+     *file = "???";
      if (line_num) *line_num=0;
    }
 
@@ -488,9 +488,7 @@ static BB* exit_bb = 0;
  */
 fn_node* CLG_(get_fn_node)(BB* bb)
 {
-    HChar      filename[FILENAME_LEN];
-    HChar      dirname[FILENAME_LEN];
-    const HChar *fnname;
+    const HChar *fnname, *filename, *dirname;
     DebugInfo* di;
     UInt       line_num;
     fn_node*   fn;
@@ -504,7 +502,7 @@ fn_node* CLG_(get_fn_node)(BB* bb)
      * 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;
@@ -535,7 +533,7 @@ fn_node* CLG_(get_fn_node)(BB* bb)
     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");
     }
index cf4b201cd54f1162f8a4db6251ff5affa20439d9..03deb6179ba478a80614f11c1f622742db3e2886 100644 (file)
@@ -690,8 +690,8 @@ void CLG_(print_debug_usage)(void);
 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, const HChar **dirname,
+                          const HChar **filename,
                           const HChar **fn_name, UInt*, DebugInfo**);
 void CLG_(collectBlockInfo)(IRSB* bbIn, UInt*, UInt*, Bool*);
 void CLG_(set_instrument_state)(const HChar*,Bool);
index 803bb3a9d4d75f0f244a37b518cacc9d8dfcd1ef..0cc29efb9423ca569ad796f2ba1388d1e42f50d4 100644 (file)
@@ -381,10 +381,9 @@ static void pp_addrinfo_WRK ( Addr a, const AddrInfo* ai, Bool mc,
                     tnr_else_tid (ai->Addr.Stack.tinfo), 
                     xpost );
          if (ai->Addr.Stack.frameNo != -1 && ai->Addr.Stack.IP != 0) {
-#define     FLEN                256
             const HChar *fn;
             Bool  hasfn;
-            HChar file[FLEN];
+            const HChar *file;
             Bool  hasfile;
             UInt linenum;
             Bool haslinenum;
@@ -397,24 +396,21 @@ static void pp_addrinfo_WRK ( Addr a, const AddrInfo* ai, Bool mc,
             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[16] = "";   // 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
          }
          switch (ai->Addr.Stack.stackPos) {
             case StackPos_stacked: break; // nothing more to say
index dbcee080edc0f3608622ba11f4f2c77cd6fa53a6..713010159a0a6131c063f52aece0d04844d49bd8 100644 (file)
@@ -2031,8 +2031,10 @@ DebugInfo* VG_(find_DebugInfo) ( Addr a )
    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. The
+   returned string is persistent as long as the DebugInfo to which it
+   belongs is not discarded. */
+Bool VG_(get_filename)( Addr a, const HChar** filename )
 {
    DebugInfo* si;
    Word       locno;
@@ -2042,9 +2044,7 @@ Bool VG_(get_filename)( Addr a, HChar* filename, Int n_filename )
    if (si == NULL) 
       return False;
    fndn_ix = ML_(fndn_ix) (si, locno);
-   VG_(strncpy_safely)(filename,
-                       ML_(fndn_ix2filename) (si, fndn_ix),
-                       n_filename);
+   *filename = ML_(fndn_ix2filename) (si, fndn_ix);
    return True;
 }
 
@@ -2065,8 +2065,8 @@ Bool VG_(get_linenum)( Addr a, UInt* lineno )
    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*/const HChar** filename,
+                                 /*OUT*/const HChar** dirname,
                                  /*OUT*/Bool* dirname_available,
                                  /*OUT*/UInt* lineno )
 {
@@ -2082,24 +2082,20 @@ Bool VG_(get_filename_linenum) ( Addr a,
    if (si == NULL) {
       if (dirname_available) {
          *dirname_available = False;
-         *dirname = 0;
+         *dirname = "";
       }
+      *filename = "";      // this used to be not initialised....
       return False;
    }
 
    fndn_ix = ML_(fndn_ix)(si, locno);
-   VG_(strncpy_safely)(filename,
-                       ML_(fndn_ix2filename) (si, fndn_ix),
-                       n_filename);
+   *filename = ML_(fndn_ix2filename) (si, fndn_ix);
    *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;
+      *dirname = ML_(fndn_ix2dirname) (si, fndn_ix);
+      *dirname_available = (*dirname)[0] != '\0';
    }
 
    return True;
@@ -2236,9 +2232,8 @@ HChar* VG_(describe_IP)(Addr eip, HChar* buf, Int n_buf, InlIPCursor *iipc)
 
    static const HChar *buf_fn;
    static const HChar *buf_obj;
-   static HChar buf_srcloc[BUF_LEN];
-   static HChar buf_dirname[BUF_LEN];
-   buf_srcloc[0] = buf_dirname[0] = 0;
+   static const HChar *buf_srcloc;
+   static const HChar *buf_dirname;
 
    Bool  know_dirinfo = False;
    Bool  know_fnname;
@@ -2273,8 +2268,8 @@ HChar* VG_(describe_IP)(Addr eip, HChar* buf, Int n_buf, InlIPCursor *iipc)
       // 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 {
@@ -2286,23 +2281,20 @@ HChar* VG_(describe_IP)(Addr eip, HChar* buf, Int n_buf, InlIPCursor *iipc)
       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 = "???";
       } 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 = fndn->dirname;
             know_dirinfo = True;
          }
-         VG_(snprintf) (buf_srcloc, BUF_LEN, "%s", fndn->filename);
+         buf_srcloc = fndn->filename;
       }
       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;
@@ -2374,7 +2366,7 @@ HChar* VG_(describe_IP)(Addr eip, HChar* buf, Int n_buf, InlIPCursor *iipc)
       if (know_srcloc) {
          APPEND(" (");
          // Get the directory name, if any, possibly pruned, into dirname.
-         HChar* dirname = NULL;
+         const HChar* dirname = NULL;
          if (VG_(sizeXA)(VG_(clo_fullpath_after)) > 0) {
             Int i;
             dirname = buf_dirname;
index 8dd452e7f1793b76ed01666c3f69853d958bff9c..b9a757474df6b99ee7aac3892aad38cb7b69c01f 100644 (file)
@@ -38,6 +38,7 @@
    Assert machinery for use in this file. vg_assert cannot be called
    here due to cyclic dependencies.
    ------------------------------------------------------------------ */
+#if 0
 #define libcbase_assert(expr)                             \
   ((void) (LIKELY(expr) ? 0 :                             \
            (ML_(libcbase_assert_fail)(#expr,              \
@@ -56,6 +57,7 @@ static void ML_(libcbase_assert_fail)( const HChar *expr,
    VG_(debugLog)(0, "libcbase", "Exiting now.\n");
    VG_(exit_now)(1);
 }
+#endif
 
 /* ---------------------------------------------------------------------
    HChar functions.
@@ -303,22 +305,6 @@ HChar* VG_(strcpy) ( HChar* dest, const HChar* src )
    return dest_orig;
 }
 
-/* Copy bytes, not overrunning the end of dest and always ensuring
-   zero termination. */
-void VG_(strncpy_safely) ( HChar* dest, const HChar* src, SizeT ndest )
-{
-   libcbase_assert(ndest > 0);
-
-   SizeT i = 0;
-   while (True) {
-      dest[i] = 0;
-      if (src[i] == 0) return;
-      if (i >= ndest-1) return;
-      dest[i] = src[i];
-      i++;
-   }
-}
-
 HChar* VG_(strncpy) ( HChar* dest, const HChar* src, SizeT ndest )
 {
    SizeT i = 0;
index 342fbe6bb8f929995f5644131d7b8c5cb0351d1d..4ddf8a35040d70f84e9ec07ea863c705c438e0ce 100644 (file)
@@ -1997,25 +1997,25 @@ void do_client_request ( ThreadId tid )
 
       case VG_USERREQ__MAP_IP_TO_SRCLOC: {
          Addr   ip    = arg[1];
-         HChar* buf64 = (HChar*)arg[2];
+         HChar* buf64 = (HChar*)arg[2];  // points to a HChar [64] array
+         const HChar *buf;  // points to a string of unknown size
 
          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) {
-            /* Find the terminating zero in the first 50 bytes. */
+            /* For backward compatibility truncate the filename to
+               49 characters. */
+            VG_(strncpy)(buf64, buf, 50);
+            buf64[49] = '\0';
             UInt i;
             for (i = 0; i < 50; i++) {
                if (buf64[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);
+            VG_(sprintf)(buf64+i, ":%u", linenum);  // safe
          } else {
             buf64[0] = 0;
          }
index 0940b3dc35fe4f2968ff160f166307130d928189..60933213767da8aa4c0fabde5a9422b0b931ee5d 100644 (file)
@@ -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, const HChar** filename );
 extern Bool VG_(get_fnname)   ( Addr a, const HChar** fnname );
 extern Bool VG_(get_linenum)  ( Addr a, UInt* linenum );
 extern Bool VG_(get_fnname_w_offset)
@@ -53,17 +53,21 @@ extern Bool VG_(get_fnname_w_offset)
    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.
 
+   The character strings returned in *filename and *dirname are not
+   persistent. They will be freed when the DebugInfo they belong to
+   is discarded.
+
    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*/const HChar** filename,
+                                /*OUT*/const HChar** dirname,
                                 /*OUT*/Bool* dirname_available,
                                 /*OUT*/UInt* linenum );
 
index 819935fccfd6f910262b4658c098f936b8342e9f..93a19c874e8c3653e4fb1379dd4bbe3e91c37a3c 100644 (file)
@@ -126,10 +126,6 @@ extern Bool VG_(parse_enum_set) ( const HChar *tokens,
                                   const HChar *input,
                                   UInt *enum_set);
 
-/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
-   last character. */
-extern void  VG_(strncpy_safely) ( HChar* dest, const HChar* src, SizeT ndest );
-
 /* ---------------------------------------------------------------------
    mem* functions
    ------------------------------------------------------------------ */