* quote strings in TGDBController.PrintCommand and .PrintFormattedCommand to

allow evaluating expressions which contain spaces

git-svn-id: trunk@30057 -
This commit is contained in:
nickysn 2015-03-02 00:26:09 +00:00
parent 547e20f1a2
commit 1709006ad3
2 changed files with 32 additions and 2 deletions

View File

@ -302,7 +302,7 @@ end;
{ print }
function TGDBController.PrintCommand(const expr : string): AnsiString;
begin
Command('-data-evaluate-expression '+expr);
Command('-data-evaluate-expression '+QuoteString(expr));
if GDB.ResultRecord.Success then
PrintCommand:=GDB.ResultRecord.Parameters['value'].AsString
else
@ -315,7 +315,7 @@ const
function TGDBController.PrintFormattedCommand(const expr : string; Format : TPrintFormatType): ansistring;
begin
Command('-var-evaluate-expression -f '+PrintFormatName[Format]+' '+expr);
Command('-var-evaluate-expression -f '+PrintFormatName[Format]+' '+QuoteString(expr));
if GDB.ResultRecord.Success then
PrintFormattedCommand:=GDB.ResultRecord.Parameters['value'].AsString
else

View File

@ -113,8 +113,38 @@ type
property Alive: Boolean read IsAlive;
end;
function QuoteString(S: string): string;
implementation
function QuoteString(S: string): string;
var
I: LongInt;
begin
I := 1;
Result := '';
while I <= Length(S) do
begin
case S[I] of
'''': Result := Result + '\''';
'"': Result := Result + '\"';
#10: Result := Result + '\n';
#13: Result := Result + '\r';
#9: Result := Result + '\t';
#11: Result := Result + '\v';
#8: Result := Result + '\b';
#12: Result := Result + '\f';
#7: Result := Result + '\a';
'\': Result := Result + '\\';
'?': Result := Result + '\?';
else
Result := Result + S[I];
end;
Inc(I);
end;
Result := '"' + Result + '"';
end;
function TGDBMI_Value.AsString: string;
begin
Result := (self as TGDBMI_StringValue).StringValue;