From bc03b2dbee8a7458a3ed89abd643bf004f0f403b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 26 Mar 2025 09:29:01 +0100 Subject: feat(debugger): Better design for LibDebugger, and a patch for the POSIX CLI. Signed-off-by: Amlal El Mahrouss --- dev/LibDebugger/src/POSIX.cc | 126 ------------------------------------------- 1 file changed, 126 deletions(-) delete mode 100644 dev/LibDebugger/src/POSIX.cc (limited to 'dev/LibDebugger/src/POSIX.cc') diff --git a/dev/LibDebugger/src/POSIX.cc b/dev/LibDebugger/src/POSIX.cc deleted file mode 100644 index b8c92ae..0000000 --- a/dev/LibDebugger/src/POSIX.cc +++ /dev/null @@ -1,126 +0,0 @@ -/*** - (C) 2025 Amlal El Mahrouss - */ - -#include -#include -#include -#include -#include - -#ifndef _WIN32 - -static bool kKeepRunning = false; -static LibDebugger::POSIX::LocalDebuggerPOSIX kDebugger; -static pid_t kPID = 0L; - -static void DebuggerCtrlCHandler(std::int32_t _) -{ - if (!kPID) - { - return; - } - - 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) - { - return EXIT_FAILURE; - } - - if (argc >= 3 && std::string(argv[1]) == "-p" && - argv[2] != nullptr) - { - kPID = std::stoi(argv[2]); - kDebugger.Attach(kPID); - } - - ::signal(SIGINT, DebuggerCtrlCHandler); - - while (YES) - { - if (kKeepRunning) - { - continue; - } - - std::string cmd; - std::getline(std::cin, cmd); - - if (cmd == "c" || - cmd == "cont") - { - kDebugger.Continue(); - kKeepRunning = true; - } - - if (cmd == "d" || - cmd == "detach") - kDebugger.Detach(); - - if (cmd == "attach") - { - std::cout << "[?] Enter a PID to attach on: "; - - std::getline(std::cin, cmd); - kPID = std::stoi(cmd.c_str()); - - pfd::notify("Debugger Event", "Attach process: " + std::to_string(kPID)); - - kDebugger.Attach(kPID); - } - - if (cmd == "exit") - { - if (kPID > 0) - kDebugger.Detach(); - - break; - } - - if (cmd == "break" || - cmd == "b") - { - std::cout << "[?] Enter an address/symbol to add a break on: "; - - std::getline(std::cin, cmd); - - 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(addr); - - if (breakpoint_addr) - kDebugger.Break(breakpoint_addr); - } - } - - return EXIT_SUCCESS; -} - -#endif \ No newline at end of file -- cgit v1.2.3