• 使用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
    ");
            retval = -1;
        }
    	
        /* open file */
        fd = open(filename, O_RDWR);
    	printf("filename is %s
    ",filename);
    	printf("nand fd = %d
    ",fd);
        if (fd < 0) {
            db_error("can't open %s(%s)
    ", filename, strerror(errno));
            retval = -1;
        }
    	
    	/* if nand ok,return 0;otherwise,return -1 */
    	retval = ioctl(fd, DRAGON_BOARD_TEST);
    	printf("ioctl_retval = %d
    ",retval);
    	if (retval < 0) {
            db_error("error in ioctl(%s)......
    ", 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了,因为这貌似涉及到公司秘密问题。



  • 相关阅读:
    Linux开机启动和用户登录启动配置 .
    配置ssh信任
    .bash_profile和.bashrc的区别(如何设置生效)
    HttpUrlConnection底层实现和关于java host绑定ip即时生效的设置及分析
    一个shell写的urldecode代码
    用 DomIt! 做简单的 XML 处理工作
    windows主机安全设置 PHP5研究室
    介绍几个测试虚拟主机性能的工具 测速(全球范围),测同服网站,测路由
    Dreamhost开启allow_url_fopen采集功能教程
    配置Editplus的PHP调试环境
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6167907.html
Copyright © 2020-2023  润新知