https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90945

            Bug ID: 90945
           Summary: Enhancement: Have pretty printer for std::vector<bool>
                    return bool values for elements
           Product: gcc
           Version: 9.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.weghorn at posteo dot de
  Target Milestone: ---

= Summary =

Currently, the iterator of the python pretty-printer for a std::vector<bool>
returns integers rather than bool values. Returning bool values (True/False)
could improve the display of values and in particular make sure that a
gdb.Value created from the value returned by the pretty-printer will have
'bool' type again.


= Current behaviour =

Small sample program:

      #include <vector>
      int main() {
          std::vector<bool> v;
          v.push_back(true);
          v.push_back(false);
          return 0; // set breakpoint here
      }

Printing the value of the vector at the given breakpoint in GDB 8.2.1 currently
results in:

    (gdb) p v
    $1 = std::vector<bool> of length 2, capacity 64 = {1, 0}


GDB's documentation on pretty-printing API [1] mentions:

> Function: pretty_printer.children (self)
> 
>     GDB will call this method on a pretty-printer to compute the children of
>     the pretty-printer’s value.
> 
>     This method must return an object conforming to the Python iterator
>     protocol. 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 Python object which is
>     convertible to a GDB value.
>     [...]

Currently, when constructing a GDB value from the value returned by the pretty
printer, the resulting gdb.Value has an integer type, e.g. 'long long' in my
case on Debian testing (amd64) with GDB 8.2.1.

IDEs may use this to display e.g. the type of local variables, resulting in a
wrong type being shown.


= Suggestion =

In my opinion, it would be desirable for the iterator to return a bool value
('True'/'False') instead, in which case a gdb.Value constructed from that
returned value also shows type 'bool' again.

The above example in a GDB session would then look like this:

    (gdb) p v
    $1 = std::vector<bool> of length 2, capacity 64 = {true, false}


I'll send a patch with the suggested change to the mailing list and would be
happy for any feedback.

[1] https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing-API.html

Reply via email to