• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision0625771b9e29116dc1fb0b597501f18e4bb0e18c (tree)
Zeit2018-02-03 04:03:25
AutorLeszek Swirski via gdb-patches <gdb-patches@sour...>
CommiterSimon Marchi

Log Message

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:

struct Foo { int val; };
struct Wrapper { Foo foo; };
int main() {
Wrapper w;
w.foo.val = 23;
}

and this pretty printer file:

import gdb.printing
class FooPrinter:
def init(self, val):
self.val = val
def to_string(self):
return "Foo" + str(self.valval)
class WrapperPrinter:
def init(self, val):
self.val = val
def to_string(self):
return self.valfoo
test_printer = gdb.printing.RegexpCollectionPrettyPrinter("test")
test_printer.add_printer('Foo', 'Foo$', FooPrinter)
test_printer.add_printer('Wrapper', '
Wrapper$', WrapperPrinter)
gdb.printing.register_pretty_printer(None, test_printer)

Setting a breakpoint at the end of the function, we call the following commands:

-enable-pretty-printing
done
-var-create var_w @ w
done,name="var_w",numchild="0",value="{val = 23}",type="Wrapper",dynamic="1",has_more="0"
-var-create var_w_foo @ w.foo
done,name="var_w_foo",numchild="0",value="Foo23",type="Foo",dynamic="1",has_more="0"
-var-evaluate-expression var_w
done,value="{val = 23}"
-var-evaluate-expression var_w_foo
done,value="Foo23"
-data-evaluate-expression w
done,value="Foo23"
-data-evaluate-expression w.foo
done,value="Foo23"

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.

Ändern Zusammenfassung

Diff

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
11 2018-02-01 Leszek Swirski <leszeks@google.com>
22
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+
38 * c-exp.y (lex_one_token, classify_name, yylex): Don't classify
49 names after a structop as a filename.
510
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -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+
115 2018-02-01 Leszek Swirski <leszeks@google.com>
216
317 * gdb.cp/filename.cc, gdb.cp/filename.exp: Test that member
--- a/gdb/testsuite/gdb.python/py-mi.exp
+++ b/gdb/testsuite/gdb.python/py-mi.exp
@@ -295,6 +295,16 @@ mi_gdb_test "-var-evaluate-expression me" \
295295 mi_create_dynamic_varobj children_as_list children_as_list 1 \
296296 "printer whose children are returned as a list"
297297
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+
298308 # Regression test for bug 14741.
299309 mi_continue_to_line \
300310 [gdb_get_line_number {breakpoint bug 14741} ${srcfile}] \
--- a/gdb/testsuite/gdb.python/py-prettyprint.c
+++ b/gdb/testsuite/gdb.python/py-prettyprint.c
@@ -112,6 +112,16 @@ class Fake
112112 };
113113 #endif
114114
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+
115125 struct substruct {
116126 int a;
117127 int b;
@@ -284,6 +294,7 @@ main ()
284294 struct lazystring estring, estring2, estring3;
285295 struct hint_error hint_error;
286296 struct children_as_list children_as_list;
297+ struct to_string_returns_value_wrapper tsrvw = { { 1989 } };
287298
288299 nstype.elements = narray;
289300 nstype.len = 0;
--- a/gdb/testsuite/gdb.python/py-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
@@ -64,6 +64,10 @@ proc run_lang_tests {exefile lang} {
6464
6565 gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}"
6666
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+
6771 if {$lang == "c++"} {
6872 gdb_test "print cps" "= a=<8> b=<$hex>"
6973 gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}"
--- a/gdb/testsuite/gdb.python/py-prettyprint.py
+++ b/gdb/testsuite/gdb.python/py-prettyprint.py
@@ -84,6 +84,25 @@ class NoStringContainerPrinter (object):
8484 def children(self):
8585 return _iterator_except (self.val['elements'], self.val['len'])
8686
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+
87106 class pp_s (object):
88107 def __init__(self, val):
89108 self.val = val
@@ -316,7 +335,12 @@ def register_pretty_printers ():
316335 pretty_printers_dict[re.compile ('^string_repr$')] = string_print
317336 pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
318337 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+
320344 pretty_printers_dict[re.compile ('^struct ns$')] = pp_ns
321345 pretty_printers_dict[re.compile ('^ns$')] = pp_ns
322346
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2274,7 +2274,7 @@ varobj_formatted_print_options (struct value_print_options *opts,
22742274 {
22752275 get_formatted_print_options (opts, format_code[(int) format]);
22762276 opts->deref_ref = 0;
2277- opts->raw = 1;
2277+ opts->raw = !pretty_printing;
22782278 }
22792279
22802280 std::string