LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-16-2005, 01:43 PM   #1
Krishna100
LQ Newbie
 
Registered: Aug 2005
Posts: 6

Rep: Reputation: 0
pthread support in gdb 6.3 on suse linux 9.3


I know gdb supports debugging of threads. I have my programs compiled the right way (-g compiler flag) and can debug them, except that I don't see support for threads ("info threads" does nothing; breakpoints set in thread functions aren't hit) in gdb. This is so frustrating because I know this support exists in gdb.

I'm running Suse Linux 9.3 and am using the gdb that arrived as part of this installation (gdb version 6.3). Hardware is AMD 64. Yast shows my gdb supports x86_64.

What is going on? What should I check and what should I do to get thread debugging support? As far as I can tell, all I need to do is use "-g" compiler option to compile and use "info threads" (or view threads in kdbg) to verify that threads are supported. Any help is appreciated.
 
Old 09-16-2005, 02:20 PM   #2
MrMichaelWill
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Rep: Reputation: 0
After running your application in gdb, does it give you messages
like
[new process 123 ...]

?

Your application actually fork off threads, just linking against -lpthreads does nothing.

Check out http://www.mhpcc.edu/training/worksh...amples/hello.c and
modify it a bit for the threads to stick around (sleep print loop or whatever) so you
have something to debug. after compiling it with gcc -o phello hello.c -lphtreads -g
you can load it into gdb with 'gdb phello', set breakpoints in the subthread and
don't forget to have a sleep in the main loop so it does not quit right away before
the threads get to execute.
(gdb) info threads
No registers.
(gdb) l
20 sleep(2);
21 }
22 pthread_exit(NULL);
23 }
24
25 int main()
26 {
27 pthread_t threads[NUM_THREADS];
28 int rc, t;
29 for(t=0;t<NUM_THREADS;t++){
(gdb) b 20
Breakpoint 1 at 0x80484bc: file h.c, line 20.
(gdb) r
Starting program: /tmp/bonnie++-1.03a/h
[Thread debugging using libthread_db enabled]
[New Thread -1208814144 (LWP 29534)]
Creating thread 0
[New Thread -1208816720 (LWP 29537)]
Creating thread 1

0: Hello World!
[New Thread -1219306576 (LWP 29538)]
Creating thread 2

1: Hello World!
[New Thread -1229796432 (LWP 29539)]
Creating thread 3
[Switching to Thread -1219306576 (LWP 29538)]

Breakpoint 1, PrintHello (threadid=0x1) at h.c:20
20 sleep(2);

...

Michael

Last edited by MrMichaelWill; 09-16-2005 at 02:27 PM.
 
Old 09-16-2005, 04:28 PM   #3
Krishna100
LQ Newbie
 
Registered: Aug 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks, but problem persists.

Michael,

Thanks for the ptr to the sample. I modified it and tried it. Had the same problem with it as I had with my program -- I can set breakpoints in the thread callback but those breakpoints aren't hit. gdb is only hitting breakpoints in the main program, not those in the thread callback.

My program is a fairly full fledged program launching several threads to perform async i/o and generating lots of i/o in that process on multiple threads. I had the same problem trying to use gdb on that as I had with hello.c you pointed me to. That is the frustrating part -- every one tells me that gdb has the support and that it should work, but it just doesn't :-(

I have plenty of experience programming and debugging with threads under Windows environment (using vc ide, ntsd, windbg debuggers), so it is all the more frustrating to get into Linux and find myself severely handicapped -- unable to get gdb to break into threads.

Should I do something special to configure gdb to work with threads besides using the -g flag during compile (and using -lpthread for linking, to get thread support)? Everything I read suggests I don't need to do anything else, but it just doesn't work. Since gdb doesn't work (on a couple of similarly configured Linux machines), I'm unable to use all those GUI debuggers (such as kdbg) that rely on gdb :-(

I must be missing something subtle in my configuration...
 
Old 09-17-2005, 04:18 PM   #4
Krishna100
LQ Newbie
 
Registered: Aug 2005
Posts: 6

Original Poster
Rep: Reputation: 0
I got gdb to work with multiple threads on another installation (suse 9.2), so I know it works. Wonder why it doesn't work on the 9.3 version boxes.

At this point it appears to be some subtle configuration or library mismatch issue -- any help would be appreciated. Is reinstall of Linux my only choice at this point?
 
Old 09-20-2007, 01:31 PM   #5
MrMichaelWill
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Rep: Reputation: 0
Quote:
Originally Posted by Krishna100 View Post
I got gdb to work with multiple threads on another installation (suse 9.2), so I know it works. Wonder why it doesn't work on the 9.3 version boxes.

At this point it appears to be some subtle configuration or library mismatch issue -- any help would be appreciated. Is reinstall of Linux my only choice at this point?
Just downloading and compiling your own version of gdb might have done it, but I guess your question was two years ago and you have solved this for a long time already ;-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
normal gdb and spec gdb for kgdb Igor007 Programming 1 09-23-2005 04:15 PM
normal gdb and spec gdb for kgdb Igor007 Linux - Newbie 1 09-23-2005 01:41 PM
gdb crashes when debugging pthread-ed program tbruer1138 Programming 0 04-21-2005 05:38 PM
gdb .. looking for 32 bit gdb.. for ia64 suse.. nkshirsagar Suse/Novell 0 12-09-2004 03:02 AM
japanese support on suse linux usham Linux - Software 0 11-06-2004 06:16 AM


All times are GMT -5. The time now is 10:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration