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:
Jorijn van der Graaf 2026-11-01 03:21:41 +01:00
commit 5d34df7afb
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 34 additions and 10 deletions

View file

@ -360,10 +360,15 @@ namespace {
const bool alive = std::ranges::any_of(env.list(), [&](const Instance& candidate) { return candidate.record.instanceId == instance->record.instanceId; });
if (!alive) {
Err() << std::format("crafter-debug: {} has exited\n", instance->record.name);
} else {
Err() << std::format("crafter-debug: cannot reach {} on port {}: {}\n", instance->record.name, instance->record.port, why);
return exitNoInstance;
}
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
@ -398,7 +403,8 @@ namespace {
void PrintAttach(bool toErr) {
std::ostream& stream = toErr ? Err() : Out();
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()) {
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);