Skip to content

Commit 36310d2

Browse files
authored
Merge branch 'pixie9' into master
Signed-off-by: Monu Lakshkar <mlakshkar@newrelic.com>
2 parents c3f35ec + e57be84 commit 36310d2

17 files changed

Lines changed: 276 additions & 30 deletions

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ include(GNUInstallDirs)
9999
include(CheckCXXCompilerFlag)
100100
include(cmake/FindCompilerFlag.cmake)
101101

102+
103+
option(ENABLE_INTROSPECTIONS "Enable introspection tool" OFF)
104+
option(ENABLE_LUA "Enable lua bindings" OFF)
105+
option(ENABLE_PYTHON "Enable python binding" OFF)
106+
option(ENABLE_SHARED "Enable shared libraries" OFF)
102107
option(ENABLE_LLVM_NATIVECODEGEN "Enable use of llvm nativecodegen module (needed by rw-engine)" ON)
103108
option(ENABLE_RTTI "Enable compiling with real time type information" OFF)
104109
option(ENABLE_LLVM_SHARED "Enable linking LLVM as a shared library" OFF)
@@ -209,7 +214,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
209214
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
210215

211216
add_subdirectory(src)
212-
add_subdirectory(introspection)
217+
if(ENABLE_INTROSPECTIONS)
218+
add_subdirectory(introspection)
219+
endif(ENABLE_INTROSPECTIONS)
213220

214221
if(ENABLE_CLANG_JIT)
215222
if(ENABLE_EXAMPLES)

src/CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
55

66
if (ENABLE_RTTI)
7-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
88
else()
9-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
1010
endif()
1111

1212
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
1313
include_directories(${CMAKE_CURRENT_BINARY_DIR})
1414

1515
if(NOT PYTHON_ONLY)
16-
add_subdirectory(cc)
16+
add_subdirectory(cc)
1717
endif()
18+
1819
if(ENABLE_CLANG_JIT)
19-
add_subdirectory(python)
20-
add_subdirectory(lua)
20+
if(ENABLE_PYTHON)
21+
add_subdirectory(python)
22+
endif(ENABLE_PYTHON)
23+
24+
if(ENABLE_LUA)
25+
add_subdirectory(lua)
26+
endif(ENABLE_LUA)
2127
endif()

src/cc/CMakeLists.txt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
include_directories(${CMAKE_CURRENT_BINARY_DIR})
55
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
6-
# to be removed
7-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/frontends/b)
8-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/b)
6+
97
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frontends/clang)
108
include_directories(${LLVM_INCLUDE_DIRS})
119
include_directories(${LIBELF_INCLUDE_DIRS})
@@ -15,6 +13,7 @@ endif(LIBLZMA_FOUND)
1513
if (LIBDEBUGINFOD_FOUND AND ENABLE_LIBDEBUGINFOD)
1614
include_directories(${LIBDEBUGINFOD_INCLUDE_DIRS})
1715
endif (LIBDEBUGINFOD_FOUND AND ENABLE_LIBDEBUGINFOD)
16+
1817
# todo: if check for kernel version
1918
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
2019
include_directories(${LIBBPF_INCLUDE_DIRS})
@@ -44,7 +43,8 @@ if (NOT HAVE_REALLOCARRAY_SUPPORT)
4443
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPAT_NEED_REALLOCARRAY")
4544
endif()
4645

47-
include(static_libstdc++)
46+
string(REGEX MATCH "^([0-9]+).*" _ ${LLVM_PACKAGE_VERSION})
47+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_MAJOR_VERSION=${CMAKE_MATCH_1}")
4848

4949
if(LIBBPF_INCLUDE_DIR)
5050
# Add user libbpf include and notify compilation
@@ -88,11 +88,13 @@ if(LIBBPF_FOUND)
8888
endif()
8989

9090
if(ENABLE_CLANG_JIT)
91-
add_library(bcc-shared SHARED
92-
link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
93-
${bcc_util_sources})
94-
set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
95-
set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc)
91+
if(ENABLE_SHARED)
92+
add_library(bcc-shared SHARED
93+
link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
94+
${bcc_util_sources})
95+
set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
96+
set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc)
97+
endif(ENABLE_SHARED)
9698

