当我在我的C++程序中使用mtrace时,我会得到以下输出:
未释放的内存:
Address Size Caller
0x0804a3c8 0x4 at 0x400b159f
我如何知道0x400b159f在代码中的位置?
当我在我的C++程序中使用mtrace时,我会得到以下输出:
Address Size Caller
0x0804a3c8 0x4 at 0x400b159f
我如何知道0x400b159f在代码中的位置?
[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 <http://gnu.org/licenses/gpl.html>
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:
<http://www.gnu.org/software/gdb/bugs/>...
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中的operator new。
#include <mcheck.h>
mtrace();
-g
进行编译。mcheck.h
只在 Linux 上使用吗? - Land