I am having trouble debugging programs with threads on Cygwin.
When the following program gets to the pthread_create()
call, the debug session gets an unknown target exception, apparently in a call to ntdll!RtlAllocateHeap()
.
I know in the past I have been able to debug threads in Eclipse -- are there some new secret settings I missed, or is this a problem with Eclipse?
For the record, I am running Cygwin64 (CYGWIN_NT-6.1) with gcc 7.4.0 / gdb 8.1.1 / Eclipse 4.13.0.
The programs runs fine when run directly from the command line. I can also start the program in gdb, and step through statements until it gets to the pthread_create()
call.
The gdb session:
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
The program:
// 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;
}
User contributions licensed under CC BY-SA 3.0