Skip to content

Commit

Permalink
feat(wasm): Unconditionally parse instruction addresses (#13655)
Browse files Browse the repository at this point in the history
Currently we are only setting the `platform` and `instruction_addr` for
a wasm frame if we find a matching debug image. This is not always the
case and unconditionally parsing the instruction address is almost
always desirable.
  • Loading branch information
lforst authored Sep 13, 2024
1 parent 0f122a1 commit cbb9475
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/wasm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ const _wasmIntegration = (() => {
patchWebAssembly();
},
processEvent(event: Event): Event {
let haveWasm = false;
let hasAtLeastOneWasmFrameWithImage = false;

if (event.exception && event.exception.values) {
event.exception.values.forEach(exception => {
if (exception.stacktrace && exception.stacktrace.frames) {
haveWasm = haveWasm || patchFrames(exception.stacktrace.frames);
hasAtLeastOneWasmFrameWithImage =
hasAtLeastOneWasmFrameWithImage || patchFrames(exception.stacktrace.frames);
}
});
}

if (haveWasm) {
if (hasAtLeastOneWasmFrameWithImage) {
event.debug_meta = event.debug_meta || {};
event.debug_meta.images = [...(event.debug_meta.images || []), ...getImages()];
}
Expand All @@ -37,10 +38,11 @@ export const wasmIntegration = defineIntegration(_wasmIntegration);

/**
* Patches a list of stackframes with wasm data needed for server-side symbolication
* if applicable. Returns true if any frames were patched.
* if applicable. Returns true if the provided list of stack frames had at least one
* matching registered image.
*/
function patchFrames(frames: Array<StackFrame>): boolean {
let haveWasm = false;
let hasAtLeastOneWasmFrameWithImage = false;
frames.forEach(frame => {
if (!frame.filename) {
return;
Expand All @@ -50,14 +52,15 @@ function patchFrames(frames: Array<StackFrame>): boolean {
| [string, string, string];
if (match) {
const index = getImage(match[1]);
frame.instruction_addr = match[2];
frame.filename = match[1];
frame.platform = 'native';

if (index >= 0) {
frame.instruction_addr = match[2];
frame.addr_mode = `rel:${index}`;
frame.filename = match[1];
frame.platform = 'native';
haveWasm = true;
hasAtLeastOneWasmFrameWithImage = true;
}
}
});
return haveWasm;
return hasAtLeastOneWasmFrameWithImage;
}

0 comments on commit cbb9475

Please sign in to comment.