【问题标题】:(lldb) Print unsigned long long in hex(lldb) 以十六进制打印 unsigned long long
【发布时间】:2012-09-11 13:16:15
【问题描述】:

我正在尝试调试我的 Objective-C 程序,我需要以十六进制打印我的 unsigned long long 变量。我正在使用lldb 调试器。

为了将short 打印为十六进制,you can use this

(lldb) type format add --format hex short
(lldb) print bit
(short) $11 = 0x0000

但是,我无法让它为 unsigned long long 工作。

// failed attempts:
(lldb) type format add --format hex (unsigned long long)
(lldb) type format add --format hex unsigned long long
(lldb) type format add --format hex unsigned decimal
(lldb) type format add --format hex long long
(lldb) type format add --format hex long
(lldb) type format add --format hex int

我正在模拟器上运行一个 iOS 应用程序,如果这有什么不同的话。

【问题讨论】:

    标签: objective-c debugging hex lldb unsigned-long-long-int


    【解决方案1】:

    您可以使用格式字母。链接到 GDB 文档(也适用于 LLDB):https://sourceware.org/gdb/current/onlinedocs/gdb/Output-Formats.html#Output-Formats

    (lldb) p a
    (unsigned long long) $0 = 10
    (lldb) p/x a
    (unsigned long long) $1 = 0x000000000000000a
    

    【讨论】:

    • 请注意,虽然 gdb 接受 p/x 之间的空格,但 lldb 不接受,所以 p /x 在 gdb 中有效,但在 lldb 中它必须是 p/x。跨度>
    • @Vlad 你能指出所有命令的更具体的链接吗?
    • @DeveloperSheldon 好像链接已经过期了。我已经编辑了我的答案,所以现在它包含 GDB 的所有输出格式的工作链接。请检查一下。
    【解决方案2】:

    type format add 期望类型名称为单个单词——如果它是多个单词,则需要引用参数。例如

       2    {
       3      unsigned long long a = 10;
    -> 4      a += 5;
       5      return a;
       6    }
    (lldb) type form add -f h "unsigned long long"
    (lldb) p a
    (unsigned long long) $0 = 0x000000000000000a
    (lldb) 
    

    【讨论】:

      【解决方案3】:

      在阅读了document 的其余部分后,我发现可以这样做:

      // ObjC code
      typedef int A;
      

      那么,

      (lldb) type format add --format hex A
      

      这让我想到了typedef unsigned long long BigInt

      // ObjC code
      typedef unsigned long long BigInt;
      

      那么,

      (lldb) type format add --format hex BigInt
      

      像魅力一样工作。

      【讨论】:

        猜你喜欢
        • 2013-10-17
        • 2015-06-13
        • 2020-05-14
        • 2015-12-18
        • 1970-01-01
        • 2013-03-05
        • 1970-01-01
        • 2016-07-29
        • 2013-10-01
        相关资源
        最近更新 更多