Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.
Change the names of the functions to reflect the new name of the library.
Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.
Bug: 31919199
Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
diff --git a/libc/malloc_debug/Android.bp b/libc/malloc_debug/Android.bp
index 708c101..b071b90 100644
--- a/libc/malloc_debug/Android.bp
+++ b/libc/malloc_debug/Android.bp
@@ -13,9 +13,10 @@
stl: "libc++_static",
- static_libs: ["libc_logging"],
+ whole_static_libs: ["libasync_safe"],
include_dirs: ["bionic/libc"],
+
export_include_dirs: ["."],
sanitize: {
@@ -29,7 +30,6 @@
"-Werror",
"-Wno-error=format-zero-length",
],
-
}
// ==============================================================
@@ -61,9 +61,9 @@
},
static_libs: [
+ "libasync_safe",
"libbase",
"libc_malloc_debug_backtrace",
- "libc_logging",
],
multilib: {
@@ -89,7 +89,6 @@
"-fno-stack-protector",
"-Wno-error=format-zero-length",
],
-
}
// ==============================================================
@@ -118,7 +117,7 @@
whole_static_libs: ["libc_malloc_debug"],
local_include_dirs: ["tests"],
- include_dirs: ["bionic/libc"],
+ include_dirs: ["bionic/libc", "bionic/libc/async_safe/include"],
shared_libs: ["libbase"],
@@ -127,5 +126,4 @@
"-Werror",
"-Wno-error=format-zero-length",
],
-
}
diff --git a/libc/malloc_debug/backtrace.cpp b/libc/malloc_debug/backtrace.cpp
index 75a255c..88f5a1d 100644
--- a/libc/malloc_debug/backtrace.cpp
+++ b/libc/malloc_debug/backtrace.cpp
@@ -158,13 +158,13 @@
char* demangled_symbol = __cxa_demangle(symbol, nullptr, nullptr, nullptr);
const char* best_name = (demangled_symbol != nullptr) ? demangled_symbol : symbol;
- __libc_format_buffer(buf, sizeof(buf),
- " #%02zd pc %" PAD_PTR " %s (%s+%" PRIuPTR ")\n", frame_num,
+ async_safe_format_buffer(
+ buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s (%s+%" PRIuPTR ")\n", frame_num,
rel_pc, soname, best_name, frames[frame_num] - offset);
free(demangled_symbol);
} else {
- __libc_format_buffer(buf, sizeof(buf),
- " #%02zd pc %" PAD_PTR " %s\n", frame_num, rel_pc, soname);
+ async_safe_format_buffer(
+ buf, sizeof(buf), " #%02zd pc %" PAD_PTR " %s\n", frame_num, rel_pc, soname);
}
str += buf;
}
diff --git a/libc/malloc_debug/debug_log.h b/libc/malloc_debug/debug_log.h
index 4df0408..ed4b541 100644
--- a/libc/malloc_debug/debug_log.h
+++ b/libc/malloc_debug/debug_log.h
@@ -29,18 +29,18 @@
#ifndef MALLOC_DEBUG_LOG_H
#define MALLOC_DEBUG_LOG_H
-#include <private/libc_logging.h>
+#include <async_safe/log.h>
// =============================================================================
// log functions
// =============================================================================
#define debug_log(format, ...) \
- __libc_format_log(ANDROID_LOG_DEBUG, "malloc_debug", (format), ##__VA_ARGS__ )
+ async_safe_format_log(ANDROID_LOG_DEBUG, "malloc_debug", (format), ##__VA_ARGS__ )
#define error_log(format, ...) \
- __libc_format_log(ANDROID_LOG_ERROR, "malloc_debug", (format), ##__VA_ARGS__ )
+ async_safe_format_log(ANDROID_LOG_ERROR, "malloc_debug", (format), ##__VA_ARGS__ )
#define error_log_string(str) \
- __libc_write_log(ANDROID_LOG_ERROR, "malloc_debug", (str))
+ async_safe_write_log(ANDROID_LOG_ERROR, "malloc_debug", (str))
#define info_log(format, ...) \
- __libc_format_log(ANDROID_LOG_INFO, "malloc_debug", (format), ##__VA_ARGS__ )
+ async_safe_format_log(ANDROID_LOG_INFO, "malloc_debug", (format), ##__VA_ARGS__ )
#endif // MALLOC_DEBUG_LOG_H
diff --git a/libc/malloc_debug/tests/log_fake.cpp b/libc/malloc_debug/tests/log_fake.cpp
index 194d42b..fb64e3e 100644
--- a/libc/malloc_debug/tests/log_fake.cpp
+++ b/libc/malloc_debug/tests/log_fake.cpp
@@ -44,7 +44,7 @@
return g_fake_log_print;
}
-extern "C" int __libc_format_log(int priority, const char* tag, const char* format, ...) {
+extern "C" int async_safe_format_log(int priority, const char* tag, const char* format, ...) {
g_fake_log_print += std::to_string(priority) + ' ';
g_fake_log_print += tag;
g_fake_log_print += ' ';