| View previous topic :: View next topic |
| Author |
Message |
ira
Joined: 14 Dec 2009 Posts: 19
|
Posted: Mon Jul 05, 2010 10:15 am Post subject: best way to debug multithread app? |
|
|
Madshi, my multithread app have an error. The steps to produce error is unknown. The time to produce error is unpredictable. I use MadExcept to find the cause of error. The error is list index out of bounds. Right now MadExcept only show error in thread code. I can't find the bad listview.
| Code: | callstack crc : $838685cf, $05f57280, $3edc7b80
exception number : 1
exception class : EListError
exception message : List index out of bounds (-1).
thread $948 (TMyThread):
0046bb41 +19 Program.exe Classes TList.Get
004772bb +0b Program.exe Contnrs TOrderedList.PeekItem
004772cc +08 Program.exe Contnrs TOrderedList.PopItem
0047721e +02 Program.exe Contnrs TOrderedList.Pop
00477305 +05 Program.exe Contnrs TObjectQueue.Pop
006747a9 +0d Program.exe unitSearch 302 +2 TObjectLockingQueue.Pop
006746aa +52 Program.exe unitSearch 252 +9 TWaitingItemCustomList.Pop
00404b55 +1d Program.exe System 13630 +0 @AfterConstruction
00674d1c +48 Program.exe unitSearch 510 +7 TTaskThread.Create
0067490f +73 Program.exe unitSearch 355 +14 TMyThread.Execute
0045272b +2b Program.exe madExcept HookedTThreadExecute
00475268 +34 Program.exe Classes ThreadProc
004056f4 +28 Program.exe System 13630 +0 ThreadWrapper
0045260d +0d Program.exe madExcept CallThreadProcSafe
00452677 +37 Program.exe madExcept ThreadExceptFrame
>> created by main thread ($ab8) at:
0067480f +23 Program.exe unitSearch 323 +1 TMyThread.Create
main thread ($ab8):
77d49426 +00a USER32.dll WaitMessage
004c5591 +12d Program.exe Forms TApplication.Idle
004c4943 +017 Program.exe Forms TApplication.HandleMessage
004c4c47 +0b3 Program.exe Forms TApplication.Run
00689066 +18e Program.exe Program 163 +60 initialization
thread $b48:
7c90e286 +00a ntdll.dll NtReadFile
7c801873 +061 kernel32.dll ReadFile
004da80d +1e5 Program.exe madCodeHook PipedIpcThread1
0045260d +00d Program.exe madExcept CallThreadProcSafe
00452677 +037 Program.exe madExcept ThreadExceptFrame
>> created by main thread ($ab8) at:
004daa7c +22c Program.exe madCodeHook CreatePipedIpcQueue
thread $860:
7c90e397 +0a ntdll.dll NtReplyWaitReceivePortEx
0045260d +0d Program.exe madExcept CallThreadProcSafe
00452677 +37 Program.exe madExcept ThreadExceptFrame
>> created by main thread ($ab8) at:
77e87675 +00 RPCRT4.dll
thread $bf8:
7c90d85a +0a ntdll.dll NtDelayExecution
7c8023eb +4b kernel32.dll SleepEx
7c802450 +0a kernel32.dll Sleep
0045260d +0d Program.exe madExcept CallThreadProcSafe
00452677 +37 Program.exe madExcept ThreadExceptFrame
>> created by main thread ($ab8) at:
7752fd94 +00 ole32.dll
thread $8e4:
7c90e397 +0a ntdll.dll NtReplyWaitReceivePortEx
0045260d +0d Program.exe madExcept CallThreadProcSafe
00452677 +37 Program.exe madExcept ThreadExceptFrame
>> created by thread $860 at:
77e87675 +00 RPCRT4.dll
thread $978 (TSearchThread):
7c90e9be +00a ntdll.dll NtWaitForSingleObject
7c919016 +087 ntdll.dll RtlpWaitForCriticalSection
7c901046 +041 ntdll.dll RtlEnterCriticalSection
00485c1c +004 Program.exe SyncObjs TCriticalSection.Acquire
00674799 +005 Program.exe unitSearch 289 +0 TObjectLockingQueue.Lock
006747c4 +008 Program.exe unitSearch 308 +1 TObjectLockingQueue.Push
006746ea +006 Program.exe unitSearch 264 +1 TWaitingItemCustomList.Push
00674b8b +003 Program.exe unitSearch 469 +0 TWaitingItemList.Push
0067ed02 +526 Program.exe uMain 4346 +88 TForm1.FindFileFileMatch
005eb037 +0cf Program.exe FindFile 1558 +12 TFindFile.DoFileMatch
005eb3b9 +181 Program.exe FindFile 1663 +22 TFindFile.SearchIn
005eb50b +2d3 Program.exe FindFile 1684 +43 TFindFile.SearchIn
005eb227 +043 Program.exe FindFile 1631 +7 TFindFile.SearchForFiles
005eadf4 +02c Program.exe FindFile 1490 +3 TSearchThread.Execute
004056f4 +028 Program.exe System 13630 +0 ThreadWrapper
0045260d +00d Program.exe madExcept CallThreadProcSafe
00452677 +037 Program.exe madExcept ThreadExceptFrame
>> created by main thread ($ab8) at:
005ead8b +01f Program.exe FindFile 1480 +1 TSearchThread.Create
thread $870:
7c90e397 +0a ntdll.dll NtReplyWaitReceivePortEx
0045260d +0d Program.exe madExcept CallThreadProcSafe
00452677 +37 Program.exe madExcept ThreadExceptFrame
>> created by thread $860 at:
77e87675 +00 RPCRT4.dll |
Maybe you can read those lines above for me, or is there any better way to debug multithread app? |
|
| Back to top |
|
 |
