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().
This commit is contained in:
Andreas Kling 2020-12-11 19:11:25 +01:00
parent 03fcd02dfd
commit aec54af04f
Notes: sideshowbarker 2024-07-19 00:55:20 +09:00
2 changed files with 13 additions and 13 deletions

View file

@ -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)

View file

@ -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;