使用gdb

1、gdb调试

gdb 对于看系统内部是非常有用. 在这个级别精通调试器的使用要求对 gdb 命令有信心,
需要理解目标平台的汇编代码, 以及对应源码和优化的汇编码的能力.
LINUX DEVICE DRIVERS,3RD EDITION
调试器必须把内核作为一个应用程序来调用. 除了指定内核映象的文件名之外, 你需要在
命令行提供一个核心文件的名子. 对于一个运行的内核, 核心文件是内核核心映象,
/proc/kcore. 一个典型的 gdb 调用看来如下:
gdb /usr/src/linux/vmlinux /proc/kcore
第一个参数是非压缩的 ELF 内核可执行文件的名子, 不是 zImage 或者 bzImage 或者给
启动环境特别编译的任何东东.
gdb 命令行的第二个参数是核心文件的名子. 如同任何 /proc 中的文件, /proc/kcore
是在被读的时候产生的. 当 read 系统调用在 /proc 文件系统中执行时, 它映射到一个
数据产生函数,而不是一个数据获取函数; 我们已经在本章”使用 /proc 文件系统”一节中
利用了这个特点. kcore 用来代表内核”可执行文件”, 以一个核心文件的形式; 它是一个
巨大的文件, 因为他代表整个的内核地址空间, 对应于所有的物理内存. 从 gdb 中, 你
可查看内核变量,通过发出标准 gdb 命令. 例如, p jiffies 打印时钟的从启动到当前时
间的嘀哒数

weiqifa@weiqifa-Inspiron-3847:~/weiqifa/new_tm100/tm100$ vim wmkkernel 
weiqifa@weiqifa-Inspiron-3847:~/weiqifa/new_tm100/tm100$ find ./out/ -iname vmlinux
./out/target/product/mid713l_lp_lvds/obj/KERNEL_OBJ/arch/arm/boot/compressed/vmlinux
./out/target/product/mid713l_lp_lvds/obj/KERNEL_OBJ/vmlinux
^C
weiqifa@weiqifa-Inspiron-3847:~/weiqifa/new_tm100/tm100$ gdb ./out/target/product/mid713l_lp_lvds/obj/KERNEL_OBJ/vmlinux /proc/
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./out/target/product/mid713l_lp_lvds/obj/KERNEL_OBJ/vmlinux...done.
"/proc/" is not a core dump: Is a directory
(gdb) l* tpd_down
0xc05ca0ac is in tpd_down (/home/weiqifa/weiqifa/new_tm100/tm100/kernel/mediatek/custom/out/kernel/touchpanel/mtk_gslX680.c:689).
684     
685 }
686 #endif
687 
688 void tpd_down( int id, int x, int y, int p) 
689 {
690     print_info("============tpd_down id: %d, x:%d, y:%d============ \n", id, x, y);
691     while(1);
692     input_report_key(tpd->dev, BTN_TOUCH, 1);
693     input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 1);
(gdb) 

2、在内核驱动里面加上一个while(1);系统会不会挂掉

上面的代码就是我加的while(1)代码。
linux内核是进程调度的,系统肯定没有崩溃,但是你加代码的位置,这个驱动已经用不了了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值