ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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."
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.