Debugger, IDE: fix dangling pointer in watches / crash when history entry was active and restarting debugger.

This commit is contained in:
Martin 2022-10-23 13:16:39 +02:00
parent efc94ab2db
commit 1e7d87dd64
2 changed files with 46 additions and 5 deletions

View File

@ -155,6 +155,7 @@ type
procedure DoItemRemovedFromView(Sender: TDbgTreeView; AnItem: TObject;
ANode: PVirtualNode);
procedure DoUnLockCommandProcessing(Data: PtrInt);
procedure DoWatchFreed(Sender: TObject);
function GetWatches: TIdeWatches;
procedure ContextChanged(Sender: TObject);
procedure SnapshotChanged(Sender: TObject);
@ -920,11 +921,26 @@ begin
DebugBoss.UnLockCommandProcessing;
end;
procedure TWatchesDlg.DoWatchFreed(Sender: TObject);
var
nd: PVirtualNode;
begin
nd := tvWatches.FindNodeForItem(Sender);
if nd = nil then
exit;
tvWatches.OnItemRemoved := nil;
tvWatches.NodeItem[nd] := nil;
tvWatches.OnItemRemoved := @DoItemRemovedFromView;
end;
procedure TWatchesDlg.DoItemRemovedFromView(Sender: TDbgTreeView;
AnItem: TObject; ANode: PVirtualNode);
begin
if AnItem <> nil then
if AnItem <> nil then begin
TWatch(AnItem).ClearDisplayData;
TWatch(AnItem).RemoveFreeNotification(@DoWatchFreed);
end;
end;
procedure TWatchesDlg.DoBeginUpdate;
@ -1623,6 +1639,7 @@ begin
then begin
VNode := tvWatches.AddChild(nil, AWatch);
tvWatches.SelectNode(VNode);
AWatch.AddFreeNotification(@DoWatchFreed);
end;
UpdateItem(VNode, AWatch);

View File

@ -5,10 +5,11 @@ unit IdeDebuggerBase;
interface
uses
Classes, SysUtils, LazClasses, LazLoggerBase, IdeDebuggerWatchResult,
IdeDebuggerBackendValueConv, IdeDebuggerWatchResultJSon, DbgIntfDebuggerBase,
DbgIntfMiscClasses, LazDebuggerIntf, LazDebuggerTemplate,
LazDebuggerIntfBaseTypes, LazDebuggerValueConverter, FpDebugConvDebugForJson;
Classes, SysUtils, LazClasses, LazLoggerBase, LazMethodList,
IdeDebuggerWatchResult, IdeDebuggerBackendValueConv,
IdeDebuggerWatchResultJSon, DbgIntfDebuggerBase, DbgIntfMiscClasses,
LazDebuggerIntf, LazDebuggerTemplate, LazDebuggerIntfBaseTypes,
LazDebuggerValueConverter, FpDebugConvDebugForJson;
type
@ -112,6 +113,7 @@ type
TWatch = class(TDelayedUdateItem)
private
FFreeNotificationList: TMethodList;
FFirstIndexOffs: Int64;
FDbgBackendConverter: TIdeDbgValueConvertSelector;
@ -146,6 +148,9 @@ type
destructor Destroy; override;
procedure ClearValues; virtual;
procedure ClearDisplayData; // keep only what's needed for the snapshot
procedure AddFreeNotification(ANotification: TNotifyEvent);
procedure RemoveFreeNotification(ANotification: TNotifyEvent);
public
property Enabled: Boolean read FEnabled write SetEnabled;
property Expression: String read FExpression write SetExpression;
@ -622,7 +627,12 @@ begin
FDbgBackendConverter.RemoveFreeNotification(@FDbgBackendConverterFreed);
FValueList.Clear;
if FFreeNotificationList <> nil then
FFreeNotificationList.CallNotifyEvents(Self);
inherited Destroy;
FreeAndNil(FFreeNotificationList);
FreeAndNil(FValueList);
end;
@ -636,6 +646,20 @@ begin
FValueList.ClearDisplayData;
end;
procedure TWatch.AddFreeNotification(ANotification: TNotifyEvent);
begin
if FFreeNotificationList = nil then
FFreeNotificationList := TMethodList.Create;
FFreeNotificationList.Add(TMethod(ANotification));
end;
procedure TWatch.RemoveFreeNotification(ANotification: TNotifyEvent);
begin
if FFreeNotificationList = nil then
exit;
FFreeNotificationList.Remove(TMethod(ANotification));
end;
{ TWatches }
function TWatches.GetItemBase(const AnIndex: Integer): TWatch;