summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-11-15 13:33:40 +0100
committerhjk <hjk121@nokiamail.com>2014-11-15 13:37:12 +0100
commit82268eb77c367981c77bbf34c3278ed81f9757db (patch)
tree9e3565611190480e9d5895532437a1dd7f5ad1a5 /src
parent9f6f2e7a0e38cdd2bd0f9abc6bba41e93c4db7cd (diff)
downloadqt-creator-82268eb77c367981c77bbf34c3278ed81f9757db.tar.gz
Debugger: Use line information to find matching scopes for tooltips
More robust to variations in tool chains than function names. (e.g. GDB reports 'foo' and LLDB 'foo()') Change-Id: I1e5a3273b571658b4dd4200c9b3a0e9542a16015 Reviewed-by: hjk <hjk121@nokiamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/debugger/debuggertooltipmanager.cpp45
-rw-r--r--src/plugins/debugger/debuggertooltipmanager.h8
-rw-r--r--src/plugins/debugger/sourceutils.cpp23
-rw-r--r--src/plugins/debugger/sourceutils.h3
4 files changed, 40 insertions, 39 deletions
diff --git a/src/plugins/debugger/debuggertooltipmanager.cpp b/src/plugins/debugger/debuggertooltipmanager.cpp
index b25dad17e3..d6ebc3711d 100644
--- a/src/plugins/debugger/debuggertooltipmanager.cpp
+++ b/src/plugins/debugger/debuggertooltipmanager.cpp
@@ -726,7 +726,7 @@ public:
void positionShow(const TextEditorWidget *editorWidget);
void handleItemIsExpanded(const QModelIndex &sourceIdx);
- void updateTooltip(const QString &frameFile, const QString &frameFunction);
+ void updateTooltip(const StackFrame &frame);
void setState(State newState);
@@ -769,7 +769,7 @@ void DebuggerToolTipHolder::handleItemIsExpanded(const QModelIndex &sourceIdx)
*/
DebuggerToolTipContext::DebuggerToolTipContext()
- : position(0), line(0), column(0)
+ : position(0), line(0), column(0), scopeFromLine(0), scopeToLine(0)
{
}
@@ -780,25 +780,26 @@ static bool filesMatch(const QString &file1, const QString &file2)
return f1.canonicalFilePath() == f2.canonicalFilePath();
}
-bool DebuggerToolTipContext::matchesFrame(const QString &frameFile, const QString &frameFunction) const
+bool DebuggerToolTipContext::matchesFrame(const StackFrame &frame) const
{
- return (fileName.isEmpty() || frameFile.isEmpty() || filesMatch(fileName, frameFile))
- && (function.isEmpty() || frameFunction.isEmpty() || function == frameFunction);
+ return (fileName.isEmpty() || frame.file.isEmpty() || filesMatch(fileName, frame.file))
+ //&& (function.isEmpty() || frame.function.isEmpty() || function == frame.function);
+ && (frame.line <= 0 || (scopeFromLine <= frame.line && frame.line <= scopeToLine));
}
bool DebuggerToolTipContext::isSame(const DebuggerToolTipContext &other) const
{
return filesMatch(fileName, other.fileName)
- && function == other.function
+ && scopeFromLine == other.scopeFromLine
+ && scopeToLine == other.scopeToLine
&& iname == other.iname;
}
QDebug operator<<(QDebug d, const DebuggerToolTipContext &c)
{
QDebug nsp = d.nospace();
- nsp << c.fileName << '@' << c.line << ',' << c.column << " (" << c.position << ')' << "INAME: " << c.iname << " EXP: " << c.expression;
- if (!c.function.isEmpty())
- nsp << ' ' << c.function << "()";
+ nsp << c.fileName << '@' << c.line << ',' << c.column << " (" << c.position << ')'
+ << "INAME: " << c.iname << " EXP: " << c.expression << " FUNCTION: " << c.function;
return d;
}
@@ -868,9 +869,9 @@ DebuggerToolTipHolder::~DebuggerToolTipHolder()
delete widget; widget.clear();
}
-void DebuggerToolTipHolder::updateTooltip(const QString &frameFile, const QString &frameFunction)
+void DebuggerToolTipHolder::updateTooltip(const StackFrame &frame)
{
- const bool sameFrame = context.matchesFrame(frameFile, frameFunction);
+ const bool sameFrame = context.matchesFrame(frame);
DEBUG("UPDATE TOOLTIP: STATE " << state << context.iname
<< "PINNED: " << widget->isPinned << "SAME FRAME: " << sameFrame);
@@ -1197,18 +1198,9 @@ void DebuggerToolTipManager::updateEngine(DebuggerEngine *engine)
// Stack frame changed: All tooltips of that file acquire the engine,
// all others release (arguable, this could be more precise?)
- QString fileName;
- QString function;
- const int index = engine->stackHandler()->currentIndex();
- if (index >= 0) {
- const StackFrame frame = engine->stackHandler()->currentFrame();
- if (frame.usable) {
- fileName = frame.file;
- function = frame.function;
- }
- }
+ StackFrame frame = engine->stackHandler()->currentFrame();
foreach (DebuggerToolTipHolder *tooltip, m_tooltips)
- tooltip->updateTooltip(fileName, function);
+ tooltip->updateTooltip(frame);
slotUpdateVisibleToolTips(); // Move tooltip when stepping in same file.
}
@@ -1321,7 +1313,8 @@ static void slotTooltipOverrideRequested
context.position = pos;
context.mousePosition = point;
editorWidget->convertPosition(pos, &context.line, &context.column);
- QString raw = cppExpressionAt(editorWidget, context.position, &context.line, &context.column, &context.function);
+ QString raw = cppExpressionAt(editorWidget, context.position, &context.line, &context.column,
+ &context.function, &context.scopeFromLine, &context.scopeToLine);
context.expression = fixCppExpression(raw);
if (context.expression.isEmpty()) {
@@ -1426,9 +1419,9 @@ DebuggerToolTipContexts DebuggerToolTipManager::pendingTooltips(DebuggerEngine *
StackFrame frame = engine->stackHandler()->currentFrame();
DebuggerToolTipContexts rc;
foreach (DebuggerToolTipHolder *tooltip, m_tooltips) {
- if (tooltip->context.iname.startsWith("tooltip")
- && tooltip->context.matchesFrame(frame.file, frame.function))
- rc.push_back(tooltip->context);
+ const DebuggerToolTipContext &context = tooltip->context;
+ if (context.iname.startsWith("tooltip") && context.matchesFrame(frame))
+ rc.push_back(context);
}
return rc;
}
diff --git a/src/plugins/debugger/debuggertooltipmanager.h b/src/plugins/debugger/debuggertooltipmanager.h
index a184a8b076..2ff2f591d6 100644
--- a/src/plugins/debugger/debuggertooltipmanager.h
+++ b/src/plugins/debugger/debuggertooltipmanager.h
@@ -47,19 +47,23 @@ class DebuggerEngine;
namespace Internal {
+class StackFrame;
+
class DebuggerToolTipContext
{
public:
DebuggerToolTipContext();
bool isValid() const { return !expression.isEmpty(); }
- bool matchesFrame(const QString &frameFile, const QString &frameFunction) const;
+ bool matchesFrame(const StackFrame &frame) const;
bool isSame(const DebuggerToolTipContext &other) const;
QString fileName;
int position;
int line;
int column;
- QString function; //!< Optional function. This must be set by the engine as it is language-specific.
+ int scopeFromLine;
+ int scopeToLine;
+ QString function; //!< Optional, informational only.
QString engineType;
QDate creationDate;
diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp
index d3bf19ff6d..eec4b595cf 100644
--- a/src/plugins/debugger/sourceutils.cpp
+++ b/src/plugins/debugger/sourceutils.cpp
@@ -269,11 +269,7 @@ bool isCppEditor(TextEditorWidget *editorWidget)
QString cppFunctionAt(const QString &fileName, int line, int column)
{
- CppModelManager *modelManager = CppModelManager::instance();
- if (!modelManager)
- return QString();
-
- const Snapshot snapshot = modelManager->snapshot();
+ const Snapshot snapshot = CppModelManager::instance()->snapshot();
if (const Document::Ptr document = snapshot.document(fileName))
return document->functionAt(line, column);
@@ -283,7 +279,8 @@ QString cppFunctionAt(const QString &fileName, int line, int column)
// Return the Cpp expression, and, if desired, the function
QString cppExpressionAt(TextEditorWidget *editorWidget, int pos,
- int *line, int *column, QString *function /* = 0 */)
+ int *line, int *column, QString *function,
+ int *scopeFromLine, int *scopeToLine)
{
*line = *column = 0;
if (function)
@@ -291,8 +288,7 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos,
QTextCursor tc = editorWidget->textCursor();
QString expr = tc.selectedText();
- CppModelManager *modelManager = CppModelManager::instance();
- if (expr.isEmpty() && modelManager) {
+ if (expr.isEmpty()) {
tc.setPosition(pos);
const QChar ch = editorWidget->characterAt(pos);
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
@@ -308,8 +304,15 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos,
*line = tc.blockNumber();
}
- if (function && !expr.isEmpty())
- *function = cppFunctionAt(editorWidget->textDocument()->filePath(), *line, *column);
+ if (!expr.isEmpty()) {
+ QString fileName = editorWidget->textDocument()->filePath();
+ const Snapshot snapshot = CppModelManager::instance()->snapshot();
+ if (const Document::Ptr document = snapshot.document(fileName)) {
+ QString func = document->functionAt(*line, *column, scopeFromLine, scopeToLine);
+ if (function)
+ *function = func;
+ }
+ }
return expr;
}
diff --git a/src/plugins/debugger/sourceutils.h b/src/plugins/debugger/sourceutils.h
index cb5f9edf39..9dda73c08c 100644
--- a/src/plugins/debugger/sourceutils.h
+++ b/src/plugins/debugger/sourceutils.h
@@ -42,7 +42,8 @@ namespace Internal {
// Editor tooltip support
bool isCppEditor(TextEditor::TextEditorWidget *editorWidget);
QString cppExpressionAt(TextEditor::TextEditorWidget *editorWidget, int pos,
- int *line, int *column, QString *function = 0);
+ int *line, int *column, QString *function = 0,
+ int *scopeFromLine = 0, int *scopeToLine = 0);
QString fixCppExpression(const QString &exp);
QString cppFunctionAt(const QString &fileName, int line, int column = 0);