It is currently April 26th, 2024, 4:32 am

How do you debug a plug-in in Visual Studio?

Share and get help with Plugins and Addons
UpDryTwist
Posts: 4
Joined: May 14th, 2013, 10:05 pm

How do you debug a plug-in in Visual Studio?

Post by UpDryTwist »

I've been trying various things, and can't seem to get breakpoints to show up in the Visual Studio (2010) debugger.

1. Build with Debug settings

2. Copy .dll and .pdb to plug-in directory (or, alternatively, set that directory as output directory)

3. Start debugger with rainmeter.exe as the executable

... the .dll loads and executes, but my breakpoints are never hit (and in the debugger, it says that there are no symbols loaded for the current source file).

Is there a guide to debugging somewhere? Any tips?
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: How do you debug a plug-in in Visual Studio?

Post by poiru »

Here's how:
  • In Visual Studio, right-click on your plugin project → PropertiesConfiguration PropertiesDebugging. Set the Command field to the full path of Rainmeter.exe
  • Set the output directory of your plugin project to your Rainmeter plugin directory.
  • Build the project with a debug configuration. Make sure that the plugin DLL and PDB files are in the Rainmeter plugin directory.
Assuming that your plugin project is the startup project (right-click on the project → Set as StartUp Porject), you should now be able to press F5 (or Start Debugging) and your breakpoints should be hit. Let me know how it works out.
UpDryTwist
Posts: 4
Joined: May 14th, 2013, 10:05 pm

Re: How do you debug a plug-in in Visual Studio?

Post by UpDryTwist »

Thanks! I'd been following the exact steps above, without success. I finally figured it out -- I was using the old plug-in model. When I rewrote the plug-in to the new API, debugging started working. I assume it had something, then, to do with the DLL load process.
UpDryTwist
Posts: 4
Joined: May 14th, 2013, 10:05 pm

Re: How do you debug a plug-in in Visual Studio?

Post by UpDryTwist »

Sorry ... I spoke too soon. I'm still not able to set a breakpoint, and am being asked for an .il file by the debugger (suggesting that the DLL doesn't have symbols?). Frustrating. If I solve it, I'll post solution back here.

EDIT: I should note that I'm using C#, not C++. So I suspect that the problem is that DllExporter is mangling something (?).

EDIT: That's definitely the case. When I rebuilt DllExporter to not delete the .il file at the end, I now wind up in the disassembled DLL in the debugger.

For your instructions, above ... does that just apply to C++ plugins? Is it possible to debug a C# plugin?

SUCCESS! The problem is that DllExporter, which is disassembling then reassembling the C# DLL in order to put in an entry point that can be called from Rainmeter, is losing the source line information. A simple change fixes it: Grab the DllExporter code (from the Rainmeter project on github), and modify the disassembler (ildasm) line to include " /linenum " as a disassembler option. Rebuild DllExporter, and ensure that you're using the new executable. Voila -- between that and the general debugging instructions above, it works!

Poiru: is there a way to get this added to the Rainmeter API source (for debug versions only)?
UpDryTwist
Posts: 4
Joined: May 14th, 2013, 10:05 pm

Re: How do you debug a plug-in in Visual Studio?

Post by UpDryTwist »

Is it possible that the entire Rainmeter.API interface is super thread-unsafe? I seem to be having re-entrancy problems when calling things like api.ReadString() that trash the original api reference. Is this an unstable interface?
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: How do you debug a plug-in in Visual Studio?

Post by poiru »

UpDryTwist wrote:Is it possible that the entire Rainmeter.API interface is super thread-unsafe?
Yes, unfortunately it is not thread-safe. From the wiki:
Rainmeter.API class - Implements methods to query and control Rainmeter. The API.Log method is the only thread-safe function -- other methods should not be called in secondary threads.
I recommend your read and store everything you need in the Measure.Reload method and then pass the stored data to your thread(s). You will need to handle synchronization yourself.
UpDryTwist wrote:SUCCESS! The problem is that DllExporter, which is disassembling then reassembling the C# DLL in order to put in an entry point that can be called from Rainmeter, is losing the source line information. A simple change fixes it: Grab the DllExporter code (from the Rainmeter project on github), and modify the disassembler (ildasm) line to include " /linenum " as a disassembler option. Rebuild DllExporter, and ensure that you're using the new executable. Voila -- between that and the general debugging instructions above, it works!

Poiru: is there a way to get this added to the Rainmeter API source (for debug versions only)?
Great! I will include your fix in the SDK. Do you want me to commit the change in your name? (If so, can you PM your name and email?)
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: How do you debug a plug-in in Visual Studio?

Post by poiru »

UpDryTwist wrote:Poiru: is there a way to get this added to the Rainmeter API source (for debug versions only)?
Your fix has been committed. Thanks!