Commit 5f38a26c authored by hjk's avatar hjk

debugger: fix 'Jump To/Run to' when in instruction-wise mode

parent cd18b3ce
......@@ -172,20 +172,10 @@ struct MemoryViewCookie
quint64 length;
};
struct SourceLocationCookie
{
explicit SourceLocationCookie(const QString &f = QString(), int l = 0) :
fileName(f), lineNumber(l) {}
QString fileName;
int lineNumber;
};
} // namespace Internal
} // namespace Debugger
Q_DECLARE_METATYPE(Debugger::Internal::MemoryViewCookie)
Q_DECLARE_METATYPE(Debugger::Internal::SourceLocationCookie)
namespace Debugger {
namespace Internal {
......@@ -1070,12 +1060,12 @@ void CdbEngine::doInterruptInferior(SpecialStopMode sm)
#endif
}
void CdbEngine::executeRunToLine(const QString &fileName, int lineNumber)
void CdbEngine::executeRunToLine(const ContextData &data)
{
// Add one-shot breakpoint
BreakpointParameters bp(BreakpointByFileAndLine);
bp.fileName = fileName;
bp.lineNumber = lineNumber;
bp.fileName = data.fileName;
bp.lineNumber = data.lineNumber;
postCommand(cdbAddBreakpointCommand(bp, BreakpointId(-1), true), 0);
continueInferior();
}
......@@ -1102,13 +1092,13 @@ void CdbEngine::setRegisterValue(int regnr, const QString &value)
reloadRegisters();
}
void CdbEngine::executeJumpToLine(const QString & fileName, int lineNumber)
void CdbEngine::executeJumpToLine(const ContextData &data)
{
QByteArray cmd;
ByteArrayInputStream str(cmd);
// Resolve source line address and go to that location
str << "? `" << QDir::toNativeSeparators(fileName) << ':' << lineNumber << '`';
const QVariant cookie = qVariantFromValue(SourceLocationCookie(fileName, lineNumber));
str << "? `" << QDir::toNativeSeparators(data.fileName) << ':' << data.lineNumber << '`';
const QVariant cookie = qVariantFromValue(data);
postBuiltinCommand(cmd, 0, &CdbEngine::handleJumpToLineAddressResolution, 0, cookie);
}
......@@ -1123,8 +1113,8 @@ void CdbEngine::handleJumpToLineAddressResolution(const CdbBuiltinCommandPtr &cm
if (equalPos == -1)
return;
answer.remove(0, equalPos + 3);
QTC_ASSERT(qVariantCanConvert<SourceLocationCookie>(cmd->cookie), return ; )
const SourceLocationCookie cookie = qvariant_cast<SourceLocationCookie>(cmd->cookie);
QTC_ASSERT(qVariantCanConvert<ContextData>(cmd->cookie), return);
const ContextData cookie = qvariant_cast<ContextData>(cmd->cookie);
QByteArray registerCmd;
ByteArrayInputStream str(registerCmd);
......
......@@ -108,9 +108,9 @@ public:
virtual void continueInferior();
virtual void interruptInferior();
virtual void executeRunToLine(const QString &fileName, int lineNumber);
virtual void executeRunToLine(const ContextData &data);
virtual void executeRunToFunction(const QString &functionName);
virtual void executeJumpToLine(const QString &fileName, int lineNumber);
virtual void executeJumpToLine(const ContextData &data);
virtual void assignValueInDebugger(const WatchData *w, const QString &expr, const QVariant &value);
virtual void executeDebuggerCommand(const QString &command);
......
......@@ -1458,7 +1458,7 @@ void DebuggerEngine::interruptInferior()
{
}
void DebuggerEngine::executeRunToLine(const QString &, int)
void DebuggerEngine::executeRunToLine(const ContextData &)
{
}
......@@ -1466,7 +1466,7 @@ void DebuggerEngine::executeRunToFunction(const QString &)
{
}
void DebuggerEngine::executeJumpToLine(const QString &, int)
void DebuggerEngine::executeJumpToLine(const ContextData &)
{
}
......
......@@ -121,6 +121,17 @@ private:
quint64 m_address;
};
class ContextData
{
public:
ContextData() : lineNumber(0), address(0) {}
public:
QString fileName;
int lineNumber;
quint64 address;
};
} // namespace Internal
......@@ -323,9 +334,9 @@ protected:
virtual void interruptInferior();
virtual void requestInterruptInferior();
virtual void executeRunToLine(const QString &fileName, int lineNumber);
virtual void executeRunToLine(const Internal::ContextData &data);
virtual void executeRunToFunction(const QString &functionName);
virtual void executeJumpToLine(const QString &fileName, int lineNumber);
virtual void executeJumpToLine(const Internal::ContextData &data);
virtual void executeDebuggerCommand(const QString &command);
virtual void frameUp();
......@@ -374,4 +385,6 @@ private:
} // namespace Debugger
Q_DECLARE_METATYPE(Debugger::Internal::ContextData)
#endif // DEBUGGER_DEBUGGERENGINE_H
......@@ -530,22 +530,25 @@ private:
//
///////////////////////////////////////////////////////////////////////
class ContextData
static TextEditor::ITextEditor *currentTextEditor()
{
public:
ContextData() : lineNumber(0), address(0) {}
public:
QString fileName;
int lineNumber;
quint64 address;
};
} // namespace Internal
} // namespace Debugger
Q_DECLARE_METATYPE(Debugger::Internal::ContextData)
if (const Core::EditorManager *editorManager = Core::EditorManager::instance())
if (Core::IEditor *editor = editorManager->currentEditor())
return qobject_cast<TextEditor::ITextEditor*>(editor);
return 0;
}
static bool currentTextEditorPosition(ContextData *data)
{
if (TextEditor::ITextEditor *textEditor = currentTextEditor()) {
if (const Core::IFile *file = textEditor->file()) {
data->fileName = file->fileName();
data->lineNumber = textEditor->currentLine();
return true;
}
}
return false;
}
///////////////////////////////////////////////////////////////////////
//
......@@ -553,9 +556,6 @@ Q_DECLARE_METATYPE(Debugger::Internal::ContextData)
//
///////////////////////////////////////////////////////////////////////
namespace Debugger {
namespace Internal {
static DebuggerPluginPrivate *theDebuggerCore = 0;
/*!
......@@ -817,20 +817,18 @@ public slots:
{
//removeTooltip();
currentEngine()->resetLocation();
QString fileName;
int lineNumber;
if (currentTextEditorPosition(&fileName, &lineNumber))
currentEngine()->executeJumpToLine(fileName, lineNumber);
ContextData data;
if (currentTextEditorPosition(&data))
currentEngine()->executeJumpToLine(data);
}
void handleExecRunToLine()
{
//removeTooltip();
currentEngine()->resetLocation();
QString fileName;
int lineNumber;
if (currentTextEditorPosition(&fileName, &lineNumber))
currentEngine()->executeRunToLine(fileName, lineNumber);
ContextData data;
if (currentTextEditorPosition(&data))
currentEngine()->executeRunToLine(data);
}
void handleExecRunToSelectedFunction()
......@@ -883,7 +881,7 @@ public slots:
const QAction *action = qobject_cast<const QAction *>(sender());
QTC_ASSERT(action, return);
const ContextData data = action->data().value<ContextData>();
currentEngine()->executeRunToLine(data.fileName, data.lineNumber);
currentEngine()->executeRunToLine(data);
}
void slotJumpToLine()
......@@ -891,7 +889,7 @@ public slots:
const QAction *action = qobject_cast<const QAction *>(sender());
QTC_ASSERT(action, return);
const ContextData data = action->data().value<ContextData>();
currentEngine()->executeJumpToLine(data.fileName, data.lineNumber);
currentEngine()->executeJumpToLine(data);
}
void handleAddToWatchWindow()
......@@ -1619,6 +1617,7 @@ void DebuggerPluginPrivate::requestContextMenu(ITextEditor *editor,
ContextData args;
args.lineNumber = lineNumber;
bool contextUsable = true;
BreakpointId id = BreakpointId();
if (editor->property("DisassemblerView").toBool()) {
......@@ -1631,6 +1630,7 @@ void DebuggerPluginPrivate::requestContextMenu(ITextEditor *editor,
args.address = needle.address;
needle.lineNumber = -1;
id = breakHandler()->findSimilarBreakpoint(needle);
contextUsable = args.address != 0;
} else {
args.fileName = editor->file()->fileName();
id = breakHandler()
......@@ -1668,27 +1668,30 @@ void DebuggerPluginPrivate::requestContextMenu(ITextEditor *editor,
menu->addAction(act);
} else {
// Handle non-existing breakpoint.
const QString text = args.address ?
tr("Set Breakpoint at 0x%1").arg(args.address, 0, 16) :
tr("Set Breakpoint at line %1").arg(lineNumber);
const QString text = args.address
? tr("Set Breakpoint at 0x%1").arg(args.address, 0, 16)
: tr("Set Breakpoint at line %1").arg(lineNumber);
QAction *act = new QAction(text, menu);
act->setData(QVariant::fromValue(args));
act->setEnabled(contextUsable);
connect(act, SIGNAL(triggered()),
SLOT(breakpointSetMarginActionTriggered()));
menu->addAction(act);
}
// Run to, jump to line below in stopped state.
if (currentEngine()->state() == InferiorStopOk) {
if (currentEngine()->state() == InferiorStopOk && contextUsable) {
menu->addSeparator();
const QString runText =
DebuggerEngine::tr("Run to Line %1").arg(lineNumber);
const QString runText = args.address
? DebuggerEngine::tr("Run to Address 0x%1").arg(args.address, 0, 16)
: DebuggerEngine::tr("Run to Line %1").arg(args.lineNumber);
QAction *runToLineAction = new QAction(runText, menu);
runToLineAction->setData(QVariant::fromValue(args));
connect(runToLineAction, SIGNAL(triggered()), SLOT(slotRunToLine()));
menu->addAction(runToLineAction);
if (currentEngine()->debuggerCapabilities() & JumpToLineCapability) {
const QString jumpText =
DebuggerEngine::tr("Jump to Line %1").arg(lineNumber);
const QString jumpText = args.address
? DebuggerEngine::tr("Jump to Address 0x%1").arg(args.address, 0, 16)
: DebuggerEngine::tr("Jump to Line %1").arg(args.lineNumber);
QAction *jumpToLineAction = new QAction(jumpText, menu);
menu->addAction(runToLineAction);
jumpToLineAction->setData(QVariant::fromValue(args));
......
......@@ -132,6 +132,7 @@ static bool readStartElement(QXmlStreamReader &r, const char *name)
return true;
}
#if 0
static void debugMode(const QAbstractItemModel *model)
{
QDebug nospace = qDebug().nospace();
......@@ -139,6 +140,7 @@ static void debugMode(const QAbstractItemModel *model)
for (int r = 0; r < model->rowCount(); r++)
nospace << '#' << r << ' ' << model->data(model->index(r, 0)).toString() << '\n';
}
#endif
namespace Debugger {
namespace Internal {
......
......@@ -2015,17 +2015,26 @@ void GdbEngine::executeNextI()
postCommand("-exec-next-instruction", RunRequest, CB(handleExecuteContinue));
}
void GdbEngine::executeRunToLine(const QString &fileName, int lineNumber)
static QByteArray addressSpec(quint64 address)
{
return "*0x" + QByteArray::number(address, 16);
}
void GdbEngine::executeRunToLine(const ContextData &data)
{
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
setTokenBarrier();
notifyInferiorRunRequested();
showStatusMessage(tr("Run to line %1 requested...").arg(lineNumber), 5000);
showStatusMessage(tr("Run to line %1 requested...").arg(data.lineNumber), 5000);
#if 1
m_targetFrame.file = fileName;
m_targetFrame.line = lineNumber;
QByteArray loc = '"' + breakLocation(fileName).toLocal8Bit() + '"' + ':'
+ QByteArray::number(lineNumber);
m_targetFrame.file = data.fileName;
m_targetFrame.line = data.lineNumber;
QByteArray loc;
if (data.address)
loc = addressSpec(data.address);
else
loc = '"' + breakLocation(data.fileName).toLocal8Bit() + '"' + ':'
+ QByteArray::number(data.lineNumber);
postCommand("tbreak " + loc);
postCommand("continue", RunRequest, CB(handleExecuteRunToLine));
#else
......@@ -2046,15 +2055,15 @@ void GdbEngine::executeRunToFunction(const QString &functionName)
continueInferiorInternal();
}
void GdbEngine::executeJumpToLine(const QString &fileName, int lineNumber)
void GdbEngine::executeJumpToLine(const ContextData &data)
{
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
StackFrame frame;
frame.file = fileName;
frame.line = lineNumber;
#if 1
QByteArray loc = '"' + breakLocation(fileName).toLocal8Bit() + '"' + ':'
+ QByteArray::number(lineNumber);
QByteArray loc;
if (data.address)
loc = addressSpec(data.address);
else
loc = '"' + breakLocation(data.fileName).toLocal8Bit() + '"' + ':'
+ QByteArray::number(data.lineNumber);
postCommand("tbreak " + loc);
notifyInferiorRunRequested();
postCommand("jump " + loc, RunRequest, CB(handleExecuteJumpToLine));
......@@ -2064,15 +2073,6 @@ void GdbEngine::executeJumpToLine(const QString &fileName, int lineNumber)
// ~"run1 (argc=1, argv=0x7fffbf1f5538) at test1.cpp:242"
// ~"242\t x *= 2;"
// 23^done"
gotoLocation(frame);
//setBreakpoint();
//postCommand("jump " + loc);
#else
gotoLocation(frame);
setBreakpoint(fileName, lineNumber);
notifyInferiorRunRequested();
postCommand("jump " + loc, RunRequest);
#endif
}
void GdbEngine::executeReturn()
......@@ -2220,11 +2220,6 @@ QString GdbEngine::breakLocation(const QString &file) const
return where;
}
static QByteArray addressSpec(quint64 address)
{
return "*0x" + QByteArray::number(address, 16);
}
QByteArray GdbEngine::breakpointLocation(BreakpointId id)
{
BreakHandler *handler = breakHandler();
......
......@@ -333,9 +333,9 @@ private: ////////// Inferior Management //////////
void interruptInferior();
void interruptInferiorTemporarily();
void executeRunToLine(const QString &fileName, int lineNumber);
void executeRunToLine(const ContextData &data);
void executeRunToFunction(const QString &functionName);
void executeJumpToLine(const QString &fileName, int lineNumber);
void executeJumpToLine(const ContextData &data);
void executeReturn();
void handleExecuteContinue(const GdbResponse &response);
......
......@@ -285,13 +285,12 @@ void LldbEngineGuest::interruptInferior()
updateThreads();
}
void LldbEngineGuest::executeRunToLine(const QString &fileName, int lineNumber)
void LldbEngineGuest::executeRunToLine(const ContextData &data);
{
DEBUG_FUNC_ENTER;
// TODO
Q_UNUSED(fileName);
Q_UNUSED(lineNumber);
Q_UNUSED(data);
}
void LldbEngineGuest::executeRunToFunction(const QString &functionName)
......@@ -301,13 +300,12 @@ void LldbEngineGuest::executeRunToFunction(const QString &functionName)
// TODO
Q_UNUSED(functionName);
}
void LldbEngineGuest::executeJumpToLine(const QString &fileName, int lineNumber)
void LldbEngineGuest::executeJumpToLine(const ContextData &data);
{
DEBUG_FUNC_ENTER;
// TODO
Q_UNUSED(fileName);
Q_UNUSED(lineNumber);
Q_UNUSED(data);
}
void LldbEngineGuest::activateFrame(qint64 token)
......
......@@ -89,9 +89,9 @@ public:
void executeNextI();
void continueInferior();
void interruptInferior();
void executeRunToLine(const QString &fileName, int lineNumber);
void executeRunToLine(const ContextData &data);
void executeRunToFunction(const QString &functionName);
void executeJumpToLine(const QString &fileName, int lineNumber);
void executeJumpToLine(const ContextData &data);
void activateFrame(qint64);
void selectThread(qint64);
void disassemble(quint64 pc);
......
......@@ -224,11 +224,10 @@ void IPCEngineGuest::rpcCallback(quint64 f, QByteArray payload)
{
QDataStream s(payload);
SET_NATIVE_BYTE_ORDER(s);
QString fileName;
quint64 lineNumber;
s >> fileName;
s >> lineNumber;
executeRunToLine(fileName, lineNumber);
ContextData data;
s >> data.fileName;
s >> data.lineNumber;
executeRunToLine(data);
}
break;
case IPCEngineHost::ExecuteRunToFunction:
......@@ -244,11 +243,10 @@ void IPCEngineGuest::rpcCallback(quint64 f, QByteArray payload)
{
QDataStream s(payload);
SET_NATIVE_BYTE_ORDER(s);
QString fileName;
quint64 lineNumber;
s >> fileName;
s >> lineNumber;
executeJumpToLine(fileName, lineNumber);
ContextData data;
s >> data.fileName;
s >> data.lineNumber;
executeJumpToLine(data);
}
break;
case IPCEngineHost::ActivateFrame:
......
......@@ -74,9 +74,9 @@ public:
virtual void executeNextI() = 0;
virtual void continueInferior() = 0;
virtual void interruptInferior() = 0;
virtual void executeRunToLine(const QString &fileName, int lineNumber) = 0;
virtual void executeRunToLine(const ContextData &data) = 0;
virtual void executeRunToFunction(const QString &functionName) = 0;
virtual void executeJumpToLine(const QString &fileName, int lineNumber) = 0;
virtual void executeJumpToLine(const ContextData &data) = 0;
virtual void activateFrame(qint64 token) = 0;
virtual void selectThread(qint64 token) = 0;
virtual void disassemble(quint64 pc) = 0;
......
......@@ -177,14 +177,14 @@ void IPCEngineHost::interruptInferior()
rpcCall(InterruptInferior);
}
void IPCEngineHost::executeRunToLine(const QString &fileName, int lineNumber)
void IPCEngineHost::executeRunToLine(const ContextData &data)
{
QByteArray p;
{
QDataStream s(&p, QIODevice::WriteOnly);
SET_NATIVE_BYTE_ORDER(s);
s << fileName;
s << quint64(lineNumber);
s << data.fileName;
s << quint64(data.lineNumber);
}
rpcCall(ExecuteRunToLine, p);
}
......@@ -200,14 +200,14 @@ void IPCEngineHost::executeRunToFunction(const QString &functionName)
rpcCall(ExecuteRunToFunction, p);
}
void IPCEngineHost::executeJumpToLine(const QString &fileName, int lineNumber)
void IPCEngineHost::executeJumpToLine(const ContextData &data)
{
QByteArray p;
{
QDataStream s(&p, QIODevice::WriteOnly);
SET_NATIVE_BYTE_ORDER(s);
s << fileName;
s << quint64(lineNumber);
s << data.fileName;
s << quint64(data.lineNumber);
}
rpcCall(ExecuteJumpToLine, p);
}
......
......@@ -104,9 +104,9 @@ public:
void executeNextI();
void continueInferior();
void interruptInferior();
void executeRunToLine(const QString &fileName, int lineNumber);
void executeRunToLine(const ContextData &data);
void executeRunToFunction(const QString &functionName);
void executeJumpToLine(const QString &fileName, int lineNumber);
void executeJumpToLine(const ContextData &data);
void activateFrame(int index);
void selectThread(int index);
void fetchDisassembler(DisassemblerAgent *);
......
......@@ -280,10 +280,9 @@ void PdbEngine::continueInferior()
postCommand("continue", CB(handleUpdateAll));
}
void PdbEngine::executeRunToLine(const QString &fileName, int lineNumber)
void PdbEngine::executeRunToLine(const ContextData &data)
{
Q_UNUSED(fileName)
Q_UNUSED(lineNumber)
Q_UNUSED(data)
SDEBUG("FIXME: PdbEngine::runToLineExec()");
}
......@@ -293,10 +292,9 @@ void PdbEngine::executeRunToFunction(const QString &functionName)
XSDEBUG("FIXME: PdbEngine::runToFunctionExec()");
}
void PdbEngine::executeJumpToLine(const QString &fileName, int lineNumber)
void PdbEngine::executeJumpToLine(const ContextData &data)
{
Q_UNUSED(fileName)
Q_UNUSED(lineNumber)
Q_UNUSED(data)
XSDEBUG("FIXME: PdbEngine::jumpToLineExec()");
}
......
......@@ -85,9 +85,9 @@ private:
void continueInferior();
void interruptInferior();
void executeRunToLine(const QString &fileName, int lineNumber);
void executeRunToLine(const ContextData &data);
void executeRunToFunction(const QString &functionName);
void executeJumpToLine(const QString &fileName, int lineNumber);
void executeJumpToLine(const ContextData &data);
void activateFrame(int index);
void selectThread(int index);
......
......@@ -384,9 +384,9 @@ void QmlCppEngine::requestInterruptInferior()
d->m_cppEngine->requestInterruptInferior();
}
void QmlCppEngine::executeRunToLine(const QString &fileName, int lineNumber)
void QmlCppEngine::executeRunToLine(const ContextData &data)
{
d->m_activeEngine->executeRunToLine(fileName, lineNumber);
d->m_activeEngine->executeRunToLine(data);
}
void QmlCppEngine::executeRunToFunction(const QString &functionName)
......@@ -394,9 +394,9 @@ void QmlCppEngine::executeRunToFunction(const QString &functionName)
d->m_activeEngine->executeRunToFunction(functionName);
}
void QmlCppEngine::executeJumpToLine(const QString &fileName, int lineNumber)
void QmlCppEngine::executeJumpToLine(const ContextData &data)
{
d->m_activeEngine->executeJumpToLine(fileName, lineNumber);
d->m_activeEngine->executeJumpToLine(data);
}
void QmlCppEngine::executeDebuggerCommand(const QString &command)
......
......@@ -103,9 +103,9 @@ protected:
void interruptInferior();
void requestInterruptInferior();
void executeRunToLine(const QString &fileName, int lineNumber);
void executeRunToLine(const ContextData &data);
void executeRunToFunction(const QString &functionName);
void executeJumpToLine(const QString &fileName, int lineNumber);
void executeJumpToLine(const ContextData &data);
void executeDebuggerCommand(const QString &command);
void setupEngine();
......
......@@ -449,10 +449,9 @@ void QmlEngine::executeNextI()
SDEBUG("QmlEngine::executeNextI()");
}