Debugger: refactor

git-svn-id: trunk@44472 -
This commit is contained in:
martin 2014-03-19 18:04:42 +00:00
parent e221726c5a
commit 26e420585f
4 changed files with 147 additions and 141 deletions

View File

@ -1313,6 +1313,13 @@ type
function CreateStackEntry: TCallStackEntry; virtual;
public
constructor Create;
constructor 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: String;
AState: TDebuggerDataState = ddsValid);
function CreateCopy: TThreadEntry; virtual;
destructor Destroy; override;
procedure Assign(AnOther: TThreadEntry); virtual;
@ -1326,27 +1333,33 @@ type
{ TThreadsBase }
TThreads = class(TObject)
private
FCurrentThreadId: Integer;
FList: TList;
function GetEntry(const AnIndex: Integer): TThreadEntry;
function GetEntryById(const AnID: Integer): TThreadEntry;
protected
function GetEntryBase(const AnIndex: Integer): TThreadEntry; virtual; abstract;
function GetEntryByIdBase(const AnID: Integer): TThreadEntry; virtual; abstract;
function GetCurrentThreadId: Integer; virtual; abstract;
procedure SetCurrentThreadId(AValue: Integer); virtual; abstract;
procedure SetCurrentThreadId(AValue: Integer); virtual;
property List: TList read FList;
public
function Count: Integer; virtual; abstract;
procedure Clear; virtual; abstract;
procedure Add(AThread: TThreadEntry); virtual; abstract;
procedure Remove(AThread: TThreadEntry); virtual; abstract;
constructor Create;
destructor Destroy; override;
procedure Assign(AnOther: TThreads); virtual;
function Count: Integer; virtual;
procedure Clear; virtual;
procedure Add(AThread: TThreadEntry); virtual;
procedure Remove(AThread: TThreadEntry); virtual;
function 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: String;
AState: TDebuggerDataState = ddsValid): TThreadEntry; virtual; abstract;
procedure SetValidity(AValidity: TDebuggerDataState); virtual; abstract;
property Entries[const AnIndex: Integer]: TThreadEntry read GetEntryBase; default;
property EntryById[const AnID: Integer]: TThreadEntry read GetEntryByIdBase;
property CurrentThreadId: Integer read GetCurrentThreadId write SetCurrentThreadId;
AState: TDebuggerDataState = ddsValid): TThreadEntry; virtual;
procedure SetValidity(AValidity: TDebuggerDataState); virtual;
property Entries[const AnIndex: Integer]: TThreadEntry read GetEntry; default;
property EntryById[const AnID: Integer]: TThreadEntry read GetEntryById;
property CurrentThreadId: Integer read FCurrentThreadId write SetCurrentThreadId;
end;
{ TThreadsSupplier }
@ -1943,6 +1956,18 @@ begin
inherited Create;
end;
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: String;
AState: TDebuggerDataState);
begin
Create;
TopFrame.Init(AnAdress, AnArguments, AFunctionName, FileName, FullName, ALine, AState);
FThreadId := AThreadId;
FThreadName := AThreadName;
FThreadState := AThreadState;
end;
function TThreadEntry.CreateCopy: TThreadEntry;
begin
Result := TThreadEntry.Create;
@ -1964,6 +1989,102 @@ begin
FThreadState := AnOther.FThreadState;
end;
{ TThreads }
function TThreads.GetEntry(const AnIndex: Integer): TThreadEntry;
begin
if (AnIndex < 0) or (AnIndex >= Count) then exit(nil);
Result := TThreadEntry(FList[AnIndex]);
end;
function TThreads.GetEntryById(const AnID: Integer): TThreadEntry;
var
i: Integer;
begin
i := Count - 1;
while i >= 0 do begin
Result := Entries[i];
if Result.ThreadId = AnID then
exit;
dec(i);
end;
Result := nil;
end;
procedure TThreads.SetCurrentThreadId(AValue: Integer);
begin
if FCurrentThreadId = AValue then exit;
FCurrentThreadId := AValue;
end;
constructor TThreads.Create;
begin
FList := TList.Create;
end;
destructor TThreads.Destroy;
begin
Clear;
FreeAndNil(FList);
inherited Destroy;
end;
procedure TThreads.Assign(AnOther: TThreads);
var
i: Integer;
begin
Clear;
FCurrentThreadId := AnOther.FCurrentThreadId;
for i := 0 to AnOther.FList.Count-1 do
FList.Add(TThreadEntry(AnOther.FList[i]).CreateCopy);
end;
function TThreads.Count: Integer;
begin
Result := FList.Count;
end;
procedure TThreads.Clear;
begin
while FList.Count > 0 do begin
TThreadEntry(Flist[0]).Free;
FList.Delete(0);
end;
end;
procedure TThreads.Add(AThread: TThreadEntry);
begin
FList.Add(AThread.CreateCopy);
if FList.Count = 1 then
FCurrentThreadId := AThread.ThreadId;
end;
procedure TThreads.Remove(AThread: TThreadEntry);
begin
FList.Remove(AThread);
if FCurrentThreadId = AThread.ThreadId then begin
if FList.Count > 0 then
FCurrentThreadId := Entries[0].ThreadId
else
FCurrentThreadId := 0;
end;
AThread.Free;
end;
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: String;
AState: TDebuggerDataState): TThreadEntry;
begin
Result := TThreadEntry.Create(AnAdress, AnArguments, AFunctionName, FileName,
FullName, ALine, AThreadId, AThreadName, AThreadState, AState);
end;
procedure TThreads.SetValidity(AValidity: TDebuggerDataState);
begin
//
end;
{ TThreadsMonitor }
function TThreadsMonitor.GetSupplier: TThreadsSupplier;

