• <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>
            Valgrind 是在linux系統(tǒng)下開發(fā)應(yīng)用程序時(shí)用于調(diào)試內(nèi)存問題的工具。它尤其擅長(zhǎng)發(fā)現(xiàn)內(nèi)存管理的問題,它可以檢查程序運(yùn)行時(shí)的內(nèi)存泄漏問題。

               它的官方網(wǎng)址是 http://www.valgrind.org/

               下載最新版本的Valgrind,目前是3.2.0。 wget http://www.valgrind.org/downloads/valkyrie-1.2.0.tar.bz2

               執(zhí)行常規(guī)的安裝步驟:./confgure && make && make install。注意: 系統(tǒng)必須安裝QT的開發(fā)包。即便這樣在make 時(shí)還是出現(xiàn)qplatformdefs.h這個(gè)文件找不到的情況,導(dǎo)致make失敗。查找系統(tǒng)中的qplatformdefs.h 之后,發(fā)現(xiàn)沒有存在于qt的標(biāo)準(zhǔn)頭文件目錄/usr/lib/qt-3.3/include。如是將/usr/lib/qt-3.3/mkspecs/linux-g++/ 目錄下該頭文件復(fù)制標(biāo)準(zhǔn)頭文件目錄,重新make ,后面一切OK。

            初次使用
                編譯如下代碼:  gcc -Wall example.c -g -o example 

            #include <stdlib.h>
                        void f(void)
                        {
                        int* x = malloc(10 * sizeof(int));
                        x[10] = 0;        // problem 1: heap block overrun
                        }                    // problem 2: memory leak -- x not freed
                        int main(void)
                        {
                        f();
                        return 0;
                        }

                 注意:gcc 的-g 選項(xiàng)讓Valgrind調(diào)試輸出時(shí)指出相應(yīng)信息的代碼所在的行號(hào)。

             
            valgrind --tool=memcheck --leak-check=yes ./example

            ==6742== Memcheck, a memory error detector for x86-linux.
            ==6742== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
            ==6742== Using valgrind-2.2.0, a program supervision framework for x86-linux.
            ==6742== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
            ==6742== For more details, rerun with: -v
            ==6742==
            ==6742== Invalid write of size 4
            ==6742==    at 0x8048384: f (example.c:6)
            ==6742==    by 0x80483AC: main (example.c:12)
            ==6742==  Address 0x1B908050 is 0 bytes after a block of size 40 alloc'd
            ==6742==    at 0x1B904984: malloc (vg_replace_malloc.c:131)
            ==6742==    by 0x8048377: f (example.c:5)
            ==6742==    by 0x80483AC: main (example.c:12)
            ==6742==
            ==6742== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 1)
            ==6742== malloc/free: in use at exit: 40 bytes in 1 blocks.
            ==6742== malloc/free: 1 allocs, 0 frees, 40 bytes allocated.
            ==6742== For counts of detected errors, rerun with: -v
            ==6742== searching for pointers to 1 not-freed blocks.
            ==6742== checked 1360800 bytes.
            ==6742==
            ==6742==
            ==6742== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
            ==6742==    at 0x1B904984: malloc (vg_replace_malloc.c:131)
            ==6742==    by 0x8048377: f (example.c:5)
            ==6742==    by 0x80483AC: main (example.c:12)
            ==6742==
            ==6742== LEAK SUMMARY:
            ==6742==    definitely lost: 40 bytes in 1 blocks.
            ==6742==    possibly lost:   0 bytes in 0 blocks.
            ==6742==    still reachable: 0 bytes in 0 blocks.
            ==6742==         suppressed: 0 bytes in 0 blocks.
            ==6742== Reachable blocks (those to which a pointer was found) are not shown.
            ==6742== To see them, rerun with: --show-reachable=yes

               上面的C程序存在兩個(gè)錯(cuò)誤:1. 數(shù)組下標(biāo)越界;2. 分配的內(nèi)存沒有釋放,存在內(nèi)存泄露的問題。對(duì)于錯(cuò)誤1,看Valgrind的調(diào)試信息片斷
            ==6742== Invalid write of size 4
            ==6742==    at 0x8048384: f (example.c:6)
            ==6742==    by 0x80483AC: main (example.c:12)
            ==6742==  Address 0x1B908050 is 0 bytes after a block of size 40 alloc'd
            ==6742==    at 0x1B904984: malloc (vg_replace_malloc.c:131)
            ==6742==    by 0x8048377: f (example.c:5)

            對(duì)于錯(cuò)誤2,看這個(gè)

            ==6742== malloc/free: 1 allocs, 0 frees, 40 bytes allocated.

            ......

            ==6742== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
            ==6742==    at 0x1B904984: malloc (vg_replace_malloc.c:131)
            ==6742==    by 0x8048377: f (example.c:5)
            ==6742==    by 0x80483AC: main (example.c:12)

            欧美亚洲另类久久综合| 精品国产综合区久久久久久| 久久e热在这里只有国产中文精品99| 中文字幕亚洲综合久久| 久久久中文字幕日本| 久久亚洲国产成人精品性色| 久久久久99精品成人片牛牛影视| 狠狠色综合网站久久久久久久高清| 国产精品久久久久…| 久久91精品国产91久| 91精品国产91久久久久久青草| 四虎国产精品免费久久| 国产一区二区精品久久凹凸| 精品国产乱码久久久久软件| 久久久久国产精品| 久久久一本精品99久久精品88| 理论片午午伦夜理片久久 | 久久精品国产国产精品四凭| 久久99精品久久久大学生| 99久久精品这里只有精品 | 亚洲va久久久噜噜噜久久狠狠| 亚洲精品成人网久久久久久| 国产午夜福利精品久久| 国产精品久久久久9999| 久久精品免费一区二区| 久久无码一区二区三区少妇| 精品综合久久久久久97超人 | WWW婷婷AV久久久影片| 久久久久99精品成人片试看 | 久久一区二区免费播放| 久久99热国产这有精品| 精品久久久久久中文字幕人妻最新| 久久精品一区二区三区AV| 欧美精品国产综合久久| 亚洲Av无码国产情品久久| 久久亚洲av无码精品浪潮| 精品久久久无码中文字幕天天| 久久精品国产亚洲沈樵| 人人狠狠综合久久亚洲88| 狠狠狠色丁香婷婷综合久久俺| 国产午夜免费高清久久影院|