Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15339874
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2007-11-21 17:18:03

浅析modutils-2.4.27中insmod()程序--编译和gdb调试

文章来源:http://gliethttp.cublog.cn

因为其他事情,这些天linux没有多少时间来看,今天有点空闲时间,来讨论一下insmod的调试问题.
首先下载modutils-2.4.27.tar.bz2
下载地址:

//[root@localhost gliethttp]# tar jxvf modutils-2.4.27.tar.bz2
之后配置
//[root@localhost modutils-2.4.27]# ./configure
找到Makefile.common,对CFLAGS做如下修改,使我们的gdb能够进行跟踪源码调试:
CFLAGS        = -g#-O2 -Wall
之后让insmod.c文件内容发生变化,进而make时能够重新链接生成新的insmod等elf可执行文件,最后执行make.

先看看程序的执行流程:insmod/insmod.c->main()->insmod_main()->insmod_main_32()也就是INSMOD_MAIN()
/*hello.o在《浅析module-init-tools-3.2下insmod()和rmmod()两个函数--之1--编译篇》中已作介绍*/
//[root@localhost modutils-2.4.27]# make;insmod/insmod insmod/hello.o;rmmod hello
编译成功之后,我们就可以通过gdb来调试了,部分调试输出内容如下:
//[root@localhost modutils-2.4.27]# cd insmod/
//[root@localhost insmod]# gdb insmod
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) b insmod_main_32
Breakpoint 1 at 0x804c452: file insmod.c, line 1631.
(gdb) pwd
//查看当前gdb目录
Working directory /mnt/hgfs/glx_sourcecode/modutils-2.4.27/insmod.
//将hello.o驱动文件拷贝到/mnt/hgfs/glx_sourcecode/modutils-2.4.27/insmod目录下
//r hello.o 表示把hello.o作为被gdb调试程序insmod的参数传递过去,等同于insmod hello.o
(gdb) r hello.o
Starting program: /mnt/hgfs/glx_sourcecode/modutils-2.4.27/insmod/insmod hello.o

xxxxxxxxxx_gliethttp_xxxxxxxxxxxxx

Breakpoint 1, insmod_main_32 (argc=2, argv=0xbfffecd4) at insmod.c:1631
1631 struct option long_opts[] = {
(gdb) display argc
1: argc = 2
(gdb) display argv[0]
2: argv[0] = 0xbffffb45 "/mnt/hgfs/glx_sourcecode/modutils-2.4.27/insmod/insmod"
(gdb) display argv[1]
3: argv[1] = 0xbffffb7c "hello.o"
(gdb)
......
接下来就慢慢磕吧,大家好运[gliethttp_20071121]!

阅读(1640) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~