summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format41
-rw-r--r--.gitignore2
-rw-r--r--imgui.ini10
-rw-r--r--include/boltdbg/util/logger.h26
-rwxr-xr-xscripts/format.sh45
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/main.cpp148
-rw-r--r--src/util/logger.cpp29
8 files changed, 220 insertions, 82 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..3e44e3f
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,41 @@
+BasedOnStyle: GNU
+AlignAfterOpenBracket: Align
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: All
+# Uncommenting these lines will sometimes result in lines following an
+# if(){} or for(){} block being attached to the end of the block.
+# AllowShortIfStatementsOnASingleLine: true
+# AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+BreakBeforeBraces: Custom
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterStruct: true
+ AfterUnion: true
+ AfterExternBlock: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: true
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
+ContinuationIndentWidth: 2
+Cpp11BracedListStyle: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+Language: Cpp
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 1
+PointerAlignment: Right
+SortIncludes: false
+SpaceBeforeParens: Never
+SpacesInContainerLiterals: false
+Standard: Cpp11
diff --git a/.gitignore b/.gitignore
index c504c0a..d20ee4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,5 @@ Makefile
.DS_Store
external/
+*.log
+*.ini
diff --git a/imgui.ini b/imgui.ini
deleted file mode 100644
index 9452231..0000000
--- a/imgui.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-[Window][Debug##Default]
-Pos=60,60
-Size=400,400
-Collapsed=0
-
-[Window][BoltDBG - Demo]
-Pos=60,20
-Size=393,352
-Collapsed=0
-
diff --git a/include/boltdbg/util/logger.h b/include/boltdbg/util/logger.h
new file mode 100644
index 0000000..554f2c7
--- /dev/null
+++ b/include/boltdbg/util/logger.h
@@ -0,0 +1,26 @@
+#ifndef BOLTDBG_UTIL_LOGGER_H_
+#define BOLTDBG_UTIL_LOGGER_H_
+
+/*
+ * Global spdlog accessor for boltdbg.
+ *
+ * Use Log::get() anywhere to obtain the shared logger.
+ */
+
+#include <memory>
+#include <spdlog/spdlog.h>
+
+namespace Log { // NOTE: capital 'L' to avoid collision with C math 'log'
+ // Return a reference to a shared_ptr logger initialized on first use.
+ std::shared_ptr<spdlog::logger>& get();
+}
+
+// Handy logger macros (use Log with capital L)
+#define LOG_TRACE(...) ::Log::get()->trace(__VA_ARGS__)
+#define LOG_DEBUG(...) ::Log::get()->debug(__VA_ARGS__)
+#define LOG_INFO(...) ::Log::get()->info(__VA_ARGS__)
+#define LOG_WARN(...) ::Log::get()->warn(__VA_ARGS__)
+#define LOG_ERROR(...) ::Log::get()->error(__VA_ARGS__)
+#define LOG_CRITICAL(...) ::Log::get()->critical(__VA_ARGS__)
+
+#endif // BOLTDBG_UTIL_LOGGER_H_
diff --git a/scripts/format.sh b/scripts/format.sh
new file mode 100755
index 0000000..3b77776
--- /dev/null
+++ b/scripts/format.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+#
+# format.sh — Formats all source files in the project using clang-format.
+#
+# Usage:
+# ./scripts/format.sh # Format all C/C++ source files
+# ./scripts/format.sh --check # Check formatting without modifying files
+#
+
+set -euo pipefail
+
+# Project root (one level up from scripts/)
+ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "$ROOT_DIR"
+
+# Find all C/C++ files (excluding build directories and third-party code)
+FILES=$(find src include -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) \
+ ! -path "*/build/*" ! -path "*/third_party/*")
+
+# Default clang-format style (fallback if no .clang-format exists)
+STYLE="file"
+if [ ! -f ".clang-format" ]; then
+ STYLE="llvm"
+fi
+
+# Command arguments
+CMD_ARGS=("-i" "--style=${STYLE}")
+if [[ "${1:-}" == "--check" ]]; then
+ CMD_ARGS=("--dry-run" "--Werror" "--style=${STYLE}")
+ echo "Checking code format..."
+else
+ echo "Formatting source files..."
+fi
+
+# Run clang-format on each file
+for file in $FILES; do
+ clang-format "${CMD_ARGS[@]}" "$file"
+done
+
+if [[ "${1:-}" == "--check" ]]; then
+ echo "Format check passed!"
+else
+ echo "Formatting complete."
+fi
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9875cd7..9bad7f7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.15) # local guard if included standalone
# Collect core sources (placeholder + real sources later)
set(BOLTDBG_CORE_SOURCES
dummy.cpp # placeholder; replace/add real core sources here
+ util/logger.cpp
# src/core/debugger.cpp
# src/core/process.cpp
)
diff --git a/src/main.cpp b/src/main.cpp
index 0a23004..b9a327f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,14 +1,12 @@
// src/main.cpp
#include <iostream>
-// spdlog
-#include <spdlog/spdlog.h>
-
// Prevent GLFW from including OpenGL headers (so glad can provide them)
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
-// GL loader (glad) - include after GLFW_INCLUDE_NONE so glad can provide GL headers
+// GL loader (glad) - include after GLFW_INCLUDE_NONE so glad can provide GL
+// headers
#if __has_include("glad/glad.h")
#include <glad/glad.h>
#define HAVE_GLAD 1
@@ -16,103 +14,109 @@
#define HAVE_GLAD 0
#endif
-// Now include ImGui and its backends (they expect glfw + GL loader to be present)
+// Now include ImGui and its backends (they expect glfw + GL loader to be
+// present)
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
-int main(int argc, char** argv) {
- // init logger
- try {
- spdlog::set_level(spdlog::level::info);
- spdlog::info("BoltDBG demo starting (spdlog initialized).");
- } catch (const std::exception &e) {
- std::cerr << "spdlog init failed: " << e.what() << std::endl;
- }
+#include <boltdbg/util/logger.h>
+
+int main(int argc, char **argv)
+{
- if (!glfwInit()) {
- spdlog::error("Failed to initialize GLFW");
- return 1;
+ if(!glfwInit())
+ {
+ LOG_ERROR("Failed to initialize GLFW");
+ return 1;
}
- // GL settings (3.3 core as example)
- const char* glsl_version = "#version 330";
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
+ // GL settings (3.3 core as example)
+ const char *glsl_version = "#version 330";
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
#if __APPLE__
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
- GLFWwindow* window = glfwCreateWindow(1280, 720, "BoltDBG - ImGui + spdlog demo", NULL, NULL);
- if (!window) {
- spdlog::error("Failed to create GLFW window");
- glfwTerminate();
- return 1;
+ GLFWwindow *window
+ = glfwCreateWindow(1280, 720, "BoltDBG", NULL, NULL);
+ if(!window)
+ {
+ LOG_ERROR("Failed to create GLFW window");
+ glfwTerminate();
+ return 1;
}
- glfwMakeContextCurrent(window);
- glfwSwapInterval(1);
+ glfwMakeContextCurrent(window);
+ glfwSwapInterval(1);
#if HAVE_GLAD
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
- spdlog::error("Failed to initialize GLAD");
- return 1;
+ if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
+ {
+ LOG_ERROR("Failed to initialize GLAD");
+ return 1;
}
#else
- spdlog::warn("GLAD not detected at compile-time. If you experience GL symbol errors, add glad.");
+ LOG_WARN("GLAD not detected at compile-time. If you experience GL "
+ "symbol errors, add glad.");
#endif
- // ImGui init
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGuiIO &io = ImGui::GetIO(); (void)io;
- ImGui::StyleColorsDark();
+ // ImGui init
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO &io = ImGui::GetIO();
+ (void)io;
+ ImGui::StyleColorsDark();
- ImGui_ImplGlfw_InitForOpenGL(window, true);
- ImGui_ImplOpenGL3_Init(glsl_version);
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
+ ImGui_ImplOpenGL3_Init(glsl_version);
- spdlog::info("Entering main loop.");
+ LOG_INFO("Entering main loop.");
- bool show_demo = false;
- int click_count = 0;
+ bool show_demo = false;
+ int click_count = 0;
- while (!glfwWindowShouldClose(window)) {
- glfwPollEvents();
+ while(!glfwWindowShouldClose(window))
+ {
+ glfwPollEvents();
- ImGui_ImplOpenGL3_NewFrame();
- ImGui_ImplGlfw_NewFrame();
- ImGui::NewFrame();
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplGlfw_NewFrame();
+ ImGui::NewFrame();
- ImGui::Begin("BoltDBG - Demo");
- ImGui::Text("Hello from BoltDBG demo!");
- if (ImGui::Button("Log info with spdlog")) {
- click_count++;
- spdlog::info("Button clicked {} times", click_count);
+ ImGui::Begin("BoltDBG - Demo");
+ ImGui::Text("Hello from BoltDBG demo!");
+ if(ImGui::Button("Log info with spdlog"))
+ {
+ click_count++;
+ LOG_INFO("Button clicked {} times", click_count);
}
- ImGui::Text("Click count: %d", click_count);
- ImGui::End();
+ ImGui::Text("Click count: %d", click_count);
+ ImGui::End();
- if (show_demo) ImGui::ShowDemoWindow(&show_demo);
+ if(show_demo)
+ ImGui::ShowDemoWindow(&show_demo);
- ImGui::Render();
- int display_w, display_h;
- glfwGetFramebufferSize(window, &display_w, &display_h);
- glViewport(0, 0, display_w, display_h);
- glClearColor(0.1f, 0.12f, 0.14f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+ ImGui::Render();
+ int display_w, display_h;
+ glfwGetFramebufferSize(window, &display_w, &display_h);
+ glViewport(0, 0, display_w, display_h);
+ glClearColor(0.1f, 0.12f, 0.14f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
- glfwSwapBuffers(window);
+ glfwSwapBuffers(window);
}
- // cleanup
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplGlfw_Shutdown();
- ImGui::DestroyContext();
+ // cleanup
+ ImGui_ImplOpenGL3_Shutdown();
+ ImGui_ImplGlfw_Shutdown();
+ ImGui::DestroyContext();
- glfwDestroyWindow(window);
- glfwTerminate();
+ glfwDestroyWindow(window);
+ glfwTerminate();
- spdlog::info("BoltDBG demo exiting.");
- return 0;
+ LOG_INFO("BoltDBG demo exiting.");
+ return 0;
}
diff --git a/src/util/logger.cpp b/src/util/logger.cpp
new file mode 100644
index 0000000..1586743
--- /dev/null
+++ b/src/util/logger.cpp
@@ -0,0 +1,29 @@
+#include <boltdbg/util/logger.h>
+#include <spdlog/sinks/basic_file_sink.h>
+#include <spdlog/sinks/stdout_color_sinks.h>
+#include <spdlog/sinks/ostream_sink.h>
+#include <spdlog/sinks/msvc_sink.h>
+#include <vector>
+
+namespace Log {
+
+std::shared_ptr<spdlog::logger>& get() {
+ static std::shared_ptr<spdlog::logger> logger = [] {
+
+ std::vector<spdlog::sink_ptr> sinks;
+ sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
+ sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("app.log", true));
+
+ auto logger = std::make_shared<spdlog::logger>("global", sinks.begin(), sinks.end());
+ logger->set_level(spdlog::level::trace);
+ logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [thread %t] [%s:%#] %v");
+
+ spdlog::register_logger(logger);
+ spdlog::set_default_logger(logger);
+
+ return logger;
+ }();
+ return logger;
+}
+
+} // namespace log