MadExcept into Multithreaded environment.

delphi package - automated exception handling
Post Reply
Greg
Posts: 2
Joined: Mon Jun 13, 2005 7:26 am

MadExcept into Multithreaded environment.

Post by Greg »

Hello,

I've a strange behaviour using madexcept component into a multithreaded app.
If i uncheck then 'handle exception' into 'madexcept settings' my app works well. As soon as i check this option, i get strange error message that follows :

Code: Select all

date/time         : 2005-06-13, 09:26:07, 343ms
computer name     : DEV-GREG
user name         : Greg
operating system  : Windows XP Service Pack 2 build 2600
system language   : French
system up time    : 27 minutes 45 seconds 
program up time   : 2 minutes 15 seconds 
processor         : Intel(R) Pentium(R) M processor 2.00GHz
physical memory   : 637/1023 MB (free/total)
free disk space   : (C:) 23,55 GB
display mode      : 1920x1200, 32 bit
process id        : $cec
allocated memory  : 16,65 MB
executable        : MyApp.exe
exec. date/time   : 2005-06-13 09:19
version           : 1.0.3.19
madExcept version : 2.7g
exception class   : EAccessViolation
exception message : Violation d'accès à l'adresse 01CBC756. Ecriture de l'adresse 03546723.

thread $1e0: <priority:-1>
01cbc756 ???                           
0044e5ec MyApp.exe Classes    9379 ThreadProc
00405214 MyApp.exe System    11554 ThreadWrapper
004297ff MyApp.exe madExcept       ThreadExceptFrame

main thread ($c64):
7c91eb94 ntdll.dll                    KiFastSystemCallRet
77d19416 user32.dll                   WaitMessage
004c7b49 MyApp.exe Forms     7246 TApplication.Idle
004c6ed6 MyApp.exe Forms     6892 TApplication.HandleMessage
004c7162 MyApp.exe Forms     6976 TApplication.Run
005fb0fc MyApp.exe MyApp   51 initialization

thread $cf0 (cIdxMaker): <priority:-1>
7c91eb94 ntdll.dll                        KiFastSystemCallRet
7c91d85a ntdll.dll                        NtDelayExecution
7c8023e7 kernel32.dll                     SleepEx
7c80244c kernel32.dll                     Sleep
005e00f8 MyApp.exe Classes_User  6380 cIdxMaker.Execute
0042986a MyApp.exe madExcept          HookedTThreadExecute
0044e5a6 MyApp.exe Classes       9372 ThreadProc
00405214 MyApp.exe System       11554 ThreadWrapper
004297ff MyApp.exe madExcept          ThreadExceptFrame
>> created by main thread ($c64) at:
005def78 MyApp.exe Classes_User  6100 cIdxMaker.Create

thread $d04 (TIdUDPListenerThread):
7c91eb94 ntdll.dll                          KiFastSystemCallRet
7c91e9be ntdll.dll                          NtWaitForSingleObject
719e150a WS2HELP.dll                        WahReferenceContextByHandle
719f2e64 WS2_32.dll                         select
00533dbd MyApp.exe IdStackWindows   276 TIdStackWindows.WSSelect
0053816e MyApp.exe IdUDPServer      197 TIdUDPListenerThread.Run
0053718c MyApp.exe IdThread         137 TIdThread.Execute
0042986a MyApp.exe madExcept            HookedTThreadExecute
0044e5a6 MyApp.exe Classes         9372 ThreadProc
00405214 MyApp.exe System         11554 ThreadWrapper
004297ff MyApp.exe madExcept            ThreadExceptFrame
>> created by main thread ($c64) at:
005372ab MyApp.exe IdThread         167 TIdThread.Create

thread $80c (cUDPSender):
7c91eb94 ntdll.dll                           KiFastSystemCallRet
7c91d85a ntdll.dll                           NtDelayExecution
7c8023e7 kernel32.dll                        SleepEx
7c80244c kernel32.dll                        Sleep
005e7062 MyApp.exe class_generique  2916 cUDPSender.Execute
0042986a MyApp.exe madExcept             HookedTThreadExecute
0044e5a6 MyApp.exe Classes          9372 ThreadProc
00405214 MyApp.exe System          11554 ThreadWrapper
004297ff MyApp.exe madExcept             ThreadExceptFrame
>> created by main thread ($c64) at:
005e6e9a MyApp.exe class_generique  2879 cUDPSender.Create

