]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Change pub_tool_addrinfo.h AddrInfo and VG_(describe_addr) so as to describe
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 24 Nov 2014 17:46:41 +0000 (17:46 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 24 Nov 2014 17:46:41 +0000 (17:46 +0000)
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

NEWS
coregrind/m_addrinfo.c
helgrind/hg_addrdescr.c
helgrind/hg_errors.c
include/pub_tool_addrinfo.h
memcheck/mc_errors.c
memcheck/tests/addressable.stderr.exp
memcheck/tests/dw4.c
memcheck/tests/dw4.stderr.exp
memcheck/tests/filter_dw4
memcheck/tests/mempool2.stderr.exp

diff --git a/NEWS b/NEWS
index 827c22cb98d9163e6aba267f14c45f11555acc95..05bb360a1c29cbc0666662473ff902603b0f854d 100644 (file)
--- 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=<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
index 8b364e2c70cf75e4687c85f3fe512e672d578d3a..533b620aad6bd6097015ad5544d582a227c9081e 100644 (file)
@@ -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");
    }
index c6a25b10f97833febf2a75448b5c68502466be23..abf5aa5c4c5d63249723eb05ce55feb0d97bc50d 100644 (file)
@@ -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"
index 65703e687951614286c56aca9478f944147491f2..87c5bbdfc732ae9f313b7b6a4223bd293713e03a 100644 (file)
@@ -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"
index 6e089e794d03dbd3d6a19876b5679fedb115162a..b8fc63463912b529ae16e93f15e52c264ad51fdc 100644 (file)
@@ -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;
 
index 3303ee1e055873d853c92db69bfee0acd0f8fd49..5781b8026a0c7aad4bb3c1f026a6af848a2b8d85 100644 (file)
@@ -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
index 7c8a8938713f52e953eb8d5007cdb2a6d3331b05..8fbd9528f32c763ccecb6d7e80031b06dcb15c91 100644 (file)
@@ -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:
index c66c3784380a7c67b42926f49f7fb135e66bf9d8..38c2421d3fec2c62eb74bc6df57fbd10f11f6553 100644 (file)
 
 #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 @@ 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;
 }
index b4420a991438aeaa5b9f13cd01b06c1e27cb29d1..605d9bdc0c9fd0ed758c3a83ae7c23e91326a77e 100644 (file)
@@ -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
 
index 288cb1892f0c85c9a77a60760d2fa72ce4a07a46..b192bb91b7c9257944e1990f45136121640520d9 100755 (executable)
@@ -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
index 442601851379c8ba5e91a46fad3d92dbafbdf6e7..16b1f388b24ce5af1229426647b9963aace3086a 100644 (file)
@@ -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' ---