Skip to content

Commit

Permalink
fix: solve multiple crashes in drace on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoessbauer committed Jan 9, 2020
1 parent 1609995 commit 2bbf848
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
14 changes: 10 additions & 4 deletions drace-client/include/annotations/drace_annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,32 @@

#ifdef DRACE_ANNOTATION

#ifdef __unix__
#define DRACE_ANNOTATION_EXPORT
#elif defined(_WIN32) || defined(WIN32)
#define DRACE_ANNOTATION_EXPORT __declspec(dllexport)
#endif

extern "C" {

#pragma optimize("", off)
__declspec(dllexport) void __drace_happens_before(void* identifier) {
DRACE_ANNOTATION_EXPORT void __drace_happens_before(void* identifier) {
// cppcheck-suppress unreadVariable
volatile void* noopt = identifier;
}
#pragma optimize("", on)


#pragma optimize("", off)
__declspec(dllexport) void __drace_happens_after(void* identifier) {
DRACE_ANNOTATION_EXPORT void __drace_happens_after(void* identifier) {
// cppcheck-suppress unreadVariable
volatile void* noopt = identifier;
}
#pragma optimize("", on)


#pragma optimize("", off)
__declspec(dllexport) void __drace_enter_exclude() {
DRACE_ANNOTATION_EXPORT void __drace_enter_exclude() {
int var;
// cppcheck-suppress unreadVariable
volatile void* noopt = &var;
Expand All @@ -58,7 +64,7 @@ extern "C" {


#pragma optimize("", off)
__declspec(dllexport) void __drace_leave_exclude() {
DRACE_ANNOTATION_EXPORT void __drace_leave_exclude() {
int var;
// cppcheck-suppress unreadVariable
volatile void* noopt = &var;
Expand Down
10 changes: 10 additions & 0 deletions drace-client/include/race-collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ namespace drace {
if (num_races() > MAX)
return;

#ifdef WINDOWS
auto ttr = std::chrono::duration_cast<std::chrono::milliseconds>(clock_t::now() - _start_time);
#else
// \todo when running under DR, calling clock::now()
// leads to a segfault
auto ttr = std::chrono::milliseconds(0);
#endif

std::lock_guard<DrLock> lock(_races_lock);

Expand Down Expand Up @@ -160,6 +166,10 @@ namespace drace {
* \return true if race is suppressed
*/
bool filter_excluded(const Detector::Race * r) {
DR_ASSERT(r != nullptr);
if(r->first.stack_size == 0 || r->second.stack_size == 0)
return false;

// PC is null
if (r->first.stack_trace[r->first.stack_size - 1] == 0x0)
return true;
Expand Down
7 changes: 5 additions & 2 deletions drace-client/src/drace-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ DR_EXPORT void dr_client_main(client_id_t id, int argc, const char *argv[])

LOG_INFO(-1, "application pid: %i", dr_get_process_id());

#ifdef WINDOWS
// \todo port to linux
// if we try to access a non-existing SHM,
// DR will spuriously fail some time later
if (params.extctrl) {
#if WINDOWS
if (!MSR::connect()) {
LOG_ERROR(-1, "MSR not available (required for --extctrl)");
dr_abort();
}
#else
LOG_ERROR(-1, "--extctrl is not supported on linux yet.");
dr_abort();
#endif
}
#endif
}

namespace drace {
Expand Down
7 changes: 5 additions & 2 deletions drace-client/src/module/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ namespace drace {
if (modptr->instrument != INSTR_FLAGS::STACK) {
// check if mod name is excluded
// in this case, we check for syms but only instrument stack
// \todo for linux, either strip .so.x suffix, or add support for wildcards
if (std::binary_search(excluded_mods.begin(), excluded_mods.end(), mod_name)) {
modptr->instrument = (INSTR_FLAGS)(INSTR_FLAGS::SYMBOLS | INSTR_FLAGS::STACK);
}
}
if (modptr->instrument & INSTR_FLAGS::SYMBOLS) {
// check if debug info is available
// TODO: unclear if drsyms is threadsafe.
// \todo unclear if drsyms is threadsafe.
// so better lock
lock_write();
modptr->debug_info = _syms->debug_info_available(mod);
Expand All @@ -150,7 +151,9 @@ namespace drace {
return modptr;
}

/* Module load event implementation.
/**
* \brief Module load event implementation.
*
* To get clean call-stacks, we add the shadow-stack instrumentation
* to all modules (even the excluded ones).
* \note As this function is passed as a callback to a c API, we cannot use std::bind
Expand Down

0 comments on commit 2bbf848

Please sign in to comment.