From: Philippe Waroquiers Date: Mon, 24 Nov 2014 17:46:41 +0000 (+0000) Subject: Change pub_tool_addrinfo.h AddrInfo and VG_(describe_addr) so as to describe X-Git-Tag: svn/VALGRIND_3_11_0~804 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01782fe668373a3f0e96525a25cecdab800d4b39;p=thirdparty%2Fvalgrind.git 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. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14779 --- diff --git a/NEWS b/NEWS index 827c22cb98..05bb360a1c 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ Release 3.11.0 is under development, not yet released. * ==================== 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=, can be used to mark the begin/end of errors in textual output mode, to facilitate searching/extracting errors in output files mixing valgrind diff --git a/coregrind/m_addrinfo.c b/coregrind/m_addrinfo.c index 8b364e2c70..533b620aad 100644 --- a/coregrind/m_addrinfo.c +++ b/coregrind/m_addrinfo.c @@ -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 @@ void VG_(describe_addr) ( Addr a, /*OUT*/AddrInfo* ai ) } } + /* -- 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 @@ void VG_(clear_addrinfo) ( AddrInfo* ai) 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 @@ static UInt tnr_else_tid (ThreadInfo tinfo) 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 @@ static void pp_addrinfo_WRK ( Addr a, const AddrInfo* ai, Bool mc, } 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"); } diff --git a/helgrind/hg_addrdescr.c b/helgrind/hg_addrdescr.c index c6a25b10f9..abf5aa5c4c 100644 --- a/helgrind/hg_addrdescr.c +++ b/helgrind/hg_addrdescr.c @@ -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" diff --git a/helgrind/hg_errors.c b/helgrind/hg_errors.c index 65703e6879..87c5bbdfc7 100644 --- a/helgrind/hg_errors.c +++ b/helgrind/hg_errors.c @@ -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" diff --git a/include/pub_tool_addrinfo.h b/include/pub_tool_addrinfo.h index 6e089e794d..b8fc634639 100644 --- a/include/pub_tool_addrinfo.h +++ b/include/pub_tool_addrinfo.h @@ -71,7 +71,8 @@ typedef 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 @@ struct _AddrInfo { 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; diff --git a/memcheck/mc_errors.c b/memcheck/mc_errors.c index 3303ee1e05..5781b8026a 100644 --- a/memcheck/mc_errors.c +++ b/memcheck/mc_errors.c @@ -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 @@ void MC_(pp_describe_addr) ( Addr a ) 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 diff --git a/memcheck/tests/addressable.stderr.exp b/memcheck/tests/addressable.stderr.exp index 7c8a893871..8fbd9528f3 100644 --- a/memcheck/tests/addressable.stderr.exp +++ b/memcheck/tests/addressable.stderr.exp @@ -63,12 +63,12 @@ ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 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: diff --git a/memcheck/tests/dw4.c b/memcheck/tests/dw4.c index c66c378438..38c2421d3f 100644 --- a/memcheck/tests/dw4.c +++ b/memcheck/tests/dw4.c @@ -10,7 +10,12 @@ #include #include +#include #include +#include "tests/sys_mman.h" +#include +#include +#include #include "memcheck/memcheck.h" /* Cause memcheck to complain about the address "a" and so to print @@ -45,10 +50,37 @@ int main ( void ) { 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; } diff --git a/memcheck/tests/dw4.stderr.exp b/memcheck/tests/dw4.stderr.exp index b4420a9914..605d9bdc0c 100644 --- a/memcheck/tests/dw4.stderr.exp +++ b/memcheck/tests/dw4.stderr.exp @@ -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 diff --git a/memcheck/tests/filter_dw4 b/memcheck/tests/filter_dw4 index 288cb1892f..b192bb91b7 100755 --- a/memcheck/tests/filter_dw4 +++ b/memcheck/tests/filter_dw4 @@ -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 diff --git a/memcheck/tests/mempool2.stderr.exp b/memcheck/tests/mempool2.stderr.exp index 4426018513..16b1f388b2 100644 --- a/memcheck/tests/mempool2.stderr.exp +++ b/memcheck/tests/mempool2.stderr.exp @@ -54,7 +54,7 @@ Illegal memory pool address 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 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' ---