[RFA/RFC] Prec multi-thread support [0/4]

Hui Zhu teawater@gmail.com
Wed Nov 25 08:06:00 GMT 2009


Hi guys,

Before the prec target checked in, I wrote some patches to make prec
support multi-thread.  But I got some bug I cannot deal with.  So I
delay them.

Now I found some way to handle this issue.  So I post them.

I divide the support to 4 patches:
1. X86 insn support
2. Arch support
3. thread.c support
4. record.c update

To use these patches need patch
http://sourceware.org/ml/gdb-patches/2009-11/msg00520.html first.

The following is how the prec multi-thread support works:
cat 1.c
#include <stdio.h>
#include <pthread.h>

void td1(void * i)
{
	printf ("teawater1\n");
	sleep (1);

	return;
}

void td2(void * i)
{
	while (1)
	{
		printf ("teawater2\n");
		sleep (1);
	}

	return;
}

int
main(int argc,char *argv[],char *envp[])
{
	pthread_t	t1,t2;

	pthread_create(&t1, NULL, (void*)td1, NULL);
	pthread_create(&t2, NULL, (void*)td2, NULL);

	while (1)
	{
		printf ("teawater0\n");
		sleep (1);
	}

	return (0);
}

gcc -g -lpthread 1.c

gdb ./a.out
GNU gdb (GDB) 7.0.50.20091119-cvs
Copyright (C) 2009 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 "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/teawater/gdb/rec/bgdbno/gdb/a.out...done.
Setting up the environment for debugging gdb.
Function "internal_error" not defined.
Make breakpoint pending on future shared library load? (y or [n])
[answered N; input not from terminal]
Function "info_command" not defined.
Make breakpoint pending on future shared library load? (y or [n])
[answered N; input not from terminal]
/home/teawater/gdb/rec/bgdbno/gdb/.gdbinit:8: Error in sourced command file:
No breakpoint number 0.
(gdb) start
During symbol reading, DW_AT_name missing from DW_TAG_base_type.
Temporary breakpoint 1 at 0x8048495: file 1.c, line 28.
Starting program: /home/teawater/gdb/rec/bgdbno/gdb/a.out
[Thread debugging using libthread_db enabled]

Temporary breakpoint 1, main (argc=<value optimized out>, argv=<value
optimized out>, envp=<value optimized out>)
    at 1.c:28
28		pthread_create(&t1, NULL, (void*)td1, NULL);
(gdb) record
(gdb) n
During symbol reading, incomplete CFI data; unspecified registers
(e.g., eax) at 0x8048492.
[New Thread 0xb7e52b90 (LWP 22980)]
29		pthread_create(&t2, NULL, (void*)td2, NULL);
(gdb) n
[New Thread 0xb7651b90 (LWP 22981)]
33			printf ("teawater0\n");
(gdb) info threads
  3 Thread 0xb7651b90 (LWP 22981)  0xb7faf661 in
__lll_unlock_wake_private () from /lib/tls/i686/cmov/libpthread.so.0
  2 Thread 0xb7e52b90 (LWP 22980)  0xb7eae1cf in _IO_file_doallocate
() from /lib/tls/i686/cmov/libc.so.6
* 1 Thread 0xb7e53ad0 (LWP 22977)  main (argc=<value optimized out>,
argv=<value optimized out>,
    envp=<value optimized out>) at 1.c:33
(gdb) rc
Continuing.

No more reverse-execution history.
main (argc=<value optimized out>, argv=<value optimized out>,
envp=<value optimized out>) at 1.c:28
28		pthread_create(&t1, NULL, (void*)td1, NULL);
(gdb) c
Continuing.

No more reverse-execution history.
[Switching to Thread 0xb7e52b90 (LWP 22980)]
0xb7eae1cf in _IO_file_doallocate () from /lib/tls/i686/cmov/libc.so.6
(gdb) thread
[Current thread is 2 (Thread 0xb7e52b90 (LWP 22980))]
(gdb) info threads
  3 Thread 0xb7651b90 (LWP 22981)  0xb7faf661 in
__lll_unlock_wake_private () from /lib/tls/i686/cmov/libpthread.so.0
* 2 Thread 0xb7e52b90 (LWP 22980)  0xb7eae1cf in _IO_file_doallocate
() from /lib/tls/i686/cmov/libc.so.6
  1 Thread 0xb7e53ad0 (LWP 22977)  main (argc=<value optimized out>,
argv=<value optimized out>,
    envp=<value optimized out>) at 1.c:33
(gdb) thread 1
[Switching to thread 1 (Thread 0xb7e53ad0 (LWP 22977))]#0  main
(argc=<value optimized out>,
    argv=<value optimized out>, envp=<value optimized out>) at 1.c:33
33			printf ("teawater0\n");
(gdb) c
Continuing.
teawater1
teawater0
teawater2
teawater0
teawater2
The next instruction is syscall exit.  It will make the thread Thread
0xb7e52b90 (LWP 22980) exit.  Do you want to stop the program?([y] or
n) n
[Thread 0xb7e52b90 (LWP 22980) exited]
teawater0
teawater2
teawater0
teawater2
teawater0
teawater2

Program received signal SIGINT, Interrupt.
0xb7fe3410 in __kernel_vsyscall ()
(gdb) rc
Continuing.

No more reverse-execution history.
main (argc=<value optimized out>, argv=<value optimized out>,
envp=<value optimized out>) at 1.c:28
28		pthread_create(&t1, NULL, (void*)td1, NULL);
(gdb) info threads
  3 Thread 0xb7651b90 (LWP 22981)  0xb7fe3410 in __kernel_vsyscall ()
* 1 Thread 0xb7e53ad0 (LWP 22977)  main (argc=<value optimized out>,
argv=<value optimized out>,
    envp=<value optimized out>) at 1.c:28
(gdb) n
29		pthread_create(&t2, NULL, (void*)td2, NULL);
(gdb) thread 3
[Switching to thread 3 (Thread 0xb7651b90 (LWP 22981))]#0  0xb7fe3410
in __kernel_vsyscall ()
(gdb) bt
#0  0xb7fe3410 in __kernel_vsyscall ()
#1  0xb7faf553 in __lll_lock_wait_private () from
/lib/tls/i686/cmov/libpthread.so.0
#2  0xb7fa94ea in _L_lock_2331 () from /lib/tls/i686/cmov/libpthread.so.0
#3  0xb7fa85f1 in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#4  0x00000000 in ?? ()
(gdb) n
Single stepping until exit from function __kernel_vsyscall,
which has no line number information.
0xb7faf553 in __lll_lock_wait_private () from /lib/tls/i686/cmov/libpthread.so.0
(gdb) bt
#0  0xb7faf553 in __lll_lock_wait_private () from
/lib/tls/i686/cmov/libpthread.so.0
#1  0xb7fa94ea in _L_lock_2331 () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb7fa85f1 in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#3  0xb7f2ae5e in clone () from /lib/tls/i686/cmov/libc.so.6
(gdb) b tb2
Function "tb2" not defined.
Make breakpoint pending on future shared library load? (y or [n])
(gdb) b td
td1          td2          tdelete      tdelete@plt  tdestroy
(gdb) b td2
Breakpoint 2 at 0x804846a: file 1.c, line 16.
(gdb) c
Continuing.

Breakpoint 2, td2 (i=0x0) at 1.c:16
16			printf ("teawater2\n");
(gdb) n
17			sleep (1);
(gdb) info threads
* 3 Thread 0xb7651b90 (LWP 22981)  td2 (i=0x0) at 1.c:17
  1 Thread 0xb7e53ad0 (LWP 22977)  0xb7ff91b4 in ?? () from /lib/ld-linux.so.2
(gdb) n
18		}
(gdb)

Breakpoint 2, td2 (i=0x0) at 1.c:16
16			printf ("teawater2\n");
(gdb)
17			sleep (1);
(gdb)
18		}
(gdb)

Breakpoint 2, td2 (i=0x0) at 1.c:16
16			printf ("teawater2\n");
(gdb) c
Continuing.

Breakpoint 2, td2 (i=0x0) at 1.c:16
16			printf ("teawater2\n");
(gdb) d 2
(gdb) c
Continuing.

No more reverse-execution history.
[Switching to Thread 0xb7e53ad0 (LWP 22977)]
0xb7fe3410 in __kernel_vsyscall ()
(gdb) info threads
  3 Thread 0xb7651b90 (LWP 22981)  0xb7fe3410 in __kernel_vsyscall ()
* 1 Thread 0xb7e53ad0 (LWP 22977)  0xb7fe3410 in __kernel_vsyscall ()
(gdb) q
A debugging session is active.

	Inferior 1 [process 22977] will be killed.

Quit anyway? (y or n) y

These patches test with testsuite in i386 is OK.

Please help me review it.

Thanks,
Hui



More information about the Gdb-patches mailing list