Recent

Author Topic: A problem caused this program to stop interacting with Windows.  (Read 8793 times)

engkin

  • Hero Member
  • *****
  • Posts: 2958
Re: A problem caused this program to stop interacting with Windows.
« Reply #15 on: August 12, 2021, 08:22:09 am »
Compile with -al in the custom options and check the generated assembly file.

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #16 on: August 12, 2021, 11:02:24 am »
after do more testing, there still has cross-thread deadlock happen, but this time, no exception was generated.
still, it is not always happens.

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #17 on: August 13, 2021, 05:10:27 pm »
more testing, if remove the .free part of loop, application will close normally, but sometime has a thread that not terminated. living in background. a zombie process.

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #18 on: August 24, 2021, 02:16:20 am »
i am trying to using windbg for hanging dump file, but it looks that FPC dbg file not fit into windbg, is there any
converter that can do this? convert the symbol table of FPC to windbg need

440bx

  • Hero Member
  • *****
  • Posts: 2503
Re: A problem caused this program to stop interacting with Windows.
« Reply #19 on: August 24, 2021, 11:50:59 am »
... it looks that FPC dbg file not fit into windbg, is there any converter that can do this? convert the symbol table of FPC to windbg need
I'm not sure what I'm going to mention is what you're asking for but, just in case, FPC outputs debug information in DWARF format.  WinDbg uses MS' PDB format.  There is a utility named "cv2pdb" that converts from DWARF to PDB (google it, it's on github)

cv2pdb works well on 64bit exes (produced by FPC), I haven't gotten it to work with 32bit exes.  Also, the conversion is good enough for someone who is comfortable with assembler because there is quite a bit of DWARF info that cv2pdb does not convert to PDB.  IOW, there is a fair amount of information lost, locals among other things but, in spite of that, the result is very usable.

HTH.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #20 on: August 25, 2021, 05:59:09 pm »
thanks, but i got XXX.dbg: no codeview debug entries found
that download from  Npackd.org
i had try to build from dwarf or dwarf2

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #21 on: August 26, 2021, 01:00:53 am »
ok, finally, i got the point, that's cannot use: external debug  info file

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #22 on: September 17, 2021, 05:14:54 pm »
after i reproduce, but not all the time, it most of time show me this when program hangup on clicking "close" icon on windows
before i click close, if i move over minimize and/or maximize, left the window, and back to click close. 
it shows me on windbg after i use !analyze -v -hang
Code: Pascal  [Select][+][-]
  1. 00000000`013ff358 00007fff`0e3d379d : 00000000`013ff560 00007fff`0dfbeb96 00000000`00000014 00000000`00000001 : ntdll!ZwWaitForAlertByThreadId+0x14
  2. 00000000`013ff360 00007fff`0e3d3652 : 00000000`00000000 00000000`00000000 00000000`013ff448 00000001`004dc148 : ntdll!RtlpWaitOnAddressWithTimeout+0x81
  3. 00000000`013ff390 00007fff`0e3d346d : 00000001`004dc140 00000000`00001722 00000000`00000000 00007fff`0c24e1a0 : ntdll!RtlpWaitOnAddress+0xae
  4. 00000000`013ff400 00007fff`0e39fcb4 : 00000000`0000000f 00000000`00000000 00000000`fffffffa 00007fff`0e152ccd : ntdll!RtlpWaitOnCriticalSection+0xfd
  5. 00000000`013ff4e0 00007fff`0e39fae2 : 00000000`00000000 00000000`01645200 00000000`06439398 ffffffff`f0011bb1 : ntdll!RtlpEnterCriticalSectionContended+0x1c4
  6. 00000000`013ff540 00000001`0001341a : 00000000`013ff5b0 00000001`000c81bb ffffffff`ca01164a 00000000`00000000 : ntdll!RtlEnterCriticalSection+0x42
  7. 00000000`013ff570 00000001`00012a6b : 00000000`0085000f ffffffff`f0011bb1 00000000`013ff6f0 00007fff`0e3c07b0 : CodaMinaTelnet!main+0x106fa
  8. 00000000`013ff5a0 00000001`00011f39 : 00000000`0049414e 00000000`016183c0 00000000`013ff6f0 00000001`000f8c5d : CodaMinaTelnet!main+0xfd4b
  9. 00000000`013ff5d0 00000001`00012049 : 00000000`00000000 ffffffff`f0011bb1 00004331`00000000 00000001`00000000 : CodaMinaTelnet!main+0xf219
  10. 00000000`013ff610 00000001`00012173 : 00000001`00000000 00000001`00012eef 00000001`00000000 00000000`00000000 : CodaMinaTelnet!main+0xf329
  11. 00000000`013ff650 00000001`000111eb : 00000000`000002d1 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0xf453
  12. 00000000`013ff6a0 00000001`00008fd9 : 00000000`00000001 00000001`00012eef 00000000`01669890 00000001`0016881b : CodaMinaTelnet!main+0xe4cb
  13. 00000000`013ff6d0 00000001`0000fce8 : 00000000`00000000 00000000`80007811 00000000`013ff770 00000001`00168a89 : CodaMinaTelnet!main+0x62b9
  14. 00000000`013ff700 00000001`0000fb07 : ffffffff`ffffffff 00000000`01669890 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0xcfc8
  15. 00000000`013ff740 00000001`0000fd8c : 00000000`01669890 00000001`001683d9 00000000`013ff869 00000000`01669890 : CodaMinaTelnet!main+0xcde7
  16. 00000000`013ff790 00000001`00168491 : 00000000`0000000f 00000001`000485c5 00004331`f08042ca 00000001`0001364a : CodaMinaTelnet!main+0xd06c
  17. 00000000`013ff7d0 00000001`000481c4 : 00000000`00000011 00000000`80007811 00000000`013ff930 00000000`06439220 : CodaMinaTelnet!MAINTHREADWRITE+0xa1 [lazlogger.pas @ 242]
  18. 00000000`013ff820 00000001`0004870a : 00000000`00000000 00000000`00000000 00000000`00000220 00000000`00000000 : CodaMinaTelnet!FPCADDS_$$_init$+0x8ef4
  19. 00000000`013ff850 00000001`000fc010 : 00000000`0000000f 00000000`00000000 00000000`013ff930 00000001`00011192 : CodaMinaTelnet!FPCADDS_$$_init$+0x943a
  20. 00000000`013ff8c0 00000001`000fdc67 : 00000001`001d8af0 00000000`00000001 00000000`00000048 00007fff`00000001 : CodaMinaTelnet!DOWINDOWPROC+0x6c0 [win32\win32callback.inc @ 1993]
  21. 00000000`013ff9b0 00007fff`0dfbe858 : 00000000`00000000 00000000`00000001 00000000`00000001 00000000`00000000 : CodaMinaTelnet!WINDOWPROC+0x77 [win32\win32callback.inc @ 2676]
  22. 00000000`013ffa10 00007fff`0dfbe299 : 00000000`00000000 00000001`000fdbf0 00000000`00150cd4 00000000`00000000 : user32!UserCallWinProcCheckWow+0x2f8
  23. 00000000`013ffba0 00000001`000fed8e : 00000001`000fdbf0 00000000`00000000 00000000`013ffef0 00000000`013ffef0 : user32!DispatchMessageWorker+0x249
  24. 00000000`013ffc20 00000001`0002acf7 : 00000000`013ffda0 00000000`016183c0 00000000`016183c0 00000000`015e5a01 : CodaMinaTelnet!APPPROCESSMESSAGES+0xfe [win32\win32object.inc @ 399]
  25. 00000000`013ffd40 00000001`0002b1e7 : 00000000`00000000 00000000`0161ae60 00000000`016183c0 00000000`016183c0 : CodaMinaTelnet!HANDLEMESSAGE+0x27 [include\application.inc @ 1281]
  26. 00000000`013ffd80 00000001`00037e18 : 00000000`00000001 00000000`0161ae60 00000000`015e5a60 00000000`0161ae60 : CodaMinaTelnet!RUNLOOP+0x27 [include\application.inc @ 1416]
  27. 00000000`013ffdc0 00000001`0002b1b6 : 00000000`013ffe70 00000001`000107dc 00000000`0161ae60 00000001`00000000 : CodaMinaTelnet!APPRUN+0x28 [include\interfacebase.inc @ 55]
  28. 00000000`013ffe00 00000001`00002d9a : 00000000`00000000 00000000`00000000 00000000`00000000 00000001`00003635 : CodaMinaTelnet!RUN+0x66 [include\application.inc @ 1406]
  29. 00000000`013ffe50 00000001`00002db6 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x7a [CodaMinaTelnet.lpr @ 21]
  30. 00000000`013ffe80 00000001`000170d0 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x96
  31. 00000000`013ffeb0 00000001`00002d17 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x143b0
  32. 00000000`013fff00 00007fff`0c757034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!public_all+0x1d17
  33. 00000000`013fff30 00007fff`0e3c2651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x14
  34. 00000000`013fff60 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21
  35.  


440bx

  • Hero Member
  • *****
  • Posts: 2503
Re: A problem caused this program to stop interacting with Windows.
« Reply #23 on: September 17, 2021, 06:18:47 pm »
after i reproduce, but not all the time, it most of time show me this when program hangup on clicking "close" icon on windows
before i click close, if i move over minimize and/or maximize, left the window, and back to click close. 
it shows me on windbg after i use !analyze -v -hang
Code: Pascal  [Select][+][-]
  1. 00000000`013ff358 00007fff`0e3d379d : 00000000`013ff560 00007fff`0dfbeb96 00000000`00000014 00000000`00000001 : ntdll!ZwWaitForAlertByThreadId+0x14
  2. 00000000`013ff360 00007fff`0e3d3652 : 00000000`00000000 00000000`00000000 00000000`013ff448 00000001`004dc148 : ntdll!RtlpWaitOnAddressWithTimeout+0x81
  3. 00000000`013ff390 00007fff`0e3d346d : 00000001`004dc140 00000000`00001722 00000000`00000000 00007fff`0c24e1a0 : ntdll!RtlpWaitOnAddress+0xae
  4. 00000000`013ff400 00007fff`0e39fcb4 : 00000000`0000000f 00000000`00000000 00000000`fffffffa 00007fff`0e152ccd : ntdll!RtlpWaitOnCriticalSection+0xfd
  5. 00000000`013ff4e0 00007fff`0e39fae2 : 00000000`00000000 00000000`01645200 00000000`06439398 ffffffff`f0011bb1 : ntdll!RtlpEnterCriticalSectionContended+0x1c4
  6. 00000000`013ff540 00000001`0001341a : 00000000`013ff5b0 00000001`000c81bb ffffffff`ca01164a 00000000`00000000 : ntdll!RtlEnterCriticalSection+0x42
  7.  
Based on the output you posted, the first thought is that the hang is caused by waits which cannot be satisfied (e.g, a deadlock.)

Based on that, I'd run the program under an apispy (there is a good one at rohitab), trap all apis that wait on something and inspect what is waiting on what when the wm_close message is generated.

Another way of finding out if there may be a deadlock would be using Process Hacker and/or Process Explorer.  In that case, once the program is hung - don't terminate it, instead inspect its threads in Hacker/Explorer, if there is a deadlock, under "threads" you'll see two or more threads waiting for something (most likely each other in some way.)

HTH.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #24 on: September 18, 2021, 02:27:18 am »
from windbg, i get locks below.
my program is multithread 1 main UI thread, 1 socket thread,
if let the thread terminated,will cause this, dead lock,
if not. everything goes normal.
socket thread has a Event object that use by thread itself.

from my point is that "CodaMinaTelnet!EXCEPTIONOCCURRED+0x262 [forms.pp @ 1927]
CodaMinaTelnet!main+0x14b9d
"
what cause this exception?
any tools can help?
Code: Pascal  [Select][+][-]
  1. 0:000> !locks
  2.  
  3. *** WARNING: Unable to verify timestamp for CodaMinaTelnet.exe
  4. CritSec CodaMinaTelnet!MURMURHASH3_X86_32 <PERF> (CodaMinaTelnet+0x4dc140)+0 at 00000001004dc140
  5. WaiterWoken        No
  6. LockCount          1
  7. RecursionCount     1
  8. OwningThread       19e4
  9. EntryCount         0
  10. ContentionCount    1
  11. *** Locked
  12.  
  13. Scanned 13 critical sections
  14. 0:000> ~
  15. .  0  Id: 154c.4638 Suspend: 0 Teb: 00000000`002b2000 Unfrozen
  16.    1  Id: 154c.19e4 Suspend: 0 Teb: 00000000`002ba000 Unfrozen
  17.    2  Id: 154c.4d88 Suspend: 0 Teb: 00000000`002bc000 Unfrozen
  18. 0:000> ~1 kv
  19. Child-SP          RetAddr           : Args to Child                                                           : Call Site
  20. 00000000`094e9e98 00000001`000ff28e : 00000000`016183c0 00000000`016183c0 00000000`016183c0 00000000`016183c0 : win32u!ZwUserShowWindow+0x14
  21. 00000000`094e9ea0 00000001`0002a0ae : 00000000`00000000 00000001`0001364a 00000000`015dd1a0 00000000`016183c0 : CodaMinaTelnet!APPSETVISIBLE+0x5e
  22. 00000000`094e9ee0 00000001`0001f03e : 00000000`094eaf70 00000000`094efeb0 00000000`00000001 00000000`094ebb30 : CodaMinaTelnet!UPDATEVISIBLE+0x2e [include\application.inc @ 991]
  23. 00000000`094e9f20 00000001`000237b3 : 00000000`00000062 00000000`094ebb30 00000000`0161ae60 00000000`016183c0 : CodaMinaTelnet!SETVISIBLE+0x7e
  24. 00000000`094e9f60 00000001`0001e34e : 00000000`0161ae60 00000001`0000e286 00004331`f8f12afa 00000000`0000001d : CodaMinaTelnet!HIDE+0x23
  25. 00000000`094e9fa0 00000001`0001e3ca : 00000000`00000000 00000001`00042604 00000000`094ea030 00007fff`0bd024bd : CodaMinaTelnet!BEFOREDESTRUCTION+0x5e [include\customform.inc @ 183]
  26. 00000000`094e9fe0 00000001`0000e09b : 00000000`094efeb0 00000000`094eac00 00000000`094ea080 00007fff`0e3c07b0 : CodaMinaTelnet!DESTROY+0x2a [include\customform.inc @ 198]
  27. 00000000`094ea030 00000001`0002a551 : 00000000`00000000 00000000`064401e0 00000000`01645200 00000000`00000000 : CodaMinaTelnet!main+0xb37b
  28. 00000000`094ea060 00000001`0001af95 : 00000000`00000000 00000000`00000000 00000000`00000062 00000000`094ebb30 : CodaMinaTelnet!DOBEFOREFINALIZATION+0x61
  29. 00000000`094ea0b0 00000001`000109e9 : 00000000`00000020 00000000`094ebb30 00000000`0646af10 00000000`00000062 : CodaMinaTelnet!BEFOREFINALIZATION+0x15
  30. 00000000`094ea0e0 00000001`00010bba : 00000000`06462c40 00000001`00360b40 00000000`094ea270 00000001`00088cd9 : CodaMinaTelnet!main+0xdcc9
  31. 00000000`094ea220 00000001`00010be0 : 00000000`00000000 00000000`00000000 00000000`06462c40 00000001`00360b40 : CodaMinaTelnet!main+0xde9a
  32. 00000000`094ea250 00000001`0001ad4c : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0xdec0
  33. 00000000`094ea280 00000001`000178bd : 00000000`00000000 00000000`00000000 00000000`06439318 00000000`07f5a636 : CodaMinaTelnet!EXCEPTIONOCCURRED+0x5c [forms.pp @ 1915]
  34. 00000000`094ea470 00007fff`0e4121ff : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x14b9d
  35. 00000000`094ea610 00007fff`0e3a0939 : 00000001`00002db6 00000000`094eab90 00000000`00000002 00000000`094eaf70 : ntdll!RtlpExecuteHandlerForUnwind+0xf
  36. 00000000`094ea640 00000001`00017692 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUnwindEx+0x339
  37. 00000000`094ead60 00007fff`0e41217f : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x14972
  38. 00000000`094eaf00 00007fff`0e3c1454 : 00000000`00000000 00000000`094eb470 00000000`094ebb30 00000000`00000000 : ntdll!RtlpExecuteHandlerForException+0xf
  39. 00000000`094eaf30 00007fff`0e410cae : 00000000`00000000 00000000`00000000 00000000`00000300 00000000`00000000 : ntdll!RtlDispatchException+0x244
  40. 00000000`094eb640 00000001`00011de0 : 00000000`00000000 00000001`00012eef 00000000`00000160 00000000`00150cc0 : ntdll!KiUserExceptionDispatcher+0x2e (TrapFrame @ 00000000`094eba68)
  41. 00000000`094ebdf0 00000001`00011f10 : 00000000`094ebee0 00000000`094efde9 00000000`00000002 00000000`094e0000 : CodaMinaTelnet!main+0xf0c0
  42. 00000000`094ebe40 00000001`0001253d : 00000000`00000040 00000000`00000013 00000000`094ebf30 00000001`00011ef2 : CodaMinaTelnet!main+0xf1f0
  43. 00000000`094ebe80 00000001`0001124b : 00000000`04957e10 00000000`094ec008 00000000`094ebf30 00000001`00011192 : CodaMinaTelnet!main+0xf81d
  44. 00000000`094ebec0 00000001`00009f2b : 00000000`07f664d0 00000000`ffffffff 00000000`00000013 00000001`000111cb : CodaMinaTelnet!main+0xe52b
  45. 00000000`094ebef0 00000001`00009734 : 00000000`00000000 00000000`094efde9 00000000`06440138 00000000`06452d78 : CodaMinaTelnet!main+0x720b
  46. 00000000`094ebf40 00000001`0002eae9 : 00000000`00000000 00007fff`0dfd19b1 00000000`00004638 00000000`094ec110 : CodaMinaTelnet!main+0x6a14
  47. 00000000`094ebfe0 00000001`0002eb2d : 00000000`094ec1c0 00000001`000c8703 00000000`094ec1f0 00000001`00061599 : CodaMinaTelnet!DUMPEXCEPTIONCALLSTACK+0x199
  48. 00000000`094ec180 00000001`0002ab9c : 0000000f`00000000 00000000`06452cc0 00000010`06462c40 00000000`06462c40 : CodaMinaTelnet!CUSTOMEXCEPTIONHANDLER+0x1d [mainform.pas @ 172]
  49. 00000000`094ec1d0 00000001`0001af52 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!HANDLEEXCEPTION+0x1ac [include\application.inc @ 1257]
  50. 00000000`094ec240 00000001`000178bd : 00000000`00000000 00000000`00000000 00000000`0643b518 00000000`07f5a636 : CodaMinaTelnet!EXCEPTIONOCCURRED+0x262 [forms.pp @ 1927]
  51. 00000000`094ec430 00007fff`0e4121ff : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x14b9d
  52. 00000000`094ec5d0 00007fff`0e3a0939 : 00000001`00002db6 00000000`094ecb50 00000000`00000002 00000000`094ecf30 : ntdll!RtlpExecuteHandlerForUnwind+0xf
  53. 00000000`094ec600 00000001`00017692 : 00000000`00000000 00000000`00000000 00000000`00000000 00007fff`0e3fed41 : ntdll!RtlUnwindEx+0x339
  54. 00000000`094ecd20 00007fff`0e41217f : 00000001`00017610 00000000`00000000 00000000`00000000 00000000`00000000 : CodaMinaTelnet!main+0x14972
  55. 00000000`094ecec0 00007fff`0e3c1454 : 00000000`00000000 00000000`094ed430 00000000`094edaf0 00000000`00000000 : ntdll!RtlpExecuteHandlerForException+0xf
  56. 00000000`094ecef0 00007fff`0e410cae : 00000000`094ed6a0 00007fff`0afd83f0 00000000`00000680 00007fff`0afd83d0 : ntdll!RtlDispatchException+0x244
  57. 00000000`094ed600 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!KiUserExceptionDispatcher+0x2e
  58.  
  59.  

440bx

  • Hero Member
  • *****
  • Posts: 2503
Re: A problem caused this program to stop interacting with Windows.
« Reply #25 on: September 18, 2021, 03:16:56 am »
from my point is that "CodaMinaTelnet!EXCEPTIONOCCURRED+0x262 [forms.pp @ 1927]
CodaMinaTelnet!main+0x14b9d
"
what cause this exception?
any tools can help?
Without seeing the code, nothing else comes to mind.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 2958
Re: A problem caused this program to stop interacting with Windows.
« Reply #26 on: September 18, 2021, 07:49:40 am »
Just curious:

What do you have around mainform.pas line 172?

In your second post, can you tell us more about l, t, and r?

Do you have an event assigned to the OnTerminate of the thread?


powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #27 on: September 19, 2021, 07:13:41 am »
my recent 2 exception that catch from dump, my thread at last will free event object.
..\..\Crypto\HlpTiger2.pas @ 1005
the line 1005 is the "end" of function
this one doesnt raise Application exception
Code: Pascal  [Select][+][-]
  1. ntdll!ZwWaitForAlertByThreadId+0x14
  2. ntdll!RtlpWaitOnAddressWithTimeout+0x81
  3. ntdll!RtlpWaitOnAddress+0xae
  4. ntdll!RtlpWaitOnCriticalSection+0xfd
  5. ntdll!RtlpEnterCriticalSectionContended+0x1c4
  6. ntdll!RtlEnterCriticalSection+0x42
  7. CodaMinaTelnet!main+0x106fa [..\..\Crypto\HlpTiger2.pas @ 1005]
  8. CodaMinaTelnet!main+0xfd4b [..\..\Crypto\HlpTiger2.pas @ 1005]
  9. CodaMinaTelnet!main+0xf219 [..\..\Crypto\HlpTiger2.pas @ 1005]
  10. CodaMinaTelnet!main+0xf329 [..\..\Crypto\HlpTiger2.pas @ 1005]
  11. CodaMinaTelnet!main+0xf453 [..\..\Crypto\HlpTiger2.pas @ 1005]
  12. CodaMinaTelnet!main+0xe4cb [..\..\Crypto\HlpTiger2.pas @ 1005]
  13. CodaMinaTelnet!main+0x62b9 [..\..\Crypto\HlpTiger2.pas @ 1005]
  14. CodaMinaTelnet!main+0xcfc8 [..\..\Crypto\HlpTiger2.pas @ 1005]
  15. CodaMinaTelnet!main+0xcde7 [..\..\Crypto\HlpTiger2.pas @ 1005]
  16. CodaMinaTelnet!main+0xd06c [..\..\Crypto\HlpTiger2.pas @ 1005]
  17. CodaMinaTelnet!MAINTHREADWRITE+0xa1 [..\..\Crypto\HlpTiger2.pas @ 1005]
  18. CodaMinaTelnet!FPCADDS_$$_init$+0x8ef4 [..\..\Crypto\HlpTiger2.pas @ 1005]
  19. CodaMinaTelnet!FPCADDS_$$_init$+0x943a [..\..\Crypto\HlpTiger2.pas @ 1005]
  20. CodaMinaTelnet!DOWINDOWPROC+0x6c0 [..\..\Crypto\HlpTiger2.pas @ 1005]
  21. CodaMinaTelnet!WINDOWPROC+0x77 [..\..\Crypto\HlpTiger2.pas @ 1005]
  22. user32!UserCallWinProcCheckWow+0x2f8
  23. user32!DispatchMessageWorker+0x249
  24. CodaMinaTelnet!APPPROCESSMESSAGES+0xfe [..\..\Crypto\HlpTiger2.pas @ 1005]
  25. CodaMinaTelnet!HANDLEMESSAGE+0x27 [..\..\Crypto\HlpTiger2.pas @ 1005]
  26. CodaMinaTelnet!RUNLOOP+0x27 [..\..\Crypto\HlpTiger2.pas @ 1005]
  27. CodaMinaTelnet!APPRUN+0x28 [..\..\Crypto\HlpTiger2.pas @ 1005]
  28. CodaMinaTelnet!RUN+0x66 [..\..\Crypto\HlpTiger2.pas @ 1005]
  29. CodaMinaTelnet!main+0x7a [..\..\Crypto\HlpTiger2.pas @ 1005]
  30. CodaMinaTelnet!main+0x96 [..\..\Crypto\HlpTiger2.pas @ 1005]
  31. CodaMinaTelnet!main+0x143b0 [..\..\Crypto\HlpTiger2.pas @ 1005]
  32. CodaMinaTelnet!public_all+0x1d17 [..\..\Crypto\HlpTiger2.pas @ 1005]
  33. kernel32!BaseThreadInitThunk+0x14
  34. ntdll!RtlUserThreadStart+0x21
  35.  
this one raise application exception.
Code: Pascal  [Select][+][-]
  1. ntdll!ZwWaitForAlertByThreadId+0x14
  2. ntdll!RtlpWaitOnAddressWithTimeout+0x81
  3. ntdll!RtlpWaitOnAddress+0xae
  4. ntdll!RtlpWaitOnCriticalSection+0xfd
  5. ntdll!RtlpEnterCriticalSectionContended+0x1c4
  6. ntdll!RtlEnterCriticalSection+0x42
  7. CodaMinaTelnet!main+0x106fa [..\..\Crypto\HlpTiger2.pas @ 1005]
  8. CodaMinaTelnet!main+0xfd4b [..\..\Crypto\HlpTiger2.pas @ 1005]
  9. CodaMinaTelnet!main+0xf219 [..\..\Crypto\HlpTiger2.pas @ 1005]
  10. CodaMinaTelnet!main+0xf329 [..\..\Crypto\HlpTiger2.pas @ 1005]
  11. CodaMinaTelnet!main+0xf453 [..\..\Crypto\HlpTiger2.pas @ 1005]
  12. CodaMinaTelnet!main+0xe4cb [..\..\Crypto\HlpTiger2.pas @ 1005]
  13. CodaMinaTelnet!main+0xa960 [..\..\Crypto\HlpTiger2.pas @ 1005]
  14. CodaMinaTelnet!main+0xd089 [..\..\Crypto\HlpTiger2.pas @ 1005]
  15. CodaMinaTelnet!main+0xcde7 [..\..\Crypto\HlpTiger2.pas @ 1005]
  16. CodaMinaTelnet!main+0xd06c [..\..\Crypto\HlpTiger2.pas @ 1005]
  17. CodaMinaTelnet!main+0xd59f [..\..\Crypto\HlpTiger2.pas @ 1005]
  18. CodaMinaTelnet!main+0xa958 [..\..\Crypto\HlpTiger2.pas @ 1005]
  19. CodaMinaTelnet!main+0xd089 [..\..\Crypto\HlpTiger2.pas @ 1005]
  20. CodaMinaTelnet!CLPED25519_$$_finalize_implicit$+0xb9 [..\..\Crypto\HlpTiger2.pas @ 1005]
  21. CodaMinaTelnet!main+0xdb27 [..\..\Crypto\HlpTiger2.pas @ 1005]
  22. CodaMinaTelnet!main+0xddf2 [..\..\Crypto\HlpTiger2.pas @ 1005]
  23. CodaMinaTelnet!main+0xde9a [..\..\Crypto\HlpTiger2.pas @ 1005]
  24. CodaMinaTelnet!main+0x7f [..\..\Crypto\HlpTiger2.pas @ 1005]
  25. CodaMinaTelnet!main+0x96 [..\..\Crypto\HlpTiger2.pas @ 1005]
  26. CodaMinaTelnet!main+0x143b0 [..\..\Crypto\HlpTiger2.pas @ 1005]
  27. CodaMinaTelnet!public_all+0x1d17 [..\..\Crypto\HlpTiger2.pas @ 1005]
  28. kernel32!BaseThreadInitThunk+0x14
  29. ntdll!RtlUserThreadStart+0x21
  30.  
« Last Edit: September 19, 2021, 08:16:18 am by powerpcer »

powerpcer

  • Jr. Member
  • **
  • Posts: 55
Re: A problem caused this program to stop interacting with Windows.
« Reply #28 on: September 19, 2021, 07:19:47 am »
Code: Pascal  [Select][+][-]
  1. unit ClientThread;
  2. interface
  3. uses
  4.   Types,
  5.   {$ifdef unix}cthreads, {$endif}
  6. {$IFDEF WINDOWS}
  7.   winsock2,windows,
  8. {$ENDIF}
  9.   SysUtils,Classes,dateutils,syncobjs;
  10. const
  11.   BUFSIZE=4096;
  12.   {$IFDEF unix}
  13.     {$DEFINE TSOCKET := Integer}
  14.         {$DEFINE closesocket:=close}
  15.         INVALID_SOCKET = -1;
  16.         SOCKET_ERROR = -1;
  17.   {$ENDIF}
  18. type
  19.  
  20. TCPClientThread = class(TThread)
  21.         public
  22.  
  23.                 mEvent:TEventObject;
  24.                 isWaiting:boolean;
  25.     perhapsbeclosed:boolean;
  26.                 serverhost:string;
  27.                 serverport:integer;
  28.                 isclosed:boolean;
  29.                 procedure ThreadConnectTo(servIP:string;PORT,itimeout:integer);
  30.           function ConnectTo(servIP:string;PORT,itimeout:integer):integer;
  31.     procedure sendOut(data:pbyte;size:integer);
  32.     procedure close();
  33.                 procedure Event(SocketEvent : Integer; iRead:Integer;rcvbuf: pbyte );virtual;abstract;
  34.                 procedure disconnect();virtual;abstract;
  35.                 constructor Create(b:boolean);
  36.                 procedure dodestroy();virtual;abstract;
  37.     procedure doWork();
  38.     procedure doTerminate;override;
  39.                 procedure Logtofile(sfilename:string);
  40.                 procedure hexdump(pin:pbyte;isize:integer);
  41.   private
  42.     timeouts:integer;
  43.   protected
  44.     skt:Integer;
  45.                 doLogs:boolean;
  46.                 logfile:TextFile;
  47.                 locker:TCriticalSection;
  48.                 logfilename:string;
  49.     procedure Execute; override;
  50.                 procedure LogMsg(s:String;const p:pbyte=nil;const psize:integer=0);
  51. end;
  52.  
  53. implementation
  54. function GetIPByName(const Name:String):String;
  55. var
  56.   r:PHostEnt;
  57.   a:TInAddr;
  58. begin
  59.   Result:='';
  60.   r:= gethostbyname(PChar(Name));
  61.   if Assigned(r) then
  62.     begin
  63.       a:=PInAddr(r^.h_Addr_List^)^;
  64.       Result:=inet_ntoa(a);
  65.     end;
  66. end;
  67. procedure TCPClientThread.logMsg(s:String;const p:pbyte=nil;const psize:integer=0);
  68. begin
  69.         if doLogs then
  70.         begin
  71.           locker.Acquire;
  72.     writeln(logfile,s);
  73.                 if p<>nil then
  74.                 begin
  75.       hexdump(@p[0],psize);
  76.                 end;
  77.     flush(logfile);
  78.                 locker.Release;
  79.         end;
  80. end;
  81. procedure TCPClientThread.hexdump(pin:pbyte;isize:integer);
  82. var
  83.         Buff: array [0..16] of byte;
  84.         CountRead,i,j: Integer;
  85.         HexText: array [0..32] of byte;
  86.         HexText2: array [0..16] of byte;
  87. begin
  88.         i:=0;
  89.         while i < isize do
  90.         begin
  91.                 CountRead := 0;
  92.                 HexText[32]:=0;
  93.                 Buff[16]:=0;
  94.                 fillbyte(HexText[0],32,32);
  95.                 fillbyte(Buff[0],16,32);
  96.                 while ((CountRead+i)<isize) and (CountRead<16) do
  97.                 begin
  98.                         Buff[CountRead]:=pin[i+CountRead];
  99.                         inc(CountRead);
  100.                 end;
  101.                 i:=i+CountRead;
  102.                 BinToHex(@Buff, @HexText, CountRead);
  103.     Write(logfile,strpas(@HexText));
  104.     //for y:=CountRead*2+1 to 32 do
  105.     //  Write(logfile,' ');
  106.                 HexText2[16]:=0;
  107.                 fillbyte(HexText2[0],16,32);
  108.     for j := 0 to CountRead-1 do
  109.     begin
  110.       if (Buff[j]>126) or (Buff[j]<32) then
  111.       begin
  112.         Buff[j]:=Byte('.');
  113.       end;
  114.       HexText2[j+1]:=Buff[j];
  115.     end;
  116.     logmsg(strpas(@HexText2));
  117.         end;
  118. end;
  119. procedure TCPClientThread.Logtofile(sfilename:string);
  120. begin
  121.   logfilename:=sfilename;
  122.         if not doLogs then
  123.         begin
  124.         {$I+}
  125.         AssignFile(logFile, logfilename);
  126.         //FileMode := fmOpenWrite;
  127.         Rewrite(logFile);
  128.         logmsg('log start...');
  129.         end;
  130.   doLogs:=true;
  131. end;
  132.  
  133. constructor TCPClientThread.Create(b:boolean);
  134.  
  135. begin
  136.   inherited Create(b);
  137.   Freeonterminate:=false;
  138.         mEvent := TEventObject.Create(nil,true,false,'');
  139.         isWaiting:=false;
  140.         perhapsbeclosed:=true;
  141.         skt:=-1;
  142.   locker:=TCriticalSection.Create;
  143. end;
  144.  
  145. procedure TCPClientThread.ThreadConnectTo(servIP:string;PORT,itimeout:integer);
  146. begin
  147.         serverhost:=servIP;
  148.         serverport:=port;
  149.         mEvent.SetEvent;
  150. end;
  151. function TCPClientThread.ConnectTo(servIP:string;PORT,itimeout:integer):integer;
  152. var
  153.   wsd:WSADATA;
  154.   ret:integer;
  155.   server:sockaddr_in;
  156.   cTimeOut:integer;
  157.   ul,ul1:uint32;
  158.   timeout:Ttimeval;
  159.   r:Tfdset;
  160. begin
  161.   if (WSAStartup(MAKEWORD(2,0),wsd)<0) then
  162.          exit(-11);
  163.   skt:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  164.  
  165.  
  166.   ul := 1;
  167.   ret := ioctlsocket(skt, long(FIONBIO), @ul);
  168.   if(ret<>NO_ERROR) then
  169.          exit(-3);
  170.  
  171.  
  172.   server.sin_family := AF_INET;
  173.   server.sin_port := htons(port);
  174.   server.sin_addr .s_addr := inet_addr(PAnsiChar(GetIPByName(servIP)));
  175.   if (server.sin_addr.s_addr = INADDR_NONE) then
  176.          exit(-1);
  177.  
  178.   ret:=connect(skt,@server,sizeof(sockaddr_in));
  179.  
  180.  
  181.   FD_ZERO(r);
  182.   FD_SET(skt, r);
  183.   timeout.tv_sec := itimeout;
  184.   timeout.tv_usec :=0;
  185.   ret := select(0, nil, @r, nil, @timeout);
  186.   if ( ret <= 0 ) then
  187.   begin
  188.     closesocket(skt);
  189.                 skt:=-1;
  190.     exit(-4);
  191.   end;
  192.  
  193.   ul1 := 0 ;
  194.   ret := ioctlsocket(skt, long(FIONBIO), @ul1);
  195.   if (ret<>NO_ERROR) then
  196.   begin
  197.     closesocket(skt);
  198.                 skt:=-1;
  199.     exit(-5);
  200.   end;
  201.   //writeln(stdout,'connect done skt=',skt);
  202.   perhapsbeclosed:=false;
  203.   result:=0;
  204.         serverhost:=servIP;
  205.         serverport:=port;
  206. end;
  207. procedure TCPClientThread.sendOut(data:pbyte;size:integer);
  208. begin
  209.   send(skt,data,size,0);
  210. end;
  211. procedure TCPClientThread.close();
  212. begin
  213.   if skt>0 then
  214.     closesocket(skt);
  215.         skt:=-1;
  216.         perhapsbeclosed:=true;
  217.        
  218.   //if doLogs then
  219.         //begin
  220.   //  if isclosed=false then
  221.   //    closefile(logFile);
  222.   //end;
  223.         isclosed:=true;
  224. end;
  225. procedure TCPClientThread.Execute;
  226. var
  227.   ustart,uend:Uint32;
  228.   res:integer;
  229.         timeval:TTimeVal;
  230.         BufRev:pbyte;//buffer
  231. begin
  232.   //ustart:=MilliSecondOfTheday(now);
  233.   BufRev:=allocmem(BUFSIZE);
  234.   timeval.tv_sec:=timeouts*1000;
  235.   timeval.tv_usec:=50;
  236.   //res:=setsockopt(skt,SOL_SOCKET,SO_RCVTIMEO,@timeval,sizeof(timeval));
  237.   while Terminated=false do
  238.         begin
  239.           if skt=-1 then
  240.                 begin
  241.                 isWaiting:=true;
  242.                         if Terminated then
  243.                           continue;
  244.                         logmsg('start Waiting..');
  245.       mEvent.WaitFor(INFINITE);
  246.       mEvent.ResetEvent;
  247.                         logmsg('start check Terminated..');
  248.                         if Terminated then
  249.                           continue;
  250.       logmsg('start working..');
  251.                         if skt=-1 then
  252.                         begin
  253.         res:=ConnectTo(serverhost,serverport,5);
  254.                         if res<0 then
  255.                         begin
  256.           logmsg('connect fail..');
  257.                           Event(4,0,nil);
  258.                           continue;
  259.                         end;
  260.                         end;
  261.                         logmsg('connect fail to live..');
  262.                         isWaiting:=false;
  263.                         Event(1,0,nil);
  264.                 end;
  265.           while  (skt>0)   do
  266.     begin
  267.                 res:=recv(skt,BufRev[0],BUFSIZE,0);
  268.                 if (res>0) then
  269.                 begin
  270.                         Event(3,res,@BufRev[0]);
  271.                 end
  272.                 else
  273.                         if (res<=0) then
  274.                 begin
  275.                                 Event(2,res,@BufRev[0]);
  276.                                 disconnect();
  277.                         break;
  278.                 end;
  279.                 end;
  280.   end;//end while true
  281.   logmsg('Terminated..');
  282.   FreeMem(BufRev);
  283.         mEvent.free;
  284.         locker.free;
  285.         dodestroy();
  286.  
  287. end;
  288.  
  289. procedure TCPClientThread.doWork();
  290. begin
  291.   mEvent.SetEvent;
  292.   logmsg('lets working..');
  293.   isWaiting:=false;
  294. end;
  295. procedure TCPClientThread.doTerminate;
  296. begin
  297.   // Signal event to wake up the thread
  298.   CLOSE();
  299.   freeOnTerminate:=true;
  300.   // Base Terminate method (to set Terminated=true)
  301.   Terminate;
  302.         logmsg('lets terminate..');
  303.         mEvent.SetEvent;
  304. end;
  305. end.
  306.  
  307.  

Code: Pascal  [Select][+][-]
  1. type
  2.   ptermrec=^TTermRec;
  3.   TTermRec=record
  4.     r:Prect;
  5.     zorder:integer;
  6.     t:TCodaMinaTerminal;
  7.     mmi:TMenuItem;
  8.   end;
  9. procedure Tmainfrm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  10. var
  11.   l:PTermRec;
  12. begin
  13.   l:=telnet.loopforward();
  14.   i:=telnet.getCount();
  15.   while l<>nil do
  16.   begin
  17.        l^.t.doTerminate();
  18.        //sleep(50);
  19.  
  20.        Dispose(l^.r);
  21.        Dispose(l);
  22.        l:=telnet.loopforward();
  23.   end;
  24.   telnet.Free;
  25. end;
  26.  

 

TinyPortal © 2005-2018