kdw
Joined: 05 May 2006 Posts: 1460
|
Posted: 08.10.2009, 16:13 Post subject: Debuggen von Multithread-Programmen … |
|
|
Hallo Forum.
Selbstverständlich kann man die von uns zur Verfügung gestellten GNU-Tools auch zum Debuggen von Multithread-Programmen benutzen. Das folgende Beispiel wurde auf einem DNP/9200 mit einem 2.6-Linux-Kernel angefertigt:
Konsolenausgaben auf dem Entwicklungs-PC:
Code: | mha@hareangle-pluto:/tmp/0/demo_pthread$ ../arm-ssv1-linux-gdb demo_pthread
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i386-ssv-linux --target=arm-ssv1-linux"...
(gdb) target remote 192.168.0.111:2222
Remote debugging using 192.168.0.111:2222
0x400ff4bc in ?? ()
Reading symbols from /usr/local/arm-ssv1-linux/sysroot/lib/libpthread.so.0...done.
Loaded symbols for /usr/local/arm-ssv1-linux/sysroot/lib/libpthread.so.0
Reading symbols from /usr/local/arm-ssv1-linux/sysroot/lib/libc.so.6...done.
Loaded symbols for /usr/local/arm-ssv1-linux/sysroot/lib/libc.so.6
Reading symbols from /usr/local/arm-ssv1-linux/sysroot/lib/ld-linux.so.2...done.Loaded symbols for /usr/local/arm-ssv1-linux/sysroot/lib/ld-linux.so.2
(gdb) list 20
15 {
16 int cnt_t;
17
18 for (cnt_t=0; cnt_t<10; cnt_t++) {
19 printf("counter_thread: %d\n", cnt_t);
20 sleep(1);
21 }
22
23 return NULL;
24 }
(gdb) break 20
Breakpoint 1 at 0x85e4: file demo_pthread.c, line 20.
(gdb) list 40
35 exit(1);
36 }
37
38 for (cnt=0; cnt<8; cnt++) {
39 printf("counter_main: %d\n", cnt);
40 sleep(2);
41 }
42
43 status = pthread_join(counter_pt, NULL);
44 if (status) {
(gdb) break 40
Breakpoint 2 at 0x8688: file demo_pthread.c, line 40.
(gdb) cont
Continuing.
[New thread 1556]
[Switching to thread 1556]
Breakpoint 2, main () at demo_pthread.c:40
40 sleep(2);
(gdb)
Continuing.
[New thread 1558]
[Switching to thread 1558]
Breakpoint 1, counter_thread (arg=0x0) at demo_pthread.c:20
20 sleep(1);
(gdb) delete
Delete all breakpoints? (y or n) y
(gdb) cont
Continuing.
Program exited normally.
(gdb) quit
mha@hareangle-pluto:/tmp/0/demo_pthread$ |
Konsolenausgaben auf dem DNP/9200:
Code: | [root@emblinux /tmp]$./demo_pthread > output.log &
[1] 1556
[root@emblinux /tmp]$./gdbserver-threads :2222 --attach 1556
Attached; pid = 1556
Listening on port 2222
Remote debugging from host 192.168.0.102
Child exited with retcode = 0
Child exited with status 0
GDBserver exiting
[1]+ Done ./demo_pthread >output.log
[root@emblinux /tmp]$cat output.log
counter_main: 0
counter_thread: 0
counter_thread: 1
counter_main: 1
counter_thread: 2
counter_thread: 3
counter_thread: 4
counter_thread: 5
counter_thread: 6
counter_thread: 7
counter_main: 2
counter_thread: 8
counter_thread: 9
counter_main: 3
counter_main: 4
counter_main: 5
counter_main: 6
counter_main: 7
[root@emblinux /tmp]$ |
Gruß
KDW |
|