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