[PATCH] [ASan] Print mmap errno/GetLastError in a readable and consistent way

Timur Iskhodzhanov timurrrr at google.com
Tue Mar 18 03:00:30 PDT 2014


Hi kcc,

See lib/sanitizer_common/sanitizer_posix.cc:67 as a good example:
  67     Report("ERROR: %s failed to allocate 0x%zx (%zd) bytes of %s: %d\n",
  68            SanitizerToolName, size, size, mem_type, reserrno);
Here the errno is separated by a colon.

In the trunk version, the other errors are printed like this:
  111    Report("ERROR: "
  112           "%s failed to allocate 0x%zx (%zd) bytes at address %zu (%d)\n",
  113           SanitizerToolName, size, size, fixed_addr, reserrno);

As you can see, one can easily misread this as if the errno in the parenthesis was the decimal representation of the address.
I think this is confusing and simply inconsistent, so this patch puts the colon in all the places.

Similarly, I explicitly prefix the Error Code on Windows with a string.

The 0x%zx -> %p on Windows is done because I was confused by the number of digits in this error a few times:
  ERROR: Failed to allocate 0x4010000 (67174400) bytes at 0x1fff0000, Error Code 203
I think it's safe to print out the full 8-digit `0x0401000` addresses when allocating large chunks of virtual memory.

http://llvm-reviews.chandlerc.com/D3107

Files:
  lib/sanitizer_common/sanitizer_posix.cc
  lib/sanitizer_common/sanitizer_win.cc

Index: lib/sanitizer_common/sanitizer_posix.cc
===================================================================
--- lib/sanitizer_common/sanitizer_posix.cc
+++ lib/sanitizer_common/sanitizer_posix.cc
@@ -92,7 +92,7 @@
   int reserrno;
   if (internal_iserror(p, &reserrno)) {
     Report("ERROR: "
-           "%s failed to allocate noreserve 0x%zx (%zd) bytes for '%s' (%d)\n",
+           "%s failed to allocate noreserve 0x%zx (%zd) bytes for '%s': %d\n",
            SanitizerToolName, size, size, mem_type, reserrno);
     CHECK("unable to mmap" && 0);
   }
@@ -109,7 +109,7 @@
   int reserrno;
   if (internal_iserror(p, &reserrno))
     Report("ERROR: "
-           "%s failed to allocate 0x%zx (%zd) bytes at address %zu (%d)\n",
+           "%s failed to allocate 0x%zx (%zd) bytes at address %zu: %d\n",
            SanitizerToolName, size, size, fixed_addr, reserrno);
   return (void *)p;
 }
@@ -124,7 +124,7 @@
   int reserrno;
   if (internal_iserror(p, &reserrno)) {
     Report("ERROR:"
-           " %s failed to allocate 0x%zx (%zd) bytes at address %zu (%d)\n",
+           " %s failed to allocate 0x%zx (%zd) bytes at address %zu: %d\n",
            SanitizerToolName, size, size, fixed_addr, reserrno);
     CHECK("unable to mmap" && 0);
   }
Index: lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -80,8 +80,8 @@
 void *MmapOrDie(uptr size, const char *mem_type) {
   void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
   if (rv == 0) {
-    Report("ERROR: Failed to allocate 0x%zx (%zd) bytes of %s\n",
-           size, size, mem_type);
+    Report("ERROR: Failed to allocate 0x%zx (%zd) bytes of %s, Error Code %d\n",
+           size, size, mem_type, GetLastError());
     CHECK("unable to mmap" && 0);
   }
   return rv;
@@ -101,7 +101,7 @@
   void *p = VirtualAlloc((LPVOID)fixed_addr, size,
       MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
   if (p == 0)
-    Report("ERROR: Failed to allocate 0x%zx (%zd) bytes at %p (%d)\n",
+    Report("ERROR: Failed to allocate %p (%zd) bytes at %p, Error Code %d\n",
            size, size, fixed_addr, GetLastError());
   return p;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3107.1.patch
Type: text/x-patch
Size: 2277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140318/8815afd1/attachment.bin>


More information about the llvm-commits mailing list