[lldb-dev] Unreliable process attach on Linux
Florian Weimer via lldb-dev
lldb-dev at lists.llvm.org
Fri Jan 4 08:38:42 PST 2019
Consider this example program:
#include <err.h>
#include <sys/wait.h>
#include <unistd.h>
#include <lldb/API/SBDebugger.h>
#include <lldb/API/SBProcess.h>
#include <lldb/API/SBTarget.h>
int
main(void)
{
// Target process for the debugger.
pid_t pid = fork();
if (pid < 0)
err(1, "fork");
if (pid == 0)
while (true)
pause();
lldb::SBDebugger::Initialize();
{
auto debugger(lldb::SBDebugger::Create());
if (!debugger.IsValid())
errx(1, "SBDebugger::Create failed");
auto target(debugger.CreateTarget(nullptr));
if (!target.IsValid())
errx(1, "SBDebugger::CreateTarget failed");
lldb::SBAttachInfo attachinfo(pid);
lldb::SBError error;
auto process(target.Attach(attachinfo, error));
if (!process.IsValid())
errx(1, "SBTarget::Attach failed: %s", error.GetCString());
error = process.Detach();
if (error.Fail())
errx(1, "SBProcess::Detach failed: %s", error.GetCString());
}
lldb::SBDebugger::Terminate();
if (kill(pid, SIGKILL) != 0)
err(1, "kill");
if (waitpid(pid, NULL, 0) < 0)
err(1, "waitpid");
return 0;
}
Run it in a loop like this:
$ while ./test-attach ; do date; done
On Linux x86-64 (Fedora 29), with LLDB 7 (lldb-7.0.0-1.fc29.x86_64) and
kernel 4.19.12 (kernel-4.19.12-301.fc29.x86_64), after 100 iterations or
so, attaching to the newly created process fails:
test-attach: SBTarget::Attach failed: lost connection
This also reproduces occasionally with LLDB itself (with “lldb -p PID”).
Any suggestions how to get more information about the cause of this
error?
Thanks,
Florian
More information about the lldb-dev
mailing list