GNU Binutils with patches for OS216
Revision | 0625771b9e29116dc1fb0b597501f18e4bb0e18c (tree) |
---|---|
Zeit | 2018-02-03 04:03:25 |
Autor | Leszek Swirski via gdb-patches <gdb-patches@sour...> |
Commiter | Simon Marchi |
MI: Allow non-raw varobj evaluation
Make the MI variable object expression evaluation, with the
-var-evaluate-expression command, recursively call pretty printers, to
match the output of normal expression printing.
Consider the following code:
and this pretty printer file:
Setting a breakpoint at the end of the function, we call the following commands:
So, in the -var-evaluate-expression var_w case, we print the "raw" value
of w.foo, while in the -data-evaluate-expression w case, we print the
pretty printed w.foo value. After this patch, all of the above print
"Foo23".
gdb/ChangeLog:
* varobj.c (varobj_formatted_print_options): Allow recursive
pretty printing if pretty printing is enabled.
gdb/testsuite/ChangeLog:
* gdb.python/py-prettyprint.c
(struct to_string_returns_value_inner,
struct to_string_returns_value_wrapper): New.
(main): Add tsrvw variable.
* gdb.python/py-prettyprint.py (ToStringReturnsValueInner,
ToStringReturnsValueWrapper): New classes.
(register_pretty_printers): Register new pretty-printers.
* gdb.python/py-prettyprint.exp (run_lang_tests): Test printing
recursive pretty printer.
* gdb.python/py-mi.exp: Likewise.
@@ -1,5 +1,10 @@ | ||
1 | 1 | 2018-02-01 Leszek Swirski <leszeks@google.com> |
2 | 2 | |
3 | + * varobj.c (varobj_formatted_print_options): Allow recursive | |
4 | + pretty printing if pretty printing is enabled. | |
5 | + | |
6 | +2018-02-01 Leszek Swirski <leszeks@google.com> | |
7 | + | |
3 | 8 | * c-exp.y (lex_one_token, classify_name, yylex): Don't classify |
4 | 9 | names after a structop as a filename. |
5 | 10 |
@@ -1,3 +1,17 @@ | ||
1 | +2018-02-01 Simon Marchi <simon.marchi@polymtl.ca> | |
2 | + Leszek Swirski <leszeks@google.com> | |
3 | + | |
4 | + * gdb.python/py-prettyprint.c | |
5 | + (struct to_string_returns_value_inner, | |
6 | + struct to_string_returns_value_wrapper): New. | |
7 | + (main): Add tsrvw variable. | |
8 | + * gdb.python/py-prettyprint.py (ToStringReturnsValueInner, | |
9 | + ToStringReturnsValueWrapper): New classes. | |
10 | + (register_pretty_printers): Register new pretty-printers. | |
11 | + * gdb.python/py-prettyprint.exp (run_lang_tests): Test printing | |
12 | + recursive pretty printer. | |
13 | + * gdb.python/py-mi.exp: Likewise. | |
14 | + | |
1 | 15 | 2018-02-01 Leszek Swirski <leszeks@google.com> |
2 | 16 | |
3 | 17 | * gdb.cp/filename.cc, gdb.cp/filename.exp: Test that member |
@@ -295,6 +295,16 @@ mi_gdb_test "-var-evaluate-expression me" \ | ||
295 | 295 | mi_create_dynamic_varobj children_as_list children_as_list 1 \ |
296 | 296 | "printer whose children are returned as a list" |
297 | 297 | |
298 | +# Test that when a pretty-printer returns a gdb.Value in its to_string, we call | |
299 | +# the pretty-printer of that value too. | |
300 | +mi_create_varobj_checked tsrvw tsrvw \ | |
301 | + "struct to_string_returns_value_wrapper" \ | |
302 | + "create tsrvw varobj" | |
303 | +mi_check_varobj_value tsrvw "Inner to_string 1989" "check tsrvw varobj value" | |
304 | +mi_gdb_test "-data-evaluate-expression tsrvw" \ | |
305 | + "\\^done,value=\"Inner to_string 1989\"" \ | |
306 | + "check tsrvw expression value" | |
307 | + | |
298 | 308 | # Regression test for bug 14741. |
299 | 309 | mi_continue_to_line \ |
300 | 310 | [gdb_get_line_number {breakpoint bug 14741} ${srcfile}] \ |
@@ -112,6 +112,16 @@ class Fake | ||
112 | 112 | }; |
113 | 113 | #endif |
114 | 114 | |
115 | +struct to_string_returns_value_inner | |
116 | +{ | |
117 | + int val; | |
118 | +}; | |
119 | + | |
120 | +struct to_string_returns_value_wrapper | |
121 | +{ | |
122 | + struct to_string_returns_value_inner inner; | |
123 | +}; | |
124 | + | |
115 | 125 | struct substruct { |
116 | 126 | int a; |
117 | 127 | int b; |
@@ -284,6 +294,7 @@ main () | ||
284 | 294 | struct lazystring estring, estring2, estring3; |
285 | 295 | struct hint_error hint_error; |
286 | 296 | struct children_as_list children_as_list; |
297 | + struct to_string_returns_value_wrapper tsrvw = { { 1989 } }; | |
287 | 298 | |
288 | 299 | nstype.elements = narray; |
289 | 300 | nstype.len = 0; |
@@ -64,6 +64,10 @@ proc run_lang_tests {exefile lang} { | ||
64 | 64 | |
65 | 65 | gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}" |
66 | 66 | |
67 | + # Test that when a pretty-printer returns a gdb.Value in its to_string, we | |
68 | + # call the pretty-printer of that value too. | |
69 | + gdb_test "print tsrvw" " = Inner to_string 1989" | |
70 | + | |
67 | 71 | if {$lang == "c++"} { |
68 | 72 | gdb_test "print cps" "= a=<8> b=<$hex>" |
69 | 73 | gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}" |
@@ -84,6 +84,25 @@ class NoStringContainerPrinter (object): | ||
84 | 84 | def children(self): |
85 | 85 | return _iterator_except (self.val['elements'], self.val['len']) |
86 | 86 | |
87 | +# See ToStringReturnsValueWrapper. | |
88 | +class ToStringReturnsValueInner: | |
89 | + | |
90 | + def __init__(self, val): | |
91 | + self.val = val | |
92 | + | |
93 | + def to_string(self): | |
94 | + return 'Inner to_string {}'.format(int(self.val['val'])) | |
95 | + | |
96 | +# Test a printer that returns a gdb.Value in its to_string. That gdb.Value | |
97 | +# also has its own pretty-printer. | |
98 | +class ToStringReturnsValueWrapper: | |
99 | + | |
100 | + def __init__(self, val): | |
101 | + self.val = val | |
102 | + | |
103 | + def to_string(self): | |
104 | + return self.val['inner'] | |
105 | + | |
87 | 106 | class pp_s (object): |
88 | 107 | def __init__(self, val): |
89 | 108 | self.val = val |
@@ -316,7 +335,12 @@ def register_pretty_printers (): | ||
316 | 335 | pretty_printers_dict[re.compile ('^string_repr$')] = string_print |
317 | 336 | pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter |
318 | 337 | pretty_printers_dict[re.compile ('^justchildren$')] = NoStringContainerPrinter |
319 | - | |
338 | + | |
339 | + pretty_printers_dict[re.compile ('^struct to_string_returns_value_inner$')] = ToStringReturnsValueInner | |
340 | + pretty_printers_dict[re.compile ('^to_string_returns_value_inner$')] = ToStringReturnsValueInner | |
341 | + pretty_printers_dict[re.compile ('^struct to_string_returns_value_wrapper$')] = ToStringReturnsValueWrapper | |
342 | + pretty_printers_dict[re.compile ('^to_string_returns_value_wrapper$')] = ToStringReturnsValueWrapper | |
343 | + | |
320 | 344 | pretty_printers_dict[re.compile ('^struct ns$')] = pp_ns |
321 | 345 | pretty_printers_dict[re.compile ('^ns$')] = pp_ns |
322 | 346 |
@@ -2274,7 +2274,7 @@ varobj_formatted_print_options (struct value_print_options *opts, | ||
2274 | 2274 | { |
2275 | 2275 | get_formatted_print_options (opts, format_code[(int) format]); |
2276 | 2276 | opts->deref_ref = 0; |
2277 | - opts->raw = 1; | |
2277 | + opts->raw = !pretty_printing; | |
2278 | 2278 | } |
2279 | 2279 | |
2280 | 2280 | std::string |