Haskell 使用hs_init分析共享阴谋集团库时GHC RTS运行时错误

Haskell 使用hs_init分析共享阴谋集团库时GHC RTS运行时错误,haskell,ghc,ffi,Haskell,Ghc,Ffi,我有一个大型的C项目,必须与gcc编译。因此,我将主可执行文件与如下文件链接: #include <HsFFI.h> static void my_enter(void) __attribute__((constructor)); static void my_enter(void) { static char *argv[] = { "Pointer.exe", 0 }; //static char *argv[] = { "Pointer.exe", "+RTS", "

我有一个大型的C项目,必须与gcc编译。因此,我将主可执行文件与如下文件链接:

#include <HsFFI.h>

static void my_enter(void) __attribute__((constructor));
static void my_enter(void) {
  static char *argv[] = { "Pointer.exe", 0 };
  //static char *argv[] = { "Pointer.exe", "+RTS", "-N", "-p", "-s", "-h", "-i0.1", "-RTS", 0 };
  static char **argv_ = argv;
  static int argc = 1; // 8 for profiling
  hs_init(&argc, &argv_);
  //hs_init_with_rtsopts(&argc, &argv_);
}

static void my_exit(void) __attribute__((destructor));
static void my_exit(void) { hs_exit(); }
我用以下配置了cabal包:

"--enable-library-profiling"
"--enable-executable-profiling"
"--enable-shared"
"--enable-tests"
"--enable-coverage"
当运行作为cabal项目一部分编译的可执行文件时,它正确地为我提供了堆栈跟踪和代码覆盖率

如果我按照错误消息的建议尝试将
hs_init_与_rtsopts一起使用
,我会在GHC rts初始化期间收到SIGSEGV:

Pointer.exe: the flag -N requires the program to be built with -threaded
Pointer.exe: the flag -p requires the program to be built with -prof
Pointer.exe: Most RTS options are disabled. Use hs_init_with_rtsopts() to enable them.
Pointer.exe: newBoundTask: RTS is not initialised; call hs_init() first
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a2d0ca in strlen () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff6a2d0ca in strlen () from /usr/lib/libc.so.6
#1  0x00007ffff798c5f6 in copyArg (
    arg=0x657372615062696c <error: Cannot access memory at address 0x657372615062696c>) at rts/RtsFlags.c:1684
#2  0x00007ffff798c679 in copyArgv (argc=8, argv=0x555555554cee) at rts/RtsFlags.c:1696
#3  0x00007ffff798dbe2 in setFullProgArgv (argc=<optimized out>, argv=<optimized out>) at rts/RtsFlags.c:1780
#4  0x00007ffff798e773 in hs_init_ghc (argc=0x555555756090 <argc>, argv=0x5555557560a0 <argv>, rts_config=...)
    at rts/RtsStartup.c:162
#5  0x00007ffff798e7cc in hs_init_with_rtsopts (argc=<optimized out>, argv=<optimized out>)
    at rts/RtsStartup.c:121
#6  0x0000555555554c7d in __libc_csu_init ()
#7  0x00007ffff69cc59f in __libc_start_main () from /usr/lib/libc.so.6
#8  0x0000555555554b29 in _start ()
使用主机libthread\u db库“/usr/lib/libthread\u db.so.1”。
程序接收信号SIGSEGV,分段故障。
来自/usr/lib/libc.so.6的strlen()中的0x00007FF6A2D0CA
(gdb)英国电信
#来自/usr/lib/libc.so.6的strlen()中的0 0x00007FF6A2D0CA
#copyArg中的1 0x00007ffff798c5f6(
arg=0x657372615062696c)在rts/RtsFlags时。c:1684
#在rts/RtsFlags处,2个0x00007ffff798c679在copyArgv中(argc=8,argv=0x554CEE)。c:1696
#rts/RtsFlags处setFullProgArgv(argc=,argv=)中的3 0x00007ffff798dbe2.c:1780
#hs_init_ghc中的4 0x00007ffff798e773(argc=0x5555756090,argv=0x55557560a0,rts_配置=…)
在rts/RTSS启动时。c:162
#5 0x00007FF798E7CC在hs_init_中,带有_rtsopts(argc=,argv=)
在rts/RTSS启动时。c:121
#6 0x0000555554C7D在uuu libc_csu_uinit()中
#7 0x00007FF69CC59F,位于/usr/lib/libc.so.6中的
#8 0x00005554B29英寸(U开始)

那么,如何从使用gcc编译的程序中启用运行时评测呢?

因此,SEGFULT是由于问题中未包含的输入错误造成的。鬼鬼祟祟的

要启用线程和分析等功能,必须将最终程序与适当的RTS风格相链接。这是GHC的
-prof
标志的一种效果,也是它的
-threaded
标志和各种其他标志(如
-debug
)的唯一效果

RTS风格在不同的库中,具有表单名称

libHSrts.a           libHSrts-ghc7.8.4.so        (vanilla)
libHSrts_debug.a     libHSrts_debug-ghc7.8.4.so  (debug)
libHSrts_thr.a       libHSrts_thr-ghc7.8.4.so    (threaded)
libHSrts_p.a         -                           (profiling)
libHSrts_thr_p.a     -                           (threaded+profiling)
libHSrts_l.a         libHSrts_l-ghc7.8.4.so      (eventlog)
...
左边是静态库;右侧是动态库,其库名称包括GHC版本,以便在安装了多个GHC版本的情况下,运行时动态加载程序更容易找到正确的版本。您可以在
GHC--info
中的“RTS方式”下查看GHC安装的完整列表


默认情况下没有安装动态评测库,但我认为拥有它们没有根本问题,您可以配置GHC构建系统来构建它们。(它们现在不是特别有用,因为ghci不支持评测,不过希望很快就会改变。)

C代码是从实际程序复制粘贴的吗?特别是,您真的确定您在
hs\u init\u中包含了
&
关于
argv
的内容,并带有
?它看起来与您的gdb输出不兼容。对于线程化和评测,您需要针对RTS的线程化和评测版本进行链接(
HSrts\u thr\p
)。我正在链接
-lHSrts-ghc7.10.2
。我现在将尝试使用
HSrts\u thr\p
。你是对的-当SIGSEGV发生时,我错过了
\u
。是的-我现在需要自己构建ghc以获得正确的
。因此
文件,但使用其中一个线程版本摆脱了线程消息,因此一旦我有机会编译ghc,它应该可以工作。