GDB with pthreads
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) wat开发者_如何学编程ch ptext
No symbol "ptext" in current context.
Can somebody please help?
Although I have not extensively used gdb
with pthreads
but I have a few pointers which you might try out.
You can switch to the thread you want to debug using
thread threadnum
wherethreadnum
is the id (first column) displayed throughinfo threads
.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 throughdirectory <path_to_source>
commandWhile 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!
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).
精彩评论