scripts/gdb/vmalloc: fix vmallocinfo error
[linux-2.6-block.git] / scripts / gdb / linux / vmalloc.py
CommitLineData
852622bf
KYL
1# SPDX-License-Identifier: GPL-2.0
2#
3# Copyright (c) 2023 MediaTek Inc.
4#
5# Authors:
6# Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
7#
8
9import gdb
10import re
11from linux import lists, utils, stackdepot, constants, mm
12
6620999f
BW
13if constants.LX_CONFIG_MMU:
14 vmap_area_type = utils.CachedType('struct vmap_area')
15 vmap_area_ptr_type = vmap_area_type.get_type().pointer()
852622bf
KYL
16
17def is_vmalloc_addr(x):
18 pg_ops = mm.page_ops().ops
19 addr = pg_ops.kasan_reset_tag(x)
20 return addr >= pg_ops.VMALLOC_START and addr < pg_ops.VMALLOC_END
21
22class LxVmallocInfo(gdb.Command):
23 """Show vmallocinfo"""
24
25 def __init__(self):
26 super(LxVmallocInfo, self).__init__("lx-vmallocinfo", gdb.COMMAND_DATA)
27
28 def invoke(self, arg, from_tty):
6620999f
BW
29 if not constants.LX_CONFIG_MMU:
30 raise gdb.GdbError("Requires MMU support")
31
0040f2c5
KYL
32 nr_vmap_nodes = gdb.parse_and_eval('nr_vmap_nodes')
33 for i in range(0, nr_vmap_nodes):
34 vn = gdb.parse_and_eval('&vmap_nodes[%d]' % i)
35 for vmap_area in lists.list_for_each_entry(vn['busy']['head'], vmap_area_ptr_type, "list"):
36 if not vmap_area['vm']:
37 gdb.write("0x%x-0x%x %10d vm_map_ram\n" % (vmap_area['va_start'], vmap_area['va_end'],
38 vmap_area['va_end'] - vmap_area['va_start']))
39 continue
40 v = vmap_area['vm']
41 gdb.write("0x%x-0x%x %10d" % (v['addr'], v['addr'] + v['size'], v['size']))
42 if v['caller']:
43 gdb.write(" %s" % str(v['caller']).split(' ')[-1])
44 if v['nr_pages']:
45 gdb.write(" pages=%d" % v['nr_pages'])
46 if v['phys_addr']:
47 gdb.write(" phys=0x%x" % v['phys_addr'])
48 if v['flags'] & constants.LX_VM_IOREMAP:
49 gdb.write(" ioremap")
50 if v['flags'] & constants.LX_VM_ALLOC:
51 gdb.write(" vmalloc")
52 if v['flags'] & constants.LX_VM_MAP:
53 gdb.write(" vmap")
54 if v['flags'] & constants.LX_VM_USERMAP:
55 gdb.write(" user")
56 if v['flags'] & constants.LX_VM_DMA_COHERENT:
57 gdb.write(" dma-coherent")
58 if is_vmalloc_addr(v['pages']):
59 gdb.write(" vpages")
60 gdb.write("\n")
852622bf
KYL
61
62LxVmallocInfo()