使用mtrace来调试程序有4个基本的步骤,需要用到GNU C 函数库里面的一些辅助的函数功能。
1. 在需要跟踪的程序中需要包含头文件
2. 定义一个环境变量,用来指示一个文件。该文件用来输出log信息。如下的例子:
$export MALLOC_TRACE=mymemory.log
3. 正常运行程序。此时程序中的关于内存分配和释放的操作都可以记录下来。
4. 然后用mtrace使用工具来分析log文件。例如:
$mtrace testmem $MALLOC_TRACE
下面我们看一个例子:
[hwang@langchao test]$ cat testmtrace.c
#include
#include
#include
int main()
{
char *hello;
mtrace();
hello = (char*) malloc(20);
sprintf(hello,"\nhello world!");
return 1;
}
[hwang@langchao test]$export MALLOC_TRACE=mytrace.log
[hwang@langchao test]$ gcc testmtrace.c -o testmtrace
[hwang@langchao test]$./testmtrace
[hwang@langchao test]$ mtrace testmtrace mytrace.log
Memory not freed:
-----------------
Address Size Caller
0x08049860 0x14 at /usr/src/build/53700-i386/BUILD/glibc-2.2.4/csu/init.c:0
59.25.9.* 于 2007-07-19 06:02:29发表:
http://www.ringtones-dir.net/get/ ringtones site. Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. From website .
59.25.9.* 于 2007-07-19 06:02:21发表:
http://www.ringtones-dir.net/get/ ringtones site. ringtones download: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. samsung ringtones From website .
194.88.214.* 于 2007-07-19 06:02:17发表:
http://www.ringtones-dir.net/download/ download ringtones. nokia ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-dir.net/free/ [link=http://www.ringtones-dir.net]ring tones[/link] From site .
194.88.214.* 于 2007-07-19 06:01:46发表:
http://www.ringtones-dir.net/download/ download ringtones. nokia ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-dir.net/free/ [link=http://www.ringtones-dir.net]ring tones[/link] From site .
194.88.214.* 于 2007-07-19 06:00:39发表:
http://www.ringtones-dir.net/download/ download ringtones. nokia ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-dir.net/free/ [link=http://www.ringtones-dir.net]ring tones[/link] From site .