From 4f74d1400180ca4ad7cfcd1903386fda8779818d Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 18 Sep 2026 12:25:58 +0200 Subject: feat: improve layout and themes --- src/main.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/main.cpp') 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 +#include +#include +#include #include +#include + +namespace +{ + // dev aid: HSDBG_WINDOW=x sizes the window, and HSDBG_BREAK=: + // 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 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(); -- cgit v1.3