Debugger: Make most views per-engine instead of singletons

This is a step towards properly supporting multiple debugger
sessions side-by-side.

The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.

Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.

Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.

The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.

There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.

The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.

There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.

Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2018-07-31 12:30:48 +02:00
parent d6911fd10c
commit 3b5ecac238
58 changed files with 6543 additions and 6100 deletions

View File

@@ -84,6 +84,7 @@ static int &currentToken()
LldbEngine::LldbEngine()
{
setObjectName("LldbEngine");
setDebuggerName("LLDB");
connect(action(AutoDerefPointers), &SavedAction::valueChanged,
this, &LldbEngine::updateLocals);
@@ -114,7 +115,7 @@ LldbEngine::~LldbEngine()
m_lldbProc.disconnect();
}
void LldbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages)
void LldbEngine::executeDebuggerCommand(const QString &command)
{
DebuggerCommand cmd("executeDebuggerCommand");
cmd.arg("command", command);
@@ -175,13 +176,18 @@ void LldbEngine::shutdownInferior()
void LldbEngine::shutdownEngine()
{
QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state());
m_lldbProc.kill();
notifyEngineShutdownFinished();
if (m_lldbProc.state() == QProcess::Running)
m_lldbProc.terminate();
else
notifyEngineShutdownFinished();
}
void LldbEngine::abortDebuggerProcess()
{
m_lldbProc.kill();
if (m_lldbProc.state() == QProcess::Running)
m_lldbProc.kill();
else
notifyEngineShutdownFinished();
}
void LldbEngine::setupEngine()
@@ -290,17 +296,9 @@ void LldbEngine::setupEngine()
}
cmd2.callback = [this](const DebuggerResponse &response) {
bool success = response.data["success"].toInt();
const bool success = response.data["success"].toInt();
if (success) {
for (Breakpoint bp : breakHandler()->unclaimedBreakpoints()) {
if (acceptsBreakpoint(bp)) {
bp.setEngine(this);
insertBreakpoint(bp);
} else {
showMessage(QString("BREAKPOINT %1 IN STATE %2 IS NOT ACCEPTABLE")
.arg(bp.id().toString()).arg(bp.state()));
}
}
BreakpointManager::claimBreakpointsForEngine(this);
} else {
notifyEngineSetupFailed();
}
@@ -442,7 +440,7 @@ void LldbEngine::activateFrame(int frameIndex)
QTC_ASSERT(frameIndex < handler->stackSize(), return);
handler->setCurrentIndex(frameIndex);
gotoLocation(handler->currentFrame());
gotoCurrentLocation();
DebuggerCommand cmd("activateFrame");
cmd.arg("index", frameIndex);
@@ -477,104 +475,103 @@ bool LldbEngine::stateAcceptsBreakpointChanges() const
}
}
bool LldbEngine::acceptsBreakpoint(Breakpoint bp) const
bool LldbEngine::acceptsBreakpoint(const BreakpointParameters &bp) const
{
if (runParameters().startMode == AttachCore)
return false;
if (bp.parameters().isCppBreakpoint())
if (bp.isCppBreakpoint())
return true;
return isNativeMixedEnabled();
}
void LldbEngine::insertBreakpoint(Breakpoint bp)
void LldbEngine::insertBreakpoint(const Breakpoint &bp)
{
QTC_ASSERT(bp, return);
DebuggerCommand cmd("insertBreakpoint");
cmd.callback = [this, bp](const DebuggerResponse &response) {
QTC_CHECK(bp.state() == BreakpointInsertProceeding);
QTC_CHECK(bp && bp->state() == BreakpointInsertionProceeding);
updateBreakpointData(bp, response.data, true);
};
bp.addToCommand(&cmd);
bp.notifyBreakpointInsertProceeding();
bp->addToCommand(&cmd);
notifyBreakpointInsertProceeding(bp);
runCommand(cmd);
}
void LldbEngine::changeBreakpoint(Breakpoint bp)
void LldbEngine::updateBreakpoint(const Breakpoint &bp)
{
const BreakpointResponse &response = bp.response();
QTC_ASSERT(bp, return);
DebuggerCommand cmd("changeBreakpoint");
cmd.arg("lldbid", response.id.toString());
cmd.arg("lldbid", bp->responseId());
cmd.callback = [this, bp](const DebuggerResponse &response) {
QTC_CHECK(!bp.isValid() || bp.state() == BreakpointChangeProceeding);
QTC_CHECK(bp && bp->state() == BreakpointUpdateProceeding);
updateBreakpointData(bp, response.data, false);
};
bp.addToCommand(&cmd);
bp.notifyBreakpointChangeProceeding();
bp->addToCommand(&cmd);
notifyBreakpointChangeProceeding(bp);
runCommand(cmd);
}
void LldbEngine::removeBreakpoint(Breakpoint bp)
void LldbEngine::removeBreakpoint(const Breakpoint &bp)
{
const BreakpointResponse &response = bp.response();
if (response.id.isValid()) {
QTC_ASSERT(bp, return);
if (!bp->responseId().isEmpty()) {
DebuggerCommand cmd("removeBreakpoint");
cmd.arg("lldbid", response.id.toString());
cmd.callback = [bp](const DebuggerResponse &) {
QTC_CHECK(bp.state() == BreakpointRemoveProceeding);
Breakpoint bp0 = bp;
bp0.notifyBreakpointRemoveOk();
};
bp.notifyBreakpointRemoveProceeding();
cmd.arg("lldbid", bp->responseId());
notifyBreakpointRemoveProceeding(bp);
runCommand(cmd);
// Pretend it succeeds without waiting for response. Feels better.
// Otherwise, clicking in the gutter leaves the breakpoint visible
// for quite some time, so the user assumes a mis-click and clicks
// again, effectivly re-introducing the breakpoint.
notifyBreakpointRemoveOk(bp);
}
}
void LldbEngine::updateBreakpointData(Breakpoint bp, const GdbMi &bkpt, bool added)
void LldbEngine::updateBreakpointData(const Breakpoint &bp, const GdbMi &bkpt, bool added)
{
BreakHandler *handler = breakHandler();
BreakpointResponseId rid = BreakpointResponseId(bkpt["lldbid"].data());
if (!bp.isValid())
bp = handler->findBreakpointByResponseId(rid);
BreakpointResponse response = bp.response();
QTC_ASSERT(bp, return);
QString rid = bkpt["lldbid"].data();
QTC_ASSERT(bp, return);
if (added)
response.id = rid;
QTC_CHECK(response.id == rid);
response.address = 0;
response.enabled = bkpt["enabled"].toInt();
response.ignoreCount = bkpt["ignorecount"].toInt();
response.condition = fromHex(bkpt["condition"].data());
response.hitCount = bkpt["hitcount"].toInt();
response.fileName = bkpt["file"].data();
response.lineNumber = bkpt["line"].toInt();
bp->setResponseId(rid);
QTC_CHECK(bp->responseId() == rid);
bp->setAddress(0);
bp->setEnabled(bkpt["enabled"].toInt());
bp->setIgnoreCount(bkpt["ignorecount"].toInt());
bp->setCondition(fromHex(bkpt["condition"].data()));
bp->setHitCount(bkpt["hitcount"].toInt());
bp->setFileName(bkpt["file"].data());
bp->setLineNumber(bkpt["line"].toInt());
GdbMi locations = bkpt["locations"];
const int numChild = int(locations.children().size());
if (numChild > 1) {
for (const GdbMi &location : locations.children()) {
const int locid = location["locid"].toInt();
BreakpointResponse sub;
sub.id = BreakpointResponseId(rid.majorPart(), locid);
sub.type = response.type;
sub.address = location["addr"].toAddress();
sub.functionName = location["func"].data();
sub.fileName = location["file"].data();
sub.lineNumber = location["line"].toInt();
bp.insertSubBreakpoint(sub);
const QString locid = QString("%1.%2").arg(rid).arg(location["locid"].data());
SubBreakpoint loc = bp->findOrCreateSubBreakpoint(locid);
QTC_ASSERT(loc, continue);
loc->params.type = bp->type();
loc->params.address = location["addr"].toAddress();
loc->params.functionName = location["function"].data();
loc->params.fileName = location["file"].data();
loc->params.lineNumber = location["line"].toInt();
}
response.pending = false;
bp->setPending(false);
} else if (numChild == 1) {
const GdbMi location = locations.childAt(0);
response.address = location["addr"].toAddress();
response.functionName = location["func"].data();
response.pending = false;
bp->setAddress(location["addr"].toAddress());
bp->setFunctionName(location["function"].data());
bp->setPending(false);
} else {
// This can happen for pending breakpoints.
showMessage(QString("NO LOCATIONS (YET) FOR BP %1").arg(response.toString()));
showMessage(QString("NO LOCATIONS (YET) FOR BP %1").arg(bp->parameters().toString()));
}
bp.setResponse(response);
bp->adjustMarker();
if (added)
bp.notifyBreakpointInsertOk();
notifyBreakpointInsertOk(bp);
else
bp.notifyBreakpointChangeOk();
notifyBreakpointChangeOk(bp);
}
void LldbEngine::handleOutputNotification(const GdbMi &output)
@@ -896,7 +893,7 @@ void LldbEngine::handleLocationNotification(const GdbMi &reportedLocation)
void LldbEngine::reloadRegisters()
{
if (!Internal::isRegistersWindowVisible())
if (!isRegistersWindowVisible())
return;
if (state() != InferiorStopOk && state() != InferiorUnrunnable)
@@ -1012,7 +1009,8 @@ void LldbEngine::setRegisterValue(const QString &name, const QString &value)
bool LldbEngine::hasCapability(unsigned cap) const
{
if (cap & (ReverseSteppingCapability
if (cap & (0
//| ReverseSteppingCapability
| AutoDerefPointersCapability
| DisassemblerCapability
| RegisterCapability