linux - 使用 GDB 调试 netlink 通信

标签 linux timeout gdb netlink

我有一个多线程应用程序,它使用 netlink 套接字与内核模块通信。用户模式应用程序中的一个线程用作服务器,内核模块用作客户端。大致内核代码如下:

timeout = 3500;
netlink_unicast();
wait:
__set_current_state(TASK_INTERRUPTIBLE);
timeout = schedule_timeout(timeout);
__set_current_state(TASK_RUNNING);
if (!timeout)
{
    printk(KERN_ERR "No response received\n");
    return -1;
}
if (message_status != UPDATED)
{
   printk(KERN_ERR "Somebody woke us up before we got a reply. Time left %d\n", timeout);
   __set_current_state(TASK_INTERRUPTIBLE);
   goto wait;
}

当用户模式应用程序回复此消息时,message_status 变量在 netlink 回调中更新。所以基本上这个想法是发送一条消息,然后在最大超时时间等待回复。

现在,使用 gdb,如果我在 netlink 服务器线程在用户模式下调用的任何函数中添加一个断点,断点永远不会被击中,内核日志中会充斥着类似

的消息

Somebody woke us up before we got a reply. Time left 3499

Somebody woke us up before we got a reply. Time left 3499

Somebody woke us up before we got a reply. Time left 3499

Somebody woke us up before we got a reply. Time left 3499

..

..

Somebody woke us up before we got a reply. Time left 3498

直到我终于得到

No response received

是什么导致内核线程超时唤醒,我应该如何调试用户态代码?

PS:我在 RHEL 6.0 上使用 2.6.32-71.el6.x86_64

最佳答案

使用 gdb。在 gdb 中,您可以使用“信息线程”来查看线程列表。您可以使用命令“线程”跳转到特定线程,其中 n 是所需的线程。您可以使用“break : thread”设置要中断的特定线程。请参阅手册的这一部分以控制与线程停止相关的程序行为。 IE。您可以指定在您只处理一个线程时停止所有线程。 https://sourceware.org/gdb/onlinedocs/gdb/Thread-Stops.html#Thread-Stops

关于linux - 使用 GDB 调试 netlink 通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10821762/

相关文章:

python - 如何使用 Python subprocess.Popen 控制 gdb?

.net - 如何在 TeamCity Ubuntu Linux 上启用 NuGet 恢复?

linux - 递归查找所有不以注释开头的php文件

python - 在 Python 中打开文件时使用超时来防止死锁?

objective-c - "Current language: auto; currently objective-c"是什么意思?

c++ - 无法在Mac OS X上的Visual Code中调试C++

linux - 用于在 ubuntu 上运行 sublime text 3 的终端命令

c++ - Linux串口RAW模式

php 手动 session.gc_maxlifetime 在 Linux (Debian,Ubuntu) 下被忽略。如何设置备选?

scala - Apache 弗林克 : Count window with timeout