7

I try to setup debugging in visual studio code for a C++ Node-Addon compiled with GYP. I want to step through the source-code if possible. I use typescript as my server language and include the ".node" file compiled by gyp. This works fine but how do I set it up so I can step not only through the typescript code but also through the C++ code?

VSCode breakpoints for .cc file:

I know I can compile a debug-version with gyp node-gyp rebuild --debug, but I have no plan how to use that in vscode.

ZachB
  • 13,051
  • 4
  • 61
  • 89
Silvan Hau
  • 85
  • 1
  • 8
  • Did you figure this out? I thought that if I changed the require to use Debug instead of Release it would work but it doesn't.. – Stellan Feb 03 '17 at 13:41
  • nope sorry, didnt find a solution :( – Silvan Hau Feb 07 '17 at 18:24
  • Do you have C++ debugging configured? See https://code.visualstudio.com/docs/languages/cpp#_debugging. I haven't debugged native addons from VSCode and I know at least some versions of it create problems when using native addons, but from Visual Studio you can easily set breakpoints in native addon code. – ZachB Feb 12 '17 at 08:14
  • @ZachB do you know how i can do it using linux? – betomoretti May 08 '18 at 02:49
  • are you using visual studio? – Aditya_Anand Jun 19 '18 at 11:53
  • I have answered a similiar question here: https://stackoverflow.com/a/51176037/2881112 – Atul Jul 05 '18 at 04:03

2 Answers2

4

If you use Windows, this VSCode launch.json may help you:

{
  "version": "0.2.0",
  "configurations": [{
      "type": "cppvsdbg",
      "request": "launch",
      "name": "Addon Debug",
      "program": "node",
      "args": ["C:\\repos\\HighloadCup\\db.js"]
  }]
}

Make sure you build Node.js addon with correct architecture and other options.

Inflight
  • 497
  • 4
  • 12
  • 1
    Just a note that cppvsdbg is for debugging Visual C++ and not GNU C++. For GNU C++ you'd use cppdbg. See here https://github.com/microsoft/vscode-cpptools/issues/2609#issuecomment-428772329 – apeman Jan 13 '21 at 17:32
0

You can add breakpoints in VS to your code then after the require statement is executed in js, Use the attach feature of the VS to attach to the node process that you are running (you will get a list of possible processes when you click on attach). Your breakpoint will now halt the execution of the code in VS in c or c++.

Aditya_Anand
  • 525
  • 7
  • 17