1edb874b2SJonas DevlieghereTutorial 2edb874b2SJonas Devlieghere======== 3edb874b2SJonas Devlieghere 4e19f7221SDavid SpickettThis document describes how to use LLDB if you are already familiar with 5e19f7221SDavid SpickettGDB's command set. We will start with some details on LLDB command structure and 6eb6097a7SDavid Spickettsyntax. 7edb874b2SJonas Devlieghere 8edb874b2SJonas DevlieghereCommand Structure 9edb874b2SJonas Devlieghere----------------- 10edb874b2SJonas Devlieghere 11e19f7221SDavid SpickettUnlike GDB's quite free-form commands, LLDB's are more structured. All commands 12eb6097a7SDavid Spickettare of the form: 13edb874b2SJonas Devlieghere 14edb874b2SJonas Devlieghere:: 15edb874b2SJonas Devlieghere 16edb874b2SJonas Devlieghere <noun> <verb> [-options [option-value]] [argument [argument...]] 17edb874b2SJonas Devlieghere 18eb6097a7SDavid SpickettThe command line parsing is done before command execution, so it is the same for 19eb6097a7SDavid Spickettall commands. The command syntax for basic commands is very simple. 20d9808603SJim Ingham 21eb6097a7SDavid Spickett* Arguments, options and option values are all white-space separated. 22eb6097a7SDavid Spickett* Either single ``'`` or double-quotes ``"`` (in pairs) are used to protect white-spaces 23eb6097a7SDavid Spickett in an argument. 24eb6097a7SDavid Spickett* Escape backslashes and double quotes within arguments should be escaped 25eb6097a7SDavid Spickett with a backslash ``\``. 26eb6097a7SDavid Spickett 27e19f7221SDavid SpickettThis makes LLDB's commands more regular, but it also means you may have to quote 28e19f7221SDavid Spickettsome arguments in LLDB that you would not in GDB. 29eb6097a7SDavid Spickett 30e19f7221SDavid SpickettThere is one other special quote character in LLDB - the backtick `````. 31e19f7221SDavid SpickettIf you put backticks around an argument or option value, LLDB will run the text 32d9808603SJim Inghamof the value through the expression parser, and the result of the expression 33eb6097a7SDavid Spickettwill be passed to the command. So for instance, if ``len`` is a local 34eb6097a7SDavid Spickett``int`` variable with the value ``5``, then the command: 35d9808603SJim Ingham 36d9808603SJim Ingham:: 37d9808603SJim Ingham 38d9808603SJim Ingham (lldb) memory read -c `len` 0x12345 39d9808603SJim Ingham 40eb6097a7SDavid SpickettWill receive the value ``5`` for the count option, rather than the string ``len``. 41edb874b2SJonas Devlieghere 42edb874b2SJonas DevlieghereOptions can be placed anywhere on the command line, but if the arguments begin 43e19f7221SDavid Spickettwith a ``-`` then you have to tell LLDB that you are done with options for the 44eb6097a7SDavid Spickettcurrent command by adding an option termination: ``--``. 45eb6097a7SDavid Spickett 46eb6097a7SDavid SpickettSo for instance, if you want to launch a process and give the ``process launch`` 47eb6097a7SDavid Spickettcommand the ``--stop-at-entry`` option, yet you want the process you are about 48eb6097a7SDavid Spickettto launch to be launched with the arguments ``-program_arg value``, you would type: 49edb874b2SJonas Devlieghere 50edb874b2SJonas Devlieghere:: 51edb874b2SJonas Devlieghere 52edb874b2SJonas Devlieghere (lldb) process launch --stop-at-entry -- -program_arg value 53edb874b2SJonas Devlieghere 54edb874b2SJonas DevlieghereWe also tried to reduce the number of special purpose argument parsers, which 55eb6097a7SDavid Spickettsometimes forces the user to be explicit about their intentions. The first 56e19f7221SDavid Spickettinstance you willl see of this is the breakpoint command. In GDB, to set a 57eb6097a7SDavid Spickettbreakpoint, you might enter: 58edb874b2SJonas Devlieghere 59edb874b2SJonas Devlieghere:: 60edb874b2SJonas Devlieghere 61edb874b2SJonas Devlieghere (gdb) break foo.c:12 62edb874b2SJonas Devlieghere 63eb6097a7SDavid SpickettTo break at line ``12`` of ``foo.c``, and: 64edb874b2SJonas Devlieghere 65edb874b2SJonas Devlieghere:: 66edb874b2SJonas Devlieghere 67edb874b2SJonas Devlieghere (gdb) break foo 68edb874b2SJonas Devlieghere 69eb6097a7SDavid SpickettTo break at the function ``foo``. As time went on, the parser that tells ``foo.c:12`` 70eb6097a7SDavid Spickettfrom ``foo`` from ``foo.c::foo`` (which means the function ``foo`` in the file ``foo.c``) 71eb6097a7SDavid Spickettgot more and more complex. Especially in C++ there are times where there is 72eb6097a7SDavid Spickettreally no way to specify the function you want to break on. 73edb874b2SJonas Devlieghere 74e19f7221SDavid SpickettThe LLDB commands are more verbose but also more precise and allow for 75eb6097a7SDavid Spickettintelligent auto completion. 76eb6097a7SDavid Spickett 77e19f7221SDavid SpickettTo set the same file and line breakpoint in LLDB you can enter either of: 78edb874b2SJonas Devlieghere 79edb874b2SJonas Devlieghere:: 80edb874b2SJonas Devlieghere 81edb874b2SJonas Devlieghere (lldb) breakpoint set --file foo.c --line 12 82edb874b2SJonas Devlieghere (lldb) breakpoint set -f foo.c -l 12 83edb874b2SJonas Devlieghere 84e19f7221SDavid SpickettTo set a breakpoint on a function named ``foo`` in LLDB you can enter either of: 85edb874b2SJonas Devlieghere 86edb874b2SJonas Devlieghere:: 87edb874b2SJonas Devlieghere 88edb874b2SJonas Devlieghere (lldb) breakpoint set --name foo 89edb874b2SJonas Devlieghere (lldb) breakpoint set -n foo 90edb874b2SJonas Devlieghere 91eb6097a7SDavid SpickettYou can use the ``--name`` option multiple times to make a breakpoint on a set of 92edb874b2SJonas Devliegherefunctions as well. This is convenient since it allows you to set common 93edb874b2SJonas Devlieghereconditions or commands without having to specify them multiple times: 94edb874b2SJonas Devlieghere 95edb874b2SJonas Devlieghere:: 96edb874b2SJonas Devlieghere 97edb874b2SJonas Devlieghere (lldb) breakpoint set --name foo --name bar 98edb874b2SJonas Devlieghere 99e19f7221SDavid SpickettSetting breakpoints by name is even more specialized in LLDB as you can specify 100edb874b2SJonas Devliegherethat you want to set a breakpoint at a function by method name. To set a 101eb6097a7SDavid Spickettbreakpoint on all C++ methods named ``foo`` you can enter either of: 102edb874b2SJonas Devlieghere 103edb874b2SJonas Devlieghere:: 104edb874b2SJonas Devlieghere 105edb874b2SJonas Devlieghere (lldb) breakpoint set --method foo 106edb874b2SJonas Devlieghere (lldb) breakpoint set -M foo 107edb874b2SJonas Devlieghere 108edb874b2SJonas Devlieghere 109eb6097a7SDavid SpickettTo set a breakpoint Objective-C selectors named ``alignLeftEdges:`` you can enter either of: 110edb874b2SJonas Devlieghere 111edb874b2SJonas Devlieghere:: 112edb874b2SJonas Devlieghere 113edb874b2SJonas Devlieghere (lldb) breakpoint set --selector alignLeftEdges: 114edb874b2SJonas Devlieghere (lldb) breakpoint set -S alignLeftEdges: 115edb874b2SJonas Devlieghere 116edb874b2SJonas DevlieghereYou can limit any breakpoints to a specific executable image by using the 117eb6097a7SDavid Spickett``--shlib <path>`` (``-s <path>`` for short): 118edb874b2SJonas Devlieghere 119edb874b2SJonas Devlieghere:: 120edb874b2SJonas Devlieghere 121edb874b2SJonas Devlieghere (lldb) breakpoint set --shlib foo.dylib --name foo 122edb874b2SJonas Devlieghere (lldb) breakpoint set -s foo.dylib -n foo 123edb874b2SJonas Devlieghere 124eb6097a7SDavid SpickettThe ``--shlib`` option can also be repeated to specify several shared libraries. 125edb874b2SJonas Devlieghere 126edb874b2SJonas DevlieghereSuggestions on more interesting primitives of this sort are also very welcome. 127edb874b2SJonas Devlieghere 128e19f7221SDavid SpickettJust like GDB, the LLDB command interpreter does a shortest unique string match 129edb874b2SJonas Devlieghereon command names, so the following two commands will both execute the same 130edb874b2SJonas Devliegherecommand: 131edb874b2SJonas Devlieghere 132edb874b2SJonas Devlieghere:: 133edb874b2SJonas Devlieghere 134edb874b2SJonas Devlieghere (lldb) breakpoint set -n "-[SKTGraphicView alignLeftEdges:]" 135edb874b2SJonas Devlieghere (lldb) br s -n "-[SKTGraphicView alignLeftEdges:]" 136edb874b2SJonas Devlieghere 137e19f7221SDavid SpickettLLDB also supports command completion for source file names, symbol names, file 138eb6097a7SDavid Spickettnames, etc. Completion is initiated by hitting TAB. Individual options in a 139eb6097a7SDavid Spickettcommand can have different completers, so for instance, the ``--file <path>`` 140eb6097a7SDavid Spickettoption in ``breakpoint`` completes to source files, the ``--shlib <path>`` option 141eb6097a7SDavid Spickettto currently loaded shared libraries, etc. You can even do things like if you 142e19f7221SDavid Spickettspecify ``--shlib <path>``, and are completing on ``--file <path>``, LLDB will only 143eb6097a7SDavid Spickettlist source files in the shared library specified by ``--shlib <path>``. 144edb874b2SJonas Devlieghere 145eb6097a7SDavid SpickettThe individual commands are pretty extensively documented. You can use the ``help`` 146edb874b2SJonas Devliegherecommand to get an overview of which commands are available or to obtain details 147eb6097a7SDavid Spickettabout specific commands. There is also an ``apropos`` command that will search the 148edb874b2SJonas Devliegherehelp text for all commands for a particular word and dump a summary help string 149edb874b2SJonas Devliegherefor each matching command. 150edb874b2SJonas Devlieghere 151edb874b2SJonas DevlieghereFinally, there is a mechanism to construct aliases for commonly used commands. 152b68545acSSushma UnnibhaviFor instance, if you get annoyed typing: 153edb874b2SJonas Devlieghere 154edb874b2SJonas Devlieghere:: 155edb874b2SJonas Devlieghere 156edb874b2SJonas Devlieghere (lldb) breakpoint set --file foo.c --line 12 157edb874b2SJonas Devlieghere 158eb6097a7SDavid SpickettYou can do: 159edb874b2SJonas Devlieghere 160edb874b2SJonas Devlieghere:: 161edb874b2SJonas Devlieghere 162edb874b2SJonas Devlieghere (lldb) command alias bfl breakpoint set -f %1 -l %2 163edb874b2SJonas Devlieghere (lldb) bfl foo.c 12 164edb874b2SJonas Devlieghere 165e19f7221SDavid SpickettLLDB has a few aliases for commonly used commands (e.g. ``step``, ``next`` and 166eb6097a7SDavid Spickett``continue``) but it does not try to be exhaustive because in our experience it 167edb874b2SJonas Devlieghereis more convenient to make the basic commands unique down to a letter or two, 168edb874b2SJonas Devlieghereand then learn these sequences than to fill the namespace with lots of aliases, 169edb874b2SJonas Devlieghereand then have to type them all the way out. 170edb874b2SJonas Devlieghere 1718334d2bfSMed Ismail BennaniIf the alias abbreviation or the full alias command collides with another 1728334d2bfSMed Ismail Bennaniexisting command, the command resolver will prefer to use the alias over any 1738334d2bfSMed Ismail Bennaniother command as far as there is only one alias command match. 1748334d2bfSMed Ismail Bennani 175e19f7221SDavid SpickettHowever, users are free to customize LLDB's command set however they like, and 176e19f7221SDavid Spickettsince LLDB reads the file ``~/.lldbinit`` at startup, you can store all your 177edb874b2SJonas Devliegherealiases there and they will be generally available to you. Your aliases are 178eb6097a7SDavid Spickettalso documented in the ``help`` command so you can remind yourself of what you have 179edb874b2SJonas Devlieghereset up. 180edb874b2SJonas Devlieghere 181e19f7221SDavid SpickettOne alias of note that LLDB does include by popular demand is a weak emulator of 182e19f7221SDavid SpickettGDB's ``break`` command. It does not try to do everything that GDB's break command 183eb6097a7SDavid Spickettdoes (for instance, it does not handle ``foo.c::bar``). But it mostly works, and 184eb6097a7SDavid Spickettmakes the transition easier. Also, by popular demand, it is aliased to ``b``. If you 185e19f7221SDavid Spickettactually want to learn the LLDB command set natively, that means it will get in 186eb6097a7SDavid Spickettthe way of the rest of the breakpoint commands. Fortunately, if you do not like 187eb6097a7SDavid Spickettone of our aliases, you can easily get rid of it by running, for example: 188edb874b2SJonas Devlieghere 189edb874b2SJonas Devlieghere:: 190edb874b2SJonas Devlieghere 191edb874b2SJonas Devlieghere (lldb) command unalias b 192edb874b2SJonas Devlieghere 193eb6097a7SDavid SpickettYou can also do: 194edb874b2SJonas Devlieghere 195edb874b2SJonas Devlieghere:: 196edb874b2SJonas Devlieghere 197edb874b2SJonas Devlieghere (lldb) command alias b breakpoint 198edb874b2SJonas Devlieghere 199e19f7221SDavid SpickettSo you can run the native LLDB breakpoint command with just ``b``. 200edb874b2SJonas Devlieghere 201e19f7221SDavid SpickettThe LLDB command parser also supports "raw" commands, where, after command 202edb874b2SJonas Devlieghereoptions are stripped off, the rest of the command string is passed 203edb874b2SJonas Devlieghereuninterpreted to the command. This is convenient for commands whose arguments 204edb874b2SJonas Devliegheremight be some complex expression that would be painful to backslash protect. 205eb6097a7SDavid SpickettFor instance, the ``expression`` command is a "raw" command for obvious reasons. 206eb6097a7SDavid SpickettThe ``help`` output for a command will tell you if it is "raw" or not, so you 207edb874b2SJonas Devlieghereknow what to expect. The one thing you have to watch out for is that since raw 208edb874b2SJonas Devliegherecommands still can have options, if your command string has dashes in it, 209eb6097a7SDavid Spickettyou will have to indicate these are not option markers by putting ``--`` after the 210edb874b2SJonas Devliegherecommand name, but before your command string. 211edb874b2SJonas Devlieghere 212e19f7221SDavid SpickettLLDB also has a built-in Python interpreter, which is accessible by the 213*646aa817S苏灵素@夏日限定``script`` command. All the functionality of the debugger is available as classes 214e19f7221SDavid Spickettin the Python interpreter, so the more complex commands that in GDB you would 215eb6097a7SDavid Spickettintroduce with the ``define`` command can be done by writing Python functions 216e19f7221SDavid Spickettusing the LLDB Python library, then loading the scripts into your running 217eb6097a7SDavid Spickettsession and accessing them with the ``script`` command. 218edb874b2SJonas Devlieghere 219e19f7221SDavid SpickettLoading a Program Into LLDB 220edb874b2SJonas Devlieghere--------------------------- 221edb874b2SJonas Devlieghere 222e19f7221SDavid SpickettFirst you need to set the program to debug. As with GDB, you can start LLDB and 223eb6097a7SDavid Spickettspecify the file you wish to debug on the command line: 224edb874b2SJonas Devlieghere 225edb874b2SJonas Devlieghere:: 226edb874b2SJonas Devlieghere 227edb874b2SJonas Devlieghere $ lldb /Projects/Sketch/build/Debug/Sketch.app 228edb874b2SJonas Devlieghere Current executable set to '/Projects/Sketch/build/Debug/Sketch.app' (x86_64). 229edb874b2SJonas Devlieghere 230eb6097a7SDavid SpickettOr you can specify it after the fact with the ``file`` command: 231edb874b2SJonas Devlieghere 232edb874b2SJonas Devlieghere:: 233edb874b2SJonas Devlieghere 234edb874b2SJonas Devlieghere $ lldb 235edb874b2SJonas Devlieghere (lldb) file /Projects/Sketch/build/Debug/Sketch.app 236edb874b2SJonas Devlieghere Current executable set to '/Projects/Sketch/build/Debug/Sketch.app' (x86_64). 237edb874b2SJonas Devlieghere 238edb874b2SJonas DevlieghereSetting Breakpoints 239edb874b2SJonas Devlieghere------------------- 240edb874b2SJonas Devlieghere 241eb6097a7SDavid SpickettWe have discussed how to set breakpoints above. You can use ``help breakpoint set`` 242eb6097a7SDavid Spickettto see all the options for breakpoint setting. For instance, you could do: 243edb874b2SJonas Devlieghere 244edb874b2SJonas Devlieghere:: 245edb874b2SJonas Devlieghere 246edb874b2SJonas Devlieghere (lldb) breakpoint set --selector alignLeftEdges: 247edb874b2SJonas Devlieghere Breakpoint created: 1: name = 'alignLeftEdges:', locations = 1, resolved = 1 248edb874b2SJonas Devlieghere 249eb6097a7SDavid SpickettYou can find out about the breakpoints you have set with: 250edb874b2SJonas Devlieghere 251edb874b2SJonas Devlieghere:: 252edb874b2SJonas Devlieghere 253edb874b2SJonas Devlieghere (lldb) breakpoint list 254edb874b2SJonas Devlieghere Current breakpoints: 255edb874b2SJonas Devlieghere 1: name = 'alignLeftEdges:', locations = 1, resolved = 1 256edb874b2SJonas Devlieghere 1.1: where = Sketch`-[SKTGraphicView alignLeftEdges:] + 33 at /Projects/Sketch/SKTGraphicView.m:1405, address = 0x0000000100010d5b, resolved, hit count = 0 257edb874b2SJonas Devlieghere 258edb874b2SJonas Devlieghere 259edb874b2SJonas DevlieghereNote that setting a breakpoint creates a logical breakpoint, which could 260edb874b2SJonas Devlieghereresolve to one or more locations. For instance, break by selector would set a 261edb874b2SJonas Devliegherebreakpoint on all the methods that implement that selector in the classes in 262edb874b2SJonas Devlieghereyour program. Similarly, a file and line breakpoint might result in multiple 263edb874b2SJonas Devliegherelocations if that file and line were inlined in different places in your code. 264edb874b2SJonas Devlieghere 2654fd3347dSKazu HirataThe logical breakpoint has an integer id, and its locations have an id within 266eb6097a7SDavid Spicketttheir parent breakpoint (the two are joined by a ``.``, e.g. ``1.1`` in the example 267b68545acSSushma Unnibhaviabove). 268edb874b2SJonas Devlieghere 269eb6097a7SDavid SpickettAlso logical breakpoints remain live so that if another shared library were 270eb6097a7SDavid Spickettto be loaded that had another implementation of the ``alignLeftEdges:`` selector, 271eb6097a7SDavid Spickettthe new location would be added to breakpoint ``1`` (e.g. a ``1.2`` breakpoint would 272edb874b2SJonas Devliegherebe set on the newly loaded selector). 273edb874b2SJonas Devlieghere 274edb874b2SJonas DevlieghereThe other piece of information in the breakpoint listing is whether the 275edb874b2SJonas Devliegherebreakpoint location was resolved or not. A location gets resolved when the file 276edb874b2SJonas Devlieghereaddress it corresponds to gets loaded into the program you are debugging. For 277edb874b2SJonas Devlieghereinstance if you set a breakpoint in a shared library that then gets unloaded, 278edb874b2SJonas Devliegherethat breakpoint location will remain, but it will no longer be resolved. 279edb874b2SJonas Devlieghere 280e19f7221SDavid SpickettOne other thing to note for GDB users is that LLDB acts like GDB with: 281edb874b2SJonas Devlieghere 282edb874b2SJonas Devlieghere:: 283edb874b2SJonas Devlieghere 284edb874b2SJonas Devlieghere (gdb) set breakpoint pending on 285edb874b2SJonas Devlieghere 286e19f7221SDavid SpickettWhich means that LLDB will always make a breakpoint from your specification, even if it 287eb6097a7SDavid Spickettcould not find any locations that match the specification. You can tell whether 288edb874b2SJonas Devliegherethe expression was resolved or not by checking the locations field in 289e19f7221SDavid Spickett``breakpoint list``, and LLDB reports the breakpoint as ``pending`` when you set it so 290eb6097a7SDavid Spickettyou can tell you have made a typo more easily, if that was indeed the reason no 291edb874b2SJonas Devliegherelocations were found: 292edb874b2SJonas Devlieghere 293edb874b2SJonas Devlieghere:: 294edb874b2SJonas Devlieghere 295edb874b2SJonas Devlieghere (lldb) breakpoint set --file foo.c --line 12 296edb874b2SJonas Devlieghere Breakpoint created: 2: file ='foo.c', line = 12, locations = 0 (pending) 297edb874b2SJonas Devlieghere WARNING: Unable to resolve breakpoint to any actual locations. 298edb874b2SJonas Devlieghere 299edb874b2SJonas DevlieghereYou can delete, disable, set conditions and ignore counts either on all the 300edb874b2SJonas Devliegherelocations generated by your logical breakpoint, or on any one of the particular 301eb6097a7SDavid Spickettlocations your specification resolved to. For instance, if you wanted to add a 302eb6097a7SDavid Spickettcommand to print a backtrace when you hit this breakpoint you could do: 303edb874b2SJonas Devlieghere 304edb874b2SJonas Devlieghere:: 305edb874b2SJonas Devlieghere 306edb874b2SJonas Devlieghere (lldb) breakpoint command add 1.1 307edb874b2SJonas Devlieghere Enter your debugger command(s). Type 'DONE' to end. 308edb874b2SJonas Devlieghere > bt 309edb874b2SJonas Devlieghere > DONE 310edb874b2SJonas Devlieghere 311e19f7221SDavid SpickettBy default, the breakpoint command add command takes LLDB command line 312eb6097a7SDavid Spickettcommands. You can also specify this explicitly by passing the ``--command`` 313eb6097a7SDavid Spickettoption. Use ``--script`` if you want to implement your breakpoint command using 314edb874b2SJonas Devliegherethe Python script instead. 315edb874b2SJonas Devlieghere 316e19f7221SDavid SpickettThis is a convenient point to bring up another feature of the LLDB command 317eb6097a7SDavid Spickett``help``. Do: 318edb874b2SJonas Devlieghere 319edb874b2SJonas Devlieghere:: 320edb874b2SJonas Devlieghere 321edb874b2SJonas Devlieghere (lldb) help break command add 322edb874b2SJonas Devlieghere Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit. 323edb874b2SJonas Devlieghere 324edb874b2SJonas Devlieghere Syntax: breakpoint command add <cmd-options> <breakpt-id> 325edb874b2SJonas Devlieghere etc... 326edb874b2SJonas Devlieghere 327eb6097a7SDavid SpickettWhen you see arguments to commands specified in the ``Syntax`` section in angle brackets 328eb6097a7SDavid Spickettlike ``<breakpt-id>``, that indicates that that is some common argument type that 329edb874b2SJonas Devlieghereyou can get further help on from the command system. So in this case you could 330edb874b2SJonas Devliegheredo: 331edb874b2SJonas Devlieghere 332edb874b2SJonas Devlieghere:: 333edb874b2SJonas Devlieghere 334*646aa817S苏灵素@夏日限定 (lldb) help <breakpt-id> 335*646aa817S苏灵素@夏日限定 <breakpt-id> -- Breakpoint ID's consist major and minor numbers; the major etc... 336edb874b2SJonas Devlieghere 337edb874b2SJonas DevlieghereBreakpoint Names 338edb874b2SJonas Devlieghere---------------- 339edb874b2SJonas Devlieghere 340eb6097a7SDavid SpickettBreakpoints carry two orthogonal sets of information: one specifies where to set 341eb6097a7SDavid Spickettthe breakpoint, and the other how to react when the breakpoint is hit. The latter 342eb6097a7SDavid Spickettset of information (e.g. commands, conditions, hit-count, auto-continue...) we 343eb6097a7SDavid Spickettcall breakpoint options. 344edb874b2SJonas Devlieghere 345eb6097a7SDavid SpickettIt is fairly common to want to apply one set of options to a number of breakpoints. 346eb6097a7SDavid SpickettFor instance, you might want to check that ``self == nil`` and if it is, print a 347eb6097a7SDavid Spickettbacktrace and continue, on a number of methods. One convenient way to do that would 348eb6097a7SDavid Spickettbe to make all the breakpoints, then configure the options with: 349edb874b2SJonas Devlieghere 350edb874b2SJonas Devlieghere:: 351edb874b2SJonas Devlieghere 352edb874b2SJonas Devlieghere (lldb) breakpoint modify -c "self == nil" -C bt --auto-continue 1 2 3 353edb874b2SJonas Devlieghere 354eb6097a7SDavid SpickettThat is not too bad, but you have to repeat this for every new breakpoint you make, 355eb6097a7SDavid Spickettand if you wanted to change the options, you have to remember all the ones you are 356eb6097a7SDavid Spickettusing this way. 357edb874b2SJonas Devlieghere 358eb6097a7SDavid SpickettBreakpoint names provide a convenient solution to this problem. The simple solution 359eb6097a7SDavid Spickettwould be to use the name to gather the breakpoints you want to affect this way into 360eb6097a7SDavid Spicketta group. So when you make the breakpoint you would do: 361edb874b2SJonas Devlieghere 362edb874b2SJonas Devlieghere:: 363edb874b2SJonas Devlieghere 364edb874b2SJonas Devlieghere (lldb) breakpoint set -N SelfNil 365edb874b2SJonas Devlieghere 366eb6097a7SDavid SpickettThen when you have made all your breakpoints, you can set up or modify the options 367eb6097a7SDavid Spickettusing the name to collect all the relevant breakpoints. 368edb874b2SJonas Devlieghere 369edb874b2SJonas Devlieghere:: 370edb874b2SJonas Devlieghere 371edb874b2SJonas Devlieghere (lldb) breakpoint modify -c "self == nil" -C bt --auto-continue SelfNil 372edb874b2SJonas Devlieghere 373edb874b2SJonas DevlieghereThat is better, but suffers from the problem that when new breakpoints get 374eb6097a7SDavid Spickettadded, they do not pick up these modifications, and the options only exist in 375eb6097a7SDavid Spickettthe context of actual breakpoints, so they are hard to store and reuse. 376edb874b2SJonas Devlieghere 3775dd95687SKazu HirataAn even better solution is to make a fully configured breakpoint name: 378edb874b2SJonas Devlieghere 379edb874b2SJonas Devlieghere:: 380edb874b2SJonas Devlieghere 381edb874b2SJonas Devlieghere (lldb) breakpoint name configure -c "self == nil" -C bt --auto-continue SelfNil 382edb874b2SJonas Devlieghere 383edb874b2SJonas DevlieghereThen you can apply the name to your breakpoints, and they will all pick up 384edb874b2SJonas Devliegherethese options. The connection from name to breakpoints remains live, so when 385edb874b2SJonas Devlieghereyou change the options configured on the name, all the breakpoints pick up 386edb874b2SJonas Devliegherethose changes. This makes it easy to use configured names to experiment with 387edb874b2SJonas Devlieghereyour options. 388edb874b2SJonas Devlieghere 389eb6097a7SDavid SpickettYou can make breakpoint names in your ``.lldbinit`` file, so you can use them to 390edb874b2SJonas Devliegherecan behaviors that you have found useful and reapply them in future sessions. 391edb874b2SJonas Devlieghere 392edb874b2SJonas DevlieghereYou can also make a breakpoint name from the options set on a breakpoint: 393edb874b2SJonas Devlieghere 394edb874b2SJonas Devlieghere:: 395edb874b2SJonas Devlieghere 396edb874b2SJonas Devlieghere (lldb) breakpoint name configure -B 1 SelfNil 397edb874b2SJonas Devlieghere 398edb874b2SJonas Devliegherewhich makes it easy to copy behavior from one breakpoint to a set of others. 399edb874b2SJonas Devlieghere 400edb874b2SJonas DevlieghereSetting Watchpoints 401edb874b2SJonas Devlieghere------------------- 402edb874b2SJonas Devlieghere 403edb874b2SJonas DevlieghereIn addition to breakpoints, you can use help watchpoint to see all the commands 404eb6097a7SDavid Spickettfor watchpoint manipulations. For instance, you might do the following to watch 405eb6097a7SDavid Spicketta variable called ``global`` for write operation, but only stop if the condition 406eb6097a7SDavid Spickett``(global==5)`` is true: 407edb874b2SJonas Devlieghere 408edb874b2SJonas Devlieghere:: 409edb874b2SJonas Devlieghere 410edb874b2SJonas Devlieghere (lldb) watch set var global 411edb874b2SJonas Devlieghere Watchpoint created: Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w 412edb874b2SJonas Devlieghere declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12' 413edb874b2SJonas Devlieghere (lldb) watch modify -c '(global==5)' 414edb874b2SJonas Devlieghere (lldb) watch list 415edb874b2SJonas Devlieghere Current watchpoints: 416edb874b2SJonas Devlieghere Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w 417edb874b2SJonas Devlieghere declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12' 418edb874b2SJonas Devlieghere condition = '(global==5)' 419edb874b2SJonas Devlieghere (lldb) c 420edb874b2SJonas Devlieghere Process 15562 resuming 421edb874b2SJonas Devlieghere (lldb) about to write to 'global'... 422edb874b2SJonas Devlieghere Process 15562 stopped and was programmatically restarted. 423edb874b2SJonas Devlieghere Process 15562 stopped and was programmatically restarted. 424edb874b2SJonas Devlieghere Process 15562 stopped and was programmatically restarted. 425edb874b2SJonas Devlieghere Process 15562 stopped and was programmatically restarted. 426edb874b2SJonas Devlieghere Process 15562 stopped 427edb874b2SJonas Devlieghere * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1 428edb874b2SJonas Devlieghere frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16 429edb874b2SJonas Devlieghere 13 430edb874b2SJonas Devlieghere 14 static void modify(int32_t &var) { 431edb874b2SJonas Devlieghere 15 ++var; 432edb874b2SJonas Devlieghere -> 16 } 433edb874b2SJonas Devlieghere 17 434edb874b2SJonas Devlieghere 18 int main(int argc, char** argv) { 435edb874b2SJonas Devlieghere 19 int local = 0; 436edb874b2SJonas Devlieghere (lldb) bt 437edb874b2SJonas Devlieghere * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1 438edb874b2SJonas Devlieghere frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16 439edb874b2SJonas Devlieghere frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25 440edb874b2SJonas Devlieghere frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1 441edb874b2SJonas Devlieghere (lldb) frame var global 442edb874b2SJonas Devlieghere (int32_t) global = 5 443edb874b2SJonas Devlieghere (lldb) watch list -v 444edb874b2SJonas Devlieghere Current watchpoints: 445edb874b2SJonas Devlieghere Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w 446edb874b2SJonas Devlieghere declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12' 447edb874b2SJonas Devlieghere condition = '(global==5)' 448a3fe9221SJason Molenda hit_count = 5 ignore_count = 0 449edb874b2SJonas Devlieghere (lldb) 450edb874b2SJonas Devlieghere 451edb874b2SJonas DevlieghereStarting or Attaching to Your Program 452edb874b2SJonas Devlieghere------------------------------------- 453edb874b2SJonas Devlieghere 454e19f7221SDavid SpickettTo launch a program in LLDB you will use the ``process launch`` command or one of 455eb6097a7SDavid Spickettits built in aliases: 456edb874b2SJonas Devlieghere 457edb874b2SJonas Devlieghere:: 458edb874b2SJonas Devlieghere 459edb874b2SJonas Devlieghere (lldb) process launch 460edb874b2SJonas Devlieghere (lldb) run 461edb874b2SJonas Devlieghere (lldb) r 462edb874b2SJonas Devlieghere 463edb874b2SJonas DevlieghereYou can also attach to a process by process ID or process name. When attaching 464e19f7221SDavid Spickettto a process by name, LLDB also supports the ``--waitfor`` option which waits for 465edb874b2SJonas Devliegherethe next process that has that name to show up, and attaches to it 466edb874b2SJonas Devlieghere 467edb874b2SJonas Devlieghere:: 468edb874b2SJonas Devlieghere 469edb874b2SJonas Devlieghere (lldb) process attach --pid 123 470edb874b2SJonas Devlieghere (lldb) process attach --name Sketch 471edb874b2SJonas Devlieghere (lldb) process attach --name Sketch --waitfor 472edb874b2SJonas Devlieghere 473edb874b2SJonas DevlieghereAfter you launch or attach to a process, your process might stop somewhere: 474edb874b2SJonas Devlieghere 475edb874b2SJonas Devlieghere:: 476edb874b2SJonas Devlieghere 477edb874b2SJonas Devlieghere (lldb) process attach -p 12345 478edb874b2SJonas Devlieghere Process 46915 Attaching 479edb874b2SJonas Devlieghere Process 46915 Stopped 480edb874b2SJonas Devlieghere 1 of 3 threads stopped with reasons: 481edb874b2SJonas Devlieghere * thread #1: tid = 0x2c03, 0x00007fff85cac76a, where = libSystem.B.dylib`__getdirentries64 + 10, stop reason = signal = SIGSTOP, queue = com.apple.main-thread 482edb874b2SJonas Devlieghere 483eb6097a7SDavid SpickettNote the line that says ``1 of 3 threads stopped with reasons:`` and the lines 484edb874b2SJonas Devliegherethat follow it. In a multi-threaded environment it is very common for more than 485edb874b2SJonas Devlieghereone thread to hit your breakpoint(s) before the kernel actually returns control 486edb874b2SJonas Devlieghereto the debugger. In that case, you will see all the threads that stopped for 487edb874b2SJonas Devliegheresome interesting reason listed in the stop message. 488edb874b2SJonas Devlieghere 489edb874b2SJonas DevlieghereControlling Your Program 490edb874b2SJonas Devlieghere------------------------ 491edb874b2SJonas Devlieghere 492eb6097a7SDavid SpickettAfter launching, you can continue until you hit your breakpoint. The primitive commands 493eb6097a7SDavid Spickettfor process control all exist under the "thread" command: 494edb874b2SJonas Devlieghere 495edb874b2SJonas Devlieghere:: 496edb874b2SJonas Devlieghere 497edb874b2SJonas Devlieghere (lldb) thread continue 498edb874b2SJonas Devlieghere Resuming thread 0x2c03 in process 46915 499edb874b2SJonas Devlieghere Resuming process 46915 500edb874b2SJonas Devlieghere (lldb) 501edb874b2SJonas Devlieghere 502eb6097a7SDavid SpickettAt present you can only operate on one thread at a time, but the design will 503eb6097a7SDavid Spickettultimately support saying "step over the function in Thread 1, and step into the 504e19f7221SDavid Spickettfunction in Thread 2, and continue Thread 3" etc. When LLDB eventually supports 505eb6097a7SDavid Spickettkeeping some threads running while others are stopped this will be particularly 506eb6097a7SDavid Spickettimportant. For convenience, however, all the stepping commands have easy aliases. 507eb6097a7SDavid SpickettSo ``thread continue`` is just ``c``, etc. 508edb874b2SJonas Devlieghere 509e19f7221SDavid SpickettThe other program stepping commands are pretty much the same as in GDB. You have got: 510edb874b2SJonas Devlieghere 511edb874b2SJonas Devlieghere:: 512edb874b2SJonas Devlieghere 513e19f7221SDavid Spickett (lldb) thread step-in // The same as GDB's "step" or "s" 514e19f7221SDavid Spickett (lldb) thread step-over // The same as GDB's "next" or "n" 515e19f7221SDavid Spickett (lldb) thread step-out // The same as GDB's "finish" or "f" 516edb874b2SJonas Devlieghere 517e19f7221SDavid SpickettBy default, LLDB does defined aliases to all common GDB process control commands 518e19f7221SDavid Spickett(``s``, ``step``, ``n``, ``next``, ``finish``). If LLDB is missing any, please add 519eb6097a7SDavid Spickettthem to your ``~/.lldbinit`` file using the ``command alias`` command. 520edb874b2SJonas Devlieghere 521e19f7221SDavid SpickettLLDB also supports the step by instruction versions: 522edb874b2SJonas Devlieghere 523edb874b2SJonas Devlieghere:: 524edb874b2SJonas Devlieghere 525edb874b2SJonas Devlieghere 526e19f7221SDavid Spickett (lldb) thread step-inst // The same as GDB's "stepi" / "si" 527e19f7221SDavid Spickett (lldb) thread step-over-inst // The same as GDB's "nexti" / "ni" 528edb874b2SJonas Devlieghere 529e19f7221SDavid SpickettFinally, LLDB has a run until line or frame exit stepping mode: 530edb874b2SJonas Devlieghere 531edb874b2SJonas Devlieghere:: 532edb874b2SJonas Devlieghere 533edb874b2SJonas Devlieghere (lldb) thread until 100 534edb874b2SJonas Devlieghere 535eb6097a7SDavid SpickettThis command will run the thread in the current frame until it reaches line 100 536edb874b2SJonas Devliegherein this frame or stops if it leaves the current frame. This is a pretty close 537e19f7221SDavid Spickettequivalent to GDB's ``until`` command. 538edb874b2SJonas Devlieghere 539a4197e47SjiminghamOne other useful thing to note about the lldb stepping commands is that they 540a4197e47Sjiminghamare implemented as a stack of interruptible operations. Until the operation - 541a4197e47Sjiminghame.g. step to the next line - is completed, it will remain on the 542a4197e47Sjiminghamstack. If the step over is interrupted and control returned to you, 543a4197e47Sjiminghamany new stepping commands you issue won't replace the step-over, but instead 544a4197e47Sjiminghamtheir operations will be pushed onto the stack after the original step over. 545a4197e47SjiminghamThen each of them will be retired as they are completed, finally returning to the 546a4197e47Sjiminghamoriginal step over operation. 547a4197e47Sjimingham 548a4197e47SjiminghamSuppose, for instance, you ``step-over`` a source line with a function call. 549a4197e47SjiminghamIf there is a breakpoint in that function, hitting the breakpoint will interrupt 550a4197e47Sjiminghamthe step over. At that point, you will likely want to examine the state at 551a4197e47Sjiminghamthe breakpoint, maybe stepping around in that frame, or stepping into other 552a4197e47Sjiminghamfunctions, running some expressions, etc. 553a4197e47Sjimingham 554a4197e47SjiminghamBecause the original step-over has remained on the stack, when you've finished 555a4197e47Sjiminghamyour examinations, a simple ``continue`` will resume the original ``step-over`` 556a4197e47Sjiminghamoperation, and you will arrive at the end of your starting source line in the 557a4197e47Sjiminghamoriginal frame. 558a4197e47Sjimingham 559a4197e47SjiminghamThis saves you from having to keep track of your original intention, and manually 560a4197e47Sjiminghamissuing the requisite number of ``step-out`` commands to get back to the frame 561a4197e47Sjiminghamyou were stepping over. The stack maintains that information for you. 562a4197e47Sjimingham 563a4197e47SjiminghamHand-called functions using the ``expr`` command are also implemented by 564a4197e47Sjiminghamoperations on this same stack. So if you are calling some code with the ``expr`` command, 565a4197e47Sjiminghamand hit a breakpoint during the evaluation of that code, you can examine 566a4197e47Sjiminghamthe state where you stopped, and when you're satisfied, issue a 567a4197e47Sjimingham``continue`` to finish the expression evaluation operation and print the function 568a4197e47Sjiminghamresult. 569a4197e47Sjimingham 570a4197e47SjiminghamYou can examine the state of the operations stack using the ``thread plan list`` 571a4197e47Sjiminghamcommand, and if, for instance, you decide you don't actually want that outermost 572a4197e47Sjiminghamnext to continue running, you can remove it with the ``thread plan discard`` 573a4197e47Sjiminghamcommand. If you are interested in following this process in more detail, the 574a4197e47Sjimingham``lldb step`` logging channel is useful source of information. 575a4197e47Sjimingham 576e19f7221SDavid SpickettA process, by default, will share the LLDB terminal with the inferior process. 577e19f7221SDavid SpickettWhen in this mode, much like when debugging with GDB, when the process is 578eb6097a7SDavid Spickettrunning anything you type will go to the ``STDIN`` of the inferior process. To 579eb6097a7SDavid Spickettinterrupt your inferior program, type ``CTRL+C``. 580edb874b2SJonas Devlieghere 581eb6097a7SDavid SpickettIf you attach to a process, or launch a process with the ``--no-stdin`` option, 582258cd02cSMed Ismail Bennanithe command interpreter is always available to enter commands. It might be a 583e19f7221SDavid Spickettlittle disconcerting to GDB users to always have an ``(lldb)`` prompt. This allows 584eb6097a7SDavid Spickettyou to set a breakpoint, or use any other command without having to explicitly 585eb6097a7SDavid Spickettinterrupt the program you are debugging: 586edb874b2SJonas Devlieghere 587edb874b2SJonas Devlieghere:: 588edb874b2SJonas Devlieghere 589edb874b2SJonas Devlieghere (lldb) process continue 590edb874b2SJonas Devlieghere (lldb) breakpoint set --name stop_here 591edb874b2SJonas Devlieghere 592edb874b2SJonas DevlieghereThere are many commands that won't work while running, and the command 593eb6097a7SDavid Spickettinterpreter will let you know when this is the case. Please file an issue if 594eb6097a7SDavid Spickettit does not. This way of operation will set us up for a future debugging 595edb874b2SJonas Devliegheremode called thread centric debugging. This mode will allow us to run all 596edb874b2SJonas Devliegherethreads and only stop the threads that are at breakpoints or have exceptions or 597edb874b2SJonas Devliegheresignals. 598edb874b2SJonas Devlieghere 599edb874b2SJonas DevlieghereThe commands that currently work while running include interrupting the process 600eb6097a7SDavid Spickettto halt execution (``process interrupt``), getting the process status (``process status``), 601eb6097a7SDavid Spickettbreakpoint setting and clearing (``breakpoint [set|clear|enable|disable|list] ...``), 602eb6097a7SDavid Spickettand memory reading and writing (``memory [read|write] ...``). 603edb874b2SJonas Devlieghere 604edb874b2SJonas DevlieghereThe question of disabling stdio when running brings up a good opportunity to 605eb6097a7SDavid Spickettshow how to set debugger properties. If you always want to run in 606eb6097a7SDavid Spickettthe ``--no-stdin`` mode, you can set this as a generic process property using the 607e19f7221SDavid SpickettLLDB ``settings`` command, which is equivalent to GDB's ``set`` command. 608eb6097a7SDavid SpickettIn this case you would say: 609edb874b2SJonas Devlieghere 610edb874b2SJonas Devlieghere:: 611edb874b2SJonas Devlieghere 612edb874b2SJonas Devlieghere (lldb) settings set target.process.disable-stdio true 613edb874b2SJonas Devlieghere 614e19f7221SDavid SpickettOver time, GDB's ``set`` command became a wilderness of disordered options, so 615e19f7221SDavid Spickettthat there were useful options that even experienced GDB users did not know 616e19f7221SDavid Spickettabout because they were too hard to find. LLDB instead organizes the settings 617edb874b2SJonas Devliegherehierarchically using the structure of the basic entities in the debugger. For 618edb874b2SJonas Devliegherethe most part anywhere you can specify a setting on a generic entity (threads, 619eb6097a7SDavid Spickettfor example) you can also apply the option to a particular instance. You can 620eb6097a7SDavid Spickettview the available settings with the command ``settings list`` and there is help 621eb6097a7SDavid Spicketton the settings command explaining how it works more generally. 622edb874b2SJonas Devlieghere 623edb874b2SJonas DevlieghereExamining Thread State 624edb874b2SJonas Devlieghere---------------------- 625edb874b2SJonas Devlieghere 626e19f7221SDavid SpickettOnce you have stopped, LLDB will choose a current thread, usually the one that 627edb874b2SJonas Devliegherestopped "for a reason", and a current frame in that thread (on stop this is 628edb874b2SJonas Devliegherealways the bottom-most frame). Many the commands for inspecting state work on 629edb874b2SJonas Devliegherethis current thread/frame. 630edb874b2SJonas Devlieghere 631edb874b2SJonas DevlieghereTo inspect the current state of your process, you can start with the threads: 632edb874b2SJonas Devlieghere 633edb874b2SJonas Devlieghere:: 634edb874b2SJonas Devlieghere 635edb874b2SJonas Devlieghere (lldb) thread list 636edb874b2SJonas Devlieghere Process 46915 state is Stopped 637edb874b2SJonas Devlieghere * thread #1: tid = 0x2c03, 0x00007fff85cac76a, where = libSystem.B.dylib`__getdirentries64 + 10, stop reason = signal = SIGSTOP, queue = com.apple.main-thread 638edb874b2SJonas Devlieghere thread #2: tid = 0x2e03, 0x00007fff85cbb08a, where = libSystem.B.dylib`kevent + 10, queue = com.apple.libdispatch-manager 639edb874b2SJonas Devlieghere thread #3: tid = 0x2f03, 0x00007fff85cbbeaa, where = libSystem.B.dylib`__workq_kernreturn + 10 640edb874b2SJonas Devlieghere 641edb874b2SJonas DevlieghereThe ``*`` indicates that Thread 1 is the current thread. To get a backtrace for 642edb874b2SJonas Devliegherethat thread, do: 643edb874b2SJonas Devlieghere 644edb874b2SJonas Devlieghere:: 645edb874b2SJonas Devlieghere 646edb874b2SJonas Devlieghere (lldb) thread backtrace 647edb874b2SJonas Devlieghere thread #1: tid = 0x2c03, stop reason = breakpoint 1.1, queue = com.apple.main-thread 648edb874b2SJonas Devlieghere frame #0: 0x0000000100010d5b, where = Sketch`-[SKTGraphicView alignLeftEdges:] + 33 at /Projects/Sketch/SKTGraphicView.m:1405 649edb874b2SJonas Devlieghere frame #1: 0x00007fff8602d152, where = AppKit`-[NSApplication sendAction:to:from:] + 95 650edb874b2SJonas Devlieghere frame #2: 0x00007fff860516be, where = AppKit`-[NSMenuItem _corePerformAction] + 365 651edb874b2SJonas Devlieghere frame #3: 0x00007fff86051428, where = AppKit`-[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121 652edb874b2SJonas Devlieghere frame #4: 0x00007fff860370c1, where = AppKit`-[NSMenu performKeyEquivalent:] + 272 653edb874b2SJonas Devlieghere frame #5: 0x00007fff86035e69, where = AppKit`-[NSApplication _handleKeyEquivalent:] + 559 654edb874b2SJonas Devlieghere frame #6: 0x00007fff85f06aa1, where = AppKit`-[NSApplication sendEvent:] + 3630 655edb874b2SJonas Devlieghere frame #7: 0x00007fff85e9d922, where = AppKit`-[NSApplication run] + 474 656edb874b2SJonas Devlieghere frame #8: 0x00007fff85e965f8, where = AppKit`NSApplicationMain + 364 657edb874b2SJonas Devlieghere frame #9: 0x0000000100015ae3, where = Sketch`main + 33 at /Projects/Sketch/SKTMain.m:11 658edb874b2SJonas Devlieghere frame #10: 0x0000000100000f20, where = Sketch`start + 52 659edb874b2SJonas Devlieghere 660eb6097a7SDavid SpickettYou can also provide a list of threads to backtrace, or the keyword ``all`` to see all threads: 661edb874b2SJonas Devlieghere 662edb874b2SJonas Devlieghere:: 663edb874b2SJonas Devlieghere 664edb874b2SJonas Devlieghere (lldb) thread backtrace all 665edb874b2SJonas Devlieghere 666edb874b2SJonas DevlieghereYou can select the current thread, which will be used by default in all the 667eb6097a7SDavid Spickettcommands in the next section, with the ``thread select`` command: 668edb874b2SJonas Devlieghere 669edb874b2SJonas Devlieghere:: 670edb874b2SJonas Devlieghere 671edb874b2SJonas Devlieghere (lldb) thread select 2 672edb874b2SJonas Devlieghere 673eb6097a7SDavid Spickettwhere the thread index is just the one shown in the ``thread list`` listing. 674edb874b2SJonas Devlieghere 675edb874b2SJonas Devlieghere 676edb874b2SJonas DevlieghereExamining Stack Frame State 677edb874b2SJonas Devlieghere--------------------------- 678edb874b2SJonas Devlieghere 679edb874b2SJonas DevlieghereThe most convenient way to inspect a frame's arguments and local variables is 680eb6097a7SDavid Spickettto use the ``frame variable`` command: 681edb874b2SJonas Devlieghere 682edb874b2SJonas Devlieghere:: 683edb874b2SJonas Devlieghere 684edb874b2SJonas Devlieghere (lldb) frame variable 685edb874b2SJonas Devlieghere self = (SKTGraphicView *) 0x0000000100208b40 686edb874b2SJonas Devlieghere _cmd = (struct objc_selector *) 0x000000010001bae1 687edb874b2SJonas Devlieghere sender = (id) 0x00000001001264e0 688edb874b2SJonas Devlieghere selection = (NSArray *) 0x00000001001264e0 689edb874b2SJonas Devlieghere i = (NSUInteger) 0x00000001001264e0 690edb874b2SJonas Devlieghere c = (NSUInteger) 0x00000001001253b0 691edb874b2SJonas Devlieghere 692eb6097a7SDavid SpickettAs you see above, if you do not specify any variable names, all arguments and 693eb6097a7SDavid Spickettlocals will be shown. If you call ``frame variable`` passing in the names of 694eb6097a7SDavid Spickettparticular local variables, only those variables will be printed. For instance: 695edb874b2SJonas Devlieghere 696edb874b2SJonas Devlieghere:: 697edb874b2SJonas Devlieghere 698edb874b2SJonas Devlieghere (lldb) frame variable self 699edb874b2SJonas Devlieghere (SKTGraphicView *) self = 0x0000000100208b40 700edb874b2SJonas Devlieghere 701eb6097a7SDavid SpickettYou can also pass in a path to some sub-element of one of the available locals, 702edb874b2SJonas Devlieghereand that sub-element will be printed. For instance: 703edb874b2SJonas Devlieghere 704edb874b2SJonas Devlieghere:: 705edb874b2SJonas Devlieghere 706edb874b2SJonas Devlieghere (lldb) frame variable self.isa 707edb874b2SJonas Devlieghere (struct objc_class *) self.isa = 0x0000000100023730 708edb874b2SJonas Devlieghere 709eb6097a7SDavid SpickettThe ``frame variable`` command is not a full expression parser but it does 710edb874b2SJonas Devliegheresupport a few simple operations like ``&``, ``*``, ``->``, ``[]`` (no 711edb874b2SJonas Devlieghereoverloaded operators). The array brackets can be used on pointers to treat 712edb874b2SJonas Devliegherepointers as arrays: 713edb874b2SJonas Devlieghere 714edb874b2SJonas Devlieghere:: 715edb874b2SJonas Devlieghere 716edb874b2SJonas Devlieghere (lldb) frame variable *self 717edb874b2SJonas Devlieghere (SKTGraphicView *) self = 0x0000000100208b40 718edb874b2SJonas Devlieghere (NSView) NSView = { 719edb874b2SJonas Devlieghere (NSResponder) NSResponder = { 720edb874b2SJonas Devlieghere ... 721edb874b2SJonas Devlieghere 722edb874b2SJonas Devlieghere (lldb) frame variable &self 723edb874b2SJonas Devlieghere (SKTGraphicView **) &self = 0x0000000100304ab 724edb874b2SJonas Devlieghere 725edb874b2SJonas Devlieghere (lldb) frame variable argv[0] 726edb874b2SJonas Devlieghere (char const *) argv[0] = 0x00007fff5fbffaf8 "/Projects/Sketch/build/Debug/Sketch.app/Contents/MacOS/Sketch" 727edb874b2SJonas Devlieghere 728edb874b2SJonas DevlieghereThe frame variable command will also perform "object printing" operations on 729e19f7221SDavid Spickettvariables (currently LLDB only supports ObjC printing, using the object's 730eb6097a7SDavid Spickett``description`` method. Turn this on by passing the ``-o`` flag to frame variable: 731edb874b2SJonas Devlieghere 732edb874b2SJonas Devlieghere:: 733edb874b2SJonas Devlieghere 734edb874b2SJonas Devlieghere (lldb) frame variable -o self (SKTGraphicView *) self = 0x0000000100208b40 <SKTGraphicView: 0x100208b40> 735edb874b2SJonas Devlieghere You can select another frame to view with the "frame select" command 736edb874b2SJonas Devlieghere 737edb874b2SJonas Devlieghere (lldb) frame select 9 738edb874b2SJonas Devlieghere frame #9: 0x0000000100015ae3, where = Sketch`function1 + 33 at /Projects/Sketch/SKTFunctions.m:11 739edb874b2SJonas Devlieghere 740eb6097a7SDavid SpickettYou can also move up and down the stack by passing the ``--relative`` (``-r``) option. 741e19f7221SDavid SpickettWe also have built-in aliases ``u`` and ``d`` which behave like their GDB equivalents. 742