Skip to content

Commit 50a5f21

Browse files
julianbrostAl2Klimov
authored andcommitted
Add comments to stack trace formatter and test case
1 parent d81f040 commit 50a5f21

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/base/stacktrace.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ using namespace icinga;
1414

1515
std::ostream &icinga::operator<<(std::ostream &os, const StackTraceFormatter &f)
1616
{
17+
/* In most cases, this operator<< just relies on the operator<< for the `boost::stacktrace::stacktrace` wrapped in
18+
* the `StackTraceFormatter`. But as this operator turned out to not work properly on some platforms, there is a
19+
* fallback implementation that can be enabled using the `-DICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS` flag at
20+
* compile time. This will then switch to `backtrace_symbols()` from `<execinfo.h>` instead of the implementation
21+
* provided by Boost.
22+
*/
23+
1724
const boost::stacktrace::stacktrace &stack = f.m_Stack;
1825

1926
#ifdef ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS

lib/base/stacktrace.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
namespace icinga
99
{
1010

11+
/**
12+
* Formatter for `boost::stacktrace::stacktrace` objects
13+
*
14+
* This class wraps `boost::stacktrace::stacktrace` objects and provides an operator<<
15+
* for printing them to an `std::ostream` in a custom format.
16+
*/
1117
class StackTraceFormatter {
1218
public:
1319
StackTraceFormatter(const boost::stacktrace::stacktrace &stack) : m_Stack(stack) {}

test/base-stacktrace.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
using namespace icinga;
77

88

9+
/* If you are reading this, you are probably doing so because this test case just failed. This might happen as it
10+
* heavily depends on platform and compiler behavior. There are two likely causes why this could break:
11+
*
12+
* - Your compiler found new ways to optimize the functions that are called to create a stack, even though we tried
13+
* to disable optimizations using #pragmas for some compilers. If you know a way to disable (more) optimizations for
14+
* your compiler, you can try if this helps.
15+
*
16+
* - Boost fails to resolve symbol names as we've already seen on some platforms. In this case, you can try again
17+
* passing the additional flag `-DICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS=ON` to CMake and see if this helps.
18+
*
19+
* In any case, please report a bug. If you run `make CTEST_OUTPUT_ON_FAILURE=1 test`, the stack trace in question
20+
* should be printed. If it looks somewhat meaningful, you can probably ignore a failure of this test case.
21+
*/
22+
923
#pragma GCC push_options
1024
#pragma GCC optimize ("O0")
1125
#pragma clang optimize off

0 commit comments

Comments
 (0)