An example output is provided (see Pretty Printing).
A pretty-printer is represented by an object of type <gdb:pretty-printer>.
Pretty-printer objects are created with
The following pretty-printer-related procedures are provided by the
<gdb:pretty-printer>object named name.
lookup-function is a function of one parameter: the value to be printed. If the value is handled by this pretty-printer, then lookup-function returns an object of type <gdb:pretty-printer-worker> to perform the actual pretty-printing. Otherwise lookup-function returns
#tif object is a
<gdb:pretty-printer>object. Otherwise return
#tif pretty-printer is enabled. Otherwise return
Set the enabled flag of pretty-printer to flag. The value returned is unspecified.
Set the list of global pretty-printers to pretty-printers. The value returned is unspecified.
Return an object of type
This function takes three parameters:
- display-hint provides a hint to gdb or gdb front end via MI to change the formatting of the value being printed. The value must be a string or
#f(meaning there is no hint). Several values for display-hint are predefined by gdb:
- Indicate that the object being printed is “array-like”. The CLI uses this to respect parameters such as
set print elementsand
set print array.
- Indicate that the object being printed is “map-like”, and that the children of this value can be assumed to alternate between keys and values.
- Indicate that the object being printed is “string-like”. If the printer's
to-stringfunction returns a Guile string of some kind, then gdb will call its internal language-specific string-printing function to format the string. For the CLI this means adding quotation marks, possibly escaping some characters, respecting
set print elements, and the like.
- to-string is either a function of one parameter, the
When printing from the CLI, if the
to-stringmethod exists, then gdb will prepend its result to the values returned by
children. Exactly how this formatting is done is dependent on the display hint, and may change as more hints are added. Also, depending on the print settings (see Print Settings), the CLI may print just the result of
to-stringin a stack trace, omitting the result of
If this method returns a string, it is printed verbatim.
Otherwise, if this method returns an instance of
<gdb:value>, then gdb prints this value. This may result in a call to another pretty-printer.
If instead the method returns a Guile value which is convertible to a
<gdb:value>, then gdb performs the conversion and prints the resulting value. Again, this may result in a call to another pretty-printer. Guile scalars (integers, floats, and booleans) and strings are convertible to
<gdb:value>; other types are not.
Finally, if this method returns
#fthen no further operations are peformed in this method and nothing is printed.
If the result is not one of these types, an exception is raised.
to-string may also be
#fin which case it is left to children to print the value.
- children is either a function of one parameter, the
gdb will call this function on a pretty-printer to compute the children of the pretty-printer's value.
This function must return a <gdb:iterator> object. Each item returned by the iterator must be a tuple holding two elements. The first element is the “name” of the child; the second element is the child's value. The value can be any Guile object which is convertible to a gdb value.
If children is
#f, gdb will act as though the value has no children.
gdb provides a function which can be used to look up the
default pretty-printer for a