之前已修复fpdebug中文变量的Bug,但GDB还存在问题(提示:Invalid character xxxx in expression)
修复步骤:
打开lazarus/components/lazdebuggergdbmi/gdbmidebugger.pp,按红色代码修改。
在TGDBMIExceptionInfo = record后添加function ischinese(s:string):string(1790行):TGDBMIExceptionInfo = record ObjAddr: String; Name: String; end; function ischinese(s:string):string; var i:integer; begin result:=s; for i:=1 to length(s) do begin if ord(s[i])>127 then begin result:=''''+s+''''; break; end; end; end; { =========================================================================== } { Some win32 stuff } { =========================================================================== } {$IFdef MSWindows} var DebugBreakAddr: Pointer = nil;
12468行
if tfClassIsPointer in TargetInfo^.TargetFlags then AFlags := AFlags + [gtcfClassIsPointer]; if FullTypeInfo then AFlags := AFlags + [gtcfFullTypeInfo]; Result := TGdbType.CreateForExpression(ischinese(AExpression), AFlags, wdfDefault, ARepeatCount); while not Result.ProcessExpression do begin if Result.EvalError then break;
12559行
begin Result := ''; UseShortString := False; if dfImplicidTypes in FTheDebugger.DebuggerFlags then begin S := Format(ischinese(AExpression), AValues); UseShortString := TargetInfo^.TargetFlags * [tfFlagHasTypeShortstring, tfFlagMaybeDwarf3] = [tfFlagHasTypeShortstring]; if UseShortString then s := Format('^^shortstring(%s+%d)^^', [S, TargetInfo^.TargetPtrSize * 3])
12576行
end else begin UseShortString := True; Str(TDbgPtr(GetData(ischinese(AExpression) + '+12', AValues)), S); OK := ExecuteCommand('-data-evaluate-expression pshortstring(%s)^', [S], R); end; if OK then begin ResultList := TGDBMINameValueList.Create(R);
12619/12622行
function TGDBMIDebuggerCommand.GetInstanceClassName(const AExpression: String; const AValues: array of const): String; begin if dfImplicidTypes in FTheDebugger.DebuggerFlags then begin Result := GetClassName('^' + PointerTypeCast + '(' + ischinese(AExpression) + ')^', AValues); end else begin Result := GetClassName(GetData(ischinese(AExpression), AValues)); end; end;
12667/12678/12693行
function TGDBMIDebuggerCommand.GetData(const AExpression: String; const AValues: array of const): TDbgPtr; var R: TGDBMIExecResult; e: Integer; begin Result := 0; if ExecuteCommand('x/d ' + ischinese(AExpression), AValues, R, [cfNoMemLimits]) then Val(StripLN(GetPart('\t', '', R.Values)), Result, e); if e=0 then ; end; function TGDBMIDebuggerCommand.GetStrValue(const AExpression: String; const AValues: array of const; AFlags: TGDBMICommandFlags): String; var R: TGDBMIExecResult; ResultList: TGDBMINameValueList; begin if ExecuteCommand('-data-evaluate-expression %s', [Format(ischinese(AExpression), AValues)], R, AFlags) then begin ResultList := TGDBMINameValueList.Create(R); Result := DeleteEscapeChars(ResultList.Values['value']); ResultList.Free; end else Result := ''; end; function TGDBMIDebuggerCommand.GetIntValue(const AExpression: String; const AValues: array of const): Integer; var e: Integer; begin Result := 0; Val(GetStrValue(ischinese(AExpression), AValues, [cfNoMemLimits]), Result, e); if e=0 then ; end;
12722行
function TGDBMIDebuggerCommand.GetPtrValue(const AExpression: String; const AValues: array of const; ConvertNegative: Boolean; AFlags: TGDBMICommandFlags): TDbgPtr; begin Result := GetPtrValue( GetStrValue(ischinese(AExpression), AValues, [cfNoMemLimits]+AFlags) ); end;
14494行
procedure GetNumValue(const AExpression: String); var s: String; begin s := GetStrValue(ischinese(AExpression), [], [cfNoMemLimits]); FHasNumValue := nvUnsigned; if (s <> '') and (s[1] = '-') then FHasNumValue := nvSigned; FNumValue := GetPtrValue(s); end;
修改后重新编译lazarus.
标签:begin,const,AExpression,GDB,lazarus,AValues,Result,debug,end From: https://www.cnblogs.com/qiufeng2014/p/18451348