[compiler-rt] d4602f7 - sanitizer_common: make parsing of smaps testable (NFC)

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 04:44:32 PDT 2021


Author: Dmitry Vyukov
Date: 2021-10-29T13:44:28+02:00
New Revision: d4602f759a97333ff6f1470a1658f048cac6c35c

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

LOG: sanitizer_common: make parsing of smaps testable (NFC)

Move parsing of /proc/self/smaps into a separate function
so that it can be tested.

Depends on D112788.

Reviewed By: melver

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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 9f034b0623f7d..986b674b3a951 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -198,6 +198,8 @@ typedef void (*fill_profile_f)(uptr start, uptr rss, bool file,
 // |cb| is a tool-specific callback that fills the |stats| array containing
 // |stats_size| elements.
 void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size);
+void ParseUnixMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size,
+                            const char *smaps, uptr smaps_len);
 
 // Simple low-level (mmap-based) allocator for internal use. Doesn't have
 // constructor, so all instances of LowLevelAllocator should be

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp
index 1b7dd46d8de4f..dd46540402ec8 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp
@@ -151,6 +151,12 @@ void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {
   uptr smaps_len = 0;
   if (!ReadFileToBuffer("/proc/self/smaps", &smaps, &smaps_cap, &smaps_len))
     return;
+  ParseUnixMemoryProfile(cb, stats, stats_size, smaps, smaps_len);
+  UnmapOrDie(smaps, smaps_cap);
+}
+
+void ParseUnixMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size,
+                            const char *smaps, uptr smaps_len) {
   uptr start = 0;
   bool file = false;
   const char *pos = smaps;
@@ -166,7 +172,6 @@ void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {
     }
     while (*pos++ != '\n') {}
   }
-  UnmapOrDie(smaps, smaps_cap);
 }
 
 } // namespace __sanitizer


        


More information about the llvm-commits mailing list