diff --git a/CMakeLists.txt b/CMakeLists.txt index 035b4aa4d599..bbbac55f7ff8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,21 +145,6 @@ endif() if(POLICY CMP0075) cmake_policy(SET CMP0075 NEW) endif() -if(STATIC_BPF_BCC) - set(CMAKE_REQUIRED_LIBRARIES bcc bcc_bpf bpf elf z) -else() - set(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_LIBRARIES} ${LIBBPF_LIBRARIES}) -endif(STATIC_BPF_BCC) -get_filename_component(LIBBCC_LIBDIR ${LIBBCC_LIBRARIES} DIRECTORY) -set(CMAKE_REQUIRED_LINK_OPTIONS -L${LIBBCC_LIBDIR}) - -check_symbol_exists(bcc_elf_foreach_sym "${LIBBCC_INCLUDE_DIRS}/bcc/bcc_elf.h" HAVE_BCC_ELF_FOREACH_SYM) -check_symbol_exists(bpf_attach_kfunc "${LIBBCC_INCLUDE_DIRS}/bcc/libbpf.h" HAVE_BCC_KFUNC) -check_symbol_exists(bcc_usdt_addsem_probe "${LIBBCC_INCLUDE_DIRS}/bcc/bcc_usdt.h" HAVE_BCC_USDT_ADDSEM) -check_symbol_exists(bcc_procutils_which_so "${LIBBCC_INCLUDE_DIRS}/bcc/bcc_proc.h" HAVE_BCC_WHICH_SO) - -set(CMAKE_REQUIRED_LIBRARIES) -set(CMAKE_REQUIRED_LINK_OPTIONS) if(${LIBBFD_FOUND} AND ${LIBOPCODES_FOUND}) set(HAVE_BFD_DISASM TRUE) @@ -215,38 +200,6 @@ if(HAVE_NAME_TO_HANDLE_AT) set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_NAME_TO_HANDLE_AT=1) endif(HAVE_NAME_TO_HANDLE_AT) -if(HAVE_BCC_ELF_FOREACH_SYM) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BCC_ELF_FOREACH_SYM) -endif(HAVE_BCC_ELF_FOREACH_SYM) - -if(HAVE_BCC_USDT_ADDSEM) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BCC_USDT_ADDSEM) -endif(HAVE_BCC_USDT_ADDSEM) - -if(HAVE_BCC_WHICH_SO) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BCC_WHICH_SO) -endif(HAVE_BCC_WHICH_SO) - -if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE) -endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE) - -if(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE) -endif(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE) - -if (HAVE_LIBBPF_MAP_BATCH) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_MAP_BATCH) -endif() - -if (HAVE_LIBBPF_LINK_CREATE) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_LINK_CREATE) -endif() - -if (HAVE_LIBBPF_PROG_TEST_RUN_OPTS) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_PROG_TEST_RUN_OPTS) -endif() - if(HAVE_BFD_DISASM) set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_BFD_DISASM) if(LIBBFD_DISASM_FOUR_ARGS_SIGNATURE) @@ -257,37 +210,6 @@ if(HAVE_BFD_DISASM) endif(LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE) endif(HAVE_BFD_DISASM) -if (LIBBPF_BTF_DUMP_FOUND) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP) - if (HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL) - endif() -endif(LIBBPF_BTF_DUMP_FOUND) - -if (HAVE_LIBBPF_BPF_PROG_LOAD) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BPF_PROG_LOAD) -endif(HAVE_LIBBPF_BPF_PROG_LOAD) - -if (HAVE_LIBBPF_BPF_MAP_CREATE) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BPF_MAP_CREATE) -endif(HAVE_LIBBPF_BPF_MAP_CREATE) - -if (HAVE_LIBBPF_BTF_TYPE_CNT) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_TYPE_CNT) -endif(HAVE_LIBBPF_BTF_TYPE_CNT) - -if (HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0) -endif(HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0) - -if (HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED) -endif(HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED) - -if (HAVE_LIBBPF_KPROBE_MULTI) - set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBBPF_KPROBE_MULTI) -endif(HAVE_LIBBPF_KPROBE_MULTI) - if (LIBDW_FOUND) set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBDW) endif () diff --git a/cmake/FindLibBcc.cmake b/cmake/FindLibBcc.cmake index a56fddbaa035..573158149c97 100644 --- a/cmake/FindLibBcc.cmake +++ b/cmake/FindLibBcc.cmake @@ -7,8 +7,6 @@ # LIBBCC_DEFINITIONS - Compiler switches required for using libbcc # LIBBCC_BPF_LIBRARIES - libbcc runtime library # LIBBCC_LOADER_LIBRARY_STATIC - libbcc helper static library (for static compilation) -# LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE -# LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE # LIBBCC_BPF_CONTAINS_RUNTIME - whether libbcc_bpf.so has been expanded to contain everything !llvm & !clang # # Note that the shared libbcc binary has libbpf and bcc_loader already compiled in but @@ -109,25 +107,6 @@ endif() INCLUDE(CheckCXXSourceCompiles) SET(CMAKE_REQUIRED_INCLUDES ${LIBBCC_INCLUDE_DIRS}) -CHECK_CXX_SOURCE_COMPILES(" -#include - -int main(void) { - bpf_attach_kprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0); - return 0; -} -" LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE) - -CHECK_CXX_SOURCE_COMPILES(" -#include - -int main(void) { - bpf_attach_uprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0, 0); - return 0; -} -" LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE) -SET(CMAKE_REQUIRED_INCLUDES) - SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_BPF_LIBRARIES}) include(CheckSymbolExists) check_symbol_exists(bcc_usdt_foreach ${LIBBCC_INCLUDE_DIRS}/bcc/bcc_usdt.h LIBBCC_BPF_CONTAINS_RUNTIME) diff --git a/cmake/FindLibBpf.cmake b/cmake/FindLibBpf.cmake index ac56550e4e99..7e62d36fa3b0 100644 --- a/cmake/FindLibBpf.cmake +++ b/cmake/FindLibBpf.cmake @@ -56,72 +56,3 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBpf ${LIBBPF_ERROR_MESSAGE} LIBBPF_INCLUDE_DIRS) mark_as_advanced(LIBBPF_INCLUDE_DIRS LIBBPF_LIBRARIES) - -# We need btf_dump support, set LIBBPF_BTF_DUMP_FOUND -# when it's found. -if (KERNEL_INCLUDE_DIRS) - set(INCLUDE_KERNEL -isystem ${KERNEL_INCLUDE_DIRS}) -endif () -include(CheckSymbolExists) -# adding also elf for static build check -SET(CMAKE_REQUIRED_LIBRARIES ${LIBBPF_LIBRARIES} elf z) -# libbpf quirk, needs upstream fix -SET(CMAKE_REQUIRED_DEFINITIONS -include stdbool.h -isystem "${LIBBPF_INCLUDE_DIRS}" ${INCLUDE_KERNEL}) -check_symbol_exists(btf_dump__new "${LIBBPF_INCLUDE_DIRS}/bpf/btf.h" HAVE_BTF_DUMP) -if (HAVE_BTF_DUMP) - set(LIBBPF_BTF_DUMP_FOUND TRUE) -endif () -check_symbol_exists(btf_dump__emit_type_decl "${LIBBPF_INCLUDE_DIRS}/bpf/btf.h" HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL) - -check_symbol_exists(bpf_prog_load "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_BPF_PROG_LOAD) -check_symbol_exists(bpf_map_create "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_BPF_MAP_CREATE) -check_symbol_exists(bpf_map_lookup_batch "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_MAP_BATCH) -check_symbol_exists(bpf_link_create "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_LINK_CREATE) -check_symbol_exists(bpf_prog_test_run_opts "${LIBBPF_INCLUDE_DIRS}/bpf/bpf.h" HAVE_LIBBPF_PROG_TEST_RUN_OPTS) -SET(CMAKE_REQUIRED_DEFINITIONS) -SET(CMAKE_REQUIRED_LIBRARIES) - -INCLUDE(CheckCXXSourceCompiles) -SET(CMAKE_REQUIRED_INCLUDES ${LIBBPF_INCLUDE_DIRS}) -SET(CMAKE_REQUIRED_LIBRARIES ${LIBBPF_LIBRARIES} elf z) -CHECK_CXX_SOURCE_COMPILES(" -#include - -int main(void) { - btf__type_cnt(NULL); - return 0; -} -" HAVE_LIBBPF_BTF_TYPE_CNT) - -CHECK_CXX_SOURCE_COMPILES(" -#include - -int main(void) { - const struct btf_dump_opts *opts = (const struct btf_dump_opts*) 1; - - btf_dump__new(NULL, NULL, NULL, opts); - return 0; -} -" HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0) - -CHECK_CXX_SOURCE_COMPILES(" -#include - -int main(void) { - btf_dump__new_deprecated(NULL, NULL, NULL, NULL); - return 0; -} -" HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED) - -CHECK_CXX_SOURCE_COMPILES(" -#include - -int main(void) { - DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts); - - opts.kprobe_multi.syms = NULL; - return 0; -} -" HAVE_LIBBPF_KPROBE_MULTI) -SET(CMAKE_REQUIRED_INCLUDES) -SET(CMAKE_REQUIRED_LIBRARIES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90177e4d35da..ce16469a47a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -124,12 +124,9 @@ if(STATIC_LINKING) endif(STATIC_LINKING) +target_link_libraries(runtime ${LIBBPF_LIBRARIES}) target_link_libraries(libbpftrace parser resources runtime aot ast arch cxxdemangler_llvm) -if (LIBBPF_BTF_DUMP_FOUND) - target_link_libraries(runtime ${LIBBPF_LIBRARIES}) -endif(LIBBPF_BTF_DUMP_FOUND) - if(LIBPCAP_FOUND) target_link_libraries(libbpftrace ${LIBPCAP_LIBRARIES}) endif(LIBPCAP_FOUND) diff --git a/src/ast/attachpoint_parser.cpp b/src/ast/attachpoint_parser.cpp index 9e51cc34521a..9de84b4ad97f 100644 --- a/src/ast/attachpoint_parser.cpp +++ b/src/ast/attachpoint_parser.cpp @@ -6,11 +6,7 @@ #include #include #include - -#ifdef HAVE_BCC_WHICH_SO #include -#endif - #include "ast/int_parser.h" #include "log.h" #include "types.h" @@ -388,7 +384,6 @@ AttachPointParser::State AttachPointParser::uprobe_parser(bool allow_offset, ap_->target = ""; -#ifdef HAVE_BCC_WHICH_SO if (!has_wildcard(parts_[1]) && parts_[1].find("lib") == 0) { // Automatic resolution of shared library paths. @@ -400,7 +395,6 @@ AttachPointParser::State AttachPointParser::uprobe_parser(bool allow_offset, if (lib_path) ap_->target = lib_path; } -#endif if (ap_->target.empty()) { diff --git a/src/attached_probe.cpp b/src/attached_probe.cpp index 6977e8df5f2d..53594364d5e4 100644 --- a/src/attached_probe.cpp +++ b/src/attached_probe.cpp @@ -125,7 +125,6 @@ int AttachedProbe::detach_kfunc(void) return 0; } -#ifdef HAVE_LIBBPF_LINK_CREATE void AttachedProbe::attach_iter(void) { linkfd_ = bpf_link_create(progfd_, @@ -144,20 +143,6 @@ int AttachedProbe::detach_iter(void) close(linkfd_); return 0; } -#else -void AttachedProbe::attach_iter(void) -{ - throw std::runtime_error( - "Error attaching probe: " + probe_.name + - ", iter API is not available for linked libbpf version"); -} - -int AttachedProbe::detach_iter(void) -{ - LOG(ERROR) << "iter is not available for linked bpf version"; - return 0; -} -#endif // HAVE_LIBBPF_LINK_CREATE AttachedProbe::AttachedProbe(Probe &probe, std::tuple func, @@ -708,13 +693,9 @@ void AttachedProbe::load_prog(BPFfeature &feature) continue; } -#ifdef HAVE_LIBBPF_BPF_PROG_LOAD LIBBPF_OPTS(bpf_prog_load_opts, opts); opts.log_buf = log_buf.get(); opts.log_size = log_buf_size; -#else - struct bpf_load_program_attr opts = {}; -#endif opts.log_level = log_level; if (probe_.type == ProbeType::kfunc) @@ -744,22 +725,12 @@ void AttachedProbe::load_prog(BPFfeature &feature) opts.kern_version = version; } -#ifdef HAVE_LIBBPF_BPF_PROG_LOAD progfd_ = bpf_prog_load(static_cast<::bpf_prog_type>(prog_type), name.c_str(), license, reinterpret_cast(insns), prog_len / sizeof(struct bpf_insn), &opts); -#else - opts.prog_type = static_cast<::bpf_prog_type>(prog_type); - opts.name = name.c_str(); - opts.insns = reinterpret_cast(insns); - opts.insns_cnt = prog_len / sizeof(struct bpf_insn); - opts.license = license; - opts.attach_prog_fd = 0; - progfd_ = bpf_load_program_xattr(&opts, log_buf.get(), log_buf_size); -#endif if (progfd_ >= 0) break; } @@ -815,7 +786,6 @@ void AttachedProbe::load_prog(BPFfeature &feature) cache_progfd(); } -#ifdef HAVE_LIBBPF_KPROBE_MULTI static inline uint64_t ptr_to_u64(const void *ptr) { return (uint64_t)(unsigned long)ptr; @@ -862,33 +832,22 @@ void AttachedProbe::attach_multi_kprobe(void) throw std::runtime_error("Error attaching probe: '" + probe_.name + "'"); } } -#endif // HAVE_LIBBPF_KPROBE_MULTI void AttachedProbe::attach_kprobe(bool safe_mode) { -#ifdef HAVE_LIBBPF_KPROBE_MULTI if (!probe_.funcs.empty()) { attach_multi_kprobe(); return; } -#endif resolve_offset_kprobe(safe_mode); -#ifdef LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE int perf_event_fd = bpf_attach_kprobe(progfd_, attachtype(probe_.type), eventname().c_str(), probe_.attach_point.c_str(), offset_, 0); -#else - int perf_event_fd = bpf_attach_kprobe(progfd_, - attachtype(probe_.type), - eventname().c_str(), - probe_.attach_point.c_str(), - offset_); -#endif if (perf_event_fd < 0) { if (probe_.orig_name != probe_.name) { @@ -911,23 +870,13 @@ void AttachedProbe::attach_uprobe(bool safe_mode) { resolve_offset_uprobe(safe_mode); - int perf_event_fd = -#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE - bpf_attach_uprobe(progfd_, - attachtype(probe_.type), - eventname().c_str(), - probe_.path.c_str(), - offset_, - probe_.pid, - 0); -#else - bpf_attach_uprobe(progfd_, - attachtype(probe_.type), - eventname().c_str(), - probe_.path.c_str(), - offset_, - probe_.pid); -#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE + int perf_event_fd = bpf_attach_uprobe(progfd_, + attachtype(probe_.type), + eventname().c_str(), + probe_.path.c_str(), + offset_, + probe_.pid, + 0); if (perf_event_fd < 0) throw std::runtime_error("Error attaching probe: " + probe_.name); @@ -960,7 +909,6 @@ int AttachedProbe::usdt_sem_up_manual(const std::string &fn_name, void *ctx) return err; } -#ifdef HAVE_BCC_USDT_ADDSEM int AttachedProbe::usdt_sem_up_manual_addsem(int pid, const std::string &fn_name, void *ctx) @@ -1003,15 +951,6 @@ int AttachedProbe::usdt_sem_up_manual_addsem(int pid, return err; } -#else -int AttachedProbe::usdt_sem_up_manual_addsem(int pid __attribute__((unused)), - const std::string &fn_name - __attribute__((unused)), - void *ctx __attribute__((unused))) -{ - return 0; -} -#endif // HAVE_BCC_USDT_ADDSEM int AttachedProbe::usdt_sem_up([[maybe_unused]] BPFfeature &feature, [[maybe_unused]] int pid, @@ -1027,11 +966,7 @@ int AttachedProbe::usdt_sem_up([[maybe_unused]] BPFfeature &feature, return 0; } -#if defined(HAVE_BCC_USDT_ADDSEM) return usdt_sem_up_manual_addsem(pid, fn_name, ctx); -#else - return usdt_sem_up_manual(fn_name, ctx); -#endif } void AttachedProbe::attach_usdt(int pid, BPFfeature &feature) @@ -1100,7 +1035,6 @@ void AttachedProbe::attach_usdt(int pid, BPFfeature &feature) } int perf_event_fd = -#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE bpf_attach_uprobe(progfd_, attachtype(probe_.type), eventname().c_str(), @@ -1108,14 +1042,6 @@ void AttachedProbe::attach_usdt(int pid, BPFfeature &feature) offset_, pid == 0 ? -1 : pid, semaphore_offset); -#else - bpf_attach_uprobe(progfd_, - attachtype(probe_.type), - eventname().c_str(), - probe_.path.c_str(), - offset_, - pid == 0 ? -1 : pid); -#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE if (perf_event_fd < 0) { diff --git a/src/bpffeature.cpp b/src/bpffeature.cpp index e527b57be102..b12cc50ebc96 100644 --- a/src/bpffeature.cpp +++ b/src/bpffeature.cpp @@ -1,9 +1,7 @@ #include "bpffeature.h" #include -#ifdef HAVE_LIBBPF_MAP_BATCH #include -#endif #include #include #include @@ -43,13 +41,9 @@ static bool try_load_(const char* name, continue; } -#ifdef HAVE_LIBBPF_BPF_PROG_LOAD LIBBPF_OPTS(bpf_prog_load_opts, opts); opts.log_buf = logbuf; opts.log_size = logbuf_size; -#else - struct bpf_load_program_attr opts = {}; -#endif opts.log_level = loglevel; opts.kern_version = version; if (attach_type.has_value()) @@ -60,22 +54,12 @@ static bool try_load_(const char* name, if (attach_btf_id.has_value()) opts.attach_btf_id = attach_btf_id.value(); -#ifdef HAVE_LIBBPF_BPF_PROG_LOAD int ret = bpf_prog_load(static_cast<::bpf_prog_type>(prog_type), name, "GPL", insns, insns_cnt, &opts); -#else - opts.prog_type = static_cast<::bpf_prog_type>(prog_type); - opts.name = name; - opts.insns = insns; - opts.insns_cnt = insns_cnt; - opts.license = "GPL"; - opts.attach_prog_fd = 0; - int ret = bpf_load_program_xattr(&opts, logbuf, logbuf_size); -#endif if (ret >= 0) { if (outfd) @@ -189,7 +173,6 @@ bool BPFfeature::detect_map(enum libbpf::bpf_map_type map_type) break; } -#ifdef HAVE_LIBBPF_BPF_MAP_CREATE LIBBPF_OPTS(bpf_map_create_opts, opts); opts.map_flags = flags; map_fd = bpf_map_create(static_cast(map_type), @@ -198,16 +181,6 @@ bool BPFfeature::detect_map(enum libbpf::bpf_map_type map_type) value_size, max_entries, &opts); -#else - struct bpf_create_map_attr attr = {}; - attr.name = nullptr; - attr.map_flags = flags; - attr.map_type = static_cast(map_type); - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - map_fd = bpf_create_map_xattr(&attr); -#endif if (map_fd >= 0) close(map_fd); @@ -290,10 +263,6 @@ int BPFfeature::instruction_limit(void) bool BPFfeature::has_map_batch() { -#ifndef HAVE_LIBBPF_MAP_BATCH - return false; - -#else int key_size = 4; int value_size = 4; int max_entries = 10; @@ -306,7 +275,6 @@ bool BPFfeature::has_map_batch() if (has_map_batch_.has_value()) return *has_map_batch_; -#ifdef HAVE_LIBBPF_BPF_MAP_CREATE LIBBPF_OPTS(bpf_map_create_opts, opts); opts.map_flags = flags; map_fd = bpf_map_create(static_cast( @@ -316,16 +284,6 @@ bool BPFfeature::has_map_batch() value_size, max_entries, &opts); -#else - struct bpf_create_map_attr attr = {}; - attr.name = nullptr; - attr.map_flags = flags; - attr.map_type = static_cast(libbpf::BPF_MAP_TYPE_HASH); - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - map_fd = bpf_create_map_xattr(&attr); -#endif if (map_fd < 0) return false; @@ -336,8 +294,6 @@ bool BPFfeature::has_map_batch() has_map_batch_ = err >= 0; return *has_map_batch_; - -#endif } bool BPFfeature::has_d_path(void) @@ -371,14 +327,10 @@ bool BPFfeature::has_uprobe_refcnt() if (has_uprobe_refcnt_.has_value()) return *has_uprobe_refcnt_; -#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE struct stat sb; has_uprobe_refcnt_ = ::stat("/sys/bus/event_source/devices/uprobe/format/ref_ctr_offset", &sb) == 0; -#else - has_uprobe_refcnt_ = false; -#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE return *has_uprobe_refcnt_; } @@ -388,7 +340,6 @@ bool BPFfeature::has_kprobe_multi() if (has_kprobe_multi_.has_value()) return *has_kprobe_multi_; -#if defined(HAVE_LIBBPF_KPROBE_MULTI) const char* sym = "ksys_read"; DECLARE_LIBBPF_OPTS(bpf_link_create_opts, link_opts); int progfd, linkfd = -1; @@ -431,11 +382,6 @@ bool BPFfeature::has_kprobe_multi() { close(progfd); } - -#else - has_kprobe_multi_ = false; -#endif // HAVE_LIBBPF_KPROBE_MULTI - return *has_kprobe_multi_; } @@ -449,7 +395,6 @@ bool BPFfeature::has_skb_output(void) int map_fd = 0; -#ifdef HAVE_LIBBPF_BPF_MAP_CREATE LIBBPF_OPTS(bpf_map_create_opts, opts); opts.map_flags = 0; map_fd = bpf_map_create(static_cast( @@ -459,17 +404,6 @@ bool BPFfeature::has_skb_output(void) sizeof(int), 1, &opts); -#else - struct bpf_create_map_attr attr = {}; - attr.name = "rb"; - attr.map_flags = 0; - attr.map_type = static_cast( - libbpf::BPF_MAP_TYPE_PERF_EVENT_ARRAY); - attr.key_size = sizeof(int); - attr.value_size = sizeof(int); - attr.max_entries = 1; - map_fd = bpf_create_map_xattr(&attr); -#endif if (map_fd < 0) return false; @@ -503,7 +437,6 @@ bool BPFfeature::has_raw_tp_special() if (has_raw_tp_special_.has_value()) return *has_raw_tp_special_; -#ifdef HAVE_LIBBPF_PROG_TEST_RUN_OPTS struct bpf_insn insns[] = { BPF_MOV64_IMM(BPF_REG_0, 0), BPF_EXIT_INSN() }; int fd; @@ -523,9 +456,6 @@ bool BPFfeature::has_raw_tp_special() } else has_raw_tp_special_ = false; -#else - has_raw_tp_special_ = false; -#endif return *has_raw_tp_special_; } diff --git a/src/bpftrace.cpp b/src/bpftrace.cpp index 2ef3b48bf4ec..d8ec05026655 100644 --- a/src/bpftrace.cpp +++ b/src/bpftrace.cpp @@ -19,11 +19,8 @@ #include #include #include - -#ifdef HAVE_BCC_ELF_FOREACH_SYM #include #include -#endif #include #include @@ -1022,12 +1019,10 @@ int BPFtrace::run_special_probe(std::string name, if (feature_->has_raw_tp_special()) { -#ifdef HAVE_LIBBPF_PROG_TEST_RUN_OPTS struct bpf_test_run_opts opts = {}; opts.sz = sizeof(opts); return ::bpf_prog_test_run_opts(aps[0]->progfd(), &opts); -#endif } else { @@ -1040,7 +1035,6 @@ int BPFtrace::run_special_probe(std::string name, return 0; } -#ifdef HAVE_LIBBPF_LINK_CREATE int BPFtrace::run_iter() { auto probe = resources.probes.begin(); @@ -1101,13 +1095,6 @@ int BPFtrace::run_iter() return 0; } -#else -int BPFtrace::run_iter() -{ - LOG(ERROR) << "iter is not available for linked bpf version"; - return 1; -} -#endif int BPFtrace::prerun() const { @@ -1923,7 +1910,6 @@ uint64_t BPFtrace::resolve_cgroupid(const std::string &path) const return bpftrace_linux::resolve_cgroupid(path); } -#ifdef HAVE_BCC_ELF_FOREACH_SYM static int sym_resolve_callback(const char *name, uint64_t addr, uint64_t size, @@ -1938,31 +1924,17 @@ static int sym_resolve_callback(const char *name, } return 0; } -#endif int BPFtrace::resolve_uname(const std::string &name, struct symbol *sym, const std::string &path) const { sym->name = name; -#ifdef HAVE_BCC_ELF_FOREACH_SYM struct bcc_symbol_option option; memset(&option, 0, sizeof(option)); option.use_symbol_type = (1 << STT_OBJECT); return bcc_elf_foreach_sym(path.c_str(), sym_resolve_callback, &option, sym); -#else - std::string call_str = - std::string("objdump -tT ") + path + " | grep -w " + sym->name; - const char *call = call_str.c_str(); - auto result = exec_system(call); - sym->address = read_address_from_output(result); - /* Trying to grab the size from objdump output is not that easy. foreaech_sym - has been around for a while, users should switch to that. - */ - sym->size = 8; - return 0; -#endif } std::string BPFtrace::resolve_mac_address(const uint8_t *mac_addr) const @@ -1996,13 +1968,11 @@ std::string BPFtrace::resolve_cgroup_path(uint64_t cgroup_path_id, return result.str().substr(0, result.str().size() - 1); } -#ifdef HAVE_BCC_ELF_FOREACH_SYM static int add_symbol(const char *symname, uint64_t /*start*/, uint64_t /*size*/, void *payload) { auto syms = static_cast *>(payload); syms->insert(std::string(symname)); return 0; } -#endif std::string BPFtrace::extract_func_symbols_from_path(const std::string &path) const { @@ -2011,19 +1981,16 @@ std::string BPFtrace::extract_func_symbols_from_path(const std::string &path) co real_paths = resolve_binary_path(path); else real_paths.push_back(path); -#ifdef HAVE_BCC_ELF_FOREACH_SYM struct bcc_symbol_option symbol_option; memset(&symbol_option, 0, sizeof(symbol_option)); symbol_option.use_debug_file = 1; symbol_option.check_debug_file_crc = 1; symbol_option.use_symbol_type = (1 << STT_FUNC) | (1 << STT_GNU_IFUNC); -#endif std::string result; for (auto &real_path : real_paths) { std::set syms; -#ifdef HAVE_BCC_ELF_FOREACH_SYM // Workaround: bcc_elf_foreach_sym() can return the same symbol twice if // it's also found in debug info (#1138), so a std::set is used here (and in // the add_symbol callback) to ensure that each symbol will be unique in the @@ -2034,15 +2001,6 @@ std::string BPFtrace::extract_func_symbols_from_path(const std::string &path) co { LOG(WARNING) << "Could not list function symbols: " + real_path; } -#else - std::string call_str = std::string("objdump -tT ") + real_path + +" | " + - "grep \"F .text\" | grep -oE '[^[:space:]]+$'"; - const char *call = call_str.c_str(); - std::istringstream iss(exec_system(call)); - std::copy(std::istream_iterator(iss), - std::istream_iterator(), - std::inserter(syms, syms.begin())); -#endif for (auto &sym : syms) result += real_path + ":" + sym + "\n"; } diff --git a/src/btf.cpp b/src/btf.cpp index 24742b8ec832..f3b911d81875 100644 --- a/src/btf.cpp +++ b/src/btf.cpp @@ -16,7 +16,6 @@ #include #include -#ifdef HAVE_LIBBPF_BTF_DUMP #include #include #pragma GCC diagnostic push @@ -31,11 +30,7 @@ namespace bpftrace { static __u32 type_cnt(const struct btf *btf) { -#ifdef HAVE_LIBBPF_BTF_TYPE_CNT return btf__type_cnt(btf) - 1; -#else - return btf__get_nr_types(btf); -#endif } static unsigned char *get_data(const char *file, ssize_t *sizep) @@ -199,18 +194,7 @@ static struct btf_dump *dump_new(const struct btf *btf, btf_dump_printf_fn_t dump_printf, void *ctx) { -#ifdef HAVE_LIBBPF_BTF_DUMP_NEW_V0_6_0 return btf_dump__new(btf, dump_printf, ctx, nullptr); -#else - struct btf_dump_opts opts = { - .ctx = ctx, - }; -#ifdef HAVE_LIBBPF_BTF_DUMP_NEW_DEPRECATED - return btf_dump__new_deprecated(btf, nullptr, &opts, dump_printf); -#else - return btf_dump__new(btf, nullptr, &opts, dump_printf); -#endif -#endif } static const char *btf_str(const struct btf *btf, __u32 off) @@ -584,7 +568,6 @@ std::unique_ptr BTF::get_all_funcs() const std::map> BTF::get_params( const std::set &funcs) const { -#ifdef HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL __s32 id, max = (__s32)type_cnt(btf); std::string type = std::string(""); struct btf_dump *dump; @@ -671,11 +654,6 @@ std::map> BTF::get_params( btf_dump__free(dump); return params; -#else - LOG(ERROR) << "Could not get kfunc arguments " - "(HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL is not set)"; - return {}; -#endif } std::set BTF::get_all_structs() const @@ -757,48 +735,3 @@ int BTF::get_btf_id(const std::string &name) const } } // namespace bpftrace -#else // HAVE_LIBBPF_BTF_DUMP - -namespace bpftrace { - -BTF::BTF() { } - -BTF::~BTF() { } - -std::string BTF::c_def(const std::unordered_set& set - __attribute__((__unused__))) const -{ - return std::string(""); -} - -std::string BTF::type_of(const std::string& name __attribute__((__unused__)), - const std::string& field __attribute__((__unused__))) { - return std::string(""); -} - -int BTF::resolve_args(const std::string &func __attribute__((__unused__)), - std::map& args - __attribute__((__unused__)), - bool ret __attribute__((__unused__))) -{ - return -1; -} - -std::set BTF::get_all_structs() const -{ - return {}; -} - -std::unique_ptr BTF::get_all_funcs() const -{ - return nullptr; -} - -std::map> BTF::get_params( - const std::set& funcs __attribute__((__unused__))) const -{ - return {}; -} -} // namespace bpftrace - -#endif // HAVE_LIBBPF_BTF_DUMP diff --git a/src/build_info.cpp b/src/build_info.cpp index 2381acee6945..c3dccad2a68b 100644 --- a/src/build_info.cpp +++ b/src/build_info.cpp @@ -12,12 +12,6 @@ std::string BuildInfo::report() << " version: " << BPFTRACE_VERSION << std::endl << " LLVM: " << LLVM_VERSION_MAJOR << "." << LLVM_VERSION_MINOR << "." << LLVM_VERSION_PATCH << std::endl - << " foreach_sym: " -#ifdef HAVE_BCC_ELF_FOREACH_SYM - << "yes" << std::endl -#else - << "no" << std::endl -#endif << " unsafe uprobe: " #ifdef HAVE_UNSAFE_UPROBE << "yes" << std::endl; @@ -29,48 +23,6 @@ std::string BuildInfo::report() << "yes" << std::endl; #else << "no" << std::endl; -#endif - buf << " bcc_usdt_addsem: " -#ifdef HAVE_BCC_USDT_ADDSEM - << "yes" << std::endl; -#else - << "no" << std::endl; -#endif - buf << " bcc bpf_attach_uprobe refcount: " -#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE - << "yes" << std::endl; -#else - << "no" << std::endl; -#endif - buf << " bcc library path resolution: " -#ifdef HAVE_BCC_WHICH_SO - << "yes" << std::endl; -#else - << "no" << std::endl; -#endif - buf << " libbpf btf dump: " -#ifdef HAVE_LIBBPF_BTF_DUMP - << "yes" << std::endl; -#else - << "no" << std::endl; -#endif - buf << " libbpf btf dump type decl: " -#ifdef HAVE_LIBBPF_BTF_DUMP_EMIT_TYPE_DECL - << "yes" << std::endl; -#else - << "no" << std::endl; -#endif - buf << " libbpf bpf_prog_load: " -#ifdef HAVE_LIBBPF_BPF_PROG_LOAD - << "yes" << std::endl; -#else - << "no" << std::endl; -#endif - buf << " libbpf bpf_map_create: " -#ifdef HAVE_LIBBPF_BPF_MAP_CREATE - << "yes" << std::endl; -#else - << "no" << std::endl; #endif buf << " libdw (DWARF support): " #ifdef HAVE_LIBDW diff --git a/src/map.cpp b/src/map.cpp index ebddd94ed30c..311570dc852f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -30,7 +30,6 @@ int create_map(libbpf::bpf_map_type map_type, name_ptr = &fixed_name; } -#ifdef HAVE_LIBBPF_BPF_MAP_CREATE LIBBPF_OPTS(bpf_map_create_opts, opts); opts.map_flags = flags; return bpf_map_create(static_cast<::bpf_map_type>(map_type), @@ -39,16 +38,6 @@ int create_map(libbpf::bpf_map_type map_type, value_size, max_entries, &opts); -#else - struct bpf_create_map_attr attr = {}; - attr.name = name_ptr->c_str(); - attr.map_flags = flags; - attr.map_type = static_cast<::bpf_map_type>(map_type); - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - return bpf_create_map_xattr(&attr); -#endif } } // namespace diff --git a/src/probe_matcher.cpp b/src/probe_matcher.cpp index 617e282f91ef..89ca545e385b 100644 --- a/src/probe_matcher.cpp +++ b/src/probe_matcher.cpp @@ -15,15 +15,11 @@ #include "utils.h" #include - -#ifdef HAVE_BCC_ELF_FOREACH_SYM #include #include -#endif namespace bpftrace { -#ifdef HAVE_BCC_ELF_FOREACH_SYM static int add_symbol(const char* symname, uint64_t /*start*/, uint64_t /*size*/, @@ -33,7 +29,6 @@ static int add_symbol(const char* symname, syms->insert(std::string(symname)); return 0; } -#endif /* * Finds all matches of search_input in the provided input stream. @@ -214,19 +209,16 @@ std::unique_ptr ProbeMatcher::get_func_symbols_from_file( real_paths = resolve_binary_path(path); else real_paths.push_back(path); -#ifdef HAVE_BCC_ELF_FOREACH_SYM struct bcc_symbol_option symbol_option; memset(&symbol_option, 0, sizeof(symbol_option)); symbol_option.use_debug_file = 1; symbol_option.check_debug_file_crc = 1; symbol_option.use_symbol_type = (1 << STT_FUNC) | (1 << STT_GNU_IFUNC); -#endif std::string result; for (auto& real_path : real_paths) { std::set syms; -#ifdef HAVE_BCC_ELF_FOREACH_SYM // Workaround: bcc_elf_foreach_sym() can return the same symbol twice if // it's also found in debug info (#1138), so a std::set is used here (and in // the add_symbol callback) to ensure that each symbol will be unique in the @@ -237,15 +229,6 @@ std::unique_ptr ProbeMatcher::get_func_symbols_from_file( { LOG(WARNING) << "Could not list function symbols: " + real_path; } -#else - std::string call_str = std::string("objdump -tT ") + real_path + +" | " + - "grep \"F .text\" | grep -oE '[^[:space:]]+$'"; - const char* call = call_str.c_str(); - std::istringstream iss(exec_system(call)); - std::copy(std::istream_iterator(iss), - std::istream_iterator(), - std::inserter(syms, syms.begin())); -#endif for (auto& sym : syms) result += real_path + ":" + sym + "\n"; } diff --git a/src/usdt.cpp b/src/usdt.cpp index 82c489f05cda..1f7d1da715fe 100644 --- a/src/usdt.cpp +++ b/src/usdt.cpp @@ -35,11 +35,7 @@ static void usdt_probe_each(struct bcc_usdt *usdt_probe) .path = usdt_probe->bin_path, .provider = usdt_probe->provider, .name = usdt_probe->name, -#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE .semaphore_offset = usdt_probe->semaphore_offset, -#else - .semaphore_offset = 0, -#endif .num_locations = usdt_probe->num_locations, }); current_pid_paths.emplace(usdt_probe->bin_path); diff --git a/tests/bpftrace.cpp b/tests/bpftrace.cpp index 3368d3d41542..7981f7fdcffd 100644 --- a/tests/bpftrace.cpp +++ b/tests/bpftrace.cpp @@ -10,6 +10,8 @@ namespace bpftrace { namespace test { namespace bpftrace { +#include "btf_common.h" + using ::testing::ContainerEq; using ::testing::StrictMock; @@ -965,10 +967,6 @@ TEST(bpftrace, sort_by_key_int_str) EXPECT_THAT(values_by_key, ContainerEq(expected_values)); } -#ifdef HAVE_LIBBPF_BTF_DUMP - -#include "btf_common.h" - class bpftrace_btf : public test_btf { }; @@ -1021,8 +1019,6 @@ TEST_F(bpftrace_btf, add_probes_iter_task_file) check_probe(bpftrace.get_probes().at(0), ProbeType::iter, "iter:task_file"); } -#endif // HAVE_LIBBPF_BTF_DUMP - } // namespace bpftrace } // namespace test } // namespace bpftrace diff --git a/tests/clang_parser.cpp b/tests/clang_parser.cpp index 6336905847d0..c44fc56493b5 100644 --- a/tests/clang_parser.cpp +++ b/tests/clang_parser.cpp @@ -10,6 +10,8 @@ namespace bpftrace { namespace test { namespace clang_parser { +#include "btf_common.h" + static void parse(const std::string &input, BPFtrace &bpftrace, bool result = true, const std::string& probe = "kprobe:sys_read { 1 }") { @@ -516,10 +518,6 @@ TEST(clang_parser, parse_fail) parse("struct a { int a; struct b b; };", bpftrace, false); } -#ifdef HAVE_LIBBPF_BTF_DUMP - -#include "btf_common.h" - class clang_parser_btf : public test_btf { }; @@ -691,7 +689,6 @@ TEST_F(clang_parser_btf, btf_type_override) false, "kprobe:sys_read { @x1 = ((struct Foo3 *)curtask); }"); } -#endif // HAVE_LIBBPF_BTF_DUMP TEST(clang_parser, struct_typedef) { diff --git a/tests/portability_analyser.cpp b/tests/portability_analyser.cpp index 2e31c2e987e5..fcb961c76caa 100644 --- a/tests/portability_analyser.cpp +++ b/tests/portability_analyser.cpp @@ -4,6 +4,7 @@ #include "ast/passes/field_analyser.h" #include "ast/passes/portability_analyser.h" #include "ast/passes/semantic_analyser.h" +#include "btf_common.h" #include "clang_parser.h" #include "driver.h" #include "mocks.h" @@ -57,8 +58,6 @@ TEST(portability_analyser, tracepoint_field_access) test("tracepoint:sched:sched_* { args->common_field }", 0); } -#if defined(HAVE_LIBBPF_BTF_DUMP) -#include "btf_common.h" class portability_analyser_btf : public test_btf { }; @@ -70,7 +69,6 @@ TEST_F(portability_analyser_btf, kfunc_field_access) test("kfunc:func_2 { args->foo1 }", 0); test("kfunc:func_2, kfunc:func_3 { $x = args->foo1; }", 0); } -#endif TEST(portability_analyser, positional_params_disabled) { diff --git a/tests/probe.cpp b/tests/probe.cpp index 8b0a4c1419b0..6e66eb5340d1 100644 --- a/tests/probe.cpp +++ b/tests/probe.cpp @@ -16,6 +16,8 @@ namespace bpftrace { namespace test { namespace probe { +#include "btf_common.h" + using bpftrace::ast::AttachPoint; using bpftrace::ast::AttachPointList; using bpftrace::ast::Probe; @@ -73,10 +75,6 @@ TEST(probe, short_name) compare_bytecode("interval:s:1 { 1 }", "i:s:1 { 1 }"); } -#ifdef HAVE_LIBBPF_BTF_DUMP - -#include "btf_common.h" - class probe_btf : public test_btf { }; @@ -89,8 +87,6 @@ TEST_F(probe_btf, short_name) compare_bytecode("iter:task_file { 1 }", "it:task_file { 1 }"); } -#endif // HAVE_LIBBPF_BTF_DUMP - } // namespace probe } // namespace test } // namespace bpftrace diff --git a/tests/runtime/engine/parser.py b/tests/runtime/engine/parser.py index 21e4d8bf4910..80df5e04f08b 100644 --- a/tests/runtime/engine/parser.py +++ b/tests/runtime/engine/parser.py @@ -151,7 +151,6 @@ def __read_test_struct(test, test_suite): "probe_read_kernel", "dpath", "uprobe_refcount", - "bcc_usdt_addsem", "signal", "iter:task", "iter:task_file", diff --git a/tests/runtime/engine/runner.py b/tests/runtime/engine/runner.py index f6398bcb7368..d8dde0873b66 100644 --- a/tests/runtime/engine/runner.py +++ b/tests/runtime/engine/runner.py @@ -129,7 +129,6 @@ def __get_bpffeature(): bpffeature["dpath"] = output.find("dpath: yes") != -1 bpffeature["uprobe_refcount"] = \ output.find("uprobe refcount (depends on Build:bcc bpf_attach_uprobe refcount): yes") != -1 - bpffeature["bcc_usdt_addsem"] = output.find("bcc_usdt_addsem: yes") != -1 bpffeature["signal"] = output.find("send_signal: yes") != -1 bpffeature["iter:task"] = output.find("iter:task: yes") != -1 bpffeature["iter:task_file"] = output.find("iter:task_file: yes") != -1 @@ -158,10 +157,11 @@ def run_test(test): signal.signal(signal.SIGALRM, Runner.__handler) + p = None + before = None + bpftrace = None + after = None try: - before = None - bpftrace = None - after = None timeout = False print(ok("[ RUN ] ") + "%s.%s" % (test.suite, test.name)) @@ -210,7 +210,7 @@ def run_test(test): raise TimeoutError('Timed out waiting for BEFORE %s ', test.before) bpf_call = Runner.prepare_bpf_call(test) - if test.before: + if test.before and '{{BEFORE_PID}}' in bpf_call: childpid = subprocess.Popen(["pidof", child_name], stdout=subprocess.PIPE, universal_newlines=True).communicate()[0].split()[0] bpf_call = re.sub("{{BEFORE_PID}}", str(childpid), bpf_call) env = { @@ -263,10 +263,11 @@ def run_test(test): # # Send a SIGTERM here so bpftrace exits cleanly. We'll send an SIGKILL # if SIGTERM didn't do the trick later - if p.poll() is None: - os.killpg(os.getpgid(p.pid), signal.SIGTERM) - output += p.communicate()[0] - result = re.search(test.expect, output) + if p: + if p.poll() is None: + os.killpg(os.getpgid(p.pid), signal.SIGTERM) + output += p.communicate()[0] + result = re.search(test.expect, output) if not result: print(fail("[ TIMEOUT ] ") + "%s.%s" % (test.suite, test.name)) print('\tCommand: %s' % bpf_call) @@ -283,7 +284,7 @@ def run_test(test): if after and after.poll() is None: os.killpg(os.getpgid(after.pid), signal.SIGKILL) - if p.returncode != 0 and not test.will_fail and not timeout: + if p and p.returncode != 0 and not test.will_fail and not timeout: print(fail("[ FAILED ] ") + "%s.%s" % (test.suite, test.name)) print('\tCommand: ' + bpf_call) print('\tUnclean exit code: ' + str(p.returncode)) diff --git a/tests/runtime/usdt b/tests/runtime/usdt index 5e3f38874423..39ca03e5787c 100644 --- a/tests/runtime/usdt +++ b/tests/runtime/usdt @@ -140,13 +140,9 @@ RUN {{BPFTRACE}} -e 'usdt:./testprogs/usdt_test*::* { printf("here\n" ); exit(); EXPECT Attaching 3 probes... TIMEOUT 5 -# Wasn't fully debugged, but looks like old bcc API (bcc_usdt_enable_fully_specified_probe) -# doesn't like inlined usdt probes very much. So that's why the bcc_usdt_addsem feature is -# required NAME "usdt probes - attach to probe on multiple files by wildcard" PROG usdt:./testprogs/usdt*::* { printf("here\n" ); exit(); } EXPECT Attaching 41 probes... -REQUIRES_FEATURE bcc_usdt_addsem TIMEOUT 5 NAME "usdt probes - attach to probe on multiple providers by wildcard and pid" @@ -244,7 +240,7 @@ NAME "usdt probes - file based semaphore activation multi process" RUN {{BPFTRACE}} runtime/scripts/usdt_file_activation_multiprocess.bt --usdt-file-activation EXPECT found 2 processes TIMEOUT 5 -BEFORE ./testprogs/usdt_semaphore_test & ./testprogs/usdt_semaphore_test +BEFORE ./testprogs/two_usdt_semaphore_tests REQUIRES ./testprogs/usdt_semaphore_test should_not_skip NAME "usdt probes - list probes by pid in separate mountns" diff --git a/tests/semantic_analyser.cpp b/tests/semantic_analyser.cpp index d7e18065f851..3a0e42002266 100644 --- a/tests/semantic_analyser.cpp +++ b/tests/semantic_analyser.cpp @@ -12,6 +12,8 @@ namespace bpftrace { namespace test { namespace semantic_analyser { +#include "btf_common.h" + using ::testing::_; using ::testing::HasSubstr; @@ -2578,10 +2580,6 @@ TEST(semantic_analyser, string_size) ASSERT_EQ(var_assign->var->type.GetField(0).type.GetSize(), 6UL); } -#ifdef HAVE_LIBBPF_BTF_DUMP - -#include "btf_common.h" - class semantic_analyser_btf : public test_btf { }; @@ -2662,8 +2660,6 @@ TEST_F(semantic_analyser_btf, iter) test("iter:task,f:func_1 { 1 }", 1); } -#endif // HAVE_LIBBPF_BTF_DUMP - #ifdef HAVE_LIBDW #include "dwarf_common.h" diff --git a/tests/testprogs/two_usdt_semaphore_tests.c b/tests/testprogs/two_usdt_semaphore_tests.c new file mode 100644 index 000000000000..d271ea2cb6da --- /dev/null +++ b/tests/testprogs/two_usdt_semaphore_tests.c @@ -0,0 +1,17 @@ +#include + +int main(int argc __attribute__((unused)), char **argv) +{ + int pid = fork(); + + if (pid < 0) + return 1; + else if (pid == 0) + // child, test 1 + execv("./testprogs/usdt_semaphore_test", argv); + else + // parent, test 2 + execv("./testprogs/usdt_semaphore_test", argv); + + return 0; +}