使用objdump调试驱动

最近在调式一个判断nand是好的还是坏的驱动+测试程序,于是有了以下的调式过程,似乎自己也学到了一点知识,所以记录一下。

这篇文章主要是讲述调式驱动的一个方法而已。

先来看看测试程序

#include <string.h>
#include <errno.h>
#include "dragonboard_inc.h"
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

/* just define an ioctl cmd for nand test*/
#define DRAGON_BOARD_TEST    _IO(‘V‘,55)  

int main(int argc, char *argv[])
{
    char filename[256];
    int fd;
    int retval = -1;

    if (argc == 2) {
        strncpy(filename, argv[1], 256);
    }
    else {
        db_error("Usage: nandrw FILE\n");
        retval = -1;
    }

    /* open file */
    fd = open(filename, O_RDWR);
	printf("filename is %s\n",filename);
	printf("nand fd = %d\n",fd);
    if (fd < 0) {
        db_error("can‘t open %s(%s)\n", filename, strerror(errno));
        retval = -1;
    }

	/* if nand ok,return 0;otherwise,return -1 */
	retval = ioctl(fd, DRAGON_BOARD_TEST);
	printf("ioctl_retval = %d\n",retval);
	if (retval < 0) {
        db_error("error in ioctl(%s)......\n", strerror(errno));
				return retval;
    }
    /* TEST OK */
    return retval;
}

测试用例很简单,先打开/dev/nanda的设备节点,用于返回fd给ioctl用, ioctl里的cmd = DRAGON_BOARD_TEST,这是底层实现。

ioctl调用完了就返回,如果返回0表示nand是好的,否则表示nand是坏的。底层如何实现,我就不细说了。

这里需要提的是,测试用例并没有主动调用close(fd),但是,但是,但是,你万万不要忘了,系统是会自动回收的,系统会帮你调用close函数。

于是有了下面这个bug 的log信息:

