mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
Fixed overlap errors so the hacky strdup'ing of strings isn't necessary;
now passing in the relevant parameters via an 'extra' struct, as is proper. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1809
This commit is contained in:
parent
e1d0585265
commit
f1bde14402
@ -287,13 +287,21 @@ void MAC_(pp_shared_SkinError) ( Error* err )
|
||||
MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo);
|
||||
break;
|
||||
|
||||
case OverlapErr:
|
||||
VG_(message)(Vg_UserMsg,
|
||||
"Source and destination overlap in %s",
|
||||
VG_(get_error_string)(err));
|
||||
case OverlapErr: {
|
||||
OverlapExtra* ov_extra = (OverlapExtra*)VG_(get_error_extra)(err);
|
||||
if (ov_extra->len == -1)
|
||||
VG_(message)(Vg_UserMsg,
|
||||
"Source and destination overlap in %s(%p, %p)",
|
||||
VG_(get_error_string)(err),
|
||||
ov_extra->dst, ov_extra->src);
|
||||
else
|
||||
VG_(message)(Vg_UserMsg,
|
||||
"Source and destination overlap in %s(%p, %p, %d)",
|
||||
VG_(get_error_string)(err),
|
||||
ov_extra->dst, ov_extra->src, ov_extra->len);
|
||||
VG_(pp_ExeContext)( VG_(get_error_where)(err) );
|
||||
break;
|
||||
|
||||
}
|
||||
case LeakErr: {
|
||||
/* Totally abusing the types of these spare fields... oh well. */
|
||||
UInt n_this_record = (UInt)VG_(get_error_address)(err);
|
||||
@ -470,43 +478,36 @@ void MAC_(record_freemismatch_error) ( ThreadId tid, Addr a )
|
||||
|
||||
|
||||
// This one not passed a ThreadId, so it grabs it itself.
|
||||
void MAC_(record_overlap_error) ( Char* function )
|
||||
void MAC_(record_overlap_error) ( Char* function, OverlapExtra* ov_extra )
|
||||
{
|
||||
static Int n_strdups = 0;
|
||||
MAC_Error err_extra;
|
||||
|
||||
/* Potential space leak; this strdup'd space is never
|
||||
reclaimed. Hence hacky sanity check. */
|
||||
if (n_strdups < 1000) {
|
||||
n_strdups++;
|
||||
function = VG_(strdup) ( function );
|
||||
} else {
|
||||
function = NULL;
|
||||
}
|
||||
|
||||
MAC_(clear_MAC_Error)( &err_extra );
|
||||
VG_(maybe_record_error)( VG_(get_current_or_recent_tid)(),
|
||||
OverlapErr, /*addr*/0, /*s*/function, &err_extra );
|
||||
OverlapErr, /*addr*/0, /*s*/function, ov_extra );
|
||||
}
|
||||
|
||||
|
||||
/* Updates the copy with address info if necessary (but not for LeakErrs). */
|
||||
/* Updates the copy with address info if necessary (but not for all errors). */
|
||||
UInt SK_(update_extra)( Error* err )
|
||||
{
|
||||
MAC_Error* extra;
|
||||
|
||||
switch (VG_(get_error_kind)(err)) {
|
||||
case ValueErr:
|
||||
case CoreMemErr:
|
||||
case AddrErr:
|
||||
case ParamErr:
|
||||
case UserErr:
|
||||
case FreeErr:
|
||||
case FreeMismatchErr: {
|
||||
MAC_Error* extra = (MAC_Error*)VG_(get_error_extra)(err);
|
||||
if (extra != NULL && Undescribed == extra->addrinfo.akind) {
|
||||
describe_addr ( VG_(get_error_address)(err), &(extra->addrinfo) );
|
||||
}
|
||||
return sizeof(MAC_Error);
|
||||
}
|
||||
/* Don't need to return the correct size -- LeakErrs are always shown with
|
||||
VG_(unique_error)() so they're not copied anyway. */
|
||||
if (LeakErr == VG_(get_error_kind)(err))
|
||||
return 0;
|
||||
|
||||
extra = (MAC_Error*)VG_(get_error_extra)(err);
|
||||
|
||||
if (extra != NULL && Undescribed == extra->addrinfo.akind) {
|
||||
describe_addr ( VG_(get_error_address)(err), &(extra->addrinfo) );
|
||||
case LeakErr: return 0;
|
||||
case OverlapErr: return sizeof(OverlapExtra);
|
||||
default: VG_(skin_panic)("update_extra: bad errkind");
|
||||
}
|
||||
|
||||
return sizeof(MAC_Error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,9 +35,6 @@
|
||||
#define __VALGRIND_SOMESKIN_H
|
||||
#include "valgrind.h"
|
||||
|
||||
/* For snprintf(), ok because on simd CPU */
|
||||
#include <stdio.h>
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
The normal versions of these functions are hyper-optimised, which fools
|
||||
Memcheck and cause spurious value warnings. So we replace them with
|
||||
@ -82,17 +79,20 @@ Bool is_overlap ( void* dst, const void* src, UInt dstlen, UInt srclen )
|
||||
static __inline__
|
||||
void complain2 ( Char* s, char* dst, const char* src )
|
||||
{
|
||||
Char buf[256];
|
||||
snprintf(buf, 100, "%s(%p, %p)", s, dst, src );
|
||||
VALGRIND_NON_SIMD_CALL1( MAC_(record_overlap_error), buf );
|
||||
OverlapExtra extra = {
|
||||
.src = (Addr)src, .dst = (Addr)dst, .len = -1,
|
||||
};
|
||||
VALGRIND_NON_SIMD_CALL2( MAC_(record_overlap_error), s, &extra );
|
||||
}
|
||||
|
||||
static __inline__
|
||||
void complain3 ( Char* s, void* dst, const void* src, int n )
|
||||
{
|
||||
Char buf[256];
|
||||
snprintf(buf, 100, "%s(%p, %p, %d)", s, dst, src, n );
|
||||
VALGRIND_NON_SIMD_CALL1( MAC_(record_overlap_error), buf );
|
||||
/* Must wrap it up here, because we cannot pass 4 args to core */
|
||||
OverlapExtra extra = {
|
||||
.src = (Addr)src, .dst = (Addr)dst, .len = n,
|
||||
};
|
||||
VALGRIND_NON_SIMD_CALL2( MAC_(record_overlap_error), s, &extra );
|
||||
}
|
||||
|
||||
char* strrchr ( const char* s, int c )
|
||||
|
||||
@ -123,6 +123,15 @@ typedef
|
||||
}
|
||||
MAC_Error;
|
||||
|
||||
/* Extra info for overlap errors */
|
||||
typedef
|
||||
struct {
|
||||
Addr src;
|
||||
Addr dst;
|
||||
Int len; // -1 if unused
|
||||
}
|
||||
OverlapExtra;
|
||||
|
||||
/* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */
|
||||
typedef
|
||||
enum {
|
||||
@ -302,7 +311,7 @@ extern void MAC_(record_param_error) ( ThreadId tid, Addr a,
|
||||
extern void MAC_(record_jump_error) ( ThreadId tid, Addr a );
|
||||
extern void MAC_(record_free_error) ( ThreadId tid, Addr a );
|
||||
extern void MAC_(record_freemismatch_error)( ThreadId tid, Addr a );
|
||||
extern void MAC_(record_overlap_error) ( Char* function );
|
||||
extern void MAC_(record_overlap_error) ( Char* function, OverlapExtra* oe );
|
||||
|
||||
extern void MAC_(pp_shared_SkinError) ( Error* err);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user