summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger/src/POSIXMachContractCLI.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-29 10:48:12 +0200
committerGitHub <noreply@github.com>2025-05-29 10:48:12 +0200
commit433bb5ef102b2bfa0049468be00d63011da8b973 (patch)
treee0893a30710477045a5bb085cb7a27aada425c14 /dev/LibDebugger/src/POSIXMachContractCLI.cc
parent1ddeab9a4426abd781a5066ba79af2ba64de11d9 (diff)
parent756ee7f8dc954e27350fe5bdfbaa83b9f69780c8 (diff)
Merge pull request #6 from nekernel-org/dev
0.0.2e3
Diffstat (limited to 'dev/LibDebugger/src/POSIXMachContractCLI.cc')
-rw-r--r--dev/LibDebugger/src/POSIXMachContractCLI.cc95
1 files changed, 95 insertions, 0 deletions
diff --git a/dev/LibDebugger/src/POSIXMachContractCLI.cc b/dev/LibDebugger/src/POSIXMachContractCLI.cc
new file mode 100644
index 0000000..90cebc3
--- /dev/null
+++ b/dev/LibDebugger/src/POSIXMachContractCLI.cc
@@ -0,0 +1,95 @@
+/***
+ LibDebugger
+ (C) 2025 Amlal El Mahrouss
+ File: POSIXMachContract.cc
+ Purpose: OS X/Darwin Debugger
+*/
+
+#ifdef LD_MACH_DEBUGGER
+
+#include <LibCompiler/Defines.h>
+#include <LibDebugger/POSIXMachContract.h>
+#include <Vendor/Dialogs.h>
+#include <cstdint>
+#include <iostream>
+#include <string>
+
+#include <LibDebugger/CommonCLI.inl>
+
+/// @internal
+/// @brief Handles CTRL-C signal on debugger.
+static void dbgi_ctrlc_handler(std::int32_t _) {
+ if (!kPID) {
+ return;
+ }
+
+ auto list = kDebugger.Get();
+
+ kDebugger.Break();
+
+ pfd::notify("Debugger Event", "Breakpoint hit!");
+
+ kKeepRunning = false;
+}
+
+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 << "[+] Image 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