ConditionRacer
ConditionRacer

Reputation: 4498

Catching abort()

I'm referencing a c++ COM library in a WPF application whose code has unfortunately been lost. I'm pretty sure the library is calling abort() or doing something that's causing the process to die. Is there a way to catch something like this so I can log and/or troubleshoot?

Edit: The specific error I'm getting is:

Microsoft Visual C++ Runtime Library
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Then the process quits.

Upvotes: 1

Views: 218

Answers (2)

Medinoc
Medinoc

Reputation: 6618

To "catch" the abort, you can outright put a breakpoint in abort(), I think. Have your initialization code reference it in some way (function pointer, etc.) to get its address, then jump to this address on the disassembly window to put a breakpoint there.

Upvotes: 1

Servy
Servy

Reputation: 203842

If you're referencing a library that is (intentionally or not) bringing down the entire process, your first goal should obviously be to avoid the situation. Look for patches, alternative references, fix the reference (if that's possible), etc. Consider the possibility that the library is being fed bad data, or if there is in some other way to avoid having it crash in the first place through proper use of said library. This is a bad position to be in, and may well be a sign that even if you could recover from this, your program is very likely to be in a state in which you wouldn't want to.

Your best bet when working with a library such as this, assuming you have no choice in the matter, is to run it in an entirely separate process. Spin up a worker process and use some form of inter process communication to have it send back the results of whatever you're having the library do. This way the library will only ever take down this worker process, and you can be at least moderately safe in terms of knowing that your main process is in a state in which continuing on is a valid option.

Upvotes: 3

Related Questions