Home | History | Annotate | Line # | Download | only in gdbscripts
module revision 1.1.12.1
      1  1.1.12.1   tls 
      2  1.1.12.1   tls # Copyright (c)2011,2013 YAMAMOTO Takashi,
      3  1.1.12.1   tls # All rights reserved.
      4  1.1.12.1   tls #
      5  1.1.12.1   tls # Redistribution and use in source and binary forms, with or without
      6  1.1.12.1   tls # modification, are permitted provided that the following conditions
      7  1.1.12.1   tls # are met:
      8  1.1.12.1   tls # 1. Redistributions of source code must retain the above copyright
      9  1.1.12.1   tls #    notice, this list of conditions and the following disclaimer.
     10  1.1.12.1   tls # 2. Redistributions in binary form must reproduce the above copyright
     11  1.1.12.1   tls #    notice, this list of conditions and the following disclaimer in the
     12  1.1.12.1   tls #    documentation and/or other materials provided with the distribution.
     13  1.1.12.1   tls #
     14  1.1.12.1   tls # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     15  1.1.12.1   tls # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  1.1.12.1   tls # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     17  1.1.12.1   tls # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     18  1.1.12.1   tls # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     19  1.1.12.1   tls # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     20  1.1.12.1   tls # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     21  1.1.12.1   tls # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     22  1.1.12.1   tls # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     23  1.1.12.1   tls # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     24  1.1.12.1   tls # SUCH DAMAGE.
     25  1.1.12.1   tls 
     26  1.1.12.1   tls # a macro to dump kernel modules
     27  1.1.12.1   tls 
     28  1.1.12.1   tls # printed addresses can be used for gdb add-symbol-file command.
     29  1.1.12.1   tls #
     30  1.1.12.1   tls # for example:
     31  1.1.12.1   tls #
     32  1.1.12.1   tls # % objdump -h puffs.kmod
     33  1.1.12.1   tls #     :
     34  1.1.12.1   tls #     :
     35  1.1.12.1   tls #     :
     36  1.1.12.1   tls # Sections:
     37  1.1.12.1   tls # Idx Name          Size      VMA               LMA               File off  Algn
     38  1.1.12.1   tls #   0 .text         0000c87c  0000000000000000  0000000000000000  00000040  2**2
     39  1.1.12.1   tls #                   CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
     40  1.1.12.1   tls #     :
     41  1.1.12.1   tls #     :
     42  1.1.12.1   tls #     :
     43  1.1.12.1   tls # 
     44  1.1.12.1   tls # 
     45  1.1.12.1   tls # (gdb) target kvm /dev/mem
     46  1.1.12.1   tls # #0  0xffffffff804f14d4 in mi_switch (l=0xffffffff80dfa020)
     47  1.1.12.1   tls #     at /siro/nbsd/src/sys/kern/kern_synch.c:720
     48  1.1.12.1   tls # 720                     prevlwp = cpu_switchto(l, newl, returning);
     49  1.1.12.1   tls # (gdb) modules                                                                   module puffs    0xffffffff810c6000-0xffffffff810ffcd0
     50  1.1.12.1   tls # module wmimsi
     51  1.1.12.1   tls # module wmihp
     52  1.1.12.1   tls # module wmieeepc
     53  1.1.12.1   tls #     :
     54  1.1.12.1   tls #     :
     55  1.1.12.1   tls #     :
     56  1.1.12.1   tls # (gdb) add-symbol-file /siro/nbsd/src/sys/modules/puffs/obj/puffs.kmod 0xffffffff810c6000+0x40
     57  1.1.12.1   tls # add symbol table from file "/siro/nbsd/src/sys/modules/puffs/obj/puffs.kmod" at
     58  1.1.12.1   tls #         .text_addr = 0xffffffff810c6040
     59  1.1.12.1   tls # (y or n) y
     60  1.1.12.1   tls # Reading symbols from /siro/nbsd/src/sys/modules/puffs/obj/puffs.kmod...done.
     61  1.1.12.1   tls # (gdb) disas puffs_getvnode
     62  1.1.12.1   tls # Dump of assembler code for function puffs_getvnode:   
     63  1.1.12.1   tls #    0xffffffff810c609a <+0>:     push   %rbp
     64  1.1.12.1   tls #    0xffffffff810c609b <+1>:     rorb   $0x45,-0x75(%rax)
     65  1.1.12.1   tls #    0xffffffff810c609f <+5>:     callq  0xffffffffc9dce9ed
     66  1.1.12.1   tls #    0xffffffff810c60a4 <+10>:    mov    $0x810d28a0,%ecx
     67  1.1.12.1   tls #    0xffffffff810c60aa <+16>:    mov    $0x16,%edx
     68  1.1.12.1   tls #    0xffffffff810c60af <+21>:    mov    $0x1,%esi
     69  1.1.12.1   tls 
     70       1.1  yamt define modules
     71       1.1  yamt 	set $h = module_list
     72  1.1.12.1   tls 	set $e = $h.tqh_first
     73       1.1  yamt 	while ($e != 0)
     74       1.1  yamt 		if ($e->mod_kobj != 0)
     75  1.1.12.1   tls 			printf "module %s\t0x%016lx-0x%016lx\n", \
     76       1.1  yamt 			    $e->mod_info.mi_name, \
     77       1.1  yamt 			    $e->mod_kobj->ko_address, \
     78       1.1  yamt 			    $e->mod_kobj->ko_address + $e->mod_kobj->ko_size
     79       1.1  yamt 		else
     80       1.1  yamt 			printf "module %s\n", \
     81       1.1  yamt 			    $e->mod_info.mi_name
     82       1.1  yamt 		end
     83       1.1  yamt 		set $e = $e->mod_chain.tqe_next
     84       1.1  yamt 	end
     85       1.1  yamt end
     86