DBG: Parse filenames returned by gdb for escape sequences

git-svn-id: trunk@28354 -
This commit is contained in:
martin 2010-11-19 22:24:54 +00:00
parent 76cd8c6607
commit 594f4eb14b
2 changed files with 62 additions and 7 deletions

View File

@ -61,7 +61,9 @@ function GetLine(var ABuffer: String): String;
function ConvertToCString(const AText: String): String;
function ConvertPathDelims(const AFileName: String): String;
function DeleteEscapeChars(const AValue: String; const AEscapeChar: Char = '\'): String;
function UnEscapeOctal(const AValue: String): String;
function UnQuote(const AValue: String): String;
function ConvertGdbPathAndFile(const AValue: String): String; // fix path, delim, unescape, and to utf8
procedure SmartWriteln(const s: string);
@ -181,6 +183,54 @@ begin
Result[i] := PathDelim;
end;
function UnEscapeOctal(const AValue: String): String;
var
c, cnt, len: Integer;
Src, Dst: PChar;
Oct: PChar;
begin
len := Length(AValue);
if len = 0 then Exit('');
Src := @AValue[1];
cnt := len;
SetLength(Result, len); // allocate initial space
Dst := @Result[1];
while cnt > 0 do
begin
if (Src^ = '\') and ((Src+1)^ in ['0'..'7', '\'])
then begin
inc(Src);
dec(cnt);
if Src^ <> '\'
then begin
Oct := Src;
c := 0;
while (Src^ in ['0'..'7']) and (cnt > 0)
do begin
c := (c * 8) + ord(Src^) - ord('0');
Inc(Src);
Dec(cnt);
end;
//c := UnicodeToUTF8SkipErrors(c, Dst);
//inc(Dst, c);
Dst^ := chr(c and 255);
if (c and 255) <> 0
then Inc(Dst);
if cnt = 0 then Break;
continue;
end;
end;
Dst^ := Src^;
Inc(Dst);
Inc(Src);
Dec(cnt);
end;
SetLength(Result, Dst - @Result[1]); // adjust to actual length
end;
function Unquote(const AValue: String): String;
var
len: Integer;
@ -193,6 +243,11 @@ begin
else Result := AValue;
end;
function ConvertGdbPathAndFile(const AValue: String): String;
begin
Result := AnsiToUtf8(ConvertPathDelims(UnEscapeOctal(AValue)));
end;
function DeleteEscapeChars(const AValue: String; const AEscapeChar: Char): String;
var
cnt, len: Integer;

View File

@ -2445,7 +2445,7 @@ function TGDBMIDebuggerCommandExecute.ProcessStopped(const AParams: String;
if ExecuteCommand('info line * pointer(%s)', [S], R)
then begin
Result.SrcLine := StrToIntDef(GetPart('Line ', ' of', R.Values), -1);
Result.SrcFile := ConvertPathDelims(GetPart('\"', '\"', R.Values));
Result.SrcFile := ConvertGdbPathAndFile(GetPart('\"', '\"', R.Values));
end;
end;
@ -4671,8 +4671,8 @@ begin
Val(Frame.Values['addr'], Location.Address, e);
if e=0 then ;
Location.FuncName := Frame.Values['func'];
Location.SrcFile := ConvertPathDelims(Frame.Values['file']);
Location.SrcFullName := ConvertPathDelims(Frame.Values['fullname']);
Location.SrcFile := ConvertGdbPathAndFile(Frame.Values['file']);
Location.SrcFullName := ConvertGdbPathAndFile(Frame.Values['fullname']);
Location.SrcLine := StrToIntDef(Frame.Values['line'], -1);
Frame.Free;
@ -6313,8 +6313,8 @@ begin
Val(AFrameInfo.Values['addr'], addr, e);
if e=0 then ;
func := AFrameInfo.Values['func'];
filename := ConvertPathDelims(AFrameInfo.Values['file']);
fullname := ConvertPathDelims(AFrameInfo.Values['fullname']);
filename := ConvertGdbPathAndFile(AFrameInfo.Values['file']);
fullname := ConvertGdbPathAndFile(AFrameInfo.Values['fullname']);
line := AFrameInfo.Values['line'];
end;
@ -7794,8 +7794,8 @@ begin
Val(Frame.Values['addr'], Location.Address, e);
if e=0 then ;
Location.FuncName := Frame.Values['func'];
Location.SrcFile := ConvertPathDelims(Frame.Values['file']);
Location.SrcFullName := ConvertPathDelims(Frame.Values['fullname']);
Location.SrcFile := ConvertGdbPathAndFile(Frame.Values['file']);
Location.SrcFullName := ConvertGdbPathAndFile(Frame.Values['fullname']);
Location.SrcLine := StrToIntDef(Frame.Values['line'], -1);
Frame.Free;