/* compile with: gcc -pthread -Wall recthr.c -o recthr */ #include #include #include volatile int th1_done; void *th1(void *_) { printf("run\ngdb -p %d\nthen in gdb type:\ncont\nand press enter in this term\n", getpid()); getchar(); th1_done = 1; return 0; } int traceme(void) { int x=0; int i=0; for (x = 0; x < 10; x++) i += x*2; return i; } void after_traceme(int x) { printf("%d\n", x); } void *th2(void *x) { int i = traceme(); after_traceme(i); return 0; } void new_thread(void *(*f)(void *)) { pthread_t th; pthread_create(&th, 0, f, 0); } int main(void) { new_thread(th1); while (!th1_done) usleep(10*1000); printf("type:\nctrl+c\nhb *%p\nhb *%p\ncont\nin gdb and press enter in this term\n", traceme, after_traceme); getchar(); printf("type:\nset scheduler-locking on\nrecord full\ncont\nin gdb\n"); printf("then:\nrecord save /tmp/XX\nit should fail\n"); printf("then type:\ninfo record\nit should segfault\n"); printf("and happy debugging to you too.:)\n"); new_thread(th2); while (1) pause(); }