GDB调试内存泄露(CentOS7 实战记录)

首先感谢《一种定位内存泄露的方法(Linux)》这片文章。基本思路是一致的。
本文追加了对于后续内存如何查看对象数据的方法。

先POST一下原来第三方文章,主要关注其思想理念:


目的:
本文是《一种定位内存泄露的方法(Solaris)》对应的Linux版本,调试器使用gdb。主要介绍实例部分。其他请见《一种定位内存泄露的方法(Solaris)》。

模拟new失败的程序:

#include 
class ABC
{
public:
        virtual ~ABC(){}
        int i;
        int j;
};

void f()
{
        for (int i = 0; i < 1000; ++i)
        {
                ABC* p = new ABC;
        }
        throw std::bad_alloc();
}

int main()
{
        f();
        return 0;
}

1) 编译运行此段代码。产生一个core文件
2) 用gdb打开这个core文件:

gdb a.out core
(gdb) run
Starting program: /test/new_fail/a.out
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Program received signal SIGABRT, Aborted.
0x00007ffff733f645 in raise () from /lib64/libc.so.6
(gdb) info proc
process 10683
cmdline = '/test/new_fail/a.out'
cwd = '/test/new_fail'
exe = '/test/new_fail/a.out'
(gdb) shell pmap 10683
10683: a.out
START               SIZE     RSS     PSS   DIRTY    SWAP PERM MAPPING
0000000000400000      4K      4K      4K      0K      0K r-xp /test/new_fail/a.out
0000000000600000      4K      4K      4K      4K      0K r--p /test/new_fail/a.out
0000000000601000      4K      4K      4K      4K      0K rw-p /test/new_fail/a.out
0000000000602000    132K     32K     32K     32K      0K rw-p [heap]
…(略)
Total:            11468K   1048K    684K    180K      0K

360K writable-private, 11108K readonly-private, 0K shared, and 1048K referenced

可以看到heap空间的起始地址是0x0000000000602000,共132K字节,即132*1024=135168字节。
3) 因为是64位应用程序,所以指针占8字节。所以需要遍历的指针个数为135168/8=16896。
4) 将结果输出到日志文件gdb.txt中:

(gdb) set height 0
(gdb) set logging on
Copying output to gdb.txt.
(gdb) x/16896a 0x0000000000602000

gdb.txt的内容:

0x602000:       0x0     0x21
0x602010:       0x400b30 <_ZTV3ABC+16>  0x0
0x602020:       0x0     0x21
0x602030:       0x400b30 <_ZTV3ABC+16>  0x0
….

5) 过滤gdb.txt:

awk '{print $2"/n"$3}' gdb.txt|C++filt|grep vtable>gdb_vtable.txt

gdb_vtable.txt的内容为:

for ABC+16>
for ABC+16>
for ABC+16>
for ABC+16>

6) 将gdb_vtable.txt的内容导入到SQLServer中(如果记录不多,可以用Excel代替)。表名为gdb_vtable,第一列Col001为符号。对其分组求和:

select Col001, count(1) quantity from gdb_vtable
group by Col001
order by quantity desc

结果为:

Col001                                                                                    quantity
for ABC+16>                                                              1000
for std::bad_alloc@@GLIBCXX_3.4+16>          

可知core里有1000个ABC,遍历使用ABC的代码,可知存在泄漏。


参考上述的文章,我们进行实战排查并记录全过程。

[root@mcu_rrs sips]# ps faxu
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         2  0.0  0.0      0     0 ?        S    314   0:00 [kthreadd]
……
root      3592 11.8 25.3 9110048 2009168 ?     Sl   314 179:33  \_ ./H323Gateway -x -c -i ../etc/H323Gateway.conf -m s.cgw.10.35.10.53 -n s.h323gw.10.35.10.53 -b tcp://127.0.0.1:10882
……

可以看到H323Gateway进程RSS巨大,明显存在内存泄漏

