Skip to content

Commit

Permalink
make error message more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwei37 committed Aug 10, 2024
1 parent 26a5794 commit 778dd4a
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ third_party/frida
third_party/phaole
third_party/phaole1
output_metrics.json
perf.data
perf.data.old
40 changes: 21 additions & 19 deletions attach/frida_uprobe_attach_impl/src/frida_attach_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ static std::string get_executable_path()
{
char exec_path[PATH_MAX] = { 0 };

#if __linux__
ssize_t len =
readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
if (len != -1) {
exec_path[len] = '\0'; // Null-terminate the string
SPDLOG_INFO("Executable path: {}", exec_path);
} else {
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
}
#elif __APPLE__
pid_t pid = getpid();
if (proc_pidpath(pid, exec_path, sizeof(exec_path)) > 0) {
SPDLOG_INFO("Executable path: {}", exec_path);
} else {
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
}
#endif
#if __linux__
ssize_t len =
readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
if (len != -1) {
exec_path[len] = '\0'; // Null-terminate the string
SPDLOG_INFO("Executable path: {}", exec_path);
} else {
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
}
#elif __APPLE__
pid_t pid = getpid();
if (proc_pidpath(pid, exec_path, sizeof(exec_path)) > 0) {
SPDLOG_INFO("Executable path: {}", exec_path);
} else {
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
}
#endif
return exec_path;
}
namespace bpftime
Expand All @@ -47,8 +47,10 @@ resolve_function_addr_by_module_offset(const std::string_view &module_name,
get_module_base_addr(std::string(module_name).c_str());
}
if (!module_base_addr) {
SPDLOG_ERROR("Failed to find module base address for {}",
module_name);
// It's not a bug, it might be attach to a unrelated process
// when using the LD_PRELOAD
SPDLOG_INFO("Failed to find module base address for {}",
module_name);
return nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ int frida_attach_impl::create_attach_with_ebpf_callback(
}
}
if (!ok) {
SPDLOG_ERROR(
SPDLOG_INFO(
"Unable to attach: module name {} doesn't exist in current process's memory maps",
sub.module_name);
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all: benchmark test
test: test.c
gcc test.c -O3 -lpthread -o test
gcc test.c -g -O3 -lpthread -o test

# test with the files in bpf-loader
TEST_CASES_DIRS=$(filter-out $(SKIP_TESTS),$(shell ls -l $(./) | grep ^d | awk '{print $$9}'))
Expand Down
4 changes: 2 additions & 2 deletions runtime/agent/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ extern "C" void bpftime_agent_main(const gchar *data, gboolean *stay_resident)
res = ctx_holder.ctx.init_attach_ctx_from_handlers(
bpftime_get_agent_config());
if (res != 0) {
SPDLOG_ERROR("Failed to initialize attach context");
SPDLOG_INFO("Failed to initialize attach context, exiting..");
return;
}
} catch (std::exception &ex) {
SPDLOG_ERROR("Unable to instantiate handlers: {}", ex.what());
SPDLOG_ERROR("Unable to instantiate handlers with error: {}", ex.what());
return;
}
SPDLOG_INFO("Attach successfully");
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/attach/bpf_attach_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int bpf_attach_ctx::init_attach_ctx_from_handlers(
if (int err = instantiate_handler_at(manager, i, stk,
config);
err < 0) {
SPDLOG_ERROR("Failed to instantiate handler {}",
SPDLOG_INFO("Failed to instantiate handler {}",
i);
return err;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ int bpf_attach_ctx::instantiate_handler_at(const handler_manager *manager,
}
if (int err = instantiate_bpf_link_handler_at(id, link_handler);
err < 0) {
SPDLOG_ERROR(
SPDLOG_DEBUG(
"Unable to instantiate bpf link handler {}: {}",
id, err);
return err;
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/bpftime_prog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ using namespace std;
namespace bpftime
{


thread_local std::optional<uint64_t> current_thread_bpf_cookie;


bpftime_prog::bpftime_prog(const struct ebpf_inst *insn, size_t insn_cnt,
const char *name)
: name(name)
{
SPDLOG_DEBUG("Creating bpftime_prog with name {}", name);
insns.assign(insn, insn + insn_cnt);
vm = ebpf_create();
ebpf_toggle_bounds_check(vm, false);
// Disable bounds check because we have no implementation yet
// ebpf_toggle_bounds_check(vm, false);
ebpf_set_lddw_helpers(vm, map_ptr_by_fd, nullptr, map_val, nullptr,
nullptr);
}
Expand Down Expand Up @@ -111,7 +110,8 @@ int bpftime_prog::bpftime_prog_register_raw_helper(
return ebpf_register(vm, info.index, info.name.c_str(), info.fn);
}

int bpftime_prog::load_aot_object(const std::vector<uint8_t> &buf) {
int bpftime_prog::load_aot_object(const std::vector<uint8_t> &buf)
{
ebpf_jit_fn res = ebpf_load_aot_object(vm, buf.data(), buf.size());
if (res == nullptr) {
SPDLOG_ERROR("Failed to load aot object");
Expand Down
4 changes: 4 additions & 0 deletions runtime/syscall-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ target_link_libraries(bpftime-syscall-server PUBLIC
-lm
-ldl
spdlog::spdlog)

add_dependencies(bpftime-syscall-server spdlog::spdlog)

if(${BPFTIME_BUILD_WITH_LIBBPF})
target_include_directories(bpftime-syscall-server
PUBLIC
Expand All @@ -32,10 +34,12 @@ target_include_directories(bpftime-syscall-server
${SPDLOG_INCLUDE}
)
endif()

set_target_properties(bpftime-syscall-server PROPERTIES CXX_STANDARD 20 LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/syscall-server.version)
if(UNIX AND NOT APPLE)
target_link_options(bpftime-syscall-server PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/syscall-server.version)
endif()

if(${ENABLE_EBPF_VERIFIER})
add_dependencies(bpftime-syscall-server bpftime-verifier)
target_link_libraries(bpftime-syscall-server PRIVATE bpftime-verifier)
Expand Down
18 changes: 0 additions & 18 deletions tools/bpftimetool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,3 @@ SPDLOG_LEVEL=Debug ~/.bpftime/bpftimetool import /home/yunwei/bpftime/tools/bpft
[2023-10-23 19:02:04.956] [info] import handler type bpf_perf_event_handler fd 5
INFO [99712]: Global shm destructed
```

## Run program with bpftime

```console
$ SPDLOG_LEVEL=Debug bpftime start ./example/minimal/victim
[2023-10-23 19:03:26.105] [info] Entering bpftime agent
[2023-10-23 19:03:26.106] [info] Global shm constructed. shm_open_type 1 for bpftime_maps_shm
[2023-10-23 19:03:26.106] [info] Initializing agent..
[2023-10-23 19:03:26][info][99986] Executable path: /home/yunwei/bpftime/example/minimal/victim
[2023-10-23 19:03:26][info][99986] Attached 1 uprobe programs to function 5590e1d41169
[2023-10-23 19:03:26][info][99986] Attach successfully
target_func called.
target_func
target_func called.
target_func
target_func called.
target_func
```
2 changes: 1 addition & 1 deletion vm/compat/include/bpftime_vm_compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class bpftime_vm_impl {
*/
virtual bool toggle_bounds_check(bool enable)
{
SPDLOG_WARN("Not implemented yet: toggle_bounds_check");
SPDLOG_DEBUG("Not implemented yet: toggle_bounds_check");
return false;
}
/**
Expand Down

0 comments on commit 778dd4a

Please sign in to comment.