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

autoAttachSmartPattern should also apply to autoAttachChildProcesses #1246

Open
huw opened this issue Apr 29, 2022 · 1 comment
Open

autoAttachSmartPattern should also apply to autoAttachChildProcesses #1246

huw opened this issue Apr 29, 2022 · 1 comment
Assignees
Labels
feature-request Request for new features or functionality help welcome Issues identified as good community contribution opportunities

Comments

@huw
Copy link

huw commented Apr 29, 2022

It’s expensive & time-consuming to automatically attach debuggers to every child process when using a task runner like yarn. We don’t need to attach to the yarn process, but can end up getting a large chain of attached debuggers, when we only want to debug the leaf process.

We can fix this in the integrated terminal only by configuring like so:

{
  "debug.javascript.autoAttachFilter": "smart",
  "debug.javascript.autoAttachSmartPattern": ["<PATH_TO_DESIRED_PROGRAM>"]
}

This prevents attaching to everything except the leaf processes that you specify, which greatly improves startup time.

However, this functionality is only enabled in the integrated terminal—nowhere else supports autoAttachSmartPattern.

I think that we should enable autoAttachSmartPattern in the launch.json options and it would function the same way.

Apologies if I’m missing something—I pored over the docs but I couldn’t find a different way to make this work.

@huw huw added the feature-request Request for new features or functionality label Apr 29, 2022
@connor4312
Copy link
Member

connor4312 commented Apr 29, 2022

Good suggestion, we actually had this in early versions of this tool but never got around to reimplementing it... Would not be terribly difficult to PR if you're interested.

Debugging works by the inclusion of a "bootloader" script in NODE_OPTIONS that is required before the program starts. Code that runs in the bootloader to determine if we should attach to the child process:

function shouldForceProcessIntoDebugMode(env: IBootloaderInfo) {
switch (env.autoAttachMode) {
case AutoAttachMode.Always:
return true;
case AutoAttachMode.Smart:
return shouldSmartAttach(env);
case AutoAttachMode.OnlyWithFlag:
default:
return false;
}
}

Code that sets the variables that the bootloader gets:

const bootloaderInfo: IBootloaderInfo = {
inspectorIpc: serverAddress,
deferredMode: false,
// todo: look at reimplementing the filter
// NODE_INSPECTOR_WAIT_FOR_DEBUGGER: this._launchParams!.nodeFilter || '',
waitForDebugger: '',
// Supply some node executable for running top-level watchdog in Electron
// environments. Bootloader will replace this with actual node executable used if any.
execPath: await findInPath(fs.promises, 'node', process.env),
onlyEntrypoint: !params.autoAttachChildProcesses,
verbose:
params.trace === true || (typeof params.trace === 'object' && params.trace.stdio)
? true
: undefined,
autoAttachMode: AutoAttachMode.Always,
mandatePortTracking: this.portLeaseTracker.isMandated ? true : undefined,
...additionalOptions,
};

Configuration interface where the option could be added:

export interface INodeBaseConfiguration extends IBaseConfiguration, IConfigurationWithEnv {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help welcome Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

2 participants