status will tell you: SDK path, processor architecture, OS version and even list of available devices for this SDK.

The "print_hello" python command has been installed and is ready for use. Use Swift syntax to evaluate and interact with your running app, or write new code to …

In this article, I just scratched the surface of true LLDB’s power. If you need you can hang it above your Mac to remember these commands . The Swift.org community makes use of the LLDB debugger to provide a rich REPL as well as the debugging environment for the Swift Language. The strategy used for textually If a method is going to return something you don't want, you can create a new object in lldb, get its memory address with e and inject it into the desired register. Just use -D flag with appropriate depth level to do so: By default LLDB will look infinitely into the object and show you a full description of every nested object: You can also explore object description with e -O -- or simply using alias po like in the example below: Not so descriptive, isn’t it? There are commands for C++, Objective-C, Swift and RenderScript. The previous example allows me to call $increaseCounter() directly from lldb, which will add 1 to my "I can't handle this bug anymore" counter. Debugging using any other version of LLDB can lead to unpredictable function, set a breakpoint in it, and then call it. inspection of Swift types as well as full-featured expression Which will allow you to manage (add, delete, import and list) custom Python scripts. It could be really helpful if you encounter some problem but want to tackle it a bit later.

Type 'DONE' to end. LLDB has this great little command called bugreport which will generate a full report of current app’s state. For sure, there is a flag for that: Now let’s tackle the most interesting part — breakpoint automation. evaluator. in this case, the jump instruction is 0x100000da0 : jne 0x100000da7, which will jump to the memory address 0x100000da7 if the r8 register (that is set in the previous 0x100000d9c : test r8, 0x1 instruction) is different than zero (so, true). I won’t describe them all.

In general, all advanced breakpoint commands are extremely painful to write manually in lldb (which is why I’ll avoid them in this article), but thankfully you can easily set breakpoint actions inside of Xcode: If you’ve used po for some time, you might've seen a cryptic error message like this in the past: This is because po evaluates your code by compiling it, and unfortunately there are still cases where this can go wrong even though the code you're trying to access is correct. Enter your debugger command(s). This object contains some string and structure as properties. are automatically injected into playground code so no explicit reference As I'm not subscribed, r8 will certainly be zero, which will prevent that instruction from being triggered. You might already know po (short for "print object") -- the friendly command that is commonly used to print the contents of a property: However, po is much more powerful than that -- despite the name implying that it prints things, po is an alias for expression --object-description --, an argumented version of the more raw expression (or just e) command that makes the output more swifty: Because it’s an alias, po can do everything that e can. If you are interested in such topic, please leave a comment below. These are direct equivalent of flow control buttons on Xcode debugger toolbar. Even though LLDB here with us for ages, there are still many people who don’t use its full potential. And -l is a line number of a new breakpoint. And you can spend hours reading it. For example, if I can’t recompile the code, how can I force the following method to go inside the isSubscribed condition even though I'm not subscribed? Swift is tightly coupled to the version of the Swift compiler embedded in the debugger. Well, you can’t use LLDB GUI mode in the Xcode, but you can always do it from the terminal. For example, you want to explore first-level properties only. But since Xcode does the process attachment for us automatically (LLDB is attached by Xcode every time you run a target) I won’t stop on that. In other words, we are looking for any UIView instance whose isFocused property is true. So here is our plan: I have also prepared the map of useful LLDB commands with description and examples. evaluation in the context of a rapidly evolving language. the full range of language features in Swift and can freely declare of interest on a line-by-line basis and communicate them to Xcode.

By following this chart, we can see that the OPCODE for je is 74, so if we want to make jne become je, we need to swap the first two bits with 74. . This can range from creating methods on the fly to even changing the CPU’s registers to force a specific flow on the app without having to recompile it, and knowing them can greatly improve your debugging experience.
It shows you reference count for the specific object. stops at a breakpoint the full feature set of the debugger is With process you can basically control debug process and attach to a specific target or detach a debugger from it. toolchain to work with the latest Swift features in Xcode playgrounds. Follow me on my Twitter (@rockbruno_), and let me know of any suggestions and corrections you want to share. Let’s skip the most obvious commands like: breakpoint enable, breakpoint disable and breakpoint delete. Write the command below in the terminal to get full documentation: I’d like to stop on the following expression's flags: Let’s say we have some object called logger.

There is also a predefined LLDB shortcut for these particular commands: In order to get more information about the current thread just call info subcommand: To see a list of all currently active threads use list subcommand: In the LLDB you can find a command for managing other commands.
Fancy Xcode Debugger UI shows you all available information without typing a single LLDB command. So to find a problem you can do something like this: Or… it’s better to use LLDB expression instead to change the value in the runtime. scenarios in the debugger set a high bar for the expression Did you know you can set a specific action which will execute as soon as breakpoint occurs? I’d like to walk you through the most useful commands instead. So here are these two commands: demangle and refcount. Let’s see the output example with an object we used in the previous section — logger: For sure, this could be quite useful if you are debugging some memory leaks. While Xcode provides several visual abstractions for lldb commands like adding breakpoints by clicking the lines of code and running by clicking the play button, lldb provides several useful commands that are not present in Xcode’s UI. Playground Support will be included in frame command can help you with that: Use snippet below to get a quick understanding where you are and what surrounding conditions are at the moment: This information will be useful in breakpoint management later in the article. e is meant for evaluating expressions, which can range from printing properties to changing their values and even defining new classes. It’s trivial to declare a Without Xcode to assist you, some of these tricks can prevent you from having to compile the app again to test certain changes. immediately available.