教你用gdb工具检查内存泄露


注: set heap-check scramble on 可以不设置,要是设置了易出现程序运行不起来。

PTosa(scd1)> gdb chefers
HP gdb 5.4.0 for HP Itanium (32 or 64 bit) and target HP-UX 11.2x.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 5.4.0 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.
..
(gdb) set heap-check leaks on
(gdb) set heap-check free on
(gdb) set heap-check bounds on
(gdb) set heap-check scramble on
(gdb) b amob_chkAbnormal.cpp:180
Breakpoint 1 at 0x405a3c0:2: file /data/users/cc2000/optes/chefers/amob_chkAbnormal.cpp, line 180 from /data/users/osa/bin/chefers.
(gdb) run ots1 scada psbob
Starting program: /data/users/osa/bin/chefers ots1 scada psbob
warning: Load module /oracle/app/oracle/product/9.2/lib32/libclntsh.so.9.0 has been stripped.
Debugging information is not available.

warning: Load module /oracle/app/oracle/product/9.2/lib32/libwtc9.so has been stripped.
Debugging information is not available.

warning: Load module /oracle/app/oracle/product/9.2/lib32/libclntsh.so.9.0 has been stripped.
Debugging information is not available.

warning: Load module /oracle/app/oracle/product/9.2/lib32/libwtc9.so has been stripped.
Debugging information is not available.

input = POINT_SIMULATE positon is 10

Breakpoint 1, chkErrors::verifyRuningState (this=0x40024d50,
eqID=0x40ca97b0 "djbCB251", eqType=0x40426e0 "cb",
stID=0x7fffe410 "DongJinBian")
at /data/users/cc2000/optes/chefers/amob_chkAbnormal.cpp:180
180 ret=m_EqStatus->getEqStatus(stID, eqID,eqType);//cold
(gdb) c 1
Will stop next time breakpoint 1 is reached. Continuing.
--------------CreateCBTree begin and eq_id is djbCB251
------------------------UtilRtdb:getStByNd
--------------CreateCBTree begin and eq_id is djbDIS2513
------------------------UtilRtdb:getStByNd
------------------------UtilRtdb:getStByNd
--------------CreateCBTree begin and eq_id is djbDIS2512
------------------------UtilRtdb:getStByNd
--------------CreateCBTree begin and eq_id is djbDIS2511
------------------------UtilRtdb:getStByNd
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) v_djbDIS2513@N(0)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) djbDIS2516a(0)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) djbPT251(-1)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) LNhuijin1L(1)
djbCB251(1) djbCB251@N(0) djbDIS2516b(0)
djbCB251(1) djbCB251@Z(0) djbDIS2512(0) djb220BUSⅡ@B(0) djb220BUSⅡ(1)
djbCB251(1) djbCB251@Z(0) djbDIS2511(0) djb220BUSⅢ@B(0) djb220BUSⅢ(1)
djbCB251(1) djbCB251@Z(0) djbDIS2516c(0)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) v_djbDIS2513@N(0)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) djbDIS2516a(0)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDI

S2513@N(0) djbPT251(-1)
djbCB251(1) djbCB251@N(0) djbDIS2513(1) djbDIS2513@N(0) LNhuijin1L(1)
djbCB251(1) djbCB251@N(0) djbDIS2516b(0)
djbCB251(1) djbCB251@Z(0) djbDIS2512(0) djb220BUSⅡ@B(0) djb220BUSⅡ(1)
djbCB251(1) djbCB251@Z(0) djbDIS2511(0) djb220BUSⅢ@B(0) djb220BUSⅢ(1)
djbCB251(1) djbCB251@Z(0) djbDIS2516c(0)

Breakpoint 1, chkErrors::verifyRuningState (this=0x40024d50,
eqID=0x40ca9b60 "djbCB252", eqType=0x40426e0 "cb",
stID=0x7fffe410 "DongJinBian")
at /data/users/cc2000/optes/chefers/amob_chkAbnormal.cpp:180
180 ret=m_EqStatus->getEqStatus(stID, eqID,eqType);//cold
(gdb) info leaks
Scanning for memory leaks...


