Skip to content
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

feat: make wasm inline breakpoints work #1806

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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