-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Make it possible to use nwind-capi as alternative unwinding backend
See also: koute/not-perf#37
- Loading branch information
Showing
8 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# - Try to find nwind_capi library | ||
# | ||
# This will define | ||
# NWIND_CAPI_FOUND | ||
# NWIND_CAPI_INCLUDE_DIRS | ||
# NWIND_CAPI_LIBRARIES | ||
# | ||
|
||
find_path(NWIND_CAPI_INCLUDE_DIRS NAMES nwind_capi.h) | ||
find_library(NWIND_CAPI_LIBRARIES NAMES nwind_capi) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args( | ||
NWIND_CAPI DEFAULT_MSG | ||
NWIND_CAPI_LIBRARIES NWIND_CAPI_INCLUDE_DIRS | ||
) | ||
|
||
mark_as_advanced(NWIND_CAPI_INCLUDE_DIRS NWIND_CAPI_LIBRARIES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ struct Trace | |
} | ||
|
||
static void setup(); | ||
static void invalidateModuleCache(); | ||
|
||
static void print(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2014-2019 Milian Wolff <[email protected]> | ||
SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
/** | ||
* @brief A libunwind based backtrace. | ||
*/ | ||
|
||
#include "trace.h" | ||
|
||
#include <cstdio> | ||
|
||
#include <nwind_capi.h> | ||
|
||
namespace { | ||
struct AddressSpace | ||
{ | ||
AddressSpace() | ||
: handle(nwind_create_local_address_space()) | ||
{ | ||
nwind_local_address_space_use_shadow_stack(handle, 1); | ||
} | ||
|
||
~AddressSpace() | ||
{ | ||
nwind_free_local_address_space(handle); | ||
} | ||
|
||
nwind_local_address_space* const handle; | ||
}; | ||
|
||
nwind_local_address_space* addressSpace() | ||
{ | ||
static AddressSpace addressSpace; | ||
return addressSpace.handle; | ||
} | ||
|
||
struct UnwindContext | ||
{ | ||
UnwindContext() | ||
: handle(nwind_create_local_unwind_context()) | ||
{ | ||
} | ||
|
||
~UnwindContext() | ||
{ | ||
nwind_free_local_unwind_context(handle); | ||
} | ||
|
||
nwind_local_unwind_context* const handle; | ||
}; | ||
|
||
nwind_local_unwind_context* unwindContext() | ||
{ | ||
static thread_local UnwindContext unwindContext; | ||
return unwindContext.handle; | ||
} | ||
} | ||
|
||
void Trace::print() | ||
{ | ||
Trace trace; | ||
if (!trace.fill(1)) { | ||
return; | ||
} | ||
|
||
unsigned frameNr = 0; | ||
for (auto ip : trace) { | ||
++frameNr; | ||
fprintf(stderr, "#%-2u %p\n", frameNr, ip); | ||
} | ||
} | ||
|
||
void Trace::setup() | ||
{ | ||
} | ||
|
||
void Trace::invalidateModuleCache() | ||
{ | ||
nwind_reload_local_address_space(addressSpace()); | ||
} | ||
|
||
int Trace::unwind(void** data) | ||
{ | ||
return nwind_local_backtrace(addressSpace(), unwindContext(), data, MAX_SIZE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,10 @@ void Trace::setup() | |
{ | ||
} | ||
|
||
void Trace::invalidateModuleCache() | ||
{ | ||
} | ||
|
||
void Trace::print() | ||
{ | ||
Trace trace; | ||
|