Search code examples
pythonstlgdbpretty-printlldb

pretty printer for STL in lldb


gdb 7 has some useful python script for STL structure http://sourceware.org/gdb/wiki/STLSupport

Is there any similar tools for lldb? The information shown is pretty cryptic even with simple map or vector.

-> 100      h->moveReceivedSummaries(summaries);
   101      auto res = h->moveReceivedSummaries();
   102      EXPECT_TRUE(*summary == *res[1].get());
   103  }
(lldb) p summaries
(std::__1::map<int, std::__1::unique_ptr<ContextSummary, std::__1::default_delete<ContextSummary> >, std::__1::less<int>, std::__1::allocator<std::__1::pair<const int, std::__1::unique_ptr<ContextSummary, std::__1::default_delete<ContextSummary> > > > >) $0 = size=1 {
  (std::__1::__tree_node<std::__1::pair<int, std::__1::unique_ptr<ContextSummary, std::__1::default_delete<ContextSummary> > >, void *>::value_type) [0] = {
    (int) first = 1
    (std::__1::unique_ptr<ContextSummary, std::__1::default_delete<ContextSummary> >) second = {
      (std::__1::__compressed_pair<ContextSummary *, std::__1::default_delete<ContextSummary> >) __ptr_ = {
        (std::__1::__libcpp_compressed_pair_imp<ContextSummary *, std::__1::default_delete<ContextSummary> >) std::__1::__libcpp_compressed_pair_imp<ContextSummary *, std::__1::default_delete<ContextSummary> > = {
          (ContextSummary *) __first_ = 0x0000000100308390
        }
      }
    }
  }
}

Solution

  • I think the simplest solution could be just using Xcode when you are using Mac OS X.

    enter image description here

    In lldb, following(How can I get sensible variable displays when using libc++ in Xcode 4.3.1?), I tried to use command script import ../libcxx.py after downloading the python script from this site.

    However, the result is the same.

    (lldb) p v
    (std::__1::vector<std::__1::unique_ptr<A, std::__1::default_delete<A> >, std::__1::allocator<std::__1::unique_ptr<A, std::__1::default_delete<A> > > >) $4 = size=0 {
      [0] = {
        __ptr_ = {
          std::__1::__libcpp_compressed_pair_imp<A *, std::__1::default_delete<A> > = {
            __first_ = 0x0000000100200000
          }
        }
      }
    }