Ide,FpDebug: In FpDebug add a thread number (order of first occurrence). In the IDE, prefix the ID with the number.

This commit is contained in:
Martin 2024-01-18 21:08:49 +01:00
parent b2dc565bb3
commit 8ed6d90eb1
5 changed files with 68 additions and 21 deletions

View File

@ -1217,6 +1217,7 @@ type
FTopFrame: TCallStackEntry;
protected
FThreadId: Integer;
FThreadNum: Integer;
FThreadName: String;
FThreadState: TDbgThreadState;
procedure SetThreadState(AValue: TDbgThreadState); virtual;
@ -1229,20 +1230,23 @@ type
const ALine: Integer;
const AThreadId: Integer; const AThreadName: String;
const AThreadState: TDbgThreadState;
AState: TDebuggerDataState = ddsValid);
AState: TDebuggerDataState = ddsValid;
AThreadNum: Integer = 0);
procedure Init(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String;
const FileName, FullName: String;
const ALine: Integer;
const AThreadId: Integer; const AThreadName: String;
const AThreadState: TDbgThreadState;
AState: TDebuggerDataState = ddsValid);
AState: TDebuggerDataState = ddsValid;
AThreadNum: Integer = 0);
procedure SetThreadStateOnly(AValue: TDbgThreadState); virtual;
function CreateCopy: TThreadEntry; virtual;
destructor Destroy; override;
procedure Assign(AnOther: TThreadEntry); virtual;
published
property ThreadId: Integer read FThreadId;
property ThreadNum: Integer read FThreadNum;
property ThreadName: String read FThreadName;
property ThreadState: TDbgThreadState read FThreadState write SetThreadState;
property TopFrame: TCallStackEntry read FTopFrame;
@ -1273,7 +1277,8 @@ type
const ALine: Integer;
const AThreadId: Integer; const AThreadName: String;
const AThreadState: TDbgThreadState;
AState: TDebuggerDataState = ddsValid): TThreadEntry; virtual;
AState: TDebuggerDataState = ddsValid;
AThreadNum: Integer = 0): TThreadEntry; virtual;
procedure SetValidity({%H-}AValidity: TDebuggerDataState); virtual;
property Entries[const AnIndex: Integer]: TThreadEntry read GetEntry; default;
property EntryById[const AnID: Integer]: TThreadEntry read GetEntryById;
@ -2286,10 +2291,11 @@ constructor TThreadEntry.Create(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String; const FileName,
FullName: String; const ALine: Integer; const AThreadId: Integer;
const AThreadName: String; const AThreadState: TDbgThreadState;
AState: TDebuggerDataState);
AState: TDebuggerDataState; AThreadNum: Integer);
begin
Create;
TopFrame.Init(AnAdress, AnArguments, AFunctionName, FileName, FullName, ALine, AState);
FThreadNum := AThreadNum;
FThreadId := AThreadId;
FThreadName := AThreadName;
FThreadState := AThreadState;
@ -2299,9 +2305,10 @@ procedure TThreadEntry.Init(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String; const FileName,
FullName: String; const ALine: Integer; const AThreadId: Integer;
const AThreadName: String; const AThreadState: TDbgThreadState;
AState: TDebuggerDataState);
AState: TDebuggerDataState; AThreadNum: Integer);
begin
TopFrame.Init(AnAdress, AnArguments, AFunctionName, FileName, FullName, ALine, AState);
FThreadNum := AThreadNum;
FThreadId := AThreadId;
FThreadName := AThreadName;
FThreadState := AThreadState;
@ -2415,10 +2422,10 @@ function TThreads.CreateEntry(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String; const FileName,
FullName: String; const ALine: Integer; const AThreadId: Integer;
const AThreadName: String; const AThreadState: TDbgThreadState;
AState: TDebuggerDataState): TThreadEntry;
AState: TDebuggerDataState; AThreadNum: Integer): TThreadEntry;
begin
Result := TThreadEntry.Create(AnAdress, AnArguments, AFunctionName, FileName,
FullName, ALine, AThreadId, AThreadName, AThreadState, AState);
FullName, ALine, AThreadId, AThreadName, AThreadState, AState, AThreadNum);
end;
procedure TThreads.SetValidity(AValidity: TDebuggerDataState);

View File

