Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix microsoft/vscode-chrome-debug#934
  • Loading branch information
roblourens committed Sep 24, 2019
1 parent 179e8fc commit 9a58f73
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 73 deletions.
65 changes: 23 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"glob": "^7.1.3",
"noice-json-rpc": "^1.2.0",
"source-map": "^0.6.1",
"vscode-debugadapter": "^1.34.0",
"vscode-debugprotocol": "^1.34.0",
"vscode-debugadapter": "^1.37.1",
"vscode-debugprotocol": "^1.37.0",
"vscode-nls": "^4.0.0",
"vscode-uri": "^2.0.2",
"ws": "^6.0.0"
Expand Down
86 changes: 84 additions & 2 deletions src/chrome/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Breakpoints {
if (sourceMapTransformerResponse && sourceMapTransformerResponse.ids) {
ids = sourceMapTransformerResponse.ids;
}
args = this.adapter.pathTransformer.setBreakpoints(args);
args.source = this.adapter.pathTransformer.setBreakpoints(args.source);

// Get the target url of the script
let targetScriptUrl: string;
Expand Down Expand Up @@ -146,7 +146,7 @@ export class Breakpoints {
// We need to send the original args to avoid adjusting the line and column numbers twice here
return this.unverifiedBpResponseForBreakpoints(originalArgs, requestSeq, targetScriptUrl, body.breakpoints, localize('bp.fail.unbound', 'Breakpoint set but not yet bound'));
}
this.adapter.sourceMapTransformer.setBreakpointsResponse(body, requestSeq);
body.breakpoints = this.adapter.sourceMapTransformer.setBreakpointsResponse(body.breakpoints, true, requestSeq) || body.breakpoints;
this.adapter.lineColTransformer.setBreakpointsResponse(body);
return body;
});
Expand Down Expand Up @@ -264,6 +264,88 @@ export class Breakpoints {
};
}

/**
* Using the request object from the DAP, set all breakpoints on the target
* @param args The setBreakpointRequest arguments from the DAP client
* @param scripts The script container associated with this instance of the adapter
* @param requestSeq The request sequence number from the DAP
* @param ids IDs passed in for previously unverified breakpoints
*/
public async getBreakpointsLocations(args: DebugProtocol.BreakpointLocationsArguments, scripts: ScriptContainer, requestSeq: number): Promise<DebugProtocol.BreakpointLocationsResponse['body']> {

if (args.source.path) {
args.source.path = this.adapter.displayPathToRealPath(args.source.path);
args.source.path = utils.canonicalizeUrl(args.source.path);
}

await this.validateBreakpointsPath(args);

// Deep copy the args that we are going to modify, and keep the original values in originalArgs
args = JSON.parse(JSON.stringify(args));
args.endLine = this.adapter.lineColTransformer.convertClientLineToDebugger(typeof args.endLine === 'number' ? args.endLine : args.line + 1);
args.endColumn = this.adapter.lineColTransformer.convertClientLineToDebugger(args.endColumn || 1);
args.line = this.adapter.lineColTransformer.convertClientLineToDebugger(args.line);
args.column = this.adapter.lineColTransformer.convertClientColumnToDebugger(args.column || 1);

if (args.source.path) {
const source1 = JSON.parse(JSON.stringify(args.source));
const startArgs = this.adapter.sourceMapTransformer.setBreakpoints({ breakpoints: [{ line: args.line, column: args.column }], source: source1 }, requestSeq);
args.line = startArgs.args.breakpoints[0].line;
args.column = startArgs.args.breakpoints[0].column;

const endArgs = this.adapter.sourceMapTransformer.setBreakpoints({ breakpoints: [{ line: args.endLine, column: args.endColumn }], source: args.source }, requestSeq);
args.endLine = endArgs.args.breakpoints[0].line;
args.endColumn = endArgs.args.breakpoints[0].column;
}

args.source = this.adapter.pathTransformer.setBreakpoints(args.source);

// Get the target url of the script
let targetScriptUrl: string;
if (args.source.sourceReference) {
const handle = scripts.getSource(args.source.sourceReference);
if ((!handle || !handle.scriptId) && args.source.path) {
// A sourcemapped script with inline sources won't have a scriptId here, but the
// source.path has been fixed.
targetScriptUrl = args.source.path;
} else {
const targetScript = scripts.getScriptById(handle.scriptId);
if (targetScript) {
targetScriptUrl = targetScript.url;
}
}
} else if (args.source.path) {
targetScriptUrl = args.source.path;
}

if (targetScriptUrl) {
const script = scripts.getScriptByUrl(targetScriptUrl);
if (script) {
const end = typeof args.endLine === 'number' ?
{ scriptId: script.scriptId, lineNumber: args.endLine, columnNumber: args.endColumn || 0 } :
{ scriptId: script.scriptId, lineNumber: args.line + 1, columnNumber: 0 };

const possibleBpResponse = await this.chrome.Debugger.getPossibleBreakpoints({
start: { scriptId: script.scriptId, lineNumber: args.line, columnNumber: args.column || 0 },
end,
restrictToFunction: false
});
let breakpoints = possibleBpResponse.locations.map(loc => {
return <DebugProtocol.Breakpoint>{
line: loc.lineNumber,
column: loc.columnNumber
};
});
breakpoints = this.adapter.sourceMapTransformer.setBreakpointsResponse(breakpoints, false, requestSeq);
const response = { breakpoints };
this.adapter.lineColTransformer.setBreakpointsResponse(response);
return response as DebugProtocol.BreakpointLocationsResponse['body'];
}
}

return null;
}

/**
* Transform breakpoint responses from the chrome-devtools target to the DAP response
* @param url The URL of the script for which we are translating breakpoint responses
Expand Down
6 changes: 5 additions & 1 deletion src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
supportsDelayedStackTraceLoading: true,
supportsValueFormattingOptions: true,
supportsEvaluateForHovers: true,
supportsLoadedSourcesRequest: true
supportsLoadedSourcesRequest: true,
supportsBreakpointLocationsRequest: true
};
}

Expand Down Expand Up @@ -1679,4 +1680,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
return this._breakpoints.validateBreakpointsPath(args);
}

public breakpointLocations(args: DebugProtocol.BreakpointLocationsArguments, _telemetryPropertyCollector?: ITelemetryPropertyCollector, requestSeq?: number): Promise<DebugProtocol.BreakpointLocationsResponse['body']> {
return this._breakpoints.getBreakpointsLocations(args, this._scriptContainer, requestSeq);
}
}
6 changes: 3 additions & 3 deletions src/transformers/basePathTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { DebugProtocol } from 'vscode-debugprotocol';

import { ISetBreakpointsArgs, ILaunchRequestArgs, IAttachRequestArgs, IStackTraceResponseBody } from '../debugAdapterInterfaces';
import { ILaunchRequestArgs, IAttachRequestArgs, IStackTraceResponseBody } from '../debugAdapterInterfaces';

/**
* Converts a local path from Code to a path on the target.
Expand All @@ -18,8 +18,8 @@ export class BasePathTransformer {
return Promise.resolve();
}

public setBreakpoints(args: ISetBreakpointsArgs): ISetBreakpointsArgs {
return args;
public setBreakpoints(source: DebugProtocol.Source): DebugProtocol.Source {
return source;
}

public clearTargetContext(): void {
Expand Down
Loading

0 comments on commit 9a58f73

Please sign in to comment.