我需要在CLion中添加十六进制格式的手表.
ltoa(variable, 16) 至少在我的系统上不起作用.
在Java/Python中,我可以有一个解决方法:为我的类编写一个自定义toString()/ __str__并让它以我需要的方式显示.gdb有p/x.我如何在CLion中做到这一点?
编辑:ltoa(variable, 16)如果我ltoa在我的代码中定义,则有效,因为它并不总是出现在标准库中.
set output-radix 16
Run Code Online (Sandbox Code Playgroud)
您可以将此设置为名为的文件中的默认选项.gdbinit,您可以将其放在主目录中,也可以将其作为启动GDB的工作目录(例如,项目根目录).
......在完善配方之后,我明白了。
\n\n我写了我自己的char *lltoa(long long value, int radix)函数。我现在可以在手表中使用它。
更新:在相应的功能请求中,Chris White 在 OS X 上使用 lldb 找到了解决方法:
\n\n\n\n\n我决定做更多的挖掘,并找到了一种在 OS X\n 上设置 lldb 的方法,以强制对 unsigned char 数据类型进行十六进制输出:
\n\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\x8btype format add \xe2\x80\x93format hex "unsigned char"\n如果您想使此设置持久化,您还可以创建\n .lldbinit 文件并向其中添加此命令。执行此操作后,CLion\n 将以十六进制格式显示此数据类型。
\n
这使得该类型的所有变量都以十六进制显示。
\n\n更新 2:我的第一个解决方法非常脏,这里有一个更好的解决方法。
\n\n您可以将格式分配给更具体的类型。调试器跟踪类型继承。因此,添加hex格式uint8_t不会影响unsigned char. 您可以微调显示。
您也可以为结构指定格式。这是我的一个例子.lldbinit:
type format add --format dec int32_t\n\n# https://lldb.llvm.org/varformats.html\ntype summary add --summary-string "addr=${var.address} depth=${var.depth}" Position\nRun Code Online (Sandbox Code Playgroud)\n