View C ++ shared_ptr content in debugger

Debugging C ++ code in xcode, is there a way to view the contents of std :: shared_ptr?

If I look at the watch window, all I see is __ptr = (element_type *) 0xa66945c

and writing "po myPointer" in the direct window also prints only the memory address.

I also tried looking at the memory __ptr_ and looking at the memory * __ ptr_, but that only allows me to see

raw memory and actual readable text

Can anyone suggest a way to view the object for which I have a pointer?

+5
source share
3 answers

The fr command in LLDB has an argument --ptr-depth , which can help in these situations. For example, try entering this in the immediate area:

fr var myPointer --ptr-depth=1

+1
source

I think the best way would be to make hardcode in the std :: cout statement to display the contents of the object (if any) ...

0
source

Try right-clicking on __ptr_ and choosing "View Value As" β†’ "Custom Type"

In the field that appears, replaces element_type with the actual type pointed to by std :: shared_ptr.

It seems ridiculous to me that something like this does not work by default.

0
source

Source: https://habr.com/ru/post/1201012/


All Articles