|
From: <sv...@va...> - 2014-11-24 17:46:49
|
Author: philippe
Date: Mon Nov 24 17:46:41 2014
New Revision: 14779
Log:
Change pub_tool_addrinfo.h AddrInfo and VG_(describe_addr) so as to describe
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.
Modified:
trunk/NEWS
trunk/coregrind/m_addrinfo.c
trunk/helgrind/hg_addrdescr.c
trunk/helgrind/hg_errors.c
trunk/include/pub_tool_addrinfo.h
trunk/memcheck/mc_errors.c
trunk/memcheck/tests/addressable.stderr.exp
trunk/memcheck/tests/dw4.c
trunk/memcheck/tests/dw4.stderr.exp
trunk/memcheck/tests/filter_dw4
trunk/memcheck/tests/mempool2.stderr.exp
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Mon Nov 24 17:46:41 2014
@@ -14,6 +14,10 @@
* ==================== 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
Modified: trunk/coregrind/m_addrinfo.c
==============================================================================
--- trunk/coregrind/m_addrinfo.c (original)
+++ trunk/coregrind/m_addrinfo.c Mon Nov 24 17:46:41 2014
@@ -36,6 +36,7 @@
#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"
@@ -258,6 +259,30 @@
}
}
+ /* -- 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;
@@ -303,6 +328,10 @@
VG_(free)(ai->Addr.SectKind.objname);
break;
+ case Addr_SegmentKind:
+ VG_(free)(ai->Addr.SegmentKind.filename);
+ break;
+
default:
VG_(core_panic)("VG_(clear_addrinfo)");
}
@@ -343,6 +372,16 @@
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 )
{
@@ -547,6 +586,22 @@
}
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");
}
Modified: trunk/helgrind/hg_addrdescr.c
==============================================================================
--- trunk/helgrind/hg_addrdescr.c (original)
+++ trunk/helgrind/hg_addrdescr.c Mon Nov 24 17:46:41 2014
@@ -37,6 +37,7 @@
#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"
Modified: trunk/helgrind/hg_errors.c
==============================================================================
--- trunk/helgrind/hg_errors.c (original)
+++ trunk/helgrind/hg_errors.c Mon Nov 24 17:46:41 2014
@@ -40,6 +40,7 @@
#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"
Modified: trunk/include/pub_tool_addrinfo.h
==============================================================================
--- trunk/include/pub_tool_addrinfo.h (original)
+++ trunk/include/pub_tool_addrinfo.h Mon Nov 24 17:46:41 2014
@@ -71,7 +71,8 @@
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;
@@ -173,6 +174,14 @@
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;
Modified: trunk/memcheck/mc_errors.c
==============================================================================
--- trunk/memcheck/mc_errors.c (original)
+++ trunk/memcheck/mc_errors.c Mon Nov 24 17:46:41 2014
@@ -44,6 +44,7 @@
#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"
@@ -1085,6 +1086,7 @@
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
Modified: trunk/memcheck/tests/addressable.stderr.exp
==============================================================================
--- trunk/memcheck/tests/addressable.stderr.exp (original)
+++ trunk/memcheck/tests/addressable.stderr.exp Mon Nov 24 17:46:41 2014
@@ -63,12 +63,12 @@
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:
Modified: trunk/memcheck/tests/dw4.c
==============================================================================
--- trunk/memcheck/tests/dw4.c (original)
+++ trunk/memcheck/tests/dw4.c Mon Nov 24 17:46:41 2014
@@ -10,7 +10,12 @@
#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
@@ -45,10 +50,37 @@
{
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;
}
Modified: trunk/memcheck/tests/dw4.stderr.exp
==============================================================================
--- trunk/memcheck/tests/dw4.stderr.exp (original)
+++ trunk/memcheck/tests/dw4.stderr.exp Mon Nov 24 17:46:41 2014
@@ -1,19 +1,29 @@
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
Modified: trunk/memcheck/tests/filter_dw4
==============================================================================
--- trunk/memcheck/tests/filter_dw4 (original)
+++ trunk/memcheck/tests/filter_dw4 Mon Nov 24 17:46:41 2014
@@ -3,6 +3,9 @@
# 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
Modified: trunk/memcheck/tests/mempool2.stderr.exp
==============================================================================
--- trunk/memcheck/tests/mempool2.stderr.exp (original)
+++ trunk/memcheck/tests/mempool2.stderr.exp Mon Nov 24 17:46:41 2014
@@ -54,7 +54,7 @@
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 ------
@@ -74,7 +74,7 @@
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' ---
|