gdb: Make python display_hint None handling defined behaviour
The documentation say that the display_hint method must return a string to serve as a display hint, and then goes on to list some acceptable strings. However, if we don't supply the display_hint method then we get a default display style behaviour and there's currently no way (in the python api) to force this default behaviour. The guile api allows #f to be used in order to force the default display style behaviour, and this is documented. Currently, using None in the python api also forces the default display behaviour. This commit extends the documentation to make returning None from the display_hint method an official mechanism by which the user can get the default display style. I've extended one of the existing tests to cover this case. gdb/doc/ChangeLog: * python.texi (Pretty Printing API): Document use of None for the display_hint. gdb/testsuite/ChangeLog: * gdb.python/py-prettyprint.c (struct container) <is_map_p>: New field. (make_container): Initialise new field. * gdb.python/py-prettyprint.exp: Add new tests. * gdb.python/py-prettyprint.py (class ContainerPrinter) <display_hint>: New method.
This commit is contained in:
parent
3714a195e0
commit
9f9aa85206
6 changed files with 40 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
|
||||||
|
|
||||||
|
* python.texi (Pretty Printing API): Document use of None for the
|
||||||
|
display_hint.
|
||||||
|
|
||||||
2019-03-22 Alan Hayward <alan.hayward@arm.com>
|
2019-03-22 Alan Hayward <alan.hayward@arm.com>
|
||||||
Jiong Wang <jiong.wang@arm.com>
|
Jiong Wang <jiong.wang@arm.com>
|
||||||
|
|
||||||
|
|
|
@ -1294,7 +1294,7 @@ consumer as a @samp{displayhint} attribute of the variable being
|
||||||
printed.
|
printed.
|
||||||
|
|
||||||
This method is optional. If it does exist, this method must return a
|
This method is optional. If it does exist, this method must return a
|
||||||
string.
|
string or the special value @code{None}.
|
||||||
|
|
||||||
Some display hints are predefined by @value{GDBN}:
|
Some display hints are predefined by @value{GDBN}:
|
||||||
|
|
||||||
|
@ -1317,6 +1317,9 @@ string-printing function to format the string. For the CLI this means
|
||||||
adding quotation marks, possibly escaping some characters, respecting
|
adding quotation marks, possibly escaping some characters, respecting
|
||||||
@code{set print elements}, and the like.
|
@code{set print elements}, and the like.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
The special value @code{None} causes @value{GDBN} to apply the default
|
||||||
|
display rules.
|
||||||
@end defun
|
@end defun
|
||||||
|
|
||||||
@defun pretty_printer.to_string (self)
|
@defun pretty_printer.to_string (self)
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
|
||||||
|
|
||||||
|
* gdb.python/py-prettyprint.c (struct container) <is_map_p>: New
|
||||||
|
field.
|
||||||
|
(make_container): Initialise new field.
|
||||||
|
* gdb.python/py-prettyprint.exp: Add new tests.
|
||||||
|
* gdb.python/py-prettyprint.py (class ContainerPrinter)
|
||||||
|
<display_hint>: New method.
|
||||||
|
|
||||||
2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
|
2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
|
||||||
|
|
||||||
* gdb.python/py-prettyprint.exp: Use gdb_breakpoint and
|
* gdb.python/py-prettyprint.exp: Use gdb_breakpoint and
|
||||||
|
|
|
@ -175,6 +175,7 @@ struct container
|
||||||
string name;
|
string name;
|
||||||
int len;
|
int len;
|
||||||
int *elements;
|
int *elements;
|
||||||
|
int is_map_p;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct container zzz_type;
|
typedef struct container zzz_type;
|
||||||
|
@ -195,6 +196,7 @@ make_container (const char *s)
|
||||||
result.name = make_string (s);
|
result.name = make_string (s);
|
||||||
result.len = 0;
|
result.len = 0;
|
||||||
result.elements = 0;
|
result.elements = 0;
|
||||||
|
result.is_map_p = 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,12 @@ proc run_lang_tests {exefile lang} {
|
||||||
gdb_test_no_output "set python print-stack full"
|
gdb_test_no_output "set python print-stack full"
|
||||||
gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
|
gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
|
||||||
|
|
||||||
gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
|
gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" \
|
||||||
|
"print c, pretty printing on, default display hint"
|
||||||
|
|
||||||
|
gdb_test_no_output "set variable c.is_map_p=1"
|
||||||
|
gdb_test "print c" " = container \"container\" with 2 elements = \{$nl \\\[23\\\] = 72$nl\}" \
|
||||||
|
"print c, pretty printing on, display hint is now map"
|
||||||
|
|
||||||
gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
|
gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
|
||||||
|
|
||||||
|
@ -117,6 +122,14 @@ proc run_lang_tests {exefile lang} {
|
||||||
gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \
|
gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \
|
||||||
"print nstype on one line"
|
"print nstype on one line"
|
||||||
|
|
||||||
|
# Now we have pretty printing turned off, try printing 'c' again.
|
||||||
|
gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[23\\\] = 72\}" \
|
||||||
|
"print c, pretty printing off, display hint is now map"
|
||||||
|
|
||||||
|
gdb_test_no_output "set variable c.is_map_p=0"
|
||||||
|
gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[0\\\] = 23, \\\[1\\\] = 72\}" \
|
||||||
|
"print c, pretty printing off, default display hint"
|
||||||
|
|
||||||
# Check that GDB doesn't lose typedefs when looking for a printer.
|
# Check that GDB doesn't lose typedefs when looking for a printer.
|
||||||
gdb_test "print an_int" " = -1"
|
gdb_test "print an_int" " = -1"
|
||||||
gdb_test "print (int) an_int" " = -1"
|
gdb_test "print (int) an_int" " = -1"
|
||||||
|
|
|
@ -56,6 +56,12 @@ class ContainerPrinter (object):
|
||||||
def children(self):
|
def children(self):
|
||||||
return _iterator(self.val['elements'], self.val['len'])
|
return _iterator(self.val['elements'], self.val['len'])
|
||||||
|
|
||||||
|
def display_hint (self):
|
||||||
|
if (self.val['is_map_p']):
|
||||||
|
return 'map'
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
# Treats a container as array.
|
# Treats a container as array.
|
||||||
class ArrayPrinter (object):
|
class ArrayPrinter (object):
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue