• <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

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

            1. gdb

            a.  .gdbinit

            gdb運(yùn)行時(shí)會首先加載 ~/.gdbinit文件

            例如:我在debug時(shí),每次都需要進(jìn)行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在棧中移動(dòng)!上下移動(dòng)棧,查詢變量和內(nèi)存的值。這個(gè)有什么好處呢?

            看看如下的例子就知道了

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

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

            c. 設(shè)置臨時(shí)斷點(diǎn) tbreak

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

            e. return 和jump命令

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

              jump :跳過或重新執(zhí)行當(dāng)前函數(shù)中的語句。

            f. shared library

            可以顯示哪些DLL已經(jīng)載入,并且為尚未載入調(diào)試信息的DLL載入調(diào)試信息

            g. 按下Ctrl + C,只是暫停程序,程序還可以繼續(xù)運(yùn)行。

            h. 注意設(shè)置條件斷點(diǎn)有可能會影響執(zhí)行速度。

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

            2.  strace

            在進(jìn)行以下高度時(shí)可以考慮使用strace:

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

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

            c. 調(diào)試性能問題,看OS調(diào)用的頻率

            d. 查看內(nèi)存分配、釋放、映射的情況。

            3. gcc

            gcc -E 可以觀察預(yù)處理器的輸出。這樣,宏出錯(cuò)時(shí)可以看看為什么。

            4. 設(shè)置LD_DEBUGS有點(diǎn)用


            $ 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 閱讀(2662) 評論(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.  回復(fù)  更多評論
              
            # re: gdb,strace那些不常用的功能 2011-05-26 09:48 | hex108
            @Bubber
            They're short,so I put them together.  回復(fù)  更多評論
              
            久久精品无码一区二区无码| 国产精品免费看久久久| 免费精品久久久久久中文字幕| 精品久久久久久无码免费| 亚洲人成无码久久电影网站| 久久亚洲AV无码精品色午夜| 日日躁夜夜躁狠狠久久AV| 777久久精品一区二区三区无码| 日本精品久久久久久久久免费| 婷婷伊人久久大香线蕉AV| 99久久精品这里只有精品 | 色综合久久久久久久久五月| 国产成人久久AV免费| 久久中文字幕无码专区 | 国产精品美女久久久久| 精品久久久久久无码中文字幕| 97视频久久久| 久久激情亚洲精品无码?V| 久久无码人妻一区二区三区午夜| 国产综合成人久久大片91| .精品久久久麻豆国产精品| 久久久久人妻一区精品 | 91精品国产综合久久婷婷| 免费精品久久天干天干| 国产毛片久久久久久国产毛片 | 久久久久se色偷偷亚洲精品av| 久久久久久人妻无码| 国产精品中文久久久久久久| 93精91精品国产综合久久香蕉| 久久精品人人槡人妻人人玩AV| 久久精品国产男包| 久久人人超碰精品CAOPOREN| 欧美久久精品一级c片片| 国产V综合V亚洲欧美久久| 久久夜色精品国产欧美乱| 国产69精品久久久久APP下载| 久久福利片| 亚洲精品午夜国产va久久| 久久久不卡国产精品一区二区 | 伊人久久无码中文字幕| 久久只有这精品99|