This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: gdb pretty-printers for libstdc++
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Phil Muldoon <pmuldoon at redhat dot com>
- Cc: Tom Tromey <tromey at redhat dot com>, libstdc++ at gcc dot gnu dot org
- Date: Sun, 8 Mar 2009 02:27:47 +0000
- Subject: Re: gdb pretty-printers for libstdc++
- References: <49AC5361.5090609@redhat.com> <4348dea50903071736x36251d26g325b02ffd80adbbf@mail.gmail.com>
Oops, this didn't go to the list the first time I sent it ...
2009/3/8 Jonathan Wakely:
> 2009/3/2 Phil Muldoon:
>>
>> I fixed that, and all the other issues mentioned in the email. ? I also did
>> some other small comment clean-ups. ?I've included a new copy of the file,
>> and also a patch. ?What do you think?
>
> I finally got a chance to build gdb and apply the patch - very nice
> work! ?Although it needs something like the attached to handle empty
> pointers. ?I also think the names should be correct for the std::tr1
> types.
>
> std::shared_ptr and std::tr1::shared_ptr are distinct types and both
> can exist in the same program. The attached patch means gdb can print
> everything in this testcase:
>
>
> #include <memory>
> #include <tr1/memory>
> #include <vector>
>
> int main()
> {
> ?{
> ? ?using namespace std;
> ? ?shared_ptr<int> p(new int(2));
> ? ?std::vector<weak_ptr<void> > v(1, p);
> ? ?p.reset();
> ? ?v[0].reset();
> ?}
> ?{
> ? ?using namespace std::tr1;
> ? ?shared_ptr<int> p(new int(2));
> ? ?std::vector<weak_ptr<void> > v(1, p);
> ? ?p.reset();
> ? ?v[0].reset();
> ?}
> ?return 0;
> }
>
> compile with g++ -std=c++0x
>
> The same is true of the unordered containers, but I haven't done the
> same for them in this patch.
>
> Jonathan
>
--- python/libstdcxx/v6/printers.py.orig 2009-03-08 01:14:24.000000000 +0000
+++ python/libstdcxx/v6/printers.py 2009-03-08 01:21:24.000000000 +0000
@@ -27,6 +27,8 @@
self.val = val
def to_string (self):
+ if self.val['_M_refcount']['_M_pi'] == 0:
+ return '%s (empty) %s' % (self.typename, self.val['_M_ptr'])
return '%s (count %d) %s' % (self.typename,
self.val['_M_refcount']['_M_pi']['_M_use_count'],
self.val['_M_ptr'])
@@ -616,10 +618,12 @@
pretty_printers_dict[re.compile('^std::unique_ptr<.*>$')] = UniquePointerPrinter
pretty_printers_dict[re.compile('^std::vector<.*>$')] = StdVectorPrinter
- # These are the C++0x printers. They also exist in the standard namespace.
+ # These are the TR1 and C++0x printers.
# For array - the default GDB pretty-printer seems reasonable.
- pretty_printers_dict[re.compile('^std::(tr1::)?shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::shared_ptr', val)
- pretty_printers_dict[re.compile('^std::(tr1::)?weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::weak_ptr', val)
+ pretty_printers_dict[re.compile('^std::shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::shared_ptr', val)
+ pretty_printers_dict[re.compile('^std::weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::weak_ptr', val)
+ pretty_printers_dict[re.compile('^std::tr1::shared_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::tr1::shared_ptr', val)
+ pretty_printers_dict[re.compile('^std::tr1::weak_ptr<.*>$')] = lambda val: StdPointerPrinter ('std::tr1::weak_ptr', val)
pretty_printers_dict[re.compile('^std::(tr1::)?unordered_map<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::tr1::unordered_map', val)
pretty_printers_dict[re.compile('^std::(tr1::)?unordered_set<.*>$')] = lambda val: Tr1UnorderedSetPrinter ('std::tr1::unordered_set', val)
pretty_printers_dict[re.compile('^std::(tr1::)?unordered_multimap<.*>$')] = lambda val: Tr1UnorderedMapPrinter ('std::tr1::unordered_multimap', val)