[root@mcu_rrs sips]# pmap 3592
3592:   ./H323Gateway -x -c -i ../etc/H323Gateway.conf -m s.cgw.10.35.10.53 -n s.h323gw.10.35.10.53 -b tcp://127.0.0.1:10882
0000000000400000   1380K r-x-- H323Gateway
0000000000759000      4K r---- H323Gateway
000000000075a000     12K rw--- H323Gateway
000000000075d000     16K rw---   [ anon ]
0000000002148000   2604K rw---   [ anon ]
00007f6eac000000  54268K rw---   [ anon ]
00007f6eaf4ff000  11268K -----   [ anon ]
00007f6eb4000000  65536K rw---   [ anon ]
00007f6ebc000000  65536K rw---   [ anon ]
00007f6ec4000000  65536K rw---   [ anon ]
00007f6ecc000000  65536K rw---   [ anon ]
00007f6ed4000000  65536K rw---   [ anon ]
00007f6edc000000  65536K rw---   [ anon ]
00007f6ee4000000  65536K rw---   [ anon ]
00007f6eec000000  65536K rw---   [ anon ]
00007f6ef4000000  65536K rw---   [ anon ]
00007f6efc000000  65536K rw---   [ anon ]
00007f6f04000000  65536K rw---   [ anon ]
00007f6f0c000000  65536K rw---   [ anon ]
00007f6f14000000  65536K rw---   [ anon ]
00007f6f1c000000  65536K rw---   [ anon ]
00007f6f24000000  65536K rw---   [ anon ]
00007f6f2c000000  65536K rw---   [ anon ]
00007f6f34000000  65536K rw---   [ anon ]
00007f6f3c000000  65536K rw---   [ anon ]
00007f6f44000000  65536K rw---   [ anon ]
00007f6f4c000000  65536K rw---   [ anon ]
00007f6f54000000  65536K rw---   [ anon ]
00007f6f5c000000  65536K rw---   [ anon ]
00007f6f64000000  65536K rw---   [ anon ]
00007f6f6c000000  65536K rw---   [ anon ]
00007f6f74000000  65536K rw---   [ anon ]
00007f6f7c000000  65536K rw---   [ anon ]
00007f6f84000000  65536K rw---   [ anon ] <---- 本次以此条为查看样本
00007f6f8c000000  65536K rw---   [ anon ]
00007f6f94000000  65536K rw---   [ anon ]
00007f6f9c000000  65536K rw---   [ anon ]
00007f6fa4000000  65536K rw---   [ anon ]
00007f6fac000000  65536K rw---   [ anon ]
00007f6fb4000000  65536K rw---   [ anon ]
00007f6fbc000000  65536K rw---   [ anon ]
00007f6fc4000000  65536K rw---   [ anon ]
00007f6fcc000000  65536K rw---   [ anon ]
00007f6fd4000000  65536K rw---   [ anon ]
00007f6fdc000000  65536K rw---   [ anon ]
00007f6fe4000000  65536K rw---   [ anon ]
00007f6fec000000  65536K rw---   [ anon ]
00007f6ff4000000  65536K rw---   [ anon ]
00007f6ffc000000  65536K rw---   [ anon ]
00007f7004000000  65536K rw---   [ anon ]
00007f700c000000  65536K rw---   [ anon ]
00007f7014000000  65536K rw---   [ anon ]
00007f701c000000  65536K rw---   [ anon ]
00007f7024000000  65536K rw---   [ anon ]
00007f702c000000  65536K rw---   [ anon ]
00007f7034000000  65536K rw---   [ anon ]
00007f703c000000  65536K rw---   [ anon ]
00007f7044000000  65536K rw---   [ anon ]
00007f704c000000  65536K rw---   [ anon ]
00007f7054000000  65536K rw---   [ anon ]
00007f705c000000  65536K rw---   [ anon ]
00007f7064000000  65536K rw---   [ anon ]
00007f706c000000  65536K rw---   [ anon ]
00007f7074000000  65536K rw---   [ anon ]
00007f707c000000  65536K rw---   [ anon ]
00007f7084000000  65536K rw---   [ anon ]
00007f708c000000  65536K rw---   [ anon ]
00007f7094000000  65536K rw---   [ anon ]
00007f709c000000  65536K rw---   [ anon ]
00007f70a4000000  65536K rw---   [ anon ]
00007f70ac000000  65536K rw---   [ anon ]
00007f70b4000000  65536K rw---   [ anon ]
00007f70bc000000  65536K rw---   [ anon ]
00007f70c4000000  65536K rw---   [ anon ]
00007f70cc000000  65536K rw---   [ anon ]
00007f70d4000000  65536K rw---   [ anon ]
00007f70dc000000  65536K rw---   [ anon ]
00007f70e4000000  65536K rw---   [ anon ]
00007f70ec000000  65536K rw---   [ anon ]
00007f70f4000000  65536K rw---   [ anon ]
00007f70fc000000  65536K rw---   [ anon ]
00007f7104000000    132K rw---   [ anon ]
00007f7104021000  65404K -----   [ anon ]
00007f710c000000    304K rw---   [ anon ]
00007f710c04c000  65232K -----   [ anon ]
00007f7110000000    132K rw---   [ anon ]
00007f7110021000  65404K -----   [ anon ]
00007f7114000000    132K rw---   [ anon ]
00007f7114021000  65404K -----   [ anon ]
00007f7118000000    132K rw---   [ anon ]
00007f7118021000  65404K -----   [ anon ]
00007f711c000000    152K rw---   [ anon ]
00007f711c026000  65384K -----   [ anon ]
00007f7120000000    132K rw---   [ anon ]
00007f7120021000  65404K -----   [ anon ]
00007f7124000000    352K rw---   [ anon ]
00007f7124058000  65184K -----   [ anon ]
00007f7128000000   5836K rw---   [ anon ]
00007f71285b3000  59700K -----   [ anon ]
00007f712c000000  11280K rw---   [ anon ]
00007f712cb04000  54256K -----   [ anon ]
00007f7130000000    132K rw---   [ anon ]
00007f7130021000  65404K -----   [ anon ]
00007f7134000000    132K rw---   [ anon ]
00007f7134021000  65404K -----   [ anon ]
00007f7138000000    132K rw---   [ anon ]
00007f7138021000  65404K -----   [ anon ]
00007f713c000000    132K rw---   [ anon ]
00007f713c021000  65404K -----   [ anon ]
00007f7140000000    312K rw---   [ anon ]
00007f714004e000  65224K -----   [ anon ]
00007f7144000000    296K rw---   [ anon ]
00007f714404a000  65240K -----   [ anon ]
00007f7148000000    132K rw---   [ anon ]
00007f7148021000  65404K -----   [ anon ]
00007f714c000000    372K rw---   [ anon ]
00007f714c05d000  65164K -----   [ anon ]
00007f7150000000   5836K rw---   [ anon ]
00007f71505b3000  59700K -----   [ anon ]
00007f7154000000  11196K rw---   [ anon ]
00007f7154aef000  54340K -----   [ anon ]
00007f7158000000    152K rw---   [ anon ]
00007f7158026000  65384K -----   [ anon ]
00007f715c000000    276K rw---   [ anon ]
00007f715c045000  65260K -----   [ anon ]
00007f7160000000    132K rw---   [ anon ]
00007f7160021000  65404K -----   [ anon ]
00007f7164000000   5836K rw---   [ anon ]
00007f71645b3000  59700K -----   [ anon ]
00007f7168000000    132K rw---   [ anon ]
00007f7168021000  65404K -----   [ anon ]
00007f716c000000  11276K rw---   [ anon ]
00007f716cb03000  54260K -----   [ anon ]
00007f7170000000    132K rw---   [ anon ]
00007f7170021000  65404K -----   [ anon ]
00007f7174000000  65536K rw---   [ anon ]
00007f7178000000    372K rw---   [ anon ]
00007f717805d000  65164K -----   [ anon ]
00007f717c000000  65536K rw---   [ anon ]
00007f7180000000    292K rw---   [ anon ]
00007f7180049000  65244K -----   [ anon ]
00007f7184000000    132K rw---   [ anon ]
00007f7184021000  65404K -----   [ anon ]
00007f7188000000    312K rw---   [ anon ]
00007f718804e000  65224K -----   [ anon ]
00007f718c000000    132K rw---   [ anon ]
00007f718c021000  65404K -----   [ anon ]
00007f7190000000    308K rw---   [ anon ]
00007f719004d000  65228K -----   [ anon ]
00007f7194000000    132K rw---   [ anon ]
00007f7194021000  65404K -----   [ anon ]
00007f7198000000    132K rw---   [ anon ]
00007f7198021000  65404K -----   [ anon ]
00007f719c000000    132K rw---   [ anon ]
00007f719c021000  65404K -----   [ anon ]
00007f71a0000000    132K rw---   [ anon ]
00007f71a0021000  65404K -----   [ anon ]
00007f71a4000000    692K rw---   [ anon ]
00007f71a40ad000  64844K -----   [ anon ]
00007f71a8000000    352K rw---   [ anon ]
00007f71a8058000  65184K -----   [ anon ]
00007f71ae582000      4K -----   [ anon ]
00007f71ae583000   2048K rw---   [ anon ]
00007f71ae783000      4K -----   [ anon ]
00007f71ae784000   2048K rw---   [ anon ]
00007f71ae984000      4K -----   [ anon ]
00007f71ae985000    256K rw---   [ anon ]
00007f71ae9c5000      4K -----   [ anon ]
00007f71ae9c6000   1024K rw---   [ anon ]
00007f71aeac6000      4K -----   [ anon ]
00007f71aeac7000    256K rw---   [ anon ]
00007f71aeb07000      4K -----   [ anon ]
00007f71aeb08000    256K rw---   [ anon ]
00007f71aeb48000      4K -----   [ anon ]
00007f71aeb49000    256K rw---   [ anon ]
00007f71aeb89000      4K -----   [ anon ]
00007f71aeb8a000    256K rw---   [ anon ]
00007f71aebca000      4K -----   [ anon ]
00007f71aebcb000    256K rw---   [ anon ]
00007f71aec7e000      4K -----   [ anon ]
00007f71aec7f000    256K rw---   [ anon ]
00007f71aecbf000      4K -----   [ anon ]
00007f71aecc0000   1024K rw---   [ anon ]
00007f71aedc0000      4K -----   [ anon ]
00007f71aedc1000    256K rw---   [ anon ]
00007f71aee01000      4K -----   [ anon ]
00007f71aee02000   2048K rw---   [ anon ]
00007f71af003000      4K -----   [ anon ]
00007f71af004000    256K rw---   [ anon ]
00007f71af044000      4K -----   [ anon ]
00007f71af045000    256K rw---   [ anon ]
00007f71af085000      4K -----   [ anon ]
00007f71af086000    256K rw---   [ anon ]
00007f71af0c6000      4K -----   [ anon ]
00007f71af0c7000    256K rw---   [ anon ]
00007f71af107000      4K -----   [ anon ]
00007f71af108000    256K rw---   [ anon ]
00007f71af148000      4K -----   [ anon ]
00007f71af149000    256K rw---   [ anon ]
00007f71af189000      4K -----   [ anon ]
00007f71af18a000    256K rw---   [ anon ]
00007f71af1ca000      4K -----   [ anon ]
00007f71af1cb000   1024K rw---   [ anon ]
00007f71af2cb000      4K -----   [ anon ]
00007f71af2cc000   2048K rw---   [ anon ]
00007f71af4cc000      4K -----   [ anon ]
00007f71af4cd000   2048K rw---   [ anon ]
00007f71af6cd000      4K -----   [ anon ]
00007f71af6ce000   2048K rw---   [ anon ]
00007f71af8fd000      4K -----   [ anon ]
00007f71af8fe000    256K rw---   [ anon ]
00007f71af93e000      4K -----   [ anon ]
00007f71af93f000    256K rw---   [ anon ]
00007f71af97f000      4K -----   [ anon ]
00007f71af980000    256K rw---   [ anon ]
00007f71af9c0000      4K -----   [ anon ]
00007f71af9c1000    256K rw---   [ anon ]
00007f71afa01000      4K -----   [ anon ]
00007f71afa02000    256K rw---   [ anon ]
00007f71afa42000      4K -----   [ anon ]
00007f71afa43000    256K rw---   [ anon ]
00007f71afa83000      4K -----   [ anon ]
00007f71afa84000    256K rw---   [ anon ]
00007f71afac4000      4K -----   [ anon ]
00007f71afac5000    256K rw---   [ anon ]
00007f71afb05000      4K -----   [ anon ]
00007f71afb06000    256K rw---   [ anon ]
00007f71afb46000      4K -----   [ anon ]
00007f71afb47000    256K rw---   [ anon ]
00007f71afb87000      4K -----   [ anon ]
00007f71afb88000    256K rw---   [ anon ]
00007f71afbc8000      4K -----   [ anon ]
00007f71afbc9000    256K rw---   [ anon ]
00007f71afdff000      4K -----   [ anon ]
00007f71afe00000   2048K rw---   [ anon ]
00007f71b0000000    132K rw---   [ anon ]
00007f71b0021000  65404K -----   [ anon ]
00007f71b4000000    156K rw---   [ anon ]
00007f71b4027000  65380K -----   [ anon ]
00007f71b8000000    136K rw---   [ anon ]
00007f71b8022000  65400K -----   [ anon ]
00007f71bc000000   6036K rw---   [ anon ]
00007f71bc5e5000  59500K -----   [ anon ]
00007f71c0000000    132K rw---   [ anon ]
00007f71c0021000  65404K -----   [ anon ]
00007f71c4000000    132K rw---   [ anon ]
00007f71c4021000  65404K -----   [ anon ]
00007f71c8000000    132K rw---   [ anon ]
00007f71c8021000  65404K -----   [ anon ]
00007f71cc000000    132K rw---   [ anon ]
00007f71cc021000  65404K -----   [ anon ]
00007f71d0000000    132K rw---   [ anon ]
00007f71d0021000  65404K -----   [ anon ]
00007f71d4000000  58612K rw---   [ anon ]
00007f71d793d000   6924K -----   [ anon ]
00007f71d8000000  65536K rw---   [ anon ]
00007f71dc000000    132K rw---   [ anon ]
00007f71dc021000  65404K -----   [ anon ]
00007f71e0000000    132K rw---   [ anon ]
00007f71e0021000  65404K -----   [ anon ]
00007f71e4000000    132K rw---   [ anon ]
00007f71e4021000  65404K -----   [ anon ]
00007f71e8000000    132K rw---   [ anon ]
00007f71e8021000  65404K -----   [ anon ]
00007f71ec000000    132K rw---   [ anon ]
00007f71ec021000  65404K -----   [ anon ]
00007f71f0000000    132K rw---   [ anon ]
00007f71f0021000  65404K -----   [ anon ]
00007f71f4000000    132K rw---   [ anon ]
00007f71f4021000  65404K -----   [ anon ]
00007f71f8000000    132K rw---   [ anon ]
00007f71f8021000  65404K -----   [ anon ]
00007f71fc00c000      4K -----   [ anon ]
00007f71fc00d000    256K rw---   [ anon ]
00007f71fc04d000      4K -----   [ anon ]
00007f71fc04e000    256K rw---   [ anon ]
00007f71fc08e000      4K -----   [ anon ]
00007f71fc08f000   1024K rw---   [ anon ]
00007f71fc18f000      4K -----   [ anon ]
00007f71fc190000   2048K rw---   [ anon ]
00007f71fca5b000      4K -----   [ anon ]
00007f71fca5c000   2048K rw---   [ anon ]
00007f71fce52000      4K -----   [ anon ]
00007f71fce53000    256K rw---   [ anon ]
00007f71fce93000      4K -----   [ anon ]
00007f71fce94000    256K rw---   [ anon ]
00007f71fcf0b000      4K -----   [ anon ]
00007f71fcf0c000    256K rw---   [ anon ]
00007f71fcf4c000      4K -----   [ anon ]
00007f71fcf4d000    256K rw---   [ anon ]
00007f71fcf8d000      4K -----   [ anon ]
00007f71fcf8e000    256K rw---   [ anon ]
00007f71fcfce000      4K -----   [ anon ]
00007f71fcfcf000    256K rw---   [ anon ]
00007f71fd00f000      4K -----   [ anon ]
00007f71fd010000   1024K rw---   [ anon ]
00007f71fd110000      4K -----   [ anon ]
00007f71fd111000   1024K rw---   [ anon ]
00007f71fd211000      4K -----   [ anon ]
00007f71fd212000   1024K rw---   [ anon ]
00007f71fd312000      4K -----   [ anon ]
00007f71fd313000   1024K rw---   [ anon ]
00007f71fd413000      4K -----   [ anon ]
00007f71fd414000   1024K rw---   [ anon ]
00007f71fd514000      4K -----   [ anon ]
00007f71fd515000   1024K rw---   [ anon ]
00007f71fd615000      4K -----   [ anon ]
00007f71fd616000    256K rw---   [ anon ]
00007f71fd656000      4K -----   [ anon ]
00007f71fd657000    256K rw---   [ anon ]
00007f71fd697000     68K r-x-- h263-1998_video_pwplugin.so
00007f71fd6a8000   2044K ----- h263-1998_video_pwplugin.so
00007f71fd8a7000      4K r---- h263-1998_video_pwplugin.so
00007f71fd8a8000      4K rw--- h263-1998_video_pwplugin.so
00007f71fd8a9000     48K r-x-- libnss_files-2.17.so
00007f71fd8b5000   2044K ----- libnss_files-2.17.so
00007f71fdab4000      4K r---- libnss_files-2.17.so
00007f71fdab5000      4K rw--- libnss_files-2.17.so
00007f71fdab6000     24K rw---   [ anon ]
00007f71fdabc000      8K r-x-- libXau.so.6.0.0
00007f71fdabe000   2048K ----- libXau.so.6.0.0
00007f71fdcbe000      4K r---- libXau.so.6.0.0
00007f71fdcbf000      4K rw--- libXau.so.6.0.0
00007f71fdcc0000    144K r-x-- liblzma.so.5.0.99
00007f71fdce4000   2044K ----- liblzma.so.5.0.99
00007f71fdee3000      4K r---- liblzma.so.5.0.99
00007f71fdee4000      4K rw--- liblzma.so.5.0.99
00007f71fdee5000    384K r-x-- libpcre.so.1.2.0
00007f71fdf45000   2044K ----- libpcre.so.1.2.0
00007f71fe144000      4K r---- libpcre.so.1.2.0
00007f71fe145000      4K rw--- libpcre.so.1.2.0
00007f71fe146000     32K r-x-- libpciaccess.so.0.11.1
00007f71fe14e000   2048K ----- libpciaccess.so.0.11.1
00007f71fe34e000      4K r---- libpciaccess.so.0.11.1
00007f71fe34f000      4K rw--- libpciaccess.so.0.11.1
00007f71fe350000    156K r-x-- libxcb.so.1.1.0
00007f71fe377000   2044K ----- libxcb.so.1.1.0
00007f71fe576000      4K r---- libxcb.so.1.1.0
00007f71fe577000      4K rw--- libxcb.so.1.1.0
00007f71fe578000    132K r-x-- libselinux.so.1
00007f71fe599000   2048K ----- libselinux.so.1
00007f71fe799000      4K r---- libselinux.so.1
00007f71fe79a000      4K rw--- libselinux.so.1
00007f71fe79b000      8K rw---   [ anon ]
00007f71fe79d000      8K r-x-- libfreebl3.so
00007f71fe79f000   2044K ----- libfreebl3.so
00007f71fe99e000      4K r---- libfreebl3.so
00007f71fe99f000      4K rw--- libfreebl3.so
00007f71fe9a0000    136K r-x-- libdrm_intel.so.1.0.0
00007f71fe9c2000   2048K ----- libdrm_intel.so.1.0.0
00007f71febc2000      4K r---- libdrm_intel.so.1.0.0
00007f71febc3000      4K rw--- libdrm_intel.so.1.0.0
00007f71febc4000     20K r-x-- libXfixes.so.3.1.0
00007f71febc9000   2044K ----- libXfixes.so.3.1.0
00007f71fedc8000      4K r---- libXfixes.so.3.1.0
00007f71fedc9000      4K rw--- libXfixes.so.3.1.0
00007f71fedca000     68K r-x-- libXext.so.6.4.0
00007f71feddb000   2044K ----- libXext.so.6.4.0
00007f71fefda000      4K r---- libXext.so.6.4.0
00007f71fefdb000      4K rw--- libXext.so.6.4.0
00007f71fefdc000   1248K r-x-- libX11.so.6.3.0
00007f71ff114000   2048K ----- libX11.so.6.3.0
00007f71ff314000      4K r---- libX11.so.6.3.0
00007f71ff315000     20K rw--- libX11.so.6.3.0
00007f71ff31a000     56K r-x-- libdrm.so.2.4.0
00007f71ff328000   2044K ----- libdrm.so.2.4.0
00007f71ff527000      4K r---- libdrm.so.2.4.0
00007f71ff528000      4K rw--- libdrm.so.2.4.0
00007f71ff529000     12K r-x-- libkeyutils.so.1.5
00007f71ff52c000   2044K ----- libkeyutils.so.1.5
00007f71ff72b000      4K r---- libkeyutils.so.1.5
00007f71ff72c000      4K rw--- libkeyutils.so.1.5
00007f71ff72d000     52K r-x-- libkrb5support.so.0.1
00007f71ff73a000   2044K ----- libkrb5support.so.0.1
00007f71ff939000      4K r---- libkrb5support.so.0.1
00007f71ff93a000      4K rw--- libkrb5support.so.0.1
00007f71ff93b000     32K r-x-- libcrypt-2.17.so
00007f71ff943000   2044K ----- libcrypt-2.17.so
00007f71ffb42000      4K r---- libcrypt-2.17.so
00007f71ffb43000      4K rw--- libcrypt-2.17.so
00007f71ffb44000    184K rw---   [ anon ]
00007f71ffb72000    696K r-x-- libfdk-aac.so.1.0.0
00007f71ffc20000   2044K ----- libfdk-aac.so.1.0.0
00007f71ffe1f000      8K r---- libfdk-aac.so.1.0.0
00007f71ffe21000      4K rw--- libfdk-aac.so.1.0.0
00007f71ffe22000      8K rw---   [ anon ]
00007f71ffe24000   1136K r-x-- libx264.so.142
00007f71fff40000   2044K ----- libx264.so.142
00007f720013f000      4K r---- libx264.so.142
00007f7200140000      4K rw--- libx264.so.142
00007f7200141000    492K rw---   [ anon ]
00007f72001bc000   3640K r-x-- libx265.so.68
00007f720054a000   2044K ----- libx265.so.68
00007f7200749000      8K r---- libx265.so.68
00007f720074b000      4K rw--- libx265.so.68
00007f720074c000     20K rw---   [ anon ]
00007f7200751000    312K r-x-- libavutil.so.55.9.100
00007f720079f000   2048K ----- libavutil.so.55.9.100
00007f720099f000     64K r---- libavutil.so.55.9.100
00007f72009af000      4K rw--- libavutil.so.55.9.100
00007f72009b0000     80K rw---   [ anon ]
00007f72009c4000     96K r-x-- libswresample.so.2.0.101
00007f72009dc000   2048K ----- libswresample.so.2.0.101
00007f7200bdc000      8K r---- libswresample.so.2.0.101
00007f7200bde000      4K rw--- libswresample.so.2.0.101
00007f7200bdf000   1704K r-x-- i965_drv_video.so
00007f7200d89000   2044K ----- i965_drv_video.so
00007f7200f88000      4K r---- i965_drv_video.so
00007f7200f89000     16K rw--- i965_drv_video.so
00007f7200f8d000     16K r-x-- libva-x11.so.1.3800.0
00007f7200f91000   2044K ----- libva-x11.so.1.3800.0
00007f7201190000      4K r---- libva-x11.so.1.3800.0
00007f7201191000      4K rw--- libva-x11.so.1.3800.0
00007f7201192000   1828K r-x-- libavformat.so.57.19.100
00007f720135b000   2048K ----- libavformat.so.57.19.100
00007f720155b000     76K r---- libavformat.so.57.19.100
00007f720156e000     88K rw--- libavformat.so.57.19.100
00007f7201584000      8K r-x-- libva-drm.so.1.3800.0
00007f7201586000   2044K ----- libva-drm.so.1.3800.0
00007f7201785000      4K r---- libva-drm.so.1.3800.0
00007f7201786000      4K rw--- libva-drm.so.1.3800.0
00007f7201787000    108K r-x-- libva.so.1.3800.0
00007f72017a2000   2044K ----- libva.so.1.3800.0
00007f72019a1000      4K r---- libva.so.1.3800.0
00007f72019a2000      4K rw--- libva.so.1.3800.0
00007f72019a3000     84K r-x-- libz.so.1.2.7
00007f72019b8000   2044K ----- libz.so.1.2.7
00007f7201bb7000      4K r---- libz.so.1.2.7
00007f7201bb8000      4K rw--- libz.so.1.2.7
00007f7201bb9000     12K r-x-- libcom_err.so.2.1
00007f7201bbc000   2044K ----- libcom_err.so.2.1
00007f7201dbb000      4K r---- libcom_err.so.2.1
00007f7201dbc000      4K rw--- libcom_err.so.2.1
00007f7201dbd000    196K r-x-- libk5crypto.so.3.1
00007f7201dee000   2044K ----- libk5crypto.so.3.1
00007f7201fed000      8K r---- libk5crypto.so.3.1
00007f7201fef000      4K rw--- libk5crypto.so.3.1
00007f7201ff0000    864K r-x-- libkrb5.so.3.3
00007f72020c8000   2044K ----- libkrb5.so.3.3
00007f72022c7000     56K r---- libkrb5.so.3.3
00007f72022d5000     12K rw--- libkrb5.so.3.3
00007f72022d8000    296K r-x-- libgssapi_krb5.so.2.2
00007f7202322000   2048K ----- libgssapi_krb5.so.2.2
00007f7202522000      4K r---- libgssapi_krb5.so.2.2
00007f7202523000      8K rw--- libgssapi_krb5.so.2.2
00007f7202525000    228K r-x-- libnspr4.so
00007f720255e000   2048K ----- libnspr4.so
00007f720275e000      4K r---- libnspr4.so
00007f720275f000      8K rw--- libnspr4.so
00007f7202761000      8K rw---   [ anon ]
00007f7202763000     16K r-x-- libplc4.so
00007f7202767000   2044K ----- libplc4.so
00007f7202966000      4K r---- libplc4.so
00007f7202967000      4K rw--- libplc4.so
00007f7202968000     12K r-x-- libplds4.so
00007f720296b000   2044K ----- libplds4.so
00007f7202b6a000      4K r---- libplds4.so
00007f7202b6b000      4K rw--- libplds4.so
00007f7202b6c000    148K r-x-- libnssutil3.so
00007f7202b91000   2048K ----- libnssutil3.so
00007f7202d91000     24K r---- libnssutil3.so
00007f7202d97000      4K rw--- libnssutil3.so
00007f7202d98000   1144K r-x-- libnss3.so
00007f7202eb6000   2044K ----- libnss3.so
00007f72030b5000     20K r---- libnss3.so
00007f72030ba000      8K rw--- libnss3.so
00007f72030bc000      8K rw---   [ anon ]
00007f72030be000    144K r-x-- libsmime3.so
00007f72030e2000   2044K ----- libsmime3.so
00007f72032e1000     12K r---- libsmime3.so
00007f72032e4000      4K rw--- libsmime3.so
00007f72032e5000    244K r-x-- libssl3.so
00007f7203322000   2048K ----- libssl3.so
00007f7203522000     12K r---- libssl3.so
00007f7203525000      4K rw--- libssl3.so
00007f7203526000      4K rw---   [ anon ]
00007f7203527000    160K r-x-- libssh2.so.1.0.1
00007f720354f000   2048K ----- libssh2.so.1.0.1
00007f720374f000      4K r---- libssh2.so.1.0.1
00007f7203750000      4K rw--- libssh2.so.1.0.1
00007f7203751000    200K r-x-- libidn.so.11.6.11
00007f7203783000   2044K ----- libidn.so.11.6.11
00007f7203982000      4K r---- libidn.so.11.6.11
00007f7203983000      4K rw--- libidn.so.11.6.11
00007f7203984000     88K r-x-- libresolv-2.17.so
00007f720399a000   2048K ----- libresolv-2.17.so
00007f7203b9a000      4K r---- libresolv-2.17.so
00007f7203b9b000      4K rw--- libresolv-2.17.so
00007f7203b9c000      8K rw---   [ anon ]
00007f7203b9e000    156K r-x-- libexpat.so.1.6.0
00007f7203bc5000   2048K ----- libexpat.so.1.6.0
00007f7203dc5000      8K r---- libexpat.so.1.6.0
00007f7203dc7000      4K rw--- libexpat.so.1.6.0
00007f7203dc8000   2256K r-x-- libcrypto.so.1.0.2k
00007f7203ffc000   2048K ----- libcrypto.so.1.0.2k
00007f72041fc000    112K r---- libcrypto.so.1.0.2k
00007f7204218000     52K rw--- libcrypto.so.1.0.2k
00007f7204225000     16K rw---   [ anon ]
00007f7204229000    412K r-x-- libssl.so.1.0.2k
00007f7204290000   2048K ----- libssl.so.1.0.2k
00007f7204490000     16K r---- libssl.so.1.0.2k
00007f7204494000     28K rw--- libssl.so.1.0.2k
00007f720449b000    344K r-x-- libldap_r-2.4.so.2.10.3
00007f72044f1000   2048K ----- libldap_r-2.4.so.2.10.3
00007f72046f1000     12K r---- libldap_r-2.4.so.2.10.3
00007f72046f4000      4K rw--- libldap_r-2.4.so.2.10.3
00007f72046f5000      8K rw---   [ anon ]
00007f72046f7000     56K r-x-- liblber-2.4.so.2.10.3
00007f7204705000   2044K ----- liblber-2.4.so.2.10.3
00007f7204904000      4K r---- liblber-2.4.so.2.10.3
00007f7204905000      4K rw--- liblber-2.4.so.2.10.3
00007f7204906000    320K r-x-- libldap-2.4.so.2.10.3
00007f7204956000   2044K ----- libldap-2.4.so.2.10.3
00007f7204b55000     12K r---- libldap-2.4.so.2.10.3
00007f7204b58000      4K rw--- libldap-2.4.so.2.10.3
00007f7204b59000    112K r-x-- libsasl2.so.3.0.0
00007f7204b75000   2044K ----- libsasl2.so.3.0.0
00007f7204d74000      4K r---- libsasl2.so.3.0.0
00007f7204d75000      4K rw--- libsasl2.so.3.0.0
00007f7204d76000     28K r-x-- librt-2.17.so
00007f7204d7d000   2044K ----- librt-2.17.so
00007f7204f7c000      4K r---- librt-2.17.so
00007f7204f7d000      4K rw--- librt-2.17.so
00007f7204f7e000     32K r-x-- libG7221Enc.so
00007f7204f86000   2044K ----- libG7221Enc.so
00007f7205185000     24K rw--- libG7221Enc.so
00007f720518b000     48K rw---   [ anon ]
00007f7205197000     28K r-x-- libG7221Dec.so
00007f720519e000   2044K ----- libG7221Dec.so
00007f720539d000     20K rw--- libG7221Dec.so
00007f72053a2000     48K rw---   [ anon ]
00007f72053ae000    116K r-x-- libG722Enc.so
00007f72053cb000   2048K ----- libG722Enc.so
00007f72055cb000      4K rw--- libG722Enc.so
00007f72055cc000   1136K rw---   [ anon ]
00007f72056e8000    136K r-x-- libG722Dec.so
00007f720570a000   2044K ----- libG722Dec.so
00007f7205909000      8K rw--- libG722Dec.so
00007f720590b000   1132K rw---   [ anon ]
00007f7205a26000    284K r-x-- libopus.so.0.5.2
00007f7205a6d000   2048K ----- libopus.so.0.5.2
00007f7205c6d000      4K r---- libopus.so.0.5.2
00007f7205c6e000      4K rw--- libopus.so.0.5.2
00007f7205c6f000    496K r-x-- libswscale.so.4.0.100
00007f7205ceb000   2048K ----- libswscale.so.4.0.100
00007f7205eeb000      4K r---- libswscale.so.4.0.100
00007f7205eec000      4K rw--- libswscale.so.4.0.100
00007f7205eed000     32K rw---   [ anon ]
00007f7205ef5000  10796K r-x-- libavcodec.so.57.16.100
00007f7206980000   2048K ----- libavcodec.so.57.16.100
00007f7206b80000    156K r---- libavcodec.so.57.16.100
00007f7206ba7000    136K rw--- libavcodec.so.57.16.100
00007f7206bc9000   6672K rw---   [ anon ]
00007f720724d000   1748K r-x-- libDynamicCodec.so.1.85770
00007f7207402000   2048K ----- libDynamicCodec.so.1.85770
00007f7207602000     20K r---- libDynamicCodec.so.1.85770
00007f7207607000     40K rw--- libDynamicCodec.so.1.85770
00007f7207611000      4K rw---   [ anon ]
00007f7207612000      8K r-x-- libdl-2.17.so
00007f7207614000   2048K ----- libdl-2.17.so
00007f7207814000      4K r---- libdl-2.17.so
00007f7207815000      4K rw--- libdl-2.17.so
00007f7207816000     92K r-x-- libpthread-2.17.so
00007f720782d000   2044K ----- libpthread-2.17.so
00007f7207a2c000      4K r---- libpthread-2.17.so
00007f7207a2d000      4K rw--- libpthread-2.17.so
00007f7207a2e000     16K rw---   [ anon ]
00007f7207a32000   1760K r-x-- libc-2.17.so
00007f7207bea000   2048K ----- libc-2.17.so
00007f7207dea000     16K r---- libc-2.17.so
00007f7207dee000      8K rw--- libc-2.17.so
00007f7207df0000     20K rw---   [ anon ]
00007f7207df5000     84K r-x-- libgcc_s-4.8.5-20150702.so.1
00007f7207e0a000   2044K ----- libgcc_s-4.8.5-20150702.so.1
00007f7208009000      4K r---- libgcc_s-4.8.5-20150702.so.1
00007f720800a000      4K rw--- libgcc_s-4.8.5-20150702.so.1
00007f720800b000   1028K r-x-- libm-2.17.so
00007f720810c000   2044K ----- libm-2.17.so
00007f720830b000      4K r---- libm-2.17.so
00007f720830c000      4K rw--- libm-2.17.so
00007f720830d000    932K r-x-- libstdc++.so.6.0.19
00007f72083f6000   2048K ----- libstdc++.so.6.0.19
00007f72085f6000     32K r---- libstdc++.so.6.0.19
00007f72085fe000      8K rw--- libstdc++.so.6.0.19
00007f7208600000     84K rw---   [ anon ]
00007f7208615000    708K r-x-- libsqlite3.so.0.8.6
00007f72086c6000   2044K ----- libsqlite3.so.0.8.6
00007f72088c5000      8K r---- libsqlite3.so.0.8.6
00007f72088c7000     12K rw--- libsqlite3.so.0.8.6
00007f72088ca000    400K r-x-- libcurl.so.4.3.0
00007f720892e000   2048K ----- libcurl.so.4.3.0
00007f7208b2e000      8K r---- libcurl.so.4.3.0
00007f7208b30000      4K rw--- libcurl.so.4.3.0
00007f7208b31000      4K rw---   [ anon ]
00007f7208b32000    304K r-x-- libzmq.so.4
00007f7208b7e000   2044K ----- libzmq.so.4
00007f7208d7d000     16K r---- libzmq.so.4
00007f7208d81000      4K rw--- libzmq.so.4
00007f7208d82000   9316K r-x-- libh323_x86_64_.so.1.26.5
00007f720969b000   2048K ----- libh323_x86_64_.so.1.26.5
00007f720989b000    596K r---- libh323_x86_64_.so.1.26.5
00007f7209930000     72K rw--- libh323_x86_64_.so.1.26.5
00007f7209942000     24K rw---   [ anon ]
00007f7209948000   4056K r-x-- libpt.so.2.12.8
00007f7209d3e000   2048K ----- libpt.so.2.12.8
00007f7209f3e000    332K r---- libpt.so.2.12.8
00007f7209f91000     48K rw--- libpt.so.2.12.8
00007f7209f9d000     32K rw---   [ anon ]
00007f7209fa5000    252K r-x-- libjson.so
00007f7209fe4000   2048K ----- libjson.so
00007f720a1e4000      4K r---- libjson.so
00007f720a1e5000      8K rw--- libjson.so
00007f720a1e7000    296K r-x-- libDynamicCodecForGW.so
00007f720a231000   2044K ----- libDynamicCodecForGW.so
00007f720a430000      8K r---- libDynamicCodecForGW.so
00007f720a432000     16K rw--- libDynamicCodecForGW.so
00007f720a436000   1872K r-x-- libraknet.so
00007f720a60a000   2048K ----- libraknet.so
00007f720a80a000     16K r---- libraknet.so
00007f720a80e000     36K rw--- libraknet.so
00007f720a817000     52K rw---   [ anon ]
00007f720a824000   1372K r-x-- libRakNetForC.so.1.79956
00007f720a97b000   2044K ----- libRakNetForC.so.1.79956
00007f720ab7a000     16K r---- libRakNetForC.so.1.79956
00007f720ab7e000     28K rw--- libRakNetForC.so.1.79956
00007f720ab85000      8K rw---   [ anon ]
00007f720ab87000    132K r-x-- ld-2.17.so
00007f720abad000      4K -----   [ anon ]
00007f720abae000    256K rw---   [ anon ]
00007f720abee000      4K -----   [ anon ]
00007f720abef000    256K rw---   [ anon ]
00007f720ac2f000      4K -----   [ anon ]
00007f720ac30000    256K rw---   [ anon ]
00007f720ac70000      4K -----   [ anon ]
00007f720ac71000    256K rw---   [ anon ]
00007f720acb1000      4K -----   [ anon ]
00007f720acb2000    256K rw---   [ anon ]
00007f720acf2000      4K -----   [ anon ]
00007f720acf3000    256K rw---   [ anon ]
00007f720ad33000      4K -----   [ anon ]
00007f720ad34000    388K rw---   [ anon ]
00007f720ada4000     16K rw---   [ anon ]
00007f720ada8000      4K r---- ld-2.17.so
00007f720ada9000      4K rw--- ld-2.17.so
00007f720adaa000      4K rw---   [ anon ]
00007ffcc492a000    132K rw---   [ stack ]
00007ffcc49cb000      8K r-x--   [ anon ]
ffffffffff600000      4K r-x--   [ anon ]
 total          9110048K

