help icon indicating copy to clipboard operation
help copied to clipboard

Breakpoint does not work on Node.js modules

Open ugultopu opened this issue 4 years ago • 5 comments

  • Node.js Version: v15.0.1
  • OS: macOS
  • Scope (install, code, runtime, meta, other?): code, debugging
  • Module (and version) (if relevant): Stream but I don't think module is important

I have the following code:

basic-stream.js:

const readStream = require('stream').Readable();
readStream.push('beep ');

I run it with node inspect basic-stream.js, open my browser, open developer tools and click on the "Open dedicated DevTools for Node.js" button. This launches a new window for debugging my application.

I'm able to step through the code just fine. I can step into a function call and the debugger will go to the line where the function is, even if the function is a Node.js library.

I'm also able to put a breakpoint to somewhere in my code and when I click on "Resume script execution", the code will stop on the breakpoint.

However, when I try to insert a breakpoint in a Node.js library and then click on "Resume script execution", the breakpoint will not be hit, even though the execution will go through that point:

Node.js debugging demonstration

What's the problem here? How can I fix this?

ugultopu avatar Dec 02 '20 20:12 ugultopu

It doesn't work from the command line debugger either. I get "Could not resolve breakpoint - undefined" error when I try to set the breakpoint:

$ node inspect basic-stream.js 
< Debugger listening on ws://127.0.0.1:9229/d694952c-7819-45d6-bdac-e0c1541553d7
< For help, see: https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in basic-stream.js:1
> 1 const readStream = require('stream').Readable();
  2 readStream.push('beep ');
  3 
debug> setBreakpoint(2)
  1 const readStream = require('stream').Readable();
> 2 readStream.push('beep ');
  3 
debug> cont
break in basic-stream.js:2
  1 const readStream = require('stream').Readable();
> 2 readStream.push('beep ');
  3 
debug> step
break in node:internal/streams/readable:218
 216 // write() some more.
 217 Readable.prototype.push = function(chunk, encoding) {
>218   return readableAddChunk(this, chunk, encoding, false);
 219 };
 220 
debug> step
break in node:internal/streams/readable:227
 225 
 226 function readableAddChunk(stream, chunk, encoding, addToFront) {
>227   debug('readableAddChunk', chunk);
 228   const state = stream._readableState;
 229 
debug> list()
 222 Readable.prototype.unshift = function(chunk, encoding) {
 223   return readableAddChunk(this, chunk, encoding, true);
 224 };
 225 
 226 function readableAddChunk(stream, chunk, encoding, addToFront) {
>227   debug('readableAddChunk', chunk);
 228   const state = stream._readableState;
 229 
 230   let err;
 231   if (!state.objectMode) {
 232     if (typeof chunk === 'string') {
debug> setBreakpoint(230)
Uncaught Error: Could not resolve breakpoint - undefined
    at _pending.<computed> (node:internal/deps/node-inspect/lib/internal/inspect_client:243:27)
    at Client._handleChunk (node:internal/deps/node-inspect/lib/internal/inspect_client:213:11)
    at Socket.emit (node:events:327:20)
    at Socket.EventEmitter.emit (node:domain:486:12)
    at addChunk (node:internal/streams/readable:304:12)
    at readableAddChunk (node:internal/streams/readable:279:9)
    at Socket.Readable.push (node:internal/streams/readable:218:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:192:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:129:14) {
  code: -32000
}
debug> 

ugultopu avatar Dec 03 '20 13:12 ugultopu

@nodejs/inspector Is this a bug?

aduh95 avatar Dec 05 '20 10:12 aduh95

That's not a bug afaik debugging inside core isn't supported.

The user can use the userland readable-stream (slightly older though) and break there https://www.npmjs.com/package/readable-stream :]

benjamingr avatar Dec 05 '20 11:12 benjamingr

(Or they can build core from source and put a literal debugger that worked for me in the past (and there is --inspect-brk-node but I don't think that'd help)

benjamingr avatar Dec 05 '20 11:12 benjamingr

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar May 11 '24 01:05 github-actions[bot]

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Jun 10 '24 01:06 github-actions[bot]

Trying to pass the --no-node-snapshot argument to node. It may resolves the issue.

CyanChanges avatar Jan 10 '25 07:01 CyanChanges