Skip to content

Commit

Permalink
Make debuginfod configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Jan 24, 2025
1 parent 84ffa4b commit b00e6e2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 17 deletions.
30 changes: 17 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ IfUpdatedUnsetAll(lo2s_USE_STATIC_LIBS
Radare_USE_STATIC_LIBS
Sensors_USE_STATIC_LIBS
Veosinfo_USE_STATIC_LIBS
Audit_USE_STATIC_LIBS)
Audit_USE_STATIC_LIBS
Debuginfod_USE_STATIC_LIBS
)

if(lo2s_USE_STATIC_LIBS STREQUAL "OFF")
set(Dl_USE_STATIC_LIBS OFF CACHE BOOL "")
Expand All @@ -56,7 +58,6 @@ if(lo2s_USE_STATIC_LIBS STREQUAL "OFF")
else()
if(lo2s_USE_STATIC_LIBS STREQUAL "MOSTLY")
set(Dl_USE_STATIC_LIBS OFF CACHE BOOL "")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
elseif(lo2s_USE_STATIC_LIBS STREQUAL "ALL")
set(Dl_USE_STATIC_LIBS ON CACHE BOOL "")
Expand All @@ -67,8 +68,6 @@ else()
set(CMAKE_LINK_SEARCH_START_STATIC 1)
set(CMAKE_LINK_SEARCH_END_STATIC 1)
endif()

if(lo2s_USE_STATIC_LIBS STREQUAL "MOSTLY")
set(Dl_USE_STATIC_LIBS OFF CACHE BOOL "")
set(LibElf_USE_STATIC_LIBS ON CACHE BOOL "")
set(OTF2_USE_STATIC_LIBS ON CACHE BOOL "")
Expand All @@ -81,6 +80,8 @@ else()
set(Veosinfo_USE_STATIC_LIBS ON CACHE BOOL "")
set(Radare_USE_STATIC_LIBS ON CACHE BOOL "")
set(Audit_USE_STATIC_LIBS ON CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS ON CACHE BOOL "")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif()

# Check if we are running Linux
Expand Down Expand Up @@ -116,6 +117,7 @@ find_package(CUDAToolkit)
find_package(Radare)
find_package(Audit)
find_package(LibElf REQUIRED)
find_package(Debuginfod)


