通过GDB调试内核(Kernel)和模块(Module)

一、   需求

在Linux内核开发过程中不可避免地地会面对如何调试内核的问题。比如printk() 是调试内核代码时最常用的一种技术,但是这种调试方法需要对问题产生的点有个大概的感知,这样才能有的放矢地在合适的代码处添加打印信息。

但是很多情况下,我们对问题产生的原因毫无头绪,也就不可能在茫茫的代码中添加printk,这时候我们就依赖于GDB构建Linux内核调试环境。本文以Linux 4.1.15为例,介绍调试环境的搭建过程。

二、   原理

参考内核文档:

linux/Documentation/gdb-kernel-debugging.txt

GDB调试过程中需要加载符号信息,即lx-symbols命令,该命令是实现在内核自带python脚本:/linux/scripts/gdb/vmlinux-gdb.py,这也是”build gdb 7.2+ (recommended: 7.4+) with python supportenabled”的原因。

三、   在虚拟机上搭建调试环境

1. 检查虚拟机上已安装的GDB和python

[admin@local /home/elvis]

$whichgdb

/usr/bin/gdb

[admin@local /home/elvis]

$/usr/bin/gdb-v

GNUgdb (GDB) Red Hat Enterprise Linux (7.0.1-37.el5)

Copyright(C) 2009 Free Software Foundation, Inc.

LicenseGPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

Thisis free software: you are free to change and redistribute it.

Thereis NO WARRANTY, to the extent permitted by law. Type "show copying"

and"show warranty" for details.

ThisGDB was configured as "x86_64-redhat-linux-gnu".

Forbug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

[admin@local /home/elvis]

$which python

/usr/bin/python

[admin@<

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值