[compiler-rt] c3caba8 - DEBUGGING, print all allocations when PrintOnAllocation is set

Russell Gallop via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 04:22:51 PST 2021


Author: Russell Gallop
Date: 2021-01-21T16:37:48Z
New Revision: c3caba8b1f9fea74f5a54403440f6da47f51e0cd

URL: https://github.com/llvm/llvm-project/commit/c3caba8b1f9fea74f5a54403440f6da47f51e0cd
DIFF: https://github.com/llvm/llvm-project/commit/c3caba8b1f9fea74f5a54403440f6da47f51e0cd.diff

LOG: DEBUGGING, print all allocations when PrintOnAllocation is set

Added: 
    

Modified: 
    compiler-rt/lib/scudo/scudo_allocator.cpp
    compiler-rt/lib/scudo/scudo_flags.inc

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/scudo_allocator.cpp b/compiler-rt/lib/scudo/scudo_allocator.cpp
index dd07db32af00..bf351193d272 100644
--- a/compiler-rt/lib/scudo/scudo_allocator.cpp
+++ b/compiler-rt/lib/scudo/scudo_allocator.cpp
@@ -34,6 +34,7 @@
 
 #include <errno.h>
 #include <string.h>
+#include <cstdio>
 
 namespace __scudo {
 
@@ -707,7 +708,11 @@ void *scudoAllocate(uptr Size, uptr Alignment, AllocType Type) {
       return nullptr;
     reportAllocationAlignmentNotPowerOfTwo(Alignment);
   }
-  return SetErrnoOnNull(Instance.allocate(Size, Alignment, Type));
+  void * mem = SetErrnoOnNull(Instance.allocate(Size, Alignment, Type));
+  if (getFlags()->PrintOnAllocation) {
+    printf("Allocating memory at %p, size %d\n", mem, Size);
+  }
+  return mem;
 }
 
 void scudoDeallocate(void *Ptr, uptr Size, uptr Alignment, AllocType Type) {

diff  --git a/compiler-rt/lib/scudo/scudo_flags.inc b/compiler-rt/lib/scudo/scudo_flags.inc
index c124738c1f3a..38bc1cfa55c2 100644
--- a/compiler-rt/lib/scudo/scudo_flags.inc
+++ b/compiler-rt/lib/scudo/scudo_flags.inc
@@ -46,3 +46,6 @@ SCUDO_FLAG(bool, DeleteSizeMismatch, true,
 
 SCUDO_FLAG(bool, ZeroContents, false,
           "Zero chunk contents on allocation and deallocation.")
+
+SCUDO_FLAG(bool, PrintOnAllocation, false,
+          "Print out pointer and size when allocating")


        


More information about the llvm-commits mailing list