Skip to content

Commit

Permalink
Parse DebugInfo with LLDB
Browse files Browse the repository at this point in the history
  • Loading branch information
ttreyer committed Mar 27, 2024
1 parent c44d010 commit 81ea7bd
Show file tree
Hide file tree
Showing 22 changed files with 481 additions and 468 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to
#### Changed
- Better error message for args in mixed probes
- [#3047](https://github.com/bpftrace/bpftrace/pull/3047)
- Parse DWARF using liblldb instead of libdw
- [#3042](https://github.com/bpftrace/bpftrace/pull/3042)
#### Deprecated
#### Removed
#### Fixed
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ set(CMAKE_REQUIRED_DEFINITIONS)

find_package(LibBfd)
find_package(LibOpcodes)
find_package(LibDw)

if(ENABLE_SKB_OUTPUT)
find_package(LibPcap)
Expand Down Expand Up @@ -154,6 +153,8 @@ add_definitions(${LLVM_DEFINITIONS})
find_package(Clang REQUIRED)
include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})

find_package(LLDB)

# BPFtrace compile definitions

set(BPFTRACE_FLAGS)
Expand All @@ -175,8 +176,8 @@ if(HAVE_BFD_DISASM)
endif(LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE)
endif(HAVE_BFD_DISASM)

if (LIBDW_FOUND)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBDW)
if (LLDB_FOUND)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" HAVE_LIBLLDB)
endif ()

if(LIBPCAP_FOUND)
Expand Down
3 changes: 1 addition & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,8 @@ Use specific OS build sections listed earlier if available.
- Flex
- Bison
- Asciidoctor
- LLVM & Clang 10.0+ development packages
- LLVM, LLDB & Clang 10.0+ development packages
- LibElf
- LibDw
- Binutils development package
- Libcereal
- Kernel requirements described earlier
Expand Down
54 changes: 54 additions & 0 deletions cmake/FindLLDB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# - Try to find LLDB
# Once done this will define
#
# LLDB_FOUND - system has lldb
# LLDB_INCLUDE_DIRS - the lldb include directory
# LLDB_LIBRARIES - Link these to use lldb
#
# Copyright (c) 2008 Bernhard Walle <bernhard.walle@gmx.de>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

if (LLDB_LIBRARIES AND LLDB_INCLUDE_DIRS)
set (LLDB_FIND_QUIETLY TRUE)
endif (LLDB_LIBRARIES AND LLDB_INCLUDE_DIRS)

find_path (LLDB_INCLUDE_DIRS
NAMES
lldb/API/LLDB.h
PATHS
ENV CPATH)

find_library (LLDB_LIBRARIES
NAMES
lldb
PATHS
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)


# handle the QUIETLY and REQUIRED arguments and set LLDB_FOUND to TRUE if all listed variables are TRUE
include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LLDB "Please install the lldb development package"
LLDB_LIBRARIES
LLDB_INCLUDE_DIRS)

if (LLDB_FOUND)
add_library(LLDB SHARED IMPORTED)
set_target_properties(LLDB PROPERTIES
INCLUDE_DIRECTORIES "${LLDB_INCLUDE_DIRS}"
IMPORTED_LOCATION "${LLDB_LIBRARIES}")

if (LLVM_VERSION_MAJOR VERSION_GREATER 10)
set_target_properties(LLDB PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES clang-cpp)
else ()
set_target_properties(LLDB PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES libclang)
endif ()
endif (LLDB_FOUND)

