• <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>
            隨筆-19  評論-21  文章-0  trackbacks-0

            經常使用這些工具,有那么些功能卻不常用,也不知道。

            1. gdb

            a.  .gdbinit

            gdb運行時會首先加載 ~/.gdbinit文件

            例如:我在debug時,每次都需要進行handle SIGBUS noprint pass來處理SIGBUS信號,這種情況就可以把它寫入 .gdbinit文件。

            在.gdbinit里也可以定義函

              eg:  在.gdbinit里定義print_regs
                 def print_regs
                    i r eax ebx ecx edx
                 end

              (gdb) print_regs
              eax            0xbffff4a4    -1073744732
              ebx            0x28bff4    2670580
              ecx            0x902c5562    -1876142750
              edx            0x1    1

            b. 在GDB中,可以使用命令up或down在棧中移動!上下移動棧,查詢變量和內存的值。這個有什么好處呢?

            看看如下的例子就知道了

            test0(a){
                int m = GetNumber();
                test1(b);
            }
            test1(b){
                test3(c);
            }
            

            執行到test3(c)的時候,如果你想看看test0中的變量m的值是多少,怎么辦?這時就可以使用up了,up到test0的棧時就可以直接print m的值了。很方便!

            c. 設置臨時斷點 tbreak

            d. 如果watch變量不好用,可以watch它的地址

            e. return 和jump命令

              return <expr> :return 從函數退出,跳過剩下的語句。

              jump :跳過或重新執行當前函數中的語句。

            f. shared library

            可以顯示哪些DLL已經載入,并且為尚未載入調試信息的DLL載入調試信息

            g. 按下Ctrl + C,只是暫停程序,程序還可以繼續運行。

            h. 注意設置條件斷點有可能會影響執行速度。

            如果需要在某條執行特別頻繁的語句上設置條件斷點,則比較好的方法是在代碼中直接插入源代碼做判斷,這樣速度更快。

            2.  strace

            在進行以下高度時可以考慮使用strace:

            a. 查明哪些文件被打開了

            b. 在OS全程中未捕獲的錯誤或中斷。用strace查找返回的錯誤值,并再次核對源代碼 是否處理了這些值

            c. 調試性能問題,看OS調用的頻率

            d. 查看內存分配、釋放、映射的情況。

            3. gcc

            gcc -E 可以觀察預處理器的輸出。這樣,宏出錯時可以看看為什么。

            4. 設置LD_DEBUGS有點用


            $ export LD_DEBUG=libs
            $ ./a.out
                  1715:    find library=libc.so.6 [0]; searching
                  1715:     search cache=/etc/ld.so.cache
                  1715:      trying file=/lib/i386-linux-gnu/libc.so.6
                  1715:   
                  1715:   
                  1715:    calling init: /lib/i386-linux-gnu/libc.so.6
                  1715:   
                  1715:   
                  1715:    initialize program: ./a.out
                  1715:   
                  1715:   
                  1715:    transferring control: ./a.out
                  1715:   
            hello
                  1715:   
                  1715:    calling fini: ./a.out [0]
                  1715:   
                  1715:   
                  1715:    calling fini: /lib/i386-linux-gnu/libc.so.6 [0]
                  1715:   
            $ export LD_DEBUG=help
            $ ./a.out
            Valid options for the LD_DEBUG environment variable are:

              libs        display library search paths
              reloc       display relocation processing
              files       display progress for input file
              symbols     display symbol table processing
              bindings    display information about symbol binding
              versions    display version dependencies
              all         all previous options combined
              statistics  display relocation statistics
              unused      determined unused DSOs
              help        display this help message and exit

            To direct the debugging output into a file instead of standard output
            a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

            posted on 2011-05-17 21:14 hex108 閱讀(2688) 評論(3)  編輯 收藏 引用 所屬分類: Program

            評論:
            # You?ve got it in one. Cuodln?t have put it better. 2011-05-25 21:10 | Bubber
            You?ve got it in one. Cuodln?t have put it better.  回復  更多評論
              
            # re: gdb,strace那些不常用的功能 2011-05-26 09:48 | hex108
            @Bubber
            They're short,so I put them together.  回復  更多評論
              
            午夜精品久久久久| 亚洲精品国产第一综合99久久| 久久这里都是精品| 热久久国产欧美一区二区精品| 久久综合狠狠综合久久激情 | 99久久精品国产麻豆| 精品国产VA久久久久久久冰| av国内精品久久久久影院| 久久99国产精品久久99| 久久亚洲国产欧洲精品一| 91秦先生久久久久久久| 久久噜噜久久久精品66| 日产久久强奸免费的看| 国内精品综合久久久40p| 久久一日本道色综合久久| 99久久这里只有精品| 狠狠综合久久综合中文88| 伊人 久久 精品| 亚洲AV无码久久精品狠狠爱浪潮| 精品久久人妻av中文字幕| 国产99久久久久久免费看| 青青热久久国产久精品 | 亚洲精品无码久久久久久| 色综合久久无码中文字幕| 狠狠色婷婷综合天天久久丁香 | 人妻少妇久久中文字幕一区二区| 久久A级毛片免费观看| 久久夜色精品国产亚洲| 亚洲欧美日韩精品久久亚洲区| 亚洲国产另类久久久精品黑人 | 久久久综合九色合综国产| 无夜精品久久久久久| 久久发布国产伦子伦精品| 国产精品va久久久久久久| 四虎国产精品成人免费久久| 久久最新精品国产| 久久久SS麻豆欧美国产日韩| 91麻豆精品国产91久久久久久| 亚洲综合日韩久久成人AV| 国产成人久久久精品二区三区| 久久久无码人妻精品无码|