Skip to content

Commit

Permalink
Modify libdw detection and check for conflict with dyninst
Browse files Browse the repository at this point in the history
  • Loading branch information
daboehme committed Oct 25, 2017
1 parent 004d799 commit 786700b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 87 deletions.
38 changes: 24 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ option(WITH_CUPTI "Enable CUPTI service (CUDA performance analysis)" FALSE)
option(WITH_NETOUT "Enable netout service (requires curl)" FALSE)
option(WITH_PAPI "Enable PAPI hardware counter service (requires papi)" TRUE)
option(WITH_LIBPFM "Enable libpfm (perf_event) sampling" TRUE)
option(WITH_LIBDW "Enable libdw support (for module detection in callpath service)" FALSE)
option(WITH_CALLPATH "Enable callpath service (requires libunwind)" TRUE)
option(WITH_MPI "Enable MPI" TRUE)
option(WITH_MPIT "Enable MPI-T" TRUE)
Expand Down Expand Up @@ -87,20 +88,6 @@ if(CALIPER_HAVE_TAU)
list(APPEND CALIPER_EXTERNAL_LIBS ${tau_lib})
endif()

# Find libunwind
if (WITH_CALLPATH)
include(FindLibunwind)
if (LIBUNWIND_FOUND)
set(CALIPER_HAVE_LIBUNWIND TRUE)
list(APPEND CALIPER_EXTERNAL_LIBS ${LIBUNWIND_LIBRARY})
endif()
include(FindDwarf)
if (DWARF_FOUND)
list(APPEND CALIPER_EXTERNAL_LIBS dw)
add_definitions(-DWITH_DWARF)
endif()
endif()

if (WITH_NETOUT)
include(FindLibcurl)
if (LIBCURL_FOUND)
Expand Down Expand Up @@ -145,6 +132,29 @@ if (WITH_DYNINST)
endif()
endif()

# Find libunwind
if (WITH_CALLPATH)
include(FindLibunwind)
if (LIBUNWIND_FOUND)
set(CALIPER_HAVE_LIBUNWIND TRUE)
list(APPEND CALIPER_EXTERNAL_LIBS ${LIBUNWIND_LIBRARY})
endif()
if (WITH_LIBDW)
# For some reason Dyninst crashes when libdw is linked.
# Detect this here and disable libdw.
if (Dyninst_FOUND)
message(WARNING "Libdw option is incompatible with dyninst -- disabling libdw.")
else()
include(FindLibDw)
if (LIBDW_FOUND)
message(STATUS "Found libdw in " ${LIBDW_LIBRARY})
list(APPEND CALIPER_EXTERNAL_LIBS ${LIBDW_LIBRARY})
set(CALIPER_HAVE_LIBDW TRUE)
endif()
endif()
endif()
endif()

if (WITH_GOTCHA)
set(CALIPER_HAVE_GOTCHA TRUE)
set(GOTCHA_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/ext/gotcha/gotcha-download/gotcha-src/include)
Expand Down
1 change: 1 addition & 0 deletions caliper-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#cmakedefine CALIPER_HAVE_DYNINST
#cmakedefine CALIPER_HAVE_GOTCHA
#cmakedefine CALIPER_HAVE_CUPTI
#cmakedefine CALIPER_HAVE_LIBDW

// Version information -- numerical and a version string
#define CALIPER_MAJOR_VERSION @CALIPER_MAJOR_VERSION@
Expand Down
68 changes: 0 additions & 68 deletions cmake/FindDwarf.cmake

This file was deleted.

42 changes: 42 additions & 0 deletions cmake/FindLibDw.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Try to find LIBDW headers and libraries.
#
# Usage of this module as follows:
#
# find_package(ElfUtils)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# LIBDW_PREFIX Set this variable to the root installation of
# libpapi if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# LIBDW_FOUND System has LIBDW libraries and headers
# LIBDW_LIBRARIES The LIBDW library
# LIBDW_INCLUDE_DIRS The location of LIBDW headers

if (LIBDW_INCLUDE_DIR AND LIBDW_LIBRARY)
set(LIBDW_FIND_QUIETLY true)
endif()

find_path(LIBDW_INCLUDE_DIR elfutils/libdw.h
HINTS ${LIBDW_PREFIX}/include
)

find_library(LIBDW_LIBRARY
NAMES dw
HINTS ${LIBDW_PREFIX}/lib
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBDW DEFAULT_MSG
LIBDW_LIBRARY
LIBDW_INCLUDE_DIR
)

mark_as_advanced(
LIBDW_INCLUDE_DIR
LIBDW_LIBRARY
)
10 changes: 5 additions & 5 deletions src/services/callpath/Callpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define UNW_LOCAL_ONLY
#include <libunwind.h>

#ifdef WITH_DWARF
#ifdef CALIPER_HAVE_LIBDW
#include <elfutils/libdwfl.h>
#include <unistd.h>
#endif
Expand All @@ -72,7 +72,7 @@ bool use_addr { false };

unsigned skip_frames { 0 };

#ifdef WITH_DWARF
#ifdef CALIPER_HAVE_LIBDW
Dwfl* dwfl;
Dwfl_Module* caliper_module;
#endif
Expand Down Expand Up @@ -124,7 +124,7 @@ void snapshot_cb(Caliper* c, int scope, const SnapshotRecord*, SnapshotRecord* s

while (n < MAX_PATH && unw_step(&unw_cursor) > 0) {

#ifdef WITH_DWARF
#ifdef CALIPER_HAVE_LIBDW
// skip stack frames inside caliper
unw_word_t ip;
unw_get_reg(&unw_cursor, UNW_REG_IP, &ip);
Expand All @@ -137,7 +137,7 @@ void snapshot_cb(Caliper* c, int scope, const SnapshotRecord*, SnapshotRecord* s

// store path from top to bottom
if (use_addr) {
#ifndef WITH_DWARF
#ifndef CALIPER_HAVE_LIBDW
unw_word_t ip;
unw_get_reg(&unw_cursor, UNW_REG_IP, &ip);
#endif
Expand Down Expand Up @@ -166,7 +166,7 @@ void snapshot_cb(Caliper* c, int scope, const SnapshotRecord*, SnapshotRecord* s

void initialize()
{
#ifdef WITH_DWARF
#ifdef CALIPER_HAVE_LIBDW
// initialize dwarf
char *debuginfo_path=nullptr;
Dwfl_Callbacks callbacks;
Expand Down

0 comments on commit 786700b

Please sign in to comment.