Skip to content

Commit

Permalink
Optionally accept a SourceURL parameter for debug builds
Browse files Browse the repository at this point in the history
Summary: Adds a SourceURL field to the stackframes, which can be used to extract the required information if we deal with a classic bundle, particularly when debug info is used to extract the information from Hermes.

Reviewed By: motiz88

Differential Revision: D27650889

fbshipit-source-id: 768cdce4ae324c3481caf8fd57635d47e20bb3c3
  • Loading branch information
GijsWeterings authored and facebook-github-bot committed Apr 19, 2021
1 parent af23a1b commit 7ad7560
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 deletions.
22 changes: 11 additions & 11 deletions packages/metro-symbolicate/src/Symbolication.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ type HermesCoverageInfo = {
};

type HermesCoverageStackFrame = $ReadOnly<{
SegmentID: number,
VirtualOffset: number,
line: number, // SegmentID or zero-based line,
column: number, // VirtualOffset or zero-based column,
SourceURL: ?string,
}>;

type NativeCodeStackFrame = $ReadOnly<{|
Expand Down Expand Up @@ -458,20 +459,19 @@ class SymbolicationContext<ModuleIdsT> {

if (executedFunctions != null) {
for (const stackItem of executedFunctions) {
const {SegmentID, VirtualOffset: localOffset} = stackItem;
const generatedLine = SegmentID + this.options.inputLineStart;
const generatedColumn = localOffset + this.options.inputColumnStart;

const {line, column, SourceURL} = stackItem;
const generatedLine = line + this.options.inputLineStart;
const generatedColumn = column + this.options.inputColumnStart;
const originalPosition = this.getOriginalPositionDetailsFor(
generatedLine,
generatedColumn,
this.parseFileName(SourceURL || ''),
);
symbolicatedTrace.push(originalPosition);
}
}
return symbolicatedTrace;
}

/*
* An internal helper function similar to getOriginalPositionFor. This one
* returns both `name` and `functionName` fields so callers can distinguish the
Expand Down Expand Up @@ -617,13 +617,13 @@ class SingleMapSymbolicationContext extends SymbolicationContext<SingleMapModule

if (executedFunctions != null) {
for (const stackItem of executedFunctions) {
const {SegmentID, VirtualOffset: localOffset} = stackItem;
const generatedLine = SegmentID + this.options.inputLineStart;
const generatedColumn = localOffset + this.options.inputColumnStart;

const {line, column, SourceURL} = stackItem;
const generatedLine = line + this.options.inputLineStart;
const generatedColumn = column + this.options.inputColumnStart;
const originalPosition = this.getOriginalPositionDetailsFor(
generatedLine,
generatedColumn,
this.parseFileName(SourceURL || ''),
);
symbolicatedTrace.push(originalPosition);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"executedFunctions": [
{
"line": 0,
"column": 25522,
"SourceURL": "main.js"
},
{
"line": 0,
"column": 25877,
"SourceURL": "main.js"
},
{
"line": 0,
"column": 139,
"SourceURL": "seg-1.js"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"executedFunctions": [
{
"SegmentID": 0,
"VirtualOffset": 23819
"line": 0,
"column": 23819
},
{
"SegmentID": 0,
"VirtualOffset": 22579
"line": 0,
"column": 22579
},
{
"line": 51,
"column": 27
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ Array [
"name": null,
"source": "/js/RKJSModules/Libraries/MobileConfig/MobileConfig.js",
},
Object {
"column": 0,
"functionName": "<global>",
"line": 8,
"name": null,
"source": "/js/RKJSModules/Apps/HermesModulesTest/HMTLazyFetched.js",
},
]
`;

exports[`coverage option symbolicating a coverage stack trace Classic 1`] = `
Array [
Object {
"column": 9,
"functionName": "<anonymous>",
"line": 162,
"name": "param",
"source": "/js/RKJSModules/Libraries/MobileConfig/MobileConfig.js",
},
Object {
"column": 21,
"functionName": "<anonymous>",
"line": 100,
"name": null,
"source": "/js/RKJSModules/Libraries/MobileConfig/MobileConfig.js",
},
Object {
"column": 15,
"functionName": "getValue",
"line": 10,
"name": "getValue",
"source": "/js/RKJSModules/Apps/HermesModulesTest/HMTLazyFetched.js",
},
]
`;

Expand Down
10 changes: 10 additions & 0 deletions packages/metro-symbolicate/src/__tests__/symbolicate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ describe('coverage option', () => {
expect(output).toMatchSnapshot();
});

test('symbolicating a coverage stack trace Classic', async () => {
const output = JSON.parse(
await execute(
[HERMES_MAP, '--hermes-coverage'],
read('coverageStackTrace.json'),
),
);
expect(output).toMatchSnapshot();
});

test('symbolicating a CJS stack trace ignores the module id of the file name', async () => {
const output = await execute([HERMES_MAP_CJS, '5.js', '52', '83']);
expect(output).toMatchSnapshot();
Expand Down

0 comments on commit 7ad7560

Please sign in to comment.