Browse Source

* quote strings in TGDBController.PrintCommand and .PrintFormattedCommand to
allow evaluating expressions which contain spaces

git-svn-id: trunk@30057 -

nickysn 10 years ago
parent
commit
1709006ad3
2 changed files with 32 additions and 2 deletions
  1. 2 2
      ide/gdbmicon.pas
  2. 30 0
      ide/gdbmiwrap.pas

+ 2 - 2
ide/gdbmicon.pas

@@ -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

+ 30 - 0
ide/gdbmiwrap.pas

@@ -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;