libdispatch-dev SIGILL,dispatch_release中的非法指令

时间:2017-09-01 21:48:29

标签: c linux grand-central-dispatch libdispatch

我有一个在Ubuntu linux中使用libdispatch的程序。在我的main函数结束时,我有dispatch_main()来保持主线程挂起。我的程序的其余部分按预期运行但由于某种原因,一旦调用dispatch_main,它将退出SIGILL。运行GDB,这是下面的输出。最后的Backtrace显示它在dispatch_release失败。

程序:

int main(int argc, const char *argv[]) {
    char *error_message = NULL;

    // Process command line args.
    int option;
    while ((option = getopt_long(argc, (char * const *)argv, "i:", longopts, NULL)) != -1) {
        switch (option) {
            case 'i':
                device_path = optarg;
                break;
        }
    }       

    // prompt has its own "read" function, so instead of using a
    // DispatchSource to read from STDIN_FILENO a global queue is used to loop
    // while it receives input.
//    dispatch_queue_t input_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_queue_t input_queue = dispatch_queue_create("serialctl.prompt_input", NULL);
    dispatch_async(input_queue, ^{
        char *line;
        while((line = prompt_read()) != NULL) {
            interpret_command(line);
            free(line);
        }
    });


    char *home_id_str = create_home_id_str(device->home_id);
    prompt_printf("Initialized SerialAPI device at '%s'\n", device->path);
    prompt_printf("Library '0x%02x' - Version '%.2Lf'\n", device->library, device->version);
    prompt_printf("Home ID '%s' - Node ID '%03d'\n", home_id_str, device->node_id);
    free(home_id_str);



    dispatch_main();
}

gdb debug:

 (gdb) r
    Starting program: /home/jia/libzwsapi/cmake-build-debug/serialapictl -i /dev/ttyACM2
    warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    [New Thread 0x7ffff6ba8700 (LWP 2813)]
    [New Thread 0x7ffff63a7700 (LWP 2814)]
    serialAPI> [New Thread 0x7ffff5ba6700 (LWP 2815)]
                                                     [New Thread 0x7ffff53a5700 (LWP 2816)]
                                                                                           [New Thread 0x7ffff4ba4700 (LWP 2817)]
                                                                                                                                 [New Thread 0x7fffe7fff700 (LWP 2818)]
                                       [New Thread 0x7fffe77fe700 (LWP 2819)]
    Initialized SerialAPI device at '/dev/ttyACM2'
    Library '0x07' - Version '4.33'
    Home ID 'dbf54165' - Node ID '001'
    serialAPI> 
               Thread 1 "serialapictl" received signal SIGILL, Illegal instruction.
                                                                                   0x00007ffff79c6b73 in _dispatch_release () from /usr/lib/libdispatch.so.0
    (gdb) bt
    #0  0x00007ffff79c6b73 in _dispatch_release () from /usr/lib/libdispatch.so.0
    #1  0x00007ffff79c77bb in dispatch_main () from /usr/lib/libdispatch.so.0
    #2  0x0000000000402e69 in main (argc=3, argv=0x7fffffffe368) at /home/jia/libzwsapi/serialapictl/main.c:138
    (gdb) 

0 个答案:

没有答案