From 377adea81ccd56bfbf684db2e70ab7d261870119 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Sat, 8 Oct 2022 05:06:52 +0000 Subject: [PATCH 1/2] libutils: DEBUG_* modes compile forever I've seen these fixed before, so we compile the debug modes now. Bug: 244325464 Test: 'm libutils_test_compile' Change-Id: I4271909e81893ad448bc46b8a3a567a84c40f8a3 --- libutils/Android.bp | 36 ++++++++++++++++++++++++++++++------ libutils/Looper.cpp | 4 ++++ libutils/RefBase.cpp | 4 ++++ libutils/Tokenizer.cpp | 3 ++- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/libutils/Android.bp b/libutils/Android.bp index c744b5316..26e159793 100644 --- a/libutils/Android.bp +++ b/libutils/Android.bp @@ -58,10 +58,6 @@ cc_defaults { vendor_available: true, product_available: true, recovery_available: true, - vndk: { - enabled: true, - support_system_process: true, - }, host_supported: true, cflags: [ @@ -126,8 +122,8 @@ cc_defaults { }, } -cc_library { - name: "libutils", +cc_defaults { + name: "libutils_impl_defaults", defaults: ["libutils_defaults"], native_bridge_supported: true, @@ -180,12 +176,40 @@ cc_library { }, } +cc_library { + name: "libutils", + defaults: ["libutils_impl_defaults"], + + vndk: { + enabled: true, + support_system_process: true, + }, +} + +cc_library { + name: "libutils_test_compile", + defaults: ["libutils_impl_defaults"], + + cflags: [ + "-DCALLSTACKS=1", + "-DDEBUG_POLL_AND_WAKE=1", + "-DDEBUG_REFS=1", + "-DDEBUG_TOKENIZER=1", + ], + + visibility: [":__subpackages__"], +} + cc_library { name: "libutilscallstack", defaults: ["libutils_defaults"], // TODO(b/153609531): remove when no longer needed. native_bridge_supported: true, min_sdk_version: "29", + vndk: { + enabled: true, + support_system_process: true, + }, srcs: [ "CallStack.cpp", diff --git a/libutils/Looper.cpp b/libutils/Looper.cpp index 1a3f34bed..402e43cc6 100644 --- a/libutils/Looper.cpp +++ b/libutils/Looper.cpp @@ -8,10 +8,14 @@ //#define LOG_NDEBUG 0 // Debugs poll and wake interactions. +#ifndef DEBUG_POLL_AND_WAKE #define DEBUG_POLL_AND_WAKE 0 +#endif // Debugs callback registration and invocation. +#ifndef DEBUG_CALLBACKS #define DEBUG_CALLBACKS 0 +#endif #include diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index ed5b2a958..b5b3efd1a 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -21,9 +21,11 @@ #include +#include #include #include +#include #include @@ -32,7 +34,9 @@ #endif // Compile with refcounting debugging enabled. +#ifndef DEBUG_REFS #define DEBUG_REFS 0 +#endif // The following three are ignored unless DEBUG_REFS is set. diff --git a/libutils/Tokenizer.cpp b/libutils/Tokenizer.cpp index 98dd2fda5..c3ec1652b 100644 --- a/libutils/Tokenizer.cpp +++ b/libutils/Tokenizer.cpp @@ -21,9 +21,10 @@ #include #include +#ifndef DEBUG_TOKENIZER // Enables debug output for the tokenizer. #define DEBUG_TOKENIZER 0 - +#endif namespace android { From b7412c8cd6c1428183866b47052131fc694837fa Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Sat, 8 Oct 2022 05:07:52 +0000 Subject: [PATCH 2/2] libutils: RefBase DEBUG_REF love Done here: - path saved to a useable location on host - path always printed (for visibility for new users) - open(.., 666) - That's '01204' not '0644' oops Future considerations: - make defines constexpr instead of ifdef - copy malloc hook design to avoid needing to recompile code - make libutilscallstack default on host - run libutils tests, not just test compile debug mode - code incorrectly prints ref 'doesn't exist' seems it's gotten out of sync, but still good enough to use stacktraces Bug: 244325464 Test: manual Change-Id: I732e5b8aec3cd946ef3559a2a814caf693846cc0 --- libutils/RefBase.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index b5b3efd1a..ab122c732 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -49,7 +49,11 @@ // folder where stack traces are saved when DEBUG_REFS is enabled // this folder needs to exist and be writable +#ifdef __ANDROID__ #define DEBUG_REFS_CALLSTACK_PATH "/data/debug" +#else +#define DEBUG_REFS_CALLSTACK_PATH "." +#endif // log all reference counting operations #define PRINT_REFS 0 @@ -324,11 +328,11 @@ public: char name[100]; snprintf(name, sizeof(name), DEBUG_REFS_CALLSTACK_PATH "/%p.stack", this); - int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 644); + int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 0644); if (rc >= 0) { (void)write(rc, text.string(), text.length()); close(rc); - ALOGD("STACK TRACE for %p saved in %s", this, name); + ALOGI("STACK TRACE for %p saved in %s", this, name); } else ALOGE("FAILED TO PRINT STACK TRACE for %p in %s: %s", this, name, strerror(errno));