For example, with the source code 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;
}
With the LLDB
debugger, print a
produce:
(int [10]) $0 = {
[0] = 0
[1] = 1
[2] = 2
[3] = 3
[4] = 4
[5] = 5
[6] = 6
[7] = 7
[8] = 8
[9] = 9
}
question 0: How can I get a compact printing on one line for print
, like with GDB
:
$1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
With the LLDB
debugger, display a
and display b
produce:
- 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
question 1: How can I get a compact printing on two lines for display
, like with GDB
:
2: b = 2
1: a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
by default the decision of what types do and do not get “one line” printing is hardcoded in FormatManager::ShouldPrintAsOneLiner
The only setting that users can tweak with regard to that is
(lldb) settings show auto-one-line-summaries
auto-one-line-summaries (boolean) = true
which acts as a global kill-switch for the feature (true means “allow”)
A quick fix for your problem is to manually add a summary for all int arrays, thusly:
(lldb) type summary add -x "int \[[0-9]+]" -c
That is saying, for all types whose names match the regular expression int [ followed by one ore more digits followed by a ], then force one-line formatting
With that, I get
(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)
With all of that said, I think you are on an older version of LLDB
On a fairly recent build of the debugger, I get one-line display even without customizing the formatting:
(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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.