diff options
author | hjk <hjk@qt.io> | 2018-08-22 17:35:12 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2018-09-04 13:33:29 +0000 |
commit | c7f0285c4c1d39572b99dfee3f92eccf6893dda6 (patch) | |
tree | c69a5876cc4c98b551528b3cd14a37f9ee0a7d79 | |
parent | 4192d7d62fe65b70b9f00f540425ea52bcb68c81 (diff) | |
download | qt-creator-c7f0285c4c1d39572b99dfee3f92eccf6893dda6.tar.gz |
Debugger: Consolidate breakpoint search
We already have a concept of Context when action on editor events,
use that directly when searching an (almost) matching breakpoint
instead of translating it into breakpoint manager's interface
language.
This also centralizes the guesswork for non-exact matches in one
place, making it easier to fix currently wrong matches later.
Change-Id: I5579e7e01792d425cad4ccf1dbcbbd1bd56c84ec
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/debugger/breakhandler.cpp | 55 | ||||
-rw-r--r-- | src/plugins/debugger/breakhandler.h | 9 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerplugin.cpp | 13 |
3 files changed, 34 insertions, 43 deletions
diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index c70c0188dc..ac6d321ddd 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -941,13 +941,6 @@ static bool isSimilarTo(const BreakpointParameters ¶ms, const BreakpointPara && params.lineNumber == needle.lineNumber) return true; - // At least at a position we were looking for. - // FIXME: breaks multiple breakpoints at the same location - if (!params.fileName.isEmpty() - && fileNameMatch(params.fileName, needle.fileName) - && params.lineNumber == needle.lineNumber) - return true; - return false; } @@ -2415,14 +2408,6 @@ const GlobalBreakpoints BreakpointManager::globalBreakpoints() return items; } -GlobalBreakpoint BreakpointManager::findSimilarBreakpoint(const BreakpointParameters &needle) -{ - // Search a breakpoint we might refer to. - return theBreakpointManager->findItemAtLevel<1>([needle](const GlobalBreakpoint &gbp) { - return gbp && isSimilarTo(gbp->m_params, needle); - }); -} - void BreakpointManager::claimBreakpointsForEngine(DebuggerEngine *engine) { theBreakpointManager->forItemsAtLevel<1>([&](GlobalBreakpoint gbp) { @@ -2472,7 +2457,7 @@ void BreakpointManager::createBreakpointForEngine(const BreakpointParameters &pa void BreakpointManager::toggleBreakpoint(const ContextData &location, const QString &tracePointMessage) { QTC_ASSERT(location.isValid(), return); - GlobalBreakpoint gbp = findBreakpointByLocation(location); + GlobalBreakpoint gbp = findBreakpointFromContext(location); if (gbp) { gbp->deleteBreakpoint(); @@ -2496,16 +2481,38 @@ void BreakpointManager::toggleBreakpoint(const ContextData &location, const QStr } } -GlobalBreakpoint BreakpointManager::findBreakpointByLocation(const ContextData &location) +GlobalBreakpoint BreakpointManager::findBreakpointFromContext(const ContextData &location) { - return theBreakpointManager->findItemAtLevel<1>([&location](GlobalBreakpoint bp) { - if (location.type == LocationByFile) - return bp->m_params.isLocatedAt(location.fileName, location.lineNumber, QString()); - if (location.type == LocationByAddress) - return bp->m_params.address == location.address; - return false; + int matchLevel = 0; + GlobalBreakpoint bestMatch; + theBreakpointManager->forItemsAtLevel<1>([&](const GlobalBreakpoint &gbp) { + if (location.type == LocationByFile) { + if (gbp->m_params.isLocatedAt(location.fileName, location.lineNumber, QString())) { + matchLevel = 2; + bestMatch = gbp; + } else if (matchLevel < 2) { + for (const QPointer<DebuggerEngine> engine : EngineManager::engines()) { + BreakHandler *handler = engine->breakHandler(); + for (Breakpoint bp : handler->breakpoints()) { + if (bp->globalBreakpoint() == gbp) { + if (fileNameMatch(bp->fileName(), location.fileName) + && bp->lineNumber() == location.lineNumber) { + matchLevel = 1; + bestMatch = gbp; + } + } + } + } + } + } else if (location.type == LocationByAddress) { + if (gbp->m_params.address == location.address) { + matchLevel = 2; + bestMatch = gbp; + } + } }); - return {}; + + return bestMatch; } void BreakpointManager::executeAddBreakpointDialog() diff --git a/src/plugins/debugger/breakhandler.h b/src/plugins/debugger/breakhandler.h index 118e8ca022..048e2f996a 100644 --- a/src/plugins/debugger/breakhandler.h +++ b/src/plugins/debugger/breakhandler.h @@ -78,8 +78,6 @@ public: void updateLineNumber(int lineNumber); void updateFileName(const Utils::FileName &fileName); - bool isLocatedAt(const QString &fileName, int lineNumber, bool useMarkerPosition) const; - QString displayName() const; QString markerFileName() const; QString toolTip() const; @@ -296,12 +294,7 @@ public: static const GlobalBreakpoints globalBreakpoints(); static GlobalBreakpoint createBreakpoint(const BreakpointParameters &data); - - static GlobalBreakpoint findBreakpointByLocation(const ContextData &location); - // Find a breakpoint matching approximately the data in needle. - static GlobalBreakpoint findSimilarBreakpoint(const BreakpointParameters &needle); - static GlobalBreakpoint findWatchpoint(const BreakpointParameters &data); - static GlobalBreakpoint findBreakpointByFunction(const QString &functionName); + static GlobalBreakpoint findBreakpointFromContext(const ContextData &location); static void claimBreakpointsForEngine(DebuggerEngine *engine); static void toggleBreakpoint(const ContextData &location, const QString &tracePointMessage = QString()); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 27bdbc1f63..40483cc02b 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1881,19 +1881,10 @@ void DebuggerPluginPrivate::updateBreakMenuItem(IEditor *editor) void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget, int lineNumber, QMenu *menu) { - GlobalBreakpoint gbp; TextDocument *document = widget->textDocument(); - ContextData args = getLocationContext(document, lineNumber); - if (args.type == LocationByAddress) { - BreakpointParameters needle; - needle.type = BreakpointByAddress; - needle.address = args.address; - needle.lineNumber = -1; - gbp = BreakpointManager::findSimilarBreakpoint(needle); - } else if (args.type == LocationByFile) { - gbp = BreakpointManager::findBreakpointByLocation(args); - } + const ContextData args = getLocationContext(document, lineNumber); + const GlobalBreakpoint gbp = BreakpointManager::findBreakpointFromContext(args); if (gbp) { |