[PATCH] Make StdVectorPrinter in printers.py compatible with ddd

Hans Erickson hans.p.erickson@gmail.com
Thu Mar 24 22:00:00 GMT 2011


Hello,

On Thu, Mar 24, 2011 at 2:34 PM, Paolo Carlini <pcarlini@gmail.com> wrote:
> Hi,
>
>>> If noone else objects I'll commit it to trunk in a day or two.
>>
>> If you allow this, where does it stop?  Any badly written gdb frontend
>> will complain about something.
>
> I understand Uli's point, but I have to add that, as far as I know, there aren't that many other lightweight options on Linux, besides DDD, thus, if knowledgeable people tell me the change really helps DDD, I'm in favor of the change. Well, it would help if somebody could explain which specific pattern of DDD usage is improved, lately I have been using DDD quite a bit for normal debugging of C++ without major problems.
>
> Thanks,
> Paolo

Thanks for the feedback.  I view the issue with ddd as more of a
symptom of the underlying problem rather than the main problem itself.
 I will try to demonstrate what I mean below.

Let's say we have the following program:

    #include <iostream>
    #include <vector>

    int main(int argc, char** argv)
    {
            std::vector<int> v;
            v.push_back(1);
            v.push_back(2);

            // break on line below
            std::cout << v[0] << " " << v[1] << std::endl;
    }


Now if the program is debugged through gdb and a breakpoint is set on
the line indicated in the program comments, the result of a "print v"
with STL pretty-printing enabled is as follows:
    $1 = std::vector of length 2, capacity 2 = {1, 2}

If the program is debugged through ddd (v.3.3.11 in my test), and
ddd's "Display Local Variables" feature is used, the gdb output is
parsed incorrectly.  An ASCII art rendition of this is as follows:
    +---------------------------+
    |Locals                     |
    +---------------------------+
    |v = std::vector of length 2|
    |    +-----------+          |
    |    |         1 |          |
    |2 = +  ---------+          |
    |    |         2 |          |
    |    +-----------+          |
    +---------------------------+

As you can see, ddd assumes that the pretty-printed variable is
actually two different variables because, presumably, it is splitting
fields based upon the location of the comma.  Given the other types of
output that gdb usually produces, this assumption doesn't seem
unreasonable, which is why I am submitting this patch to the libstdc++
maintainers instead of to the ddd maintainers.


With the patch, the comma is removed and the capacity is placed within
parentheses.  The gdb output appears as
    $1 = std::vector of length 2 (capacity 2) = {1, 2}

And ddd now parses the output correctly
    +-------------------------------------------------+
    |Locals                                           |
    +-------------------------------------------------+
    |v = std::vector of length 2 (capacity 2) = {1, 2}|
    +-------------------------------------------------+


It seems to me as though there are two questions involved:
1) Does this patch make the STL pretty-print code more consistent?
2) Is it reasonable for a gdb front-end to expect a comma to be used
   in the way that it is used in the pre-patched code?

As you maybe can guess, my answers to these would be yes to 1) and no
to 2).

Thanks,

- Hans Erickson
  hans.p.erickson@gmail.com



More information about the Libstdc++ mailing list