How to debug C++ Electron addon from Visual Studio

Viewed 1089

I'm trying to do a debug step-by-step of my C++ addons that is used within a simple Electron App. The problem is that the break points are never triggered, even if I can see that Visual Studio loaded correctly the .pdb file. What did I do wrong?

I'm using Visual Studio 2019, with Electron 5.0.4. The addon works just fine, and I can put a break point in the Init function :

api_value Init(napi_env env, napi_value exports)

and the debugger breaks at startup.

However when I'm trying to debug a but other members functions are never breaking

napi_value MyObject::PlusOne(napi_env env, napi_callback_info info) 

registered with :

status = napi_wrap(env, jsthis, reinterpret_cast<void*>(obj), MyObject::Destructor, nullptr, &obj->wrapper_)

I tried to launch my addon project with electron.exe as run time, I tried to attach my addon project debugger to the main tread of electron, it still doesn't work.

I'd like the break points to stop in every methods, and understand why it doesn't work at the moment.

1 Answers

0) Install "electron-rebuild" module globally

1) Run this command at the directory of the native module you want to debug. The folder that contains the addons "package.json" file

electron-rebuild --version [CURRENTLY_USED_ELECTRON_VERION] --debug

2) Run your electron app normally

3) Open the Visual Studio project found at the module's build folder.

4) Debug by attaching to all electron processes. In Visual Studio 2019: Debug -> Attach to process -> find your electron.exe processes -> select them all -> press attach

5) Put your breakpoints and now they should hit properly

Related