Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed May 14, 2024
1 parent 307b16f commit a8a8f52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions attach/text_segment_transformer/agent-transformer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "spdlog/cfg/env.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"
#include <cstdlib>
#include <dlfcn.h>
Expand Down Expand Up @@ -45,6 +47,8 @@ extern "C" int __libc_start_main(int (*main)(int, char **, char **), int argc,

extern "C" void bpftime_agent_main(const gchar *data, gboolean *stay_resident)
{
auto logger = spdlog::stderr_color_mt("stderr");
spdlog::set_default_logger(logger);
spdlog::cfg::load_env_levels();
/* We don't want to our library to be unloaded after we return. */
*stay_resident = TRUE;
Expand Down
11 changes: 8 additions & 3 deletions runtime/agent/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "frida_attach_private_data.hpp"
#include "frida_uprobe_attach_impl.hpp"
#include "spdlog/common.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/stdout_sinks.h"
#include "syscall_trace_attach_impl.hpp"
#include "syscall_trace_attach_private_data.hpp"
#include <chrono>
Expand Down Expand Up @@ -72,7 +74,6 @@ extern "C" int __libc_start_main(int (*main)(int, char **, char **), int argc,
void (*fini)(void), void (*rtld_fini)(void),
void *stack_end)
{
SPDLOG_INFO("Entering bpftime agent");
orig_main_func = main;
using this_func_t = decltype(&__libc_start_main);
this_func_t orig = (this_func_t)dlsym(RTLD_NEXT, "__libc_start_main");
Expand All @@ -88,12 +89,17 @@ static void sig_handler_sigusr1(int sig)
SPDLOG_ERROR("Unable to detach: {}", err);
return;
}
shm_holder.global_shared_memory.remove_pid_from_alive_agent_set(getpid());
shm_holder.global_shared_memory.remove_pid_from_alive_agent_set(
getpid());
SPDLOG_DEBUG("Detaching done");
}

extern "C" void bpftime_agent_main(const gchar *data, gboolean *stay_resident)
{
auto logger = spdlog::stderr_color_mt("stderr");
logger->set_pattern("[%Y-%m-%d %H:%M:%S][%^%l%$][%t] %v");
spdlog::set_default_logger(logger);
SPDLOG_DEBUG("Entered bpftime_agent_main");
SPDLOG_DEBUG("Registering signal handler");
// We use SIGUSR1 to indicate the detaching
signal(SIGUSR1, sig_handler_sigusr1);
Expand Down Expand Up @@ -146,7 +152,6 @@ extern "C" void bpftime_agent_main(const gchar *data, gboolean *stay_resident)
return priv_data;
});
SPDLOG_INFO("Initializing agent..");
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S][%^%l%$][%t] %v");
/* We don't want to our library to be unloaded after we return. */
*stay_resident = TRUE;

Expand Down

0 comments on commit a8a8f52

Please sign in to comment.