Fog Creek Software
Discussion Board




Debugging C DLLs called from p/Invoke

Is there anyway to debug into the DLL being called from a p/Invoke interface in C# from VS.NET?  It seems it should be possible if there are symbols in the DLL, but I haven't found anyway to do this.

christopher (baus.net)
Thursday, July 08, 2004

<Debugging Strategies for .NET Developers>
by Darin Dillon

redguardtoo
Thursday, July 08, 2004

Don't feel like waiting for a book.  Give me the cliff notes.  If .NET is so easy why do I need a book (http://www.baus.net/archives/000107.html) to do anything? 

Ohh that was troll sorry. 

christopher (baus.net)
Thursday, July 08, 2004

There's an option in your project properties (Configuration Properties\Debugging\Enable Unmanaged Debugging) to be enabled.

See also http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=%22unmanaged+debugging%22

I confess I've just tried it, and it didn't work for me (I've been using unmanaged test applications to debug unmanaged DLLs).

Christopher Wells
Thursday, July 08, 2004

If this dll was a VC 6 DLL. Simply run the exe.  Run MSVC 6 and chose Build-Start Debug-Attach to Process and select your exe.  You will be able to then be able set breakpoints and you will get called when the function is called. 

  If the symbols arent loaded yet because the dll isnt loaded yet- chose Project-Settings-Go to the Debug Tab.  In the drop down, select "Additional Dlls" and add your DLL here.  You should now be able to set breakpoints.

If the DLL was built with .NET the process should be the similar.  Chose Tools/Debug Processes and go from there (sorry, cant give you specifics, but i cant imagine it changed that much)

Mike

MikeG
Thursday, July 08, 2004

Forgot to mention.  When exiting you can save the debug session.  Now you can just run it with this newly created project.  (Make sure you add your dll's in the "Additional DLL" list so that way your symbols will be loaded at startup and you wont have to worry about resetting your breakpoints.)

Mike

MikeG
Thursday, July 08, 2004

The DLL is written C and has been built with VC++ 7.1.  I am able to debug if it is in process (ie a console app), but if I try to attach to the asp.net process, the asp.net process crashes before I can trace into it. 

christopher (baus.net)
Thursday, July 08, 2004

I found this link:
http://blogs.msdn.com/stevejs/archive/2004/05/05/126497.aspx

There are some hints there that may help.  Haven't had the pleasure of this situation in .NET yet.

I've been in similar situations before with 6.0 where attaching to the process crashes the app immediately or doesnt crash anymore/behave the same.  In those situations, I've reverted to brute force- Writing information to a debug file (or output debug string) to pinpoint the line it is crashing on

MikeG
Thursday, July 08, 2004

*  Recent Topics

*  Fog Creek Home