View File

@ -1397,13 +1397,6 @@ type
AUnitInvoPrv: TDebuggerUnitInfoProvider = nil
); reintroduce;
public
constructor 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: String;
AState: TDebuggerDataState = ddsValid); overload;
function CreateCopy: TThreadEntry; override;
property TopFrame: TIdeThreadFrameEntry read GetTopFrame;
end;
@ -1412,16 +1405,9 @@ type
TIdeThreads = class(TThreads)
private
FCurrentThreadId: Integer;
FList: TList;
function GetEntry(const AnIndex: Integer): TIdeThreadEntry;
function GetEntryById(const AnID: Integer): TIdeThreadEntry;
protected
procedure SetCurrentThreadId(AValue: Integer); override;
function GetCurrentThreadId: Integer; override;
function GetEntryBase(const AnIndex: Integer): TThreadEntry; override;
function GetEntryByIdBase(const AnID: Integer): TThreadEntry; override;
procedure Assign(AOther: TIdeThreads);
procedure LoadDataFromXMLConfig(const AConfig: TXMLConfig;
APath: string;
AUnitInvoPrv: TDebuggerUnitInfoProvider = nil
@ -1431,12 +1417,6 @@ type
AUnitInvoPrv: TDebuggerUnitInfoProvider = nil
);
public
constructor Create;
destructor Destroy; override;
function Count: Integer; override;
procedure Clear; override;
procedure Add(AThread: TThreadEntry); override;
procedure Remove(AThread: TThreadEntry); override;
function CreateEntry(const AnAdress: TDbgPtr;
const AnArguments: TStrings; const AFunctionName: String;
const FileName, FullName: String;
@ -4170,7 +4150,7 @@ end;
procedure TCurrentThreads.SetCurrentThreadId(AValue: Integer);
begin
if FCurrentThreadId = AValue then exit;
if CurrentThreadId = AValue then exit;
DebugLn(DBG_DATA_MONITORS, ['DebugDataMonitor: TCurrentThreads.SetCurrentThreadId ', AValue]);
inherited SetCurrentThreadId(AValue);
FMonitor.CurrentChanged; // TODO ChangedSelection
@ -4481,18 +4461,6 @@ begin
AConfig.SetValue(APath + 'ThreadState', ThreadState);
end;
constructor TIdeThreadEntry.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: String;
AState: TDebuggerDataState);
begin
inherited Create;
TopFrame.Init(AnAdress, AnArguments, AFunctionName, FileName, FullName, ALine, AState);
FThreadId := AThreadId;
FThreadName := AThreadName;
FThreadState := AThreadState;
end;
function TIdeThreadEntry.CreateCopy: TThreadEntry;
begin
Result := TIdeThreadEntry.Create;
@ -4503,53 +4471,12 @@ end;
function TIdeThreads.GetEntry(const AnIndex: Integer): TIdeThreadEntry;
begin
if (AnIndex < 0) or (AnIndex >= Count) then exit(nil);
Result := TIdeThreadEntry(FList[AnIndex]);
Result := TIdeThreadEntry(inherited Entries[AnIndex]);
end;
function TIdeThreads.GetEntryById(const AnID: Integer): TIdeThreadEntry;
var
i: Integer;
begin
i := Count - 1;
while i >= 0 do begin
Result := Entries[i];
if Result.ThreadId = AnID then
exit;
dec(i);
end;
Result := nil;
end;
procedure TIdeThreads.SetCurrentThreadId(AValue: Integer);
begin
if FCurrentThreadId = AValue then exit;
FCurrentThreadId := AValue;
end;
function TIdeThreads.GetCurrentThreadId: Integer;
begin
Result := FCurrentThreadId;
end;
function TIdeThreads.GetEntryBase(const AnIndex: Integer): TThreadEntry;
begin
Result := TThreadEntry(GetEntry(AnIndex));
end;
function TIdeThreads.GetEntryByIdBase(const AnID: Integer): TThreadEntry;
begin
Result := TThreadEntry(GetEntryById(AnID));
end;
procedure TIdeThreads.Assign(AOther: TIdeThreads);
var
i: Integer;
begin
Clear;
FCurrentThreadId := AOther.FCurrentThreadId;
for i := 0 to AOther.FList.Count-1 do
FList.Add(TIdeThreadEntry(AOther.FList[i]).CreateCopy);
Result := TIdeThreadEntry(inherited EntryById[AnID]);
end;
procedure TIdeThreads.LoadDataFromXMLConfig(const AConfig: TXMLConfig; APath: string;
@ -4557,15 +4484,17 @@ procedure TIdeThreads.LoadDataFromXMLConfig(const AConfig: TXMLConfig; APath: st
var
c, i: Integer;
e: TIdeThreadEntry;
NewCurrentThreadId: Integer;
begin
Clear;
FCurrentThreadId := AConfig.GetValue(APath + 'CurrentThreadId', -1);
NewCurrentThreadId := AConfig.GetValue(APath + 'CurrentThreadId', -1);
inherited SetCurrentThreadId(NewCurrentThreadId);
c := AConfig.GetValue(APath + 'Count', 0);
APath := APath + 'Entry';
for i := 0 to c - 1 do begin
e := TIdeThreadEntry.Create;
e.LoadDataFromXMLConfig(AConfig, APath + IntToStr(i) + '/', AUnitInvoPrv);
FList.Add(e);
List.Add(e);
end;
end;
@ -4574,57 +4503,13 @@ procedure TIdeThreads.SaveDataToXMLConfig(const AConfig: TXMLConfig; APath: stri
var
i: Integer;
begin
AConfig.SetValue(APath + 'CurrentThreadId', FCurrentThreadId);
AConfig.SetValue(APath + 'CurrentThreadId', CurrentThreadId);
AConfig.SetDeleteValue(APath + 'Count', Count, 0);
APath := APath + 'Entry';
for i := 0 to Count - 1 do
Entries[i].SaveDataToXMLConfig(AConfig, APath + IntToStr(i) + '/', AUnitInvoPrv);
end;
constructor TIdeThreads.Create;
begin
FList := TList.Create;
end;
destructor TIdeThreads.Destroy;
begin
Clear;
FreeAndNil(FList);
inherited Destroy;
end;
function TIdeThreads.Count: Integer;
begin
Result := FList.Count;
end;
procedure TIdeThreads.Clear;
begin
while FList.Count > 0 do begin
TIdeThreadEntry(Flist[0]).Free;
FList.Delete(0);
end;
end;
procedure TIdeThreads.Add(AThread: TThreadEntry);
begin
FList.Add((AThread as TIdeThreadEntry).CreateCopy);
if FList.Count = 1 then
FCurrentThreadId := (AThread as TIdeThreadEntry).ThreadId;
end;
procedure TIdeThreads.Remove(AThread: TThreadEntry);
begin
FList.Remove(AThread);
if FCurrentThreadId = (AThread as TIdeThreadEntry).ThreadId then begin
if FList.Count > 0 then
FCurrentThreadId := Entries[0].ThreadId
else
FCurrentThreadId := 0;
end;
AThread.Free;
end;
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: String;

View File

@ -223,7 +223,7 @@ type
FLocals: TIdeLocalsMonitor;
FLineInfo: TIDELineInfo;
FWatches: TIdeWatchesMonitor;
FThreads: TIdeThreadsMonitor;
FThreads: TThreadsMonitor;
FRegisters: TRegistersMonitor;
private
FParent: TGDBTestsuite;
@ -300,7 +300,7 @@ type
property Registers: TRegistersMonitor read FRegisters;
//property Signals: TBaseSignals read FSignals; // A list of actions for signals we know of
property Watches: TIdeWatchesMonitor read FWatches;
property Threads: TIdeThreadsMonitor read FThreads;
property Threads: TThreadsMonitor read FThreads;
end;
function GetCompilers: TCompilerList;
@ -555,7 +555,7 @@ begin
//FBreakPoints := TManagedBreakPoints.Create(Self);
//FBreakPointGroups := TIDEBreakPointGroups.Create;
FWatches := TIdeWatchesMonitor.Create;
FThreads := TIdeThreadsMonitor.Create;
FThreads := TThreadsMonitor.Create;
FExceptions := TBaseExceptions.Create(TBaseException);
//FSignals := TBaseSignals.Create(TBaseSignal);
FLocals := TIdeLocalsMonitor.Create;

View File

@ -50,7 +50,7 @@ type
FLocals: TIdeLocalsMonitor;
FLineInfo: TIDELineInfo;
FWatches: TIdeWatchesMonitor;
FThreads: TIdeThreadsMonitor;
FThreads: TThreadsMonitor;
FRegisters: TRegistersMonitor;
published
procedure RangeMap;
@ -337,7 +337,7 @@ var
IdeDisAss := Gdb.Disassembler;
FWatches := TIdeWatchesMonitor.Create;
FThreads := TIdeThreadsMonitor.Create;
FThreads := TThreadsMonitor.Create;
FExceptions := TBaseExceptions.Create(TBaseException);
//FSignals := TBaseSignals.Create(TBaseSignal);
FLocals := TIdeLocalsMonitor.Create;