[    7.947228] Unable to handle kernel paging request at virtual address ed9f4b00
[    7.956339] pgd = d78a8000
[    7.956876] [ed9f4b00] *pgd=00000000
[    7.956876] Internal error: Oops: 80000005 [#1] PREEMPT SMP ARM
[    7.956876] Modules linked in: sunxi_keyboard ft5x_ts nand(O) lcd disp
[    7.956876] CPU: 0    Tainted: G           O  (3.4.39 #21)
[    7.956876] PC is at 0xed9f4b00
[    7.956876] LR is at nand_blk_release+0x24/0x28 [nand]
[    7.956876] pc : [<ed9f4b00>]    lr : [<bf116ed4>]    psr: a0000033
[    7.956876] sp : d76abe08  ip : d76abe18  fp : d76abe14
[    7.956876] r10: d7dc5998  r9 : d7740a90  r8 : d7c02650
[    7.956876] r7 : d7854000  r6 : 0000001f  r5 : bf11719c  r4 : bf14b828
[    7.956876] r3 : ed9f4b01  r2 : d76abe00  r1 : 0000ffff  r0 : d7854400
[    7.956876] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment user
[    7.956876] Control: 10c5387d  Table: 578a806a  DAC: 00000015
[    7.956876]
[    7.956876] PC: 0xed9f4a80:
[    7.956876] 4a80  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4aa0  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4ac0  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4ae0  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b00  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b20  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b40  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b60  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876]
[    7.956876] SP: 0xd76abd88:
[    7.956876] bd88  c09a7b40 c0e769e4 d76abdb4 d76abda0 c0062dec c0085640 ed9f4b00 a0000033
[    7.956876] bda8  ffffffff d76abdf4 d76abe14 d76abdc0 c0010438 c000a25c d7854400 0000ffff
[    7.956876] bdc8  d76abe00 ed9f4b01 bf14b828 bf11719c 0000001f d7854000 d7c02650 d7740a90
[    7.956876] bde8  d7dc5998 d76abe14 d76abe18 d76abe08 bf116ed4 ed9f4b00 a0000033 ffffffff
[    7.956876] be08  d76abe2c d76abe18 bf1171c8 bf116ebc bf14b7f8 d7c02640 d76abe5c d76abe30
[    7.956876] be28  c0134da0 bf1171a8 d7c027a0 d7c02640 0000001f d7c02650 d7776688 00000000
[    7.956876] be48  d7740a90 d7dc5998 d76abe7c d76abe60 c0134f5c c0134ce0 d7776680 d780f070
[    7.956876] be68  00000008 d7776688 d76abe8c d76abe80 c0134f94 c0134e44 d76abec4 d76abe90
[    7.956876]
[    7.956876] IP: 0xd76abd98:
[    7.956876] bd98  c0062dec c0085640 ed9f4b00 a0000033 ffffffff d76abdf4 d76abe14 d76abdc0
[    7.956876] bdb8  c0010438 c000a25c d7854400 0000ffff d76abe00 ed9f4b01 bf14b828 bf11719c
[    7.956876] bdd8  0000001f d7854000 d7c02650 d7740a90 d7dc5998 d76abe14 d76abe18 d76abe08
[    7.956876] bdf8  bf116ed4 ed9f4b00 a0000033 ffffffff d76abe2c d76abe18 bf1171c8 bf116ebc
[    7.956876] be18  bf14b7f8 d7c02640 d76abe5c d76abe30 c0134da0 bf1171a8 d7c027a0 d7c02640
[    7.956876] be38  0000001f d7c02650 d7776688 00000000 d7740a90 d7dc5998 d76abe7c d76abe60
[    7.956876] be58  c0134f5c c0134ce0 d7776680 d780f070 00000008 d7776688 d76abe8c d76abe80
[    7.956876] be78  c0134f94 c0134e44 d76abec4 d76abe90 c01045a8 c0134f78 00000000 00000000
[    7.956876]
[    7.956876] FP: 0xd76abd94:
[    7.956876] bd94  d76abda0 c0062dec c0085640 ed9f4b00 a0000033 ffffffff d76abdf4 d76abe14
[    7.956876] bdb4  d76abdc0 c0010438 c000a25c d7854400 0000ffff d76abe00 ed9f4b01 bf14b828
[    7.956876] bdd4  bf11719c 0000001f d7854000 d7c02650 d7740a90 d7dc5998 d76abe14 d76abe18
[    7.956876] bdf4  d76abe08 bf116ed4 ed9f4b00 a0000033 ffffffff d76abe2c d76abe18 bf1171c8
[    7.956876] be14  bf116ebc bf14b7f8 d7c02640 d76abe5c d76abe30 c0134da0 bf1171a8 d7c027a0
[    7.956876] be34  d7c02640 0000001f d7c02650 d7776688 00000000 d7740a90 d7dc5998 d76abe7c
[    7.956876] be54  d76abe60 c0134f5c c0134ce0 d7776680 d780f070 00000008 d7776688 d76abe8c
[    7.956876] be74  d76abe80 c0134f94 c0134e44 d76abec4 d76abe90 c01045a8 c0134f78 00000000
[    7.956876]
[    7.956876] R0: 0xd7854380:
[    7.956876] 4380  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 43a0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 43c0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 43e0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 4400  bf14b828 ee367b0e ee205b07 ee376b02 eeb5cb05 ee311bc0 eef18b06 ee0efa10
[    7.956876] 4420  bf48cb0e 5b41eeb1 eeb0d401 eeb55b41 eef16bc0 bf48fa10 7b46eeb1 eeb0d401
[    7.956876] 4440  eeb47b46 eef15bc7 f301fa10 ee36839e 4bda7b48 ed93447b ee316b00 ed9d7b07
[    7.956876] 4460  ee371b02 ee317b06 ee399b07 ed9f4b08 4bd37bc0 ed93447b ee201b00 ee246b07
[    7.956876]
[    7.956876] R2: 0xd76abd80:
[    7.956876] bd80  00000000 c00d09b4 c09a7b40 c0e769e4 d76abdb4 d76abda0 c0062dec c0085640
[    7.956876] bda0  ed9f4b00 a0000033 ffffffff d76abdf4 d76abe14 d76abdc0 c0010438 c000a25c
[    7.956876] bdc0  d7854400 0000ffff d76abe00 ed9f4b01 bf14b828 bf11719c 0000001f d7854000
[    7.956876] bde0  d7c02650 d7740a90 d7dc5998 d76abe14 d76abe18 d76abe08 bf116ed4 ed9f4b00
[    7.956876] be00  a0000033 ffffffff d76abe2c d76abe18 bf1171c8 bf116ebc bf14b7f8 d7c02640
[    7.956876] be20  d76abe5c d76abe30 c0134da0 bf1171a8 d7c027a0 d7c02640 0000001f d7c02650
[    7.956876] be40  d7776688 00000000 d7740a90 d7dc5998 d76abe7c d76abe60 c0134f5c c0134ce0
[    7.956876] be60  d7776680 d780f070 00000008 d7776688 d76abe8c d76abe80 c0134f94 c0134e44
[    7.956876]
[    7.956876] R3: 0xed9f4a81:
[    7.956876] 4a80  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4aa0  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4ac0  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4ae0  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b00  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b20  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b40  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b60  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876] 4b80  ******** ******** ******** ******** ******** ******** ******** ********
[    7.956876]
[    7.956876] R7: 0xd7853f80:
[    7.956876] 3f80  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 3fa0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 3fc0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 3fe0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 4000  0000005d 00000000 00000001 646e616e 00000061 00000000 00000000 00000000
[    7.956876] 4020  00000000 00000000 00000000 00000000 00000000 00000000 d777c880 00000000
[    7.956876] 4040  00000000 00000000 00000200 00000000 00000000 00000000 00000000 00000000
[    7.956876] 4060  00000000 d79e4f40 d777c640 d776a22c d79e5e0c d81b3b40 d80c3d00 c097e5c8
[    7.956876]
[    7.956876] R8: 0xd7c025d0:
[    7.956876] 25d0  00000000 00000000 d7c025d8 d7c025d8 00000000 00000000 00000000 c06496fc
[    7.956876] 25f0  000200d0 d7761b70 00000000 00000000 d7c02600 d7c02600 00000000 d7c0260c
[    7.956876] 2610  d7c0260c d7c02440 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 2630  00000000 00000000 00000000 00000000 05d00000 00000000 d7c026d0 00000000
[    7.956876] 2650  00000000 00000000 00000000 d7c0265c d7c0265c d78e73c0 d780f1ac d780f1ac
[    7.956876] 2670  00000000 00000000 00000000 00000000 d7c02680 d7c02680 d7c02640 00001000
[    7.956876] 2690  d7854040 00000000 00000000 d7854000 d760c078 d7c02aa4 c096d70c 00000000
[    7.956876] 26b0  00000000 00000001 00000000 00000000 d7c026c0 d7c026c0 00000000 00000000
[    7.956876]
[    7.956876] R9: 0xd7740a10:
[    7.956876] 0a10  d7740a10 d7740a10 d7740a18 d7740a18 d7740a20 d7740a20 00000000 d800ba40
[    7.956876] 0a30  00000000 00000000 00000017 00000000 00000000 00000000 00000000 00000000
[    7.956876] 0a50  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.956876] 0a70  00000000 00000000 00000000 00000000 d801fd00 d801fd00 d8021380 d7d26aa8
[    7.956876] 0a90  d7c01f70 d810dc00 00000020 c0940774 00000001 d7740cec d7740cec d80212ec
[    7.956876] 0ab0  d7740dac d810dc8c d7740f34 d781aec0 d7740d00 d7740dc0 d7740ac8 d7740ac8
[    7.956876] 0ad0  d7740ad0 d7740ad0 d7740ad8 d7740ad8 d7740ae0 d7740ae0 00000000 d800ba40
[    7.956876] 0af0  00000000 00000000 00000014 00000000 00000000 00000000 00000000 00000000
[    7.956876]
[    7.956876] R10: 0xd7dc5918:
[    7.956876] 5918  d7cda1a8 c12872e0 d7dc52b0 bf51d0bd 0000000f d7dc5934 d7e0ce58 74736574
[    7.956876] 5938  6e6f635f 2e676966 00786566 00000000 00000000 00000000 00000000 00000000
[    7.956876] 5958  00000000 00000000 00000000 c0652fc0 d782fc00 00000002 00000000 d782fc94
[    7.956876] 5978  d782fc94 d7dc5324 d7dc5324 d7dc5984 d7dc5984 d7e0cefc d7e0cefc 00000000
[    7.956876] 5998  00000088 00000004 00000000 c128ba94 d7c01f70 12770052 00000005 d7dc59bc
[    7.956876] 59b8  d780f070 646e616e 00000061 00000000 00000000 00000000 00000000 00000000
[    7.956876] 59d8  00000000 00000000 00000002 00000000 00000000 c0648a40 d810dc00 00000000
[    7.956876] 59f8  00000000 d7dc59fc d7dc59fc d7d2a20c d7d23d34 d7dc5a0c d7dc5a0c d780f114
[    7.956876] Process nandrw (pid: 159, stack limit = 0xd76aa2f8)
[    7.956876] Stack: (0xd76abe08 to 0xd76ac000)
[    7.956876] be00:                   d76abe2c d76abe18 bf1171c8 bf116ebc bf14b7f8 d7c02640
[    7.956876] be20: d76abe5c d76abe30 c0134da0 bf1171a8 d7c027a0 d7c02640 0000001f d7c02650
[    7.956876] be40: d7776688 00000000 d7740a90 d7dc5998 d76abe7c d76abe60 c0134f5c c0134ce0
[    7.956876] be60: d7776680 d780f070 00000008 d7776688 d76abe8c d76abe80 c0134f94 c0134e44
[    7.956876] be80: d76abec4 d76abe90 c01045a8 c0134f78 00000000 00000000 d76abec4 d7776680
[    7.956876] bea0: 00000000 d8038380 d8038388 00000028 d76aa000 00000000 d76abee4 d76abec8
[    7.956876] bec0: c0100dc4 c0104494 d80383fc d8038380 00000000 00000001 d76abf0c d76abee8
[    7.956876] bee0: c00397cc c0100d50 d78e73c0 d8038380 d78e7680 000000f8 c00109e8 00000000
[    7.956876] bf00: d76abf2c d76abf10 c00398c0 c0039738 00800000 d78e73c0 00000000 d76aa000
[    7.956876] bf20: d76abf74 d76abf30 c0039b80 c0039884 d76abf6c 00000001 c0102b08 c013ae84
[    7.956876] bf40: 00000000 00000000 d76abf64 d793eb80 00000000 d76aa000 000000f8 c00109e8
[    7.956876] bf60: d76aa000 00000000 d76abf94 d76abf78 c003a384 c00398d0 000a27f0 b6fc475c
[    7.956876] bf80: 00000000 000000f8 d76abfa4 d76abf98 c003a3d0 c003a2f8 00000000 d76abfa8
[    7.956876] bfa0: c0010780 c003a3bc 000a27f0 b6fc475c 00000000 000a27dc ffffffff 00000000
[    7.956876] bfc0: 000a27f0 b6fc475c 00000000 000000f8 b6fc6000 00000000 b6fc6000 00000000
[    7.956876] bfe0: b6fee000 bede1b48 b6eb6494 b6f23964 60000010 00000000 587c1821 587c1c21
[    7.956876] [<bf116ed4>] (nand_blk_release+0x24/0x28 [nand]) from [<bf1171c8>] (nand_release+0x2c/0x44 [nand])
[    7.956876] [<bf1171c8>] (nand_release+0x2c/0x44 [nand]) from [<c0134da0>] (__blkdev_put+0xcc/0x164)
[    7.956876] [<c0134da0>] (__blkdev_put+0xcc/0x164) from [<c0134f5c>] (blkdev_put+0x124/0x134)
[    7.956876] [<c0134f5c>] (blkdev_put+0x124/0x134) from [<c0134f94>] (blkdev_close+0x28/0x2c)
[    7.956876] [<c0134f94>] (blkdev_close+0x28/0x2c) from [<c01045a8>] (fput+0x120/0x228)
[    7.956876] [<c01045a8>] (fput+0x120/0x228) from [<c0100dc4>] (filp_close+0x80/0x8c)
[    7.956876] [<c0100dc4>] (filp_close+0x80/0x8c) from [<c00397cc>] (put_files_struct+0xa0/0xfc)
[    7.956876] [<c00397cc>] (put_files_struct+0xa0/0xfc) from [<c00398c0>] (exit_files+0x48/0x4c)
[    7.956876] [<c00398c0>] (exit_files+0x48/0x4c) from [<c0039b80>] (do_exit+0x2bc/0x7d0)
[    7.956876] [<c0039b80>] (do_exit+0x2bc/0x7d0) from [<c003a384>] (do_group_exit+0x98/0xc4)
[    7.956876] [<c003a384>] (do_group_exit+0x98/0xc4) from [<c003a3d0>] (__wake_up_parent+0x0/0x30)
[    7.956876] [<c003a3d0>] (__wake_up_parent+0x0/0x30) from [<c0010780>] (ret_fast_syscall+0x0/0x30)
[    7.956876] Code: bad PC value
[    9.177219] ---[ end trace b1efa7b6baf6b056 ]---
[    9.182375] Fixing recursive fault but reboot is needed!

