aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/backtrace/backtrace-inl.h
blob: b78eeffd75fc27b96f49cb717909e2595173b426 (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
#pragma once
#ifndef BACKTRACE_INL_H_
#error "Direct inclusion of this file is not allowed, include backtrace.h"
// For the sake of sane code completion.
#include "backtrace.h"
#endif

#include <util/system/compiler.h>

namespace NYT::NBacktrace {

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

template <class TCursor>
Y_NO_INLINE TBacktrace GetBacktrace(
    TCursor* cursor,
    TBacktraceBuffer buffer,
    int framesToSkip)
{
    // Account for the current frame.
    ++framesToSkip;
    size_t frameCount = 0;
    while (frameCount < buffer.size() && !cursor->IsFinished()) {
        if (framesToSkip > 0) {
            --framesToSkip;
        } else {
            buffer[frameCount++] = cursor->GetCurrentIP();
        }
        cursor->MoveNext();
    }
    return {buffer.begin(), frameCount};
}

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

} // namespace NYT::NBacktrace