在valgrind中包装函数时出现分段错误

时间:2015-03-18 13:44:44

标签: c pthreads valgrind

我正在尝试使用valgrind工具来测量pthread.h库中与线程相关的一些东西。为此,我需要包装一些函数。

该工具有2个文件:fb_main.cfb_intercept.c

fb_intercept.c是包装器的位置。我开始尝试用一个包含pthread_create函数的简单示例。

fb_intercept.c

#include "pub_tool_basics.h"
#include "pub_tool_redir.h"
#include "pub_tool_clreq.h"
#include "valgrind.h"
#include "config.h"

int I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME, pthreadZucreateZAZa)
    (pthread_t *thread, const pthread_attr_t *attr, void *(*start) (void*), void *arg)
{
    int result;
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    CALL_FN_W_WWWW(result, fn, thread, attr, start, arg);
    return result;
}

由于某些原因,当我使用此工具运行程序时,出现以下错误:

--5013-- VG_USERREQ__CLIENT_CALL2: func=0x0
==5013== 
==5013== Process terminating with default action of signal 11 (SIGSEGV)
==5013==  Access not within mapped region at address 0x10
==5013==    at 0x35006084D1: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.18.so)
==5013==    by 0x4A07BF3: pthread_create@* (fb_intercept.c:66)
==5013==    by 0x40074E: main (in /home/andres/Documents/valgrind/prueba/a.out)
==5013==  If you believe this happened as a result of a stack
==5013==  overflow in your program's main thread (unlikely but
==5013==  possible), you can try to increase the size of the
==5013==  main thread stack using the --main-stacksize= flag.
==5013==  The main thread stack size used in this run was 8388608.

实际上,当我致电CALL_FN_W_WWWW(result, fn, thread, attr, start, arg)时会出现问题。当我对此行发表评论时没有错误,只有pthread_create无法按预期正常工作。

我认为这应该是那样的,但事实并非如此,我不知道那个错误意味着什么,或者我错过了什么。可能有人对这种东西了解得更多。

我正在使用svn存储库中的valgind 3.11。

0 个答案:

没有答案