Home > Blockchain >  print contents of std::vector<std::string> in lldb
print contents of std::vector<std::string> in lldb

Time:01-28

I want to print all the strings in a vector. When I do

(lldb) p myVector
(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >) $30 = size=65 {
  [0] = Summary Unavailable
  [1] = Summary Unavailable
  [2] = Summary Unavailable
  [3] = Summary Unavailable
  [4] = Summary Unavailable
  [5] = Summary Unavailable
  [6] = Summary Unavailable
  [7] = Summary Unavailable
  [8] = Summary Unavailable
  [9] = Summary Unavailable
  [10] = Summary Unavailable
  [11] = Summary Unavailable
...

However, printing individual elements work e.g.,

p myVector[5].c_str()
(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >::value_type *) $31 = 0x0000600000210280 "-D__STDC_CONSTANT_MACROS"

I'd like to print all elements at once as there are quite a few.

CodePudding user response:

Add -fstandalone-debug to the compiler command line.

I have this set on my cmake for the debug build:

set(CMAKE_CXX_FLAGS_DEBUG_INIT "-ggdb3 -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fstandalone-debug ${SANITIZE_OPTS}" CACHE STRING "Initial debug flags")

CodePudding user response:

So i was able to solve this by using lldb's expr evaluation

(lldb) expr -- for (int x = 0; x < myVector.size(); x  ) printf("arg[%d] = %s\n", x, myVector[x].c_str())

# prints:
arg[0] = /Library/Developer/CommandLineTools/usr/bin/c  
arg[1] = --driver-mode=g  
arg[2] = -DGTEST_HAS_RTTI=0
arg[3] = -D__STDC_CONSTANT_MACROS
arg[4] = -D__STDC_FORMAT_MACROS
arg[5] = -D__STDC_LIMIT_MACROS
...
  • Related