<div dir="ltr">Thanks for the information Greg. I have a quick followup. I'm using the version of lldb that comes with XCode 5.1.1<div><br></div><div>Launching it like this</div><div><br></div><div><div>Scotts-MacBook-Pro:~ scottknight$ /Applications/Xcode.app/Contents/Developer/usr/bin/lldb -p 13892</div>
<div>Attaching to process with:</div><div>    process attach -p 13892</div><div>Process 13892 stopped</div><div>Executable module set to "/Users/scottknight/.rbenv/versions/2.1.1/bin/ruby".</div><div>Architecture set to: x86_64-apple-macosx.</div>
</div><div><br></div><div>When I tried using GetValueForVariablePath I got 'No value' back. See the output below.</div><div><br></div><div><div>(lldb) v</div><div>lldb-310.2.37</div><div>(lldb) script</div><div>Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.</div>
<div>>>> print lldb.frame.EvaluateExpression('ruby_current_vm')</div><div>(rb_vm_t *) $1 = 0x00007f9a01003000</div><div>>>> print lldb.frame.GetValueForVariablePath('ruby_current_vm')</div>
<div>No value</div><div><br></div></div><div>Since ruby_current_vm is a global variable is there something different I would need to do to access it?</div><div><br></div><div>Thanks,</div><div>Scott Knight</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Apr 17, 2014 at 1:45 PM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Running expressions has all sorts of side effects like storing data in the inferior program and it also involves running the clang expression parser which can be expensive.<br>
<br>
You can, from a frame, get a SBValue for a variable without using the expression parser:<br>
<br>
    lldb::SBValue<br>
    SBFrame.GetValueForVariablePath (const char *var_path);<br>
<br>
So you can change your code to this:<br>
<br>
heaps_used = lldb.frame.GetValueForVariablePath('ruby_current_vm->objspace->heap_pages.used').GetValueAsUnsigned(0)<br>
<br>
for i in xrange(heaps_used):<br>
    page = lldb.frame.GetValueForVariablePath('*ruby_current_vm->objspace->heap_pages.sorted[%i]' % i)<br>
<br>
The GetValueForVariablePath() will find the variable and not create a temporary each time. It also doesn't use the expression parser at all so it won't call any code. The objects you access must be available in the hierarchy of the struct or class and the struct or class can't override the "->" operator. Other than that, the GetValueForVariablePath() knows how to access members ("ruby_current_vm->objspace->heap_pages.sorted"), dereference pointers using the array syntax ("my_ptr[12]"), deref a pointer ("*this->other_ptr"), and take the address of something ("&ruby_current_vm->objspace->heap_pages.sorted[12]").<br>

<br>
So give the GetValueForVariablePath a try. The SBValue returned is something that represents the live variable value, not a const result like you get back from expression. SBValue you get back is tied to the frame from which you got it, so it will continue to evaluate correctly and its value will change if you step between calling functions with it. If the frame it came from goes away (step out), then it won't return any valid values again as it will detect the frame is gone and stop answering any questions. So you should always fetch a fresh value from the frame each time you want to use it.<br>

<br>
Greg<br>
<br>
<br>
On Apr 17, 2014, at 7:57 AM, Scott Knight <<a href="mailto:knightsc@gmail.com">knightsc@gmail.com</a>> wrote:<br>
<br>
> I was recently using lldb to connect to a debug build of ruby to inspect the heap. In order to do this I was doing something like this<br>
><br>
> -----------<br>
> heaps_used = lldb.frame.EvaluateExpression('ruby_current_vm->objspace->heap_pages.used').GetValueAsUnsigned(0)<br>
><br>
> for i in xrange(heaps_used):<br>
>     page = lldb.frame.EvaluateExpression('*ruby_current_vm->objspace->heap_pages.sorted[%i]' % i)<br>
> -----------<br>
><br>
> What I noticed was that for each EvaluateExpression a temporary $0, $1, $2, etc.. variable is created. If I ended up calling my python code multiple times more and more variables seemed to pile up and every EvaluateExpression call seemed to take longer and longer.<br>

><br>
> I tried calling EvaluateExpression how I would call expr from the lldb command line setting my own variable, so something like<br>
><br>
> lldb.frame.EvaluateExpression('int $test = 5')<br>
><br>
> But that seemed to error out. So is there some other way in the API that is better for accessing global variables that won't slow down. Is this something actually wrong with the debugger? I can create an actual test case similar to the test suite in lldb if that would be helpful.<br>

><br>
> Thanks,<br>
> Scott Knight<br>
><br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div><br></div>