出现大量的[anon]的堆信息。一般这些属于主程序的堆。

随意选一个看起来很大的堆进行调试

(gdb) x/16896a 0x00007f6f84000000
……
出现了很多,我们节选一段
……
0x7f6f84020ce0: 0xa2c65736c610000   0x75df80 <_ZTV7PString+16>  <---我们选择查看了此PString
0x7f6f84020cf0: 0x5373692200000000  0x7f6f84020d30
0x7f6f84020d00: 0x7274203a00000001  0x7f6f84020d50
0x7f6f84020d10: 0x920202001 0x3a2022656d010100
0x7f6f84020d20: 0x200a223031332220  0x25
0x7f6f84020d30: 0x10000000a 0x7f71d8000001
0x7f6f84020d40: 0x0 0x25
0x7f6f84020d50: 0x2e302e302e373231  0x7f71d8000031
0x7f6f84020d60: 0x0 0x25
0x7f6f84020d70: 0x100000004 0x7f71d8000001
0x7f6f84020d80: 0x0 0x25
0x7f6f84020d90: 0x393231    0x7f71d8000000
0x7f6f84020da0: 0x0 0x95
0x7f6f84020db0: 0x1312d8100000001   0x75df80 <_ZTV7PString+16>
0x7f6f84020dc0: 0x0 0x7f6f84020d70
0x7f6f84020dd0: 0x64656c6c00000001  0x7f6f84020d90
0x7f6f84020de0: 0x3200a2c01 0x120202000
---Type <return> to continue, or q <return> to quit---
0x7f6f84020df0: 0x6172656d61430000  0x75df80 <_ZTV7PString+16>
0x7f6f84020e00: 0x20200a2c00000000  0x7f6f84020e40
0x7f6f84020e10: 0x7369447300000001  0x7f6f84020e60
0x7f6f84020e20: 0x9203a2001 0x2020202020010100
0x7f6f84020e30: 0x6922202020202020  0x25
0x7f6f84020e40: 0x10000000a 0x7f71d8000001
0x7f6f84020e50: 0x0 0x25
0x7f6f84020e60: 0x2e302e302e373231  0x7f71d8000031
0x7f6f84020e70: 0x0 0x25
0x7f6f84020e80: 0x100000004 0x7f71d8000001
0x7f6f84020e90: 0x0 0x25
0x7f6f84020ea0: 0x383231    0x7f71d8000000
0x7f6f84020eb0: 0x0 0x95
0x7f6f84020ec0: 0x1312d8000000001   0x75df80 <_ZTV7PString+16>
0x7f6f84020ed0: 0x0 0x7f6f84020e80
0x7f6f84020ee0: 0x7053736900000001  0x7f6f84020ea0
0x7f6f84020ef0: 0x33a202201 0x1200a2c00
0x7f6f84020f00: 0x2220202020200000  0x75df80 <_ZTV7PString+16>
0x7f6f84020f10: 0x20200a2200000000  0x7f6f84020f50
0x7f6f84020f20: 0x2020202000000001  0x7f6f84020f70
0x7f6f84020f30: 0x920202001 0x3a2022726c010100
0x7f6f84020f40: 0x200a2c6575727420  0x25
0x7f6f84020f50: 0x10000000a 0x7f71d8000001
0x7f6f84020f60: 0x0 0x25
0x7f6f84020f70: 0x2e302e302e373231  0x7f71d8000031
0x7f6f84020f80: 0x0 0x25
0x7f6f84020f90: 0x100000004 0x7f71d8000001
0x7f6f84020fa0: 0x0 0x25
0x7f6f84020fb0: 0x373231    0x7f71d8000000
0x7f6f84020fc0: 0x0 0x95
0x7f6f84020fd0: 0x1312d7f00000001   0x75df80 <_ZTV7PString+16> <---我们选择查看了此PString
0x7f6f84020fe0: 0x0 0x7f6f84020f90
0x7f6f84020ff0: 0x2020200a00000001  0x7f6f84020fb0
(gdb) p *((PString*) 0x7f6f84020fd8)
$2 = {<PCharArray> = {<PBaseArray<char>> = {<PAbstractArray> = {<PContainer> = {<PObject> = {_vptr.PObject = 0x75df80 <vtable for PString+16>, m_traceContextIdentifier = 0}, reference = 0x7f6f84020f90}, elementSize = 1, 
        theArray = 0x7f6f84020fb0 "127", allocatedDynamically = true}, <No data fields>}, <No data fields>}, m_length = 3}
(gdb) p *((PString*) 0x7f6f84020ce8)
$3 = {<PCharArray> = {<PBaseArray<char>> = {<PAbstractArray> = {<PContainer> = {<PObject> = {_vptr.PObject = 0x75df80 <vtable for PString+16>, m_traceContextIdentifier = 0}, reference = 0x7f6f84020d30}, elementSize = 1, 
        theArray = 0x7f6f84020d50 "127.0.0.1", allocatedDynamically = true}, <No data fields>}, <No data fields>}, m_length = 9}

可以明显看到,存在大量的PString类泄露。由于我们是8进制一组,且指针出现在了右侧,所以我们应当在左侧地址偏移8,得到PString类的指针地址。打印发现里面存在着这些信息。可以多尝试几组打印值。接着就可以结合业务,猜测出来是那块代码发生了泄露。

你可能感兴趣的:(调试技巧)