65 #include <sys/types.h> 75 #include <boost/tokenizer.hpp> 78 #include <include/hpctoolkit-config.h> 90 #define EXT_LIBS_DIR_STR "HPCTOOLKIT_EXT_LIBS_DIR" 91 #define LD_LIBRARY_PATH "LD_LIBRARY_PATH" 93 #define LIBDWARF_NAME "libdwarf.so" 94 #define DLOPEN_OPTS (RTLD_NOW | RTLD_LOCAL) 96 #define KEEP_LIBDWARF_OPEN 0 100 #ifdef DYNINST_USE_LIBDW 105 typedef int dwarf_init_fcn_t
106 (
int, Dwarf_Unsigned, Dwarf_Handler, Dwarf_Ptr, Dwarf_Debug *, Dwarf_Error *);
108 typedef int dwarf_finish_fcn_t (Dwarf_Debug, Dwarf_Error *);
110 typedef void dwarf_dealloc_fcn_t (Dwarf_Debug,
void *, Dwarf_Unsigned);
112 typedef int dwarf_get_fde_list_eh_fcn_t
113 (Dwarf_Debug, Dwarf_Cie **, Dwarf_Signed *, Dwarf_Fde **, Dwarf_Signed *, Dwarf_Error *);
115 typedef int dwarf_get_fde_range_fcn_t
116 (Dwarf_Fde, Dwarf_Addr *, Dwarf_Unsigned *, Dwarf_Ptr *, Dwarf_Unsigned *,
117 Dwarf_Off *, Dwarf_Signed *, Dwarf_Off *, Dwarf_Error *);
119 typedef void dwarf_fde_cie_list_dealloc_fcn_t
120 (Dwarf_Debug, Dwarf_Cie *, Dwarf_Signed, Dwarf_Fde *, Dwarf_Signed);
122 static dwarf_init_fcn_t * real_dwarf_init =
NULL;
123 static dwarf_finish_fcn_t * real_dwarf_finish =
NULL;
124 static dwarf_dealloc_fcn_t * real_dwarf_dealloc =
NULL;
125 static dwarf_get_fde_list_eh_fcn_t * real_dwarf_get_fde_list_eh =
NULL;
126 static dwarf_get_fde_range_fcn_t * real_dwarf_get_fde_range =
NULL;
127 static dwarf_fde_cie_list_dealloc_fcn_t * real_dwarf_fde_cie_list_dealloc =
NULL;
129 #define DWARF_INIT (* real_dwarf_init) 130 #define DWARF_FINISH (* real_dwarf_finish) 131 #define DWARF_DEALLOC (* real_dwarf_dealloc) 132 #define DWARF_GET_FDE_LIST_EH (* real_dwarf_get_fde_list_eh) 133 #define DWARF_GET_FDE_RANGE (* real_dwarf_get_fde_range) 134 #define DWARF_FDE_CIE_LIST_DEALLOC (* real_dwarf_fde_cie_list_dealloc) 136 static string library_file;
137 static void * libdwarf_handle =
NULL;
139 static int found_library = 0;
140 static int dlopen_done = 0;
141 static int dlsym_done = 0;
148 #define DWARF_INIT dwarf_init 149 #define DWARF_FINISH dwarf_finish 150 #define DWARF_DEALLOC dwarf_dealloc 151 #define DWARF_GET_FDE_LIST_EH dwarf_get_fde_list_eh 152 #define DWARF_GET_FDE_RANGE dwarf_get_fde_range 153 #define DWARF_FDE_CIE_LIST_DEALLOC dwarf_fde_cie_list_dealloc 167 #ifdef DYNINST_USE_LIBDW 170 if (! found_library) {
179 libdwarf_handle = dlopen(library_file.c_str(),
DLOPEN_OPTS);
181 if (libdwarf_handle !=
NULL) {
191 if (! found_library) {
204 boost::char_separator <char> sep (
":;",
"", boost::drop_empty_tokens);
205 boost::tokenizer <boost::char_separator <char>> token (path, sep);
207 for (
auto it = token.begin(); it != token.end(); ++it) {
209 libdwarf_handle = dlopen(library_file.c_str(),
DLOPEN_OPTS);
211 if (libdwarf_handle !=
NULL) {
217 if (! found_library) {
223 if (! found_library) {
229 libdwarf_handle = dlopen(library_file.c_str(),
DLOPEN_OPTS);
231 if (libdwarf_handle ==
NULL) {
232 warnx(
"unable to open: %s", library_file.c_str());
241 real_dwarf_init = (dwarf_init_fcn_t *) dlsym(libdwarf_handle,
"dwarf_init");
242 real_dwarf_finish = (dwarf_finish_fcn_t *) dlsym(libdwarf_handle,
"dwarf_finish");
243 real_dwarf_dealloc = (dwarf_dealloc_fcn_t *) dlsym(libdwarf_handle,
"dwarf_dealloc");
244 real_dwarf_get_fde_list_eh = (dwarf_get_fde_list_eh_fcn_t *)
245 dlsym(libdwarf_handle,
"dwarf_get_fde_list_eh");
246 real_dwarf_get_fde_range = (dwarf_get_fde_range_fcn_t *)
247 dlsym(libdwarf_handle,
"dwarf_get_fde_range");
248 real_dwarf_fde_cie_list_dealloc = (dwarf_fde_cie_list_dealloc_fcn_t *)
249 dlsym(libdwarf_handle,
"dwarf_fde_cie_list_dealloc");
251 if (real_dwarf_init ==
NULL 252 || real_dwarf_finish ==
NULL 253 || real_dwarf_dealloc ==
NULL 254 || real_dwarf_get_fde_list_eh ==
NULL 255 || real_dwarf_get_fde_range ==
NULL 256 || real_dwarf_fde_cie_list_dealloc ==
NULL)
274 #if defined(DYNINST_USE_LIBDW) && ! KEEP_LIBDWARF_OPEN 276 dlclose(libdwarf_handle);
277 real_dwarf_init =
NULL;
278 real_dwarf_finish =
NULL;
294 static int open_failed = 0;
296 if (fd < 0 || open_failed) {
311 for (
auto it = addrSet.begin(); it != addrSet.end(); ++it) {
330 if (ret == DW_DLV_ERROR) {
DWARF_DEALLOC (dbg, err, DW_DLA_ERROR); }
332 if (ret != DW_DLV_OK) {
336 Dwarf_Cie * cie_data =
NULL;
337 Dwarf_Fde * fde_data =
NULL;
338 Dwarf_Signed cie_count = 0;
339 Dwarf_Signed fde_count = 0;
342 if (ret == DW_DLV_ERROR) {
DWARF_DEALLOC (dbg, err, DW_DLA_ERROR); }
344 if (ret == DW_DLV_OK ) {
345 for (
long i = 0; i < fde_count; i++) {
346 Dwarf_Addr low_pc = 0;
350 if (ret == DW_DLV_ERROR) {
DWARF_DEALLOC (dbg, err, DW_DLA_ERROR); }
352 if (ret == DW_DLV_OK && low_pc != 0) {
353 addrSet.insert((
void *) low_pc);
361 if (ret == DW_DLV_ERROR) {
DWARF_DEALLOC (dbg, err, DW_DLA_ERROR); }
static void release_libdwarf_functions(void)
#define DWARF_GET_FDE_RANGE
static void dwarf_frame_info_help(int, AddrSet &)
#define DWARF_GET_FDE_LIST_EH
#define DWARF_FDE_CIE_LIST_DEALLOC
static int get_libdwarf_functions(void)
void dwarf_eh_frame_info(int fd)
void add_frame_addr(void *)