mark_as_advanced(LLDB_INCLUDE_DIRS LLDB_LIBRARIES)
41 changes: 0 additions & 41 deletions cmake/FindLibDw.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion docker/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ RUN apt-get update && apt-get install -y \
libbpf-dev \
libbpfcc-dev \
libcereal-dev \
libdw-dev \
libelf-dev \
libiberty-dev \
libpcap-dev \
llvm-dev \
liblldb-dev \
libclang-dev \
systemtap-sdt-dev \
zlib1g-dev
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ RUN apt-get update && apt-get install -y \
libbpf-dev \
libbpfcc-dev \
libcereal-dev \
libdw-dev \
libelf-dev \
libiberty-dev \
libpcap-dev \
llvm-dev \
liblldb-dev \
libclang-dev \
systemtap-sdt-dev \
zlib1g-dev
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
libopcodes
libpcap
libsystemtap
lldb
llvm
pahole
xxd
Expand Down
41 changes: 9 additions & 32 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ endif(STATIC_LINKING)
target_link_libraries(runtime ${LIBBPF_LIBRARIES} ${ZLIB_LIBRARIES})
target_link_libraries(libbpftrace parser resources runtime aot ast arch cxxdemangler_llvm)

if(LLDB_FOUND)
target_link_libraries(runtime LLDB)
endif(LLDB_FOUND)

if(LIBPCAP_FOUND)
target_link_libraries(libbpftrace ${LIBPCAP_LIBRARIES})
endif(LIBPCAP_FOUND)
Expand Down Expand Up @@ -172,45 +176,18 @@ if(STATIC_LINKING)
target_link_libraries(runtime ${LIBBPF_LIBRARIES})
target_link_libraries(runtime ${LIBBCC_LOADER_LIBRARY_STATIC})

find_package(LibLzma)
add_library(LIBLZMA STATIC IMPORTED)
set_property(TARGET LIBLZMA PROPERTY IMPORTED_LOCATION ${LIBLZMA_LIBRARIES})
target_link_libraries(runtime LIBLZMA)

add_library(LIBELF STATIC IMPORTED)
set_property(TARGET LIBELF PROPERTY IMPORTED_LOCATION ${LIBELF_LIBRARIES})
target_link_libraries(runtime LIBELF)
else()
target_link_libraries(runtime ${LIBELF_LIBRARIES})
endif(STATIC_LINKING)

if (LIBDW_FOUND)
if(STATIC_LINKING)
find_package(LibBz2)
find_package(LibLzma)
find_package(LibEbl)

add_library(LIBBZ2 STATIC IMPORTED)
set_property(TARGET LIBBZ2 PROPERTY IMPORTED_LOCATION ${LIBBZ2_LIBRARIES})

add_library(LIBLZMA STATIC IMPORTED)
set_property(TARGET LIBLZMA PROPERTY IMPORTED_LOCATION ${LIBLZMA_LIBRARIES})

add_library(LIBDW STATIC IMPORTED)
set_property(TARGET LIBDW PROPERTY IMPORTED_LOCATION ${LIBDW_LIBRARIES})

set(LIBDW_LIBS LIBBZ2 LIBELF LIBLZMA)

if (${LIBEBL_FOUND})
# libebl is not necessary on some systems (e.g. Alpine)
add_library(LIBEBL STATIC IMPORTED)
set_property(TARGET LIBEBL PROPERTY IMPORTED_LOCATION ${LIBEBL_LIBRARIES})
set(LIBDW_LIBS ${LIBDW_LIBS} LIBEBL)
endif()

target_link_libraries(LIBDW INTERFACE ${LIBDW_LIBS})

target_link_libraries(runtime LIBDW)
else()
target_link_libraries(runtime ${LIBDW_LIBRARIES})
endif()
endif()

# Support for std::filesystem
# GCC version <9 and Clang (all versions) require -lstdc++fs
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "9")
Expand Down
4 changes: 2 additions & 2 deletions src/build_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ std::string BuildInfo::report()
#else
<< "no" << std::endl;
#endif
buf << " libdw (DWARF support): "
#ifdef HAVE_LIBDW
buf << " liblldb (DWARF support): "
#ifdef HAVE_LIBLLDB
<< "yes" << std::endl;
#else
<< "no" << std::endl;
Expand Down
Loading

0 comments on commit 81ea7bd

Please sign in to comment.