Formatter for std::shared_ptr<std::wstring>


I am looking to write data formatter for std::shared_ptrstd::wstring.

I found the following old article but this doesn’t seem to work.
I have ver 159 installed.

Any idea?

Thank you much,

Hi Alexander,

I've written the wstring printer and it works for me when printing the pointer and not the shared_ptr.

boost::shared_ptr<std::wstring> pString;

print pString <-- prints informations about the shared_ptr
print pString.px <-- prints the string pointet at



I've seen, that the script attached to the mail is not on the server, so I attached it again, although it would be better to have it in the lldb svn.

Yust copy the script to your hom directory and ad the folowing line to your .lldbinit

script sys.path[:0] = [os.path.expanduser('~')]
command alias pwd script print os.getcwd()
script import wstring
type summary add --python-function wstring.wstring_summary "std::wstring"
type summary add --python-function wstring.wstring_summary "std::basic_string<int, class std::char_traits<int>, class std::allocator<int> >"
type summary add --python-function wstring.wstring_summary "std::basic_string<unsigned short, class std::char_traits<unsigned

, class std::allocator<unsigned short> >"

type summary add --python-function wstring.wstring_summary "std::basic_string<wchar_t, class std::char_traits<wchar_t>, class std::allocator<wchar_t> >"

Cheers, Nino (881 Bytes)

I am using Mac OS X Version 10.7.4
The following is the lldb output:

(lldb) frame variable x

(std::__1::wstring) x = {

_r = {

std::__1::__libcpp_compressed_pair_imp<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::__rep, std::__1::allocator<wchar_t> > = {

_first = {

= {

__l = {

_cap = 17

_size = 12

_data = 0x00000001001009c0


__s = {

= {

_size = ‘\x11’

_ = \x11\0\0\0


_data = {

[0] = \0\0\0\0

[1] = \f\0\0\0

[2] = \0\0\0\0

[3] = \xc0\t\x10\0

[4] = \x01\0\0\0



__r = {

__words = {

[0] = 17

[1] = 12

[2] = 4296018368










Hi Alexander,

your string implementation looks very complicated.

Also the type of the string looks strange. I would expect that "std::wstring" is a typedef
for "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>"

You are using "std::__1::wstring" and the real type also contains this "__1" stuff
"std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t>>"
and it is additionally wrapped by a std::pair or sth similar.

I've never seen this before. Maybe somebody else in the mailing list did?!

So the data formater works only for std::wstring with a "_M_dataplus" and a "_M_p" member


Alexander is using libcpp, part of the LLVM project, whereas you are using libstdcpp (a GNU project).
They both implement the C++ Standard Library but with different internals!
Luckily they are easy to differentiate because libcpp classes lived in a std::__1 namespace

Enrico Granata
:email: egranata@.com
✆ (408) 972-7683


I got it working.
I follow example from the following to navigate and Nino’s script to read the char.

I can post the script if needed.


feel free to share your script if you desire.
I can work on integrating it into mainline LLDB.


Enrico Granata
:email: egranata@.com
✆ (408) 972-7683

But this doesn’t work with global variables and I haven’t had chance to look at it.

formatter.bin (3.46 KB)

If you are using GetPointeeData() it is a known bug in LLDB, which was resolved in r 161384

If that does not fix the issue, please do let us know with a reproduction case :slight_smile:

Enrico Granata
:email: egranata@.com
✆ (408) 972-7683