简体   繁体   English

lldb不会在终端中打印所有字符

[英]lldb won't print all characters in Terminal

I'm using lldb from Terminal to debug a C++ program. 我正在使用来自Terminal的lldb调试C ++程序。 I can use it for most things except it won't print certain characters. 我可以将其用于大多数事情,除了它不会打印某些字符。

At some point my program receives a byte array from a remote system ( vector<unsigned char> ) and when I print that value I get the following: 在某个时候,我的程序从远程系统( vector<unsigned char> )接收一个字节数组,当我打印该值时,得到以下信息:

  [10] = '\0'
  [11] = '\0'
  [12] = 'O'
  [13] = '\b'
  [14] = '\0'
  [15] = '\x01'
  [16] = '\0'
  [17] = '\0'
  [18] = '\0'
  [19] = '\x17'
  [20] = '\0'
  [21] = '\x04'
  [22] = '?'
  [23] = '?'
  [24] = '?'
  [25] = '?'
  [26] = '\0'
  [27] = '\0'
  [28] = 'n'
  [29] = 'a'
  [30] = 'm'
  [31] = 'e'
  [32] = '\0'
  [33] = '\0'
  [34] = '\0'

Using Xcode I can see that the four ? 使用Xcode我可以看到这四个? marks have been turned to four \\xff . 标记已变成四个\\xff Is there a way to make lldb print these characters correctly without Xcode? 有没有一种方法可以使lldb在没有Xcode的情况下正确打印这些字符?

If you want to see the hex values of elements of a character array, you can use lldb's emulation of the gdb formatting synatax: 如果要查看字符数组元素的十六进制值,可以使用lldb对gdb格式的合成语法的仿真:

(lldb) print/x char_vec

To see all the formatting options available do: 要查看所有可用的格式设置选项,请执行以下操作:

(lldb) help gdb-format

BTW, I'm not sure it's right to say this is "printing them correctly...". 顺便说一句,我不确定是否正确地说这是“正确打印它们...”。 If I have a character array with some 0xff values in it, printf prints them as '?'. 如果我有一个字符数组,其中包含一些0xff值,则printf将它们打印为'?'。 That's the character representation of this value. 这就是该值的字符表示。 By default lldb prints char variables by interpreting them as printf would. 默认情况下,lldb通过将字符变量解释为printf来打印char变量。 You can change this default to hex if that suits you better using lldb's data formatters. 如果更适合使用lldb的数据格式化程序,则可以将此默认值更改为十六进制。 See: 看到:

http://lldb.llvm.org/varformats.html http://lldb.llvm.org/varformats.html

for more details. 更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM