From 3f5e79075e1b8e87494dee74cdb948aea262ab7d Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 13 Jul 2016 13:48:38 +0200 Subject: [PATCH] Debugger: Robustify GDB attaching In some cases GDB output seem to get stuck/not flushed and there is no proper ^ response in time. Force a flush by running an extra dummy command afterwards. Change-Id: I2293dcea0877572a68f37253e60f2a99c03d443f Reviewed-by: Christian Stenger --- src/plugins/debugger/gdb/attachgdbadapter.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp index aa49d6a00e6..0d372a10ac7 100644 --- a/src/plugins/debugger/gdb/attachgdbadapter.cpp +++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp @@ -35,12 +35,6 @@ namespace Debugger { namespace Internal { -/////////////////////////////////////////////////////////////////////// -// -// AttachGdbAdapter -// -/////////////////////////////////////////////////////////////////////// - GdbAttachEngine::GdbAttachEngine(const DebuggerRunParameters &startParameters) : GdbEngine(startParameters) { @@ -70,9 +64,16 @@ void GdbAttachEngine::runEngine() { QTC_ASSERT(state() == EngineRunRequested, qDebug() << state()); const qint64 pid = runParameters().attachPID; + showStatusMessage(tr("Attaching to process %1.").arg(pid)); runCommand({"attach " + QString::number(pid), NoFlags, [this](const DebuggerResponse &r) { handleAttach(r); }}); - showStatusMessage(tr("Attached to process %1.").arg(inferiorPid())); + // In some cases we get only output like + // "Could not attach to process. If your uid matches the uid of the target\n" + // "process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try\n" + // " again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf\n" + // " ptrace: Operation not permitted.\n" + // but no(!) ^ response. Use a second command to force *some* output + runCommand({"print 24", NoFlags}); } void GdbAttachEngine::handleAttach(const DebuggerResponse &response) @@ -113,6 +114,7 @@ void GdbAttachEngine::handleAttach(const DebuggerResponse &response) } } + void GdbAttachEngine::interruptInferior2() { interruptLocalInferior(runParameters().attachPID);