diff options
Diffstat (limited to 'dev/LibDebugger/src')
| -rw-r--r-- | dev/LibDebugger/src/POSIXMachContract.cc | 189 |
1 files changed, 81 insertions, 108 deletions
diff --git a/dev/LibDebugger/src/POSIXMachContract.cc b/dev/LibDebugger/src/POSIXMachContract.cc index 4e7212c..2753e9a 100644 --- a/dev/LibDebugger/src/POSIXMachContract.cc +++ b/dev/LibDebugger/src/POSIXMachContract.cc @@ -1,129 +1,102 @@ /*** - (C) 2025 Amlal El Mahrouss + (C) 2025 Amlal El Mahrouss */ +#ifdef __APPLE__ + #include <LibCompiler/Defines.h> -#include <Vendor/Dialogs.h> #include <LibDebugger/POSIXMachContract.h> +#include <Vendor/Dialogs.h> #include <cstdint> +#include <iostream> #include <string> -#ifndef _WIN32 - -static bool kKeepRunning = false; +static BOOL kKeepRunning = false; static LibDebugger::POSIX::POSIXMachContract kDebugger; -static pid_t kPID = 0L; -static LibDebugger::CAddress kActiveAddress = nullptr; +static LibDebugger::ProcessID kPID = 0L; +static LibDebugger::CAddress kActiveAddress = nullptr; +static std::string kPath = ""; + +#define kBlank "\e[0;30m" +#define kRed "\e[0;31m" +#define kWhite "\e[0;97m" + +#define kStdOut (std::cout << kRed << "dbg: " << kWhite) /// @internal /// @brief Handles CTRL-C signal on debugger. -static void dbgi_ctrlc_handler(std::int32_t _) -{ - if (!kPID) - { - return; - } +static void dbgi_ctrlc_handler(std::int32_t _) { + if (!kPID) { + return; + } - auto list = kDebugger.Get(); + auto list = kDebugger.Get(); - kDebugger.Break(kActiveAddress); + kDebugger.Break(); - pfd::notify("Debugger Event", "Breakpoint hit!"); + pfd::notify("Debugger Event", "Breakpoint hit!"); - kKeepRunning = false; + kKeepRunning = false; } -LIBCOMPILER_MODULE(DebuggerPOSIX) -{ - pfd::notify("Debugger Event", "NeKernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); - - if (argc >= 3 && std::string(argv[1]) == "-p" && - argv[2] != nullptr) - { - kPID = std::stoi(argv[2]); - kDebugger.Attach(kPID); - } - - ::signal(SIGINT, dbgi_ctrlc_handler); - - while (YES) - { - if (kKeepRunning) - { - continue; - } - - std::string cmd; - std::getline(std::cin, cmd); - - if (cmd == "c" || - cmd == "cont" || - cmd == "continue") - { - kDebugger.Continue(); - kKeepRunning = true; - - std::cout << "[+] Continuing...\n"; - pfd::notify("Debugger Event", "Continuing..."); - } - - if (cmd == "d" || - cmd == "detach") - kDebugger.Detach(); - - if (cmd == "attach" || - cmd == "pid" || - cmd == "a") - { - 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; - } - -#ifndef __APPLE__ - 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::CAddress breakpoint_addr = reinterpret_cast<LibDebugger::CAddress>(addr); - - if (breakpoint_addr) - { - kActiveAddress = breakpoint_addr; - kDebugger.Break(kActiveAddress); - } - } -#endif // ifndef __APPLE__ - } - - return EXIT_SUCCESS; +LIBCOMPILER_MODULE(DebuggerMachPOSIX) { + pfd::notify("Debugger Event", + "Userland Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); + + if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { + kPath = argv[2]; + kDebugger.SetPath(kPath); + + kStdOut << "[+] Path set to: " << kPath << "\n"; + } + + ::signal(SIGINT, dbgi_ctrlc_handler); + + while (YES) { + if (kKeepRunning) { + continue; + } + + std::string cmd; + std::getline(std::cin, cmd); + + if (cmd == "c" || cmd == "cont" || cmd == "continue") { + if (kDebugger.Continue()) { + kKeepRunning = true; + + kStdOut << "[+] Continuing...\n"; + + pfd::notify("Debugger Event", "Continuing..."); + } + } + + if (cmd == "d" || cmd == "detach") kDebugger.Detach(); + + if (cmd == "start") { + kStdOut << "[?] Enter a argument to use: "; + std::getline(std::cin, cmd); + + kDebugger.Attach(kPath, cmd, kPID); + } + + if (cmd == "exit") { + if (kPID > 0) kDebugger.Detach(); + + break; + } + + if (cmd == "break" || cmd == "b") { + kStdOut << "[?] Enter a symbol to break on: "; + + std::getline(std::cin, cmd); + + if (kDebugger.Breakpoint(cmd)) { + pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd); + } + } + } + + return EXIT_SUCCESS; } #endif
\ No newline at end of file |
