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

Debugger isn't stopped at the debugger; statement when debugging using --inspect #30911

Open
arcanis opened this issue Dec 12, 2019 · 3 comments
Labels
inspector Issues and PRs related to the V8 inspector protocol

Comments

@arcanis
Copy link
Contributor

arcanis commented Dec 12, 2019

Note: previous thread was #10457, but it got closed recommending --inspect-brk which is more a workaround than a solution imo.

Is your feature request related to a problem? Please describe.

When debugging a CLI program, I want to break at a specific location. For DevX reasons I don't want to use --inspect-brk, as it would require me to attach the debugger before even knowing whether the codepath covered by the breakpoint is hit - which is particularly cumbersome when using nested processes (with --inspect-port=0).

Describe the solution you'd like

I'd like debugger; statements to pause the execution even if a debugger isn't attached yet; I'd then attach it myself.

Describe alternatives you've considered

Pausing the process manually using execSync w/ sleep or similar doesn't work: the debugger doesn't see the Node process. I suspect an internal integration is required for the process to answer the debugger during a synchronous call?

@june07
Copy link

june07 commented Mar 22, 2020

So I just completed a feature of NiM that partially addresses this issue. Using the underlying devtools protocol NiM will resume the debugger (past --inspect-brk) automatically when it connects...

Granted, situations where you're assigning random ports via "=0" will require more, but maybe this would help in certain other situations.

githubIssue-nodejs30911

@targos targos added inspector Issues and PRs related to the V8 inspector protocol and removed debugger labels Dec 27, 2020
@schalkneethling
Copy link

I ran into this same problem. In the curriculum used by the Linux Foundation to prepare you for the Nodejs application developer exam, it is stated that --inspect-brk will stop the debugger at the first executable line. 👍

When using debugger; the material says to use --inspect instead of --inspect-brk as the former will execute the program and then pause at the debugger; line. This is not the case, as the program executes to its conclusion without pausing.

One can use inspect-brk as a workaround (as mentioned by @arcanis), but it sounds like the documentation is unclear on whether there is a use case where one would favor --inspect over --inspect-brk.

@bnoordhuis
Copy link
Member

I'd like debugger; statements to pause the execution even if a debugger isn't attached yet

I think you can already kind of do that with a preload script: node --inspect -r preload.js app.js

Load the inspector module and start listening for breakpoint events (debugger statements are breakpoints), then call inspector.waitForDebugger() when you receive one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

No branches or pull requests

6 participants