From 611ff5aef937d705e8253d50fcd3297783e74681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=BE=AE?= <1067852565@qq.com> Date: Sat, 10 Aug 2024 03:25:28 +1000 Subject: [PATCH] Fix: debug log cannot be print when build in debug mode (#317) * fix: the spdlog debug is not enable on debujg mode * fix when not spec INFO * fix get memory size config from env --- CMakeLists.txt | 9 +++++++++ Makefile | 5 +++-- attach/CMakeLists.txt | 5 ----- runtime/src/bpftime_shm_internal.cpp | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24b2b282..1c22e23b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,6 +133,15 @@ endif() # spdlog add_subdirectory(third_party/spdlog) +if(NOT DEFINED SPDLOG_ACTIVE_LEVEL) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG) + else() + add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO) + endif() +endif() + + set(SPDLOG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/include) diff --git a/Makefile b/Makefile index 214e7030..55ebb63d 100644 --- a/Makefile +++ b/Makefile @@ -60,17 +60,18 @@ build-wo-libbpf: ## build the package with iouring extension release: ## build the release version cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \ - -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO + -DBUILD_BPFTIME_DAEMON=1 cmake --build build --config RelWithDebInfo --target install -j$(JOBS) release-with-llvm-jit: ## build the package, with llvm-jit cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \ -DBPFTIME_LLVM_JIT=1 + -DBUILD_BPFTIME_DAEMON=1 cmake --build build --config RelWithDebInfo --target install -j$(JOBS) release-with-static-lib: ## build the release version with libbpftime archive cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \ - -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO -DBPFTIME_BUILD_STATIC_LIB=ON + -DBPFTIME_BUILD_STATIC_LIB=ON cmake --build build --config RelWithDebInfo --target install -j$(JOBS) build-vm: ## build only the core library diff --git a/attach/CMakeLists.txt b/attach/CMakeLists.txt index 4d9fa2fe..aa570841 100644 --- a/attach/CMakeLists.txt +++ b/attach/CMakeLists.txt @@ -1,8 +1,3 @@ -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG) - else() - add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO) - endif() add_subdirectory(base_attach_impl) add_subdirectory(frida_uprobe_attach_impl) if(UNIX AND NOT APPLE) diff --git a/runtime/src/bpftime_shm_internal.cpp b/runtime/src/bpftime_shm_internal.cpp index 8e206f1c..35dbfc6c 100644 --- a/runtime/src/bpftime_shm_internal.cpp +++ b/runtime/src/bpftime_shm_internal.cpp @@ -546,7 +546,8 @@ bool bpftime_shm::is_exist_fake_fd(int fd) const bpftime_shm::bpftime_shm(const char *shm_name, shm_open_type type) : open_type(type) { - size_t memory_size = get_agent_config().shm_memory_size; + // Get the config from env because the shared memory is not initialized + size_t memory_size = get_agent_config_from_env().shm_memory_size; if (type == shm_open_type::SHM_OPEN_ONLY) { SPDLOG_DEBUG("start: bpftime_shm for client setup"); // open the shm