首页 > 其他分享 >今天终于解决lazarus debug模式为GDB时中文变量显示出错的问题

今天终于解决lazarus debug模式为GDB时中文变量显示出错的问题

时间:2024-10-08 11:32:58浏览次数:1  
标签:begin const AExpression GDB lazarus AValues Result debug end

之前已修复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

相关文章

  • gdb调试
    1、https://gitee.com/下载课程代码,编译运⾏"bestidiocs2024/ch02/c/testgdb.c",记录编译运⾏结果(2分)运行结果:Thesumof1-50is12752、参考https://www.cnblogs.com/rocedu/p/16714289.html调试代码,⾄少涵盖4种断点(⾏断点,函数断点,临时断点,条件断点)行断点:bmain函数断点:b......
  • gdb
    gdb控制程序行为环境变量(gdb)setenvironmentVAR=value多线程相关命令查看线程列表:在gdb中可以使用以下命令查看当前所有线程的列表:(gdb)infothreads这将列出所有线程及其状态,包括它们的LWPID和线程标识符。切换到特定线程:如果你想切换调试上下文到某......
  • Debuggers 1012:Introductory GDB
    OpenSecurityTraining2LearningPaths:VulnerabilityHunting&Exploitationpython:https://www.learnpython.org/路径图:https://ost2.fyi/OST2_LP_Vulns_Exploits.pdfDebuggers1012:IntroductoryGDB(与python)-->Architecture1001:x86-64Assembly-->R......
  • python多进程debug
    代码调试问题阐述最近遇到一个pythondebug多进程的问题有一个进程A,这个进程会fork出8个进程B,forkjoin结束后,又会fork出8个进程A。假设按时间有序,我就只想断fork出的第一个B和第一个进程A,怎么做?(breakpointjustbreakonlyonce)类似于java多线程调试的意思,只断一个线程,all-......
  • Android Debug Bridge(ADB)完全指南
    文章目录前言一、什么是ADB?二、ADB的工作原理ADB由三个部分组成:三、如何安装ADBWindows系统:macOS和Linux系统:四、ADB常用指令大全设备相关操作1.查看连接的设备:2.重启设备:3.进入Bootloader模式:4.进入恢复模式(Recovery):5.查看设备运行状态:6.获取设备的序列号:7.查......
  • android开发Execution failed for task ':bundleDebugAar'...Direct local .aar file
    1.问题描述[+103ms]FAILURE:Buildfailedwithanexception.[]*Whatwentwrong:[]Executionfailedfortask':jpush_flutter:bundleDebugAar'.[]>Errorwhileevaluatingproperty'hasLocalAarDeps'oftask......
  • linux gdb debuging
    GDBGNU下的一个调试软件,在linux下可以用来调试c/c++代码。启动可以通过gdb--help查看用法,如下:ThisistheGNUdebugger.Usage:gdb[options][executable-file[core-fileorprocess-id]]gdb[options]--argsexecutable-file[inferior-arguments...]gdb[optio......
  • mongdb7副本集修改IP
    mongdb7副本集修改IP环境信息主机名IP端口资源mongodb1192.168.56.111C/2G/50Gmongodb2192.168.56.121C/2G/50Gmongodb3192.168.56.131C/2G/50Goperatingsystem:CentOS-7.6-x86_64-DVD-1810.isoMasterIP:192.168.56.11SlaveIP:192.168.56.12ArbiterIP:192.168.56.13......
  • VS控制台出现debug()乱码问题
    出现的问题之前项目debug()控制台打印正常,增删后发现只有debug()将强转到QString::fromLocal8Bit才可以显示出来,VS控制台或调试器默认使用UTF-8解码,我通过cmd控制台查看自身活动代码为936(简体中文的GBK编码)因此不兼容有两种方法,我用的是第二种,建议第二种方法一:在控制台中......
  • /sys/kernel/debug/binder/目录下主要节点含义
    /sys/kernel/debug/binder/目录下主要节点含义state显示binder设备的整体状态信息包括进程数量、线程数量、待处理事务数量等stats展示binder操作的统计信息如事务数量、内存使用情况等transactions列出当前正在处理的binder事务包括发送方、接收方、数据大小......