2

I have a C program where the main function creates threads and I have to debug one thread. I am using gdb for he same. However I cannot "break" or "watch" variables on specific C files of this program. For eg. my thread 6 is programmed and uses certain C files and I have to break at line 601 on say call_connect.c. Is this not possible? If I try to, this is what happens:

(gdb) info threads
  6 Thread 0xb5c96b70 (LWP 3608)  0xb7fe1424 in __kernel_vsyscall ()
  5 Thread 0xb6497b70 (LWP 3607)  0xb7fe1424 in __kernel_vsyscall ()
  4 Thread 0xb6c98b70 (LWP 3606)  0xb7fe1424 in __kernel_vsyscall ()
  3 Thread 0xb7499b70 (LWP 3605)  0xb7fe1424 in __kernel_vsyscall ()
  2 Thread 0xb7c9ab70 (LWP 3604)  0xb7fe1424 in __kernel_vsyscall ()
* 1 Thread 0xb7c9b6c0 (LWP 3603)  0x0804a178 in main ()

(gdb) break 601 thread 6
No line 601 in file "events.c".

(gdb) break call_connect.c:601 thread 6
No source file named call_connect.c.

Also I debugged my C code with -O0 -ggdb and still I can't watch variables. This is what I get when I try to read a char *ptext variable.

(gdb) print ptext
No symbol "ptext" in current context.
(gdb) watch ptext
No symbol "ptext" in current context.

Can somebody please help?

2 Answers 2

3

Although I have not extensively used gdb with pthreads but I have a few pointers which you might try out.

  1. You can switch to the thread you want to debug using thread threadnum where threadnum is the id (first column) displayed through info threads.

  2. Check the source directories being looked up for the file usinf show directories command. If the directory where your source resides is not in the list add it through directory <path_to_source> command

  3. While setting the breakpoints or watch use auto completion (generally <Tab>) to look for breakpoints and watches you can set.

Please check links under Thread Debugging section in YoLinux pthreads Tutorials for more details.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Your problem is that your program is compiled without debug info.

The most likely causes: either call_connect.c was compiled without -ggdb flag despite what you have claimed (examine your build log to verify that), or you have a "stray" -s on your link line (which would strip the executable).

2 Comments

Surely, gdb will tell you if it can't find the debug symbols once you've loaded up the binary ... ? Isn't this a way to quickly verify if the binary has debug symbols or not?
GDB is telling you exactly that. What do you think No source file named call_connect.c mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.