diff --git a/Libraries/LibDebug/DebugSession.cpp b/Libraries/LibDebug/DebugSession.cpp index c4dbc414d6b..25d9cf1ff27 100644 --- a/Libraries/LibDebug/DebugSession.cpp +++ b/Libraries/LibDebug/DebugSession.cpp @@ -30,12 +30,19 @@ DebugSession::DebugSession(int pid) : m_debugee_pid(pid) - , m_executable(String::format("/proc/%d/exe", pid)) - , m_elf(ELF::Loader::create(reinterpret_cast(m_executable.data()), m_executable.size())) + , m_executable(initialize_executable_mapped_file(pid)) + , m_elf(ELF::Loader::create(reinterpret_cast(m_executable->data()), m_executable->size())) , m_debug_info(m_elf) { } +NonnullOwnPtr DebugSession::initialize_executable_mapped_file(int pid) +{ + auto executable = adopt_own(*new MappedFile(String::format("/proc/%d/exe", pid))); + ASSERT(executable->is_valid()); + return executable; +} + DebugSession::~DebugSession() { for (const auto& bp : m_breakpoints) { diff --git a/Libraries/LibDebug/DebugSession.h b/Libraries/LibDebug/DebugSession.h index 5522298383c..84a87922c26 100644 --- a/Libraries/LibDebug/DebugSession.h +++ b/Libraries/LibDebug/DebugSession.h @@ -98,7 +98,7 @@ public: const ELF::Loader& elf() const { return *m_elf; } NonnullRefPtr elf_ref() const { return m_elf; } - const MappedFile& executable() const { return m_executable; } + const MappedFile& executable() const { return *m_executable; } const DebugInfo& debug_info() const { return m_debug_info; } enum DebugDecision { @@ -119,10 +119,12 @@ private: // x86 breakpoint instruction "int3" static constexpr u8 BREAKPOINT_INSTRUCTION = 0xcc; + static NonnullOwnPtr initialize_executable_mapped_file(int pid); + int m_debugee_pid { -1 }; bool m_is_debugee_dead { false }; - MappedFile m_executable; + NonnullOwnPtr m_executable; NonnullRefPtr m_elf; DebugInfo m_debug_info;