Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug a c++ excel plugin's exception during excel exiting

I have an excel xll plug-in built in c++ (and with the help of xlw), which, runs pretty well except, when excel exits, exception happens occasionally.

My headache is that though it looks like some destructor issue, I can't see where it went wrong.

Excel window just closes then a Windows system error message pops out.

Even if I run it in Visual Studio debug mode, when the exception happened, it's already in the STL c++ code, also I can't see which part of my code, such as a destructor, is the root cause of the failure.

To be precise, Call Stack shows [External Code] -> Excel.Exe -> [External Code] -> MSO.DLL ... repeat... OART.DLL... repeat ... ntdll.cll -> [External Code] -> _cexit() -> common_exit -> __acrt_lock_and_call -> ...

The first step with source visible is exit.cpp in C:\Program Files (x86)\Windows Kits\10\Source\10.0.16299.0\ucrt\startup\exit.cpp,

extern "C" void __cdecl _cexit()
{
    common_exit(0, _crt_exit_full_cleanup, _crt_exit_return_to_caller);
}
like image 316
athos Avatar asked Jul 09 '18 01:07

athos


People also ask

How do I make Visual Studio not stop on exception?

Note: you can uncheck Break when this exception type is thrown directly in the exception handler and continue debugging (press F5 ). Visual Studio will add this exception type to the Exception settings and will remember that it shouldn't break on this exception again.

How to debug exceptions in Visual Studio?

With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions.

How do you debug PowerPoint?

Start the Excel, PowerPoint, or Word add-in projectStart the project by choosing Debug > Start Debugging from the menu bar or press the F5 button.


1 Answers

Have you tried setting a conditional breakpoint in Visual Studio settings to break on any exception (or the specific exception you are getting)? You can enable this just before you exit Excel. This might help track down the problem and give you the call stack in the call stack window when the breakpoint hits.

Also make sure to check if your symbol files (.pdb) are getting loaded for your code and any third party dependencies. Another thing that can help is to specify the Microsoft public symbol servers so that the Microsoft system pdb’s are loaded as well as mentioned in this article.

like image 59
ARau Avatar answered Nov 11 '22 20:11

ARau