diff options
author | Christopher Ferris <cferris@google.com> | 2018-06-13 10:46:34 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-06-15 12:29:13 -0700 |
commit | 2e1a40a2033088e7f2e78424a8b163d3fcf84b1b (patch) | |
tree | 51ec5d1703f6225d6dc58ad5b01f9c728e4f2883 /libc/malloc_debug/malloc_debug.cpp | |
parent | 2583b0adb201233313bbe02f665f5c623f2c5a30 (diff) |
Change heap dump format slightly.
Bump the version from v1.1 to v1.2 and add a build fingerprint line.
Update the heap dump documentation to match the new format and reflect
what made it in P and what made it in Q.
Update the unit tests for this change.
Add -O0 to unit test code to make it easier to debug.
Add an external function that can be used by the framework code
so that there is only one way to dump the heap.
Bug: 110095681
Test: Ran unit tests.
Test: Did a dump of a real process and verified fingerprint.
Test: Did a dump of a process without malloc debug enabled.
Change-Id: I769a476cbeaf4c85c5d75bd6d6385f0e3add948c
Merged-In: I769a476cbeaf4c85c5d75bd6d6385f0e3add948c
(cherry picked from commit c84a2a2601a4112ca6e43a33defb989c1da8c2f4)
Diffstat (limited to 'libc/malloc_debug/malloc_debug.cpp')
-rw-r--r-- | libc/malloc_debug/malloc_debug.cpp | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp index 836c33b86..1e7086c7d 100644 --- a/libc/malloc_debug/malloc_debug.cpp +++ b/libc/malloc_debug/malloc_debug.cpp @@ -38,6 +38,7 @@ #include <vector> #include <android-base/file.h> +#include <android-base/properties.h> #include <android-base/stringprintf.h> #include <private/bionic_malloc_dispatch.h> @@ -69,9 +70,10 @@ __BEGIN_DECLS bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child, const char* options); void debug_finalize(); -bool debug_dump_heap(const char* file_name); +void debug_dump_heap(const char* file_name); void debug_get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size); +bool debug_write_malloc_leak_info(FILE* fp); ssize_t debug_malloc_backtrace(void* pointer, uintptr_t* frames, size_t frame_count); void debug_free_malloc_leak_info(uint8_t* info); size_t debug_malloc_usable_size(void* pointer); @@ -813,28 +815,11 @@ void* debug_valloc(size_t size) { static std::mutex g_dump_lock; -bool debug_dump_heap(const char* file_name) { - ScopedDisableDebugCalls disable; - - std::lock_guard<std::mutex> guard(g_dump_lock); - - FILE* fp = fopen(file_name, "w+e"); - if (fp == nullptr) { - error_log("Unable to create file: %s", file_name); - return false; - } - error_log("Dumping to file: %s\n", file_name); +static void write_dump(FILE* fp) { + fprintf(fp, "Android Native Heap Dump v1.2\n\n"); - if (!(g_debug->config().options() & BACKTRACE)) { - fprintf(fp, "Native heap dump not available. To enable, run these commands (requires root):\n"); - fprintf(fp, "# adb shell stop\n"); - fprintf(fp, "# adb shell setprop libc.debug.malloc.options backtrace\n"); - fprintf(fp, "# adb shell start\n"); - fclose(fp); - return false; - } - - fprintf(fp, "Android Native Heap Dump v1.1\n\n"); + std::string fingerprint = android::base::GetProperty("ro.build.fingerprint", "unknown"); + fprintf(fp, "Build fingerprint: '%s'\n\n", fingerprint.c_str()); PointerData::DumpLiveToFile(fp); @@ -846,6 +831,33 @@ bool debug_dump_heap(const char* file_name) { fprintf(fp, "%s", content.c_str()); } fprintf(fp, "END\n"); - fclose(fp); +} + +bool debug_write_malloc_leak_info(FILE* fp) { + ScopedDisableDebugCalls disable; + + std::lock_guard<std::mutex> guard(g_dump_lock); + + if (!(g_debug->config().options() & BACKTRACE)) { + return false; + } + + write_dump(fp); return true; } + +void debug_dump_heap(const char* file_name) { + ScopedDisableDebugCalls disable; + + std::lock_guard<std::mutex> guard(g_dump_lock); + + FILE* fp = fopen(file_name, "w+e"); + if (fp == nullptr) { + error_log("Unable to create file: %s", file_name); + return; + } + + error_log("Dumping to file: %s\n", file_name); + write_dump(fp); + fclose(fp); +} |