LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 08-31-2004, 05:04 AM   #1
Ralf Becker
LQ Newbie
 
Registered: Aug 2004
Posts: 2

Rep: Reputation: 0
problem to debug in threads


Hello
I use SUSE 9.0, GDB 6.1, GCC 3.3.3, eclipse platform 3.0, CDT 2.0
To show the problem I have an exampe file thread1.c.
It was a "Managed Make C Poject " with name thread1 from eclipse. That is the platform eclipse generate the makefile itself.
----------------------------------------------------------------------------------
Compile the project with a console:
...>make all
Building file: ../thread1.c
gcc -O0 -g3 -Wall -c -fmessage-length=0 -othread1.o ../thread1.c
Finished building: ../thread1.c

Building target: thread1
gcc -othread1 thread1.o -lpthread -lm
Finished building: thread1
----------------------------------------------------------------------------------
file thread1.c:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>

void *thread_function(void *arg);

char message[] = "Hello World";

int main() {
int res;
pthread_t a_thread;
void *thread_result;
res = pthread_create(&a_thread, NULL, thread_function, (void *)message);
if (res != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Waiting for thread to finish...\n");
res = pthread_join(a_thread, &thread_result);
if (res != 0) {
perror("Thread join failed");
exit(EXIT_FAILURE);
}
printf("Thread joined, it returned %s\n", (char *)thread_result);
printf("Message is now %s\n", message);
exit(EXIT_SUCCESS);
}

void *thread_function(void *arg) {
printf("thread_function is running. Argument was %s\n", (char *)arg);
sleep(3);
strcpy(message, "Bye!");
pthread_exit("Thank you for the CPU time");
}
----------------------------------------------------------------------------------
I set a breakpoint at the line res = pthread_create(... and the line sleep(3).
I use the ddd (similar the degugger in the eclipse platform) and following error uccures:
DDD Backtrace:
#1 0x080485b1 in main() at thread1.c:15
#0 0x0804844c in ?? ()
DDD Registers:
eax Couldn't get registers: Kein passender Prozess gefunden
----------------------------------------------------------------------------------
What is the error, that I can not degug threads ?
Thanks for help.
 
Old 08-31-2004, 09:21 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
There error is that debugging symbols can't be found in the target.

You need to pass the -g option to gcc when compiling thread1 to put the debugging symbols into thread1. Without that it will be quite hard to make sense of the backtrace, and program symbols just won't be visible at all, except by address.
 
Old 09-01-2004, 02:04 AM   #3
Ralf Becker
LQ Newbie
 
Registered: Aug 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for your reply.
But If you can read in my question the compiler option is -g3.
man-page:
"Level 3 includes extra information, such as all the macro definitions present in
the program. Some debuggers support macro expansion when you use -g3."
 
Old 09-01-2004, 02:33 AM   #4
Stor_G
Member
 
Registered: Aug 2004
Posts: 50

Rep: Reputation: 15
Quote:
Kein passender Prozess gefunden
that doesn't seem to be english (at least to me...)
could you translate it for me pls?
plus: did you try to add debug prints to see where the program crashes exactly?
if you didn't maybe you should. would give u a better idea on where to focus the search.
just don't forget to add a \n after the debug print otherwise the buffer won't be written to the screen immediately and could be discarded if a crash occurs.
 
Old 09-01-2004, 09:22 AM   #5
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
Quote:
Originally posted by Stor_G
[B]that doesn't seem to be english (at least to me...)
could you translate it for me pls?
Yes it's german. "Kein passender Prozess gefunden" translates
to "Couldn't find appropriate process" (or maybe a required one - but approriate
fits better).
 
Old 09-01-2004, 01:08 PM   #6
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Re: problem to debug in threads

Quote:
Originally posted by Ralf Becker
gcc -othread1 thread1.o -lpthread -lm
There is no -g option used to compile this module (thread1). Therefore this module will not contain debugging information, and cannot easily be debugged.

Edit: There will be symbols in thread1.o but I don't think they'll be kept in the executable unless you pass -g here as well.

Last edited by rjlee; 09-01-2004 at 01:11 PM.
 
  


Reply



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
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
[debug]what does the following debug information mean icoming Programming 21 06-08-2004 02:13 AM
debug problem w/ c++ code nub47 Programming 2 12-17-2003 12:31 AM
how debug email problem? johnkantor12 Linux - Networking 7 11-23-2003 02:55 PM
C debug problem miasmak Programming 4 11-12-2001 01:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration