From 7d9fb7e4244d996f744233be046d9aa90afa8964 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 2 Mar 2026 14:53:33 +0100 Subject: chore: GL improvements of pstd, and DebuggerKit tweaks. Signed-off-by: Amlal El Mahrouss --- src/DebuggerKit/src/MachContract.cpp | 99 ++++++++++++++++++++++++++++ src/DebuggerKit/src/MachContractCLI.cpp | 4 +- src/DebuggerKit/src/POSIXMachContractCLI.cpp | 95 -------------------------- 3 files changed, 101 insertions(+), 97 deletions(-) create mode 100644 src/DebuggerKit/src/MachContract.cpp delete mode 100644 src/DebuggerKit/src/POSIXMachContractCLI.cpp (limited to 'src/DebuggerKit') diff --git a/src/DebuggerKit/src/MachContract.cpp b/src/DebuggerKit/src/MachContract.cpp new file mode 100644 index 0000000..53553ac --- /dev/null +++ b/src/DebuggerKit/src/MachContract.cpp @@ -0,0 +1,99 @@ +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (See accompanying +// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/nekernel-org/nectar + +#ifdef DK_MACH_DEBUGGER + +#include +#include + +#ifdef DK_MACH_DEBUGGER +#include + +/// @internal +/// @brief Handles CTRL-C signal on debugger. +static Void dbgi_ctrlc_handler(std::int32_t _) { + if (!kPID) { + return; + } + + kUserDebugger.Break(); + + pfd::notify("Debugger Event", "Breakpoint hit!"); + + kKeepRunning = false; +} + +NECTAR_MODULE(DebuggerMachPOSIX) { + pfd::notify( + "Debugger Event", + "Userland Debugger\n(C) 2025 Amlal El Mahrouss, licensed under the Apache 2.0 license."); + + constexpr auto kMaxArgs = 3; + + if (argc >= kMaxArgs + && std::string(argv[1]) == "-p" + && argv[2] != nullptr) { + kPath = argv[2]; + kUserDebugger.SetPath(kPath); + + kStdOut << "[+] Set image to: " << kPath << "\n"; + } else { + kStdOut << "usage: " << argv[0] << " -p \n"; + kStdOut << "example: " << argv[0] << " -p \n"; + + return EXIT_FAILURE; + } + + CompilerKit::install_signal(SIGINT, dbgi_ctrlc_handler); + + while (YES) { + if (kKeepRunning) { + continue; + } + + std::string cmd; + if (!std::getline(std::cin, cmd)) break; + + if (cmd == "c" || cmd == "cont" || cmd == "continue") { + if (kUserDebugger.Continue()) { + kKeepRunning = true; + + kStdOut << "[+] Continuing...\n"; + + pfd::notify("Debugger Event", "Continuing..."); + } + } + + if (cmd == "d" || cmd == "detach") kUserDebugger.Detach(); + + if (cmd == "start") { + kStdOut << "[?] Enter a argument to use: "; + std::getline(std::cin, cmd); + + kUserDebugger.Attach(kPath, cmd, kPID); + } + + if (cmd == "exit") { + if (kPID > 0) kUserDebugger.Detach(); + + break; + } + + if (cmd == "break" || cmd == "b") { + kStdOut << "[?] Enter a symbol to break on: "; + + std::getline(std::cin, cmd); + + if (kUserDebugger.BreakAt(cmd)) { + pfd::notify("Debugger Event", "Add BreakAt at: " + cmd); + } + } + } + + return EXIT_SUCCESS; +} +#endif + +#endif diff --git a/src/DebuggerKit/src/MachContractCLI.cpp b/src/DebuggerKit/src/MachContractCLI.cpp index 4d0c4e8..63c5470 100644 --- a/src/DebuggerKit/src/MachContractCLI.cpp +++ b/src/DebuggerKit/src/MachContractCLI.cpp @@ -49,7 +49,8 @@ NECTAR_MODULE(DebuggerMachPOSIX) { continue; } - std::string cmd; + CompilerKit::STLString cmd{}; + if (!std::getline(std::cin, cmd)) break; if (cmd == "c" || cmd == "cont" || cmd == "continue") { @@ -57,7 +58,6 @@ NECTAR_MODULE(DebuggerMachPOSIX) { kKeepRunning = true; kStdOut << "[+] Continuing...\n"; - pfd::notify("Debugger Event", "Continuing..."); } } diff --git a/src/DebuggerKit/src/POSIXMachContractCLI.cpp b/src/DebuggerKit/src/POSIXMachContractCLI.cpp deleted file mode 100644 index da90a1f..0000000 --- a/src/DebuggerKit/src/POSIXMachContractCLI.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (See accompanying -// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) -// Official repository: https://github.com/nekernel-org/nectar - -#ifdef DK_MACH_DEBUGGER - -#include -#include - -#ifdef DK_MACH_DEBUGGER -#include - -/// @internal -/// @brief Handles CTRL-C signal on debugger. -static Void dbgi_ctrlc_handler(std::int32_t _) { - if (!kPID) { - return; - } - - kUserDebugger.Break(); - - pfd::notify("Debugger Event", "Breakpoint hit!"); - - kKeepRunning = false; -} - -NECTAR_MODULE(DebuggerMachPOSIX) { - pfd::notify( - "Debugger Event", - "Userland Debugger\n(C) 2025 Amlal El Mahrouss, licensed under the Apache 2.0 license."); - - if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { - kPath = argv[2]; - kUserDebugger.SetPath(kPath); - - kStdOut << "[+] Image set to: " << kPath << "\n"; - } else { - kStdOut << "usage: " << argv[0] << " -p \n"; - kStdOut << "example: " << argv[0] << " -p \n"; - - return EXIT_FAILURE; - } - - CompilerKit::install_signal(SIGINT, dbgi_ctrlc_handler); - - while (YES) { - if (kKeepRunning) { - continue; - } - - std::string cmd; - if (!std::getline(std::cin, cmd)) break; - - if (cmd == "c" || cmd == "cont" || cmd == "continue") { - if (kUserDebugger.Continue()) { - kKeepRunning = true; - - kStdOut << "[+] Continuing...\n"; - - pfd::notify("Debugger Event", "Continuing..."); - } - } - - if (cmd == "d" || cmd == "detach") kUserDebugger.Detach(); - - if (cmd == "start") { - kStdOut << "[?] Enter a argument to use: "; - std::getline(std::cin, cmd); - - kUserDebugger.Attach(kPath, cmd, kPID); - } - - if (cmd == "exit") { - if (kPID > 0) kUserDebugger.Detach(); - - break; - } - - if (cmd == "break" || cmd == "b") { - kStdOut << "[?] Enter a symbol to break on: "; - - std::getline(std::cin, cmd); - - if (kUserDebugger.BreakAt(cmd)) { - pfd::notify("Debugger Event", "Add BreakAt at: " + cmd); - } - } - } - - return EXIT_SUCCESS; -} -#endif - -#endif -- cgit v1.2.3