857 bytes leaked in 23 blocks

No. Total bytes Blocks Address Function
0 276 3 0x40d5fa10 eqStatus::createGNDCB(treeNode**,char*,char*)
1 184 2 0x40d5f980 eqStatus::createGNDCB(treeNode**,char*,char*)
2 75 3 0x400251d0 operator new(unsigned long)
3 63 3 0x40025110 operator new(unsigned long)
4 50 2 0x400250d0 operator new(unsigned long)
5 42 2 0x40025050 operator new(unsigned long)
6 42 2 0x40025190 operator new(unsigned long)
7 42 2 0x40025150 operator new(unsigned long)
8 21 1 0x40025090 operator new(unsigned long)
9 21 1 0x40025010 operator new(unsigned long)
10 21 1 0x40024e90 operator new(unsigned long)
11 20 1 0x40024e10 operator new(unsigned long)
(gdb) info leak 4
50 bytes leaked in 2 blocks (5.83% of all bytes leaked)
These range in size from 25 to 25 bytes and are allocated
#0 operator new(unsigned long) from /usr/lib/hpux32/libCsup.so.1
#1 eqStatus::node_push(char*) at optes_eqStatus.cpp:1167
#2 eqStatus::createCBTree(treeNode**,char*,char*,EQ_TYPE) at optes_eqStatus.cpp:5438
#3 eqStatus::createBinaryTree(treeNode**,char*,EQ_TYPE) at optes_eqStatus.cpp:5358
(gdb) info leak 0
276 bytes leaked in 3 blocks (32.21% of all bytes leaked)
These range in size from 92 to 92 bytes and are allocated
#0 eqStatus::createGNDCB(treeNode**,char*,char*) at optes_eqStatus.cpp:5727
#1 eqStatus::createCBTree(treeNode**,char*,char*,EQ_TYPE) at optes_eqStatus.cpp:5453
#2 eqStatus::createCBTree(treeNode**,char*,char*,EQ_TYPE) at optes_eqStatus.cpp:5515
#3 eqStatus::createBinaryTree(treeNode**,char*,EQ_TYPE) at optes_eqStatus.cpp:5358
(gdb) info leak 3
63 bytes leaked in 3 blocks (7.35% of all bytes leaked)
These range in size from 21 to 21 bytes and are allocated
#0 operator new(unsigned long) from /usr/lib/hpux32/libCsup.so.1
#1 eqStatus::eq_id_push(char*) at optes_eqStatus.cpp:1144
#2 eqStatus::createCBTree(treeNode**,char*,char*,EQ_TYPE) at optes_eqStatus.cpp:5406
#

3 eqStatus::createCBTree(treeNode**,char*,char*,EQ_TYPE) at optes_eqStatus.cpp:5515
(gdb) quit
The program is running. Exit anyway? (y or n) y


======================================
(gdb) help set heap-check
Set heap-check { on/off |

: Instruct GDB to stop whenever a block at the
---Type to continue, or q to quit---
given address gets allocated or deallocated.

null-check : Instructs malloc to return null after
invocations of malloc
null-check random : Instructs malloc to return null after a random
number of invocations of malloc
null-check-size : Instructs malloc to return null after
bytes have been allocated by malloc
seed-value : Specifies the seed value to be used for
generating random null-check-count
random-range : Specifies the random range to be used by random
range
interval : Specifies the time interval to be used for
incremental memory profile
repeat : Perform incremental profile for
interval periods where each period duration
is defined by set heap-check interval command.
The default value is 100.
reset : Discard the heap interv

al data from the
internal data file.
Simply typing `set heap-check on' uses the following defaults :
leak check on, bounds check on, free check on, scrambling on

相关文档
最新文档