淘宝商城(天猫)高级技术专家.3年研发+3年性能测试调优/系统测试+4年团队管理与测试架构、研发系统实践. 新舞台新气象, 深化测试基础架构及研发架构,希望能在某个技术领域成为真正的技术大牛。欢迎荐才http://bbs.51testing.com/viewthread.php?tid=120496&extra=&page=1 .邮件: jianzhao.liangjz@alibaba-inc.com,MSN:liangjianzhao@163.com.微博:http://t.sina.com.cn/1674816524

内存调试库-ElectricFence

上一篇 / 下一篇  2009-12-14 20:13:49 / 个人分类:搜索引擎测试技巧

参考 http://mylxiaoyi.javaeye.com/blog/383918

 

原理

 采用Linux的虚拟内存机制来保护mallocfree所使用的内存,这个哨兵页在越界读写时直接core dump

 

试验环境

 

[liangjz@b2b_plat_1367 ~]$ uname -a

Linux b2b_plat_13672.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux

[liangjz@b2b_plat_1367 ~]$ gcc -v

4.2.0

 

下载:

http://perens.com/FreeSoftware/ElectricFence/

 

安装部署

 

make &&make   install 。 安装过程的waring可以暂不理会。

 

试验过程

 

[liangjz@b2b_plat_1367 ~]$ cat efence.c

 

#include <stdio.h>

#include <stdlib.h>

int main()

{

char *ptr = (char *) malloc(1024);

ptr[0] = 0;

/* Now write beyond the block */

ptr[1024] = 0;

exit(0);

}

 

确认可以打开core dump.

 [liangjz@b2b_plat_1367 ~]$ ulimit -a

core file size         (blocks, -c) unlimited

 

[liangjz@b2b_plat_1367 ~]$ gcc -g  -o efence efence.c -lefence  -lpthread

/usr/lib/libefence.a(page.o)(.text+0x29): In function `stringErrorReport':

/home/liangjz/electric-fence-2.1.13/page.c:46: warning: `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead

/usr/lib/libefence.a(page.o)(.text+0x19):/home/liangjz/electric-fence-2.1.13/page.c:45: warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead

[liangjz@b2b_plat_1367 ~]$ ./efence

 

 Electric Fence 2.1 Copyright (C) 1987-1998 Bruce Perens.

δíÎó(core dumped)

[liangjz@b2b_plat_1367 ~]$ gdb efence core.4

core.4588 core.4594 core.4606 core.4618 

[liangjz@b2b_plat_1367 ~]$ gdb efence core.4618

GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)

 

Core was generated by `./efence'.

Program terminated with signal 11, Segmentation fault.

Readingsymbols from /lib/libcwait.so...done.

Loaded symbols for /lib/libcwait.so

Readingsymbols from /lib/i686/libpthread.so.0...done.

Loaded symbols for /lib/i686/libpthread.so.0

Readingsymbols from /lib/i686/libc.so.6...done.

Loaded symbols for /lib/i686/libc.so.6

Readingsymbols from /lib/ld-linux.so.2...done.

Loaded symbols for /lib/ld-linux.so.2

#0 0x080488d2 inmain () at efence.c:9

9                        ptr[1024] = 0;


TAG: ElectricFence Linux linux 内存 

 

评分:0

我来说两句

Open Toolbar