9799
if(ENABLE_USDT)
98100
add_definitions(-DEXPORT_USDT)
@@ -112,6 +114,8 @@ set(bpf_sources libbpf.c perf_reader.c ${libbpf_sources} ${bcc_sym_sources} ${bc
112114
add_library(bpf-static STATIC ${bpf_sources})
113115
set_target_properties(bpf-static PROPERTIES OUTPUT_NAME bcc_bpf)
114116
target_link_libraries(bpf-static elf z)
117+
118+
if(ENABLE_SHARED)
115119
add_library(bpf-shared SHARED ${bpf_sources})
116120
set_target_properties(bpf-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
117121
set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bcc_bpf)
@@ -125,6 +129,7 @@ endif(LIBDEBUGINFOD_FOUND)
125129
if(CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
126130
target_link_libraries(bpf-shared ${LIBBPF_LIBRARIES})
127131
endif()
132+
endif(ENABLE_SHARED)
128133

129134
include(clang_libs)
130135
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${clang_lib_exclude_flags}")
@@ -175,15 +180,25 @@ add_subdirectory(frontends)
175180
target_sources(bcc-static PRIVATE $<TARGET_OBJECTS:clang_frontend-objects>)
176181

177182
# Link against LLVM libraries
178-
target_link_libraries(bcc-shared ${bcc_common_libs_for_s})
183+
if(ENABLE_SHARED)
184+
target_link_libraries(bcc-shared ${bcc_common_libs_for_s})
185+
endif(ENABLE_SHARED)
186+
179187
target_link_libraries(bcc-static ${bcc_common_libs_for_a} bcc-loader-static)
180188
set(bcc-lua-static ${bcc-lua-static} ${bcc_common_libs_for_lua})
181189

182-
install(TARGETS bcc-shared bcc-static bcc-loader-static bpf-static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
190+
install(TARGETS bcc-static bcc-loader-static bpf-static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
183191
install(FILES ${bcc_table_headers} DESTINATION include/bcc)
184192
install(FILES ${bcc_api_headers} DESTINATION include/bcc)
185193
install(DIRECTORY ${libbpf_uapi} DESTINATION include/bcc/compat/linux FILES_MATCHING PATTERN "*.h")
186194
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
195+
if(ENABLE_SHARED)
196+
install(TARGETS bcc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
197+
endif(ENABLE_SHARED)
198+
187199
endif(ENABLE_CLANG_JIT)
188200
install(FILES ${bcc_common_headers} DESTINATION include/bcc)
189-
install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
201+
202+
if(ENABLE_SHARED)
203+
install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
204+
endif(ENABLE_SHARED)

src/cc/api/BPF.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fcntl.h>
2424
#include <iostream>
2525
#include <memory>
26+
#include <random>
2627
#include <sstream>
2728
#include <sys/stat.h>
2829
#include <sys/types.h>

src/cc/api/BPF.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ class BPF {
409409
std::string all_bpf_program_;
410410

411411
std::map<std::string, open_probe_t> kprobes_;
412+
// For uprobes, if the binary path is longer than 250, we'll shorten them. And then keep the
413+
// mapping.
414+
std::map<std::string, std::string> name_map_;
412415
std::map<std::string, open_probe_t> uprobes_;
413416
std::map<std::string, open_probe_t> tracepoints_;
414417
std::map<std::string, open_probe_t> raw_tracepoints_;

src/cc/api/BPFTable.cc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,19 @@ void BPFStackTable::free_symcache(int pid) {
282282
}
283283
}
284284

285+
void BPFStackTable::clear_stack_id(int stack_id) {
286+
if(stack_id >= 0) {
287+
remove(&stack_id);
288+
}
289+
}
290+
285291
void BPFStackTable::clear_table_non_atomic() {
286292
for (int i = 0; size_t(i) < capacity(); i++) {
287293
remove(&i);
288294
}
289295
}
290296

291-
std::vector<uintptr_t> BPFStackTable::get_stack_addr(int stack_id) {
297+
std::vector<uintptr_t> BPFStackTable::get_stack_addr(int stack_id, const bool clear) {
292298
std::vector<uintptr_t> res;
293299
stacktrace_t stack;
294300
if (stack_id < 0)
@@ -297,6 +303,10 @@ std::vector<uintptr_t> BPFStackTable::get_stack_addr(int stack_id) {
297303
return res;
298304
for (int i = 0; (i < BPF_MAX_STACK_DEPTH) && (stack.ip[i] != 0); i++)
299305
res.push_back(stack.ip[i]);
306+
307+
if (clear) {
308+
clear_stack_id(stack_id);
309+
}
300310
return res;
301311
}
302312

@@ -326,6 +336,25 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id,
326336
return res;
327337
}
328338

339+
std::string BPFStackTable::get_addr_symbol(uintptr_t addr, int pid) {
340+
if (pid < 0)
341+
pid = -1;
342+
if (pid_sym_.find(pid) == pid_sym_.end())
343+
pid_sym_[pid] = bcc_symcache_new(pid, &symbol_option_);
344+
void* cache = pid_sym_[pid];
345+
346+
bcc_symbol symbol;
347+
std::string sym_str;
348+
if (bcc_symcache_resolve(cache, addr, &symbol) != 0) {
349+
sym_str = "[UNKNOWN]";
350+
} else {
351+
sym_str = symbol.demangle_name;
352+
bcc_symbol_free_demangle_name(&symbol);
353+
}
354+
355+
return sym_str;
356+
}
357+
329358
BPFStackBuildIdTable::BPFStackBuildIdTable(const TableDesc& desc, bool use_debug_file,
330359
bool check_debug_file_crc,
331360
void *bsymcache)

src/cc/api/BPFTable.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ class BPFHashTable : public BPFTableBase<KeyType, ValueType> {
300300
return value;
301301
}
302302

303-
std::vector<std::pair<KeyType, ValueType>> get_table_offline() {
303+
std::vector<std::pair<KeyType, ValueType>> get_table_offline(const bool clear_table=false) {
304304
std::vector<std::pair<KeyType, ValueType>> res;
305305
KeyType cur;
306+
KeyType prev;
306307
ValueType value;
307308

308309
StatusTuple r(0);
@@ -315,8 +316,16 @@ class BPFHashTable : public BPFTableBase<KeyType, ValueType> {
315316
if (!r.ok())
316317
break;
317318
res.emplace_back(cur, value);
318-
if (!this->next(&cur, &cur))
319+
prev = cur;
320+
if (!this->next(&cur, &cur)) {
321+
if(clear_table) {
322+
this->remove_value(prev);
323+
}
319324
break;
325+
}
326+
if(clear_table) {
327+
this->remove_value(prev);
328+
}
320329
}
321330

322331
return res;
@@ -380,8 +389,10 @@ class BPFStackTable : public BPFTableBase<int, stacktrace_t> {
380389

381390
void free_symcache(int pid);
382391
void clear_table_non_atomic();
383-
std::vector<uintptr_t> get_stack_addr(int stack_id);
392+
void clear_stack_id(int stack_id);
393+
std::vector<uintptr_t> get_stack_addr(int stack_id, const bool clear=false);
384394
std::vector<std::string> get_stack_symbol(int stack_id, int pid);
395+
std::string get_addr_symbol(uintptr_t addr, int pid);
385396

386397
private:
387398
bcc_symbol_option symbol_option_;

src/cc/api/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ set(bcc_api_sources BPF.cc BPFTable.cc)
22
add_library(api-static STATIC ${bcc_api_sources})
33
add_library(api-objects OBJECT ${bcc_api_sources})
44
install(FILES BPF.h BPFTable.h COMPONENT libbcc DESTINATION include/bcc)
5+
install(TARGETS api-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

src/cc/bpffs_table.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BpfFsTableStorage : public TableStorageImpl {
3232
virtual self_type &operator++() override;
3333
virtual value_type &operator*() const override;
3434
virtual pointer operator->() const override;
35+
virtual bool operator!=(const self_type &rhs) const override;
3536
};
3637
virtual ~BpfFsTableStorage() {}
3738
virtual bool Find(const string &name, TableStorage::iterator &result) const override;

src/cc/frontends/clang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ endif()
1111

1212
add_library(clang_frontend-objects OBJECT loader.cc b_frontend_action.cc tp_frontend_action.cc kbuild_helper.cc)
1313
add_library(clang_frontend STATIC $<TARGET_OBJECTS:clang_frontend-objects>)
14+
install(TARGETS clang_frontend ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

0 commit comments

Comments
 (0)