summaryrefslogtreecommitdiff
path: root/DevTools/HackStudio
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2020-05-05 14:14:29 +0300
committerAndreas Kling <kling@serenityos.org>2020-05-07 23:32:11 +0200
commitb931771d24499a4973f1c27032d1300fb8d145a2 (patch)
tree45f7ab3e77d96448ceace8ea42af472b1c62a34c /DevTools/HackStudio
parent5fd64045b11ae2f8461451c6de0c77c8916645b9 (diff)
downloadserenity-b931771d24499a4973f1c27032d1300fb8d145a2.zip
HackStudio: Gracefully handle unfound source files
Diffstat (limited to 'DevTools/HackStudio')
-rw-r--r--DevTools/HackStudio/Debugger.cpp18
-rw-r--r--DevTools/HackStudio/Debugger.h12
-rw-r--r--DevTools/HackStudio/main.cpp6
3 files changed, 25 insertions, 11 deletions
diff --git a/DevTools/HackStudio/Debugger.cpp b/DevTools/HackStudio/Debugger.cpp
index e2b5f95f8b..cb325e2b27 100644
--- a/DevTools/HackStudio/Debugger.cpp
+++ b/DevTools/HackStudio/Debugger.cpp
@@ -35,7 +35,7 @@ Debugger& Debugger::the()
}
void Debugger::initialize(
- Function<void(const PtraceRegisters&)> on_stop_callback,
+ Function<HasControlPassedToUser(const PtraceRegisters&)> on_stop_callback,
Function<void()> on_continue_callback,
Function<void()> on_exit_callback)
{
@@ -48,7 +48,7 @@ bool Debugger::is_initialized()
}
Debugger::Debugger(
- Function<void(const PtraceRegisters&)> on_stop_callback,
+ Function<HasControlPassedToUser(const PtraceRegisters&)> on_stop_callback,
Function<void()> on_continue_callback,
Function<void()> on_exit_callback)
: m_on_stopped_callback(move(on_stop_callback))
@@ -138,13 +138,17 @@ int Debugger::debugger_loop()
in_single_step_mode = false;
}
- m_on_stopped_callback(regs);
+ auto control_passed_to_user = m_on_stopped_callback(regs);
- pthread_mutex_lock(&m_continue_mutex);
- pthread_cond_wait(&m_continue_cond, &m_continue_mutex);
- pthread_mutex_unlock(&m_continue_mutex);
+ if (control_passed_to_user == HasControlPassedToUser::Yes) {
+ pthread_mutex_lock(&m_continue_mutex);
+ pthread_cond_wait(&m_continue_cond, &m_continue_mutex);
+ pthread_mutex_unlock(&m_continue_mutex);
- m_on_continue_callback();
+ m_on_continue_callback();
+ } else {
+ m_continue_type = ContinueType::Continue;
+ }
if (m_continue_type == ContinueType::Continue) {
return DebugSession::DebugDecision::Continue;
diff --git a/DevTools/HackStudio/Debugger.h b/DevTools/HackStudio/Debugger.h
index 0df030bb99..90a3318d72 100644
--- a/DevTools/HackStudio/Debugger.h
+++ b/DevTools/HackStudio/Debugger.h
@@ -37,8 +37,14 @@
class Debugger {
public:
static Debugger& the();
+
+ enum class HasControlPassedToUser {
+ No,
+ Yes,
+ };
+
static void initialize(
- Function<void(const PtraceRegisters&)> on_stop_callback,
+ Function<HasControlPassedToUser(const PtraceRegisters&)> on_stop_callback,
Function<void()> on_continue_callback,
Function<void()> on_exit_callback);
@@ -66,7 +72,7 @@ public:
private:
explicit Debugger(
- Function<void(const PtraceRegisters&)> on_stop_callback,
+ Function<HasControlPassedToUser(const PtraceRegisters&)> on_stop_callback,
Function<void()> on_continue_callback,
Function<void()> on_exit_callback);
@@ -83,7 +89,7 @@ private:
Vector<DebugInfo::SourcePosition> m_breakpoints;
String m_executable_path;
- Function<void(const PtraceRegisters&)> m_on_stopped_callback;
+ Function<HasControlPassedToUser(const PtraceRegisters&)> m_on_stopped_callback;
Function<void()> m_on_continue_callback;
Function<void()> m_on_exit_callback;
diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp
index ae3941922f..b9dbc7ad85 100644
--- a/DevTools/HackStudio/main.cpp
+++ b/DevTools/HackStudio/main.cpp
@@ -609,13 +609,17 @@ int main(int argc, char** argv)
dbg() << "Program stopped";
auto source_position = Debugger::the().session()->debug_info().get_source_position(regs.eip);
- ASSERT(source_position.has_value());
+ if (!source_position.has_value()) {
+ dbg() << "Could not find source position for address: " << (void*)regs.eip;
+ return Debugger::HasControlPassedToUser::No;
+ }
current_editor_in_execution = get_editor_of_file(source_position.value().file_path);
current_editor_in_execution->editor().set_execution_position(source_position.value().line_number - 1);
debug_info_widget.update_variables(regs);
continue_action->set_enabled(true);
single_step_action->set_enabled(true);
reveal_action_tab(debug_info_widget);
+ return Debugger::HasControlPassedToUser::Yes;
},
[&]() {
dbg() << "Program continued";