-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.cpp
More file actions
91 lines (80 loc) · 2.57 KB
/
dump.cpp
File metadata and controls
91 lines (80 loc) · 2.57 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include <wx/stackwalk.h>
#include <vector>
class wxStackTrace final : public wxStackWalker
{
public:
using StackFrameCollection = std::vector<wxStackFrame>;
using SizeType = typename StackFrameCollection::size_type;
wxStackTrace() noexcept : wxStackTrace(1, false) {}
wxStackTrace(const wxStackTrace &) noexcept = default;
wxStackTrace(wxStackTrace &&) noexcept = default;
explicit wxStackTrace(bool needFileInfo) noexcept : wxStackTrace(1, needFileInfo) {}
explicit wxStackTrace(size_t skipFrames) noexcept : wxStackTrace{skipFrames + 1, false} {}
wxStackTrace(SizeType skipFrames, bool needFileInfo) noexcept : wxStackWalker{}, needFileInfo{needFileInfo}
{
try
{
Walk(skipFrames + internalOffset);
}
catch (...)
{
frames.clear();
}
}
SizeType FrameCount() const noexcept
{
return frames.size();
}
const wxStackFrame &GetFrame(SizeType index) const noexcept
{
static auto emptyStackFrame = wxStackFrame{};
if (frames.size() == 0)
return emptyStackFrame;
if (index > frames.size() - 1)
index = frames.size() - 1;
return frames[index];
}
const StackFrameCollection &GetFrames() const noexcept
{
return frames;
}
// wxString ToString() const noexcept { // need to fix this and <filename unknown> issue possibly with configs
// auto result = wxString {};
// for (const auto& frame : frames)
// result += wxString::Format(needFileInfo ? " at %s in %s:line %lu\n" : " at %s\n", frame.GetName(), frame.GetFileName().empty() ? "<filename unknown>" : frame.GetFileName(), frame.GetLine());
// return result;
// }
wxString ToString() const noexcept
{
wxString result;
for (const auto &frame : frames)
{
if (needFileInfo)
{
// result += wxString::Format(
// " at %s in %s:line %lu\n",
// frame.GetName(),
// frame.GetFileName().empty() ? "<filename unknown>" : frame.GetFileName(),
// static_cast<unsigned long>(frame.GetLine()));
result += frame.GetFileName();
}
else
{
result += wxString::Format(" at %s\n", frame.GetName());
}
}
return result;
}
wxStackTrace &operator=(const wxStackTrace &) noexcept = default;
wxStackTrace &operator=(wxStackTrace &&) noexcept = default;
private:
void OnStackFrame(const wxStackFrame &frame) override
{
frames.push_back(frame);
}
// static constexpr SizeType internalOffset = 3;
static constexpr SizeType internalOffset = 0;
StackFrameCollection frames;
bool needFileInfo = false;
};