public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [tools-team] 11874 Vector pretty-printer chokes on bit-vectors
       [not found]     ` <m38w4aw4z2.fsf@fleche.redhat.com>
@ 2010-08-16 15:03       ` Chris Moller
  2010-08-16 18:17         ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Moller @ 2010-08-16 15:03 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

On 08/13/10 17:57, Tom Tromey wrote:
> Chris>  +                return ('[%d]' % count, obit)
>
> It seems like it might be nicer to only print the set bits, something
> like bitset.
>    

If it's a sparse vector, yeah, you're right.  But it's probably more 
trouble than it's worth to figure that out and do different things 
depending, and, on average, it probably dumps more chares to print the 
indices of the '1's than to print all of the bits.

>
> Chris>  +            return ('%s<bool>  of length %d, capacity %d'
> Chris>  +                    % (self.typename, int (length), int (capacity)))
>
> Doesn't self.typename already include the<bool>?
>    

No.  typename comes from a string in the dictionary entry for 
std::vector<.*> and is the same regardless of the template argument.


[-- Attachment #2: pr11874.patch --]
[-- Type: text/x-patch, Size: 3967 bytes --]

Index: python/libstdcxx/v6/printers.py
===================================================================
--- python/libstdcxx/v6/printers.py	(revision 163221)
+++ python/libstdcxx/v6/printers.py	(working copy)
@@ -153,37 +153,71 @@
     "Print a std::vector"
 
     class _iterator:
-        def __init__ (self, start, finish):
-            self.item = start
-            self.finish = finish
+        def __init__ (self, start, finish, bitvec):
+            self.bitvec = bitvec
+            if bitvec:
+                self.item   = start['_M_p']
+                self.so     = start['_M_offset']
+                self.finish = finish['_M_p']
+                self.fo     = finish['_M_offset']
+                itype = self.item.dereference().type
+                self.isize = 8 * itype.sizeof
+            else:
+                self.item = start
+                self.finish = finish
             self.count = 0
 
         def __iter__(self):
             return self
 
         def next(self):
-            if self.item == self.finish:
-                raise StopIteration
             count = self.count
             self.count = self.count + 1
-            elt = self.item.dereference()
-            self.item = self.item + 1
-            return ('[%d]' % count, elt)
+            if self.bitvec:
+                if self.item == self.finish and self.so >= self.fo:
+                    raise StopIteration
+                elt = self.item.dereference()
+                obit = 1 if elt & (1 << self.so) else 0
+                self.so = self.so + 1
+                if self.so >= self.isize:
+                    self.item = self.item + 1
+                    self.so = 0
+                return ('[%d]' % count, obit)
+            else:
+                if self.item == self.finish:
+                    raise StopIteration
+                elt = self.item.dereference()
+                self.item = self.item + 1
+                return ('[%d]' % count, elt)
 
     def __init__(self, typename, val):
         self.typename = typename
         self.val = val
+        self.is_bool = val.type.template_argument(0).code  == gdb.TYPE_CODE_BOOL
 
     def children(self):
         return self._iterator(self.val['_M_impl']['_M_start'],
-                              self.val['_M_impl']['_M_finish'])
+                              self.val['_M_impl']['_M_finish'],
+                              self.is_bool)
 
     def to_string(self):
         start = self.val['_M_impl']['_M_start']
         finish = self.val['_M_impl']['_M_finish']
         end = self.val['_M_impl']['_M_end_of_storage']
-        return ('%s of length %d, capacity %d'
-                % (self.typename, int (finish - start), int (end - start)))
+        if self.is_bool:
+            start = self.val['_M_impl']['_M_start']['_M_p']
+            so    = self.val['_M_impl']['_M_start']['_M_offset']
+            finish = self.val['_M_impl']['_M_finish']['_M_p']
+            fo     = self.val['_M_impl']['_M_finish']['_M_offset']
+            itype = start.dereference().type
+            bl = 8 * itype.sizeof
+            length   = (bl - so) + bl * ((finish - start) - 1) + fo
+            capacity = bl * (end - start)
+            return ('%s<bool> of length %d, capacity %d'
+                    % (self.typename, int (length), int (capacity)))
+        else:
+            return ('%s of length %d, capacity %d'
+                    % (self.typename, int (finish - start), int (end - start)))
 
     def display_hint(self):
         return 'array'
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 163221)
+++ ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2010-08-13  Chris Moller  <cmoller@redhat.com>
+
+	* python/libstdcxx/v6/printers.py (StdVectorPrinter): Added stuff
+	to handle pretty-printing of std::vector<bool>.
+
 2010-08-12  Kostya Serebryany <kcc@google.com>
 	    Paolo Carlini  <paolo.carlini@oracle.com>
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [tools-team] 11874 Vector pretty-printer chokes on bit-vectors
  2010-08-16 15:03       ` [tools-team] 11874 Vector pretty-printer chokes on bit-vectors Chris Moller
@ 2010-08-16 18:17         ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2010-08-16 18:17 UTC (permalink / raw)
  To: Chris Moller; +Cc: gdb-patches

>>>>> "Chris" == Chris Moller <cmoller@redhat.com> writes:

Chris> If it's a sparse vector, yeah, you're right.  But it's probably more
Chris> trouble than it's worth to figure that out and do different things
Chris> depending, and, on average, it probably dumps more chares to print the
Chris> indices of the '1's than to print all of the bits.

Sounds reasonable.

For future reference, this is the wrong list for libstdc++ patches.

I will forward this and apply it to gcc.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-16 18:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4C653282.4050204@redhat.com>
     [not found] ` <m38w4a1qje.fsf@fleche.redhat.com>
     [not found]   ` <4C659A95.1060207@redhat.com>
     [not found]     ` <m38w4aw4z2.fsf@fleche.redhat.com>
2010-08-16 15:03       ` [tools-team] 11874 Vector pretty-printer chokes on bit-vectors Chris Moller
2010-08-16 18:17         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).