]> Git Repo - linux.git/blob - scripts/gdb/linux/vmalloc.py
Merge tag 'input-for-v6.7-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor...
[linux.git] / scripts / gdb / linux / vmalloc.py
1 # SPDX-License-Identifier: GPL-2.0
2 #
3 # Copyright (c) 2023 MediaTek Inc.
4 #
5 # Authors:
6 #  Kuan-Ying Lee <[email protected]>
7 #
8
9 import gdb
10 import re
11 from linux import lists, utils, stackdepot, constants, mm
12
13 if constants.LX_CONFIG_MMU:
14     vmap_area_type = utils.CachedType('struct vmap_area')
15     vmap_area_ptr_type = vmap_area_type.get_type().pointer()
16
17 def 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
22 class 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):
29         if not constants.LX_CONFIG_MMU:
30             raise gdb.GdbError("Requires MMU support")
31
32         vmap_area_list = gdb.parse_and_eval('vmap_area_list')
33         for vmap_area in lists.list_for_each_entry(vmap_area_list, vmap_area_ptr_type, "list"):
34             if not vmap_area['vm']:
35                 gdb.write("0x%x-0x%x %10d vm_map_ram\n" % (vmap_area['va_start'], vmap_area['va_end'],
36                     vmap_area['va_end'] - vmap_area['va_start']))
37                 continue
38             v = vmap_area['vm']
39             gdb.write("0x%x-0x%x %10d" % (v['addr'], v['addr'] + v['size'], v['size']))
40             if v['caller']:
41                 gdb.write(" %s" % str(v['caller']).split(' ')[-1])
42             if v['nr_pages']:
43                 gdb.write(" pages=%d" % v['nr_pages'])
44             if v['phys_addr']:
45                 gdb.write(" phys=0x%x" % v['phys_addr'])
46             if v['flags'] & constants.LX_VM_IOREMAP:
47                 gdb.write(" ioremap")
48             if v['flags'] & constants.LX_VM_ALLOC:
49                 gdb.write(" vmalloc")
50             if v['flags'] & constants.LX_VM_MAP:
51                 gdb.write(" vmap")
52             if v['flags'] & constants.LX_VM_USERMAP:
53                 gdb.write(" user")
54             if v['flags'] & constants.LX_VM_DMA_COHERENT:
55                 gdb.write(" dma-coherent")
56             if is_vmalloc_addr(v['pages']):
57                 gdb.write(" vpages")
58             gdb.write("\n")
59
60 LxVmallocInfo()
This page took 0.033212 seconds and 4 git commands to generate.