summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-30 08:50:15 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-30 08:50:15 +0100
commit1c8c5cff67b20d86c442b0917d6c1fc6407140df (patch)
tree53ebea660bef14cdc2ff5b7ebefb4049f705f997 /dev/LibDebugger
parent073811d89c98d6e1c078a032ca2eedefebf80384 (diff)
feat! Breaking API changes of NeCTI's LibCompiler and LibDebugger.
what: - They've now become CompilerKit and DebuggerKit. - Expanding XCoff for NeBoot PowerPC backend. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/LibDebugger')
-rw-r--r--dev/LibDebugger/CommonCLI.inl24
-rw-r--r--dev/LibDebugger/DebuggerContract.h44
-rw-r--r--dev/LibDebugger/NeKernelContract.h47
-rw-r--r--dev/LibDebugger/POSIXMachContract.h158
-rw-r--r--dev/LibDebugger/Version.h15
-rw-r--r--dev/LibDebugger/src/NeKernelContract.cc48
-rw-r--r--dev/LibDebugger/src/NeKernelContractCLI.cc101
-rw-r--r--dev/LibDebugger/src/POSIXMachContractCLI.cc93
8 files changed, 0 insertions, 530 deletions
diff --git a/dev/LibDebugger/CommonCLI.inl b/dev/LibDebugger/CommonCLI.inl
deleted file mode 100644
index 0b07271..0000000
--- a/dev/LibDebugger/CommonCLI.inl
+++ /dev/null
@@ -1,24 +0,0 @@
-/***
- LibDebugger
- (C) 2025 Amlal El Mahrouss
- File: CommonCLI.inl
- Purpose: Common Debugger symbols.
-*/
-
-#define kBlank "\e[0;30m"
-#define kRed "\e[0;31m"
-#define kWhite "\e[0;97m"
-
-#define kStdOut (std::cout << kRed << "dbg: " << kWhite)
-
-static BOOL kKeepRunning = false;
-
-#ifdef LD_NEKERNEL_DEBUGGER
-static LibDebugger::NeKernel::NeKernelContract kKernelDebugger;
-#else
-static LibDebugger::POSIX::POSIXMachContract kDebugger;
-#endif
-
-static LibDebugger::ProcessID kPID = 0L;
-static LibDebugger::CAddress kActiveAddress = nullptr;
-static std::string kPath = "";
diff --git a/dev/LibDebugger/DebuggerContract.h b/dev/LibDebugger/DebuggerContract.h
deleted file mode 100644
index c9b269f..0000000
--- a/dev/LibDebugger/DebuggerContract.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/***
- (C) 2025 Amlal El Mahrouss
- */
-
-#pragma once
-
-#include <cstdint>
-#include <string>
-#include <unordered_map>
-
-namespace LibDebugger {
-class DebuggerContract;
-
-/// \brief Process ID
-typedef uint64_t ProcessID;
-
-/// \brief Address type, a la BSD.
-typedef char* CAddress;
-
-/// \brief Debugger contract class in C++, as per the design states.
-/// \author Amlal El Mahrouss
-class DebuggerContract {
- public:
- explicit DebuggerContract() = default;
- virtual ~DebuggerContract() = default;
-
- public:
- DebuggerContract& operator=(const DebuggerContract&) = default;
- DebuggerContract(const DebuggerContract&) = default;
-
- public:
- virtual bool Attach(std::string path, std::string argv, ProcessID& pid) noexcept = 0;
- virtual bool BreakAt(std::string symbol) noexcept = 0;
- virtual bool Break() noexcept = 0;
- virtual bool Continue() noexcept = 0;
- virtual bool Detach() noexcept = 0;
-
- virtual std::unordered_map<uintptr_t, uintptr_t>& Get() { return m_breakpoints; }
-
- protected:
- ProcessID m_pid;
- std::unordered_map<uintptr_t, uintptr_t> m_breakpoints;
-};
-} // namespace LibDebugger
diff --git a/dev/LibDebugger/NeKernelContract.h b/dev/LibDebugger/NeKernelContract.h
deleted file mode 100644
index 9f816d8..0000000
--- a/dev/LibDebugger/NeKernelContract.h
+++ /dev/null
@@ -1,47 +0,0 @@
-
-/***
- (C) 2025 Amlal El Mahrouss
- */
-
-#ifndef LD_NEKERNEL_CONTRACT_H
-#define LD_NEKERNEL_CONTRACT_H
-
-#ifdef LD_NEKERNEL_DEBUGGER
-
-#include <LibDebugger/DebuggerContract.h>
-
-namespace LibDebugger::NeKernel {
-class NeKernelContract;
-
-namespace Detail {
- inline constexpr size_t kDebugCmdLen = 256U;
- typedef char rt_debug_cmd[kDebugCmdLen];
-} // namespace Detail
-
-class NeKernelContract : public DebuggerContract {
- public:
- NeKernelContract();
- ~NeKernelContract() override;
-
- public:
- NeKernelContract& operator=(const NeKernelContract&) = default;
- NeKernelContract(const NeKernelContract&) = default;
-
- // Override additional methods from DebuggerContract
-
- public:
- bool Attach(std::string path, std::string arg_v, ProcessID& pid) noexcept override;
- bool BreakAt(std::string symbol) noexcept override;
- bool Break() noexcept override;
- bool Continue() noexcept override;
- bool Detach() noexcept override;
-
- private:
- std::string m_kernel_path;
- int64_t m_socket{0};
-};
-} // namespace LibDebugger::NeKernel
-
-#endif // ifdef LD_NEKERNEL_DEBUGGER
-
-#endif // LD_NEKERNEL_CONTRACT_H \ No newline at end of file
diff --git a/dev/LibDebugger/POSIXMachContract.h b/dev/LibDebugger/POSIXMachContract.h
deleted file mode 100644
index 98085a2..0000000
--- a/dev/LibDebugger/POSIXMachContract.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/***
- (C) 2025 Amlal El Mahrouss
- */
-
-#pragma once
-
-#ifdef LD_MACH_DEBUGGER
-
-/// @file POSIXMachContract.h
-/// @brief POSIX Mach debugger.
-
-#include <LibCompiler/Defines.h>
-#include <LibDebugger/DebuggerContract.h>
-
-#include <stdint.h>
-#include <sys/ptrace.h>
-#include <sys/types.h>
-#include <sys/user.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <filesystem>
-#include <iostream>
-
-#include <dlfcn.h>
-#include <mach-o/dyld.h>
-#include <mach/mach.h>
-#include <mach/mach_error.h>
-#include <signal.h>
-
-LC_IMPORT_C kern_return_t mach_vm_write(vm_map_t target_task, mach_vm_address_t address,
- vm_offset_t data, mach_msg_type_number_t dataCnt);
-
-LC_IMPORT_C kern_return_t mach_vm_protect(vm_map_t target_task, mach_vm_address_t address,
- mach_vm_size_t size, boolean_t set_maximum,
- vm_prot_t new_protection);
-
-#define PTRACE_ATTACH PT_ATTACHEXC
-#define PTRACE_DETACH PT_DETACH
-#define PTRACE_POKETEXT PT_WRITE_I
-#define PTRACE_CONT PT_CONTINUE
-#define PTRACE_PEEKTEXT PT_READ_I
-
-namespace LibDebugger::POSIX {
-/// \brief POSIXMachContract engine interface class in C++
-/// \author Amlal El Mahrouss
-class POSIXMachContract : public DebuggerContract {
- public:
- explicit POSIXMachContract() = default;
- ~POSIXMachContract() override = default;
-
- public:
- POSIXMachContract& operator=(const POSIXMachContract&) = default;
- POSIXMachContract(const POSIXMachContract&) = default;
-
- public:
- BOOL Attach(std::string path, std::string argv, ProcessID& pid) noexcept override {
- pid = fork();
-
- if (pid == 0) {
- if (argv.empty()) {
- ptrace(PT_TRACE_ME, 0, nullptr, 0);
- kill(getpid(), SIGSTOP);
- }
-
- std::vector<char*> argv_arr;
-
- argv_arr.push_back(const_cast<char*>(path.c_str()));
- argv_arr.push_back(const_cast<char*>(argv.c_str()));
- argv_arr.push_back(nullptr);
-
- execv(path.c_str(), argv_arr.data());
-
- _exit(1);
- }
-
- m_path = path;
- m_pid = pid;
-
- pid = this->m_pid;
-
- return true;
- }
-
- void SetPath(std::string path) noexcept {
- if (path.empty()) {
- return;
- }
-
- m_path = path;
- }
-
- BOOL BreakAt(std::string symbol) noexcept override {
- if (!m_path.empty() && std::filesystem::exists(m_path) &&
- std::filesystem::is_regular_file(m_path)) {
- auto handle = dlopen(m_path.c_str(), RTLD_LAZY);
-
- if (handle == nullptr) {
- return false;
- }
-
- auto addr = dlsym(handle, symbol.c_str());
-
- if (addr == nullptr) {
- return false;
- }
-
- task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
-
- uint32_t brk_inst = 0xD43E0000;
-
- mach_vm_protect(task, (mach_vm_address_t) addr, sizeof(uint32_t), false,
- VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
- mach_vm_write(task, (mach_vm_address_t) addr, (vm_offset_t) &brk_inst, sizeof(addr));
-
- return true;
- }
-
- return false;
- }
-
- BOOL Break() noexcept override {
- task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
-
- kern_return_t ret = task_suspend(task);
-
- return ret == KERN_SUCCESS;
- }
-
- BOOL Continue() noexcept override {
- task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
-
- kern_return_t ret = task_resume(task);
-
- return ret == KERN_SUCCESS;
- }
-
- BOOL Detach() noexcept override {
- this->Continue();
-
- task_read_t task;
- task_for_pid(mach_task_self(), m_pid, &task);
-
- kern_return_t kr = mach_port_deallocate(mach_task_self(), task);
-
- return kr = KERN_SUCCESS;
- }
-
- private:
- ProcessID m_pid{0};
- std::string m_path;
-};
-} // namespace LibDebugger::POSIX
-
-#endif
diff --git a/dev/LibDebugger/Version.h b/dev/LibDebugger/Version.h
deleted file mode 100644
index 4159191..0000000
--- a/dev/LibDebugger/Version.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* -------------------------------------------
-
- Copyright (C) 2025 Amlal EL Mahrouss, all rights reserved
-
-------------------------------------------- */
-
-#pragma once
-
-#define kDistVersion "v0.0.1-libdebugger"
-#define kDistVersionBCD 0x0001
-
-#define ToString(X) Stringify(X)
-#define Stringify(X) #X
-
-#define kDistRelease ToString(kDistReleaseBranch)
diff --git a/dev/LibDebugger/src/NeKernelContract.cc b/dev/LibDebugger/src/NeKernelContract.cc
deleted file mode 100644
index 2c2543e..0000000
--- a/dev/LibDebugger/src/NeKernelContract.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-/***
- LibDebugger
- (C) 2025 Amlal El Mahrouss
- File: NeKernelContract.cc
- Purpose: NeKernel Debugger
-*/
-
-#ifdef LD_NEKERNEL_DEBUGGER
-
-#include <LibCompiler/Defines.h>
-#include <LibDebugger/NeKernelContract.h>
-#include <Vendor/Dialogs.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-constexpr static UInt16 kDebugPort = 51820;
-
-using namespace LibDebugger::NeKernel;
-
-NeKernelContract::NeKernelContract() = default;
-
-NeKernelContract::~NeKernelContract() = default;
-
-BOOL NeKernelContract::Attach(LibCompiler::STLString path, LibCompiler::STLString argv,
- ProcessID& pid) noexcept {
- return NO;
-}
-
-BOOL NeKernelContract::BreakAt(LibCompiler::STLString symbol) noexcept {
- return NO;
-}
-
-BOOL NeKernelContract::Break() noexcept {
- return NO;
-}
-
-BOOL NeKernelContract::Continue() noexcept {
- return NO;
-}
-
-BOOL NeKernelContract::Detach() noexcept {
- return NO;
-}
-
-#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file
diff --git a/dev/LibDebugger/src/NeKernelContractCLI.cc b/dev/LibDebugger/src/NeKernelContractCLI.cc
deleted file mode 100644
index 25e9c13..0000000
--- a/dev/LibDebugger/src/NeKernelContractCLI.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-/***
- LibDebugger
- (C) 2025 Amlal El Mahrouss
- File: NeKernelContract.cc
- Purpose: NeKernel Debugger CLI.
-*/
-
-#ifdef LD_NEKERNEL_DEBUGGER
-
-#include <LibCompiler/Defines.h>
-#include <LibDebugger/NeKernelContract.h>
-#include <Vendor/Dialogs.h>
-#include <string>
-
-#include <LibDebugger/CommonCLI.inl>
-
-using namespace LibDebugger::NeKernel;
-
-static void dbgi_ctrlc_handler(std::int32_t _) {
- if (!kPID || kPath.empty()) {
- return;
- }
-
- kKernelDebugger.Break();
-
- pfd::notify("Debugger Event", "BreakAt hit!");
-
- kKeepRunning = false;
-}
-
-LIBCOMPILER_MODULE(DebuggerNeKernel) {
- pfd::notify("Debugger Event",
- "Kernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved.");
-
- if (argc >= 5 && std::string(argv[1]) == "-k" && argv[2] != nullptr &&
- std::string(argv[3]) == "-ip" && argv[4] != nullptr) {
- kPath = argv[2];
- kPath += ":";
- kPath += argv[4];
-
- kStdOut << "[+] KIP (Kernel:IP) set to: " << kPath << "\n";
-
- LibCompiler::install_signal(SIGINT, dbgi_ctrlc_handler);
-
- kKernelDebugger.Attach(kPath, "", kPID);
- kKernelDebugger.BreakAt("$HANDOVER_START");
-
- while (YES) {
- if (kKeepRunning) {
- continue;
- }
-
- std::string cmd;
- if (!std::getline(std::cin, cmd)) break;
-
- if (cmd == "c" || cmd == "cont" || cmd == "continue") {
- if (kKernelDebugger.Continue()) {
- kKeepRunning = true;
-
- kStdOut << "[+] Continuing...\n";
-
- pfd::notify("Debugger Event", "Continuing...");
- }
- }
-
- if (cmd == "d" || cmd == "detach") kKernelDebugger.Detach();
-
- if (cmd == "start") {
- kStdOut << "[?] Enter a argument to use: ";
- std::getline(std::cin, cmd);
-
- kKernelDebugger.Attach(kPath, cmd, kPID);
- }
-
- if (cmd == "exit") {
- if (kPID > 0) kKernelDebugger.Detach();
-
- break;
- }
-
- if (cmd == "break" || cmd == "b") {
- kStdOut << "[?] Enter a symbol to break on: ";
-
- std::getline(std::cin, cmd);
-
- if (kKernelDebugger.BreakAt(cmd)) {
- pfd::notify("Debugger Event", "Add BreakAt at: " + cmd);
- }
- }
- }
-
- return EXIT_SUCCESS;
- }
-
- kStdOut << "Usage: " << argv[0] << " -k <kernel_path> -ip <ip4>\n";
- kStdOut << "Example: " << argv[0] << " -k /path/to/ne_kernel -ip 127.0.0.1\n";
-
- return EXIT_FAILURE;
-}
-
-#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file
diff --git a/dev/LibDebugger/src/POSIXMachContractCLI.cc b/dev/LibDebugger/src/POSIXMachContractCLI.cc
deleted file mode 100644
index 0962ba6..0000000
--- a/dev/LibDebugger/src/POSIXMachContractCLI.cc
+++ /dev/null
@@ -1,93 +0,0 @@
-/***
- 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;
- }
-
- kDebugger.Break();
-
- pfd::notify("Debugger Event", "BreakAt 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";
- }
-
- LibCompiler::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 (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.BreakAt(cmd)) {
- pfd::notify("Debugger Event", "Add BreakAt at: " + cmd);
- }
- }
- }
-
- return EXIT_SUCCESS;
-}
-
-#endif \ No newline at end of file