如何调试Linux内核模块的init_module()调用? [英] How to debug the init_module() call of a Linux kernel module?

查看:458
本文介绍了如何调试Linux内核模块的init_module()调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始Linux内核开发的第一步. 我有一些代码生成随insmod一起安装的.ko内核模块.我想调试安装模块时会发生什么,但遇到一些困难.

I am doing first steps into Linux kernel development. I have some code producing a .ko kernel module that I install with insmod. I would like a way to debug what happens when I install the module but I am facing some difficulties.

  1. 我需要调试对init_module的调用.我运行insmode时会调用此函数吗?

  1. I need to debug the call to init_module. Is this function called when I run insmode ?

我尝试使用insmod "/my/url/fil.ko" -m调试发生的情况,但是每次出现错误-1 Unknown symbol in module时,在/cat/log/message中我都可以看到错误unknown parameter -m

I try to use insmod "/my/url/fil.ko" -m to debug what happens but each time I got error -1 Unknown symbol in module while in /cat/log/message I can see the error unknown parameter -m

您知道是否可以使用GDB进行调试吗?

Do you know if there is a way to debug with GDB?

推荐答案

是的,使用insmod将init_module函数加载到内核后,就会立即调用它.您只需添加一行printk并在插入模块后立即验证它是否已打印.

Yes, the init_module function gets called as soon as you load it to the kernel using insmod. You can just add a line of printk and verify it being printed as soon as you insert the module.

您不能传递-m之类的参数来调试内核模块.

You cannot pass a parameter such as -m to debug the kernel module.

您只能使用MODULE_PARAMS传递要在编写的内核模块中处理的参数.

You can only pass parameters that are intended to be handled within the kernel module that you have written, using MODULE_PARAMS.

这篇关于如何调试Linux内核模块的init_module()调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