HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps.

Overview

HMLLDB is a collection of LLDB commands to assist in the debugging of iOS apps.
中文介绍

Features

  • Non-intrusive. Your iOS project does not need to be modified
  • All commands support real device and simulator
  • All commands support Objective-C and Swift project
  • Some commands provide interactive UI within the APP

Requirements

  • Xcode 12.3
  • 64-bit simulator or real device, iOS 9.0+
  • Debug configuration (or Optimization Level set [-O0]/[-Onone])

Installation

  1. Download all the files. I recommend cloning the repository.
  2. Open up (or create) ~/.lldbinit file, and append the following lines to the end of the file:
command script import /path/to/HMLLDB.py

For example, the command in my computer:
command script import /Users/pal/Desktop/gitProjects/HMLLDB/commands/HMLLDB.py

  1. Restart Xcode, run your own iOS project, click Pause program execution to enter the LLDB debugging mode, enter the command help, if you see the commands described below, the installation is successful.

Commands

Command Description
deletefile Delete the specified file in the sandbox
pbundlepath Print the path of the main bundle
phomedirectory Print the path of the home directory("~")
fclass Find the class containing the input name(Case insensitive)
fsubclass Find the subclass of the input
fsuperclass Find the superclass of the input
fmethod Find the specified method in the method list, you can also find the method list of the specified class
methods Execute [inputClass _methodDescription] or [inputClass _shortMethodDescription]
properties Execute [inputClass _propertyDescription]
ivars Execute [instance _ivarDescription]
plifecycle Print life cycle of UIViewController
redirect Redirect stdout/stderr
push Find UINavigationController in keyWindow then push a specified UIViewController
showhud Display the debug HUD on the key window, it is showing the memory usage, CPU utilization and FPS of the main thread
sandbox Presenting a sandbox browser that can share and delete files
inspect Inspect UIView
environment Show diagnostic environment.
...

All commands in the table can use help <command> to view the syntax and examples. For example, the output of help fmethod:

(lldb) help fmethod
     Find the method.  Expects 'raw' input (see 'help raw-input'.)

Syntax: fmethod

    Syntax:
        fmethod <methodName>  (Case insensitive.)
        fmethod [--class] <className>

    Options:
        --class/-c; Find all method in the class

    Examples:
        (lldb) fmethod viewdid
        (lldb) fmethod viewDidLayoutSubviews
        (lldb) fmethod -c UITableViewController

    This command is implemented in HMClassInfoCommands.py

Example

Some examples use the demo in the Kingfisher project.
It is recommended to click Pause program execution to enter the LLDB debugging mode to execute commands, instead of executing commands by hitting breakpoints.

deletefile

It is recommended to re-run the project after executing the command, because some data is still in the memory.

# Delete all file in the sandbox
(lldb) deletefile -a

# Delete the "~/Documents" directory
(lldb) deletefile -d

# Delete the "~/Library" directory
(lldb) deletefile -l

# Delete the "~/tmp" directory
(lldb) deletefile -t

# Delete the "~/Library/Caches" directory
(lldb) deletefile -c

# Delete the "~Library/Preferences" directory
(lldb) deletefile -p

# Delete the specified file or directory
(lldb) deletefile -f path/to/fileOrDirectory

pbundlepath & phomedirectory

# Print the path of the main bundle
(lldb) pbundlepath
[HMLLDB] /Users/pal/Library/Developer/CoreSimulator/Devices/D90D74C6-DBDF-4976-8BEF-E7BA549F8A89/data/Containers/Bundle/Application/84AE808C-6703-488D-86A2-C90004434D3A/Kingfisher-Demo.app

# Print the path of the home directory
(lldb) phomedirectory
[HMLLDB] /Users/pal/Library/Developer/CoreSimulator/Devices/D90D74C6-DBDF-4976-8BEF-E7BA549F8A89/data/Containers/Data/Application/3F3DF0CD-7B57-4E69-9F15-EB4CCA7C4DD8

# If it is running on the simulator, you can add the -o option to open path with Finder
(lldb) pbundlepath -o
(lldb) phomedirectory -o

fclass & fsubclass & fsuperclass & fmethod

These commands are optimized for Swift, and the namespace can be omitted when entering the Swift class.

fclass: Find all class names that contain the specified string.

