Debugging mixed DLL called from legacy code

M

Max Christian

I'm writing a mixed-mode C++ DLL which is used by an old C++
application that I don't have the source code to. I'm amazed by the
ease of interoperability, but the one problem I'm having is debugging
the DLL, as the C++ app crashes if loaded into the debugger.

If I could just get the line number on which an exception occurred
that would be enough to fix most bugs. At the moment I use
exception.ToString() and get a stack trace but it's very hard to find
the bug in a large function without knowing which line.

Anyone have any tips, either on how to get the legacy app to run under
the debugger (so I can step through my DLL when called), or get the
line number an exception occurred on?

Many thanks indeed,

Max Christian
 
W

William DePalo [MVP VC++]

Max Christian said:
I'm writing a mixed-mode C++ DLL which is used by an old C++
application that I don't have the source code to. I'm amazed by the
ease of interoperability, but the one problem I'm having is debugging
the DLL, as the C++ app crashes if loaded into the debugger.
...
Anyone have any tips, either on how to get the legacy app to run under
the debugger (so I can step through my DLL when called), or get the
line number an exception occurred on?

Well, if you can't run under the debugger can you put a DebugBreak() line at
some point when your DLL gets invoked and step through from there?

Still, I'm not sure I understand what crashes when. The crash occurs only
when you debug?

Did you

1) build the DLL with VS.Net?
2) specify the "legacy" executable in the "command"
edit box on the Debugging properties page
3) launch the executable by starting the debugger

Is that the sequence that crashes? Does it crash immediately?

Regards,
Will
 
M

Max Christian

William DePalo said:
Well, if you can't run under the debugger can you put a DebugBreak() line at
some point when your DLL gets invoked and step through from there?

Unfortunately that causes the C++ app to crash immediately, which
surprised me as it's obviously my code that's running when
DebugBreak() is called.
Still, I'm not sure I understand what crashes when. The crash occurs only
when you debug?

Yes, only when debugging. I do exactly the three things you've listed
below (using VS.NET 2003), I get a warning about no debug info in EXE,
I click OK to debug anyway, and then I get this msg box:

"The application failed to initalize properly (0xc0000142). Click on
OK to terminate the application."

As I say, the app works fine when not under the debugger.

M
Did you

1) build the DLL with VS.Net?
2) specify the "legacy" executable in the "command"
edit box on the Debugging properties page
3) launch the executable by starting the debugger

(Yes, I did all of those.)
 
M

Max Christian

William DePalo said:
Did you

1) build the DLL with VS.Net?
2) specify the "legacy" executable in the "command"
edit box on the Debugging properties page
3) launch the executable by starting the debugger

I've found an answer to this -- I changed the Debugger Type from Auto
to Managed Only in Configuration Properties|Debugging and now it
works. (It crashes as before under both the Mixed and Native Only
modes.)

I hope that's useful to a future googler...

M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top