fixed mem leaks in debugger

git-svn-id: trunk@4456 -
This commit is contained in:
mattias 2003-08-08 07:49:56 +00:00
parent c89cc1d203
commit 714365de77
9 changed files with 206 additions and 25 deletions

View File

@ -215,6 +215,7 @@ end;
destructor TCmdLineDebugger.Destroy;
begin
FreeAndNil(FLineEnds);
inherited;
try
FDbgProcess.Free;
@ -381,6 +382,9 @@ initialization
end.
{ =============================================================================
$Log$
Revision 1.20 2003/08/08 07:49:56 mattias
fixed mem leaks in debugger
Revision 1.19 2003/08/02 00:23:08 marc
- removed accidently committed testcode

View File

@ -733,8 +733,10 @@ type
function Add(const AName: String): TBaseException;
function Find(const AName: String): TBaseException;
protected
procedure ClearExceptions; virtual;
public
constructor Create(const AItemClass: TBaseExceptionClass);
destructor Destroy; override;
end;
{ TDBGExceptions }
@ -1110,6 +1112,7 @@ begin
FCallStack.FDebugger := nil;
FWatches.FDebugger := nil;
FreeAndNil(FExceptions);
FreeAndNil(FBreakPoints);
FreeAndNil(FLocals);
FreeAndNil(FCallStack);
@ -3014,6 +3017,12 @@ begin
inherited Create(AItemClass);
end;
destructor TBaseExceptions.Destroy;
begin
ClearExceptions;
inherited Destroy;
end;
function TBaseExceptions.Find(const AName: String): TBaseException;
var
n: Integer;
@ -3029,6 +3038,12 @@ begin
Result := nil;
end;
procedure TBaseExceptions.ClearExceptions;
begin
while Count>0 do
TBaseException(GetItem(Count-1)).Free;
end;
{ =========================================================================== }
{ TDBGExceptions }
{ =========================================================================== }
@ -3099,6 +3114,9 @@ end;
end.
{ =============================================================================
$Log$
Revision 1.50 2003/08/08 07:49:56 mattias
fixed mem leaks in debugger
Revision 1.49 2003/08/02 00:20:20 marc
* fixed environment handling to debuggee

View File

@ -108,6 +108,7 @@ type
function GetSupportedCommands: TDBGCommands; override;
function ParseInitialization: Boolean; virtual;
function RequestCommand(const ACommand: TDBGCommand; const AParams: array of const): Boolean; override;
procedure ClearCommandQueue;
public
class function Caption: String; override;
class function ExePaths: String; override;
@ -383,6 +384,7 @@ end;
destructor TGDBMIDebugger.Destroy;
begin
inherited;
ClearCommandQueue;
FreeAndNil(FCommandQueue);
end;
@ -517,14 +519,16 @@ begin
// Delete command first to allow GDB access while processing stopped
FCommandQueue.Delete(0);
try
if StoppedParams <> ''
then ProcessStopped(StoppedParams, FPauseWaitState = pwsInternal);
if StoppedParams <> ''
then ProcessStopped(StoppedParams, FPauseWaitState = pwsInternal);
if Assigned(CmdInfo^.Callback)
then CmdInfo^.Callback(ResultState, ResultValues, 0);
Dispose(CmdInfo);
if Assigned(CmdInfo^.Callback)
then CmdInfo^.Callback(ResultState, ResultValues, 0);
finally
Dispose(CmdInfo);
end;
if FirstCmd
then begin
@ -1282,6 +1286,18 @@ begin
end;
end;
procedure TGDBMIDebugger.ClearCommandQueue;
var
CmdInfo: PGDBMICmdInfo;
i: Integer;
begin
for i:=0 to FCommandQueue.Count-1 do begin
CmdInfo:=PGDBMICmdInfo(FCommandQueue.Objects[i]);
if CmdInfo<>nil then Dispose(CmdInfo);
end;
FCommandQueue.Clear;
end;
function TGDBMIDebugger.StartDebugging(const AContinueCommand: String): Boolean;
var
S: String;
@ -1477,7 +1493,7 @@ end;
procedure TGDBMIBreakPoint.SetLocation(const ASource: String;
const ALine: Integer);
begin
writeln('TGDBMIBreakPoint.SetLocation A ',Source = ASource,' ',Line = ALine);
//writeln('TGDBMIBreakPoint.SetLocation A ',Source = ASource,' ',Line = ALine);
if (Source = ASource) and (Line = ALine) then exit;
inherited;
if Debugger = nil then Exit;
@ -1495,6 +1511,7 @@ begin
if Debugger.State = dsRun
then TGDBMIDebugger(Debugger).GDBPause(True);
writeln('TGDBMIBreakPoint.UpdateEnable Line=',Line,' Enabled=',Enabled,' InitialEnabled=',InitialEnabled);
TGDBMIDebugger(Debugger).ExecuteCommand('-break-%s %d',
[CMD[Enabled], FBreakID], []);
end;
@ -2048,6 +2065,9 @@ initialization
end.
{ =============================================================================
$Log$
Revision 1.36 2003/08/08 07:49:56 mattias
fixed mem leaks in debugger
Revision 1.35 2003/08/02 00:20:20 marc
* fixed environment handling to debuggee

View File

@ -25,9 +25,8 @@ properly:
--------------------------------------------------------------------------------
1.1 Installing FreePascal under Linux:
Lazarus requires a fpc (FreePascal) version 1.0.7 not older than
21th september 2002 and it requires both - the compiled fpc libs (binaries)
and the fpc sources. The fpc 1.0.6 is too buggy.
Lazarus requires a fpc (FreePascal) version 1.0.10 and it requires both - the
compiled fpc libs (binaries) and the fpc sources. The fpc 1.0.6 is too buggy.
The fpc binaries:
At the lazarus downloads section (www.lazarus.freepascal.org) you can get the

View File

@ -414,6 +414,7 @@ end;
procedure TManagedBreakPoint.OnToggleEnableMenuItemClick(Sender: TObject);
begin
Enabled:=not Enabled;
InitialEnabled:=Enabled;
end;
procedure TManagedBreakPoint.OnDeleteMenuItemClick(Sender: TObject);
@ -1048,11 +1049,8 @@ begin
then FWatches := nil;
FreeAndNil(FDebugger);
end
else begin
FreeAndNil(FWatches);
end;
FreeAndNil(FWatches);
FreeAndNil(FBreakPoints);
FreeAndNil(FBreakPointGroups);
FreeAndNil(FBreakpointsNotification);
@ -1251,9 +1249,17 @@ var
procedure SaveDebuggerItems;
begin
// copy the watches
OldWatches := TDBGWatches.Create(nil, TDBGWatch);
OldWatches.Assign(FWatches);
if (FDebugger<>nil)
and (FDebugger.Watches=FWatches) then begin
// wtaches belongs to the current debugger
// -> create debugger independent watches and copy watches
OldWatches := TDBGWatches.Create(nil, TDBGWatch);
OldWatches.Assign(FWatches);
end else begin
// watches are already independent of debugger
// -> keep watches
OldWatches:=FWatches;
end;
FWatches := nil;
end;
@ -1545,6 +1551,9 @@ end.
{ =============================================================================
$Log$
Revision 1.59 2003/08/08 07:49:56 mattias
fixed mem leaks in debugger
Revision 1.58 2003/07/31 19:56:49 mattias
fixed double messages SETLabel

View File

@ -160,7 +160,6 @@ end;
procedure TDebuggerOptionsForm.FetchDebuggerSpecificOptions;
var
DebuggerClass: TDebuggerClass;
i: Integer;
AMemo: TMemo;
begin

View File

@ -40,7 +40,7 @@ program Lazarus;
{$R *.res}
{$ENDIF}
{ $DEFINE IDE_MEM_CHECK}
{$DEFINE IDE_MEM_CHECK}
uses
//cmem,
@ -99,6 +99,9 @@ end.
{
$Log$
Revision 1.49 2003/08/08 07:49:56 mattias
fixed mem leaks in debugger
Revision 1.48 2003/07/24 08:52:46 marc
+ Added SSHGDB debugger

View File

@ -26,14 +26,8 @@
UNDER CONSTRUCTION by Mattias Gaertner
ToDo:
- Capacity
- Add
- Delete
- Exchange
- Insert
- GetObject
- Put
- PutObject
- Sort
- CustomSort
- Find
@ -63,6 +57,7 @@ type
protected
FArraysValid: boolean;
FLineCount: integer;
FLineCapacity: integer;
FLineRanges: ^TLineRange;// array of TLineRange
FText: string;
FUpdateCount: integer;
@ -74,10 +69,16 @@ type
procedure Changing; virtual;
function Get(Index: Integer): string; override;
procedure ClearArrays;
function GetObject(Index: Integer): TObject; override;
procedure PutObject(Index: Integer; AnObject: TObject); override;
function GetLineLen(Index: integer; IncludeNewLineChars: boolean): integer;
public
destructor Destroy; override;
procedure Clear; override;
procedure SetText(TheText: PChar); override;
procedure Insert(Index: Integer; const S: string); override;
procedure Delete(Index: Integer); override;
procedure Exchange(FromIndex, ToIndex: Integer); override;
public
property Text: string read FText write SetTextStr;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
@ -128,6 +129,7 @@ begin
end;
if (FText<>'') and (not (FText[l] in [#10,#13])) then
inc(FLineCount);
FLineCapacity:=FLineCount;
// build line range list
if FLineCount>0 then begin
ArraySize:=FLineCount*SizeOf(TLineRange);
@ -200,6 +202,36 @@ begin
FreeMem(FLineRanges);
FLineRanges:=nil;
end;
FLineCapacity:=0;
end;
function TTextStrings.GetObject(Index: Integer): TObject;
begin
if FArraysValid then
Result:=FLineRanges[Index].TheObject
else
Result:=nil;
end;
procedure TTextStrings.PutObject(Index: Integer; AnObject: TObject);
begin
if not FArraysValid then BuildArrays;
FLineRanges[Index].TheObject:=AnObject;
end;
function TTextStrings.GetLineLen(Index: integer; IncludeNewLineChars: boolean
): integer;
var
LineEndPos: Integer;
begin
if not FArraysValid then BuildArrays;
if not IncludeNewLineChars then
LineEndPos:=FLineRanges[Index].EndPos
else if Index=FLineCount-1 then
LineEndPos:=length(FText)
else
LineEndPos:=FLineRanges[Index+1].StartPos;
Result:=LineEndPos-FLineRanges[Index].StartPos;
end;
destructor TTextStrings.Destroy;
@ -222,5 +254,88 @@ begin
FArraysValid:=false;
end;
procedure TTextStrings.Insert(Index: Integer; const S: string);
var
NewStartPos: Integer;
NewLineCharCount: Integer;
NewLineLen: Integer;
i: Integer;
begin
if not FArraysValid then BuildArrays;
NewLineLen:=length(S);
if Index<FLineCount then
NewStartPos:=FLineRanges[Index].StartPos
else
NewStartPos:=length(FText);
NewLineCharCount:=0;
if (NewLineLen>0) and (S[NewLineLen] in [#10,#13]) then begin
inc(NewLineCharCount);
if (NewLineLen>1)
and (S[NewLineLen-1] in [#10,#13])
and (S[NewLineLen-1]<>S[NewLineLen]) then
inc(NewLineCharCount);
end;
// adjust text
System.Insert(S,FText,NewStartPos);
// adjust arrays
if FLineCount=FLineCapacity then begin
if FLineCapacity<8 then
FLineCapacity:=8
else
FLineCapacity:=FLineCapacity shl 1;
ReAllocMem(FLineRanges,SizeOf(TLineRange)*FLineCapacity);
end;
if Index<FLineCount then begin
System.Move(FLineRanges[Index],FLineRanges[Index+1],
(FLineCount-Index)*SizeOf(TLineRange));
for i:=Index+1 to FLineCount do begin
inc(FLineRanges[i].StartPos,NewLineLen);
inc(FLineRanges[i].EndPos,NewLineLen);
end;
end;
FLineRanges[Index].Line:=S;
FLineRanges[Index].EndPos:=NewStartPos+NewLineLen-NewLineCharCount;
inc(FLineCount);
end;
procedure TTextStrings.Delete(Index: Integer);
var
OldLineLen: Integer;
OldStartPos: Integer;
i: Integer;
begin
if not FArraysValid then BuildArrays;
// adjust text
OldLineLen:=GetLineLen(Index,true);
if OldLineLen>0 then begin
OldStartPos:=FLineRanges[Index].StartPos;
System.Delete(FText,OldStartPos,OldLineLen);
end;
// adjust arrays
dec(FLineCount);
FLineRanges[Index].Line:='';
if Index<FLineCount then begin
System.Move(FLineRanges[Index+1],FLineRanges[Index],
(FLineCount-Index)*SizeOf(TLineRange));
for i:=Index to FLineCount-1 do begin
dec(FLineRanges[i].StartPos,OldLineLen);
dec(FLineRanges[i].EndPos,OldLineLen);
end;
end;
end;
procedure TTextStrings.Exchange(FromIndex, ToIndex: Integer);
var
CurLineLen: Integer;
begin
if FromIndex=ToIndex then exit;
if not FArraysValid then BuildArrays;
CurLineLen:=GetLineLen(FromIndex,true);
// adjust text
if CurLineLen>0 then begin
end;
end;
end.

View File

@ -699,7 +699,9 @@ var
AutoPackages: TList;
i: Integer;
begin
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.CompileRequiredPackages A ');
{$ENDIF}
AutoPackages:=PackageGraph.GetAutoCompilationOrder(APackage,FirstDependency,
Policies);
if AutoPackages<>nil then begin
@ -717,7 +719,9 @@ begin
AutoPackages.Free;
end;
end;
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.CompileRequiredPackages END ');
{$ENDIF}
Result:=mrOk;
end;
@ -727,7 +731,9 @@ var
PathList: TList;
Dependency: TPkgDependency;
begin
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.CheckPackageGraphForCompilation A');
{$ENDIF}
// check for unsaved packages
PathList:=PackageGraph.FindUnsavedDependencyPath(APackage,FirstDependency);
@ -773,7 +779,9 @@ begin
exit;
end;
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.CheckPackageGraphForCompilation END');
{$ENDIF}
Result:=mrOk;
end;
@ -921,7 +929,9 @@ var
OtherStateFile: String;
begin
Result:=mrYes;
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.CheckIfPackageNeedsCompilation A ',APackage.IDAsString);
{$ENDIF}
// check state file
StateFilename:=APackage.GetStateFilename;
@ -1021,7 +1031,9 @@ begin
end;
end;
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.CheckIfPackageNeedsCompilation END ',APackage.IDAsString);
{$ENDIF}
Result:=mrNo;
end;
@ -2054,7 +2066,9 @@ var
OutputDir: String;
OldSrc: String;
begin
{$IFDEF VerbosePkgCompile}
writeln('TPkgManager.DoSavePackageMainSource A');
{$ENDIF}
// check if package is ready for saving
OutputDir:=APackage.GetOutputDirectory;
if not DirectoryExists(OutputDir) then begin