diff --git a/.clang-tidy b/.clang-tidy
index d7f8eb9..d21c33a 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -34,7 +34,8 @@ Checks: >
-readability-else-after-return,
-readability-braces-around-statements,
-google-readability-braces-around-statements,
- -misc-include-cleaner
+ -misc-include-cleaner,
+ -cppcoreguidelines-non-private-member-variables-in-classes
WarningsAsErrors: ''
@@ -86,7 +87,7 @@ CheckOptions:
value: true
# Exclude third-party code and build artifacts
-HeaderFilterRegex: '^.*/(src|test)/.*\.(h|hpp)$'
+HeaderFilterRegex: '^.*/(src|test)/(?!.*mach_exc).*\.(h|hpp)$'
# Suppress warnings from system headers
SystemHeaders: false
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e37928e..29cc91d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,44 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+# OPTIONAL: Use ccache if present
+find_program(CCACHE_PROGRAM ccache)
+if(CCACHE_PROGRAM)
+ set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
+ set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
+ message(STATUS "ccache found: ${CCACHE_PROGRAM}")
+else()
+ message(WARNING "ccache not found - builds will be slower. Install with: brew install ccache")
+endif()
+
+# Only brew LLVM is supported on OSX at the moment
+if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
+ # Find brew
+ find_program(BREW_PROGRAM brew)
+ if(NOT BREW_PROGRAM)
+ message(FATAL_ERROR "Homebrew not found! Install from https://brew.sh")
+ endif()
+
+ # Find LLVM
+ execute_process(COMMAND brew --prefix llvm OUTPUT_VARIABLE LLVM_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE BREW_LLVM_RESULT ERROR_QUIET)
+ if(NOT BREW_LLVM_RESULT EQUAL 0)
+ message(FATAL_ERROR "Brew LLVM not found! Install with: brew install llvm")
+ endif()
+
+ # Use brew LLVM clang
+ set(CMAKE_C_COMPILER "${LLVM_PREFIX}/bin/clang")
+ set(CMAKE_CXX_COMPILER "${LLVM_PREFIX}/bin/clang++")
+
+ # Link with brew LLVM libc++
+ execute_process(COMMAND brew --prefix llvm OUTPUT_VARIABLE LLVM_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
+ add_compile_options(-stdlib=libc++)
+ add_link_options(-stdlib=libc++ -L${LLVM_PREFIX}/lib/c++ -Wl,-rpath,${LLVM_PREFIX}/lib/c++)
+
+ # Set OSX SDK
+ execute_process(COMMAND xcrun --sdk macosx --show-sdk-path OUTPUT_VARIABLE OSX_SYSROOT OUTPUT_STRIP_TRAILING_WHITESPACE)
+ set(CMAKE_OSX_SYSROOT "${OSX_SYSROOT}")
+endif()
+
project(caesar VERSION 0.1.0)
# Optional: Enable code coverage
@@ -33,9 +71,13 @@ if(ENABLE_COVERAGE)
message(STATUS "Code coverage enabled")
endif()
-add_executable(caesar src/main.cpp)
+add_executable(caesar src/main.cpp src/error.cpp src/error.hpp src/formatter.hpp)
target_link_libraries(caesar PRIVATE caesar_cmd caesar_core)
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ target_link_libraries(caesar PRIVATE caesar_macho)
+endif()
+
# Optional: Build tests
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR OR CAESAR_BUILD_TESTS)
option(CAESAR_BUILD_TESTS "Build tests" ON)
@@ -52,10 +94,16 @@ if(CAESAR_BUILD_TESTS)
test/cmd/test_object.cpp
test/cmd/test_parser.cpp
test/cmd/test_scanner.cpp
+ test/cmd/test_stdlib.cpp
+ src/error.cpp
)
target_link_libraries(caesar_test PRIVATE caesar_cmd caesar_core Catch2::Catch2WithMain)
+ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ target_link_libraries(caesar_test PRIVATE caesar_macho)
+ endif()
+
# Apply coverage flags to test executable if coverage is enabled
if(ENABLE_COVERAGE)
target_compile_options(caesar_test PUBLIC ${COVERAGE_COMPILE_FLAGS})
diff --git a/README.md b/README.md
index 8080015..dc954d6 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ A modern C++20 cross-platform debugger.
The debugger is built with a modular architecture:
-- **Core Engine** (`src/core/`): Core debugger engine functionality
+- **Core Engine** (`src/core/`): Core debugger engine functionality. Split into separate libraries per platform
- **Command System** (`src/cmd/`): Expression parser, interpreter, and AST components
## Building
@@ -28,7 +28,7 @@ The debugger is built with a modular architecture:
```bash
mkdir build
cd build
-cmake ..
+cmake .. --preset (debug|release)
make
```
@@ -42,6 +42,13 @@ Run the debugger without arguments to enter interactive mode:
This starts a REPL where you can enter expressions and commands.
+Alternatively, run with a file to automatically set a target upon startup:
+
+```bash
+./caesar (file)
+```
+
+
### Development Environment
The project includes a development setup script:
@@ -50,7 +57,7 @@ The project includes a development setup script:
./start.sh
```
-This creates a tmux session with editor, compiler, and miscellaneous panes for efficient development. This is my preffered environment, feel free to use or adapt it to your own needs.
+This creates a tmux session with editor, compiler, and miscellaneous panes for efficient development. This is my preferred environment, feel free to use or adapt it to your own needs.
## Components
@@ -58,7 +65,13 @@ This creates a tmux session with editor, compiler, and miscellaneous panes for e
- **Scanner**: Tokenizes input expressions
- **Parser**: Builds abstract syntax trees from tokens
- **Interpreter**: Evaluates expressions with support for literals, grouping, unary and binary operations
-- **AST Printer**: Debug utility for visualizing abstract syntax trees
+- **Built-in Functions**: Native commands for debugging (breakpoint, run, resume, etc.)
+
+### Core Debugging Engine
+- **Target**: Process control, breakpoint management, and binary inspection
+- **Macho**: Mach-O parser supporting 64-bit architectures and byte swapping
+- **Exception Ports**: Mach-based exception handling for traps and signals
+- **ASLR**: Automatic slide detection for address resolution
## Project Status
diff --git a/src/Entitlements.plist b/src/Entitlements.plist
new file mode 100644
index 0000000..3d60e8b
--- /dev/null
+++ b/src/Entitlements.plist
@@ -0,0 +1,8 @@
+
+
+
+
+ com.apple.security.cs.debugger
+
+
+
diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt
index 6a9093e..0f58517 100644
--- a/src/cmd/CMakeLists.txt
+++ b/src/cmd/CMakeLists.txt
@@ -1,6 +1,4 @@
add_library(caesar_cmd STATIC
- error.cpp
- error.hpp
scanner.cpp
scanner.hpp
token.hpp
@@ -17,9 +15,8 @@ add_library(caesar_cmd STATIC
callable.hpp
stdlib.hpp
object.hpp
- formatter.hpp
)
target_include_directories(caesar_cmd PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/..
)
diff --git a/src/cmd/callable.hpp b/src/cmd/callable.hpp
index 081b40d..e79d25f 100644
--- a/src/cmd/callable.hpp
+++ b/src/cmd/callable.hpp
@@ -5,11 +5,16 @@
#include
#include
+#include "core/context.hpp"
+#include "core/target.hpp"
#include "object.hpp"
class Interpreter;
class Callable {
+ protected:
+ std::unique_ptr& m_target = Context::getTarget();
+
public:
virtual ~Callable() = default;
virtual Object call(std::vector