为什么Cygwin gdb在调试带有线程的程序时遇到问题?

为什么Cygwin gdb在调试带有线程的程序时遇到问题?,c,gdb,pthreads,cygwin,C,Gdb,Pthreads,Cygwin,我在调试Cygwin上带有线程的程序时遇到问题 当下面的程序到达pthread\u create()调用时,调试会话会得到一个未知的目标异常,显然是在对ntdll的调用中!RtlAllocateHeap() 我知道在过去我能够在Eclipse中调试线程——我是否遗漏了一些新的秘密设置,或者这是Eclipse的问题 为了记录在案,我正在使用gcc 7.4.0/gdb 8.1.1/Eclipse 4.13.0运行Cygwin64(CYGWIN_NT-6.1) 直接从命令行运行时,程序运行良好。我还可

我在调试Cygwin上带有线程的程序时遇到问题

当下面的程序到达
pthread\u create()
调用时,调试会话会得到一个未知的目标异常,显然是在对
ntdll的调用中!RtlAllocateHeap()

我知道在过去我能够在Eclipse中调试线程——我是否遗漏了一些新的秘密设置,或者这是Eclipse的问题

为了记录在案,我正在使用gcc 7.4.0/gdb 8.1.1/Eclipse 4.13.0运行Cygwin64(CYGWIN_NT-6.1)

直接从命令行运行时,程序运行良好。我还可以在gdb中启动程序,并逐步执行语句,直到到达
pthread\u create()
调用

gdb会议:

jay.elston@M4800-1RBTK12 ~/threadTest
$ cc -g threads.c

