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

[Bug] RN application crashes from VSCode 1.83.0 #1837

Closed
EzioLi01 opened this issue Oct 7, 2023 · 8 comments
Closed

[Bug] RN application crashes from VSCode 1.83.0 #1837

EzioLi01 opened this issue Oct 7, 2023 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@EzioLi01
Copy link

EzioLi01 commented Oct 7, 2023

Hey @connor4312, we found that react-native application will be crashed when update vscode to 1.83.0, checked this issue is occurring from js-debug v1.83.0 prod and v2023.9.1317 nightly. microsoft/vscode-react-native#2052

Here is the screen record and js-debug trace log, could you please help to check if we have any updates may cause this issue? Thank you!

Repro step:

  1. Install react-native by npm i -g react-native
  2. Create template app by npx react-native init sampleApp
  3. Install react-native-tools in vscode
  4. Run npm run android to run app in emulator
  5. Add Attach to Hermes application - Experimental in launch.json with default options
  6. Attach debugger, add breakpoint and trigger it

Record:
AppCrash

Trace:
vscode-debugadapter-5f2fdf71.json.gz

@EzioLi01 EzioLi01 added the bug Issue identified by VS Code Team member as probable bug label Oct 7, 2023
@connor4312
Copy link
Member

It seems to crash when this function is called on various objects in the scope, which is used to generate the previews seen in the Variables view. I'm guessing this is some kind of native crash; more info about what's going wrong would help. A native crash would not really be an issue in the debugger but we can see if a workaround is available

/**
* Gets a mapping of property names with a custom `.toString()` method
* to their string representations.
*/
export const getStringyProps = templateFunction(function (
this: unknown,
maxLength: number,
customToString: (defaultRepr: string) => unknown,
) {
const out: Record<string, string> = {};
const defaultPlaceholder = '<<default preview>>';
if (typeof this !== 'object' || !this) {
return out;
}
for (const [key, value] of Object.entries(this)) {
if (customToString) {
try {
const repr = customToString.call(value, defaultPlaceholder);
if (repr !== defaultPlaceholder) {
out[key] = String(repr);
continue;
}
} catch (e) {
out[key] = `<<indescribable>>${JSON.stringify([String(e), key])}`;
continue;
}
}
if (typeof value === 'object' && value) {
let str: string | undefined;
for (const sym of runtimeArgs[0]) {
try {
str = value[sym]();
break;
} catch {
// ignored
}
}
if (!str && !String(value.toString).includes('[native code]')) {
str = String(value);
}
if (str && !str.startsWith('[object ')) {
out[key] = str.length >= maxLength ? str.slice(0, maxLength) + '…' : str;
}
}
}
return out;
});

@connor4312 connor4312 added the info-needed Issue requires more information from poster label Oct 7, 2023
@EzioLi01
Copy link
Author

EzioLi01 commented Oct 8, 2023

Thanks @connor4312 sharing information, I will try to debug on this. Also adding some log in DevTools console.

console.ts:137 [Extension Host] TypeError: Cannot read properties of undefined (reading 'map')
	at c:\Users\v-yukl\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:103:6964
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
	at async Promise.all (index 0)
	at async mn.getBreakpointLocations (c:\Users\v-yukl\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:103:7197)
	at async c:\Users\v-yukl\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:159:4398
	at async Zl._onMessage (c:\Users\v-yukl\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:71:4859)
$ @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
z @ event.ts:1138
fire @ event.ts:1169
fire @ ipc.net.ts:650
Y.onmessage @ localProcessExtensionHost.ts:581

ERR Invalid debug adapter: Error: Invalid debug adapter
    at v.m (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1543:95)
    at v.$acceptDAError (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1542:7624)
    at m.S (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1551:18856)
    at m.Q (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1551:18622)
    at m.M (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1551:17715)
    at m.L (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1551:16794)
    at u.value (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1551:15597)
    at c.z (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:87:1902)
    at c.fire (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:87:2119)
    at r.fire (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:616:14393)
    at Y.onmessage (vscode-file://vscode-app/c:/Users/v-yukl/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1652:1077)

@benjaminbi
Copy link

benjaminbi commented Oct 8, 2023

adding some info
the issue seems occur since 676e7e7. The previous commit (72c0276) works well on my machine.

@EzioLi01
Copy link
Author

EzioLi01 commented Oct 9, 2023

@connor4312, I think this might be the root cause. When we attach debugger to RN application, js-debug will get breakpoint location in function:

public async getBreakpointLocations(

In line 373:

todo.push(
thread
.cdp()
.Debugger.getPossibleBreakpoints({
restrictToFunction: false,
start: { scriptId, ...lsrc.offsetSourceToScript(base1To0(start)) },
end: { scriptId, ...lsrc.offsetSourceToScript(base1To0(end)) },
})
.then(r => {
if (!r) {
return;
}
// Map the locations from CDP back to their original source positions.
// Discard any that map outside of the source we're interested in,
// which is possible (e.g. if a section of code from one source is
// inlined amongst the range we request).
return Promise.all(
r.locations.map(async breakLocation => {
const { lineNumber, columnNumber = 0 } = breakLocation;
const uiLocations = await this._sourceContainer.currentSiblingUiLocations({
source: lsrc,
...lsrc.offsetScriptToSource(base0To1({ lineNumber, columnNumber })),
});
result.push({ breakLocation, uiLocations });
}),
);

the function Debugger.getPossibleBreakpoints got the empty breakpoint object r={}, so the exception will be throwed since r.locations=undefined that cannot call function map.

But I have checked source url(source.js.zip), strangely the breakpoint start and end location seems be getting correctly in:

const [startLocations, endLocations] = await Promise.all([
this._sourceContainer.currentSiblingUiLocations({
source,
lineNumber: start1.lineNumber,
columnNumber: start1.columnNumber,
}),
this._sourceContainer.currentSiblingUiLocations({
source,
lineNumber: end1.lineNumber,
columnNumber: end1.columnNumber,
}),
]);

Screenshot 2023-10-09 at 16 49 55

I'm not familiar with CDP api, @connor4312 could you please guide me on this? Any info you needed please let me know. I will keep on investigating this issue.

BTW, found an issue in RN Hermes engine repo, I'm not sure if it's related to this: facebook/hermes#1087

@connor4312
Copy link
Member

I put in a fix for that, though I don't think that would be the cause of the crash. Available in the next nightly build.

@EzioLi01
Copy link
Author

EzioLi01 commented Oct 10, 2023

Thank you @connor4312 for the quick response, it not the reason of crashing, but resolved an unexpected error in console log. I will continue looking into this. Thank you!

@EzioLi01
Copy link
Author

Hey @connor4312, it should be the correct location. In new method getEnhancedName(), app will crash on callFunctionOn:

const ret = await thread.cdp().Runtime.callFunctionOn({
functionDeclaration: getToStringIfCustom.decl('64', 'null'),
objectId: callFrame.this.objectId,
returnByValue: true,
});

And I do some testing on my project, seems this crash can be fixed on react-native-tools by updating callFunctionOn event. I will try on this firstly. Please keep this issue opening, and I will close it if I can fix it on my project.

Thanks again for your positive help!

@EzioLi01
Copy link
Author

Close this issue, since it's resolved in RNT project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants