diff --git a/Libraries/LibDebug/DebugSession.cpp b/Libraries/LibDebug/DebugSession.cpp index 194ea09a9c..42f1ced66e 100644 --- a/Libraries/LibDebug/DebugSession.cpp +++ b/Libraries/LibDebug/DebugSession.cpp @@ -30,18 +30,18 @@ namespace Debug { -DebugSession::DebugSession(int pid) +DebugSession::DebugSession(pid_t pid) : m_debuggee_pid(pid) - , m_executable(initialize_executable_mapped_file(pid)) - , m_elf(ELF::Loader::create(reinterpret_cast(m_executable->data()), m_executable->size())) + , m_executable(map_executable_for_process(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) +MappedFile DebugSession::map_executable_for_process(pid_t pid) { - auto executable = adopt_own(*new MappedFile(String::format("/proc/%d/exe", pid))); - ASSERT(executable->is_valid()); + MappedFile executable(String::formatted("/proc/{}/exe", pid)); + ASSERT(executable.is_valid()); return executable; } @@ -62,7 +62,7 @@ DebugSession::~DebugSession() OwnPtr DebugSession::exec_and_attach(const String& command) { - int pid = fork(); + auto pid = fork(); if (pid < 0) { perror("fork"); @@ -108,7 +108,7 @@ OwnPtr DebugSession::exec_and_attach(const String& command) return nullptr; } - return make(pid); + return adopt_own(*new DebugSession(pid)); } bool DebugSession::poke(u32* address, u32 data) diff --git a/Libraries/LibDebug/DebugSession.h b/Libraries/LibDebug/DebugSession.h index fc79c9b329..6912eb59dc 100644 --- a/Libraries/LibDebug/DebugSession.h +++ b/Libraries/LibDebug/DebugSession.h @@ -48,8 +48,6 @@ class DebugSession { public: static OwnPtr exec_and_attach(const String& command); - // Has to be public for OwnPtr::make - DebugSession(int pid); ~DebugSession(); int pid() const { return m_debuggee_pid; } @@ -103,7 +101,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 { @@ -121,15 +119,17 @@ public: }; private: + explicit DebugSession(pid_t); + // x86 breakpoint instruction "int3" static constexpr u8 BREAKPOINT_INSTRUCTION = 0xcc; - static NonnullOwnPtr initialize_executable_mapped_file(int pid); + static MappedFile map_executable_for_process(pid_t); int m_debuggee_pid { -1 }; bool m_is_debuggee_dead { false }; - NonnullOwnPtr m_executable; + MappedFile m_executable; NonnullRefPtr m_elf; DebugInfo m_debug_info;