利用gdb调试内核程序和用户程序

来源:互联网 发布:r软件使用教程 编辑:程序博客网 时间:2024/05/07 12:13

objdump  -x  obj  以某种分类信息的形式把目标文件的数据组织(被分为几大块)输出   
objdump  -t  obj  输出目标文件的符号表
objdump  -h  obj  输出目标文件的所有段概括
objdump  -j .text/.data -S  obj  
输出指定段的信息,大概就是反汇编原始码把

 用户程序调试:

Gdb 使用 gcc –g src.c

B 6 : 在第6行增加断点

n/s 单步到下一行

run 运行

 模块调试:

例:objdump –DSslt ./asd_driver.ko > dump.txt

生成的dump.txt 可以把源码和汇编码对应起来。对应关系不一定完全正确,但可以作为参考。

gdb ../asd_device/asd_driver.ko

(gdb) l  *phydev_map+0x16c

(gdb)info line *phydev_map+0x16c

若call trace 信息中包含了内核的一部分信息,可以如下调试

调试内核:

gdb /lib/modules/2.6.18-prep-gcov/build/vmlinux

GNU gdb Red Hat Linux (6.5-37.el5rh)

Copyright (C) 2006 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 "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/libthread_db.so.1".

 

(gdb) l * bio_get_nr_vecs+0x0

0xffffffff8003e705 is in bio_get_nr_vecs (/usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.x86_64/include/linux/blkdev.h:627).

622     extern void blk_execute_rq_nowait(request_queue_t *, struct gendisk *,

623                                       struct request *, int, rq_end_io_fn *);

624

625     static inline request_queue_t *bdev_get_queue(struct block_device *bdev)

626     {

627             return bdev->bd_disk->queue;

628     }

629

630     static inline void blk_run_backing_dev(struct backing_dev_info *bdi,

631                                            struct page *page)

 

 

原创粉丝点击