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 <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2023-03-07 17:30:23 +01:00
parent 4f8ad43c1e
commit cdfe9462af
3 changed files with 11 additions and 1 deletions

View File

@@ -870,6 +870,7 @@ class Dumper(DumperBase):
self.startMode_ = args.get('startmode', 1) self.startMode_ = args.get('startmode', 1)
self.breakOnMain_ = args.get('breakonmain', 0) self.breakOnMain_ = args.get('breakonmain', 0)
self.useTerminal_ = args.get('useterminal', 0) self.useTerminal_ = args.get('useterminal', 0)
self.firstStop_ = True
pargs = self.hexdecode(args.get('processargs', '')) pargs = self.hexdecode(args.get('processargs', ''))
self.processArgs_ = pargs.split('\0') if len(pargs) else [] self.processArgs_ = pargs.split('\0') if len(pargs) else []
self.environment_ = args.get('environment', []) self.environment_ = args.get('environment', [])
@@ -930,6 +931,8 @@ class Dumper(DumperBase):
if self.startMode_ == DebuggerStartMode.AttachExternal: if self.startMode_ == DebuggerStartMode.AttachExternal:
attach_info = lldb.SBAttachInfo(self.attachPid_) attach_info = lldb.SBAttachInfo(self.attachPid_)
if self.breakOnMain_:
self.createBreakpointAtMain()
self.process = self.target.Attach(attach_info, error) self.process = self.target.Attach(attach_info, error)
if not error.Success(): if not error.Success():
self.reportState('enginerunfailed') self.reportState('enginerunfailed')
@@ -1474,6 +1477,12 @@ class Dumper(DumperBase):
self.reportState("inferiorstopok") self.reportState("inferiorstopok")
else: else:
self.reportState("stopped") 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: else:
self.reportState(self.stateName(state)) self.reportState(self.stateName(state))

View File

@@ -4,6 +4,7 @@
# Debugger start modes. Keep in sync with DebuggerStartMode in debuggerconstants.h # Debugger start modes. Keep in sync with DebuggerStartMode in debuggerconstants.h
# MT: Why does this not match (anymore?) to debuggerconstants.h : DebuggerStartMode ?
class DebuggerStartMode(): class DebuggerStartMode():
( (
NoStartMode, NoStartMode,

View File

@@ -279,8 +279,8 @@ void LldbEngine::handleLldbStarted()
? QString::fromLatin1("Attaching to %1 (%2)").arg(attachedPID).arg(attachedMainThreadID) ? QString::fromLatin1("Attaching to %1 (%2)").arg(attachedPID).arg(attachedMainThreadID)
: QString::fromLatin1("Attaching to %1").arg(attachedPID); : QString::fromLatin1("Attaching to %1").arg(attachedPID);
showMessage(msg, LogMisc); showMessage(msg, LogMisc);
cmd2.arg("startmode", DebuggerStartMode::AttachToLocalProcess);
cmd2.arg("attachpid", attachedPID); cmd2.arg("attachpid", attachedPID);
} else { } else {
cmd2.arg("startmode", rp.startMode); 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 // it is better not to check the start mode on the python sid (as we would have to duplicate the