summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 11:28:18 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 11:28:18 +0100
commit02c763fe5466b1876a7f71ab81690c5644d60bf1 (patch)
treeb3711366e38a7d972a8ab5ed7cb9a8ab92029016 /dev/LibDebugger/src
parentf4a3ae900294759eb79307137a1efa9e2fbe2a10 (diff)
feat(debugger): Add specs for dbg/LibDebugger, overall code
improvements. vendor(debugger): Add pfd for LibDebugger, to retrieve file to parse or notify events. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/LibDebugger/src')
-rw-r--r--dev/LibDebugger/src/POSIX.cc67
1 files changed, 57 insertions, 10 deletions
diff --git a/dev/LibDebugger/src/POSIX.cc b/dev/LibDebugger/src/POSIX.cc
index 21e122c..89ee572 100644
--- a/dev/LibDebugger/src/POSIX.cc
+++ b/dev/LibDebugger/src/POSIX.cc
@@ -3,10 +3,35 @@
*/
#include <LibCompiler/Defines.h>
+#include <LibDebugger/vendor/Dialogs.h>
#include <LibDebugger/POSIX.h>
+#include <cstdint>
+#include <string>
#ifndef _WIN32
+static bool kKeepRunning = false;
+LibDebugger::POSIX::Debugger kDebugger;
+
+static void DebuggerCtrlCHandler(std::int32_t _)
+{
+ auto list = kDebugger.Get();
+
+ LibDebugger::POSIX::CAddr addr = (LibDebugger::POSIX::CAddr)list[list.size() - 1];
+
+ if (!addr)
+ {
+ pfd::notify("Debugger Event", "Invalid breakpoint at: " + std::to_string(list[list.size() - 1]));
+ return;
+ }
+
+ kDebugger.Break(addr);
+
+ pfd::notify("Debugger Event", "Breakpoint at: " + std::to_string(list[list.size() - 1]));
+
+ kKeepRunning = false;
+}
+
LIBCOMPILER_MODULE(DebuggerPOSIX)
{
if (argc < 1)
@@ -14,28 +39,37 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
return EXIT_FAILURE;
}
- LibDebugger::POSIX::Debugger debugger;
- pid_t pid = 0L;
+ pid_t pid = 0L;
if (argc >= 3 && std::string(argv[1]) == "-p" &&
argv[2] != nullptr)
{
pid = std::stoi(argv[2]);
- debugger.Attach(pid);
+ kDebugger.Attach(pid);
}
+ ::signal(SIGINT, DebuggerCtrlCHandler);
+
while (YES)
{
+ if (kKeepRunning)
+ {
+ continue;
+ }
+
std::string cmd;
std::getline(std::cin, cmd);
if (cmd == "c" ||
cmd == "cont")
- debugger.Continue();
+ {
+ kDebugger.Continue();
+ kKeepRunning = true;
+ }
if (cmd == "d" ||
cmd == "detach")
- debugger.Detach();
+ kDebugger.Detach();
if (cmd == "attach")
{
@@ -44,13 +78,15 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
std::getline(std::cin, cmd);
pid = std::stoi(cmd.c_str());
- debugger.Attach(pid);
+ pfd::notify("Debugger Event", "Attach process: " + std::to_string(pid));
+
+ kDebugger.Attach(pid);
}
if (cmd == "exit")
{
if (pid > 0)
- debugger.Detach();
+ kDebugger.Detach();
break;
}
@@ -58,14 +94,25 @@ LIBCOMPILER_MODULE(DebuggerPOSIX)
if (cmd == "break" ||
cmd == "b")
{
- std::cout << "[?] Enter an address to add a breakpoint on: ";
+ std::cout << "[?] Enter an address/symbol to add a break on: ";
std::getline(std::cin, cmd);
- LibDebugger::POSIX::CAddr breakpoint_addr = reinterpret_cast<LibDebugger::POSIX::CAddr>(std::stoul(cmd.c_str(), nullptr, 16));
+ auto addr = std::stoul(cmd.c_str(), nullptr, 16);
+
+ try
+ {
+ pfd::notify("Debugger Event", "Add Breakpoint at: " + std::to_string(addr));
+ }
+ catch (...)
+ {
+ pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd);
+ }
+
+ LibDebugger::POSIX::CAddr breakpoint_addr = reinterpret_cast<LibDebugger::POSIX::CAddr>(addr);
if (breakpoint_addr)
- debugger.Break(breakpoint_addr);
+ kDebugger.Break(breakpoint_addr);
}
}