@ -242,6 +242,7 @@ type
TDbgThread = class(TObject)
private
FNextIsSingleStep: boolean;
FNum: Integer;
FProcess: TDbgProcess;
FID: Integer;
FHandle: THandle;
@ -322,6 +323,7 @@ type
function IsAtStartOfLine: boolean;
procedure StoreStepInfo(AnAddr: TDBGPtr = 0);
property ID: Integer read FID;
property Num: Integer read FNum;
property Handle: THandle read FHandle;
property Name: String read GetName;
property NextIsSingleStep: boolean read FNextIsSingleStep write FNextIsSingleStep;
@ -357,8 +359,11 @@ type
{ TThreadMap }
TThreadMap = class(TMap)
private
FNumCounter: integer;
public
function GetEnumerator: TThreadMapEnumerator;
procedure Add(const AId, AData); reintroduce;
end;
// Simple array to pass a list of multiple libraries in a parameter. Does
@ -1098,6 +1103,13 @@ begin
Result := TThreadMapEnumerator.Create(Self);
end;
procedure TThreadMap.Add(const AId, AData);
begin
inc(FNumCounter);
TDbgThread(AData).FNum := FNumCounter;
inherited Add(AId, AData);
end;
{ TLibraryMapEnumerator }
function TLibraryMapEnumerator.GetCurrent: TDbgLibrary;

View File

@ -938,7 +938,7 @@ procedure TFpThreadWorkerThreadsUpdate.UpdateThreads_DecRef(Data: PtrInt);
var
Threads: TThreadsSupplier;
ThreadArray: TFPDThreadArray;
i: Integer;
i, j: Integer;
CallStack: TDbgCallstackEntryList;
t, n: TThreadEntry;
FpThr: TDbgThread;
@ -950,6 +950,15 @@ begin
if (Threads.CurrentThreads <> nil) then begin
ThreadArray := FpDebugger.FDbgController.CurrentProcess.GetThreadArray;
for i := 1 to high(ThreadArray) do begin
j := i;
while (j > 0) and (ThreadArray[j].Num < ThreadArray[j-1].Num) do begin
FpThr := ThreadArray[j];
ThreadArray[j] := ThreadArray[j-1];
ThreadArray[j-1] := FpThr;
dec(j);
end;
end;
for i := 0 to high(ThreadArray) do begin
FpThr := ThreadArray[i];
ThrState := dtsPaused;
@ -961,21 +970,21 @@ begin
if Assigned(CallStack) and (CallStack.Count > 0) then begin
c := CallStack.Items[0];
if t = nil then begin
n := Threads.CurrentThreads.CreateEntry(c.AnAddress, nil, c.FunctionName, c.SourceFile, '', c.Line, FpThr.ID, FpThr.Name, ThrState);
n := Threads.CurrentThreads.CreateEntry(c.AnAddress, nil, c.FunctionName, c.SourceFile, '', c.Line, FpThr.ID, FpThr.Name, ThrState, ddsValid, FpThr.Num);
Threads.CurrentThreads.Add(n);
n.Free;
end
else
t.Init(c.AnAddress, nil, c.FunctionName, c.SourceFile, '', c.Line, FpThr.ID, FpThr.Name, ThrState);
t.Init(c.AnAddress, nil, c.FunctionName, c.SourceFile, '', c.Line, FpThr.ID, FpThr.Name, ThrState, ddsValid, FpThr.Num);
end
else begin
if t = nil then begin
n := Threads.CurrentThreads.CreateEntry(0, nil, '', '', '', 0, FpThr.ID, FpThr.Name, ThrState);
n := Threads.CurrentThreads.CreateEntry(0, nil, '', '', '', 0, FpThr.ID, FpThr.Name, ThrState, ddsValid, FpThr.Num);
Threads.CurrentThreads.Add(n);
n.Free;
end
else
t.Init(0, nil, '', '', '', 0, FpThr.ID, FpThr.Name, ThrState);
t.Init(0, nil, '', '', '', 0, FpThr.ID, FpThr.Name, ThrState, ddsValid, FpThr.Num);
end;
end;
@ -1470,8 +1479,9 @@ end;
procedure TFPThreads.RequestEntries;
var
ThreadArray: TFPDThreadArray;
i: Integer;
i, j: Integer;
ThreadEntry: TThreadEntry;
FpThr: TDbgThread;
begin
if CurrentThreads = nil then exit;
if Debugger = nil then Exit;
@ -1480,6 +1490,15 @@ begin
CurrentThreads.Clear;
ThreadArray := TFpDebugDebugger(Debugger).FDbgController.CurrentProcess.GetThreadArray;
for i := 1 to high(ThreadArray) do begin
j := i;
while (j > 0) and (ThreadArray[j].Num < ThreadArray[j-1].Num) do begin
FpThr := ThreadArray[j];
ThreadArray[j] := ThreadArray[j-1];
ThreadArray[j-1] := FpThr;
dec(j);
end;
end;
for i := 0 to high(ThreadArray) do begin
// TODO: Maybe get the address. If FpDebug has already read the ThreadState.
if TFpDebugDebugger(Debugger).FSuspendedThreads.IndexOf(ThreadArray[i].ID) < 0 then

