From cdfe9462af3b8fec912fe26ec9cc56d6f1e35768 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 7 Mar 2023 17:30:23 +0100 Subject: [PATCH] Debugger: Fix "Run in Terminal" with lldb Previously lldb never actually attached to the process running in the terminal, but started its own copy. Since the process is interrupted by the terminal stub already, code was added to automatically continue the process. "Start and break on main" and "Run in Terminal" also did not work together and are now fixed. Change-Id: Iaeb6e7dd0f511f3bf195ab5d0008856b310615d9 Reviewed-by: hjk Reviewed-by: --- share/qtcreator/debugger/lldbbridge.py | 9 +++++++++ share/qtcreator/debugger/utils.py | 1 + src/plugins/debugger/lldb/lldbengine.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/share/qtcreator/debugger/lldbbridge.py b/share/qtcreator/debugger/lldbbridge.py index 8a97e642970..bef97482af6 100644 --- a/share/qtcreator/debugger/lldbbridge.py +++ b/share/qtcreator/debugger/lldbbridge.py @@ -870,6 +870,7 @@ class Dumper(DumperBase): self.startMode_ = args.get('startmode', 1) self.breakOnMain_ = args.get('breakonmain', 0) self.useTerminal_ = args.get('useterminal', 0) + self.firstStop_ = True pargs = self.hexdecode(args.get('processargs', '')) self.processArgs_ = pargs.split('\0') if len(pargs) else [] self.environment_ = args.get('environment', []) @@ -930,6 +931,8 @@ class Dumper(DumperBase): if self.startMode_ == DebuggerStartMode.AttachExternal: attach_info = lldb.SBAttachInfo(self.attachPid_) + if self.breakOnMain_: + self.createBreakpointAtMain() self.process = self.target.Attach(attach_info, error) if not error.Success(): self.reportState('enginerunfailed') @@ -1474,6 +1477,12 @@ class Dumper(DumperBase): self.reportState("inferiorstopok") else: self.reportState("stopped") + if self.firstStop_: + self.firstStop_ = False + if self.useTerminal_: + # When using a terminal, the process will be interrupted on startup. + # We therefore need to continue it here. + self.process.Continue() else: self.reportState(self.stateName(state)) diff --git a/share/qtcreator/debugger/utils.py b/share/qtcreator/debugger/utils.py index fe2e558e711..8019d1e530a 100644 --- a/share/qtcreator/debugger/utils.py +++ b/share/qtcreator/debugger/utils.py @@ -4,6 +4,7 @@ # Debugger start modes. Keep in sync with DebuggerStartMode in debuggerconstants.h +# MT: Why does this not match (anymore?) to debuggerconstants.h : DebuggerStartMode ? class DebuggerStartMode(): ( NoStartMode, diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp index 020c9e7758b..5de46911576 100644 --- a/src/plugins/debugger/lldb/lldbengine.cpp +++ b/src/plugins/debugger/lldb/lldbengine.cpp @@ -279,8 +279,8 @@ void LldbEngine::handleLldbStarted() ? QString::fromLatin1("Attaching to %1 (%2)").arg(attachedPID).arg(attachedMainThreadID) : QString::fromLatin1("Attaching to %1").arg(attachedPID); showMessage(msg, LogMisc); + cmd2.arg("startmode", DebuggerStartMode::AttachToLocalProcess); cmd2.arg("attachpid", attachedPID); - } else { cmd2.arg("startmode", rp.startMode); // it is better not to check the start mode on the python sid (as we would have to duplicate the