49

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

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
an0
  • 17,191
  • 12
  • 86
  • 136
  • I don't see any evidence that it does. Its web site is http://lldb.llvm.org/ and they have mailing lists, perhaps you could ask the maintainers directly. – Kevin Grant Jul 29 '12 at 20:57

4 Answers4

61

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
an0
  • 17,191
  • 12
  • 86
  • 136
  • 2
    Does anyone know if there's a function to list any variables defined in this fashion during a session? That would be super handy. Something like `expr list`... – Jonathan Crooke Nov 13 '14 at 11:28
31

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. :/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
escrafford
  • 2,373
  • 16
  • 19
9

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
john.k.doe
  • 7,533
  • 2
  • 37
  • 64
2

For swift version

e let $data = Data()
po $data

output:

▿ 0 bytes
  - count : 0
  ▿ pointer : 0x000000016d36d9d0
    - pointerValue : 6127278544
  - bytes : 0 elements
andrew54068
  • 1,326
  • 14
  • 29