2000-11-14 09:06:31

by Shmuel Hen

[permalink] [raw]
Subject: Q: using kdb to trap memory modifications


I'm trying to see when and how a certain variable is being modified and I
wonder how to get kdb to do that for me.

when I do 'insmod my_module' with my network driver, I noticed that
dev->refcnt is 0 at first and gets increased to 1 after calling
register_netdev. When I want to do 'rmmod my_module' somehow dev->refcnt is
at 2 before the call to unregister_netdev and so the kernel (2.4.0-test9)
won't let the module to unload. Since I don't increase it explicitly, I want
to know who does it for me and when to see if I'm doing anything wrong.

So, I modified my module to contain in the global section:
static void* ptr;

and in my module_init function I added:

ptr = (void*) &dev->refcnt;

after running 'insmod my_module' I used ksyms and found that ptr is at
address 0xd081eeb4.

after entering kdb, I did:

kdb> md 0xd081eeb4

0xd081eeb4 c470bedc 00000000 00000000 00000000
0xd081eec4 00000000 00000000 00000000 00000000

kdb> bph 0xc470bedc
Forced Breakpoint at.... #0 ...

kdb> be 0
kdb> go

When I try to return to normal shell, the system is totally hung and won't
even receive inputs from the remote serial terminal.
I tried bp, bpa and bpha, but the result is always the same.

Shmulik Hen
Software Engineer
Linux Advanced Networking Services
Network Communications Group, Israel (NCGj)
Intel Corporation Ltd.