// Scripted private-compiler worker for the LiveSession suite. It speaks the // same notice/control protocol as vls_gcc_probe without running a compiler. #include #include #include #include #include #include namespace { constexpr std::string_view nonce = "0123456789abcdef0123456789abcdef"; void notice(const std::string &line) { std::cout << line << '\n' << std::flush; } void stopped(unsigned sequence) { notice(R"({"kind":"stopped","nonce":")" + std::string{nonce} + R"(","stop":)" + std::to_string(sequence) + "}"); } void finished(std::string_view outcome) { notice(R"({"kind":"finished","nonce":")" + std::string{nonce} + R"(","outcome":")" + std::string{outcome} + R"(","exitCode":0,"reason":""})"); } } // namespace int main(int argc, char **argv) { if (argc < 6 || std::string_view(argv[1]) != "run") return 2; const std::string scenario = std::filesystem::path(argv[4]).filename().string(); notice(R"({"kind":"started","nonce":")" + std::string{nonce} + R"(","pid":1})"); if (scenario == "silent.cpp") { std::this_thread::sleep_for(std::chrono::seconds(60)); return 0; } if (scenario == "malformed.cpp") { std::cout << std::string(70000, 'x') << '\n' << std::flush; return 0; } unsigned sequence = 1; stopped(sequence); std::string line; while (std::getline(std::cin, line)) { std::istringstream fields{line}; std::string received, action; unsigned requested = 0; fields >> received >> requested >> action; if (received != nonce) { notice(R"({"kind":"rejected"})"); continue; } if (action == "inspect") { notice( R"({"kind":"inspection","snapshot":{"schemaVersion":1,"sessionId":"live-fixture","generation":)" + std::to_string(requested) + R"(,"eventSequence":)" + std::to_string(requested) + R"(,"frames":[{"name":")" + std::string(requested == 1 ? "reflected_value" : requested == 2 ? "twice" : "twice") + R"(","line":)" + std::to_string(requested) + R"(,"source":"input.cpp","depth":0,"cached":false}],"values":[{"name":"Result","value":")" + std::to_string(requested * 17) + R"("}],"origins":[{"source":"input.cpp","line":4,"byteColumn":31,"targetKind":"declaration","targetName":"Ready","targetSource":"input.cpp","targetLine":1,"targetByteColumn":20}]}})"); } else if (action == "step") { if (sequence < 3) { stopped(++sequence); } else { finished("completed"); return 0; } } else if (action == "continue") { finished("completed"); return 0; } else if (action == "cancel") { finished("cancelled"); return 125; } } return 0; }