# configurable options
Expand All @@ -135,6 +137,8 @@ CMAKE_DEPENDENT_OPTION(USE_VEOSINFO "Use libveosinfo to sample NEC SX-Aurora Tsu
add_feature_info("USE_VEOSINFO" USE_VEOSINFO "Use libveosinfo to sample NEC SX-Aurora Tsubasa cards.")
CMAKE_DEPENDENT_OPTION(USE_CUPTI "Use CUPTI to record CUDA activity." ON "CUDAToolkit_FOUND" OFF)
add_feature_info("USE_CUPTI" USE_CUPTI "Use CUPTI to record CUDA activity.")
CMAKE_DEPENDENT_OPTION(USE_DEBUGINFOD "Use Debuginfod to download debug information on-demand." ON "Debuginfod_FOUND" OFF)
add_feature_info("USE_DEBUGINFOD" USE_DEBUGINFOD "Use Debuginfod to download debug information on-demand.")
# system configuration checks
CHECK_INCLUDE_FILES(linux/hw_breakpoint.h HAVE_HW_BREAKPOINT_H)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_attr" clockid linux/perf_event.h HAVE_PERF_EVENT_ATTR_CLOCKID)
Expand Down Expand Up @@ -231,17 +235,8 @@ target_link_libraries(lo2s
std::filesystem
LibElf::LibElf
LibElf::LibDw
debuginfod
)

find_path(DEBUGINFOD_INCLUDE_DIRS elfutils/debuginfod.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

if(DEBUGINFOD_INCLUDE_DIRS)
target_compile_definitions(lo2s PUBLIC HAVE_DEBUGINFOD)
endif()

# old glibc versions require -lrt for clock_gettime()
if(NOT CLOCK_GETTIME_FOUND)
if(CLOCK_GETTIME_FOUND_WITH_RT)
Expand Down Expand Up @@ -321,6 +316,15 @@ if (USE_VEOSINFO)
endif()
endif()

if (USE_DEBUGINFOD)
if (Debuginfod_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_DEBUGINFOD)
target_link_libraries(lo2s PRIVATE Debuginfod::Debuginfod)
else()
message(SEND_ERROR "Debuginfod not found but requested")
endif()
endif()

if (USE_LIBPFM)
if (Libpfm_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_LIBPFM)
Expand Down
56 changes: 56 additions & 0 deletions cmake/FindDebuginfod.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2022, Technische Universität Dresden, Germany
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the
# distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include(${CMAKE_CURRENT_LIST_DIR}/UnsetIfUpdated.cmake)

# Linking libelf isn't a great default because it produces warnings
option(Debuginfod_USE_STATIC_LIBS "Link debuginfod statically." OFF)

UnsetIfUpdated(Debuginfod_LIBRARY Debuginfod_USE_STATIC_LIBS)

find_path(Debuginfod_INCLUDE_DIRS libelf.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

if(Debuginfod_USE_STATIC_LIBS)
find_library(Debuginfod_LIBRARY NAMES libdebuginfod.a
HINTS ENV LIBRARY_PATH)
else()
find_library(Debuginfod_LIBRARY NAMES libdebuginfod.so
HINTS ENV LIBRARY_PATH LD_LIBRARY_PATH)
endif()

include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Debuginfod DEFAULT_MSG
Debuginfod_LIBRARY
Debuginfod_INCLUDE_DIRS)

if(Debuginfod_FOUND)
add_library(Debuginfod::Debuginfod UNKNOWN IMPORTED)
set_property(TARGET Debuginfod::Debuginfod PROPERTY IMPORTED_LOCATION ${Debuginfod_LIBRARY})
target_include_directories(Debuginfod::Debuginfod INTERFACE ${Debuginfod_INCLUDE_DIRS})
endif()

mark_as_advanced(Debuginfod_LIBRARY Debuginfod_INCLUDE_DIRS)
4 changes: 2 additions & 2 deletions include/lo2s/function_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <lo2s/line_info.hpp>
#include <lo2s/util.hpp>

#include <string>
#include <regex>
#include <string>

namespace lo2s
{
Expand Down Expand Up @@ -127,4 +127,4 @@ class Kallsyms : public FunctionResolver
std::map<Range, std::string> kallsyms_;
uint64_t start_;
};
}
} // namespace lo2s
3 changes: 2 additions & 1 deletion include/lo2s/instruction_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with lo2s. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#pragma once

#include <lo2s/address.hpp>
#ifdef HAVE_RADARE
Expand All @@ -28,6 +28,7 @@
#include <lo2s/util.hpp>

#include <string>

namespace lo2s
{
class InstructionResolver
Expand Down
3 changes: 2 additions & 1 deletion include/lo2s/process_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#pragma once

#include <lo2s/address.hpp>
#include <lo2s/dwarf_resolve.hpp>
#include <lo2s/function_resolver.hpp>
#include <lo2s/instruction_resolver.hpp>
#include <lo2s/dwarf_resolve.hpp>
#include <lo2s/log.hpp>
#include <lo2s/perf/types.hpp>

Expand Down Expand Up @@ -72,6 +72,7 @@ class ProcessInfo
FunctionResolver& fr;
InstructionResolver& ir;
};

const Process process_;
mutable std::shared_mutex mutex_;
std::map<Range, Mapping> map_;
Expand Down
1 change: 1 addition & 0 deletions src/perf/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ void SysfsEvent::use_sampling_options(const bool& use_pebs, const bool& sampling
Log::debug() << "using sampling event \'" << name_ << "\', period: " << attr_.sample_period;

attr_.mmap = 1;
attr_.mmap2 = 1;
}
else
{
Expand Down

0 comments on commit b00e6e2

Please sign in to comment.