jay.elston@M4800-1RBTK12 ~/threadTest
$ gdb a.exe
GNU gdb (GDB) (Cygwin 8.1.1-1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.exe...done.
(gdb) b 13
Breakpoint 1 at 0x10040108c: file threads.c, line 13.
(gdb) run
Starting program: /home/jay.elston/threadTest/a.exe
[New Thread 624.0xebc]
[New Thread 624.0x2ef0]
[New Thread 624.0x1b24]
[New Thread 624.0x1074]
[New Thread 624.0x2088]
[New Thread 624.0x2710]
[New Thread 624.0x2a1c]
gdb: unknown target exception 0x80000001 at 0x77a97b97

Thread 7 received signal ?, Unknown signal.
[Switching to Thread 624.0x2a1c]
0x0000000077a97b97 in ntdll!RtlAllocateHeap ()
   from /cygdrive/c/Windows/SYSTEM32/ntdll.dll
(gdb)c
Continuing.
[New Thread 624.0x2374]
[Thread 624.0x2710 exited with code 2147483649]
[Thread 624.0x2a1c exited with code 2147483649]
[Thread 624.0x2088 exited with code 2147483649]
[Thread 624.0x1b24 exited with code 2147483649]
[Thread 624.0x1074 exited with code 2147483649]
[Thread 624.0x2374 exited with code 2147483649]
[Inferior 1 (process 624) exited with code 020000000001]
(gdb) quit

jay.elston@M4800-1RBTK12 ~/threadTest
$ ./a.exe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
杰伊。elston@M4800-1RBTK12~/螺纹试验 $cc-g threads.c 松鸦。elston@M4800-1RBTK12~/螺纹试验 $gdb a.exe GNU gdb(gdb)(Cygwin 8.1.1-1)8.1.1 版权所有(C)2018免费软件基金会。 许可证GPLv3+:GNU GPL版本3或更高版本 这是自由软件:您可以自由更改和重新发布它。 在法律允许的范围内,不存在任何担保。键入“显示复制” 和“显示保修”了解详细信息。 此GDB配置为“x86_64-pc-cygwin”。 键入“显示配置”以获取配置详细信息。 有关错误报告说明,请参阅: . 在线查找GDB手册和其他文档资源,网址为: . 要获得帮助,请键入“帮助”。 键入“apropos word”以搜索与“word”相关的命令。。。 从a.exe读取符号…完成。 (gdb)b 13 断点1位于0x10040108c:文件threads.c,第13行。 (gdb)运行 启动程序:/home/jay.elston/threadTest/a.exe [新线程624.0xebc] [新线程624.0x2ef0] [新螺纹624.0x1b24] [新线程624.0x1074] [新线程624.0x2088] [新线程624.0x2710] [新螺纹624.0x2a1c] gdb:0x77a97b97处的未知目标异常0x80000001 线程7收到信号?,未知信号。 [切换到线程624.0x2a1c] ntdll中的0x0000000077a97b97!RtlAllocateHeap() 从/cygdrive/c/Windows/SYSTEM32/ntdll.dll (gdb)c 持续的。 [新线程624.0x2374] [线程624.0x2710退出,代码为2147483649] [线程624.0x2a1c退出,代码为2147483649] [线程624.0x2088退出,代码为2147483649] [线程624.0x1b24已退出,代码为2147483649] [线程624.0x1074退出,代码为2147483649] [线程624.0x2374退出,代码为2147483649] [低级1(流程624)已退出,代码为0200000000001] (gdb)退出 松鸦。elston@M4800-1RBTK12~/螺纹试验 $./a.exe 1. 2. 3. 4. 5. 6. 7. 8. 9 10 11 12 13 14 15 该方案:

// Start a thread using pthread_create
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <string.h>
#include <pthread.h>

void *fifteenSeconds(void *arg)
{
    struct timespec sleepTime;
    struct timespec sleptTime;

    int i = 0;

    while ( i++ < 15 ) {
        printf("%d\n", i);
        sleepTime.tv_sec = 01;
        sleepTime.tv_nsec = 000000000;
        nanosleep(&sleepTime, &sleptTime);
    }
    return (void *)0;
}

int main ( int argc, char *argv[] )
{
    pthread_t fifteenSecondsThreadId;

    int rc = 0;

    rc = pthread_create(&fifteenSecondsThreadId, (void *)0, &fifteenSeconds, (void *)0);
    if ( rc != 0 ) {
        fprintf(stderr, "(%s,%d): Error %d creating thread for io handler: %s\n"
                , __FILE__, __LINE__
                , errno, strerror(errno)
                );
        return rc;
    }

    pthread_join(fifteenSecondsThreadId, (void *)0);

    return 0;
}
//使用pthread\u create启动线程
#包括
#包括
#包括
#包括
#包括
无效*第五秒(无效*参数)
{
结构timespec睡眠时间;
struct timespec sleptime;
int i=0;
而(i++<15){
printf(“%d\n”,i);
sleepTime.tv_sec=01;
sleepTime.tv_nsec=000000000;
纳秒睡眠(睡眠时间和睡眠时间);
}
返回(void*)0;
}
int main(int argc,char*argv[])
{
pthread_t fifteensecondsthread;
int rc=0;
rc=pthread_create(&fifteenSecondsThreadId,(void*)0,&fifteenSeconds,(void*)0);
如果(rc!=0){
fprintf(stderr,(%s,%d):为io处理程序创建线程时出现错误%d:%s\n
,文件,行__
,errno,strerror(errno)
);
返回rc;
}
pthread_join(第五个第二个线程ID,(void*)0);
返回0;
}

我正在运行gcc 7.4.0/gdb 8.1.1/Eclipse 4.13.0。--在程序到达pthread_create调用…Puff之前,一切都正常工作,所以只需更新我的eclipse(花了我一段时间:),您的程序在cygwin64 gcc7.4 gdb8.1 eclipse4.13上运行良好,所以我必须更改某些eclipse或Cywgin设置,以解决此问题。大海捞针:-(尝试在Eclipse之外运行您的程序。如果这样做有效,请在Eclipse之外的GDB中运行它。只有这样做有效,我才会说Eclipse才是罪魁祸首。请用您的发现回答您的问题。@busybee--谢谢--看起来这与Cygwin/GDB有关,而不是Eclipse。