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