简体   繁体   中英

VS Code debug C++ Node Addon

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.

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++.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM