MadExcept not detecting crash

delphi package - automated exception handling

MadExcept not detecting crash

Postby rlevis » Tue Dec 09, 2014 7:07 am

I've built my app with MadExcept (4.0.11) fully enabled as I usually do to track down crashes, but something is getting past MadExcept to generate a Windows error box "A problem caused the program to stop working correctly. Windows will close the program..."

I can't debug it without knowing where it is crashing. I've used the Build option in the compiler (Delphi 7).

The app does have some threads and I seem to remember issues with crashes not being trapped by MadExcept in threads sometimes in the past. Is that possible? But it may not be in a thread. Anything I can do?
rlevis
 
Posts: 8
Joined: Wed Aug 08, 2007 12:40 am
Location: New Zealand

Re: MadExcept not detecting crash

Postby madshi » Wed Dec 10, 2014 7:40 am

Usually madExcept catches thread exceptions just fine. Possible reasons for why madExcept might not catch some exceptions in your case:

(1) Your process might be in such a bad state that madExcept can't work properly, anymore. E.g. memory allocation routines might have stopped working. Or some win32 APIs might have stopped working. In such a situation madExcept can't properly work, anymore, either. Such problems could be caused by random memory overwrites, which can be caused by buffer overruns or by writing to already freed memory. It might also be caused by the process running out of addressable memory or out of system resources.

(2) If there's a stack overflow, sometimes madExcept has problems dealing with the situation because the madExcept could then potentially also overflow.

(3) Of course there's always a chance of a bug in madExcept.

Can you please in your project initialization add a call to "madExcept.InstallUnhandledExceptionFilter"? This will slightly increase the chances of catching more crashes, although usually this should work automatically. But it might still be worth a try.

In order to double check that there are no buffer overruns and no accesses to already freed memory in your process, you could use the madExcept "active error search" options on the first page of the madExcept settings dialog. Try activating the "instantly crash on buffer overrun" feature, or maybe also leak reporting. If there's a buffer overrun, madExcept should detect that and instantly raise an exception at the code location which performs the buffer overrun. However, I need to add that these "active error search" features consume A LOT of additional RAM. So if your process is doing a lot of allocations, you might be running out of RAM. If that's the case, you can't use the active error search features, unfortunately. But it's worth a try, in any case.
madshi
Site Admin
 
Posts: 9442
Joined: Sun Mar 21, 2004 5:25 pm

Re: MadExcept not detecting crash

Postby peteness » Thu Dec 25, 2014 7:13 pm

I'm seeing something similar. It's happening on the main thread, and it happens in the debugger, too, so I was able to track down the source.

(1) and (2) don't seem to apply, and madExcept.InstallUnhandledExceptionFilter doesn't help.

In my case, it appears to be happening on a non-visual component with a separately created Windows Handle. Before using the object, it creates a Windows handle by calling FHandle := AllocateHWnd( WndProc ); WndProc is a simple routine that uses Dispatch in the created object, like this:

procedure TMyClass.WndProc(var msg : TMessage);
begin
with msg
do begin
Dispatch(Msg);
Result := DefWindowProc(FHandle, Msg, wParam, lParam);
end;
end;

This class has several message handlers, and if an exception is raised in any of these, the "explosion" happens and the default (ugly) windows crash handler gets invoked instead of the nice MadExcept one.

If I wrap this in a try/except/Application.HandleException(Self) like TTimer does, then the problem goes away.

I'm upgrading an application from Delphi 2007 to Delphi XE7 (running under Windows 8.1), and moving to the latest madExcept while I do it. In the 2007 version, this worked without having to wrap it in a custom handler.

Hopefully that helps get to the root of the problem.

- Pete
peteness
 
Posts: 6
Joined: Sun Mar 14, 2010 8:39 pm

Re: MadExcept not detecting crash

Postby madshi » Tue Jan 20, 2015 8:06 pm

That sounds interesting. Would you be able to create a small test project for me which reproduces this problem? That would be great!
madshi
Site Admin
 
Posts: 9442
Joined: Sun Mar 21, 2004 5:25 pm

Re: MadExcept not detecting crash

Postby jmarder » Tue Sep 12, 2017 8:03 am

I'm seeing the same problem here in my project. It seems that default exception handling of Delphi is not working in this scenario. Has anyone solved this problem?
jmarder
 
Posts: 10
Joined: Tue Sep 12, 2017 8:00 am

Re: MadExcept not detecting crash

Postby madshi » Tue Sep 12, 2017 8:15 am

It's hard to do something if I can't reproduce the problem on my PC. So as I mentioned before, getting a small test project which reproduces the problem would help tremendously to get this fixed.
madshi
Site Admin
 
Posts: 9442
Joined: Sun Mar 21, 2004 5:25 pm

Re: MadExcept not detecting crash

Postby jmarder » Tue Sep 12, 2017 9:01 am

At the end of this blog post there is sample code:
https://marc.durdin.net/2012/09/delphi- ... xceptions/

Is that sufficient?
jmarder
 
Posts: 10
Joined: Tue Sep 12, 2017 8:00 am

Re: MadExcept not detecting crash

Postby madshi » Tue Sep 12, 2017 9:37 am

A full test project would be better, if possible?
madshi
Site Admin
 
Posts: 9442
Joined: Sun Mar 21, 2004 5:25 pm

Re: MadExcept not detecting crash

