summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 09:41:29 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 09:41:29 +0200
commit0561a8d0a6ae7588309a6e3513bbfeeef5f0aa15 (patch)
treef7fdd41a02cd9c5ae5288e4c6c74ab386f200900
parent81023b13dd170b0eceb1868355a600ad15abe4ea (diff)
dev, LibDebugger: add kdbg, working on NeKernelContract's implementation.
Signed-off-by: Amlal <amlal@nekernel.org>
-rw-r--r--dev/LibDebugger/DebuggerContract.h18
-rw-r--r--dev/LibDebugger/NeKernelContract.h67
-rw-r--r--dev/LibDebugger/POSIXMachContract.h9
-rw-r--r--dev/LibDebugger/src/POSIXMachContract.cc7
-rw-r--r--tools/kdbg.cc19
-rw-r--r--tools/kdbg.json12
6 files changed, 119 insertions, 13 deletions
diff --git a/dev/LibDebugger/DebuggerContract.h b/dev/LibDebugger/DebuggerContract.h
index d5f62c2..0ef88a2 100644
--- a/dev/LibDebugger/DebuggerContract.h
+++ b/dev/LibDebugger/DebuggerContract.h
@@ -4,12 +4,18 @@
#pragma once
-#include <iostream>
+#include <cstdint>
#include <unordered_map>
+#include <string>
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.
@@ -26,10 +32,10 @@ namespace LibDebugger
public:
virtual bool Attach(std::string path, std::string argv, ProcessID& pid) noexcept = 0;
- virtual bool Breakpoint(std::string symbol) noexcept = 0;
- virtual bool Break() noexcept = 0;
- virtual bool Continue() noexcept = 0;
- virtual bool Detach() noexcept = 0;
+ virtual bool Breakpoint(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()
{
@@ -37,7 +43,7 @@ namespace LibDebugger
}
protected:
- pid_t m_pid;
+ 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
new file mode 100644
index 0000000..e6b40d0
--- /dev/null
+++ b/dev/LibDebugger/NeKernelContract.h
@@ -0,0 +1,67 @@
+
+/***
+ (C) 2025 Amlal El Mahrouss
+ */
+
+#ifndef LD_NEKERNEL_CONTRACT_H
+#define LD_NEKERNEL_CONTRACT_H
+
+#include <LibDebugger/DebuggerContract.h>
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#define kDebugUnboundPort 0x0FEED
+
+#define kDebugMag0 'K'
+#define kDebugMag1 'D'
+#define kDebugMag2 'B'
+#define kDebugMag3 'G'
+
+#define kDebugSourceFile 23
+#define kDebugLine 33
+#define kDebugTeam 43
+#define kDebugEOP 49
+
+namespace LibDebugger::NeKernel
+{
+ class NeKernelContract;
+
+ namespace Detail
+ {
+ class NeKernelPortHeader;
+
+ inline constexpr size_t kDebugTypeLen = 256U;
+
+ typedef char rt_debug_type[kDebugTypeLen];
+
+ class NeKernelPortHeader final
+ {
+ public:
+ int16_t fPort;
+ int16_t fPortBsy;
+ };
+ } // namespace Detail
+
+ class NeKernelContract : public DebuggerContract
+ {
+ public:
+ NeKernelContract();
+ virtual ~NeKernelContract();
+
+ // Override additional methods from DebuggerContract
+ virtual bool Attach(std::string path, std::string argv, ProcessID& pid) noexcept override;
+ virtual bool Breakpoint(std::string symbol) noexcept override;
+ virtual bool Break() noexcept override;
+ virtual bool Continue() noexcept override;
+ virtual bool Detach() noexcept override;
+
+ private:
+ std::string m_ip_address;
+ std::string m_port;
+ };
+} // namespace LibDebugger::NeKernel
+
+#endif // LD_NEKERNEL_CONTRACT_H \ No newline at end of file
diff --git a/dev/LibDebugger/POSIXMachContract.h b/dev/LibDebugger/POSIXMachContract.h
index a231d74..fbfe928 100644
--- a/dev/LibDebugger/POSIXMachContract.h
+++ b/dev/LibDebugger/POSIXMachContract.h
@@ -4,12 +4,10 @@
#pragma once
-#ifdef _WIN32
-#error Windows doesn't have a POSIX/Mach subsystem, please combine with windows instead.
-#endif
+#ifdef __APPLE__
/// @file POSIXMachContract.h
-/// @brief POSIX/Mach debugger.
+/// @brief POSIX Mach debugger.
#include <LibDebugger/DebuggerContract.h>
#include <LibCompiler/Defines.h>
@@ -22,6 +20,7 @@
#include <stdint.h>
#include <filesystem>
+#include <iostream>
#include <mach/mach.h>
#include <mach/mach_error.h>
@@ -168,3 +167,5 @@ namespace LibDebugger::POSIX
std::string m_path;
};
} // namespace LibDebugger::POSIX
+
+#endif
diff --git a/dev/LibDebugger/src/POSIXMachContract.cc b/dev/LibDebugger/src/POSIXMachContract.cc
index 1c23448..2f30f09 100644
--- a/dev/LibDebugger/src/POSIXMachContract.cc
+++ b/dev/LibDebugger/src/POSIXMachContract.cc
@@ -2,14 +2,15 @@
(C) 2025 Amlal El Mahrouss
*/
+ #ifdef __APPLE__
+
+#include <iostream>
#include <LibCompiler/Defines.h>
#include <Vendor/Dialogs.h>
#include <LibDebugger/POSIXMachContract.h>
#include <cstdint>
#include <string>
-#ifndef _WIN32
-
static BOOL kKeepRunning = false;
static LibDebugger::POSIX::POSIXMachContract kDebugger;
static LibDebugger::ProcessID kPID = 0L;
@@ -42,7 +43,7 @@ static void dbgi_ctrlc_handler(std::int32_t _)
LIBCOMPILER_MODULE(DebuggerMachPOSIX)
{
- pfd::notify("Debugger Event", "NeKernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved.");
+ 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)
diff --git a/tools/kdbg.cc b/tools/kdbg.cc
new file mode 100644
index 0000000..5aae438
--- /dev/null
+++ b/tools/kdbg.cc
@@ -0,0 +1,19 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved
+
+------------------------------------------- */
+
+#include <LibCompiler/Defines.h>
+
+/// @file kdbg.cxx
+/// @brief NeKernel debugger.
+
+LC_IMPORT_C int DebuggerNeKernel(int argc, char const* argv[]);
+
+/// @brief Debugger entrypoint.
+/// @return Status code of debugger.
+int main(int argc, char const* argv[])
+{
+ return DebuggerNeKernel(argc, argv);
+}
diff --git a/tools/kdbg.json b/tools/kdbg.json
new file mode 100644
index 0000000..8019a76
--- /dev/null
+++ b/tools/kdbg.json
@@ -0,0 +1,12 @@
+{
+ "compiler_path": "g++",
+ "compiler_std": "c++20",
+ "headers_path": ["../dev/LibCompiler", "../dev/", "../dev/LibCompiler/src/Detail"],
+ "sources_path": ["kdbg.cc"],
+ "output_name": "kdbg",
+ "compiler_flags": ["-L/usr/lib", "-lDebugger"],
+ "cpp_macros": [
+ "__DBG__=202401",
+ "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)"
+ ]
+}