-
Notifications
You must be signed in to change notification settings - Fork 87
debug: fallback to mark breakpoints verified on stopped/breakpoint events #1989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amanthatdoescares
wants to merge
12
commits into
swiftlang:main
Choose a base branch
from
amanthatdoescares:fix/breakpoint-verified-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
953bdc6
debug: fallback to mark breakpoints verified on stopped/breakpoint ev…
amanthatdoescares 71fe19d
Apply suggestions from code review
amanthatdoescares a1ceb6e
Use location-based breakpoint filtering, add logger, normalize paths
amanthatdoescares 986a683
Changelog: normalize adapter source.path for breakpoint fallback
amanthatdoescares 4079504
Remove duplicate vscode-tmgrammar-test dependency
amanthatdoescares 42a6748
Remove duplicate license entry in package-lock.json
amanthatdoescares 9f1a63a
Update src/debugger/logTracker.ts
amanthatdoescares a745d3a
Refine breakpoint fallback handling
amanthatdoescares 5046758
Update changelog
amanthatdoescares 2aa099b
Update CHANGELOG to remove version 2.14.2
amanthatdoescares dc97cc4
Update CHANGELOG with new features and fixes
amanthatdoescares d51fdf1
Merge branch 'main' into fix/breakpoint-verified-fallback
amanthatdoescares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| import { DebugProtocol } from "@vscode/debugprotocol"; | ||
| import * as vscode from "vscode"; | ||
|
|
||
| import { SwiftLogger } from "../logging/SwiftLogger"; | ||
|
|
@@ -68,6 +69,7 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker { | |
| private exitHandler?: (exitCode: number) => void; | ||
| private output: string[] = []; | ||
| private exitCode: number | undefined; | ||
| private logger?: SwiftLogger; | ||
|
|
||
| constructor(public id: string) { | ||
| LoggingDebugAdapterTracker.debugSessionIdMap[id] = this; | ||
|
|
@@ -86,6 +88,7 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker { | |
| cb(o); | ||
| } | ||
| if (loggingDebugAdapter.exitCode) { | ||
| loggingDebugAdapter.logger = logger; | ||
| exitHandler(loggingDebugAdapter.exitCode); | ||
| } | ||
| loggingDebugAdapter.output = []; | ||
|
|
@@ -110,6 +113,8 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker { | |
| return; | ||
| } | ||
|
|
||
| this.handleBreakpointEvent(debugMessage); | ||
|
|
||
| if (debugMessage.event === "exited" && debugMessage.body.exitCode) { | ||
| this.exitCode = debugMessage.body.exitCode; | ||
| this.exitHandler?.(debugMessage.body.exitCode); | ||
|
|
@@ -127,6 +132,129 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker { | |
| } | ||
| } | ||
|
|
||
| private handleBreakpointEvent(rawMsg: unknown): void { | ||
| // Narrow-bodied shapes for just the fields we use (local to this function). | ||
| type StoppedBodyLike = { | ||
| reason?: string; | ||
| thread?: { | ||
| frames?: { | ||
| source?: { path?: string }; | ||
| line?: number; | ||
| }[]; | ||
| }; | ||
| }; | ||
|
|
||
| try { | ||
| const msg = rawMsg as DebugProtocol.ProtocolMessage; | ||
| const eventMsg = msg as DebugProtocol.Event; | ||
|
|
||
| if (!msg || msg.type !== "event") { | ||
| return; | ||
| } | ||
|
|
||
| const normalizePath = (p: string): string => { | ||
| try { | ||
| return vscode.Uri.parse(p, true).fsPath; | ||
| } catch { | ||
| try { | ||
| return vscode.Uri.file(p).fsPath; | ||
| } catch { | ||
| return p; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Case A: stopped event with reason = "breakpoint" | ||
| if ( | ||
| eventMsg.event === "stopped" && | ||
| (eventMsg.body as StoppedBodyLike)?.reason === "breakpoint" | ||
| ) { | ||
| const frames = (eventMsg.body as StoppedBodyLike)?.thread?.frames; | ||
| if (!Array.isArray(frames) || frames.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const top = frames[0]; | ||
| const sourcePath = top?.source?.path; | ||
| const line = top?.line; | ||
| if (!sourcePath || typeof line !== "number") { | ||
| return; | ||
| } | ||
|
|
||
| const bpLine0 = line - 1; // VS Code uses 0-based lines | ||
|
|
||
| const breakpoints = vscode.debug.breakpoints.filter( | ||
| b => !!(b as vscode.SourceBreakpoint).location | ||
| ) as vscode.SourceBreakpoint[]; | ||
|
|
||
| for (const bp of breakpoints) { | ||
| const loc = bp.location; | ||
|
|
||
| if (normalizePath(loc.uri.fsPath) !== normalizePath(sourcePath)) { | ||
| continue; | ||
| } | ||
| if (loc.range.start.line !== bpLine0) { | ||
| continue; | ||
| } | ||
|
|
||
| // Force a UI refresh so the breakpoint shows as installed. | ||
| vscode.debug.removeBreakpoints([bp]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Will this also trigger when the breakpoint is already resolved? It's probably not a huge issue, but I think we should be only doing this when the breakpoint that's being hit isn't marked as resolved. |
||
| vscode.debug.addBreakpoints([bp]); | ||
| break; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Case B: explicit "breakpoint" event that carries source+line info | ||
| if (eventMsg.event === "breakpoint" && eventMsg.body) { | ||
| const bpEvent = eventMsg as DebugProtocol.BreakpointEvent; | ||
| const dapBp = bpEvent.body?.breakpoint; | ||
| if (!dapBp) { | ||
| return; | ||
| } | ||
|
|
||
| // If the adapter already marked this breakpoint as verified/resolved, | ||
| // there's no need to re-add it. | ||
| if (dapBp.verified === true) { | ||
| return; | ||
| } | ||
|
|
||
| const sourcePath = dapBp.source?.path; | ||
| const line = dapBp.line; | ||
| if (!sourcePath || typeof line !== "number") { | ||
| return; | ||
| } | ||
|
|
||
| const bpLine0 = line - 1; | ||
| const breakpoints = vscode.debug.breakpoints.filter( | ||
| b => !!(b as vscode.SourceBreakpoint).location | ||
| ) as vscode.SourceBreakpoint[]; | ||
|
|
||
| for (const bp of breakpoints) { | ||
| const loc = bp.location; | ||
|
|
||
| if (normalizePath(loc.uri.fsPath) !== normalizePath(sourcePath)) { | ||
| continue; | ||
| } | ||
| if (loc.range.start.line !== bpLine0) { | ||
| continue; | ||
| } | ||
|
|
||
| vscode.debug.removeBreakpoints([bp]); | ||
| vscode.debug.addBreakpoints([bp]); | ||
| break; | ||
| } | ||
| return; | ||
| } | ||
| } catch (err: unknown) { | ||
| try { | ||
| this.logger?.error(new Error("Breakpoint fallback error", { cause: err })); | ||
| } catch { | ||
| this.logger?.error("Breakpoint fallback error: " + String(err)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The debug adapter session is about to be stopped. Delete the session from | ||
| * the tracker | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.