通过在 conf.h 文件中使用以下设置构建 dmalloc lib
#define HAVE_VPRINTF 0
#define HAVE_SNPRINTF 0
#define HAVE_VSNPRINTF 0
并在链接后运行我的代码,日志文件内容具有未格式化的地址信息到函数名称和行号。
Unformatted log o/p is given below.
Venkatesh:~/Dmalloc/dmalloc-5.5.2$ cat logfile
%ld: %lu: Dmalloc version '%s' from '%s'
%ld: %lu: flags = %#x, logfile '%s'
%ld: %lu: interval = %lu, addr = %#lx, seen # = %ld, limit = %ld
%ld: %lu: starting time = %s
%ld: %lu: process pid = %ld
%ld: %lu: error details: %s
%ld: %lu: pointer '%#lx' from '%s' prev access '%s'
%ld: %lu: dump of proper fence-top bytes: '%.*s'
%ld: %lu: dump of '%#lx'%+d: '%.*s'
%ld: %lu: next pointer '%#lx' (size %u) may have run under from '%s'
%ld: %lu: ERROR: %s: %s (err %d)
If I define HAVE_VSNPRINTF to 1, then I log file has only dmalloc log header, no information about errors as given below.
Venkatesh:~/Dmalloc/dmalloc-5.5.2$ cat logfile
1450864250: 5: Dmalloc version '5.5.2' from 'http://dmalloc.com/'
1450864250: 11: flags = 0x4f4e503, logfile 'logfile'
1450864250: 17: interval = 100, addr = 0, seen # = 0, limit = 0
1450864250: 25: starting time = 1450864250
1450864250: 31: process pid = 10270
我的测试代码如下。
#include <stdio.h>
#include <stdlib.h>
#ifdef DMALLOC
#include "dmalloc.h"
#endif
int main ()
{
char *p;
p = malloc (50);
p[51] = 'c'; //Writing character beyond allocated range
return 0;
}
我使用的 Dmalloc optins 是:DMALLOC_OPTIONS=debug=0x4f4ed03,inter=100,log=logfile