thread $dac (TIdListenerThread):
7c91eb94 ntdll.dll                                   KiFastSystemCallRet
7c91e9be ntdll.dll                                   NtWaitForSingleObject
719e150a WS2HELP.dll                                 WahReferenceContextByHandle
719f2e64 WS2_32.dll                                  select
00533dbd MyApp.exe IdStackWindows            276 TIdStackWindows.WSSelect
00536c98 MyApp.exe IdSocketHandle            339 TIdSocketHandle.Select
00559a3e MyApp.exe IdServerIOHandlerSocket       TIdServerIOHandlerSocket.Accept
0055bcbf MyApp.exe IdTCPServer               691 TIdListenerThread.Run
0053718c MyApp.exe IdThread                  137 TIdThread.Execute
0042986a MyApp.exe madExcept                     HookedTThreadExecute
0044e5a6 MyApp.exe Classes                  9372 ThreadProc
00405214 MyApp.exe System                  11554 ThreadWrapper
004297ff MyApp.exe madExcept                     ThreadExceptFrame
>> created by main thread ($c64) at:
005372ab MyApp.exe IdThread                  167 TIdThread.Create

thread $c60 (TIdUDPListenerThread):
7c91eb94 ntdll.dll                          KiFastSystemCallRet
7c91e9be ntdll.dll                          NtWaitForSingleObject
719e150a WS2HELP.dll                        WahReferenceContextByHandle
719f2e64 WS2_32.dll                         select
00533dbd MyApp.exe IdStackWindows   276 TIdStackWindows.WSSelect
0053816e MyApp.exe IdUDPServer      197 TIdUDPListenerThread.Run
0053718c MyApp.exe IdThread         137 TIdThread.Execute
0042986a MyApp.exe madExcept            HookedTThreadExecute
0044e5a6 MyApp.exe Classes         9372 ThreadProc
00405214 MyApp.exe System         11554 ThreadWrapper
004297ff MyApp.exe madExcept            ThreadExceptFrame
>> created by main thread ($c64) at:
005372ab MyApp.exe IdThread         167 TIdThread.Create

thread $db8 (tSimpleThread):
7c91eb94 ntdll.dll                          KiFastSystemCallRet
7c91dd07 ntdll.dll                          NtOpenFile
7c80edf4 kernel32.dll                       FindFirstFileExW
7c813592 kernel32.dll                       FindFirstFileA
0042cf60 MyApp.exe SysUtils        4944 FileAge
0042cfc0 MyApp.exe SysUtils        4972 FileExists
005ea2f7 MyApp.exe Classes_Agency   858 cMemoryIndex.CheckDt
005fa567 MyApp.exe u_main          4054 tSimpleThread.Execute
0042986a MyApp.exe madExcept            HookedTThreadExecute
0044e5a6 MyApp.exe Classes         9372 ThreadProc
00405214 MyApp.exe System         11554 ThreadWrapper
004297ff MyApp.exe madExcept            ThreadExceptFrame
>> created by main thread ($c64) at:
005fa496 MyApp.exe u_main          4033 tSimpleThread.Create

thread $e00 (TIdPeerThread):
7c91eb94 ntdll.dll                             KiFastSystemCallRet
7c91e9be ntdll.dll                             NtWaitForSingleObject
719e150a WS2HELP.dll                           WahReferenceContextByHandle
719f2e64 WS2_32.dll                            select
00533d72 MyApp.exe IdStackWindows      272 TIdStackWindows.WSSelect
00536a0b MyApp.exe IdSocketHandle      258 TIdSocketHandle.Readable
00556c9d MyApp.exe IdIOHandlerSocket   193 TIdIOHandlerSocket.Readable
00557bfa MyApp.exe IdTCPConnection     436 TIdTCPConnection.ReadFromStack
00557b1b MyApp.exe IdTCPConnection     404 TIdTCPConnection.ReadBuffer
00557ec3 MyApp.exe IdTCPConnection     496 TIdTCPConnection.ReadInteger
005f1787 MyApp.exe u_main             1691 TMainFrm.IPServerExecute
0055b45f MyApp.exe IdTCPServer         408 TIdTCPServer.DoExecute
0055c010 MyApp.exe IdTCPServer         796 TIdPeerThread.Run
0055bf06 MyApp.exe IdTCPServer         759 TIdPeerThread.BeforeRun
0053718c MyApp.exe IdThread            137 TIdThread.Execute
0042986a MyApp.exe madExcept               HookedTThreadExecute
0044e5a6 MyApp.exe Classes            9372 ThreadProc
00405214 MyApp.exe System            11554 ThreadWrapper
004297ff MyApp.exe madExcept               ThreadExceptFrame
>> created by thread $dac (TIdListenerThread) at:
005372ab MyApp.exe IdThread            167 TIdThread.Create