View File

@ -1648,7 +1648,8 @@ type
const ALine: Integer;
const AThreadId: Integer; const AThreadName: String;
const AThreadState: TDbgThreadState;
AState: TDebuggerDataState = ddsValid): TThreadEntry; override;
AState: TDebuggerDataState = ddsValid;
AThreadNum: Integer = 0): TThreadEntry; override;
procedure SetValidity({%H-}AValidity: TDebuggerDataState); override;
property Entries[const AnIndex: Integer]: TIdeThreadEntry read GetEntry; default;
property EntryById[const AnID: Integer]: TIdeThreadEntry read GetEntryById;
@ -1676,7 +1677,8 @@ type
const ALine: Integer;
const AThreadId: Integer; const AThreadName: String;
const AThreadState: TDbgThreadState;
AState: TDebuggerDataState = ddsValid): TThreadEntry; override;
AState: TDebuggerDataState = ddsValid;
AThreadNum: Integer = 0): TThreadEntry; override;
procedure SetValidity(AValidity: TDebuggerDataState); override;
end;
@ -5321,10 +5323,10 @@ function TCurrentThreads.CreateEntry(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String; const FileName,
FullName: String; const ALine: Integer; const AThreadId: Integer;
const AThreadName: String; const AThreadState: TDbgThreadState;
AState: TDebuggerDataState): TThreadEntry;
AState: TDebuggerDataState; AThreadNum: Integer): TThreadEntry;
begin
Result := inherited CreateEntry(AnAdress, AnArguments, AFunctionName, FileName,
FullName, ALine, AThreadId, AThreadName, AThreadState, AState);
FullName, ALine, AThreadId, AThreadName, AThreadState, AState, AThreadNum);
TIdeThreadEntry(Result).FThreadOwner := self;
end;
@ -5579,6 +5581,7 @@ procedure TIdeThreadEntry.SaveDataToXMLConfig(const AConfig: TXMLConfig; const A
begin
TIdeCallStackEntry(TopFrame).SaveDataToXMLConfig(AConfig, APath, AUnitInvoPrv);
AConfig.SetValue(APath + 'ThreadId', ThreadId);
AConfig.SetValue(APath + 'ThreadNum', ThreadNum);
AConfig.SetValue(APath + 'ThreadName', ThreadName);
AConfig.SetValue(APath + 'ThreadState', ThreadState, TypeInfo(TDbgThreadState));
end;
@ -5636,10 +5639,10 @@ function TIdeThreads.CreateEntry(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String; const FileName,
FullName: String; const ALine: Integer; const AThreadId: Integer;
const AThreadName: String; const AThreadState: TDbgThreadState;
AState: TDebuggerDataState): TThreadEntry;
AState: TDebuggerDataState; AThreadNum: Integer): TThreadEntry;
begin
Result := TIdeThreadEntry.Create(AnAdress, AnArguments, AFunctionName, FileName,
FullName, ALine, AThreadId, AThreadName, AThreadState, AState);
FullName, ALine, AThreadId, AThreadName, AThreadState, AState, AThreadNum);
TIdeThreadEntry(Result).FThreadOwner := self;
end;

View File

@ -144,7 +144,10 @@ begin
if Threads[i].ThreadId = Threads.CurrentThreadId
then lvThreads.Items[i].ImageIndex := imgCurrentLine
else lvThreads.Items[i].ImageIndex := -1;
lvThreads.Items[i].SubItems[0] := IntToStr(Threads[i].ThreadId);
if Threads[i].ThreadNum > 0 then
lvThreads.Items[i].SubItems[0] := IntToStr(Threads[i].ThreadNum) + ': ' + IntToStr(Threads[i].ThreadId)
else
lvThreads.Items[i].SubItems[0] := IntToStr(Threads[i].ThreadId);
lvThreads.Items[i].SubItems[1] := Threads[i].ThreadName;
lvThreads.Items[i].SubItems[2] := THREAD_STATE_NAMES[Threads[i].ThreadState];
s := Threads[i].TopFrame.Source;
@ -194,7 +197,10 @@ var
begin
Item := lvThreads.Selected;
if Item = nil then exit;
id := StrToIntDef(Item.SubItems[0], -1);
if TIdeThreadEntry(Item.Data) <> nil then
id := TIdeThreadEntry(Item.Data).ThreadId
else
id := StrToIntDef(Item.SubItems[0], -1);
if id < 0 then exit;
if GetSelectedSnapshot = nil
then ThreadsMonitor.ChangeCurrentThread(id)