Skip to content

Commit 76ec0a3

Browse files
authored
Merge pull request #1804 from microsoft/connor4312/wasm-1
feat: initial DWARF debugger integration
2 parents 65f087c + 61a8b9f commit 76ec0a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2390
-1003
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
"source.organizeImports": true
2929
},
3030
"editor.formatOnSave": true,
31-
"python.formatting.provider": "black"
31+
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
3232
}

gulpfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const pipelineAsync = util.promisify(stream.pipeline);
2424

2525
const dirname = 'js-debug';
2626
const sources = ['src/**/*.{ts,tsx}'];
27+
const externalModules = ['@vscode/dwarf-debugging'];
2728
const allPackages = [];
2829

2930
const srcDir = 'src';
@@ -232,7 +233,7 @@ async function compileTs({
232233
resolveExtensions: isInVsCode
233234
? ['.extensionOnly.ts', ...resolveDefaultExts]
234235
: resolveDefaultExts,
235-
external: isInVsCode ? ['vscode'] : [],
236+
external: isInVsCode ? ['vscode', ...externalModules] : externalModules,
236237
sourcemap: !!sourcemap,
237238
sourcesContent: false,
238239
packages: nodePackages,

package-lock.json

Lines changed: 26 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"@types/ws": "^8.5.3",
126126
"@typescript-eslint/eslint-plugin": "^5.17.0",
127127
"@typescript-eslint/parser": "^5.17.0",
128+
"@vscode/dwarf-debugging": "^0.0.2",
128129
"@vscode/test-electron": "^2.2.3",
129130
"chai": "^4.3.6",
130131
"chai-as-promised": "^7.1.1",

src/adapter/breakpoints.ts

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { inject, injectable } from 'inversify';
66
import Cdp from '../cdp/api';
77
import { ILogger, LogTag } from '../common/logging';
8-
import { bisectArray, flatten } from '../common/objUtils';
8+
import { bisectArrayAsync, flatten } from '../common/objUtils';
99
import { IPosition } from '../common/positions';
1010
import { delay } from '../common/promiseUtil';
1111
import { SourceMap } from '../common/sourceMaps/sourceMap';
@@ -25,15 +25,8 @@ import { NeverResolvedBreakpoint } from './breakpoints/neverResolvedBreakpoint';
2525
import { PatternEntryBreakpoint } from './breakpoints/patternEntrypointBreakpoint';
2626
import { UserDefinedBreakpoint } from './breakpoints/userDefinedBreakpoint';
2727
import { DiagnosticToolSuggester } from './diagnosticToolSuggester';
28-
import {
29-
base0To1,
30-
base1To0,
31-
ISourceWithMap,
32-
isSourceWithMap,
33-
IUiLocation,
34-
Source,
35-
SourceContainer,
36-
} from './sources';
28+
import { ISourceWithMap, IUiLocation, Source, base0To1, base1To0, isSourceWithMap } from './source';
29+
import { SourceContainer } from './sourceContainer';
3730
import { ScriptWithSourceMapHandler, Thread } from './threads';
3831

3932
/**
@@ -226,23 +219,30 @@ export class BreakpointManager {
226219
* location in the `toSource`, using the provided source map. Breakpoints
227220
* are don't have a corresponding location won't be moved.
228221
*/
229-
public moveBreakpoints(fromSource: Source, sourceMap: SourceMap, toSource: Source) {
222+
public async moveBreakpoints(
223+
thread: Thread,
224+
fromSource: Source,
225+
sourceMap: SourceMap,
226+
toSource: Source,
227+
) {
230228
const tryUpdateLocations = (breakpoints: UserDefinedBreakpoint[]) =>
231-
bisectArray(breakpoints, bp => {
232-
const gen = this._sourceContainer.getOptiminalOriginalPosition(
229+
bisectArrayAsync(breakpoints, async bp => {
230+
const gen = await this._sourceContainer.getOptiminalOriginalPosition(
233231
sourceMap,
234232
bp.originalPosition,
235233
);
236-
if (gen.column === null || gen.line === null) {
234+
if (!gen) {
237235
return false;
238236
}
239237

238+
const base1 = gen.position.base1;
240239
bp.updateSourceLocation(
240+
thread,
241241
{
242242
path: toSource.absolutePath,
243243
sourceReference: toSource.sourceReference,
244244
},
245-
{ lineNumber: gen.line, columnNumber: gen.column + 1, source: toSource },
245+
{ lineNumber: base1.lineNumber, columnNumber: base1.columnNumber, source: toSource },
246246
);
247247
return false;
248248
});
@@ -251,14 +251,14 @@ export class BreakpointManager {
251251
const toPath = toSource.absolutePath;
252252
const byPath = fromPath ? this._byPath.get(fromPath) : undefined;
253253
if (byPath && toPath) {
254-
const [remaining, moved] = tryUpdateLocations(byPath);
254+
const [remaining, moved] = await tryUpdateLocations(byPath);
255255
this._byPath.set(fromPath, remaining);
256256
this._byPath.set(toPath, moved);
257257
}
258258

259259
const byRef = this._byRef.get(fromSource.sourceReference);
260260
if (byRef) {
261-
const [remaining, moved] = tryUpdateLocations(byRef);
261+
const [remaining, moved] = await tryUpdateLocations(byRef);
262262
this._byRef.set(fromSource.sourceReference, remaining);
263263
this._byRef.set(toSource.sourceReference, moved);
264264
}
@@ -317,18 +317,19 @@ export class BreakpointManager {
317317
end: IPosition,
318318
) {
319319
const start1 = start.base1;
320-
const startLocations = this._sourceContainer.currentSiblingUiLocations({
321-
source,
322-
lineNumber: start1.lineNumber,
323-
columnNumber: start1.columnNumber,
324-
});
325-
326320
const end1 = end.base1;
327-
const endLocations = this._sourceContainer.currentSiblingUiLocations({
328-
source,
329-
lineNumber: end1.lineNumber,
330-
columnNumber: end1.columnNumber,
331-
});
321+
const [startLocations, endLocations] = await Promise.all([
322+
this._sourceContainer.currentSiblingUiLocations({
323+
source,
324+
lineNumber: start1.lineNumber,
325+
columnNumber: start1.columnNumber,
326+
}),
327+
this._sourceContainer.currentSiblingUiLocations({
328+
source,
329+
lineNumber: end1.lineNumber,
330+
columnNumber: end1.columnNumber,
331+
}),
332+
]);
332333

333334
// As far as I know the number of start and end locations should be the
334335
// same, log if this is not the case.
@@ -343,7 +344,7 @@ export class BreakpointManager {
343344
// For each viable location, attempt to identify its script ID and then ask
344345
// Chrome for the breakpoints in the given range. For almost all scripts
345346
// we'll only every find one viable location with a script.
346-
const todo: Promise<void>[] = [];
347+
const todo: Promise<unknown>[] = [];
347348
const result: IPossibleBreakLocation[] = [];
348349
for (let i = 0; i < startLocations.length; i++) {
349350
const start = startLocations[i];
@@ -383,15 +384,17 @@ export class BreakpointManager {
383384
// Discard any that map outside of the source we're interested in,
384385
// which is possible (e.g. if a section of code from one source is
385386
// inlined amongst the range we request).
386-
for (const breakLocation of r.locations) {
387-
const { lineNumber, columnNumber = 0 } = breakLocation;
388-
const uiLocations = this._sourceContainer.currentSiblingUiLocations({
389-
source: lsrc,
390-
...lsrc.offsetScriptToSource(base0To1({ lineNumber, columnNumber })),
391-
});
392-
393-
result.push({ breakLocation, uiLocations });
394-
}
387+
return Promise.all(
388+
r.locations.map(async breakLocation => {
389+
const { lineNumber, columnNumber = 0 } = breakLocation;
390+
const uiLocations = await this._sourceContainer.currentSiblingUiLocations({
391+
source: lsrc,
392+
...lsrc.offsetScriptToSource(base0To1({ lineNumber, columnNumber })),
393+
});
394+
395+
result.push({ breakLocation, uiLocations });
396+
}),
397+
);
395398
}),
396399
);
397400
}
@@ -671,7 +674,7 @@ export class BreakpointManager {
671674
}
672675

673676
/**
674-
* Rreturns whether any of the given breakpoints are an entrypoint breakpoint.
677+
* Returns whether any of the given breakpoints are an entrypoint breakpoint.
675678
*/
676679
public isEntrypointBreak(
677680
hitBreakpointIds: ReadonlyArray<Cdp.Debugger.BreakpointId>,

0 commit comments

Comments
 (0)