从上面的log可以看出是调用nand_blk_release函数的时候出错了,为什么会出错,pc指针的操作错误。从而证明了,即使没有主动调用close函数,系统也会在自动回收资源的时候,帮你调用close函数。

重点要说的是,调式方法:

1.先找到nand_blk_release是在哪个文件编译出来的,比如:我的是nand_blk.c

2.arm-none-linux-gnueabi-objdump -S nand_blk.o > ~/nand.S

3.分析nand.S,它是一个C语言+汇编的文件,比分析全汇编的文件方便多了。

这里就不详细分析nand.S了,因为这貌似涉及到公司秘密问题。

时间: 2024-11-03 19:13:50

使用objdump调试驱动的相关文章

Window10中利用Windbg与虚拟机(window7)中调试驱动建立方法

想起自己的windbg配置就转载:eqera的windows内核调试配置,真的是获益良多希望他不会介意我转载他的博客,帮了我很多,记录下来给我也给大家, 其中我主要看的是VMWare的pipe建立,而我有些分享是在vs2015中打上DDK,然后在开始菜单window kits下找见windbgx86或者是你想要用的类型,然后 发送快捷方式到桌面利于以后用.发到桌面后,在属性插入你放置的的符号的路径,让然最后别忘了在windbg检查路径是否正确. eqera他的解述给了我很多帮助,可以耐心解读.下

