lldb:`print`和`display`的一行输出

时间:2015-07-09 21:04:35

标签: c macos lldb

例如,使用源代码main.c

#include <stdio.h>

int main()
{
    int a[10] = {0,1,2,3,4,5,6,7,8,9};
    int b = 2;
    printf("line 7\n");
    printf("line 8\n");
    return 0;
}

使用LLDB调试器,print a生成:

(int [10]) $0 = {
  [0] = 0
  [1] = 1
  [2] = 2
  [3] = 3
  [4] = 4
  [5] = 5
  [6] = 6
  [7] = 7
  [8] = 8
  [9] = 9
}

问题0 :如何在print的一行上进行小型打印,与GDB一样:

$1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

使用LLDB调试器,display adisplay b生成:

- Hook 1 (expr -- a)
(int [10]) $0 = {
  [0] = 0
  [1] = 1
  [2] = 2
  [3] = 3
  [4] = 4
  [5] = 5
  [6] = 6
  [7] = 7
  [8] = 8
  [9] = 9
}

- Hook 2 (expr -- b)
(int) $1 = 2

问题1:如何在display的两行上进行小型打印,与GDB一样:

2: b = 2
1: a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

1 个答案:

答案 0 :(得分:1)

默认情况下,在FormatManager :: ShouldPrintAsOneLiner

中硬编码哪些类型执行和不执行“一行”打印的决定

用户可以调整的唯一设置是

(lldb) settings show auto-one-line-summaries
auto-one-line-summaries (boolean) = true

充当该功能的全局kill-switch(true表示“允许”)

快速解决您的问题是手动为所有int数组添加摘要,因此:

(lldb) type summary add -x "int \[[0-9]+]" -c

也就是说,对于名称与正则表达式int匹配的所有类型[后跟一个或多个数字后跟a],然后强制执行单行格式化

有了这个,我得到了

(lldb) fr var x
(int [10]) x = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9)
(lldb) expr x
(int [10]) $2 = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9)

尽管如此,我认为你使用的是LLDB的旧版本

在最近构建的调试器上,即使没有自定义格式,我也能获得单行显示:

(lldb) expr x
(int [10]) $0 = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9)