an0
an0

Reputation: 17530

Does LLDB have convenience variables ($var)?

Does LLDB have convenience variables? If so, how do I use them? If not, is there anything similar that I can use?

Reference: http://software.intel.com/sites/products/documentation/hpc/atom/application/debugger/commands143.html

Upvotes: 52

Views: 17274

Answers (4)

andrew54068
andrew54068

Reputation: 1406

For swift version

e let $data = Data()
po $data

output:

▿ 0 bytes
  - count : 0
  ▿ pointer : 0x000000016d36d9d0
    - pointerValue : 6127278544
  - bytes : 0 elements

Upvotes: 4

escrafford
escrafford

Reputation: 2393

I struggled with this today. Here's what it looks like to deal with Objective-C variables in LLDB:

expr UIApplication *$app = (UIApplication *)[UIApplication sharedApplication]
expr UIWindow *$keyWindow = (UIWindow *)[$app keyWindow]

etc. I've found LLDB works best if you don't nest any calls, and you explicitly give a return type on every call.

Still I am getting a segmentation fault when I try to make initWithFrame: work on a UIView later on though. :/

Upvotes: 32

an0
an0

Reputation: 17530

I finally figured it out myself. Run help expr in LLDB and you will see:

User defined variables: You can define your own variables for convenience or to be used in subsequent expressions. You define them the same way you would define variables in C. If the first character of your user defined variable is a $, then the variable's value will be available in future expressions, otherwise it will just be available in the current expression.

So expr int $foo = 5 is what I want.

Upvotes: 68

john.k.doe
john.k.doe

Reputation: 7563

Just use the form:

(lldb) expr var

From their tutorial:

(lldb) expr self
$0 = (SKTGraphicView *) 0x0000000100135430
(lldb) expr self = 0x00
$1 = (SKTGraphicView *) 0x0000000000000000

You can also call functions:

(lldb) expr (int) printf ("I have a pointer 0x%llx.\n", self)
$2 = (int) 22
I have a pointer 0x0.
(lldb) expr self = $0
$4 = (SKTGraphicView *) 0x0000000100135430

Upvotes: 9

Related Questions