mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 03:19:48 +02:00
FpDebug/LazDebugger: add asserts for thread safety
git-svn-id: trunk@64542 -
This commit is contained in:
parent
ccf7d87898
commit
6857851554
@ -1000,6 +1000,7 @@ var
|
|||||||
Len, i: Integer;
|
Len, i: Integer;
|
||||||
BList: TFpInternalBreakpointArray;
|
BList: TFpInternalBreakpointArray;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadIdNotMain('TBreakLocationMap.AddLocotion');{$ENDIF}
|
||||||
LocData := GetDataPtr(ALocation);
|
LocData := GetDataPtr(ALocation);
|
||||||
|
|
||||||
if LocData <> nil then begin
|
if LocData <> nil then begin
|
||||||
@ -1046,6 +1047,7 @@ var
|
|||||||
LocData: PInternalBreakLocationEntry;
|
LocData: PInternalBreakLocationEntry;
|
||||||
Len, i: Integer;
|
Len, i: Integer;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadIdNotMain('TBreakLocationMap.RemoveLocotion');{$ENDIF}
|
||||||
LocData := GetDataPtr(ALocation);
|
LocData := GetDataPtr(ALocation);
|
||||||
if LocData = nil then begin
|
if LocData = nil then begin
|
||||||
DebugLn(DBG_WARNINGS or DBG_BREAKPOINTS, ['Missing breakpoint for loc ', FormatAddress(ALocation)]);
|
DebugLn(DBG_WARNINGS or DBG_BREAKPOINTS, ['Missing breakpoint for loc ', FormatAddress(ALocation)]);
|
||||||
@ -1126,6 +1128,7 @@ end;
|
|||||||
|
|
||||||
function TBreakLocationMap.GetEnumerator: TBreakLocationMapEnumerator;
|
function TBreakLocationMap.GetEnumerator: TBreakLocationMapEnumerator;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TBreakLocationMap.GetEnumerator');{$ENDIF}
|
||||||
Result := TBreakLocationMapEnumerator.Create(Self);
|
Result := TBreakLocationMapEnumerator.Create(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3123,6 +3126,7 @@ procedure TFpInternalBreakpoint.ResetBreak;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalBreakpoint.ResetBreak');{$ENDIF}
|
||||||
if FProcess = nil then
|
if FProcess = nil then
|
||||||
exit;
|
exit;
|
||||||
for i := 0 to High(FLocation) do
|
for i := 0 to High(FLocation) do
|
||||||
@ -3133,6 +3137,7 @@ procedure TFpInternalBreakpoint.SetBreak;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalBreakpoint.SetBreak');{$ENDIF}
|
||||||
if FProcess = nil then
|
if FProcess = nil then
|
||||||
exit;
|
exit;
|
||||||
for i := 0 to High(FLocation) do
|
for i := 0 to High(FLocation) do
|
||||||
@ -3228,6 +3233,7 @@ var
|
|||||||
R: Boolean;
|
R: Boolean;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalWatchpoint.SetBreak');{$ENDIF}
|
||||||
if FProcess = nil then
|
if FProcess = nil then
|
||||||
exit;
|
exit;
|
||||||
//TODO: read current mem content. So in case of overlap it can be checked
|
//TODO: read current mem content. So in case of overlap it can be checked
|
||||||
@ -3259,6 +3265,7 @@ end;
|
|||||||
|
|
||||||
procedure TFpInternalWatchpoint.ResetBreak;
|
procedure TFpInternalWatchpoint.ResetBreak;
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}AssertFpDebugThreadId('TFpInternalWatchpoint.ResetBreak');{$ENDIF}
|
||||||
if FProcess = nil then
|
if FProcess = nil then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ unit FpDbgCommon;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
uses Classes;
|
||||||
|
|
||||||
type
|
type
|
||||||
// Target information, could be different from host debugger
|
// Target information, could be different from host debugger
|
||||||
TMachineType = (mtNone, mtSPARC, mt386, mt68K, mtPPC, mtPPC64, mtARM, mtARM64,
|
TMachineType = (mtNone, mtSPARC, mt386, mt68K, mtPPC, mtPPC64, mtARM, mtARM64,
|
||||||
@ -23,6 +25,13 @@ type
|
|||||||
// Use when target information not yet loaded - assumes that debug target is the same as host
|
// Use when target information not yet loaded - assumes that debug target is the same as host
|
||||||
function hostDescriptor: TTargetDescriptor;
|
function hostDescriptor: TTargetDescriptor;
|
||||||
|
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}
|
||||||
|
procedure AssertFpDebugThreadId(const AName: String);
|
||||||
|
procedure AssertFpDebugThreadIdNotMain(const AName: String);
|
||||||
|
procedure SetCurrentFpDebugThreadIdForAssert(AnId: TThreadID);
|
||||||
|
property CurrentFpDebugThreadIdForAssert: TThreadID write SetCurrentFpDebugThreadIdForAssert;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
function hostDescriptor: TTargetDescriptor;
|
function hostDescriptor: TTargetDescriptor;
|
||||||
@ -49,5 +58,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK}
|
||||||
|
var
|
||||||
|
FCurrentFpDebugThreadIdForAssert: TThreadID;
|
||||||
|
FCurrentFpDebugThreadIdValidForAssert: Boolean;
|
||||||
|
|
||||||
|
procedure AssertFpDebugThreadId(const AName: String);
|
||||||
|
begin
|
||||||
|
if FCurrentFpDebugThreadIdValidForAssert then
|
||||||
|
assert(GetCurrentThreadId = FCurrentFpDebugThreadIdForAssert, AName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure AssertFpDebugThreadIdNotMain(const AName: String);
|
||||||
|
begin
|
||||||
|
AssertFpDebugThreadId(AName);
|
||||||
|
assert(GetCurrentThreadId<>MainThreadID, AName + ' runnig outside main thread');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure SetCurrentFpDebugThreadIdForAssert(AnId: TThreadID);
|
||||||
|
begin
|
||||||
|
FCurrentFpDebugThreadIdForAssert := AnId;
|
||||||
|
FCurrentFpDebugThreadIdValidForAssert := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ uses
|
|||||||
DbgIntfBaseTypes, DbgIntfDebuggerBase,
|
DbgIntfBaseTypes, DbgIntfDebuggerBase,
|
||||||
FpDebugDebuggerUtils, FpDebugDebuggerWorkThreads,
|
FpDebugDebuggerUtils, FpDebugDebuggerWorkThreads,
|
||||||
// FpDebug
|
// FpDebug
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK} FpDbgCommon, {$ENDIF}
|
||||||
FpDbgClasses, FpDbgInfo, FpErrorMessages, FpPascalBuilder, FpdMemoryTools,
|
FpDbgClasses, FpDbgInfo, FpErrorMessages, FpPascalBuilder, FpdMemoryTools,
|
||||||
FpPascalParser, FPDbgController, FpDbgDwarfDataClasses, FpDbgDwarfFreePascal,
|
FpPascalParser, FPDbgController, FpDbgDwarfDataClasses, FpDbgDwarfFreePascal,
|
||||||
FpDbgDwarf, FpDbgUtil;
|
FpDbgDwarf, FpDbgUtil;
|
||||||
@ -2923,6 +2924,7 @@ end;
|
|||||||
procedure TFpDebugDebugger.FreeDebugThread;
|
procedure TFpDebugDebugger.FreeDebugThread;
|
||||||
begin
|
begin
|
||||||
FWorkQueue.TerminateAllThreads(True);
|
FWorkQueue.TerminateAllThreads(True);
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK} CurrentFpDebugThreadIdForAssert := MainThreadID;{$ENDIF}
|
||||||
Application.ProcessMessages; // run the AsyncMethods
|
Application.ProcessMessages; // run the AsyncMethods
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3111,6 +3113,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
FWorkQueue.Clear;
|
FWorkQueue.Clear;
|
||||||
FWorkQueue.ThreadCount := 1;
|
FWorkQueue.ThreadCount := 1;
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK} CurrentFpDebugThreadIdForAssert := FWorkQueue.Threads[0].ThreadID;{$ENDIF}
|
||||||
WorkItem := TFpThreadWorkerControllerRun.Create(Self);
|
WorkItem := TFpThreadWorkerControllerRun.Create(Self);
|
||||||
FWorkQueue.PushItem(WorkItem);
|
FWorkQueue.PushItem(WorkItem);
|
||||||
FWorkQueue.WaitForItem(WorkItem, True);
|
FWorkQueue.WaitForItem(WorkItem, True);
|
||||||
@ -3659,6 +3662,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
FWorkQueue.TerminateAllThreads(True);
|
FWorkQueue.TerminateAllThreads(True);
|
||||||
Application.ProcessMessages; // run the AsyncMethods
|
Application.ProcessMessages; // run the AsyncMethods
|
||||||
|
{$IFDEF FPDEBUG_THREAD_CHECK} CurrentFpDebugThreadIdForAssert := MainThreadID;{$ENDIF}
|
||||||
|
|
||||||
Application.RemoveAsyncCalls(Self);
|
Application.RemoveAsyncCalls(Self);
|
||||||
FreeAndNil(FDbgController);
|
FreeAndNil(FDbgController);
|
||||||
|
Loading…
Reference in New Issue
Block a user