diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-11 19:11:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-11 22:59:46 +0100 |
commit | aec54af04ff2b24bd1171c1ac3679378592780ca (patch) | |
tree | aa049efd05dc761457c519e3291206142f3447a9 | |
parent | 03fcd02dfd6d572f6d35991a372961b1789fe478 (diff) | |
download | serenity-aec54af04ff2b24bd1171c1ac3679378592780ca.zip |
LibDebug: Clean up DebugSession construction a little bit
No need to wrap MappedFile in a NonnullOwnPtr. Also make the session
constructor private and use adopt_own().
-rw-r--r-- | Libraries/LibDebug/DebugSession.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibDebug/DebugSession.h | 10 |
2 files changed, 13 insertions, 13 deletions
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<const u8*>(m_executable->data()), m_executable->size())) + , m_executable(map_executable_for_process(pid)) + , m_elf(ELF::Loader::create(reinterpret_cast<const u8*>(m_executable.data()), m_executable.size())) , m_debug_info(m_elf) { } -NonnullOwnPtr<const MappedFile> 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> DebugSession::exec_and_attach(const String& command) { - int pid = fork(); + auto pid = fork(); if (pid < 0) { perror("fork"); @@ -108,7 +108,7 @@ OwnPtr<DebugSession> DebugSession::exec_and_attach(const String& command) return nullptr; } - return make<DebugSession>(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<DebugSession> 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<const ELF::Loader> 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<const MappedFile> 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<const MappedFile> m_executable; + MappedFile m_executable; NonnullRefPtr<const ELF::Loader> m_elf; DebugInfo m_debug_info; |