-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy paththreaddb.cc
More file actions
31 lines (27 loc) · 824 Bytes
/
threaddb.cc
File metadata and controls
31 lines (27 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "libpstack/threaddb.h"
#include <dlfcn.h>
namespace pstack {
const ThreadDb *loadThreadDb() {
static ThreadDb tdb;
static const ThreadDb *result = [] () -> const ThreadDb * {
void *handle = dlopen("libthread_db.so.1", RTLD_LAZY | RTLD_GLOBAL);
if (!handle)
return nullptr;
#define LOAD(name) tdb.name = reinterpret_cast<decltype(tdb.name)>(dlsym(handle, "td_" #name))
LOAD(ta_new);
LOAD(ta_delete);
LOAD(ta_thr_iter);
LOAD(thr_get_info);
#undef LOAD
if (!tdb.ta_new || !tdb.ta_delete || !tdb.ta_thr_iter || !tdb.thr_get_info) {
dlclose(handle);
return nullptr;
}
return &tdb;
}();
return result;
}
bool threaddbAvailable() {
return loadThreadDb() != nullptr;
}
} // namespace pstack