[英]delphi dll-finalization: how to debug
I have a problem in a dll (including a COM object): when the dll is unloaded some finalization sections are executed and some are not. 我在dll(包括COM对象)中遇到问题:卸载dll时,会执行某些完成部分,而某些则不会。
in the debugger I could manage to locate the problem in System FinalizeUnits(). 在调试器中,我可以设法在System FinalizeUnits()中定位问题。 pseudo code of this function - for your convenience:
此函数的伪代码-为了您的方便:
procedure FinalizeUnits;
var
Count: Integer;
Table: PUnitEntryTable;
P: Pointer;
begin
if InitContext.InitTable = nil then
exit;
Count := InitContext.InitCount;
Table := InitContext.InitTable^.UnitInfo;
try
while Count > 0 do
begin
Dec(Count);
InitContext.InitCount := Count;
P := Table^[Count].FInit;
if Assigned(P) and Assigned(Pointer(P^)) then
begin
// ISSUE: when this is called for item x the debugging just stops
// breakpoints in the except block or at the end of the function are not reached!
TProc(P)();
end;
end;
except
FinalizeUnits; { try to finalize the others }
raise;
end;
end;
there is one specific finalization call that causes the problem: 有一个特定的完成调用会导致此问题:
ie the InitContext.InitCount
is about 400 and when item x (eg 363) is executed, the debugger just stops: it does not proceed to the except block and also not to the end of the FinalizeUnits()
function (where I have set breakpoints). 也就是说,
InitContext.InitCount
大约为400,并且在执行项x(例如363)时,调试器只是停止:它不会继续执行except块,也不会继续执行FinalizeUnits()
函数的末尾(在该处我已设置断点) )。
BTW: how is that possible? 顺便说一句:那怎么可能? I thought the except block (or the line after it) must be called in any case.
我认为在任何情况下都必须调用except块(或其后的行)。
notes: 笔记:
TProc
I end up in TCriticalSection.Enter
(then Acquire
- FSection.Enter
- EnterCriticalSection
- WSACleanup
) TProc
我最终进入TCriticalSection.Enter
(然后, Acquire
FSection.Enter
- EnterCriticalSection
- WSACleanup
) some more info to the WSACleanup
call: I use a 3rd party library UniDAC that opens a TCP/IP connection to a database - I think this library calls WSACleanup
in one of it's finalization sections (but I don't have this source code). 有关
WSACleanup
调用的更多信息:我使用第三方库UniDAC,该库打开了与数据库的TCP / IP连接-我认为该库在其完成部分之一中调用WSACleanup
(但我没有此源代码)。 The strange thing is, that when the debugger is on the WSACleanup
line: 奇怪的是,当调试器位于
WSACleanup
行上时:
function WSACleanup; external winsocket name 'WSACleanup';
and I want to step over it (ie F8), the debugger just stops (as if the application had exited normally) - but it should continue the loop in FinalizeUnits
: how is this possible? 并且我想跨过它(即F8),调试器就停止了(就像应用程序正常退出一样)-但是它应该在
FinalizeUnits
继续循环:这怎么可能? ie if it were a deadlock it would not stop, but hang forever, right? 即,如果这是一个僵局,它不会停止,而是永远挂下来,对吗?
The question is: how can I debug this issue? 问题是:如何调试此问题? is it possible that a deadlock causes this problem (ie that the debugger just stops)?
死锁是否可能导致此问题(即调试器刚刚停止)?
Try switching to CPU view before stepping into the problematic TProc using F7. 在使用F7进入有问题的TProc之前,请尝试切换到CPU视图。 Sometimes this can give you a good hint.
有时这可以给您一个很好的提示。
You could also try looking up the address of "P" in the map file. 您也可以尝试在地图文件中查找“ P”的地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.