2016-02-19 5 views
5

Kiedy debuguję aplikację C++ 11, chcę zobaczyć obiekty, na które wskazują unikalne_ptr i shared_ptr. Ale używając ładnych drukarek libstdC++, drukowany jest tylko ciąg z adresem i podobnymi materiałami, ale nie mogę go rozwinąć, aby zobaczyć jego zawartość. Próbowałem już następujące obejścia, ale nie działa dla mnie:Wyświetlanie inteligentnych wskaźników w eclipse cdt przy użyciu ładnych drukarek gdb

https://sourceware.org/ml/gdb/2013-04/msg00042.html

Czy ktoś może mi pomóc z tym. Właściwie to myślę, że to może być całkiem podstawowy problem, więc zastanawiam się, czy nie ma takiej możliwości. Ale przeszukując internet, nie mogłem znaleźć podpowiedzi ...

Odpowiedz

2

Podążając za twoim linkiem, zrobiłem dokładnie to, co Michael opisał i działa dobrze. Prawdopodobnie popełniłeś błąd podczas stosowania zmian. Libstdcxx/v6/printers.py powinien teraz mieć w liniach 103 - 174:

class SharedPointerPrinter: 
    "Print a shared_ptr or weak_ptr" 

    class _iterator: 
     def __init__(self, sharedPointer): 
      self.sharedPointer = sharedPointer 
      self.managedValue = sharedPointer.val['_M_ptr'] 
      self.count = 0 

     def __iter__(self): 
      return self 

     def next(self): 
      if self.managedValue == 0: 
       raise StopIteration 
      self.count = self.count + 1 
      if (self.count == 1): 
       return ('Use count', self.sharedPointer.val['_M_refcount']['_M_pi']['_M_use_count']) 
      elif (self.count == 2): 
       return ('Weak count', self.sharedPointer.val['_M_refcount']['_M_pi']['_M_weak_count'] - 1) 
      elif (self.count == 3): 
       return ('Managed value', self.managedValue) 
      else: 
       raise StopIteration 

    def __init__ (self, typename, val): 
     self.typename = typename 
     self.val = val 

    def children (self): 
     return self._iterator(self) 

    def to_string (self): 
     state = 'empty' 
     refcounts = self.val['_M_refcount']['_M_pi'] 
     if refcounts != 0: 
      usecount = refcounts['_M_use_count'] 
      weakcount = refcounts['_M_weak_count'] 
      if usecount == 0: 
       state = 'expired, weakcount %d' % weakcount 
      else: 
       state = 'usecount %d, weakcount %d' % (usecount, weakcount - 1) 
     return '%s (%s) to %s' % (self.typename, state, self.val['_M_ptr']) 

class UniquePointerPrinter: 
    "Print a unique_ptr" 

    class _iterator: 
     def __init__(self, uniquePointer): 
      self.uniquePointer = uniquePointer 
      self.managedValue = uniquePointer.val['_M_t']['_M_head_impl'] 
      self.count = 0 

     def __iter__(self): 
      return self 

     def next(self): 
      if self.managedValue == 0 or self.count == 1: 
       raise StopIteration 
      self.count = self.count + 1 
      return ('Managed value', self.managedValue) 

    def __init__ (self, typename, val): 
     self.val = val 

    def children (self): 
     return self._iterator(self) 

    def to_string (self): 
     v = self.val['_M_t']['_M_head_impl'] 
     return ('std::unique_ptr<%s> containing %s' % (str(v.type.target()), 
                 str(v))) 

poważaniem

+0

Dzięki, że pracuje dla mnie. Ale dostaję ostrzeżenia debuggera: ostrzeżenie: nie znaleziono symbolu RTTI dla klasy 'std :: _ Sp_counted_ptr_inplace >, std :: allocator >>, (__gnu_cxx :: _ Lock_policy) 2> 'Nie jestem pewien czy to może być problem – Johannes91

+0

Może wyłączyłeś RTTI dla gcc używając flagi -fno-rtti? Nie otrzymuję ostrzeżeń o debuggerze, używając MinGW-w64 64bit gcc w wersji 6.2.0. Moje opcje g ++ to -O0 -g3 -Wall -c -fmessage-length = 0 -std = C++ 11 -D_FILE_OFFSET_BITS = 64-D__WXMSW__ – xamid

+0

Jeśli jednak twój debugger jest błędny, nie powinien to być problem, jak wyjaśniono [tutaj] (http://stackoverflow.com/questions/12986261/warning-message-rtti-symbol-not-found-when-using-boostiostreams/12991374#12991374). – xamid

Powiązane problemy