mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 20:01:45 +02:00
* Improved MI parser, based on patch by Martin Friebe
git-svn-id: trunk@13790 -
This commit is contained in:
parent
014a458c83
commit
4d014fa56c
@ -54,7 +54,9 @@ type
|
|||||||
|
|
||||||
function GetLine(var ABuffer: String): String;
|
function GetLine(var ABuffer: String): String;
|
||||||
function ConvertToCString(const AText: String): String;
|
function ConvertToCString(const AText: String): String;
|
||||||
function DeleteEscapeChars(const AText: String; const AEscapeChar: Char): String;
|
function DeleteEscapeChars(const AValue: String; const ARemoveQuotes: Boolean = True; const AEscapeChar: Char = '\'): String;
|
||||||
|
function UnQuote(const AValue: String): String;
|
||||||
|
|
||||||
|
|
||||||
procedure SmartWriteln(const s: string);
|
procedure SmartWriteln(const s: string);
|
||||||
|
|
||||||
@ -135,19 +137,60 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function DeleteEscapeChars(const AText: String; const AEscapeChar: Char): String;
|
function Unquote(const AValue: String): String;
|
||||||
var
|
var
|
||||||
i: Integer;
|
len: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=AText;
|
len := Length(AValue);
|
||||||
i:=1;
|
if len < 2 then Exit(AValue);
|
||||||
while i<length(Result) do begin
|
|
||||||
if Result[i]=AEscapeChar then
|
if (AValue[1] = '"') and (AValue[len] = '"')
|
||||||
System.Delete(Result,i,1);
|
then Result := Copy(AValue, 2, len - 2)
|
||||||
Inc(i);
|
else Result := AValue;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function DeleteEscapeChars(const AValue: String; const ARemoveQuotes: Boolean; const AEscapeChar: Char): String;
|
||||||
|
var
|
||||||
|
cnt, len: Integer;
|
||||||
|
s: String;
|
||||||
|
Src, Dst: PChar;
|
||||||
|
begin
|
||||||
|
len := Length(AValue);
|
||||||
|
if len = 0 then Exit('');
|
||||||
|
|
||||||
|
if ARemoveQuotes and (len >= 2) and (AValue[1] = '"') and (AValue[len] = '"')
|
||||||
|
then begin
|
||||||
|
Dec(len, 2);
|
||||||
|
Src := @AValue[2];
|
||||||
|
if len = 0 then Exit('');
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
Src := @AValue[1];
|
||||||
|
end;
|
||||||
|
cnt := len;
|
||||||
|
SetLength(Result, len); // allocate initial space
|
||||||
|
|
||||||
|
Dst := @Result[1];
|
||||||
|
while cnt > 0 do
|
||||||
|
begin
|
||||||
|
if Src^ = AEscapeChar
|
||||||
|
then begin
|
||||||
|
Dec(len);
|
||||||
|
Dec(cnt);
|
||||||
|
if cnt = 0 then Break;
|
||||||
|
Inc(Src);
|
||||||
|
end;
|
||||||
|
Dst^ := Src^;
|
||||||
|
Inc(Dst);
|
||||||
|
Inc(Src);
|
||||||
|
Dec(cnt);
|
||||||
|
end;
|
||||||
|
|
||||||
|
SetLength(Result, len); // adjust to actual length
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ TDelayedUdateItem }
|
{ TDelayedUdateItem }
|
||||||
|
|
||||||
procedure TDelayedUdateItem.Assign(ASource: TPersistent);
|
procedure TDelayedUdateItem.Assign(ASource: TPersistent);
|
||||||
|
@ -206,6 +206,26 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TGDMIValueList }
|
||||||
|
TGDMIValueList = Class(TStringList)
|
||||||
|
private
|
||||||
|
// function GetString(AIndex: Integer): string;
|
||||||
|
// function GetEscaped(AIndex: Integer): string;
|
||||||
|
// function GetEscapedValues(const AName: string): string;
|
||||||
|
// function GetValue(const AName : string): string;
|
||||||
|
public
|
||||||
|
constructor Create(const AResultValues: String);
|
||||||
|
constructor Create(AResult: TGDBMIExecResult);
|
||||||
|
constructor Create(const AResultValues: String; const APath: array of String);
|
||||||
|
constructor Create(AResult: TGDBMIExecResult; const APath: array of String);
|
||||||
|
procedure Init(AResultValues: String);
|
||||||
|
procedure SetPath(const APath: String); overload;
|
||||||
|
procedure SetPath(const APath: array of String); overload;
|
||||||
|
// property Strings[AIndex: Integer]: string read GetString; default;
|
||||||
|
// property Values[const AName: string]: string read GetValue;
|
||||||
|
end;
|
||||||
|
|
||||||
TGDBMIBreakPoint = class(TDBGBreakPoint)
|
TGDBMIBreakPoint = class(TDBGBreakPoint)
|
||||||
private
|
private
|
||||||
FBreakID: Integer;
|
FBreakID: Integer;
|
||||||
@ -320,6 +340,152 @@ type
|
|||||||
Tag: Integer;
|
Tag: Integer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TGDMIValueList }
|
||||||
|
|
||||||
|
constructor TGDMIValueList.Create(const AResultValues: String);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
Init(AResultValues);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TGDMIValueList.Create(const AResultValues: String; const APath: array of String);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
Init(AResultValues);
|
||||||
|
SetPath(APath);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TGDMIValueList.Create(AResult: TGDBMIExecResult);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
Init(AResult.Values);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TGDMIValueList.Create(AResult: TGDBMIExecResult; const APath: array of String);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
Init(AResult.Values);
|
||||||
|
SetPath(APath);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TGDMIValueList.SetPath(const APath: String);
|
||||||
|
begin
|
||||||
|
SetPath([APath]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TGDMIValueList.SetPath(const APath: array of String);
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
for i := low(APath) to High(APath) do
|
||||||
|
begin
|
||||||
|
Init(Unquote(Values[APath[i]]));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
(*
|
||||||
|
function TGDMIValueList.GetString(AIndex: Integer): string;
|
||||||
|
begin
|
||||||
|
Result := DeleteEscapeChars(inherited Strings[AIndex], '\', True);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TGDMIValueList.GetEscaped(AIndex: Integer): string;
|
||||||
|
begin
|
||||||
|
Result := Unquote(inherited Strings[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TGDMIValueList.GetEscapedValues(const AName: string): string;
|
||||||
|
begin
|
||||||
|
Result := Unquote(inherited Values[AName]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TGDMIValueList.GetValue(const AName: string): string;
|
||||||
|
begin
|
||||||
|
Result := DeleteEscapeChars(inherited Values[AName], '\', True);
|
||||||
|
end;
|
||||||
|
*)
|
||||||
|
|
||||||
|
procedure TGDMIValueList.Init(AResultValues: String);
|
||||||
|
function FindNextQuote(const S: String; idx: Integer) :Integer;
|
||||||
|
begin
|
||||||
|
while (idx <= Length(S)) do
|
||||||
|
begin
|
||||||
|
case S[idx] of
|
||||||
|
'\': Inc(idx, 2);
|
||||||
|
'"': Break;
|
||||||
|
else
|
||||||
|
inc(idx);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
result := idx;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function FindClosingBracket(const S: String; idx: Integer) :Integer;
|
||||||
|
var
|
||||||
|
deep, len: Integer;
|
||||||
|
c : Char;
|
||||||
|
begin
|
||||||
|
deep := 1;
|
||||||
|
len := Length(S);
|
||||||
|
while idx <= len do
|
||||||
|
begin
|
||||||
|
case S[idx] of
|
||||||
|
'\': Inc(idx);
|
||||||
|
'"': idx := FindNextQuote(S, idx + 1);
|
||||||
|
'[', '{': Inc(deep);
|
||||||
|
']', '}': Dec(deep);
|
||||||
|
end;
|
||||||
|
if deep = 0 then break;
|
||||||
|
Inc(idx);
|
||||||
|
end;
|
||||||
|
result := idx;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
n, len: Integer;
|
||||||
|
begin
|
||||||
|
Clear;
|
||||||
|
if AResultValues = '' then Exit;
|
||||||
|
// strip surrounding '[]' and '{}' first
|
||||||
|
case AResultValues[1] of
|
||||||
|
'[': begin
|
||||||
|
if AResultValues[Length(AResultValues)] = ']'
|
||||||
|
then begin
|
||||||
|
System.Delete(AResultValues, Length(AResultValues), 1);
|
||||||
|
System.Delete(AResultValues, 1, 1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
'{': begin
|
||||||
|
if AResultValues[Length(AResultValues)] = '}'
|
||||||
|
then begin
|
||||||
|
System.Delete(AResultValues, Length(AResultValues), 1);
|
||||||
|
System.Delete(AResultValues, 1, 1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
n := 1;
|
||||||
|
len := Length(AResultValues);
|
||||||
|
while n <= len do
|
||||||
|
begin
|
||||||
|
case AResultValues[n] of
|
||||||
|
'\': Inc(n); // skip escaped char
|
||||||
|
'"': n := FindNextQuote(AResultValues, n + 1);
|
||||||
|
'[', '{': n := FindClosingBracket(AResultValues, n + 1);
|
||||||
|
',': begin
|
||||||
|
Add(Copy(AResultValues, 1, n - 1));
|
||||||
|
System.Delete(AResultValues, 1, n);
|
||||||
|
n := 1;
|
||||||
|
len := Length(AResultValues);
|
||||||
|
Continue;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Inc(n);
|
||||||
|
end;
|
||||||
|
if AResultValues <> ''
|
||||||
|
then Add(AResultValues);
|
||||||
|
end;
|
||||||
|
|
||||||
{ =========================================================================== }
|
{ =========================================================================== }
|
||||||
{ Some win32 stuff }
|
{ Some win32 stuff }
|
||||||
{ =========================================================================== }
|
{ =========================================================================== }
|
||||||
@ -350,98 +516,6 @@ end;
|
|||||||
{ Helpers }
|
{ Helpers }
|
||||||
{ =========================================================================== }
|
{ =========================================================================== }
|
||||||
|
|
||||||
function CreateMIValueList(AResultValues: String): TStringList;
|
|
||||||
var
|
|
||||||
n: Integer;
|
|
||||||
InString: Boolean;
|
|
||||||
InList: Integer;
|
|
||||||
c: Char;
|
|
||||||
begin
|
|
||||||
Result := TStringList.Create;
|
|
||||||
if AResultValues = '' then Exit;
|
|
||||||
// strip surrounding '[]' and '{}' first
|
|
||||||
case AResultValues[1] of
|
|
||||||
'[': begin
|
|
||||||
if AResultValues[Length(AResultValues)] = ']'
|
|
||||||
then begin
|
|
||||||
Delete(AResultValues, Length(AResultValues), 1);
|
|
||||||
Delete(AResultValues, 1, 1);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
'{': begin
|
|
||||||
if AResultValues[Length(AResultValues)] = '}'
|
|
||||||
then begin
|
|
||||||
Delete(AResultValues, Length(AResultValues), 1);
|
|
||||||
Delete(AResultValues, 1, 1);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
n := 1;
|
|
||||||
InString := False;
|
|
||||||
InList := 0;
|
|
||||||
c := #0;
|
|
||||||
while (n <= Length(AResultValues)) do
|
|
||||||
begin
|
|
||||||
if c = '\'
|
|
||||||
then begin
|
|
||||||
// previous char was escape char
|
|
||||||
c := #0;
|
|
||||||
Inc(n);
|
|
||||||
Continue;
|
|
||||||
end;
|
|
||||||
c := AResultValues[n];
|
|
||||||
if c = '\'
|
|
||||||
then begin
|
|
||||||
Delete(AResultValues, n, 1);
|
|
||||||
Continue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if InString
|
|
||||||
then begin
|
|
||||||
if c = '"'
|
|
||||||
then begin
|
|
||||||
InString := False;
|
|
||||||
Delete(AResultValues, n, 1);
|
|
||||||
Continue;
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
if InList > 0
|
|
||||||
then begin
|
|
||||||
if c in [']', '}']
|
|
||||||
then Dec(InList);
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
if c = ','
|
|
||||||
then begin
|
|
||||||
Result.Add(Copy(AResultValues, 1, n - 1));
|
|
||||||
Delete(AResultValues, 1, n);
|
|
||||||
n := 1;
|
|
||||||
Continue;
|
|
||||||
end
|
|
||||||
else if c = '"'
|
|
||||||
then begin
|
|
||||||
InString := True;
|
|
||||||
Delete(AResultValues, n, 1);
|
|
||||||
Continue;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if c in ['[', '{']
|
|
||||||
then Inc(InList);
|
|
||||||
end;
|
|
||||||
Inc(n);
|
|
||||||
end;
|
|
||||||
if AResultValues <> ''
|
|
||||||
then Result.Add(AResultValues);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CreateMIValueList(AResult: TGDBMIExecResult): TStringList;
|
|
||||||
begin
|
|
||||||
// TODO ? add check ?
|
|
||||||
Result := CreateMIValueList(AResult.Values);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CreateValueList(AResultValues: String): TStringList;
|
function CreateValueList(AResultValues: String): TStringList;
|
||||||
var
|
var
|
||||||
n: Integer;
|
n: Integer;
|
||||||
@ -512,7 +586,7 @@ function TGDBMIDebugger.ChangeFileName: Boolean;
|
|||||||
var
|
var
|
||||||
S: String;
|
S: String;
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
List: TStringList;
|
List: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
@ -527,8 +601,8 @@ begin
|
|||||||
if (R.State = dsError)
|
if (R.State = dsError)
|
||||||
and (FileName <> '')
|
and (FileName <> '')
|
||||||
then begin
|
then begin
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R);
|
||||||
MessageDlg('Debugger', Format('Failed to load file: %s', [List.Values['msg']]), mtError, [mbOK], 0);
|
MessageDlg('Debugger', Format('Failed to load file: %s', [DeleteEscapeChars((List.Values['msg']))]), mtError, [mbOK], 0);
|
||||||
List.Free;
|
List.Free;
|
||||||
SetState(dsStop);
|
SetState(dsStop);
|
||||||
Exit;
|
Exit;
|
||||||
@ -599,7 +673,7 @@ end;
|
|||||||
|
|
||||||
function TGDBMIDebugger.CreateWatches: TDBGWatches;
|
function TGDBMIDebugger.CreateWatches: TDBGWatches;
|
||||||
begin
|
begin
|
||||||
Result := TDBGWatches.Create(Self, TGDBMIWatch);
|
Result := TGDBMIWatches.Create(Self, TGDBMIWatch);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TGDBMIDebugger.Destroy;
|
destructor TGDBMIDebugger.Destroy;
|
||||||
@ -796,7 +870,7 @@ var
|
|||||||
OK: Boolean;
|
OK: Boolean;
|
||||||
S: String;
|
S: String;
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
ResultList: TStrings;
|
ResultList: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
|
|
||||||
@ -815,8 +889,8 @@ begin
|
|||||||
|
|
||||||
if OK
|
if OK
|
||||||
then begin
|
then begin
|
||||||
ResultList := CreateMIValueList(R);
|
ResultList := TGDMIValueList.Create(R);
|
||||||
S := ResultList.Values['value'];
|
S := DeleteEscapeChars(ResultList.Values['value']);
|
||||||
Result := GetPart('''', '''', S);
|
Result := GetPart('''', '''', S);
|
||||||
ResultList.Free;
|
ResultList.Free;
|
||||||
end;
|
end;
|
||||||
@ -938,7 +1012,7 @@ function TGDBMIDebugger.GDBEvaluate(const AExpression: String;
|
|||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S: String;
|
S: String;
|
||||||
ResultList: TStringList;
|
ResultList: TGDMIValueList;
|
||||||
ResultInfo: TGDBType;
|
ResultInfo: TGDBType;
|
||||||
addr: TDbgPtr;
|
addr: TDbgPtr;
|
||||||
e: Integer;
|
e: Integer;
|
||||||
@ -959,10 +1033,11 @@ begin
|
|||||||
|
|
||||||
Result := ExecuteCommand('-data-evaluate-expression %s', [S], [cfIgnoreError, cfExternal], R);
|
Result := ExecuteCommand('-data-evaluate-expression %s', [S], [cfIgnoreError, cfExternal], R);
|
||||||
|
|
||||||
ResultList := CreateMIValueList(R);
|
ResultList := TGDMIValueList.Create(R);
|
||||||
if R.State = dsError
|
if R.State = dsError
|
||||||
then AResult := ResultList.Values['msg']
|
then AResult := ResultList.Values['msg']
|
||||||
else AResult := ResultList.Values['value'];
|
else AResult := ResultList.Values['value'];
|
||||||
|
AResult := DeleteEscapeChars(AResult);
|
||||||
ResultList.Free;
|
ResultList.Free;
|
||||||
if R.State = dsError
|
if R.State = dsError
|
||||||
then Exit;
|
then Exit;
|
||||||
@ -1179,16 +1254,12 @@ end;
|
|||||||
function TGDBMIDebugger.GetFrame(const AIndex: Integer): String;
|
function TGDBMIDebugger.GetFrame(const AIndex: Integer): String;
|
||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S: String;
|
List: TGDMIValueList;
|
||||||
List: TStringList;
|
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
if ExecuteCommand('-stack-list-frames %d %d', [AIndex, AIndex], [cfIgnoreError], R)
|
if ExecuteCommand('-stack-list-frames %d %d', [AIndex, AIndex], [cfIgnoreError], R)
|
||||||
then begin
|
then begin
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R, ['stack']);
|
||||||
S := List.Values['stack'];
|
|
||||||
List.Free;
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
Result := List.Values['frame'];
|
Result := List.Values['frame'];
|
||||||
List.Free;
|
List.Free;
|
||||||
end;
|
end;
|
||||||
@ -1215,12 +1286,12 @@ end;
|
|||||||
function TGDBMIDebugger.GetStrValue(const AExpression: String; const AValues: array of const): String;
|
function TGDBMIDebugger.GetStrValue(const AExpression: String; const AValues: array of const): String;
|
||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
ResultList: TStringList;
|
ResultList: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
if ExecuteCommand('-data-evaluate-expression %s', [Format(AExpression, AValues)], [cfIgnoreError], R)
|
if ExecuteCommand('-data-evaluate-expression %s', [Format(AExpression, AValues)], [cfIgnoreError], R)
|
||||||
then begin
|
then begin
|
||||||
ResultList := CreateMIValueList(R);
|
ResultList := TGDMIValueList.Create(R);
|
||||||
Result := ResultList.Values['value'];
|
Result := DeleteEscapeChars(ResultList.Values['value']);
|
||||||
ResultList.Free;
|
ResultList.Free;
|
||||||
end
|
end
|
||||||
else Result := '';
|
else Result := '';
|
||||||
@ -1487,7 +1558,7 @@ procedure TGDBMIDebugger.InterruptTargetCallback(const AResult: TGDBMIExecResult
|
|||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S: String;
|
S: String;
|
||||||
List: TStringList;
|
List: TGDMIValueList;
|
||||||
n: Integer;
|
n: Integer;
|
||||||
ID1, ID2: Integer;
|
ID1, ID2: Integer;
|
||||||
begin
|
begin
|
||||||
@ -1501,18 +1572,18 @@ begin
|
|||||||
|
|
||||||
S := '';
|
S := '';
|
||||||
if not ExecuteCommand('-thread-list-ids', [cfIgnoreError], R) then Exit;
|
if not ExecuteCommand('-thread-list-ids', [cfIgnoreError], R) then Exit;
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R);
|
||||||
try
|
try
|
||||||
n := StrToIntDef(List.Values['number-of-threads'], 0);
|
n := StrToIntDef(Unquote(List.Values['number-of-threads']), 0);
|
||||||
if n < 2 then Exit; //nothing to switch
|
if n < 2 then Exit; //nothing to switch
|
||||||
S := List.Values['thread-ids'];
|
S := Unquote(List.EscapedValues['thread-ids']);
|
||||||
finally
|
finally
|
||||||
List.Free;
|
List.Free;
|
||||||
end;
|
end;
|
||||||
List := CreateMIValueList(S);
|
List := TGDMIValueList.Create(S);
|
||||||
ID1 := StrToIntDef(List.Values['thread-id'], 0);
|
ID1 := StrToIntDef(Unquote(List.Values['thread-id']), 0);
|
||||||
List.Delete(0);
|
List.Delete(0);
|
||||||
ID2 := StrToIntDef(List.Values['thread-id'], 0);
|
ID2 := StrToIntDef(Unquote(List.Values['thread-id']), 0);
|
||||||
List.Free;
|
List.Free;
|
||||||
if ID1 = ID2 then Exit;
|
if ID1 = ID2 then Exit;
|
||||||
|
|
||||||
@ -1543,7 +1614,7 @@ procedure TGDBMIDebugger.ProcessFrame(const AFrame: String);
|
|||||||
var
|
var
|
||||||
S: String;
|
S: String;
|
||||||
e: Integer;
|
e: Integer;
|
||||||
Frame: TStringList;
|
Frame: TGDMIValueList;
|
||||||
Location: TDBGLocationRec;
|
Location: TDBGLocationRec;
|
||||||
begin
|
begin
|
||||||
// Do we have a frame ?
|
// Do we have a frame ?
|
||||||
@ -1551,14 +1622,14 @@ begin
|
|||||||
then S := GetFrame(0)
|
then S := GetFrame(0)
|
||||||
else S := AFrame;
|
else S := AFrame;
|
||||||
|
|
||||||
Frame := CreateMIValueList(S);
|
Frame := TGDMIValueList.Create(S);
|
||||||
|
|
||||||
Location.Address := 0;
|
Location.Address := 0;
|
||||||
Val(Frame.Values['addr'], Location.Address, e);
|
Val(Unquote(Frame.Values['addr']), Location.Address, e);
|
||||||
if e=0 then ;
|
if e=0 then ;
|
||||||
Location.FuncName := Frame.Values['func'];
|
Location.FuncName := Unquote(Frame.Values['func']);
|
||||||
Location.SrcFile := Frame.Values['file'];
|
Location.SrcFile := Unquote(Frame.Values['file']);
|
||||||
Location.SrcLine := StrToIntDef(Frame.Values['line'], -1);
|
Location.SrcLine := StrToIntDef(Unquote(Frame.Values['line']), -1);
|
||||||
|
|
||||||
Frame.Free;
|
Frame.Free;
|
||||||
|
|
||||||
@ -1827,7 +1898,7 @@ function TGDBMIDebugger.ProcessStopped(const AParams: String; const AIgnoreSigIn
|
|||||||
then begin
|
then begin
|
||||||
ExceptionMessage := GetText('^Exception(%s)^.FMessage', [ObjAddr]);
|
ExceptionMessage := GetText('^Exception(%s)^.FMessage', [ObjAddr]);
|
||||||
//ExceptionMessage := GetText('^^Exception($fp+8)^^.FMessage', []);
|
//ExceptionMessage := GetText('^^Exception($fp+8)^^.FMessage', []);
|
||||||
ExceptionMessage := DeleteEscapeChars(ExceptionMessage, '\');
|
ExceptionMessage := DeleteEscapeChars(ExceptionMessage, False);
|
||||||
end
|
end
|
||||||
else ExceptionMessage := '### Not supported on GDB < 5.3 ###';
|
else ExceptionMessage := '### Not supported on GDB < 5.3 ###';
|
||||||
|
|
||||||
@ -1861,14 +1932,14 @@ function TGDBMIDebugger.ProcessStopped(const AParams: String; const AIgnoreSigIn
|
|||||||
ProcessFrame(GetFrame(1));
|
ProcessFrame(GetFrame(1));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ProcessSignalReceived(const AList: TStringList);
|
procedure ProcessSignalReceived(const AList: TGDMIValueList);
|
||||||
var
|
var
|
||||||
SigInt: Boolean;
|
SigInt: Boolean;
|
||||||
S: String;
|
S: String;
|
||||||
begin
|
begin
|
||||||
// TODO: check to run (un)handled
|
// TODO: check to run (un)handled
|
||||||
|
|
||||||
S := AList.Values['signal-name'];
|
S := Unquote(AList.Values['signal-name']);
|
||||||
{$IFdef MSWindows}
|
{$IFdef MSWindows}
|
||||||
SigInt := S = 'SIGTRAP';
|
SigInt := S = 'SIGTRAP';
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
@ -1887,7 +1958,7 @@ function TGDBMIDebugger.ProcessStopped(const AParams: String; const AIgnoreSigIn
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
List: TStringList;
|
List: TGDMIValueList;
|
||||||
Reason: String;
|
Reason: String;
|
||||||
BreakID: Integer;
|
BreakID: Integer;
|
||||||
BreakPoint: TGDBMIBreakPoint;
|
BreakPoint: TGDBMIBreakPoint;
|
||||||
@ -1896,9 +1967,9 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
FCurrentStackFrame := 0;
|
FCurrentStackFrame := 0;
|
||||||
|
|
||||||
List := CreateMIValueList(AParams);
|
List := TGDMIValueList.Create(AParams);
|
||||||
try
|
try
|
||||||
Reason := List.Values['reason'];
|
Reason := Unquote(List.Values['reason']);
|
||||||
if (Reason = 'exited-normally')
|
if (Reason = 'exited-normally')
|
||||||
then begin
|
then begin
|
||||||
SetState(dsStop);
|
SetState(dsStop);
|
||||||
@ -1907,7 +1978,7 @@ begin
|
|||||||
|
|
||||||
if Reason = 'exited'
|
if Reason = 'exited'
|
||||||
then begin
|
then begin
|
||||||
SetExitCode(StrToIntDef(List.Values['exit-code'], 0));
|
SetExitCode(StrToIntDef(Unquote(List.Values['exit-code']), 0));
|
||||||
SetState(dsStop);
|
SetState(dsStop);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
@ -1915,7 +1986,7 @@ begin
|
|||||||
if Reason = 'exited-signalled'
|
if Reason = 'exited-signalled'
|
||||||
then begin
|
then begin
|
||||||
SetState(dsStop);
|
SetState(dsStop);
|
||||||
DoException('External: ' + List.Values['signal-name'], '');
|
DoException('External: ' + Unquote(List.Values['signal-name']), '');
|
||||||
// ProcessFrame(List.Values['frame']);
|
// ProcessFrame(List.Values['frame']);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
@ -1928,7 +1999,7 @@ begin
|
|||||||
|
|
||||||
if Reason = 'breakpoint-hit'
|
if Reason = 'breakpoint-hit'
|
||||||
then begin
|
then begin
|
||||||
BreakID := StrToIntDef(List.Values['bkptno'], -1);
|
BreakID := StrToIntDef(Unquote(List.Values['bkptno']), -1);
|
||||||
if BreakID = -1
|
if BreakID = -1
|
||||||
then begin
|
then begin
|
||||||
SetState(dsError);
|
SetState(dsError);
|
||||||
@ -2078,16 +2149,14 @@ function TGDBMIDebugger.StartDebugging(const AContinueCommand: String): Boolean;
|
|||||||
function InsertBreakPoint(const AName: String): Integer;
|
function InsertBreakPoint(const AName: String): Integer;
|
||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
ResultList, BkptList: TStringList;
|
ResultList: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
ExecuteCommand('-break-insert %s', [AName], [cfIgnoreError], R);
|
ExecuteCommand('-break-insert %s', [AName], [cfIgnoreError], R);
|
||||||
if R.State = dsError then Exit;
|
if R.State = dsError then Exit;
|
||||||
|
|
||||||
ResultList := CreateMIValueList(R);
|
ResultList := TGDMIValueList.Create(R, ['bkpt']);
|
||||||
BkptList := CreateMIValueList(ResultList.Values['bkpt']);
|
Result := StrToIntDef(Unquote(ResultList.Values['number']), -1);
|
||||||
Result := StrToIntDef(BkptList.Values['number'], -1);
|
|
||||||
ResultList.Free;
|
ResultList.Free;
|
||||||
BkptList.Free;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetTargetInfo(const AFileType: String);
|
procedure SetTargetInfo(const AFileType: String);
|
||||||
@ -2188,7 +2257,7 @@ function TGDBMIDebugger.StartDebugging(const AContinueCommand: String): Boolean;
|
|||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S: String;
|
S: String;
|
||||||
ResultList, BkptList: TStringList;
|
ResultList: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
// Try to retrieve the address of main. Setting a break on main is past initialization
|
// Try to retrieve the address of main. Setting a break on main is past initialization
|
||||||
if ExecuteCommand('info address main', [cfNoMICommand, cfIgnoreError], R)
|
if ExecuteCommand('info address main', [cfNoMICommand, cfIgnoreError], R)
|
||||||
@ -2208,17 +2277,15 @@ function TGDBMIDebugger.StartDebugging(const AContinueCommand: String): Boolean;
|
|||||||
Result := R.State <> dsError;
|
Result := R.State <> dsError;
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
|
|
||||||
ResultList := CreateMIValueList(R);
|
ResultList := TGDMIValueList.Create(R, ['bkpt']);
|
||||||
BkptList := CreateMIValueList(ResultList.Values['bkpt']);
|
FMainAddr := StrToIntDef(Unquote(ResultList.Values['addr']), 0);
|
||||||
FMainAddr := StrToIntDef(BkptList.Values['addr'], 0);
|
|
||||||
BkptList.Free;
|
|
||||||
ResultList.Free;
|
ResultList.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S, FileType, EntryPoint: String;
|
FileType, EntryPoint: String;
|
||||||
List: TStringList;
|
List: TGDMIValueList;
|
||||||
TargetPIDPart: String;
|
TargetPIDPart: String;
|
||||||
TempInstalled, CanContinue: Boolean;
|
TempInstalled, CanContinue: Boolean;
|
||||||
begin
|
begin
|
||||||
@ -2283,12 +2350,9 @@ begin
|
|||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
// OS X gdb has mi output here
|
// OS X gdb has mi output here
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R, ['section-info']);
|
||||||
S := List.Values['section-info'];
|
FileType := Unquote(List.Values['filetype']);
|
||||||
List.Free;
|
EntryPoint := Unquote(List.Values['entry-point']);
|
||||||
List := CreateMIValueList(S);
|
|
||||||
FileType := List.Values['filetype'];
|
|
||||||
EntryPoint := List.Values['entry-point'];
|
|
||||||
List.Free;
|
List.Free;
|
||||||
end;
|
end;
|
||||||
DebugLn('[Debugger] File type: ', FileType);
|
DebugLn('[Debugger] File type: ', FileType);
|
||||||
@ -2428,14 +2492,13 @@ end;
|
|||||||
|
|
||||||
procedure TGDBMIBreakPoint.SetBreakPointCallback(const AResult: TGDBMIExecResult; const ATag: Integer);
|
procedure TGDBMIBreakPoint.SetBreakPointCallback(const AResult: TGDBMIExecResult; const ATag: Integer);
|
||||||
var
|
var
|
||||||
ResultList, BkptList: TStringList;
|
ResultList: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
BeginUpdate;
|
BeginUpdate;
|
||||||
try
|
try
|
||||||
ResultList := CreateMIValueList(AResult);
|
ResultList := TGDMIValueList.Create(AResult, ['bkpt']);
|
||||||
BkptList := CreateMIValueList(ResultList.Values['bkpt']);
|
FBreakID := StrToIntDef(Unquote(ResultList.Values['number']), 0);
|
||||||
FBreakID := StrToIntDef(BkptList.Values['number'], 0);
|
SetHitCount(StrToIntDef(Unquote(ResultList.Values['times']), 0));
|
||||||
SetHitCount(StrToIntDef(BkptList.Values['times'], 0));
|
|
||||||
if FBreakID <> 0
|
if FBreakID <> 0
|
||||||
then SetValid(vsValid)
|
then SetValid(vsValid)
|
||||||
else SetValid(vsInvalid);
|
else SetValid(vsInvalid);
|
||||||
@ -2447,12 +2510,11 @@ begin
|
|||||||
and (TGDBMIDebugger(Debugger).FBreakAtMain = nil)
|
and (TGDBMIDebugger(Debugger).FBreakAtMain = nil)
|
||||||
then begin
|
then begin
|
||||||
// Check if this BP is at the same location as the temp break
|
// Check if this BP is at the same location as the temp break
|
||||||
if StrToIntDef(BkptList.Values['addr'], 0) = TGDBMIDebugger(Debugger).FMainAddr
|
if StrToIntDef(Unquote(ResultList.Values['addr']), 0) = TGDBMIDebugger(Debugger).FMainAddr
|
||||||
then TGDBMIDebugger(Debugger).FBreakAtMain := Self;
|
then TGDBMIDebugger(Debugger).FBreakAtMain := Self;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ResultList.Free;
|
ResultList.Free;
|
||||||
BkptList.Free;
|
|
||||||
finally
|
finally
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
@ -2507,18 +2569,19 @@ procedure TGDBMILocals.AddLocals(const AParams: String);
|
|||||||
var
|
var
|
||||||
n, e: Integer;
|
n, e: Integer;
|
||||||
addr: TDbgPtr;
|
addr: TDbgPtr;
|
||||||
LocList, List: TStrings;
|
LocList, List: TGDMIValueList;
|
||||||
S, Name, Value: String;
|
S, Name, Value: String;
|
||||||
begin
|
begin
|
||||||
LocList := CreateMIValueList(AParams);
|
LocList := TGDMIValueList.Create(AParams);
|
||||||
|
List := TGDMIValueList.Create('');
|
||||||
for n := 0 to LocList.Count - 1 do
|
for n := 0 to LocList.Count - 1 do
|
||||||
begin
|
begin
|
||||||
List := CreateMIValueList(LocList[n]);
|
List.Init(LocList[n]);
|
||||||
Name := List.Values['name'];
|
Name := Unquote(List.Values['name']);
|
||||||
if Name = 'this'
|
if Name = 'this'
|
||||||
then Name := 'Self';
|
then Name := 'Self';
|
||||||
|
|
||||||
Value := List.Values['value'];
|
Value := DeleteEscapeChars(List.Values['value']);
|
||||||
// try to deref. strings
|
// try to deref. strings
|
||||||
S := GetPart(['(pchar) ', '(ansistring) '], [], Value, True, False);
|
S := GetPart(['(pchar) ', '(ansistring) '], [], Value, True, False);
|
||||||
if S <> ''
|
if S <> ''
|
||||||
@ -2532,8 +2595,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
FLocals.Add(Name + '=' + Value);
|
FLocals.Add(Name + '=' + Value);
|
||||||
FreeAndNil(List);
|
|
||||||
end;
|
end;
|
||||||
|
FreeAndNil(List);
|
||||||
FreeAndNil(LocList);
|
FreeAndNil(LocList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2612,8 +2675,7 @@ end;
|
|||||||
procedure TGDBMILocals.LocalsNeeded;
|
procedure TGDBMILocals.LocalsNeeded;
|
||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S: String;
|
List: TGDMIValueList;
|
||||||
List: TStrings;
|
|
||||||
begin
|
begin
|
||||||
if Debugger = nil then Exit;
|
if Debugger = nil then Exit;
|
||||||
if FLocalsValid then Exit;
|
if FLocalsValid then Exit;
|
||||||
@ -2623,13 +2685,7 @@ begin
|
|||||||
[TGDBMIDebugger(Debugger).FCurrentStackFrame], [cfIgnoreError], R);
|
[TGDBMIDebugger(Debugger).FCurrentStackFrame], [cfIgnoreError], R);
|
||||||
if R.State <> dsError
|
if R.State <> dsError
|
||||||
then begin
|
then begin
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R, ['stack-args', 'frame']);
|
||||||
S := List.Values['stack-args'];
|
|
||||||
FreeAndNil(List);
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
S := List.Values['frame'];
|
|
||||||
FreeAndNil(List);
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
AddLocals(List.Values['args']);
|
AddLocals(List.Values['args']);
|
||||||
FreeAndNil(List);
|
FreeAndNil(List);
|
||||||
end;
|
end;
|
||||||
@ -2638,7 +2694,7 @@ begin
|
|||||||
TGDBMIDebugger(Debugger).ExecuteCommand('-stack-list-locals 1', [cfIgnoreError], R);
|
TGDBMIDebugger(Debugger).ExecuteCommand('-stack-list-locals 1', [cfIgnoreError], R);
|
||||||
if R.State <> dsError
|
if R.State <> dsError
|
||||||
then begin
|
then begin
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R);
|
||||||
AddLocals(List.Values['locals']);
|
AddLocals(List.Values['locals']);
|
||||||
FreeAndNil(List);
|
FreeAndNil(List);
|
||||||
end;
|
end;
|
||||||
@ -2747,15 +2803,15 @@ end;
|
|||||||
function TGDBMICallStack.CheckCount: Boolean;
|
function TGDBMICallStack.CheckCount: Boolean;
|
||||||
var
|
var
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
List: TStrings;
|
List: TGDMIValueList;
|
||||||
i, cnt: longint;
|
i, cnt: longint;
|
||||||
begin
|
begin
|
||||||
Result := inherited CheckCount;
|
Result := inherited CheckCount;
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
|
|
||||||
TGDBMIDebugger(Debugger).ExecuteCommand('-stack-info-depth', [cfIgnoreError], R);
|
TGDBMIDebugger(Debugger).ExecuteCommand('-stack-info-depth', [cfIgnoreError], R);
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R);
|
||||||
cnt := StrToIntDef(List.Values['depth'], -1);
|
cnt := StrToIntDef(Unquote(List.Values['depth']), -1);
|
||||||
FreeAndNil(List);
|
FreeAndNil(List);
|
||||||
if cnt = -1 then
|
if cnt = -1 then
|
||||||
begin
|
begin
|
||||||
@ -2767,8 +2823,8 @@ begin
|
|||||||
repeat
|
repeat
|
||||||
inc(i);
|
inc(i);
|
||||||
TGDBMIDebugger(Debugger).ExecuteCommand('-stack-info-depth %d', [i], [cfIgnoreError], R);
|
TGDBMIDebugger(Debugger).ExecuteCommand('-stack-info-depth %d', [i], [cfIgnoreError], R);
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R);
|
||||||
cnt := StrToIntDef(List.Values['depth'], -1);
|
cnt := StrToIntDef(Unquote(List.Values['depth']), -1);
|
||||||
FreeAndNil(List);
|
FreeAndNil(List);
|
||||||
if (cnt = -1) then begin
|
if (cnt = -1) then begin
|
||||||
// no valid stack-info-depth found, so the previous was the last valid one
|
// no valid stack-info-depth found, so the previous was the last valid one
|
||||||
@ -2783,9 +2839,9 @@ function TGDBMICallStack.CreateStackEntry(const AIndex: Integer): TCallStackEntr
|
|||||||
var
|
var
|
||||||
n, e: Integer;
|
n, e: Integer;
|
||||||
R: TGDBMIExecResult;
|
R: TGDBMIExecResult;
|
||||||
S: String;
|
|
||||||
addr: TDbgPtr;
|
addr: TDbgPtr;
|
||||||
Arguments, ArgList, List: TStrings;
|
Arguments: TStringList;
|
||||||
|
ArgList, List: TGDMIValueList;
|
||||||
begin
|
begin
|
||||||
if Debugger = nil then Exit;
|
if Debugger = nil then Exit;
|
||||||
|
|
||||||
@ -2796,21 +2852,16 @@ begin
|
|||||||
|
|
||||||
if R.State <> dsError
|
if R.State <> dsError
|
||||||
then begin
|
then begin
|
||||||
List := CreateMIValueList(R);
|
ArgList := TGDMIValueList.Create(R, ['stack-args', 'frame', 'args']);
|
||||||
S := List.Values['stack-args'];
|
|
||||||
FreeAndNil(List);
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
S := List.Values['frame']; // all arguments
|
|
||||||
FreeAndNil(List);
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
S := List.Values['args'];
|
|
||||||
FreeAndNil(List);
|
|
||||||
|
|
||||||
ArgList := CreateMIValueList(S);
|
if ArgList.Count > 0
|
||||||
|
then begin
|
||||||
|
List := TGDMIValueList.Create('');
|
||||||
for n := 0 to ArgList.Count - 1 do
|
for n := 0 to ArgList.Count - 1 do
|
||||||
begin
|
begin
|
||||||
List := CreateMIValueList(ArgList[n]);
|
List.Init(ArgList[n]);
|
||||||
Arguments.Add(List.Values['name'] + '=' + List.Values['value']);
|
Arguments.Add(Unquote(List.Values['name']) + '=' + DeleteEscapeChars(List.Values['value']));
|
||||||
|
end;
|
||||||
FreeAndNil(List);
|
FreeAndNil(List);
|
||||||
end;
|
end;
|
||||||
FreeAndNil(ArgList);
|
FreeAndNil(ArgList);
|
||||||
@ -2820,23 +2871,17 @@ begin
|
|||||||
[AIndex], [cfIgnoreError], R);
|
[AIndex], [cfIgnoreError], R);
|
||||||
if R.State <> dsError
|
if R.State <> dsError
|
||||||
then begin
|
then begin
|
||||||
List := CreateMIValueList(R);
|
List := TGDMIValueList.Create(R, ['stack', 'frame']);
|
||||||
S := List.Values['stack'];
|
|
||||||
FreeAndNil(List);
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
S := List.Values['frame'];
|
|
||||||
FreeAndNil(List);
|
|
||||||
List := CreateMIValueList(S);
|
|
||||||
addr := 0;
|
addr := 0;
|
||||||
Val(List.Values['addr'], addr, e);
|
Val(Unquote(List.Values['addr']), addr, e);
|
||||||
if e=0 then ;
|
if e=0 then ;
|
||||||
Result := TCallStackEntry.Create(
|
Result := TCallStackEntry.Create(
|
||||||
AIndex,
|
AIndex,
|
||||||
addr,
|
addr,
|
||||||
Arguments,
|
Arguments,
|
||||||
List.Values['func'],
|
Unquote(List.Values['func']),
|
||||||
List.Values['file'],
|
Unquote(List.Values['file']),
|
||||||
StrToIntDef(List.Values['line'], 0)
|
StrToIntDef(Unquote(List.Values['line']), 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
FreeAndNil(List);
|
FreeAndNil(List);
|
||||||
|
Loading…
Reference in New Issue
Block a user