kobox: key_proc.c -v1 如何使用proc文件系统调试驱动

使用proc文件系统可以很方便调试驱动,查看驱动中的一些数据 平台:TQ2440 系统版本: [email protected]:/mnt/shared/kobox# uname -a Linux ubuntu 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux 其实在3.x中创建proc文件系统和在2.x中创建是有所区别的,这里需要注意下,在2.6.x中创建起来更加方便 这里

实战windbg调试驱动例子

关于VM和WINDBG的基本配置请参考相关的文档.(在这里给各位一篇不错的文章,就是jiurl老大写的<  利用VM使用windbg  >) 好了,废话少说,让我们整点干的 :-)既然我们要分析的是sr.sys,当然我们先要看的就是目标机加载的驱动程序的位置了,sr.sys是XP系统系统还原的主体部分,它是建立在NTFS文件分区格式下的一个驱动,说白了 sr.sys其实就是ntfs.sys的filter driver.kd>!driversBase       Code Size    

YJX_Driver_014_VM+Wlndbg调试驱动

1. [120]以 第12课 的源码为例 [160]用 DDK 重新编译源码 [210]为了便于调试,我们下一个断点(ZC: 直接在源码里面下断点啊?),∵ 在入口函数那里下断点不太好下(ZC: 为什么?),我们可以在 卸载例程 里面下一个断点. [250]如果需要在 入口函数那里就开始跟的话,需要在DriverEntry里面加代码 “ __asm int 3; // 也就是一条 0xCC指令 ” [285]重新编译一下 [325]驱动文件"DDK_HelloWorld.sys"改名为

