Kaynağa Gözat

LibDebug: Prefer File::read_until_eof over DeprecatedFile

Ben Wiederhake 2 yıl önce
ebeveyn
işleme
9474e0cd94

+ 17 - 9
Userland/Libraries/LibDebug/DebugSession.cpp

@@ -10,7 +10,6 @@
 #include <AK/LexicalPath.h>
 #include <AK/Optional.h>
 #include <AK/Platform.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibFileSystem/FileSystem.h>
 #include <LibRegex/Regex.h>
 #include <stdlib.h>
@@ -126,7 +125,11 @@ OwnPtr<DebugSession> 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> 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::InsertBreakpointAtSourcePositionResult> 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<void> 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<PosixExtended> segment_name_re("(.+): ");
@@ -509,6 +515,8 @@ void DebugSession::update_loaded_libs()
 
         return IterationDecision::Continue;
     });
+
+    return {};
 }
 
 void DebugSession::stop_debuggee()

+ 1 - 1
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<void> update_loaded_libs();
 
     int m_debuggee_pid { -1 };
     DeprecatedString m_source_root;