summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 11:10:06 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 11:10:46 +0100
commitf4a3ae900294759eb79307137a1efa9e2fbe2a10 (patch)
tree8bba5e42b01ab6f79d2ae849dfc66716d96c602a /dev/LibDebugger
parent5bc9c1f376051d9fff7b837b4707437e9f756015 (diff)
debugger(posix): Refactor LibDebugger POSIX engine: rename, namespace update, API cleanup
- Renamed `IDebuggerEngine.h` → `POSIX.h` and `DebuggerEnginePOSIX.cc` → `POSIX.cc` - Moved `IDebuggerEngine` class into `LibDebugger::POSIX` namespace and renamed it to `Debugger` - Simplified method names: - `SetBreakpoint` → `Break` - `ContinueExecution` → `Continue` - Replaced generic return codes with `EXIT_SUCCESS` / `EXIT_FAILURE` - Updated includes and symbol usage to reflect changes across the codebase Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/LibDebugger')
-rw-r--r--dev/LibDebugger/POSIX.h (renamed from dev/LibDebugger/IDebuggerEngine.h)20
-rw-r--r--dev/LibDebugger/src/POSIX.cc (renamed from dev/LibDebugger/src/DebuggerEnginePOSIX.cc)17
2 files changed, 22 insertions, 15 deletions
diff --git a/dev/LibDebugger/IDebuggerEngine.h b/dev/LibDebugger/POSIX.h
index 45b7da3..d859868 100644
--- a/dev/LibDebugger/IDebuggerEngine.h
+++ b/dev/LibDebugger/POSIX.h
@@ -2,6 +2,8 @@
(C) 2025 Amlal El Mahrouss
*/
+#pragma once
+
#include <iostream>
#include <unordered_map>
@@ -20,7 +22,7 @@
#define PTRACE_PEEKTEXT PT_READ_I
#endif
-namespace LibDebugger
+namespace LibDebugger::POSIX
{
#ifdef __APPLE__
typedef caddr_t CAddr;
@@ -30,15 +32,15 @@ namespace LibDebugger
/// \brief Debugger engine interface class in C++
/// \author Amlal El Mahrouss
- class IDebuggerEngine final
+ class Debugger final
{
public:
- explicit IDebuggerEngine() = default;
- ~IDebuggerEngine() = default;
+ explicit Debugger() = default;
+ ~Debugger() = default;
public:
- IDebuggerEngine& operator=(const IDebuggerEngine&) = default;
- IDebuggerEngine(const IDebuggerEngine&) = default;
+ Debugger& operator=(const Debugger&) = default;
+ Debugger(const Debugger&) = default;
public:
void Attach(pid_t pid)
@@ -56,7 +58,7 @@ namespace LibDebugger
std::cout << "[+] Attached to process: " << m_pid << std::endl;
}
- void SetBreakpoint(CAddr addr)
+ void Break(CAddr addr)
{
uintptr_t original_data = ptrace(PTRACE_PEEKTEXT, m_pid, addr, 0);
@@ -79,7 +81,7 @@ namespace LibDebugger
m_breakpoints[reinterpret_cast<uintptr_t>(addr)] = original_data; // Store original data
}
- void ContinueExecution()
+ void Continue()
{
if (ptrace(PTRACE_CONT, m_pid, nullptr, 0) == -1)
{
@@ -116,4 +118,4 @@ namespace LibDebugger
pid_t m_pid;
std::unordered_map<uintptr_t, uintptr_t> m_breakpoints;
};
-} // namespace LibDebugger
+} // namespace LibDebugger::POSIX
diff --git a/dev/LibDebugger/src/DebuggerEnginePOSIX.cc b/dev/LibDebugger/src/POSIX.cc
index b8695fb..21e122c 100644
--- a/dev/LibDebugger/src/DebuggerEnginePOSIX.cc
+++ b/dev/LibDebugger/src/POSIX.cc
@@ -3,13 +3,18 @@
*/
#include <LibCompiler/Defines.h>
-#include <LibDebugger/IDebuggerEngine.h>
+#include <LibDebugger/POSIX.h>
#ifndef _WIN32
LIBCOMPILER_MODULE(DebuggerPOSIX)
{
- LibDebugger::IDebuggerEngine debugger;
+ if (argc < 1)
+ {
+ return EXIT_FAILURE;
+ }
+
+ LibDebugger::POSIX::Debugger debugger;
pid_t pid = 0L;
if (argc >= 3 && std::string(argv[1]) == "-p" &&
@@ -26,7 +31,7 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
if (cmd == "c" ||
cmd == "cont")
- debugger.ContinueExecution();
+ debugger.Continue();
if (cmd == "d" ||
cmd == "detach")
@@ -57,14 +62,14 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
std::getline(std::cin, cmd);
- LibDebugger::CAddr breakpoint_addr = reinterpret_cast<LibDebugger::CAddr>(std::stoul(cmd.c_str(), nullptr, 16));
+ LibDebugger::POSIX::CAddr breakpoint_addr = reinterpret_cast<LibDebugger::POSIX::CAddr>(std::stoul(cmd.c_str(), nullptr, 16));
if (breakpoint_addr)
- debugger.SetBreakpoint(breakpoint_addr);
+ debugger.Break(breakpoint_addr);
}
}
- return 0;
+ return EXIT_SUCCESS;
}
#endif \ No newline at end of file