Debug Multithreaded applic on ARM (AT91SAM9xxxx) with GDB

All design tool related questions: compiler, assembler, linker. Embedded programming questions: assembler, C code.

Moderator: nferre

Noel_V
Contact:
Location: belgium
Posts: 6
Joined: Mon Feb 25, 2008 9:30 pm

Debug Multithreaded applic on ARM (AT91SAM9xxxx) with GDB

Sat Jun 06, 2009 6:27 am

Hi,


Trying to DEBUG a linux userland application that has multiple threads but I can not get this working.


{ tried to contact some people at the GDB maling list but did not get any response that can help me further, so i decided to give it a go in this forum, because there must be some people out there that have this working (I hope) }



I'll try to describe my setup and configuration in a few words.

Host : PC
PC - runing LINUX (ubuntu)
Buildsystem : BUILDROOT (20090601 but also tried some other versions as well same result did not work.)
GDB: 6.8
{STRIPPING of bin's/libs turned off, DEBUG support for threads/pthreads is ENABLED.. }


Target: ARM
AT91SAM9260 & AT91SAM9G20 (both same results :-) not working :-( )
Running : LINUX 2.6.28.x
GDBServer 6.8
Running A 'simple' test APPLICATION that spins multiple 'p'-threads.
{ libthread_db.* and a lot of other libs are on the target (via NFS) and are NOT stripped }


Problem description:

When the application is run in 'remote-'gdb the application 'HANGS' as
soon as the second thread is created!


Note: I've a SMALL sample that can show the 'strange' behavior. (source code at the end)


<< some code snips : full source at the included bottom ! >>
41 int main()
42 {
43 pthread_t threads[NUM_THREADS];
44 int rc, t;
45 for(t=0;t<NUM_THREADS;t++){
46 printf("Creating thread %d\r\n", t);
47 rc = pthread_create(&threads[t], NULL, PrintHello, (void*)t);
48 if (rc){
49 printf("ERROR; return code from pthread_create() is %d\r\n", rc);
50 exit(-1);
51 }
52 }
53

<< TRY-ING to put a Break-point on LINE 48. --> here is the problem .!!!!!!!

(target : gdbserver *:9000 ./threading)
(host : gdb - over TCP/IP -> target ip-address port 9000)


>>> target console log <<<
# gdbserver *:9000 ./threading
Process ./threading created; pid = 905
Listening on port 9000
Remote debugging from host 150.158.205.4
Creating thread 0

0: Hello World! 0
Creating thread 1

0: Hello World! 1

--->> and now .. the target is 'HANGING' <<---------



>> a NORMAL run on the target ARM (AT91SAM9G20 or AT91SAM9260) -- gives me the expected output and is WORKING fine <<

When the Test-application runs STAND-ALONE on the target (normal
behavoir... As expected ;-))
./threading
Creating thread 0
0: Hello World! 0
Creating thread 1
1: Hello World! 0
Creating thread 2
2: Hello World! 0
Creating thread 3
3: Hello World! 0
Creating thread 4
4: Hello World! 0
Sleeping/printing in main .....
printing in main 0
0: Hello World! 1
1: Hello World! 1
2: Hello World! 1
<< some things.. Are removed here >>
Hello World! 19

4: Hello World! 19
printing in main 19
printing in main 20
printing in main 21
printing in main 22
printing in main 23
printing in main 24
printing in main 25
printing in main 26
printing in main 27
printing in main 28
printing in main 29
Sleeping in main ..... DONE ..





For the ones that can do something with it .. included is de GDB console log.

<< please have a look at this GDB-CONSOLE-LOG >>

/buildhome/20090601/buildroot/toolchain_build_arm/gdbhost-6.8/gdb$ ./gdb

GNU gdb 6.8
Copyright (C) 2008 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 "--host=i386-pc-linux-gnu
--target=arm-linux-uclibc".
Setting up the environment for debugging gdb.
Setting up the environment for debugging gdb - DONE .
Breakpoint 1 at 0x8784: file sources/main.c, line 46.
(NOEL2-gdb) run
Starting program: /tmp/threading
[New Thread 906]
[Switching to Thread 906]
Stopped due to shared library event
(NOEL2-gdb) c
Continuing.
Stopped due to shared library event
(NOEL2-gdb) info shared li
From To Syms Read Shared Object Library
0x40000930 0x40003eb0 Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/ld-uClibc.so.0
0x40011cc0 0x4001820c Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/libpthread.so.0
0x40029ca0 0x40030ec4 Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/libgcc_s.so.1
0x40044c90 0x400855b0 Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/libc.so.0
(NOEL2-gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x00008784 in main at sources/main.c:46
(NOEL2-gdb) l
37 }
38 pthread_exit(NULL);
39 }
40
41 int main()
42 {
43 pthread_t threads[NUM_THREADS];
44 int rc, t;
45 for(t=0;t<NUM_THREADS;t++){
46 printf("Creating thread %d\r\n", t);
(NOEL2-gdb) l
47 rc = pthread_create(&threads[t], NULL, PrintHello, (void
*)t);
48 if (rc){
49 printf("ERROR; return code from pthread_create() is
%d\r\n", rc);
50 exit(-1);
51 }
52 }
53
54 printf("Sleeping/printing in main ..... \r\n");
55 {
56 int n;
(NOEL2-gdb) b main.c:48
Breakpoint 2 at 0x87f8: file sources/main.c, line 48.
(NOEL2-gdb) c
Continuing.

Breakpoint 1, main () at sources/main.c:46
46 printf("Creating thread %d\r\n", t);
(NOEL2-gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x00008784 in main at sources/main.c:46
breakpoint already hit 1 time
2 breakpoint keep y 0x000087f8 in main at sources/main.c:48
(NOEL2-gdb) info shared li
From To Syms Read Shared Object Library
0x40000930 0x40003eb0 Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/ld-uClibc.so.0
0x40011cc0 0x4001820c Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/libpthread.so.0
0x40029ca0 0x40030ec4 Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/libgcc_s.so.1
0x40044c90 0x400855b0 Yes
/buildhome/20090601/buildroot/project_build_arm/at91sam9g20ek/root/lib/libc.so.0
(NOEL2-gdb) c
Continuing.

Breakpoint 2, main () at sources/main.c:48
48 if (rc){
(NOEL2-gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x00008784 in main at sources/main.c:46
breakpoint already hit 1 time
2 breakpoint keep y 0x000087f8 in main at sources/main.c:48
breakpoint already hit 1 time
(NOEL2-gdb) c
Continuing.


<< HANGING .. FOR-EVER !! --
NORMALLY the loop should BREAK again (at line 48) .. and I should have screen output on the target console .. but i don't have this... -> APPLICATION / DEBUGGER are dead :-( >>






// Source Code

/* Some Sample test*/
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5

void *PrintHello(void *threadid)
{
int n;
for (n=0;n<20;n++)
{
printf("\r\n%d: Hello World! %d \r\n", threadid,n);
sleep(5);
}
pthread_exit(NULL);
}

int main()
{
pthread_t threads[NUM_THREADS];
int rc, t;
for(t=0;t<NUM_THREADS;t++){
printf("Creating thread %d\r\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); /* WANT to STEP over OR .... */
if (rc){ /* WANT TO INSERT-BREAKP HERE ! ! */
printf("ERROR; return code from pthread_create() is %d\r\n",
rc);
exit(-1);
}
}

printf("Sleeping/printing in main ..... \r\n");
{
int n;
for(n=0;n<30;n++)
{
sleep(1);
printf("printing in main %d \r\n",n);
sleep(4);
}
}
printf("Sleeping in main ..... DONE .. \r\n");
pthread_exit(NULL);
}

Return to “Development Tools”

Who is online

Users browsing this forum: No registered users and 4 guests