6

So i had this error with a large code that I'm working on for college, i need to visualize how strings get reorder while debugging in order to know my program is working, but debugger just shows (stringVariableName) = Summary unavailable. I created this small piece of code to test with standalone strings, vector and integers to see if it made a difference, but it only shows integers.

#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<string> testString = {"test1", "test2", "test3"};
    vector<int> testInt = {1,2,3};
    string test = "test1";

}

Debugger

I know i can go into __r_std::1 ... to see the value of the string but I'm working with over 10 thousand strings that i cant verify one by one like that.

Some details, I'm using MacOS 13.4.1, clang 14.0.3, IDE: Clion 2022.2.5 and i tried with both c++ 20 and c++ 17.

I was expecting being able to visualize the string straight from the debugger.

1 Answer 1

0

A Mac std::string has a 22-byte short string optimization limit. Here is an example of printing a short string...

(lldb) v inputName
(std::string) inputName = Summary Unavailable
(lldb) p inputName
(std::string) inputName = Summary Unavailable
(lldb) p inputName.c_str()
(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >::value_type *) $0 = 0x00007ff7bfef75c9 "n4"

Use 'p' and not 'v'. 'v' prints the frame variable but it does not have a full expression parser. 'p' is an alias for the evaluate command, which can evaluate the c_str() call and other handy things.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.