[msan] Print both shadow and user address
authorVitaly Buka <vitalybuka@google.com>
Wed, 6 Oct 2021 20:10:35 +0000 (13:10 -0700)
committerVitaly Buka <vitalybuka@google.com>
Fri, 8 Oct 2021 00:56:46 +0000 (17:56 -0700)
before:
00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00
Shadow map of [0x211000000005, 0x21100000012e), 297 bytes:
now:
0x2f60d213ac10[0x7f60d213ac10]  00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00
Shadow map [0x211000000005, 0x21100000012e) of [0x711000000005, 0x711000000135), 297 bytes:

Differential Revision: https://reviews.llvm.org/D111261

compiler-rt/lib/msan/msan.cpp
compiler-rt/lib/msan/msan_report.cpp
compiler-rt/test/msan/msan_check_mem_is_initialized.cpp
compiler-rt/test/msan/msan_dump_shadow.cpp
compiler-rt/test/msan/msan_print_shadow.cpp
compiler-rt/test/msan/msan_print_shadow2.cpp
compiler-rt/test/msan/msan_print_shadow3.cpp

index 3c1ae17c7bb34797a621d745f599840640cc94e6..2202e344692137aaf494a6d6ac23329f293643a0 100644 (file)
@@ -515,6 +515,7 @@ void __msan_dump_shadow(const void *x, uptr size) {
   }
 
   unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x);
+  Printf("%p[%p]  ", s, x);
   for (uptr i = 0; i < size; i++)
     Printf("%x%x ", s[i] >> 4, s[i] & 0xf);
   Printf("\n");
index 3a7a237dea0705ed69954d894ab9d9d195b18e05..ff3e38c7db9ed8c36931d28b13c8d8dd17c0d093 100644 (file)
@@ -201,15 +201,18 @@ void DescribeMemoryRange(const void *x, uptr size) {
 
   Decorator d;
   Printf("%s", d.Warning());
-  Printf("Shadow map of [%p, %p), %zu bytes:\n",
+  uptr start_x = reinterpret_cast<uptr>(x);
+  Printf("Shadow map [%p, %p) of [%p, %p), %zu bytes:\n",
          reinterpret_cast<void *>(start), reinterpret_cast<void *>(end),
-         end - start);
+         reinterpret_cast<void *>(start_x),
+         reinterpret_cast<void *>(start_x + end - start), end - start);
   Printf("%s", d.Default());
   while (s < e) {
     // Line start.
     if (pos % 16 == 0) {
       for (int i = 0; i < 4; ++i) origin_ids[i] = -1;
-      Printf("%p:", reinterpret_cast<void *>(s));
+      Printf("%p[%p]:", reinterpret_cast<void *>(s),
+             reinterpret_cast<void *>(start_x - start + s));
     }
     // Group start.
     if (pos % 4 == 0) {
index 81f7895f7aea36beac2092900a18200b02f1f458..81752291c7c5c9f0c39e35267fc813fc3f23993e 100644 (file)
@@ -16,7 +16,7 @@ int main(void) {
 #ifdef POSITIVE
   __msan_check_mem_is_initialized(p + 5, 20);
   // CHECK: Uninitialized bytes in __msan_check_mem_is_initialized at offset 5 inside [0x{{.*}}, 20)
-  // CHECK-VERBOSE: Shadow map of [0x{{.*}}, 0x{{.*}}), 20 bytes:
+  // CHECK-VERBOSE: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 20 bytes:
   // CHECK-VERBOSE: 0x{{.*}}: ..000000 0000ffff 00000000 00000000
   // CHECK-VERBOSE: 0x{{.*}}: 00000000 00...... ........ ........
 
index 543fa7013223945bd79d2091b5092dace26d7ce5..48b84ef50f723f7ed4b85c5794e23dcea7bf1a19 100644 (file)
@@ -18,5 +18,5 @@ int main(void) {
   return 0;
 }
 
-// CHECK: ff ff ff ff ff
-// CHECK: 00 00 00
+// CHECK: 0x{{[0-9a-f]+}}[0x{{[0-9a-f]+}}]  ff ff ff ff ff
+// CHECK: 0x{{[0-9a-f]+}}[0x{{[0-9a-f]+}}]  00 00 00
index bdee3102c1ccb0782d05a87ce74de565066966c5..2782fcd83ed7d4a4251d1d0040d55c1271d914c9 100644 (file)
@@ -52,7 +52,7 @@ int main(void) {
   return 0;
 }
 
-// CHECK: Shadow map of [{{.*}}), 297 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 297 bytes:
 
 // CHECK-NO-ORIGINS: 0x{{.*}}: ..00ffff 00000000 ffffffff ffffffff
 // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
index 5095081c9655d70c47748e78c43539c9ca2be810..05c1cb12bef8cb359fbe420955da84227a643e45 100644 (file)
@@ -22,28 +22,28 @@ int main(void) {
   return 0;
 }
 
-// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes:
 // CHECK-NO-ORIGINS:   0x{{.*}}: ff...... ........ ........ ........
 // CHECK-ORIGINS:   0x{{.*}}: ff...... ........ ........ ........  |A . . .|
 // CHECK-ORIGINS: Origin A (origin_id {{.*}}):
 
-// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes:
 // CHECK-NO-ORIGINS:   0x{{.*}}: ..ff.... ........ ........ ........
 // CHECK-ORIGINS:   0x{{.*}}: ..ff.... ........ ........ ........  |A . . .|
 // CHECK-ORIGINS: Origin A (origin_id {{.*}}):
 
-// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes:
 // CHECK-NO-ORIGINS:   0x{{.*}}: ......ff ........ ........ ........
 // CHECK-ORIGINS:   0x{{.*}}: ......ff ........ ........ ........  |A . . .|
 // CHECK-ORIGINS: Origin A (origin_id {{.*}}):
 
-// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes:
 // CHECK-NO-ORIGINS:   0x{{.*}}: ......ff ........ ........ ........
 // CHECK-ORIGINS:   0x{{.*}}: ......ff ........ ........ ........  |A . . .|
 // CHECK-ORIGINS: Origin A (origin_id {{.*}}):
 
-// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 0 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 0 bytes:
 
-// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 3 bytes:
+// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 3 bytes:
 // CHECK-NO-ORIGINS:   0x{{.*}}: 000000.. ........ ........ ........
 // CHECK-ORIGINS:   0x{{.*}}: 000000.. ........ ........ ........  |. . . .|
index 410755e5dbaaa6de420cb08d8118c681ea5e7d70..d9f55a6eef9a893f32c895161307a998f87d4b3b 100644 (file)
@@ -12,5 +12,5 @@ int main(void) {
   return 0;
 }
 
-// CHECK: Shadow map of [{{.*}}), 4 bytes:
+// CHECK: Shadow map [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}) of [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}), 4 bytes:
 // CHECK: 0x{{.*}}: 77654321 ........ ........ ........