diff --git a/Userland/Libraries/LibDebug/DebugSession.cpp b/Userland/Libraries/LibDebug/DebugSession.cpp index cddfe4aed5..0a04620c5e 100644 --- a/Userland/Libraries/LibDebug/DebugSession.cpp +++ b/Userland/Libraries/LibDebug/DebugSession.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -126,7 +125,11 @@ OwnPtr DebugSession::exec_and_attach(DeprecatedString const& comma } // At this point, libraries should have been loaded - debug_session->update_loaded_libs(); + auto update_or_error = debug_session->update_loaded_libs(); + if (update_or_error.is_error()) { + dbgln("update failed: {}", update_or_error.error()); + return {}; + } return debug_session; } @@ -146,7 +149,11 @@ OwnPtr DebugSession::attach(pid_t pid, DeprecatedString source_roo auto debug_session = adopt_own(*new DebugSession(pid, source_root, move(on_initialization_progress))); // At this point, libraries should have been loaded - debug_session->update_loaded_libs(); + auto update_or_error = debug_session->update_loaded_libs(); + if (update_or_error.is_error()) { + dbgln("update failed: {}", update_or_error.error()); + return {}; + } return debug_session; } @@ -444,14 +451,13 @@ Optional DebugSession::ins return InsertBreakpointAtSourcePositionResult { lib->name, address_and_source_position.value().file, address_and_source_position.value().line, address }; } -void DebugSession::update_loaded_libs() +ErrorOr DebugSession::update_loaded_libs() { - auto file = Core::DeprecatedFile::construct(DeprecatedString::formatted("/proc/{}/vm", m_debuggee_pid)); - bool rc = file->open(Core::OpenMode::ReadOnly); - VERIFY(rc); + auto file_name = TRY(String::formatted("/proc/{}/vm", m_debuggee_pid)); + auto file = TRY(Core::File::open(file_name, Core::File::OpenMode::Read)); - auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + auto file_contents = TRY(file->read_until_eof()); + auto json = TRY(JsonValue::from_string(file_contents)); auto const& vm_entries = json.as_array(); Regex segment_name_re("(.+): "); @@ -509,6 +515,8 @@ void DebugSession::update_loaded_libs() return IterationDecision::Continue; }); + + return {}; } void DebugSession::stop_debuggee() diff --git a/Userland/Libraries/LibDebug/DebugSession.h b/Userland/Libraries/LibDebug/DebugSession.h index 70b7ce43d3..c4f18ff1f2 100644 --- a/Userland/Libraries/LibDebug/DebugSession.h +++ b/Userland/Libraries/LibDebug/DebugSession.h @@ -137,7 +137,7 @@ private: // x86 breakpoint instruction "int3" static constexpr u8 BREAKPOINT_INSTRUCTION = 0xcc; - void update_loaded_libs(); + ErrorOr update_loaded_libs(); int m_debuggee_pid { -1 }; DeprecatedString m_source_root;