moz
Joined: 07 Jul 2010 Posts: 1
|
Posted: Wed Jul 07, 2010 5:14 am Post subject: |
|
|
I'm guessing that something is trying to read from the TObjectLockingQueue while the TMyThread is popping stuff out of it.
Two options spring to my mind: try to exactly localise the error and fix only that problem; or look at the architecture to see what problems you have, and fix them systematically. I hope that's biased enough that you can see what I think you should do :)
To find the exact error what I would do is start wrapping list accesses in my own exceptions: try...except raise EMyException.Create(Exception, 'what I am doing now') end;
That way at least you will get a better idea of what exactly was happening when the error occurred. But the real answer is to start with a good idea of what your threads are doing and make sure that object ownership is very, very clear. It's ok to transfer objects between threads (conceptually, in reality a few objects are thread-bound), you just have to be sure that you're not doing conflicting things in different threads at the same time. |
|
| Back to top |
|
 |
ira
Joined: 14 Dec 2009 Posts: 19
|
Posted: Wed Jul 07, 2010 6:55 am Post subject: |
|
|
Thanks moz. This is confusing me, that's way I use MadExcept to find the error
Anyway, I guess EStringList is caused by TStringList, what about EListError? Is it same? There are many TStringLisy in my code and they are thread-safe already. Maybe using locklist is not enough  |
|
| Back to top |
|
 |
madshi Site Admin
Joined: 21 Mar 2004 Posts: 5908
|
Posted: Wed Jul 07, 2010 9:38 am Post subject: |
|
|
This line seems to be causing the exception:
| Code: | | 006747a9 +0d Program.exe unitSearch 302 +2 TObjectLockingQueue.Pop |
My best guess is that multiple threads are accessing this TObjectLockingQueue at the same time and that TObjectLockingQueue is not fully thread safe. You may need to synchronize access to this object locking queue, e.g. by using a critical section. |
|
| Back to top |
|
 |
ira
Joined: 14 Dec 2009 Posts: 19
|
Posted: Thu Jul 08, 2010 3:26 am Post subject: |
|
|
Thanks Madshi for your reply.
Its seems there is a non thread safe somewhere in my component. I"ll have to digging it. Thanks. |
|
| Back to top |
|
 |
|