Postby gerhardsachs » Tue Sep 12, 2017 7:40 pm

I am having the same problem, madExcepts does not show up on exceptions anymore.
The problem occurs on Delphi XE8 running under Windows7 and XE10 Berlin running under Windows10.
Both IDE's run in a VMWare VM.
The newest version is installed on both IDE's, the installation ran normally.
I provided a small demo with two crash buttons.
It's the absolute minimum, just a few standard delphi components.
Exe and mapfile are omitted for size reasons.
On any exception, within or outside the IDE, the standard useless dialogbox shows up.

Gerhard Sachs
Attachments
madExcept.zip
(71.73 KiB) Downloaded 9 times
gerhardsachs
 
Posts: 11
Joined: Tue Jun 29, 2010 3:12 pm

Re: MadExcept not detecting crash

Postby gerhardsachs » Tue Sep 12, 2017 8:17 pm

Now I found the solution in a post from zava (MadExcept Stopped Working in Project).
All of my projects are stored on the Host OS, the VM's just use shared folders.
The folders are treated as networkdrives by Windows and that is the problem in my case.
I chose a local drive for the exe and now madExcept is working again.
It's much better than before, at least I can deliver a software that does'nt leave me in the dark on exceptions.
But its still not ideal, a lot of copying is ncessary.

Gerhard Sachs
gerhardsachs
 
Posts: 11
Joined: Tue Jun 29, 2010 3:12 pm

Re: MadExcept not detecting crash

Postby madshi » Tue Sep 12, 2017 8:42 pm

So the IDE compiles to an EXE file path that is located on a network drive, and that produces the problem?
madshi
Site Admin
 
Posts: 9442
Joined: Sun Mar 21, 2004 5:25 pm

Re: MadExcept not detecting crash

Postby jmarder » Wed Sep 13, 2017 2:37 pm

madshi wrote:A full test project would be better, if possible?


Here it is.
Attachments
Test.zip
Test project for undetected crash.
(6.84 KiB) Downloaded 9 times
jmarder
 
Posts: 10
Joined: Tue Sep 12, 2017 8:00 am

Re: MadExcept not detecting crash

Postby gerhardsachs » Mon Sep 18, 2017 7:13 am

I can speak just for me.
In my case moving the path where the exe is created from a pseudo network drive to a local drive within the VM made madexcept work again.
Pseudo network path means that the path is physically on the PC's harddisk, but the Windows running within the VM treats the path as network drive.
The pseudo network drive is mounted as drive S:, for example, while the loacal drive is C:\localnet\S.
S: is in VMWares terminology a Shared folder.
Creating the exe on s:\Applicationpath blocks madexcept.
Creating the same exe on c:\localnet\s\applicationpath makes madexcept work.

Providing just a demo project is not possible.
The problem is not in the project but in the environment.

Gerhard Sachs
gerhardsachs
 
Posts: 11
Joined: Tue Jun 29, 2010 3:12 pm

Re: MadExcept not detecting crash

Postby madshi » Tue Sep 26, 2017 3:57 pm

Ok, I see 2 different problems here:

1) Network path in a VM. I've tried reproducing this simply by creating a test project on a network path (without a VM). But doing that works just fine, regardless of whether I use the UNC path of the assigned drive letter. So Delphi + madExcept don't have any problem compiling to a network drive. There must be something special that makes things fail within a VM, when writing to a network drive. Maybe some win32 APIs fail in that situation, e.g. maybe memory mapped files don't work? I don't have a VM with Delphi installed in it, so it's hard for me to test.

2) The test program from jmarder is interesting. Basically it shows that crashes inside of a custom "AllocateHwnd()" window proc aren't always caught by madExcept. I've analyzed this problem in detail and it seems that the exception is bypassing all of Delphi's own RTL exception handling somehow, so madExcept never gets access to it, and even Windows's "SetUnhandledExceptionFilter()" API doesn't work. It looks like a bug in the RTL to me, and I don't see any way for me to automatically fix it. Fortunately, the problem seems to be limited to AllocateHwnd(), and it's easy enough to manually solve by adding a "try .. except madExcept.HandleException() end" block around the AllocateHwnd() window proc.

The test project attached by gerhardsachs works for me, but as mentioned above, I've only tested with a simply network drive, not within a VM.
madshi
Site Admin
 
Posts: 9442
Joined: Sun Mar 21, 2004 5:25 pm

Re: MadExcept not detecting crash

Postby jmarder » Wed Sep 27, 2017 6:43 am

madshi wrote:So Delphi + madExcept don't have any problem compiling to a network drive. There must be something special that makes things fail within a VM, when writing to a network drive.


There is a commonly encountered problem, not only for Delphi applications, that if started from a network drive, an external exception may occur if the network connection is interrupted or the machine returns from standby and the network interfaces takes 1-2s to become ready. I recognized that often MadExcept is not able to catch those exception. But I don't see a problem here, because there is nothing wrong with the code and an easy and project-wide fix exists: Add this to your.DPRfile:
Code: Select all
{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP + IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP}

For detailed information see here or google the above flags: http://www.delphipraxis.net/189648-externe-exeption-c0000006.html
jmarder
 
Posts: 10
Joined: Tue Sep 12, 2017 8:00 am

Next

Return to madExcept

Who is online

Users browsing this forum: Google [Bot] and 3 guests