#include "Leaf.hpp" #include "Supervisor.hpp" #include "Trace.hpp" #include #include #include namespace { constexpr std::string_view usage = "vls_gcc_probe run COMPILER SHA256 SOURCE NEW_TRACE [--step]\n" "vls_gcc_probe replay TRACE [EVENT_SEQUENCE]\n" "At a stop, send NONCE STOP inspect|step|continue|cancel and a newline.\n" "During a stepped run, NONCE cancel cancels the running frontend.\n"; } int main(int argc, char **argv) try { using namespace vls::gcc; const std::string_view mode = argc >= 2 ? argv[1] : ""; if (mode == "--leaf" && argc == 6) { const std::string_view action{argv[5]}; if (action != "step" && action != "observe") return 126; return run_leaf(argv[2], argv[3], argv[4], action == "step"); } if (mode == "--help" && argc == 2) { std::cout << usage; return 0; } std::signal(SIGPIPE, SIG_IGN); if (mode == "run" && (argc == 6 || (argc == 7 && std::string_view(argv[6]) == "--step"))) { RunOptions options{std::filesystem::absolute(argv[2]), argv[3], std::filesystem::absolute(argv[4]), std::filesystem::absolute(argv[5]), argc == 7}; auto result = run_session(options); if (!result) { std::cerr << "vls_gcc_probe: " << result.error() << '\n'; return 1; } return *result; } if (mode == "replay" && (argc == 3 || argc == 4)) { std::optional sequence; if (argc == 4) { const std::string_view text{argv[3]}; const auto end = text.data() + text.size(); auto [last, error] = std::from_chars(text.data(), end, sequence.emplace()); if (error != std::errc{} || last != end) return 2; } auto snapshot = replay(std::filesystem::absolute(argv[2]), sequence); if (!snapshot) { std::cerr << "vls_gcc_probe: " << snapshot.error() << '\n'; return 1; } auto json = Protocol::serialize_json(*snapshot); if (!json) return 1; std::cout << *json << '\n'; return std::cout ? 0 : 1; } std::cerr << usage; return 2; } catch (const std::exception &error) { std::cerr << "vls_gcc_probe: " << error.what() << '\n'; return 1; }