自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

XCode的一些調(diào)試技巧

移動開發(fā) iOS
XCode 內(nèi)置GDB,我們可以在命令行中使用 GDB 命令來調(diào)試我們的程序。下面將介紹一些常用的命令以及調(diào)試技巧。

po 命令:為 print object 的縮寫,顯示對象的文本描述(顯示從對象的 description 消息獲得的字符串信息)。

比如:

上圖中,我使用 po 命令顯示一個 NSDictionary 的內(nèi)容。注意在左側(cè)我們可以看到 dict 的一些信息:3 key/value pairs,顯示該 dict 包含的數(shù)據(jù)量,而展開的信息顯示 isa 層次體系(即class 和 metaclass結(jié)構(gòu)關(guān)系)。我們可以右擊左側(cè)的 dict,選中“Print Description of "dict"”,則可以在控制臺輸出 dict 的詳細(xì)信息:

 

 

 view plaincopyprint?

 

  1. Printing description of dict:  
  2. <CFBasicHash 0x1001149e0 [0x7fff7e27ff40]>{type = immutable dict, count = 3,  
  3. entries =>  
  4.     0 : <CFString 0x100002458 [0x7fff7e27ff40]>{contents = "first"} = <CFString 0x100002438 [0x7fff7e27ff40]>{contents = "one"}  
  5.     1 : <CFString 0x100002498 [0x7fff7e27ff40]>{contents = "second"} = <CFString 0x100002478 [0x7fff7e27ff40]>{contents = "two"}  
  6.     2 : <CFString 0x1000024d8 [0x7fff7e27ff40]>{contents = "third"} = <CFString 0x1000024b8 [0x7fff7e27ff40]>{contents = "three"}  
  7. }  
  8. (gdb)   

 

print 命令:有點類似于格式化輸出,可以輸出對象的不同信息:

 

如:

 

 

[cpp] view plaincopyprint?

 

  1. (gdb) print (char *)[[dict description] cStringUsingEncoding:4]  
  2. $1 = 0x1001159c0 "{\n    first = one;\n    second = two;\n    third = three;\n}"  
  3. (gdb) print (int)[dict retainCount]  
  4. $2 = 1  
  5. (gdb)   

 

注:4是 NSUTF8StringEncoding 的值。

info 命令:我們可以查看內(nèi)存地址所在信息

比如 "info symbol 內(nèi)存地址" 可以獲取內(nèi)存地址所在的 symbol 相關(guān)信息:

 

 

[cpp] view plaincopyprint?

 

  1. (gdb) info symbol 0x00000001000017f7  
  2. main + 343 in section LC_SEGMENT.__TEXT.__text of /Users/LuoZhaohui/Library/Developer/Xcode/DerivedData/RunTimeSystem-anzdlhiwvlbizpfureuvenvmatnp/Build/Products/Debug/RunTimeSystem  

 

比如 "info line *內(nèi)存地址" 可以獲取內(nèi)存地址所在的代碼行相關(guān)信息:

 

 

[cpp] view plaincopyprint?

 

  1. (gdb) info line *0x00000001000017f7  
  2. Line 62 of "/Users/LuoZhaohui/Documents/Study/RunTimeSystem/RunTimeSystem/main.m" starts at address 0x1000017f7 <main+343> and ends at 0x10000180a <main+362>.  

 

show 命令:顯示 GDB 相關(guān)的信息。如:show version 顯示GDB版本信息

 

 

[cpp] view plaincopyprint?

 

  1. (gdb) show version  
  2. GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 UTC 2011)  
  3. Copyright 2004 Free Software Foundation, Inc.  
  4. GDB is free software, covered by the GNU General Public License, and you are  
  5. welcome to change it and/or distribute copies of it under certain conditions.  
  6. Type "show copying" to see the conditions.  
  7. There is absolutely no warranty for GDB.  Type "show warranty" for details.  
  8. This GDB was configured as "x86_64-apple-darwin".  

 

help 命令:如果忘記某條命令的語法了,可以使用 help 命令名 來獲取幫助信息。如:help info 顯示 info 命令的用法。

 

 

 

[cpp] view plaincopyprint?

 

  1. (gdb) help info  
  2. Generic command for showing things about the program being debugged.  
  3.   
  4. List of info subcommands:  
  5.   
  6. info address -- Describe where symbol SYM is stored  
  7. info all-registers -- List of all registers and their contents  
  8. info args -- Argument variables of current stack frame  
  9. info auxv -- Display the inferior's auxiliary vector  
  10. info breakpoints -- Status of user-settable breakpoints  
  11. info catch -- Exceptions that can be caught in the current stack frame  
  12. info checkpoints -- Help  
  13. info classes -- All Objective-C classes  
  14. ......  
  15.   
  16. Type "help info" followed by info subcommand name for full documentation.  
  17. Command name abbreviations are allowed if unambiguous.  
  18. (gdb)   

 

在系統(tǒng)拋出異常處設(shè)置斷點

有時候我們的程序不知道跑到哪個地方就 crash 了,而 crash 又很難重現(xiàn)。保守的做法是在系統(tǒng)拋出異常之前設(shè)置斷點,具體來說是在 objc_exception_throw處設(shè)置斷點。設(shè)置步驟為:首先在 XCode 按 CMD + 6,進入斷點管理窗口;然后點擊右下方的 +,增加新的 Symbolic Breakpoint,在 Symbol 一欄輸入:objc_exception_throw,然后點擊 done,完成。 這樣在 Debug 模式下,如果程序即將拋出異常,就能在拋出異常處中斷了。比如在前面的代碼中,我讓 [firstObjctcrashTest]; 拋出異常。在 objc_exception_throw 處設(shè)置斷點之后,程序就能在該代碼處中斷了,我們從而知道代碼在什么地方出問題了。

責(zé)任編輯:佚名 來源: 飄飄白云
相關(guān)推薦

2013-03-29 13:17:53

XCode調(diào)試技巧iOS開發(fā)

2011-06-01 16:50:21

JAVA

2009-11-27 13:04:16

VS2005遠(yuǎn)程調(diào)試

2013-04-18 10:19:40

iOS開發(fā)Xcode調(diào)試

2011-10-26 20:55:43

ssh 安全

2011-07-12 09:47:53

WebService

2011-05-23 18:06:24

站內(nèi)優(yōu)化SEO

2021-10-12 23:10:58

UnsafeJavaJDK

2022-12-02 14:58:27

JavaScript技巧編程

2009-11-26 10:32:57

PHP代碼優(yōu)化

2020-04-08 10:21:58

bash腳本語言

2020-04-14 09:22:47

bash腳本技巧

2017-09-20 15:07:32

數(shù)據(jù)庫SQL注入技巧分享

2018-05-07 08:22:19

LinuxImageMagick查看圖片

2022-02-17 13:58:38

Linux技巧文件

2017-05-10 15:30:30

skynet崩潰程序

2011-07-26 17:43:49

Xcode SVN

2017-08-23 09:26:16

Chromelive 狀態(tài)代碼

2024-03-11 15:08:26

Linux操作系統(tǒng)進程

2021-06-18 07:35:46

Java接口應(yīng)用
點贊
收藏

51CTO技術(shù)棧公眾號