Coverage Report

Created: 2025-06-13 06:30

/src/wxwidgets/include/wx/unix/stackwalk.h
Line
Count
Source (jump to first uncovered line)
1
///////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/unix/stackwalk.h
3
// Purpose:     declaration of wxStackWalker for Unix
4
// Author:      Vadim Zeitlin
5
// Created:     2005-01-19
6
// Copyright:   (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
7
// Licence:     wxWindows licence
8
///////////////////////////////////////////////////////////////////////////////
9
10
#ifndef _WX_UNIX_STACKWALK_H_
11
#define _WX_UNIX_STACKWALK_H_
12
13
// ----------------------------------------------------------------------------
14
// wxStackFrame
15
// ----------------------------------------------------------------------------
16
17
class WXDLLIMPEXP_BASE wxStackFrame : public wxStackFrameBase
18
{
19
    friend class wxStackWalker;
20
21
public:
22
    // arguments are the stack depth of this frame, its address and the return
23
    // value of backtrace_symbols() for it
24
    //
25
    // NB: we don't copy syminfo pointer so it should have lifetime at least as
26
    //     long as ours
27
    wxStackFrame(size_t level = 0, void *address = nullptr, const char *syminfo = nullptr)
28
0
        : wxStackFrameBase(level, address)
29
0
    {
30
0
        m_syminfo = syminfo;
31
0
    }
32
33
protected:
34
    virtual void OnGetName() override;
35
36
    // optimized for the 2 step initialization done by wxStackWalker
37
    void Set(const wxString &name, const wxString &filename, const char* syminfo,
38
             size_t level, size_t numLine, void *address)
39
0
    {
40
0
        m_level = level;
41
0
        m_name = name;
42
0
        m_filename = filename;
43
0
        m_syminfo = syminfo;
44
45
0
        m_line = numLine;
46
0
        m_address = address;
47
0
    }
48
49
private:
50
    const char *m_syminfo;
51
};
52
53
// ----------------------------------------------------------------------------
54
// wxStackWalker
55
// ----------------------------------------------------------------------------
56
57
class WXDLLIMPEXP_BASE wxStackWalker : public wxStackWalkerBase
58
{
59
public:
60
    // we need the full path to the program executable to be able to use
61
    // addr2line, normally we can retrieve it from wxTheApp but if wxTheApp
62
    // doesn't exist or doesn't have the correct value, the path may be given
63
    // explicitly
64
    wxStackWalker(const char *argv0 = nullptr)
65
0
    {
66
0
        ms_exepath = wxString::FromAscii(argv0);
67
0
    }
68
69
    ~wxStackWalker()
70
0
    {
71
0
        FreeStack();
72
0
    }
73
74
    virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) override;
75
#if wxUSE_ON_FATAL_EXCEPTION
76
0
    virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) override { Walk(2, maxDepth); }
77
#endif // wxUSE_ON_FATAL_EXCEPTION
78
79
0
    static const wxString& GetExePath() { return ms_exepath; }
80
81
82
    // these two may be used to save the stack at some point (fast operation)
83
    // and then process it later (slow operation)
84
    void SaveStack(size_t maxDepth);
85
    void ProcessFrames(size_t skip);
86
    void FreeStack();
87
88
private:
89
    int InitFrames(wxStackFrame *arr, size_t n, void **addresses, char **syminfo);
90
91
    static wxString ms_exepath;
92
    static void *ms_addresses[];
93
    static char **ms_symbols;
94
    static int m_depth;
95
};
96
97
#endif // _WX_UNIX_STACKWALK_H_