How to break at a specific function or line with the Node.js node inspect command line step debugger without modifying the source?

main.js

#!/usr/bin/env node

function myfunc(i) {
  return i + 1;
}

let i = 1;
i += 1;
console.log(myfunc(i));

Start debugging:

node inspect main.js

Leaves me at:

Break on start in main.js:7
  5 }
  6 
> 7 let i = 1;
  8 i += 1;
  9 console.log(myfunc(i));

Now I want to go directly to myfunc without:

I tried something like:

sb myfunc

to add a breakpoint on myfunc, but sb only seems to be able to set breakpoints at the current line:

sb myfunc
   ^^^^^^

Uncaught SyntaxError: Unexpected identifier

Tested on node v12.18.1.

Upvotes: 0

Views: 370

Answers (1)

jfriend00
jfriend00

Reputation: 707158

Per the doc, it looks to me like the right syntax is:

sb('myfunc()')

to set a breakpoint on the first line of a function named myfunc.

You could also set a breakpoint on a specific line number with:

sb(5)

Upvotes: 2

Related Questions