带有 pthreads 的 GDB

发布于 2024-12-07 07:31:47 字数 998 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ映画 2024-12-14 07:31:47

虽然我没有广泛使用 gdbpthreads,但我有一些建议您可以尝试一下。

  1. 您可以使用thread threadnum切换到要调试的线程,其中threadnum是通过infothreads显示的id(第一列) 。

  2. 使用inf show paths 命令检查正在查找的文件的源目录。如果您的源所在的目录不在列表中,请通过 directory 命令添加它

  3. 在设置断点或监视时使用自动完成(通常< /code>) 查找可以设置的断点和监视。

请检查YoLinux pthreads 教程线程调试部分下的链接更多细节。

希望这有帮助!

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!

酒几许 2024-12-14 07:31:47

您的问题是您的程序是在没有调试信息的情况下编译的。

最可能的原因:无论您声明了什么,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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文