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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#pragma once
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
namespace Hsdbg
{
enum class TargetState : uint8_t
{
NoTarget,
Loaded,
Launching,
Running,
Stopped,
Exited,
Crashed,
};
enum class StopReason : uint8_t
{
None,
Breakpoint,
Step,
Signal,
Exception,
Watchpoint,
};
enum class StepMode : uint8_t
{
Line,
Instruction,
};
constexpr auto to_string(TargetState state) -> std::string_view
{
switch (state)
{
case TargetState::NoTarget: return "no target";
case TargetState::Loaded: return "loaded";
case TargetState::Launching: return "launching";
case TargetState::Running: return "running";
case TargetState::Stopped: return "stopped";
case TargetState::Exited: return "exited";
case TargetState::Crashed: return "crashed";
}
return "unknown";
}
constexpr auto to_string(StopReason reason) -> std::string_view
{
switch (reason)
{
case StopReason::None: return "none";
case StopReason::Breakpoint: return "breakpoint";
case StopReason::Step: return "step";
case StopReason::Signal: return "signal";
case StopReason::Exception: return "exception";
case StopReason::Watchpoint: return "watchpoint";
}
return "unknown";
}
struct LaunchSpec
{
std::filesystem::path executable;
std::filesystem::path working_directory;
std::vector<std::string> arguments;
std::vector<std::string> environment;
// running should reach the first breakpoint, not the loader's entry point
bool stop_at_entry = false;
};
struct Breakpoint
{
uint32_t id = 0;
int32_t backend_id = 0;
std::filesystem::path file;
uint32_t line = 0;
std::string function;
uint64_t address = 0;
std::string condition;
// how many hits lldb lets through before it starts stopping
uint32_t ignore_count = 0;
uint32_t hit_count = 0;
bool enabled = true;
bool resolved = false;
// set by name, so file and line are whatever lldb found rather than
// what was asked for
bool by_function = false;
// set on an instruction, identified by where it sits in the binary so it
// survives the process being restarted somewhere else
bool by_address = false;
uint64_t file_address = 0;
};
struct StackFrame
{
uint32_t index = 0;
uint64_t program_counter = 0;
std::string function;
std::filesystem::path file;
uint32_t line = 0;
};
struct Thread
{
uint64_t id = 0;
std::string name;
StopReason stop_reason = StopReason::None;
};
struct Variable
{
std::string name;
std::string type;
std::string value;
std::vector<Variable> children;
};
struct Register
{
std::string name;
uint64_t value = 0;
};
struct Instruction
{
// where the instruction is right now, which is the load address once a
// process is running and the address in the binary before that
uint64_t address = 0;
// the same instruction across runs, so a breakpoint can point at it
uint64_t file_address = 0;
std::string mnemonic;
std::string operands;
std::string comment;
uint32_t size = 0;
// whether the selected frame is sitting on this one
bool current = false;
};
struct Symbol
{
std::string name;
uint64_t file_address = 0;
uint64_t address = 0;
uint64_t size = 0;
};
// one recorded activation of a traced function: when it was entered and how
// long it took. duration stays zero until the matching return is seen
struct TraceCall
{
double start = 0.0; // seconds since tracing began
double duration = 0.0; // seconds spent inside the call
};
// a function the user asked to time. the debugger sets an internal breakpoint
// on it that records each call without stopping the ui
struct FunctionTrace
{
uint32_t id = 0;
std::string function;
int32_t entry_backend_id = 0;
uint64_t call_count = 0;
std::vector<TraceCall> calls;
};
}
|