mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 19:52:26 +02:00
DBG: improved detection of TargetPtrSize and CPU / Improved reading ClassName
git-svn-id: trunk@28640 -
This commit is contained in:
parent
f2adb2a6da
commit
f65de69416
@ -267,6 +267,7 @@ type
|
|||||||
// GDB info (move to ?)
|
// GDB info (move to ?)
|
||||||
FGDBVersion: String;
|
FGDBVersion: String;
|
||||||
FGDBCPU: String;
|
FGDBCPU: String;
|
||||||
|
FGDBPtrSize: integer; // PointerSize of the GDB-cpu
|
||||||
FGDBOS: String;
|
FGDBOS: String;
|
||||||
|
|
||||||
// Target info (move to record ?)
|
// Target info (move to record ?)
|
||||||
@ -1240,6 +1241,16 @@ end;
|
|||||||
{ Helpers }
|
{ Helpers }
|
||||||
{ =========================================================================== }
|
{ =========================================================================== }
|
||||||
|
|
||||||
|
function CpuNameToPtrSize(const CpuName: String): Integer;
|
||||||
|
begin
|
||||||
|
//'x86', 'i386', 'i486', 'i586', 'i686',
|
||||||
|
//'ia64', 'x86_64', 'powerpc',
|
||||||
|
//'sparc', 'arm'
|
||||||
|
Result := 4;
|
||||||
|
if (LowerCase(CpuName) = 'ia64') or (LowerCase(CpuName) = 'x86_64')
|
||||||
|
then Result := 8;
|
||||||
|
end;
|
||||||
|
|
||||||
function ConvertToGDBPath(APath: string): string;
|
function ConvertToGDBPath(APath: string): string;
|
||||||
// GDB wants forward slashes in its filenames, even on win32.
|
// GDB wants forward slashes in its filenames, even on win32.
|
||||||
begin
|
begin
|
||||||
@ -2778,9 +2789,14 @@ function TGDBMIDebuggerCommandStartDebugging.DoExecute: Boolean;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetTargetInfo(const AFileType: String);
|
procedure SetTargetInfo(const AFileType: String);
|
||||||
|
var
|
||||||
|
FoundPtrSize: Boolean;
|
||||||
begin
|
begin
|
||||||
// assume some defaults
|
// assume some defaults
|
||||||
TargetInfo^.TargetPtrSize := 4;
|
TargetInfo^.TargetPtrSize := GetIntValue('sizeof(POINTER)', []);
|
||||||
|
FoundPtrSize := (FLastExecResult.State <> dsError) and (TargetInfo^.TargetPtrSize > 0);
|
||||||
|
if not FoundPtrSize
|
||||||
|
then TargetInfo^.TargetPtrSize := 4;
|
||||||
TargetInfo^.TargetIsBE := False;
|
TargetInfo^.TargetIsBE := False;
|
||||||
|
|
||||||
case StringCase(AFileType, [
|
case StringCase(AFileType, [
|
||||||
@ -2792,7 +2808,7 @@ function TGDBMIDebuggerCommandStartDebugging.DoExecute: Boolean;
|
|||||||
'pei-arm-big'
|
'pei-arm-big'
|
||||||
], True, False) of
|
], True, False) of
|
||||||
0..3: TargetInfo^.TargetCPU := 'x86';
|
0..3: TargetInfo^.TargetCPU := 'x86';
|
||||||
4: TargetInfo^.TargetCPU := 'x86_64';
|
4: TargetInfo^.TargetCPU := 'x86_64'; //TODO: should we check, PtrSize must be 8, but what if not?
|
||||||
5: begin
|
5: begin
|
||||||
//mach-o-be
|
//mach-o-be
|
||||||
TargetInfo^.TargetIsBE := True;
|
TargetInfo^.TargetIsBE := True;
|
||||||
@ -2802,10 +2818,22 @@ function TGDBMIDebuggerCommandStartDebugging.DoExecute: Boolean;
|
|||||||
end;
|
end;
|
||||||
6: begin
|
6: begin
|
||||||
//mach-o-le
|
//mach-o-le
|
||||||
|
if FoundPtrSize then begin
|
||||||
|
if FTheDebugger.FGDBPtrSize = TargetInfo^.TargetPtrSize
|
||||||
|
then TargetInfo^.TargetCPU := FTheDebugger.FGDBCPU
|
||||||
|
else // guess
|
||||||
|
case TargetInfo^.TargetPtrSize of
|
||||||
|
4: TargetInfo^.TargetCPU := 'x86'; // guess
|
||||||
|
8: TargetInfo^.TargetCPU := 'x86_64'; // guess
|
||||||
|
else TargetInfo^.TargetCPU := 'x86'; // guess
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else begin
|
||||||
if FTheDebugger.FGDBCPU <> ''
|
if FTheDebugger.FGDBCPU <> ''
|
||||||
then TargetInfo^.TargetCPU := FTheDebugger.FGDBCPU
|
then TargetInfo^.TargetCPU := FTheDebugger.FGDBCPU
|
||||||
else TargetInfo^.TargetCPU := 'x86'; // guess
|
else TargetInfo^.TargetCPU := 'x86'; // guess
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
7: begin
|
7: begin
|
||||||
TargetInfo^.TargetCPU := 'arm';
|
TargetInfo^.TargetCPU := 'arm';
|
||||||
end;
|
end;
|
||||||
@ -2818,8 +2846,12 @@ function TGDBMIDebuggerCommandStartDebugging.DoExecute: Boolean;
|
|||||||
DebugLn('[WARNING] [Debugger.TargetInfo] Unknown FileType: %s, using GDB cpu', [AFileType]);
|
DebugLn('[WARNING] [Debugger.TargetInfo] Unknown FileType: %s, using GDB cpu', [AFileType]);
|
||||||
|
|
||||||
TargetInfo^.TargetCPU := FTheDebugger.FGDBCPU;
|
TargetInfo^.TargetCPU := FTheDebugger.FGDBCPU;
|
||||||
|
// Todo, check PtrSize and downgrade 64 bit cpu to 32 bit cpu, if required
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if not FoundPtrSize
|
||||||
|
then TargetInfo^.TargetPtrSize := CpuNameToPtrSize(TargetInfo^.TargetCPU);
|
||||||
|
|
||||||
case StringCase(TargetInfo^.TargetCPU, [
|
case StringCase(TargetInfo^.TargetCPU, [
|
||||||
'x86', 'i386', 'i486', 'i586', 'i686',
|
'x86', 'i386', 'i486', 'i586', 'i686',
|
||||||
'ia64', 'x86_64', 'powerpc',
|
'ia64', 'x86_64', 'powerpc',
|
||||||
@ -2831,10 +2863,17 @@ function TGDBMIDebuggerCommandStartDebugging.DoExecute: Boolean;
|
|||||||
TargetInfo^.TargetRegisters[2] := '$ecx';
|
TargetInfo^.TargetRegisters[2] := '$ecx';
|
||||||
end;
|
end;
|
||||||
5, 6: begin // ia64, x86_64
|
5, 6: begin // ia64, x86_64
|
||||||
|
if TargetInfo^.TargetPtrSize = 4
|
||||||
|
then begin
|
||||||
|
TargetInfo^.TargetRegisters[0] := '$eax';
|
||||||
|
TargetInfo^.TargetRegisters[1] := '$edx';
|
||||||
|
TargetInfo^.TargetRegisters[2] := '$ecx';
|
||||||
|
end
|
||||||
|
else begin
|
||||||
TargetInfo^.TargetRegisters[0] := '$rdi';
|
TargetInfo^.TargetRegisters[0] := '$rdi';
|
||||||
TargetInfo^.TargetRegisters[1] := '$rsi';
|
TargetInfo^.TargetRegisters[1] := '$rsi';
|
||||||
TargetInfo^.TargetRegisters[2] := '$rdx';
|
TargetInfo^.TargetRegisters[2] := '$rdx';
|
||||||
TargetInfo^.TargetPtrSize := 8;
|
end;
|
||||||
end;
|
end;
|
||||||
7: begin // powerpc
|
7: begin // powerpc
|
||||||
TargetInfo^.TargetIsBE := True;
|
TargetInfo^.TargetIsBE := True;
|
||||||
@ -3243,7 +3282,7 @@ function TGDBMIDebuggerCommandExecute.ProcessStopped(const AParams: String;
|
|||||||
else Result.Address := GetData('$fp+%d', [TargetInfo^.TargetPtrSize * 3]);
|
else Result.Address := GetData('$fp+%d', [TargetInfo^.TargetPtrSize * 3]);
|
||||||
|
|
||||||
Str(Result.Address, S);
|
Str(Result.Address, S);
|
||||||
if ExecuteCommand('info line * pointer(%s)', [S], R)
|
if ExecuteCommand('info line * POINTER(%s)', [S], R)
|
||||||
then begin
|
then begin
|
||||||
Result.SrcLine := StrToIntDef(GetPart('Line ', ' of', R.Values), -1);
|
Result.SrcLine := StrToIntDef(GetPart('Line ', ' of', R.Values), -1);
|
||||||
Result.SrcFile := ConvertGdbPathAndFile(GetPart('\"', '\"', R.Values));
|
Result.SrcFile := ConvertGdbPathAndFile(GetPart('\"', '\"', R.Values));
|
||||||
@ -3256,7 +3295,7 @@ function TGDBMIDebuggerCommandExecute.ProcessStopped(const AParams: String;
|
|||||||
then Result.ObjAddr := TargetInfo^.TargetRegisters[0]
|
then Result.ObjAddr := TargetInfo^.TargetRegisters[0]
|
||||||
else begin
|
else begin
|
||||||
if dfImplicidTypes in FTheDebugger.DebuggerFlags
|
if dfImplicidTypes in FTheDebugger.DebuggerFlags
|
||||||
then Result.ObjAddr := Format('^pointer($fp+%d)^', [TargetInfo^.TargetPtrSize * 2])
|
then Result.ObjAddr := Format('^POINTER($fp+%d)^', [TargetInfo^.TargetPtrSize * 2])
|
||||||
else Str(GetData('$fp+%d', [TargetInfo^.TargetPtrSize * 2]), Result.ObjAddr);
|
else Str(GetData('$fp+%d', [TargetInfo^.TargetPtrSize * 2]), Result.ObjAddr);
|
||||||
end;
|
end;
|
||||||
Result.Name := GetInstanceClassName(Result.ObjAddr, []);
|
Result.Name := GetInstanceClassName(Result.ObjAddr, []);
|
||||||
@ -5308,6 +5347,8 @@ begin
|
|||||||
else MessageDlg('Debugger', Format('Failed to create debug process: %s', [ReadLine]), mtError, [mbOK], 0);
|
else MessageDlg('Debugger', Format('Failed to create debug process: %s', [ReadLine]), mtError, [mbOK], 0);
|
||||||
SetState(dsError);
|
SetState(dsError);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
FGDBPtrSize := CpuNameToPtrSize(FGDBCPU);
|
||||||
finally
|
finally
|
||||||
UnlockRelease;
|
UnlockRelease;
|
||||||
end;
|
end;
|
||||||
@ -8286,6 +8327,9 @@ begin
|
|||||||
S := Format(AExpression, AValues);
|
S := Format(AExpression, AValues);
|
||||||
OK := ExecuteCommand('-data-evaluate-expression ^^shortstring(%s+%d)^^',
|
OK := ExecuteCommand('-data-evaluate-expression ^^shortstring(%s+%d)^^',
|
||||||
[S, TargetInfo^.TargetPtrSize * 3], R);
|
[S, TargetInfo^.TargetPtrSize * 3], R);
|
||||||
|
if (not OK) or (LastExecResult.State = dsError)
|
||||||
|
then OK := ExecuteCommand('-data-evaluate-expression ^char(^pointer(%s+%d)^+1)',
|
||||||
|
[S, TargetInfo^.TargetPtrSize * 3], R);
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
Str(TDbgPtr(GetData(AExpression + '+12', AValues)), S);
|
Str(TDbgPtr(GetData(AExpression + '+12', AValues)), S);
|
||||||
@ -8314,7 +8358,7 @@ function TGDBMIDebuggerCommand.GetInstanceClassName(const AExpression: String;
|
|||||||
begin
|
begin
|
||||||
if dfImplicidTypes in FTheDebugger.DebuggerFlags
|
if dfImplicidTypes in FTheDebugger.DebuggerFlags
|
||||||
then begin
|
then begin
|
||||||
Result := GetClassName('^pointer(' + AExpression + ')^', AValues);
|
Result := GetClassName('^POINTER(' + AExpression + ')^', AValues);
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
Result := GetClassName(GetData(AExpression, AValues));
|
Result := GetClassName(GetData(AExpression, AValues));
|
||||||
|
Loading…
Reference in New Issue
Block a user