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