10 Lesser Known LLDB Commands used in iOS App development

Debugging iOS Apps

Shubham
3 min readAug 26, 2023

These super pro LLDB commands can greatly aid in debugging your iOS apps, especially when you encounter complex issues that standard debugging tools might not fully address.

This post is exclusively for those who want to dive deep into the ocean of iOS.

And yes, please Follow me on LinkedIn

Let’s continue……………………..

Here are example use cases for each of the lesser-known LLDB commands in the context of debugging iOS apps:

  1. frame variable -T:
    Use Case: When you have a variable with an unclear type and you want to quickly determine its data type.
    Example: If you have a variable named response and want to know its type, use frame variable -T response.
  2. settings set target.language swift:
    Use Case: When you’re debugging a mixed Swift and Objective-C project and want to ensure proper expression evaluation.
    Example: Set the language to Swift using settings set target.language swift.
  3. expr -l Swift — myArray.map { $0 + 1 }:
    Use Case:
    When you want to evaluate Swift expressions without altering your code.
    Example: If you have an array myArray, you can use expr -l Swift -- myArray.map { $0 + 1 } to add 1 to each element.
  4. image list -o -f:
    Use Case: When you need to see a list of loaded modules with their file paths for troubleshooting purposes.
    Example: Use image list -o -f to see all loaded modules and their paths.
  5. register read:
    Use Case: When you need to inspect the values of CPU registers to understand program state.
    Example: Use register read to examine register values during a crash or unexpected behavior.
  6. memory write -s 4–0x12345678 0xdeadbeef:
    Use Case: When you want to modify a specific memory address during debugging.
    Example: Use memory write -s 4 -- 0x12345678 0xdeadbeef to change the data at address 0x12345678 to 0xdeadbeef.
  7. watchpoint modify -c ‘(old_val != new_val)’ variable:
    Use Case: When you want to track changes to a variable’s value with a specific condition.
    Example: Modify a watchpoint on myVariable to trigger when its value changes using watchpoint modify -c '(old_val != new_val)' myVariable.
  8. disassemble -c 10 — name functionName:
    Use Case:
    When you want to inspect the assembly code of a specific function to understand its behavior.
    Example: Disassemble the first 10 instructions of a function named myFunction with disassemble -c 10 --name myFunction.
  9. breakpoint command add — one-shot true 1.1:
    Use Case: When you want to execute a specific command once when a breakpoint is hit.
    Example: Add a one-shot command to breakpoint 1.1 that prints a message using breakpoint command add --one-shot true 1.1.
  10. type lookup -r ‘^Swift.Array’:
    Use Case: When you need to find all Swift types matching a specific pattern.
    Example: Look up all types starting with “Swift.Array” using type lookup -r '^Swift.Array'.

These example use cases illustrate how each LLDB command can be applied to various scenarios during iOS app debugging, from inspecting memory to modifying variables and analyzing assembly code.

If you found this content valuable, I invite you to follow me for more insights, tips, and updates. Stay connected and be among the first to access new content. Let’s embark on this knowledge journey together. Click the follow button and stay informed!

Additionally checkout these links

--

--

Shubham

I speak for the new world. Seasoned Software Engineering Expert | Guiding Developers Towards Excellence | 12 Years of Industry Insight