aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-18 12:25:58 +0200
committerhachem <im@hachem.wtf>2026-09-18 12:25:58 +0200
commit4f74d1400180ca4ad7cfcd1903386fda8779818d (patch)
tree258a332c3076045461b5d6f8592a52140225abd1 /src/main.cpp
parent0846724177d823b632f2a4deffdcb5b6e226cd56 (diff)
feat: improve layout and themes
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b96a74a..4b0aee4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,7 +3,63 @@
#include "debugger/debugger.h"
+#include <algorithm>
+#include <charconv>
+#include <cstdlib>
+#include <filesystem>
#include <span>
+#include <string_view>
+
+namespace
+{
+ // dev aid: HSDBG_WINDOW=<w>x<h> sizes the window, and HSDBG_BREAK=<file>:<line>
+ // plants a breakpoint and launches as soon as the target loads, so a capture
+ // (HSDBG_CAPTURE) lands on a stopped target with every panel populated
+ auto dev_window_size(Hsdbg::ApplicationSpec& spec) -> void
+ {
+ const char* text = std::getenv("HSDBG_WINDOW");
+ if (text == nullptr)
+ return;
+
+ const std::string_view value(text);
+ const size_t x = value.find('x');
+ if (x == std::string_view::npos)
+ return;
+
+ std::from_chars(value.data(), value.data() + x, spec.width);
+ std::from_chars(value.data() + x + 1, value.data() + value.size(), spec.height);
+ }
+
+ auto dev_break_and_launch(Hsdbg::Debugger& debugger) -> void
+ {
+ const char* text = std::getenv("HSDBG_BREAK");
+ if (text == nullptr || !debugger.has_target())
+ return;
+
+ const std::string_view value(text);
+ const size_t colon = value.rfind(':');
+ if (colon == std::string_view::npos)
+ return;
+
+ uint32_t line = 0;
+ std::from_chars(value.data() + colon + 1, value.data() + value.size(), line);
+
+ // pick the target's own path for the file so it matches what lldb reports
+ const std::string_view name = value.substr(0, colon);
+ const std::span<const std::filesystem::path> files = debugger.source_files();
+ const auto known = std::ranges::find_if(files, [&](const std::filesystem::path& candidate)
+ {
+ return candidate.filename() == name;
+ });
+
+ debugger.add_breakpoint(known != files.end() ? *known : std::filesystem::path(name), line);
+
+ Hsdbg::LaunchSpec launch;
+ launch.executable = debugger.target_path();
+ if (const auto result = debugger.launch(launch); !result)
+ Hsdbg::Log::error("{}", result.error());
+ }
+}
auto main(int argc, char** argv) -> int
{
@@ -13,6 +69,7 @@ auto main(int argc, char** argv) -> int
spec.name = "hsdbg";
spec.width = 1600;
spec.height = 900;
+ dev_window_size(spec);
Hsdbg::Application app(spec);
@@ -20,6 +77,8 @@ auto main(int argc, char** argv) -> int
{
if (const auto result = app.debugger().load_target(arguments[1]); !result)
Hsdbg::Log::error("{}", result.error());
+
+ dev_break_and_launch(app.debugger());
}
app.run();