From befa74a7e1ab3f16892851b476c1ffc8a03d6e0d Mon Sep 17 00:00:00 2001 From: zhang-cui11 Date: Tue, 8 Nov 2022 17:33:10 +0800 Subject: [PATCH] add musl log Signed-off-by: zhang-cui11 --- musl_src.gni | 2 ++ porting/linux/user/src/hook/musl_preinit.c | 9 +++++++-- porting/linux/user/src/internal/hilog_adapter.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/musl_src.gni b/musl_src.gni index 36d59652..61400c6b 100644 --- a/musl_src.gni +++ b/musl_src.gni @@ -2140,6 +2140,8 @@ musl_src_porting_file = [ ] musl_inc_hook_files = [ + "porting/linux/user/src/internal/hilog_adapter.h", + "porting/linux/user/src/internal/musl_log.h", "porting/linux/user/src/hook/memory_tag.h", "porting/linux/user/src/hook/musl_malloc_dispatch_table.h", "porting/linux/user/src/hook/musl_malloc_dispatch.h", diff --git a/porting/linux/user/src/hook/musl_preinit.c b/porting/linux/user/src/hook/musl_preinit.c index 5ea97c67..385f3536 100644 --- a/porting/linux/user/src/hook/musl_preinit.c +++ b/porting/linux/user/src/hook/musl_preinit.c @@ -34,6 +34,7 @@ which need be escaped. #include #include #include +#include "musl_log.h" void* ohos_malloc_hook_init_function(size_t bytes); @@ -252,7 +253,7 @@ void* load_malloc_hook_shared_library(const char* shared_lib, const char* prefix shared_library_handle = dlopen(shared_lib, RTLD_NOW | RTLD_LOCAL); if (shared_library_handle == NULL) { - printf("Unable to open shared library %s: %s\n", shared_lib, dlerror()); + MUSL_LOGI("HiProfiler, Unable to open shared library %{public}s: %{public}s.", shared_lib, dlerror()); return NULL; } @@ -260,7 +261,7 @@ void* load_malloc_hook_shared_library(const char* shared_lib, const char* prefix dlclose(shared_library_handle); shared_library_handle = NULL; } - // printf("load_malloc_hook_shared_library success new version test\n"); + MUSL_LOGI("HiProfiler, load_malloc_hook_shared_library success."); return shared_library_handle; } @@ -342,6 +343,7 @@ void* ohos_malloc_hook_init_function(size_t bytes) { if (atomic_exchange(&__musl_libc_globals.current_dispatch_table, (volatile const long long)NULL)) { pthread_t thread_id; + MUSL_LOGI("HiProfiler, ohos_malloc_hook_init_function, pthread_create."); if (pthread_create(&thread_id, NULL, init_ohos_malloc_hook, NULL) != 0) { // __musl_log(__MUSL_LOG_ERROR, "%s: ohos_malloc_hook: failed to pthread_create\n", getprogname()); } else if (pthread_detach(thread_id) != 0) { @@ -364,6 +366,7 @@ static void __install_malloc_hook() volatile void* shared_library_handle = (volatile void* )atomic_load_explicit(&ohos_malloc_hook_shared_library, memory_order_acquire); if (shared_library_handle == NULL) { + MUSL_LOGI("HiProfiler, __install_malloc_hook __hook_mode %{public}d", __hook_mode); if (__hook_mode == STEP_HOOK_MODE) { atomic_store_explicit(&__musl_libc_globals.current_dispatch_table, (volatile const long long)&__ohos_malloc_hook_init_dispatch, memory_order_seq_cst); atomic_store_explicit(&ohos_malloc_hook_shared_library, (volatile long long)-1, memory_order_seq_cst); @@ -417,6 +420,7 @@ __attribute__((constructor(1))) static void __musl_initialize() __set_default_malloc(); char hook_process_path[MAX_PROC_NAME_SIZE + 1] = {0}; parse_hook_variable(&__hook_mode, hook_process_path, sizeof(hook_process_path) - 1); + MUSL_LOGI("HiProfiler, __musl_initialize %{public}d", __hook_mode); if (__hook_mode == STARTUP_HOOK_MODE) { char proc_name[MAX_PROC_NAME_SIZE + 1] = {0}; if (get_proc_name(getpid(), proc_name, sizeof(proc_name) - 1)) { @@ -427,6 +431,7 @@ __attribute__((constructor(1))) static void __musl_initialize() } else { file_name = proc_name; } + MUSL_LOGI("HiProfiler, current proc %{public}s, , target proc %{public}s", file_name, hook_process_path); if (strncmp(file_name, hook_process_path, strlen(hook_process_path)) == 0) { atomic_store_explicit(&__hook_enable_hook_flag, (volatile bool)true, memory_order_seq_cst); init_ohos_malloc_hook(); diff --git a/porting/linux/user/src/internal/hilog_adapter.h b/porting/linux/user/src/internal/hilog_adapter.h index b0225117..707b2693 100644 --- a/porting/linux/user/src/internal/hilog_adapter.h +++ b/porting/linux/user/src/internal/hilog_adapter.h @@ -20,6 +20,8 @@ #include #include +#define hidden __attribute__((visibility("hidden"))) + // Log type typedef enum { LOG_TYPE_MIN = 0, -- GitLab