Skip to content

Commit 8214154

Browse files
Kuan-Ying Leeakpm00
authored andcommitted
scripts/gdb/modules: add get module text support
When we get an text address from coredump and we cannot find this address in vmlinux, it might located in kernel module. We want to know which kernel module it located in. This GDB scripts can help us to find the target kernel module. (gdb) lx-getmod-by-textaddr 0xffff800002d305ac 0xffff800002d305ac is in kasan_test.ko Link: https://lkml.kernel.org/r/20230808083020.22254-3-Kuan-Ying.Lee@mediatek.com Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: Chinwen Chang <chinwen.chang@mediatek.com> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: Qun-Wei Lin <qun-wei.lin@mediatek.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 11f9565 commit 8214154

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

scripts/gdb/linux/modules.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,35 @@ def invoke(self, arg, from_tty):
9797

9898
gdb.write("\n")
9999

100-
101100
LxLsmod()
101+
102+
def help():
103+
t = """Usage: lx-getmod-by-textaddr [Heximal Address]
104+
Example: lx-getmod-by-textaddr 0xffff800002d305ac\n"""
105+
gdb.write("Unrecognized command\n")
106+
raise gdb.GdbError(t)
107+
108+
class LxFindTextAddrinMod(gdb.Command):
109+
'''Look up loaded kernel module by text address.'''
110+
111+
def __init__(self):
112+
super(LxFindTextAddrinMod, self).__init__('lx-getmod-by-textaddr', gdb.COMMAND_SUPPORT)
113+
114+
def invoke(self, arg, from_tty):
115+
args = gdb.string_to_argv(arg)
116+
117+
if len(args) != 1:
118+
help()
119+
120+
addr = gdb.Value(int(args[0], 16)).cast(utils.get_ulong_type())
121+
for mod in module_list():
122+
mod_text_start = mod['mem'][constants.LX_MOD_TEXT]['base']
123+
mod_text_end = mod_text_start + mod['mem'][constants.LX_MOD_TEXT]['size'].cast(utils.get_ulong_type())
124+
125+
if addr >= mod_text_start and addr < mod_text_end:
126+
s = "0x%x" % addr + " is in " + mod['name'].string() + ".ko\n"
127+
gdb.write(s)
128+
return
129+
gdb.write("0x%x is not in any module text section\n" % addr)
130+
131+
LxFindTextAddrinMod()

0 commit comments

Comments
 (0)