(lldb) fclass NormalLoadingViewController
[HMLLDB] Waiting...
[HMLLDB] Count: 1 
Kingfisher_Demo.NormalLoadingViewController (0x102148fa8)

# Case insensitive
(lldb) fclass Kingfisher_Demo.im
[HMLLDB] Waiting...
[HMLLDB] Count: 2 
Kingfisher_Demo.ImageDataProviderCollectionViewController (0x102149a18)
Kingfisher_Demo.ImageCollectionViewCell (0x1021498e8)

fsubclass: Find all subclasses of a class.

(lldb) fsubclass UICollectionViewController
[HMLLDB] Waiting...
[HMLLDB] Subclass count: 10 
Kingfisher_Demo.InfinityCollectionViewController
Kingfisher_Demo.HighResolutionCollectionViewController
...

fsuperclass: Find the super class of a class.

(lldb) fsuperclass UIButton
[HMLLDB] UIButton : UIControl : UIView : UIResponder : NSObject

(lldb) fsuperclass KingfisherManager
[HMLLDB] Kingfisher.KingfisherManager : Swift._SwiftObject

fmethod: Find the specified method in the method list, you can also find the method list of the specified class.

# Find the specified method in the method list. Case insensitive.
(lldb) fmethod viewdidload
[HMLLDB] Waiting...
[HMLLDB] Methods count: 158 
(-) playbackControlsViewDidLoad:
	Type encoding:v24@0:8@16
	Class:AVPlaybackControlsController
(-) turboModePlaybackControlsPlaceholderViewDidLoad:
	Type encoding:v24@0:8@16
	Class:AVPlaybackControlsController
(-) viewDidLoad
	Type encoding:v16@0:8
	Class:AVNewsWidgetPlayerBehaviorContext
...

# Option -c: Find the method list of the specified class. Case sensitive.
(lldb) fmethod -c ImageCache
[HMLLDB] Waiting...
[HMLLDB] Class: Kingfisher.ImageCache (0x10264c6f8)
Instance methods count: 3. Class method count: 0.
(-) cleanExpiredDiskCache
	Type encoding:v16@0:8
(-) backgroundCleanExpiredDiskCache
	Type encoding:v16@0:8
(-) clearMemoryCache
	Type encoding:v16@0:8

methods & properties & ivars

methods: Execute [inputClass _methodDescription] or [inputClass _shortMethodDescription] properties: Execute [inputClass _propertyDescription] ivars: Execute [instance _ivarDescription]

These commands are optimized for Swift, and the namespace can be omitted when entering the Swift class.

# Syntax
methods [--short] <className/classInstance>
properties <className/classInstance>
ivars <Instance>

(lldb) methods NormalLoadingViewController
[HMLLDB] <Kingfisher_Demo.NormalLoadingViewController: 0x10d55ffa8>:
in Kingfisher_Demo.NormalLoadingViewController:
	Instance Methods:
		- (id) collectionView:(id)arg1 cellForItemAtIndexPath:(id)arg2; (0x10d523f30)
		- (long) collectionView:(id)arg1 numberOfItemsInSection:(long)arg2; (0x10d522a20)
		- (void) collectionView:(id)arg1 willDisplayCell:(id)arg2 forItemAtIndexPath:(id)arg3; (0x10d523af0)
		- (void) collectionView:(id)arg1 didEndDisplayingCell:(id)arg2 forItemAtIndexPath:(id)arg3; (0x10d522cb0)
		- (id) initWithCoder:(id)arg1; (0x10d522960)
...

# These commands can only be used for subclasses of NSObject
(lldb) methods KingfisherManager
[HMLLDB] KingfisherManager is not a subclass of NSObject

plifecycle

Used to print the life cycle of UIViewController.
In a non-intrusive way, and Xcode can set the console font color to make it clearer. It has become one of my favorite commands.

Usage:

  1. Create a Symbolic Breakpoint, and then add the method to be printed in the Symbol line.(e.g. -[UIViewController viewDidAppear:])
  2. Add a Action(Debugger Command), enter the plifecycle command
  3. Check the option: Automatically continue after evaluating actions

I usually use the -i option to ignore some system-generated UIViewController. img1

I often Enable viewDidAppear: and dealloc methods, and the other methods are set to Disable and started on demand, as shown below: img2

Output in Xcode: img3

It should be noted that there are two problems with this command.

  1. Cause UIViewController switching lag.
  2. The following warning may be triggered when starting the APP. You need to click Continue program execution in Xcode to let the APP continue to run.
Warning: hit breakpoint while running function, skipping commands and conditions to prevent recursion.

BTW, the source code provides other ways to use LLDB to print the life cycle.

redirect

Redirect stdout/stder.

# You can redirect the output of Xcode to Terminal if you use the simulator
# Open the terminal, enter the "tty" command, you can get the path: /dev/ttys000
(lldb) redirect both /dev/ttys000
[HMLLDB] redirect stdout successful
[HMLLDB] redirect stderr successful

push

Find UINavigationController in keyWindow then push a specified UIViewController.
Notice: push MyViewController needs to execute [[MyViewController alloc] init] first. If the initializer of the class requires parameters, or the class needs to pass parameters after initialization, this command may cause errors.
The GIF demo didn't use Kingfisher because the UIViewController in the demo depends on the storyboard.
img4

showhud

Display the debug HUD on the keyWindow, it is showing the memory usage, CPU utilization and FPS of the main thread. img5

Tapping the debug HUD will present a new view controller, and its function will be introduced later. img6

sandbox

Presenting a sandbox browser that can share and delete files.
It takes a few seconds to call the command for the first time. img7

inspect

Inspect UIView of the current page.
img8

environment

Show diagnostic environment.
You can see that one of items is [Git commit hash], which is one of the reasons why clone repository is recommended.

(lldb) environment
[HMLLDB] [Python version] 3.8.2 (default, Nov  4 2020, 21:23:28) 
		[Clang 12.0.0 (clang-1200.0.32.28)]
[HMLLDB] [LLDB version] lldb-1200.0.44.2
		Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
[HMLLDB] [Target triple] x86_64h-apple-ios-simulator
[HMLLDB] [Git commit hash] 088f654cb158ffb16019b2deca5dce36256837ad
[HMLLDB] [Optimized] False: 28  True: 0
[HMLLDB] [Xcode version] 1230
[HMLLDB] [Xcode build version] 12C33
[HMLLDB] [Model identifier] x86_64
[HMLLDB] [System version] iOS 13.0

If an error occurs

Just-in-time compilation via LLDB is not stable. If an error occurs, please check in order according to the following steps.

  1. pull the latest code. Check the Xcode version, HMLLDB generally only adapts to the latest Xcode version.
  2. Open the ~/.lldbinit file and make sure to import the HMLLDB.py at the end of the file so that its commands are not overwritten.
  3. After launching the APP, click Pause program execution to enter the LLDB debugging mode to execute commands, instead of executing commands by hitting breakpoints. (In general, you can execute commands by hitting breakpoints)
  4. Restart Xcode can solve most problems.
  5. Restart the computer.
  6. After completing the above steps, the command still fails. Please copy the error and post it to Issue, and execute the environment command, its output should also be posted to Issue.

License

HMLLDB is released under the MIT license. See LICENSE for details.

You might also like...
FirmWire is a full-system baseband firmware emulation platform for fuzzing, debugging, and root-cause analysis of smartphone baseband firmwares
Measuring Coding Challenge Competence With APPS

Measuring Coding Challenge Competence With APPS This is the repository for Measuring Coding Challenge Competence With APPS by Dan Hendrycks*, Steven B

Avatarify Python - Avatars for Zoom, Skype and other video-conferencing apps.
Avatarify Python - Avatars for Zoom, Skype and other video-conferencing apps.

Avatarify Python - Avatars for Zoom, Skype and other video-conferencing apps.

Source code and data from the RecSys 2020 article
Source code and data from the RecSys 2020 article "Carousel Personalization in Music Streaming Apps with Contextual Bandits" by W. Bendada, G. Salha and T. Bontempelli

Carousel Personalization in Music Streaming Apps with Contextual Bandits - RecSys 2020 This repository provides Python code and data to reproduce expe

Illuminated3D This project participates in the Nasa Space Apps Challenge 2021.

Illuminated3D This project participates in the Nasa Space Apps Challenge 2021.

Create Data & AI apps in 20 lines of code with Shimoku

Install with: pip install shimoku-api-python Start with: from os import getenv import shimoku_api_python.client as Shimoku

