GDB调试Linux内核模块

关于GDB如何调试Linux内核,请参考我的另一篇文章:

Virtualbox环境通过GDB调试Linux内核_gdb能调试linux内核驱动吗-CSDN博客

调试内核模块与调试内核类似,一点区别是内核模块需要单独编译,编译时注意加入符号信息。在调试机进行远程调试时,需要载入这些符号信息,同时需要指定模块在内核中的地址。

1. 模块编译

下面是一个demo的模块示例 (demo_module.c),主要功能是当在命令行执行cat /proc/demo_proc 时,返回给用户空间一个消息:"Hello from the kernel!\n"

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>

#define PROCFS_NAME "demo_proc"

static struct proc_dir_entry *proc_file;

static ssize_t procfile_read(struct file *file, char __user *buffer, size_t len, loff_t *offset) {
    int ret;
    char *msg = "Hello from the kernel!\n";
    size_t msg_len = strlen(msg);

    if (*offset >= msg_len)
        return 0;

    if (*offset + len > msg_len)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值