未完待續,[繼續總結]html
lldb與gdb命令對比git
功能 | 命令 |
---|---|
暫停/繼續 | cmd + ctrl + Y |
斷點失效/生效 | cmd + Y |
控制檯顯示/隱藏 | cmd + shift + Y |
光標切換到控制檯 | cmd + shift + C |
清空控制檯 | cmd + K |
step over | F6 |
step into | F7 |
step out | F8 |
//swift版
func DLog<T>(message: T, file: String = #file, method: String = #function, line: Int = #line) {
#if DEBUG
print("<\((file as NSString).lastPathComponent) : \(line)>, \(method) \(message)")
#endif
}
//OC版
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"<%s : %d> %s " fmt), [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif
複製代碼
設置斷點觸發條件 github
注意:
// 正確
(BOOL)[pId isEqualToString:@"short-videopage"]
// 報錯:error: no known method '-isEqualToString:'; cast the message send to the method's return type [pId isEqualToString:@"short-videopage"] 複製代碼
在調試登陸相關的bug時,很是方便,不用擔憂常常輸密碼,還輸錯的尷尬 數據庫
調試UI,改變指定控件的顏色
當咱們查看一個陌生的項目的時候,咱們能夠先運行APP,對全部的
viewDidLoad
函數添加斷點,進而瞭解代碼執行路徑 expressSymbol
:符號
methodName
只須要寫函數名,不用寫後面的()[className methodName]
className是類名,methodName是方法名(不區分類方法和實例方法)ClassName.methodName
Module
模塊篩選:能夠避免不一樣庫中方法名或者函數名相同 Condition
觸發條件swift
這裏能夠添加一些指定觸發條件,好比添加第一個參數(arg3)不能爲nil。這裏arg4表明第2個參數,以此類推。這裏也能夠調用方法來判斷,但必須是類方法,而且返回值必須爲BOOL類型。 樣例:找出給[UIImage imageNamed:]傳nil的代碼。這裏就須要設置Symbol爲
查看某一個函數須要添加斷點的符號填寫格式(在須要調試的函數打上斷點,程序運行走到斷點後,從堆棧信息中查看相應函數的格式)[UIImage imageNamed:]
,而後Condition設置爲$arg3 == nil
。這樣在運行中若是遇到傳nil就會觸發斷點。 xcode
若是電腦配置較低,最好使用
chisel
插件命令pviews
bash
遇到EXC_BAD_ACCESS這個錯誤,那就意味着你向一個已經釋放的對象發送消息。Xcode知道這個對象是什麼,因此可讓咱們知道這個對象在哪裏,以及這是何時發生的。當開啓殭屍模式後,遇到EXC_BAD_ACCESS,xcode能夠幫咱們快速定位到出現問題的代碼。網絡
開啓殭屍模式: app
導入@import UIKit
(lldb) p self.view.frame
error: property 'frame' not found on object of type 'UIView *'
error: 1 errors parsing expression
(lldb) e @import UIKit
(lldb) p self.view.frame
(CGRect) $0 = (origin = (x = 0, y = 0), size = (width = 375, height = 667))
複製代碼
或者(CGRect)
print (CGRect)[view frame]
(CGRect) $1 = (origin = (x = 0, y = 0), size = (width = 200, height = 100))
複製代碼
UIAppliaction
.h文件
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CustomApplication : UIApplication
@end
NS_ASSUME_NONNULL_END
複製代碼
.m文件
#import "CustomApplication.h"
@implementation CustomApplication
-(void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
}
@end
複製代碼
main.m文件
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "CustomApplication.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc,
argv,
NSStringFromClass([CustomApplication class]),
NSStringFromClass([AppDelegate class]));
}
}
複製代碼
一次事件可能會執行三次函數:
-(void)sendEvent:(UIEvent *)event
三次的force
有區別
一次事件可能會執行兩次函數:
-(void)sendEvent:(UIEvent *)event
兩次的force
沒區別
一、若是是
UIControl
事件,集成UIResponder
控件(UIButton
)消息傳遞鏈(倒序)以下圖所示
二、若是是
UIGestureRecognizer
手勢事件,集成UIResponder
控件(UIView
)消息傳遞鏈(倒序)以下圖所示
三、若是
UIControl
和UIGestureRecognizer
同時存在,優先級高
Chisel是faceBook開源的lldb調試命令集合
Chisel 使用 homebrew 來安裝
brew update
brew install chisel
複製代碼
安裝完成後,將下面的命令添加到~/.lldbinit
中,xcode啓動的時候纔會加載chisel
command script import /usr/local/opt/chisel/libexec/fblldb.py
複製代碼
經常使用命令
查看幫助(lldb) help
複製代碼
Reveal 絕對是iOS界面調試利器。使用起來不只比Xcode自帶流暢,並且功能更加多。因爲收費,30天事後就沒怎麼用可是絕對好用。
大約有4中集成方法,詳情參加 官網。FLEX是Flipboard開源的一系列在應用中調試的工具集。FLEX以第三方庫的形式集成在應用中,使用時將類庫加到工程中,而後 經過調用[[FLEXManager sharedManager] showExplorer]; 就可顯示出用於調試的工具欄進行調試。
它提供的功能以下: