fix(cli): print lldb by its path, and report a held app as held
Tried on the example with the app's sandbox, two things were wrong: - `debugger` printed `flatpak enter <id> lldb -p <pid>`, and flatpak enter runs a command without the sandbox's PATH, which /app/bin is on: "Failed to execute child process lldb". It now prints the path it found, /app/bin/lldb, which attached, listed threads and detached. - With the app held by that debugger, the handshake times out, and the client said "cannot reach basic on port ..." and exited 3, no instance, though its lock said it lived. It now says the app is alive but not answering, stopped in a debugger or hung, prints how to attach, check and end it, and exits 5. Environment::haveLldb becomes lldb, the path or empty. ShouldServeOverQuic covers the second with an instance whose lock is held and whose port is silent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2c77cdcfab
commit
5d34df7afb
5 changed files with 34 additions and 10 deletions
|
|
@ -360,10 +360,15 @@ namespace {
|
||||||
const bool alive = std::ranges::any_of(env.list(), [&](const Instance& candidate) { return candidate.record.instanceId == instance->record.instanceId; });
|
const bool alive = std::ranges::any_of(env.list(), [&](const Instance& candidate) { return candidate.record.instanceId == instance->record.instanceId; });
|
||||||
if (!alive) {
|
if (!alive) {
|
||||||
Err() << std::format("crafter-debug: {} has exited\n", instance->record.name);
|
Err() << std::format("crafter-debug: {} has exited\n", instance->record.name);
|
||||||
} else {
|
return exitNoInstance;
|
||||||
Err() << std::format("crafter-debug: cannot reach {} on port {}: {}\n", instance->record.name, instance->record.port, why);
|
|
||||||
}
|
}
|
||||||
return exitNoInstance;
|
// Its lock says it lives, yet not even the handshake is
|
||||||
|
// answered: the whole process is stopped, by a debugger most
|
||||||
|
// likely, or its network threads are stuck.
|
||||||
|
Err() << std::format("crafter-debug: {} is alive but not answering on port {} ({}): stopped in a debugger, or hung.\n",
|
||||||
|
instance->record.name, instance->record.port, why);
|
||||||
|
PrintAttach(true);
|
||||||
|
return exitTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A request that got no reply. The app may be gone, stopped in a
|
// A request that got no reply. The app may be gone, stopped in a
|
||||||
|
|
@ -398,7 +403,8 @@ namespace {
|
||||||
void PrintAttach(bool toErr) {
|
void PrintAttach(bool toErr) {
|
||||||
std::ostream& stream = toErr ? Err() : Out();
|
std::ostream& stream = toErr ? Err() : Out();
|
||||||
const InstanceRecord& record = instance->record;
|
const InstanceRecord& record = instance->record;
|
||||||
const std::string debugger = env.haveLldb && env.haveLldb() ? "lldb" : "gdb";
|
const std::string lldb = env.lldb ? env.lldb() : std::string();
|
||||||
|
const std::string debugger = lldb.empty() ? std::string("gdb") : lldb;
|
||||||
if (!record.flatpakInstance.empty()) {
|
if (!record.flatpakInstance.empty()) {
|
||||||
stream << std::format(" attach (on the host): flatpak enter {} {} -p {}\n", record.flatpakInstance, debugger, record.pid);
|
stream << std::format(" attach (on the host): flatpak enter {} {} -p {}\n", record.flatpakInstance, debugger, record.pid);
|
||||||
stream << std::format(" check whether a debugger holds it: flatpak enter {} grep State /proc/{}/status (t = stopped by a tracer)\n", record.flatpakInstance, record.pid);
|
stream << std::format(" check whether a debugger holds it: flatpak enter {} grep State /proc/{}/status (t = stopped by a tracer)\n", record.flatpakInstance, record.pid);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,12 @@ int main(int argc, char** argv) {
|
||||||
{
|
{
|
||||||
Cli::Environment environment;
|
Cli::Environment environment;
|
||||||
environment.connect = Cli::ConnectQuic;
|
environment.connect = Cli::ConnectQuic;
|
||||||
environment.haveLldb = [] { return std::filesystem::exists("/app/bin/lldb") || std::filesystem::exists("/usr/bin/lldb"); };
|
environment.lldb = [] {
|
||||||
|
for (const char* path : { "/app/bin/lldb", "/usr/bin/lldb" }) {
|
||||||
|
if (std::filesystem::exists(path)) return std::string(path);
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
};
|
||||||
// Run closes its connections before it returns.
|
// Run closes its connections before it returns.
|
||||||
code = Cli::Run(args, environment);
|
code = Cli::Run(args, environment);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,10 @@ export namespace Crafter::Debug::Cli {
|
||||||
std::ostream* err = &std::cerr;
|
std::ostream* err = &std::cerr;
|
||||||
// Where a screenshot without -o goes, relative paths included.
|
// Where a screenshot without -o goes, relative paths included.
|
||||||
std::filesystem::path cwd = std::filesystem::current_path();
|
std::filesystem::path cwd = std::filesystem::current_path();
|
||||||
// Whether `lldb` exists here, for the attach command `debugger` prints.
|
// Where lldb is here, for the attach command `debugger` prints: its
|
||||||
std::function<bool()> haveLldb;
|
// absolute path, since `flatpak enter` runs a command without the
|
||||||
|
// sandbox's PATH, which /app/bin is on. Empty for none: gdb then.
|
||||||
|
std::function<std::string()> lldb;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::int32_t Run(std::span<const std::string_view> args, Environment& environment);
|
std::int32_t Run(std::span<const std::string_view> args, Environment& environment);
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace {
|
||||||
environment.out = &out;
|
environment.out = &out;
|
||||||
environment.err = &err;
|
environment.err = &err;
|
||||||
environment.cwd = fs::temp_directory_path() / "crafter-debug-ShouldRunClientCommands";
|
environment.cwd = fs::temp_directory_path() / "crafter-debug-ShouldRunClientCommands";
|
||||||
environment.haveLldb = [] { return false; };
|
environment.lldb = [] { return std::string(); };
|
||||||
const std::int32_t code = Cli::Run(args, environment);
|
const std::int32_t code = Cli::Run(args, environment);
|
||||||
return { code, out.str(), err.str() };
|
return { code, out.str(), err.str() };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,9 @@
|
||||||
// connections, each get their own reply;
|
// connections, each get their own reply;
|
||||||
// - destroying the Session answers a waiting follower and closes promptly
|
// - destroying the Session answers a waiting follower and closes promptly
|
||||||
// with a client still connected, and a client then finds the port dead
|
// with a client still connected, and a client then finds the port dead
|
||||||
// within seconds.
|
// within seconds;
|
||||||
|
// - an instance alive by its lock but silent at its port, as one a
|
||||||
|
// debugger holds, is reported as such with how to attach, not as gone.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
import std;
|
import std;
|
||||||
|
|
@ -58,7 +60,7 @@ namespace {
|
||||||
environment.connect = Cli::ConnectQuic;
|
environment.connect = Cli::ConnectQuic;
|
||||||
environment.out = &out;
|
environment.out = &out;
|
||||||
environment.err = &err;
|
environment.err = &err;
|
||||||
environment.haveLldb = [] { return false; };
|
environment.lldb = [] { return std::string(); };
|
||||||
const std::int32_t code = Cli::Run(args, environment);
|
const std::int32_t code = Cli::Run(args, environment);
|
||||||
return { code, out.str(), err.str() };
|
return { code, out.str(), err.str() };
|
||||||
}
|
}
|
||||||
|
|
@ -259,6 +261,15 @@ int main() {
|
||||||
Check(!reply && reply.error().kind == Cli::CallError::Kind::Unreachable && deadTook < 5s,
|
Check(!reply && reply.error().kind == Cli::CallError::Kind::Unreachable && deadTook < 5s,
|
||||||
std::format("a client finds the port dead in {} ms", std::chrono::duration_cast<std::chrono::milliseconds>(deadTook).count()));
|
std::format("a client finds the port dead in {} ms", std::chrono::duration_cast<std::chrono::milliseconds>(deadTook).count()));
|
||||||
|
|
||||||
|
// Alive by its lock, with nothing answering at its port: what a client
|
||||||
|
// sees of an app a debugger holds.
|
||||||
|
{
|
||||||
|
const Registration stopped(InstanceRecord{ .name = "held", .port = record.port, .token = "t", .protocol = protocolVersion, .sourceId = std::string(Detail::SourceId()) });
|
||||||
|
const Ran held = Run({ "status" });
|
||||||
|
Check(held.code == 5 && Has(held.err, "alive but not answering") && Has(held.err, "attach"),
|
||||||
|
std::format("an app alive but silent is reported as held, with how to attach (exit {}: {})", held.code, held.err));
|
||||||
|
}
|
||||||
|
|
||||||
std::fflush(stdout);
|
std::fflush(stdout);
|
||||||
std::_Exit(failures == 0 ? 0 : 1);
|
std::_Exit(failures == 0 ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue