Skip to content

Commit

Permalink
make inline breakpoints work
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Sep 19, 2023
1 parent 3447541 commit d9d52b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/adapter/sourceContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class SourceContainer {
);

if (!map) return [];
const sourceMapUiLocation = this._sourceMappedUiLocation(uiLocation, map);
const sourceMapUiLocation = await this._sourceMappedUiLocation(uiLocation, map);
if (!isUiLocation(sourceMapUiLocation)) return [];

const r = await this.getSourceMapUiLocations(sourceMapUiLocation);
Expand Down
34 changes: 33 additions & 1 deletion src/adapter/wasmSymbolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class DecompiledWasmSymbols implements IWasmSymbols {
}

class WasmSymbols extends DecompiledWasmSymbols {
private readonly mappedLines = new Map</* source URL */ string, Promise<Uint32Array>>();
private get codeOffset() {
return this.event.codeOffset || 0;
}
Expand Down Expand Up @@ -348,11 +349,23 @@ class WasmSymbols extends DecompiledWasmSymbols {
const { lineNumber, columnNumber } = sourcePosition.base0;
const locations = await this.rpc.sendMessage('sourceLocationToRawLocation', {
lineNumber,
columnNumber: columnNumber === 0 ? -1 : 0,
columnNumber: columnNumber === 0 ? -1 : columnNumber,
rawModuleId: this.moduleId,
sourceFileURL: sourceUrl,
});

// special case: unlike sourcemaps, if we resolve a location on a line
// with nothing on it, sourceLocationToRawLocation returns undefined.
// If we think this might have happened, verify it and then get
// the next mapped line and use that location.
if (columnNumber === 0 && locations.length === 0) {
const mappedLines = await this.getMappedLines(sourceUrl);
const next = mappedLines.find(l => l > lineNumber);
if (!mappedLines.includes(lineNumber) && next /* always > 0 */) {
return this.compiledPositionFor(sourceUrl, new Base0Position(next, 0));
}
}

// todo@connor4312: will there ever be a location in another module?
const location = locations.find(l => l.rawModuleId === this.moduleId);
return location && new Base0Position(0, this.codeOffset + locations[0].startOffset);
Expand Down Expand Up @@ -388,6 +401,25 @@ class WasmSymbols extends DecompiledWasmSymbols {
}),
);
}

private getMappedLines(sourceURL: string) {
const prev = this.mappedLines.get(sourceURL);
if (prev) {
return prev;
}

const value = (async () => {
try {
const lines = await this.rpc.sendMessage('getMappedLines', this.moduleId, sourceURL);
return new Uint32Array(lines?.sort((a, b) => a - b) || []);
} catch {
return new Uint32Array();
}
})();

this.mappedLines.set(sourceURL, value);
return value;
}
}

const nullType: IWasmVariableEvaluation = {
Expand Down

0 comments on commit d9d52b4

Please sign in to comment.