Using GDB for debugging netlink communication
Hi, I have a multi-threaded application that communicates with a kernel module using netlink sockets. One of the threads in user mode application works as a server and kernel module works as a client. Roughly the kernel code is as follows: -------------------------8<------------------------------------------------8<------------------------------------- timeout = 3500; netlink_unicast(); __set_current_state(TASK_INTERRUPTIBLE); wait: 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; } -------------------------8<------------------------------------------------8<------------------------------------- The message_status variable is updated in the netlink callback when the user mode application replies to this message. So basically the idea is to send a message and then wait at max timeout jiffies for the reply. Now, using gdb, if I add a break point in any function that is called by netlink server thread in user mode, the break point is never hit and the kernel log is flooded with messages like -------------------------8<------------------------------------------------8<------------------------------------- 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 -------------------------8<------------------------------------------------8<------------------------------------- Until I finally get -------------------------8<------------------------------------------------8<------------------------------------- No response received -------------------------8<------------------------------------------------8<------------------------------------- What is causing the kernel thread to wake up from the timeout and how should I debug the user mode code? -- Best Regards, Ranjan PS: I am using 2.6.32-71.el6.x86_64 on RHEL 6.0
Hi... :) On Sat, Jul 21, 2012 at 10:46 PM, Ranjan Sinha <rnjn.sinha@gmail.com> wrote:
Now, using gdb, if I add a break point in any function that is called by netlink server thread in user mode, the break point is never hit and the kernel log is flooded with messages like -------------------------8<------------------------------------------------8<------------------------------------- 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 -------------------------8<------------------------------------------------8<-------------------------------------
I got a feeling that somehow gdb trap one or more signal received/sent by/to your application. Maybe you need to ignore that by setting it in your gdb (it's the same when you debug UML kernel using gdb). Unfortunately i forgot the exact command to do it. Another possibility is that, you're not "attaching" to right thread. Are you sure you have switched to the target thread? All above are strictly my speculation..... -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
participants (2)
-
Mulyadi Santosa -
Ranjan Sinha