没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
有undefined reference to puts, 所以看起来得用-shared
gcc dg.c -c -o dg
ld dg -o dg.so.1 -soname dg.so.1 -shared
export LD_PRELOAD=$PWD/dg.so.1
#include "stdio.h"
void _init(void)
{
printf("welcome\n");
}
void _fini(void)
{
printf("byebye\n");
}
the above can get the preloaded library working properly. very cool, next let me try the mtrace function.
export MALLOC_TRACE=$PWD/mem.txt
need to include "mcheck.h" file
mtrace();
for (int i=50; i<5000; i+=50)
{
p=malloc(i);
memset((void*)p,0,i);
gcc dg.c -c -o dg
ld dg -o dg.so.1 -soname dg.so.1 -shared
export LD_PRELOAD=$PWD/dg.so.1
#include "stdio.h"
void _init(void)
{
printf("welcome\n");
}
void _fini(void)
{
printf("byebye\n");
}
the above can get the preloaded library working properly. very cool, next let me try the mtrace function.
export MALLOC_TRACE=$PWD/mem.txt
need to include "mcheck.h" file
mtrace();
for (int i=50; i<5000; i+=50)
{
p=malloc(i);
memset((void*)p,0,i);
free(p);
}
for (int i=1000; i<5000; i+=1000)
{
p=malloc(i);
memset((void*)p,0,i);
}
muntrace();
this works fine and correctly. the result is like the following:
= Start
@ ./callit:[0x804855c] + 0x84fd378 0x32
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd3b0 0x64
@ ./callit:[0x8048588] - 0x84fd3b0
@ ./callit:[0x804855c] + 0x84fd378 0x96
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0xc8
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0xfa
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x12c
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x15e
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x190
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x1c2
}
for (int i=1000; i<5000; i+=1000)
{
p=malloc(i);
memset((void*)p,0,i);
}
muntrace();
this works fine and correctly. the result is like the following:
= Start
@ ./callit:[0x804855c] + 0x84fd378 0x32
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd3b0 0x64
@ ./callit:[0x8048588] - 0x84fd3b0
@ ./callit:[0x804855c] + 0x84fd378 0x96
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0xc8
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0xfa
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x12c
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x15e
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x190
@ ./callit:[0x8048588] - 0x84fd378
@ ./callit:[0x804855c] + 0x84fd378 0x1c2
剩余15页未读,继续阅读
资源评论
sunlaurel
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功