@@ -38,11 +38,12 @@ Debugger& Debugger::the()
38
38
}
39
39
40
40
void Debugger::initialize (
41
+ String source_root,
41
42
Function<HasControlPassedToUser(const PtraceRegisters&)> on_stop_callback,
42
43
Function<void()> on_continue_callback,
43
44
Function<void()> on_exit_callback)
44
45
{
45
- s_the = new Debugger (move (on_stop_callback), move (on_continue_callback), move (on_exit_callback));
46
+ s_the = new Debugger (source_root, move (on_stop_callback), move (on_continue_callback), move (on_exit_callback));
46
47
}
47
48
48
49
bool Debugger::is_initialized ()
@@ -51,10 +52,12 @@ bool Debugger::is_initialized()
51
52
}
52
53
53
54
Debugger::Debugger (
55
+ String source_root,
54
56
Function<HasControlPassedToUser(const PtraceRegisters&)> on_stop_callback,
55
57
Function<void ()> on_continue_callback,
56
58
Function<void ()> on_exit_callback)
57
- : m_on_stopped_callback(move(on_stop_callback))
59
+ : m_source_root(source_root)
60
+ , m_on_stopped_callback(move(on_stop_callback))
58
61
, m_on_continue_callback(move(on_continue_callback))
59
62
, m_on_exit_callback(move(on_exit_callback))
60
63
{
@@ -76,7 +79,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
76
79
if (!session)
77
80
return ;
78
81
79
- auto address = session->debug_info (). get_instruction_from_source (position.file_path , position.line_number );
82
+ auto address = session->get_address_from_source_position (position.file_path , position.line_number );
80
83
if (!address.has_value ()) {
81
84
dbgln (" Warning: couldn't get instruction address from source" );
82
85
// TODO: Currently, the GUI will indicate that a breakpoint was inserted/removed at this line,
@@ -86,10 +89,10 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
86
89
}
87
90
88
91
if (change_type == BreakpointChange::Added) {
89
- bool success = session->insert_breakpoint (reinterpret_cast <void *>(address.value ()));
92
+ bool success = session->insert_breakpoint (reinterpret_cast <void *>(address.value (). address ));
90
93
ASSERT (success);
91
94
} else {
92
- bool success = session->remove_breakpoint (reinterpret_cast <void *>(address.value ()));
95
+ bool success = session->remove_breakpoint (reinterpret_cast <void *>(address.value (). address ));
93
96
ASSERT (success);
94
97
}
95
98
}
@@ -109,14 +112,14 @@ int Debugger::start_static()
109
112
110
113
void Debugger::start ()
111
114
{
112
- m_debug_session = Debug::DebugSession::exec_and_attach (m_executable_path);
115
+ m_debug_session = Debug::DebugSession::exec_and_attach (m_executable_path, m_source_root );
113
116
ASSERT (!!m_debug_session);
114
117
115
118
for (const auto & breakpoint : m_breakpoints) {
116
- dbgln (" insertig breakpoint at: {}:{}" , breakpoint.file_path , breakpoint.line_number );
117
- auto address = m_debug_session->debug_info (). get_instruction_from_source (breakpoint.file_path , breakpoint.line_number );
119
+ dbgln (" inserting breakpoint at: {}:{}" , breakpoint.file_path , breakpoint.line_number );
120
+ auto address = m_debug_session->get_address_from_source_position (breakpoint.file_path , breakpoint.line_number );
118
121
if (address.has_value ()) {
119
- bool success = m_debug_session->insert_breakpoint (reinterpret_cast <void *>(address.value ()));
122
+ bool success = m_debug_session->insert_breakpoint (reinterpret_cast <void *>(address.value (). address ));
120
123
ASSERT (success);
121
124
} else {
122
125
dbgln (" couldn't insert breakpoint" );
@@ -130,7 +133,7 @@ int Debugger::debugger_loop()
130
133
{
131
134
ASSERT (m_debug_session);
132
135
133
- m_debug_session->run ([this ](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {
136
+ m_debug_session->run (Debug::DebugSession::DesiredInitialDebugeeState::Running, [this ](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {
134
137
if (reason == Debug::DebugSession::DebugBreakReason::Exited) {
135
138
dbgln (" Program exited" );
136
139
m_on_exit_callback ();
@@ -140,9 +143,16 @@ int Debugger::debugger_loop()
140
143
ASSERT (optional_regs.has_value ());
141
144
const PtraceRegisters& regs = optional_regs.value ();
142
145
143
- auto source_position = m_debug_session->debug_info ().get_source_position (regs.eip );
146
+ auto source_position = m_debug_session->get_source_position (regs.eip );
147
+ if (!source_position.has_value ())
148
+ return Debug::DebugSession::DebugDecision::SingleStep;
149
+
150
+ // We currently do no support stepping through assembly source
151
+ if (source_position.value ().file_path .ends_with (" .S" ))
152
+ return Debug::DebugSession::DebugDecision::SingleStep;
153
+
154
+ ASSERT (source_position.has_value ());
144
155
if (m_state.get () == Debugger::DebuggingState::SingleStepping) {
145
- ASSERT (source_position.has_value ());
146
156
if (m_state.should_stop_single_stepping (source_position.value ())) {
147
157
m_state.set_normal ();
148
158
} else {
@@ -241,11 +251,18 @@ void Debugger::do_step_over(const PtraceRegisters& regs)
241
251
{
242
252
// To step over, we insert a temporary breakpoint at each line in the current function,
243
253
// as well as at the current function's return point, and continue execution.
244
- auto current_function = m_debug_session->debug_info ().get_containing_function (regs.eip );
254
+ auto lib = m_debug_session->library_at (regs.eip );
255
+ if (!lib)
256
+ return ;
257
+ auto current_function = lib->debug_info ->get_containing_function (regs.eip - lib->base_address );
258
+ if (!current_function.has_value ()) {
259
+ dbgln (" cannot perform step_over, failed to find containing function of: {:p}" , regs.eip );
260
+ return ;
261
+ }
245
262
ASSERT (current_function.has_value ());
246
- auto lines_in_current_function = m_debug_session ->debug_info (). source_lines_in_scope (current_function.value ());
263
+ auto lines_in_current_function = lib ->debug_info -> source_lines_in_scope (current_function.value ());
247
264
for (const auto & line : lines_in_current_function) {
248
- insert_temporary_breakpoint (line.address_of_first_statement );
265
+ insert_temporary_breakpoint (line.address_of_first_statement . value () + lib-> base_address );
249
266
}
250
267
insert_temporary_breakpoint_at_return_address (regs);
251
268
}
0 commit comments