1

I am trying to debug the very simple helloworld.cpp example in VS Code with the C++ extension on macOS X. However, string variables in the debugger don't print correctly where the length of the string is less than 22 bytes,. Instead of showing, for example, "Hello", the debugger shows Summary Unavailable.

VS Code debugger local variables:

(To be clear, for any for whom the image is not visible, the debugger front end shows "Summary Unavailable" as the value of local variables such as word instead of the expected value of the variable, if the strength length is shorter than 22bytes, apparently the limit for short string optimisation on OS X per this answer.)

My tasks.json is set up to build using C++17, and the launch.json is the standard generated by VS Code.

The code being debugged is based on the standard VS Code C++ example used in the VS Code introduction:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and also from the C++ extension!"};
    
    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}

I've tried running this with both the CLT and Xcode.app installed, but I get the same result.

New contributor
davidh_73 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • Just to make sure - did you go past the line that declares msg in debugger? I.e., is it already initialised? Commented Nov 25 at 9:06
  • Yes, the breakpoint is inside the for loop. Commented Nov 25 at 22:53

1 Answer 1

2

This isn’t a VS Code bug it’s LLDB’s behavior on macOS when debugging std::string built with libc++ without the correct data formatters loaded.

In your launch.json, add:

"customizedLLDBInitCommands": [
    "command script import /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python/lldb/macosx/formatters/libcxx/stdlib.py"
]
Sign up to request clarification or add additional context in comments.

1 Comment

That path doesn't exist in my Xcode (I think you are trying to refer to /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python/lldb/formatters/cpp/libcxx.py) The option "customizedLLDBInitCommands" is not allowed in a launch.json for the Microsoft C/C++ Extension "type": "cppdbg" and has no effect. Using the "setupCommands" option to import the python script leads to even weirder output (msg is reported as size = 0 and word shows a long hexadecimal number followed by an empty string, when the word is a short string.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.