小编bin*_*rym的帖子

包装abort()系统调用时出现奇怪的行为

我需要编写单一测试来包装abort()系统调用.

这是一段代码:

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

extern void __real_abort(void);
extern void * __real_malloc(int c);
extern void __real_free(void *);


void __wrap_abort(void)
{
    printf("=== Abort called !=== \n");
}   

void * __wrap_malloc(int s)
{
    void *p = __real_malloc(s);
    printf("allocated %d bytes @%p\n",s, (void *)p);
    return p;
}

void __wrap_free(void *p)
{
    printf("freeing @%p\n",(void *)p);
    return __real_free((void *)p);
}


int main(int ac, char **av)
{
    char *p = NULL;
    printf("pre malloc: p=%p\n",p);
    p = malloc(40);
    printf("post malloc p=%p\n",p);

    printf("pre abort\n");
    //abort(); …
Run Code Online (Sandbox Code Playgroud)

c linux debugging mocking abort

1
推荐指数
1
解决办法
275
查看次数

标签 统计

abort ×1

c ×1

debugging ×1

linux ×1

mocking ×1