#include "core/application.h" #include "core/log.h" #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 { const std::span arguments(argv, static_cast(argc)); Hsdbg::ApplicationSpec spec; spec.name = "hsdbg"; spec.width = 1600; spec.height = 900; dev_window_size(spec); Hsdbg::Application app(spec); if (arguments.size() > 1) { if (const auto result = app.debugger().load_target(arguments[1]); !result) Hsdbg::Log::error("{}", result.error()); dev_break_and_launch(app.debugger()); } app.run(); return 0; }