How to debug problems in the Linux kernel module `init ()`?

I use remote (k) gdb to debug a problem in a module that causes a panic at boot, for example. when called init().

The stack trace shows what do_one_initcall(mod->init)causes the failure. To get the character file loaded into gdb, I need to get the address of the text section of the module and get it to load the module.

Since insmodbusybox (1.16.1) does not support -m, so I'm tied to grep modulename /proc/modules+ adding an offset from nmto figure out the address.

So, I ran into the problem of chicken and eggs here - to debug module loading, I need to load the module, but to load the module, I need to debug the problem ...

So, I'm now thinking about two options - is there a way to get address information:

  • by printk () in module initialization code
  • by printk () somewhere in the kernel code

all this before the call mod->init()- so I could place a breakpoint there, load the symbol file, click cand see its failure and write ...

+3
source share
1 answer

Can you create your code in the kernel, and not as a module? This can simplify call debugging init().

You can also set a breakpoint at do_one_initcall()and look at the address mod->initto get the download address.

+5
source

Source: https://habr.com/ru/post/1740437/


All Articles