thread $540 (cUser):
7c91eb94 ntdll.dll                        KiFastSystemCallRet
7c91d85a ntdll.dll                        NtDelayExecution
7c8023e7 kernel32.dll                     SleepEx
7c80244c kernel32.dll                     Sleep
005da1ad MyApp.exe Classes_User  4218 cUser.Execute
0044e5a6 MyApp.exe Classes       9372 ThreadProc
00405214 MyApp.exe System       11554 ThreadWrapper
004297ff MyApp.exe madExcept          ThreadExceptFrame
>> created by thread $e00 (TIdPeerThread) at:
005cb0a8 MyApp.exe Classes_User   625 cUser.Create

thread $e14 (cIPSender): <priority:-1>
7c91eb94 ntdll.dll                        KiFastSystemCallRet
7c91d85a ntdll.dll                        NtDelayExecution
7c8023e7 kernel32.dll                     SleepEx
7c80244c kernel32.dll                     Sleep
005dc48f MyApp.exe Classes_User  5036 cIPSender.Execute
0042986a MyApp.exe madExcept          HookedTThreadExecute
0044e5a6 MyApp.exe Classes       9372 ThreadProc
00405214 MyApp.exe System       11554 ThreadWrapper
004297ff MyApp.exe madExcept          ThreadExceptFrame
>> created by thread $e00 (TIdPeerThread) at:
005dc245 MyApp.exe Classes_User  4968 cIPSender.Create

thread $c90 (cCopyThread): <priority:-1>
7c91eb94 ntdll.dll                        KiFastSystemCallRet
7c91d85a ntdll.dll                        NtDelayExecution
7c8023e7 kernel32.dll                     SleepEx
7c80244c kernel32.dll                     Sleep
005e09e6 MyApp.exe Classes_User  6552 cCopyThread.Execute
0042986a MyApp.exe madExcept          HookedTThreadExecute
0044e5a6 MyApp.exe Classes       9372 ThreadProc
00405214 MyApp.exe System       11554 ThreadWrapper
004297ff MyApp.exe madExcept          ThreadExceptFrame
>> created by thread $e00 (TIdPeerThread) at:
005e02b1 MyApp.exe Classes_User  6426 cCopyThread.Create

thread $3a0:
>> stack not accessible

thread $1e8:
>> stack not accessible

thread $604:
>> stack not accessible


Under the debugger, here is part of the asm code :

        MOV     EAX,Parameter

        MOV     ECX,[EAX].TThreadRec.Parameter
        MOV     EDX,[EAX].TThreadRec.Func
        PUSH    ECX                                                << FAULT RAISED HERE
        PUSH    EDX
        CALL    _FreeMem
        POP     EDX
        POP     EAX
        CALL    EDX

This kind of exception is raised on each destruction of a 'user thread' (which one is already unavailable in this log).
My App uses Indy Components (UDP and IP).

Have you ever seen this kind of problem before ?
Is there a workaround ( i disable madexcept for the release version at the moment )?

Hope this information may help you.

Greg
Greg
Posts: 2
Joined: Mon Jun 13, 2005 7:26 am

Post by Greg »

Nevermind, i found out the problem.

on the cCopyThread.destroy method, i didn't call "inherited" at the end of the procedure.

Now the bug has gone :)

Greg
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, sometimes madExcept brings exceptions to the light of day, which were always there, but hidden.
Post Reply