带有 pthreads 的 GDB
我有一个 C 程序,其中主函数创建线程,并且我必须调试一个线程。我正在使用 gdb,他也一样。但是,我无法“中断”或“监视”该程序的特定 C 文件上的变量。例如。我的线程 6 已编程并使用某些 C 文件,并且我必须在 call_connect.c 上的第 601 行处中断。这不可能吗?如果我尝试这样做,会发生这样的情况:
(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.
我还使用 -O0 -ggdb 调试了我的 C 代码,但仍然无法观察变量。 这是当我尝试读取 char *ptext 变量时得到的结果。
(gdb) print ptext
No symbol "ptext" in current context.
(gdb) watch ptext
No symbol "ptext" in current context.
有人可以帮忙吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我没有广泛使用
gdb
和pthreads
,但我有一些建议您可以尝试一下。您可以使用
thread threadnum
切换到要调试的线程,其中threadnum
是通过infothreads
显示的id(第一列) 。使用inf
show paths
命令检查正在查找的文件的源目录。如果您的源所在的目录不在列表中,请通过directory
命令添加它在设置断点或监视时使用自动完成(通常< /code>) 查找可以设置的断点和监视。
请检查YoLinux pthreads 教程中线程调试部分下的链接更多细节。
希望这有帮助!
Although I have not extensively used
gdb
withpthreads
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!
您的问题是您的程序是在没有调试信息的情况下编译的。
最可能的原因:无论您声明了什么,
call_connect.c
编译时都没有-ggdb
标志(检查您的构建日志以验证这一点),或者您有一个“杂散” "-s
放在链接行上(这将删除可执行文件)。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).