Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 Discussions

How to debug a DLL called from an external program

eos_pengwern
Beginner
743 Views

Hello,

I'm afraid you may consider this question somewhat basic, but it has stumped me so far.

How do I connect the debugger to a routine which is called from an external program (in my case, MATLAB)? All I can find in the debugger help file is a description of how to connect the debugger to a running process by finding its pid. However, I can't see how to find a pid for a process which only runs for a fraction of a second between when MATLAB calls it and when it finishes and sends back the result.

So far I've been putting code into my DLL to pop up a console window from within the function and interact directly with the user that way. However, the routine I'm writing has reached a level of complexity where I feel the need for something more sophisticated...

0 Kudos
5 Replies
Steven_L_Intel1
Employee
743 Views
This is easy but not obvious.

In your DLL project, go to the project properties, then Debugging. The Command property will be blank - fill this in with the complete path to the executable (MATLAB.exe, etc.) you want to run. You can also set the working directory if you choose.

Set a breakpoint in your DLL routine and then click the Go button to start debugging. MATLAB will run, and when it calls your DLL, you'll get the breakpoint.
0 Kudos
eos_pengwern
Beginner
743 Views

Thank you. I'm afraid, though, that what happens when I try this is that on pressing the 'Go' button a dialog box pops up saying "Debugging information for matlab.exe cannot be found or does not match. No symbols loaded. Do you want to continue debugging?' On selecting 'Yes', Matlab is booted-up automatically (as I'd hoped) but from that point on it runs just as if I wasn't in debug mode: breakpoints are just sailed past.

After one or two false starts, I've made sure that MATLAB is loading the DLL straight from the compiler's own Debug directory which contains the latest compilation of the DLL and the associated pdb file etc.

Am I missing something?

0 Kudos
Steven_L_Intel1
Employee
743 Views
Hmm. The initial message is fine and can be ignored. Most of the time the other problem is that a different DLL is being loaded than the one in the project. This can be tricky to get right. I have done this many times so I know that it fundamentally works.
0 Kudos
eos_pengwern
Beginner
743 Views

I'll persevere, and come back with a further question if I'm still not successful. Thank you.

0 Kudos
eos_pengwern
Beginner
743 Views

In the end I couldn't get things to work as described. However, I tried instead connecting to the pid of the main MATLAB process before it called the DLL, and this worked fine. When MATLAB subsequently called the DLL, it stopped at the breakpoint and opened up the debugger just as I'd hoped.

0 Kudos
Reply