• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: printing std::string in lldb
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printing std::string in lldb


  • Subject: Re: printing std::string in lldb
  • From: dmarkman <email@hidden>
  • Date: Fri, 24 Jun 2011 22:48:15 +0000 (GMT)

Hi Greg,
thank you very much for your answer

I see what's you saying, thanks

lldb is much faster than gdb, that's very good

however _expression_ evaluation isn't that good, especially when I want to evaluate return value of the function
and return value is a class

or I'm getting peculiar result

po std::string str =  "a"

 lldb says 
error: no member named 'string' in namespace 'std'
error: 1 errors parsing _expression_

but if I issue command

po std::string str=s;  

where s is std::string variable in the scope (po s returns right answer)

lldb enters into the mode that I can't even quit from Xcode 4 (but it doesn't hang. I can type in the console,
but I can not exit from the lldb, whatever I do) Only force quit helps
the same behavior I can see from command line

I created bugreport

thanks again





Dmitry Markman, PhD

On Jun 24, 2011, at 04:55 PM, Greg Clayton <email@hidden> wrote:

Hello Dmitry,

I saw you post about not being able to view std::string objects in LLDB. LDB has a known issue where we have trouble with calling functions on templatized types. We will resolve this issue in the future, but right now you can actually view the contents of the string without calling a function:

(lldb) frame variable s
(std::string) s = {
_M_dataplus = {
_M_p = 0x0000000100100098 "hello"
}
}



If you want a more concise representation, try using the "--flat" option:

(lldb) frame variable --flat s
s._M_dataplus._M_p = 0x0000000100100098 "hello"




Of course if you get tired of typing "frame variable" you can make an alias in your "~/.lldbinit" file:

command alias v frame variable

Then you can use the alias in our console:

(lldb) v --flat s
s._M_dataplus._M_p = 0x0000000100100098 "hello"

Calling s.c_str() is actually going to call a function in the process you are debugging just so you can get the value of "s._M_dataplus._M_p". Also, calling "s[0]" is also going to call a function in the process you are debugging just to return you the character.

You can achieve an equivalent option in LLDB by using the "frame variable" command as the command can treat pointers as arrays:

(lldb) frame variable s._M_dataplus._M_p[0]

The nice thing about the "--flat" option is that it makes it easy to copy the complete expresssion path for a variable ("s._M_dataplus._M_p") without having to manually type it all out.

Since the "frame variable" command can treat pointers as arrays, you can use this with vectors:

std::vector<int> v;
vpush_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);

(lldb) frame variable --flat v
v._M_impl._M_start = 0x00000001001000a0
v._M_impl._M_finish = 0x00000001001000b0
v._M_impl._M_end_of_storage = 0x00000001001000b0

Now we can use _M_start as a pointer:

(lldb) frame variable v._M_impl._M_start[0]
(int) v._M_impl._M_start[0] = 1
(lldb) frame variable v._M_impl._M_start[1]
(int) v._M_impl._M_start[1] = 2

Or look at the last entry using a negative index on _M_finish:

(lldb) frame variable v._M_impl._M_finish[-1]
(int) v._M_impl._M_finish[-1] = 4



Greg Clayton


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Alternate Development Environments?
  • Next by Date: WebView works in other apps, but not another?
  • Previous by thread: Re: printing std::string in lldb
  • Next by thread: TargetConditionals.h + llvm + iphone or Mac conditionals
  • Index(es):
    • Date
    • Thread