aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/backtrace/backtrace.h
blob: ea70d9558cac8283173a3ff3a1ff6060b453e8e3 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include <library/cpp/yt/memory/range.h>

namespace NYT::NBacktrace {

////////////////////////////////////////////////////////////////////////////////

using TBacktrace = TRange<const void*>;
using TBacktraceBuffer = TMutableRange<const void*>;

//! Obtains a backtrace via a given cursor.
/*!
 *  \param buffer is the buffer where the backtrace is written to
 *  \param framesToSkip is the number of top frames to skip
 *  \returns the portion of #buffer that has actually been filled
 */
template <class TCursor>
TBacktrace GetBacktrace(
    TCursor* cursor,
    TBacktraceBuffer buffer,
    int framesToSkip);

//! Symbolizes a backtrace invoking a given callback for each frame.
/*!
 *  \param backtrace Backtrace to symbolize
 *  \param frameCallback Callback to invoke per each frame
 */
void SymbolizeBacktrace(
    TBacktrace backtrace,
    const std::function<void(TStringBuf)>& frameCallback);

//! Symbolizes a backtrace to a string.
/*!
 *  \param backtrace Backtrace to symbolize
 */
TString SymbolizeBacktrace(TBacktrace backtrace);

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NBacktrace

#define BACKTRACE_INL_H_
#include "backtrace-inl.h"
#undef BACKTRACE_INL_H_