mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-07 09:30:21 +02:00
* converted the result of TGDBController.PrintCommand from pchar to ansistring:
* supports returning long strings * can be easily converted to a pchar without truncation (a simple PChar(x) works for read-only access or a full copy via StrNew(PChar(x)) ) * can be easily converted to shortstring without memleaks (shortstr := pchar works, but creates a silent memleak, when the pchar returned should be StrDispose'd) git-svn-id: trunk@30052 -
This commit is contained in:
parent
1e692a2d2e
commit
67a66f104d
@ -1212,7 +1212,7 @@ end;
|
||||
|
||||
function TDebugController.GetValue(Const expr : string) : pchar;
|
||||
begin
|
||||
GetValue:=PrintCommand(expr);
|
||||
GetValue:=StrNew(PChar(PrintCommand(expr)));
|
||||
end;
|
||||
|
||||
function TDebugController.GetFramePointer : CORE_ADDR;
|
||||
@ -1221,7 +1221,7 @@ var
|
||||
p : longint;
|
||||
begin
|
||||
{$ifdef FrameNameKnown}
|
||||
st:=strpas(PrintFormattedCommand(FrameName,pfdecimal));
|
||||
st:=PrintFormattedCommand(FrameName,pfdecimal);
|
||||
p:=pos('=',st);
|
||||
while (p<length(st)) and (st[p+1] in [' ',#9]) do
|
||||
inc(p);
|
||||
|
@ -67,8 +67,8 @@ type
|
||||
{ set command }
|
||||
function SetCommand(Const SetExpr : string) : boolean;
|
||||
{ print }
|
||||
function PrintCommand(const expr : string): pchar;
|
||||
function PrintFormattedCommand(const expr : string; Format : TPrintFormatType): pchar;
|
||||
function PrintCommand(const expr : string): AnsiString;
|
||||
function PrintFormattedCommand(const expr : string; Format : TPrintFormatType): AnsiString;
|
||||
{ breakpoints }
|
||||
function BreakpointInsert(const location: string; BreakpointFlags: TBreakpointFlags): LongInt;
|
||||
function WatchpointInsert(const location: string; WatchpointType: TWatchpointType): LongInt;
|
||||
@ -109,6 +109,17 @@ begin
|
||||
{$endif windows}
|
||||
end;
|
||||
|
||||
function AnsiStrPas(S: PChar): AnsiString;
|
||||
var
|
||||
Res: AnsiString;
|
||||
Len: LongInt;
|
||||
begin
|
||||
Len := StrLen(S);
|
||||
SetLength(Res, Len);
|
||||
Move(S, Res[1], Len);
|
||||
AnsiStrPas := Res;
|
||||
end;
|
||||
|
||||
constructor TGDBController.Init;
|
||||
begin
|
||||
inherited Init;
|
||||
@ -300,26 +311,26 @@ end;
|
||||
|
||||
|
||||
{ print }
|
||||
function TGDBController.PrintCommand(const expr : string): pchar;
|
||||
function TGDBController.PrintCommand(const expr : string): AnsiString;
|
||||
begin
|
||||
Command('-data-evaluate-expression '+expr);
|
||||
if GDB.ResultRecord.Success then
|
||||
PrintCommand:=strnew(pchar(GDB.ResultRecord.Parameters['value'].AsString))
|
||||
PrintCommand:=GDB.ResultRecord.Parameters['value'].AsString
|
||||
else
|
||||
PrintCommand:=strnew(GetError);
|
||||
PrintCommand:=AnsiStrPas(GetError);
|
||||
end;
|
||||
|
||||
const
|
||||
PrintFormatName : Array[TPrintFormatType] of string[11] =
|
||||
('binary', 'decimal', 'hexadecimal', 'octal', 'natural');
|
||||
|
||||
function TGDBController.PrintFormattedCommand(const expr : string; Format : TPrintFormatType): pchar;
|
||||
function TGDBController.PrintFormattedCommand(const expr : string; Format : TPrintFormatType): ansistring;
|
||||
begin
|
||||
Command('-var-evaluate-expression -f '+PrintFormatName[Format]+' '+expr);
|
||||
if GDB.ResultRecord.Success then
|
||||
PrintFormattedCommand:=strnew(pchar(GDB.ResultRecord.Parameters['value'].AsString))
|
||||
PrintFormattedCommand:=GDB.ResultRecord.Parameters['value'].AsString
|
||||
else
|
||||
PrintFormattedCommand:=strnew(GetError);
|
||||
PrintFormattedCommand:=AnsiStrPas(GetError);
|
||||
end;
|
||||
|
||||
function TGDBController.BreakpointInsert(const location: string; BreakpointFlags: TBreakpointFlags): LongInt;
|
||||
|
@ -61,9 +61,9 @@ type
|
||||
{ set command }
|
||||
function SetCommand(Const SetExpr : string) : boolean;
|
||||
{ print }
|
||||
function InternalGetValue(Const expr : string) : pchar;
|
||||
function PrintCommand(const expr : string): pchar;
|
||||
function PrintFormattedCommand(const expr : string; Format : TPrintFormatType): pchar;
|
||||
function InternalGetValue(Const expr : string) : AnsiString;
|
||||
function PrintCommand(const expr : string): AnsiString;
|
||||
function PrintFormattedCommand(const expr : string; Format : TPrintFormatType): AnsiString;
|
||||
{ breakpoints }
|
||||
function BreakpointInsert(const location: string; BreakpointFlags: TBreakpointFlags): LongInt;
|
||||
function WatchpointInsert(const location: string; WatchpointType: TWatchpointType): LongInt;
|
||||
@ -174,6 +174,17 @@ begin
|
||||
{$endif win32}
|
||||
end;
|
||||
|
||||
function AnsiStrPas(S: PChar): AnsiString;
|
||||
var
|
||||
Res: AnsiString;
|
||||
Len: LongInt;
|
||||
begin
|
||||
Len := StrLen(S);
|
||||
SetLength(Res, Len);
|
||||
Move(S, Res[1], Len);
|
||||
AnsiStrPas := Res;
|
||||
end;
|
||||
|
||||
constructor TGDBController.Init;
|
||||
begin
|
||||
inherited init;
|
||||
@ -418,7 +429,7 @@ end;
|
||||
|
||||
{ print }
|
||||
|
||||
function TGDBController.InternalGetValue(Const expr : string) : pchar;
|
||||
function TGDBController.InternalGetValue(Const expr : string) : AnsiString;
|
||||
var
|
||||
p,p2,p3 : pchar;
|
||||
st : string;
|
||||
@ -470,9 +481,9 @@ begin
|
||||
while p^ in [' ',#9] do
|
||||
inc(p);
|
||||
if assigned(p) then
|
||||
InternalGetValue:=StrNew(p)
|
||||
InternalGetValue:=AnsiStrPas(p)
|
||||
else
|
||||
InternalGetValue:=StrNew(GetError);
|
||||
InternalGetValue:=AnsiStrPas(GetError);
|
||||
if assigned(p3) then
|
||||
p3^:=#10;
|
||||
got_error:=false;
|
||||
@ -484,7 +495,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TGDBController.PrintCommand(const expr : string): pchar;
|
||||
function TGDBController.PrintCommand(const expr : string): AnsiString;
|
||||
begin
|
||||
PrintCommand:=InternalGetValue(expr);
|
||||
end;
|
||||
@ -493,7 +504,7 @@ const
|
||||
PrintFormatName : Array[TPrintFormatType] of string[11] =
|
||||
(' /b ', ' /d ', ' /x ', ' /o ', '');
|
||||
|
||||
function TGDBController.PrintFormattedCommand(const expr : string; Format : TPrintFormatType): pchar;
|
||||
function TGDBController.PrintFormattedCommand(const expr : string; Format : TPrintFormatType): AnsiString;
|
||||
begin
|
||||
PrintFormattedCommand:=InternalGetValue(PrintFormatName[Format]+expr);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user