简体   繁体   English

具有pthread的GDB

[英]GDB with pthreads

I have a C program where the main function creates threads and I have to debug one thread. 我有一个C程序,主要功能创建线程,并且我必须调试一个线程。 I am using gdb for he same. 我正在为他使用gdb。 However I cannot "break" or "watch" variables on specific C files of this program. 但是,我不能在该程序的特定C文件上“破坏”或“监视”变量。 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. 我的线程6被编程并使用某些C文件,我不得不在call_connect.c的第601行中断。 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. 我也用-O0 -ggdb调试了我的C代码,但仍然看不到变量。 This is what I get when I try to read a char *ptext variable. 这是我尝试读取char * ptext变量时得到的。

(gdb) print ptext
No symbol "ptext" in current context.
(gdb) watch 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. 尽管我还没有将gdbpthreads一起广泛使用,但是我有一些可以尝试的指针。

  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 . 您可以使用thread threadnum切换到要调试的thread threadnum ,其中threadnum是通过info threads显示的id(第一列)。

  2. Check the source directories being looked up for the file usinf show directories command. 检查正在查找的源目录中是否有文件usinf show directories命令。 If the directory where your source resides is not in the list add it through directory <path_to_source> command 如果源所在的目录不在列表中,请通过directory <path_to_source>命令将其添加

  3. While setting the breakpoints or watch use auto completion (generally <Tab> ) to look for breakpoints and watches you can set. 在设置断点或监视时,请使用自动完成功能(通常<Tab> )查找可以设置的断点和监视。

Please check links under Thread Debugging section in YoLinux pthreads Tutorials for more details. 请检查YoLinux pthreads教程中“ 线程调试”部分下的链接,以获取更多详细信息。

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). 最可能的原因:尽管您声明了什么, call_connect.c仍未使用-ggdb标志进行编译(请检查您的构建日志以进行验证),或者链接行上有“ stray” -s (这将剥离可执行文件) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM