• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            羅朝輝(飄飄白云)

            關(guān)注嵌入式操作系統(tǒng),移動(dòng)平臺(tái),圖形開發(fā)。-->加微博 ^_^

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              85 隨筆 :: 0 文章 :: 169 評(píng)論 :: 0 Trackbacks

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

            羅朝輝 (http://www.shnenglu.com/kesalin/)

            CC 許可,轉(zhuǎn)載請(qǐng)注明出處

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

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

            比如:

            上圖中,我使用 po 命令顯示一個(gè) 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"”,則可以在控制臺(tái)輸出 dict 的詳細(xì)信息:

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

            print 命令
            :有點(diǎn)類似于格式化輸出,可以輸出對(duì)象的不同信息:
            如:
            (gdb) print (char *)[[dict description] cStringUsingEncoding:4]
            $1 = 0x100115620 "{\n    first = one;\n    second = two;\n    third = three;\n}"
            (gdb) 

            注:4是 NSUTF8StringEncoding 的值。

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

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

            (gdb) info symbol 0x00000001000017f7 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)信息:
            (gdb) info line *0x00000001000017f7 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版本信息

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


            help 命令
            :如果忘記某條命令的語法了,可以使用 help 命令名 來獲取幫助信息。如:help info 顯示 info 命令的用法。
            (gdb) help info
            Generic command for showing things about the program being debugged.

            List of info subcommands:

            info address -- Describe where symbol SYM is stored
            info all-registers -- List of all registers and their contents
            info args -- Argument variables of current stack frame
            info auxv -- Display the inferior's auxiliary vector
            info breakpoints -- Status of user-settable breakpoints
            info catch -- Exceptions that can be caught in the current stack frame
            info checkpoints -- Help
            info classes -- All Objective-C classes

            info vector -- Print the status of the vector unit
            info warranty -- Various kinds of warranty you do not have
            info watchpoints -- Synonym for ``info breakpoints''

            Type "help info" followed by info subcommand name for full documentation.
            Command name abbreviations are allowed if unambiguous.
            (gdb) 


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

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


            posted on 2012-01-31 16:19 羅朝輝 閱讀(3276) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Cocoa 開發(fā)
            波多野结衣AV无码久久一区| 激情伊人五月天久久综合| 久久久久99精品成人片| 亚洲成人精品久久| 狠狠色丁香婷婷久久综合| 色婷婷综合久久久久中文一区二区| 97精品久久天干天天天按摩| 国产免费福利体检区久久| 国产亚洲精品久久久久秋霞| 国产精品久久久久影视不卡| 亚洲国产成人精品女人久久久 | 久久久国产精品福利免费| 久久久国产精品| 久久被窝电影亚洲爽爽爽| 久久亚洲中文字幕精品一区| 日本精品久久久久中文字幕| 奇米影视7777久久精品人人爽| 欧美综合天天夜夜久久| 久久丫精品国产亚洲av不卡| 中文成人无码精品久久久不卡 | 国产成人无码精品久久久免费| 婷婷久久久亚洲欧洲日产国码AV| 久久久噜噜噜久久| 久久久久夜夜夜精品国产| 日韩人妻无码精品久久久不卡 | 国产成人无码精品久久久久免费| 亚洲色婷婷综合久久| 久久91精品国产91| 人妻无码久久精品| 久久一本综合| 一级做a爰片久久毛片看看| 精品久久人人做人人爽综合| 热久久这里只有精品| 狠狠色丁香婷婷综合久久来| 久久精品国产亚洲AV无码娇色| 中文字幕日本人妻久久久免费| 精品久久久久久久国产潘金莲| 青青草原综合久久大伊人| 一本色道久久88精品综合| 欧美牲交A欧牲交aⅴ久久| 精品久久久噜噜噜久久久|