windbg + vmware调试驱动-环境搭建

1.vmware设置 “VirtaulMachineSettings”---> “Hardware”选项中----> 点击“Add”添加一个串口设备SeiallPort----> “Next”----> 在SerialPort里选中“Output to named pipe”----> “next”---->“Finish” 最后,回到 “Virtual Machine Settings”页面时,在“I/O Mode” 里选中“Yield CPU on poll” 这样

VM 调试驱动设置

"C:\Program Files\Debugging Tools for Windows (x86)\windbg.exe" -k com:pipe,port=\\.\pipe\com_1,baud=115200  -y E:\SourceCode\sys\objfre_wnet_x86\i386 -srcpath E:\SourceCode\sys 1. windbg.exe 快捷方式的目标设置为: "D:\Common Tools\Debugging Tools for

STM32下载调试驱动问题

No Cortex-m SW device found解决办法 16.07.14 今天工作,遇到一个问题:用jlink采用SW下载模式时,一直显示No Cortex-m SW device found.驱动都是装好的,之前采用20pin的jtack下载模式都是好好的,换装了好几次驱动,因为本机是win10,以为可能是win10的兼容性问题,就换用win XP虚拟机,但还是未能解决这一问题.直到老板说在他电脑上可用,我灵机一动,合不把他的驱动拷过来? Jlink的驱动一般网上下载为宜安装包,就和正

Windows7驱动调试小Tips

v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colb

设备驱动调试和移植的一般方法

做linux底层软件工作也有两年了,算上研究生时期对底层软件的研究,加起来也快四年了.慢慢地发现有必要总结一些一般性的方法了.因为一般性的方法有宏观上的指导意义,以后调试和移植驱动时,经常性地回味这些一般性的方法可以防止自己犯同样的错误,进而少走弯路,以最高的效率完成工作. 当谈到底层软件,我们一般都会想到bootloader.BSP.device driver.linux kernel等等.这篇文章将会着重介绍linux device driver调试的一般性方法.另外,关于设备驱动移植的方法