How to debug plugins during development?
What is the best way to get debug output while developing plugins? I am new to Notepad++ plugin development, and can’t seem to find any good way to debug my plugin. I am writing it in C++ in Visual Studio 2015. Any advice would be appreciated, Thanks!
I have no experience with c++, so I don’t know whether my advise is of any help for you.
When I’m using dot.net (sharpevelop), I redirect the output path of the dll to the plugins directory
of a test npp installation (a zipped one) and add that external program npp should be started when debugging.
When you say “debug output” you mean like something “nicer” than logging data to a file? If so what I’ve used in the past is OutputDebugString(). I’m not sure what Windows does with this internally but you can use a small application from Windows called DebugView and it will show those messages being logged in real time.
Take a look at the GEDCOM Lexer plugin, specifically the
DebugTrace.cppfiles that nicely wrap that function and can easily be “turned off” in release mode. You can see it being used through that plugin’s code.
MessageBox is rather primitive, but quite effective. I wrote a debugging function mprintf with the same arguments as printf, which formats a buffer using sprintf and then passes it to MessageBox.
Unless the change of focus resulting from the display of the message box interferes with your work, this should help.
You can also do source-level debugging.
Build a debug version of your DLL and put it in the NPP plugins directory. Then, after you start up NPP, Go to Visual Studio and select Debug->Attach To Process… and then find the instance of NPP you just started and select it.
Now you can set breakpoints in your plugin and debug away. :-)
To make the source level debugging easier you can also set a post-build event to copy the DLL to the plugins directory and set the N++ exe as the command to run when debugging. After that is as simple as pressing
Nice. I had no idea it could be so easily done. Thanks for the tip.