Skip to content

Commit

Permalink
fix: debugging failing if target has --inspect flag
Browse files Browse the repository at this point in the history
See nodejs/node#33012
Fixes microsoft/vscode#95128

We still do remove --inspect-brk since that will break in our
bootloader which entirely blocks attachment.
  • Loading branch information
connor4312 committed Apr 22, 2020
1 parent aa26d60 commit 6538f20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/targets/node/bootloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ function inspectOrQueue(env: IBootloaderEnvironment) {
return;
}

inspector.open(0, undefined, false); // first call to get the inspector.url()
// inspector.url() will be defined if --inspect is passed to the process.
// Don't call it again to avoid https://github.com/nodejs/node/issues/33012
const openedFromCli = inspector.url() !== undefined;
if (!openedFromCli) {
inspector.open(0, undefined, false); // first call to set the inspector.url()
}

const info: IAutoAttachInfo = {
ipcAddress: env.NODE_INSPECTOR_IPC || '',
Expand Down Expand Up @@ -100,7 +105,7 @@ function inspectOrQueue(env: IBootloaderEnvironment) {
);
}

inspector.open(0, undefined, true);
inspector.open(openedFromCli ? undefined : 0, undefined, true);
}

function isPipeAvailable(pipe?: string): pipe is string {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/configuration/nodeDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class NodeConfigurationProvider extends BaseConfigurationProvider<AnyNode
config.internalConsoleOptions = 'neverOpen';
}

// remove manual --inspect flags, which are no longer needed and interfere
// remove manual --inspect-brk flags, which are no longer needed and interfere
fixInspectFlags(config);

// update outfiles to the nearest package root
Expand Down
12 changes: 4 additions & 8 deletions src/ui/configurationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { ResolvingNodeLaunchConfiguration } from '../configuration';

/**
* Removes and handles any --inspect or --inspect-brk flags from the launch
* configuration. These aren't needed and don't work with the new debugger.
* Removes any --inspect-brk flags from the launch configuration and sets
* stopOnEntry instead, otherwise we break inside the bootloader.
*/
export function fixInspectFlags(config: ResolvingNodeLaunchConfiguration) {
if (!config.runtimeArgs) {
Expand All @@ -15,14 +15,10 @@ export function fixInspectFlags(config: ResolvingNodeLaunchConfiguration) {

const resolved: string[] = [];
for (const arg of config.runtimeArgs) {
const flags = /^--inspect(-brk)?(=|$)/.exec(arg);
if (!flags) {
resolved.push(arg);
} else if (flags[1]) {
// --inspect-brk
if (/^--inspect-brk(=|$)/.test(arg)) {
config.stopOnEntry = config.stopOnEntry || true;
} else {
// simple --inspect, ignored
resolved.push(arg);
}
}

Expand Down

0 comments on commit 6538f20

Please sign in to comment.