Colour detection is necessary to recognize objects, it is also used as a tool in various image editing and drawing apps.

Colour Detection On Image Colour detection is the process of detecting the name of any color. Simple isn’t it? Well, for humans this is an extremely e

A machine learning malware analysis framework for Android apps.
A machine learning malware analysis framework for Android apps.

🕵️ A machine learning malware analysis framework for Android apps. ☢️ DroidDetective is a Python tool for analysing Android applications (APKs) for p

Collection of tasks for fast prototyping, baselining, finetuning and solving problems with deep learning.
Collection of tasks for fast prototyping, baselining, finetuning and solving problems with deep learning.

Collection of tasks for fast prototyping, baselining, finetuning and solving problems with deep learning Installation

Comments
  • error

    error

    [HMLLDB] Waiting... [HMLLDB] error: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x1000007ad). The process has been returned to the state before expression evaluation. [HMLLDB] Traceback(filename='/Users/mumu/HMLLDB/commands/HMClassInfoCommands.py', lineno=524, function='findMethod', code_context=[' result = HM.evaluateExpressionValue(command_script).GetObjectDescription()\n'], index=0) [HMLLDB] None

    opened by mumuwanglin 1
Owner
mao2020
iOS Developer
mao2020
Pose estimation for iOS and android using TensorFlow 2.0

?? Mobile 2D Single Person (Or Your Own Object) Pose Estimation for TensorFlow 2.0 This repository is forked from edvardHua/PoseEstimationForMobile wh

tucan9389 165 Nov 16, 2022
An algorithm study of the 6th iOS 10 set of Boost Camp Web Mobile

알고리즘 스터디 ?? 부스트캠프 웹모바일 6기 iOS 10조의 알고리즘 스터디 입니다. 개인적인 사정 등으로 S034, S055만 참가하였습니다. 스터디 목적 상진: 코테 합격 + 부캠끝나고 아침에 일어나기 위해 필요한 사이클 기완: 꾸준하게 자리에 앉아 공부하기 +

null 2 Jan 11, 2022
A Python library created to assist programmers with complex mathematical functions

libmaths libmaths was created not only as a learning experience for me, but as a way to make mathematical models in seconds for Python users using mat

Simple 73 Oct 2, 2022
Auto-updating data to assist in investment to NEPSE

Symbol Ratios Summary Sector LTP Undervalued Bonus % MEGA Strong Commercial Banks 368 5 10 JBBL Strong Development Banks 568 5 10 SIFC Strong Finance

Amit Chaudhary 16 Nov 1, 2022
GuideDog is an AI/ML-based mobile app designed to assist the lives of the visually impaired, 100% voice-controlled

Guidedog Authors: Kyuhee Jo, Steven Gunarso, Jacky Wang, Raghav Sharma GuideDog is an AI/ML-based mobile app designed to assist the lives of the visua

Kyuhee Jo 5 Nov 24, 2021
automated systems to assist guarding corona Virus precautions for Closed Rooms (e.g. Halls, offices, etc..)

Automatic-precautionary-guard automated systems to assist guarding corona Virus precautions for Closed Rooms (e.g. Halls, offices, etc..) what is this

badra 0 Jan 6, 2022
I created My own Virtual Artificial Intelligence named genesis, He can assist with my Tasks and also perform some analysis,,

Virtual-Artificial-Intelligence-genesis- I created My own Virtual Artificial Intelligence named genesis, He can assist with my Tasks and also perform

AKASH M 1 Nov 5, 2021
Lane assist for ETS2, built with the ultra-fast-lane-detection model.

Euro-Truck-Simulator-2-Lane-Assist Lane assist for ETS2, built with the ultra-fast-lane-detection model. This project was made possible by the amazing

null 36 Jan 5, 2023
Hypersearch weight debugging and losses tutorial

tutorial Activate tensorboard option Running TensorBoard remotely When working on a remote server, you can use SSH tunneling to forward the port of th

null 1 Dec 11, 2021
A general and strong 3D object detection codebase that supports more methods, datasets and tools (debugging, recording and analysis).

ALLINONE-Det ALLINONE-Det is a general and strong 3D object detection codebase built on OpenPCDet, which supports more methods, datasets and tools (de

Michael.CV 5 Nov 3, 2022