秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  278 随笔 :: 0 文章 :: 308 评论 :: 20万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
注意:这个问题在lazarus4.99 / fixes-4(lazarus 4.0rc1) 分支中已修复。
lazarus在windows使用GDB时中文字符不能正确显示,显示为#229#173#151之类的字符而不是中文。

 

 处理方法:

 打开lazarus/components/lazdebuggergdbmi/gdbmidebugger.pp,按红色代码修改。

在function TGDBMIDebuggerCommand.GetGDBTypeInfo(const AExpression: String;(12409行)前添加function tochinesechar(str:string):string;

复制代码
function tochinesechar(str:string):string;
var i:integer;
  tmp,tmpstr:string;
  chr1:byte;
  e:integer;
begin
  tmp:='';
  result:=str;
  if (copy(str,1,8)=',value="') and (str[length(str)]='"') then
  begin
    tmp:=',value=';
    i:=9;
    while i<=length(str)-1 do
    begin
      if str[i]<>'#' then
      begin
        tmp:=tmp+str[i];
        i:=i+1;
      end
      else
      begin
         tmpstr:=copy(str,i+1,3);
         val(tmpstr,chr1,e);
         if e=0 then
         begin
           tmp:=tmp+chr(chr1);
           i:=i+4;
         end
         else
         begin
           tmp:=tmp+str[i];
           i:=i+1;
         end;
       end;
    end;
    i:=1;
    result:='';
    while i<=length(tmp) do
    begin
      if copy(tmp,i,4)='''''''''' then
      begin
        result:=result+'''''''';
        i:=i+4;
      end
      else
      if copy(tmp,i,2)='''''' then
      begin
        result:=result+'''''';
        i:=i+2;
      end
      else
      if (i>9) and (i<length(tmp)) and (copy(tmp,i,1)='''') then
      begin
        result:=result+'';
        i:=i+1;
      end
      else
      begin
        result:=result+tmp[i];
        inc(i);
      end;
    end;
  end;
end;

function TGDBMIDebuggerCommand.GetGDBTypeInfo(const AExpression: String;
  FullTypeInfo: Boolean; AFlags: TGDBTypeCreationFlags; AFormat: TWatchDisplayFormat;
  ARepeatCount: Integer): TGDBType;
var
  R: TGDBMIExecResult;
  f: Boolean;
  AReq: PGDBPTypeRequest;
  CReq: TGDBPTypeRequest;
  i: Integer;
begin
  (*   Analyze what type is in AExpression
     * "whatis AExpr"
       This return the declared type of the expression (as in the pascal source)
复制代码

 

12544行:

复制代码
        f :=  ExecuteCommand(AReq^.Request, R);
        if f and (R.State <> dsError) then begin
          if AReq^.ReqType = gcrtPType
          then AReq^.Result :=ParseTypeFromGdb(R.Values)
          else begin
            AReq^.Result.GdbDescription :={$ifdef MSWINDOWS}tochinesechar(R.Values){$ELSE}R.Values{$ENDIF};
            AReq^.Result.Kind := ptprkSimple;
          end;
        end
        else begin
          AReq^.Result.GdbDescription := R.Values;
          AReq^.Error :=R.Values;
        end;
复制代码

按上述方法修改后重新编译lazarus。
现在在windows使用GDB时已能正确显示中文字符了:

 

posted on   秋·风  阅读(93)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示