anonymous or file mmap-ed segments and shared memory segments.
* pub_tool_addrinfo.h:
new AddrTag Addr_SegmentKind // Client segment (mapped memory)
new struct SegmentKind in AddrInfo
* m_addrinfo.c:
If address is still undescribed, try to describe by findinf a client segment.
* update various tests
* mc_errors.c:
add a call to VG_(clear_addrinfo) in MC_(pp_describe_addr)
as the memory allocated in the local AddrInfo has to be cleared once
info is printed.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14779
* ==================== OTHER CHANGES ====================
+* Address description logic (used by memcheck and helgrind)
+ now describes anonymous or file mmap-ed segments and
+ shared memory segments.
+
* Option --error-markers=<begin>,<end> can be used to mark
the begin/end of errors in textual output mode, to facilitate
searching/extracting errors in output files mixing valgrind
#include "pub_core_xarray.h"
#include "pub_core_debuginfo.h"
#include "pub_core_execontext.h"
+#include "pub_core_aspacemgr.h"
#include "pub_core_addrinfo.h"
#include "pub_core_mallocfree.h"
#include "pub_core_machine.h"
}
}
+ /* -- and yet another last ditch attempt at classification -- */
+ /* Try to find a segment belonging to the client. */
+ {
+ const NSegment *seg = VG_(am_find_nsegment) (a);
+ if (seg != NULL
+ && (seg->kind == SkAnonC
+ || seg->kind == SkFileC
+ || seg->kind == SkShmC)) {
+ ai->tag = Addr_SegmentKind;
+ ai->Addr.SegmentKind.segkind = seg->kind;
+ ai->Addr.SegmentKind.filename = NULL;
+ if (seg->kind == SkFileC)
+ ai->Addr.SegmentKind.filename = VG_(am_get_filename) (seg);
+ if (ai->Addr.SegmentKind.filename != NULL)
+ ai->Addr.SegmentKind.filename
+ = VG_(strdup)("mc.da.skfname",
+ ai->Addr.SegmentKind.filename);
+ ai->Addr.SegmentKind.hasR = seg->hasR;
+ ai->Addr.SegmentKind.hasW = seg->hasW;
+ ai->Addr.SegmentKind.hasX = seg->hasX;
+ return;
+ }
+ }
+
/* -- Clueless ... -- */
ai->tag = Addr_Unknown;
return;
VG_(free)(ai->Addr.SectKind.objname);
break;
+ case Addr_SegmentKind:
+ VG_(free)(ai->Addr.SegmentKind.filename);
+ break;
+
default:
VG_(core_panic)("VG_(clear_addrinfo)");
}
return tinfo.tid;
}
+static const HChar* pp_SegKind ( SegKind sk )
+{
+ switch (sk) {
+ case SkAnonC: return "anonymous";
+ case SkFileC: return "mapped file";
+ case SkShmC: return "shared memory";
+ default: vg_assert(0);
+ }
+}
+
static void pp_addrinfo_WRK ( Addr a, const AddrInfo* ai, Bool mc,
Bool maybe_gcc )
{
}
break;
+ case Addr_SegmentKind:
+ VG_(emit)( "%sAddress 0x%llx is in "
+ "a %s%s%s %s%s%pS segment%s\n",
+ xpre,
+ (ULong)a,
+ ai->Addr.SegmentKind.hasR ? "r" : "-",
+ ai->Addr.SegmentKind.hasW ? "w" : "-",
+ ai->Addr.SegmentKind.hasX ? "x" : "-",
+ pp_SegKind(ai->Addr.SegmentKind.segkind),
+ ai->Addr.SegmentKind.filename ?
+ " " : "",
+ ai->Addr.SegmentKind.filename ?
+ ai->Addr.SegmentKind.filename : "",
+ xpost );
+ break;
+
default:
VG_(core_panic)("mc_pp_AddrInfo");
}
#include "pub_tool_execontext.h"
#include "pub_tool_debuginfo.h"
#include "pub_tool_threadstate.h"
+#include "pub_tool_aspacemgr.h"
#include "pub_tool_addrinfo.h"
#include "hg_basics.h"
#include "pub_tool_debuginfo.h"
#include "pub_tool_threadstate.h"
#include "pub_tool_options.h" // VG_(clo_xml)
+#include "pub_tool_aspacemgr.h"
#include "pub_tool_addrinfo.h"
#include "hg_basics.h"
Addr_Stack, // on a thread's stack
Addr_DataSym, // in a global data sym
Addr_Variable, // variable described by the debug info
- Addr_SectKind // last-ditch classification attempt
+ Addr_SectKind, // Section from a mmap-ed object file
+ Addr_SegmentKind // Client segment (mapped memory)
}
AddrTag;
VgSectKind kind;
} SectKind;
+ struct {
+ SegKind segkind; // SkAnonC, SkFileC or SkShmC.
+ HChar *filename; // NULL if segkind != SkFileC
+ Bool hasR;
+ Bool hasW;
+ Bool hasX;
+ } SegmentKind;
+
// Classification yielded nothing useful.
struct { } Unknown;
#include "pub_tool_threadstate.h"
#include "pub_tool_debuginfo.h" // VG_(get_dataname_and_offset)
#include "pub_tool_xarray.h"
+#include "pub_tool_aspacemgr.h"
#include "pub_tool_addrinfo.h"
#include "mc_include.h"
ai.tag = Addr_Undescribed;
describe_addr (a, &ai);
VG_(pp_addrinfo_mc) (a, &ai, /* maybe_gcc */ False);
+ VG_(clear_addrinfo) (&ai);
}
/* Fill in *origin_ec as specified by otag, or NULL it out if otag
Uninitialised byte(s) found during client check request
at 0x........: test5 (addressable.c:85)
by 0x........: main (addressable.c:125)
- Address 0x........ is not stack'd, malloc'd or (recently) free'd
+ Address 0x........ is in a rw- anonymous segment
Uninitialised byte(s) found during client check request
at 0x........: test5 (addressable.c:91)
by 0x........: main (addressable.c:125)
- Address 0x........ is not stack'd, malloc'd or (recently) free'd
+ Address 0x........ is in a r-- anonymous segment
HEAP SUMMARY:
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
+#include "tests/sys_mman.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "memcheck/memcheck.h"
/* Cause memcheck to complain about the address "a" and so to print
{
struct s1 local;
struct s1* onheap = malloc(sizeof (struct s1));
+ void *p, *q;
+ int fd;
+ int n;
+ char filename[256];
+
assert(onheap);
croak(&onheap->i);
croak( &S2[0].i );
croak( &local.i );
+
+ /* Describe anonymous mmap-ed */
+ p = mmap( 0, 16 * 1024, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 );
+ assert(p != MAP_FAILED);
+ croak( p);
+
+ /* Describe file mmap-ed */
+ snprintf(filename, sizeof(filename), "./valgrind-dw4-test.%d",
+ getpid());
+
+ unlink(filename);
+
+ fd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+ assert (fd > 0);
+ n = write(fd, filename, strlen(filename));
+ assert (n > 8);
+ q = mmap(NULL, 100, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+ assert (q != MAP_FAILED);
+ croak( q);
+ unlink(filename);
+
return 0;
}
Uninitialised byte(s) found during client check request
- at 0x........: croak (dw4.c:27)
- by 0x........: main (dw4.c:49)
+ at 0x........: croak (dw4.c:32)
+ by 0x........: main (dw4.c:59)
Address 0x........ is 4 bytes inside a block of size ... alloc'd
at 0x........: malloc (vg_replace_malloc.c:...)
- by 0x........: main (dw4.c:47)
+ by 0x........: main (dw4.c:52)
Uninitialised byte(s) found during client check request
- at 0x........: croak (dw4.c:27)
- by 0x........: main (dw4.c:51)
+ at 0x........: croak (dw4.c:32)
+ by 0x........: main (dw4.c:61)
Location 0x........ is 0 bytes inside S2[0].i,
- a global variable declared at dw4.c:42
+ a global variable declared at dw4.c:47
Uninitialised byte(s) found during client check request
- at 0x........: croak (dw4.c:27)
- by 0x........: main (dw4.c:52)
+ at 0x........: croak (dw4.c:32)
+ by 0x........: main (dw4.c:62)
Location 0x........ is 0 bytes inside local.i,
- declared at dw4.c:46, in frame #1 of thread 1
+ declared at dw4.c:51, in frame #1 of thread 1
+
+Uninitialised byte(s) found during client check request
+ at 0x........: croak (dw4.c:32)
+ by 0x........: main (dw4.c:68)
+ Address 0x........ is in a rw- anonymous segment
+
+Uninitialised byte(s) found during client check request
+ at 0x........: croak (dw4.c:32)
+ by 0x........: main (dw4.c:82)
+ Address 0x........ is in a rw- mapped file valgrind-dw4-test.PID segment
# Size of structure s1 differs between 32-bit and 64-bit programs.
sed "s/inside a block of size [0-9]* alloc'd/inside a block of size ... alloc'd/" |
+# remove directory name and pid from mapped filename
+sed "s/file .*valgrind-dw4-test.[1-9][0-9]*/file valgrind-dw4-test.PID/" |
+
./filter_stderr "$@"
exit 0
Illegal memory pool address
at 0x........: test (mempool2.c:150)
by 0x........: main (mempool2.c:196)
- Address 0x........ is not stack'd, malloc'd or (recently) free'd
+ Address 0x........ is in a rwx anonymous segment
------ double free in malloc-backed pool ------
Illegal memory pool address
at 0x........: test (mempool2.c:159)
by 0x........: main (mempool2.c:196)
- Address 0x........ is not stack'd, malloc'd or (recently) free'd
+ Address 0x........ is in a rwx anonymous segment
------ 2 invalid access in 'no no-access superblock' ---