Rational Purify 使用及分析实例

发表于:2010-11-12 14:50

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

分享:

  在UNIX系统中,使用Purify需要重新编译程序。通常的做法是修改Makefile中的编译器变量。下面是用来编译本文中程序的Makefile:

        CC=purify gcc
all: pplusdemo
pplusdemo: pplusdemo.o
        $(CC) -o pplusdemo pplusdemo.o -lstdc++
pplusdemo.o: pplusdemo.cpp
        $(CC) -g -c -w pplusdemo.cpp
clean:
        -rm pplusdemo pplusdemo.o

  首先运行Purify安装目录下的 purifyplus_setup.sh来设置环境变量,然后运行make重新编译程序。需要指出的是,程序必须编译成调试版本。在gcc中,也就是必须使用"-g"选项。在重新编译的程序运行结束后,Purify会打印出一个分析报告。它的格式和含义与Windows平台大同小异。

  下面是本文中的程序在Linux上Purify运行的结果:

    ****  Purify instrumented ./pplusdemo (pid 30669)  ****
UMR: Uninitialized memory read:
  * This is occurring while in:
 strlen         [rtlib.o]
 std::basic_ostream< char,std::char_traits< char>> & std::operator
 <<<std::char_traits< char>>(std::basic_ostream< char,std::char_traits<
 char>> &, char const *) [libstdc++.so.5]
 main           [pplusdemo.cpp:7]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Reading 1 byte from 0x80b45e0 in the heap.
  * Address 0x80b45e0 is at the beginning of a malloc'd block of 4 bytes.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
****  Purify instrumented ./pplusdemo (pid 30669)  ****
ABW: Array bounds write:
  * This is occurring while in:
 strcpy         [rtlib.o]
 main           [pplusdemo.cpp:8]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Writing 5 bytes to 0x80b45e0 in the heap (1 byte at 0x80b45e4 illegal).
  * Address 0x80b45e0 is at the beginning of a malloc'd block of 4 bytes.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
****  Purify instrumented ./pplusdemo (pid 30669)  ****
ABR: Array bounds read:
  * This is occurring while in:
 strlen         [rtlib.o]
 std::basic_ostream< char,std::char_traits< char>> & std::operator
 <<<std::char_traits< char>>(std::basic_ostream< char,std::char_traits<
 char>> &, char const *) [libstdc++.so.5]
 main           [pplusdemo.cpp:9]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Reading 5 bytes from 0x80b45e0 in the heap (1 byte at 0x80b45e4 illegal).
  * Address 0x80b45e0 is at the beginning of a malloc'd block of 4 bytes.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
****  Purify instrumented ./pplusdemo (pid 30669)  ****
FMM: Freeing mismatched memory:
  * This is occurring while in:
 operator delete( void *) [rtlib.o]
 main           [pplusdemo.cpp:10]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Attempting to free block at 0x80b45e0 in the heap.
  * Address 0x80b45e0 is at the beginning of a malloc'd block of 4 bytes.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * This block of memory was obtained using an allocation routine which is
    not compatible with the routine by which it is being freed.
****  Purify instrumented ./pplusdemo (pid 30669)  ****
FMR: Free memory read:
  * This is occurring while in:
 main           [pplusdemo.cpp:11]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Reading 1 byte from 0x80b45e0 in the heap.
  * Address 0x80b45e0 is at the beginning of a freed block of 4 bytes.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * There have been 0 frees since this block was freed from:
 free           [rtlib.o]
 _ZdLpV         [libstdc++.so.5]
 main           [pplusdemo.cpp:10]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
****  Purify instrumented ./pplusdemo (pid 30669)  ****
FMW: Free memory write:
  * This is occurring while in:
 main           [pplusdemo.cpp:11]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Writing 1 byte to 0x80b45e0 in the heap.
  * Address 0x80b45e0 is at the beginning of a freed block of 4 bytes.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * There have been 0 frees since this block was freed from:
 free           [rtlib.o]
 _ZdLpV         [libstdc++.so.5]
 main           [pplusdemo.cpp:10]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
****  Purify instrumented ./pplusdemo (pid 30669)  ****
FUM: Freeing unallocated memory:
  * This is occurring while in:
 free           [rtlib.o]
 _ZdLpV         [libstdc++.so.5]
 main           [pplusdemo.cpp:12]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * Attempting to free block at 0x80b45e0 already freed.
  * This block was allocated from:
 malloc         [rtlib.o]
 operator new( unsigned) [libstdc++.so.5]
 operator new []( unsigned) [libstdc++.so.5]
 main           [pplusdemo.cpp:5]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
  * There have been 1 frees since this block was freed from:
 free           [rtlib.o]
 _ZdLpV         [libstdc++.so.5]
 main           [pplusdemo.cpp:10]
 __libc_start_main [libc.so.6]
 _start         [crt1.o]
****  Purify instrumented ./pplusdemo (pid 30669)  ****
Current file descriptors in use: 5
FIU: file descriptor 0: <stdin>
FIU: file descriptor 1: <stdout>
FIU: file descriptor 2: <stderr>
FIU: file descriptor 26: <reserved for Purify internal use>
FIU: file descriptor 27: <reserved for Purify internal use>
****  Purify instrumented ./pplusdemo (pid 30669)  ****
Purify: Searching for all memory leaks...
Memory leaked: 0 bytes (0%); potentially leaked: 0 bytes (0%)
Purify Heap Analysis (combining suppressed and unsuppressed blocks)
                         Blocks        Bytes
              Leaked          0            0
  Potentially Leaked          0            0
              In-Use          0            0
  ----------------------------------------
     Total Allocated          0            0
****  Purify instrumented ./pplusdemo (pid 30669)  ****
  * Program exited with status code 0.
  * 7 access errors, 7 total occurrences.
  * 0 bytes leaked.
  * 0 bytes potentially leaked.
  * Basic memory usage (including Purify overhead):
    290012 code
    152928 data/bss
    6816 heap (peak use)
    7800 stack

43/4<1234>
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号