您可以在gdb中加载程序并使用
命令
[root@localhost ~]#
[root@localhost ~]# mtrace ./a.out mtrace.log
Memory not freed:
-----------------
Address Size Caller
0x08de3378 0x4 at 0x42028da
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# gdb ./a.out
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /root/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x80484fd: file test.cpp, line 6.
Temporary breakpoint 1, main () at test.cpp:6
6 mtrace();
(gdb) info symbol 0x42028da
operator new(unsigned int) + 42 in section .text of /usr/lib/libstdc++.so.6
(gdb)
此外,您可能需要启动程序,直到主过程开始,才能从共享库中加载所有符号。在上面的例子中,调用者是
新操作员
它位于libstdc++.so.6中。