• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * gdb helper commands and functions for Linux kernel debugging
3 *
4 *  Kernel constants derived from include files.
5 *
6 * Copyright (c) 2016 Linaro Ltd
7 *
8 * Authors:
9 *  Kieran Bingham <kieran.bingham@linaro.org>
10 *
11 * This work is licensed under the terms of the GNU GPL version 2.
12 *
13 */
14
15#include <linux/clk-provider.h>
16#include <linux/fs.h>
17#include <linux/hrtimer.h>
18#include <linux/irq.h>
19#include <linux/mount.h>
20#include <linux/of_fdt.h>
21#include <linux/page_ext.h>
22#include <linux/radix-tree.h>
23#include <linux/slab.h>
24#include <linux/threads.h>
25#include <linux/vmalloc.h>
26
27/* We need to stringify expanded macros so that they can be parsed */
28
29#define STRING(x) #x
30#define XSTRING(x) STRING(x)
31
32#define LX_VALUE(x) LX_##x = x
33#define LX_GDBPARSED(x) LX_##x = gdb.parse_and_eval(XSTRING(x))
34
35/*
36 * IS_ENABLED generates (a || b) which is not compatible with python
37 * We can only switch on configuration items we know are available
38 * Therefore - IS_BUILTIN() is more appropriate
39 */
40#define LX_CONFIG(x) LX_##x = IS_BUILTIN(x)
41
42/* The build system will take care of deleting everything above this marker */
43<!-- end-c-headers -->
44
45import gdb
46
47LX_CONFIG(CONFIG_DEBUG_INFO_REDUCED)
48
49/* linux/clk-provider.h */
50if IS_BUILTIN(CONFIG_COMMON_CLK):
51    LX_GDBPARSED(CLK_GET_RATE_NOCACHE)
52
53/* linux/fs.h */
54LX_GDBPARSED(SB_RDONLY)
55LX_GDBPARSED(SB_SYNCHRONOUS)
56LX_GDBPARSED(SB_MANDLOCK)
57LX_GDBPARSED(SB_DIRSYNC)
58LX_GDBPARSED(SB_NOATIME)
59LX_GDBPARSED(SB_NODIRATIME)
60
61/* linux/htimer.h */
62LX_GDBPARSED(hrtimer_resolution)
63
64/* linux/irq.h */
65LX_GDBPARSED(IRQD_LEVEL)
66LX_GDBPARSED(IRQ_HIDDEN)
67
68/* linux/module.h */
69if IS_BUILTIN(CONFIG_MODULES):
70    LX_GDBPARSED(MOD_TEXT)
71    LX_GDBPARSED(MOD_DATA)
72    LX_GDBPARSED(MOD_RODATA)
73    LX_GDBPARSED(MOD_RO_AFTER_INIT)
74
75/* linux/mount.h */
76LX_VALUE(MNT_NOSUID)
77LX_VALUE(MNT_NODEV)
78LX_VALUE(MNT_NOEXEC)
79LX_VALUE(MNT_NOATIME)
80LX_VALUE(MNT_NODIRATIME)
81LX_VALUE(MNT_RELATIME)
82
83/* linux/threads.h */
84LX_VALUE(NR_CPUS)
85
86/* linux/of_fdt.h> */
87LX_VALUE(OF_DT_HEADER)
88
89/* linux/radix-tree.h */
90LX_GDBPARSED(RADIX_TREE_ENTRY_MASK)
91LX_GDBPARSED(RADIX_TREE_INTERNAL_NODE)
92LX_GDBPARSED(RADIX_TREE_MAP_SIZE)
93LX_GDBPARSED(RADIX_TREE_MAP_SHIFT)
94LX_GDBPARSED(RADIX_TREE_MAP_MASK)
95
96/* linux/vmalloc.h */
97LX_VALUE(VM_IOREMAP)
98LX_VALUE(VM_ALLOC)
99LX_VALUE(VM_MAP)
100LX_VALUE(VM_USERMAP)
101LX_VALUE(VM_DMA_COHERENT)
102
103/* linux/page_ext.h */
104if IS_BUILTIN(CONFIG_PAGE_OWNER):
105    LX_GDBPARSED(PAGE_EXT_OWNER)
106    LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED)
107
108/* linux/slab.h */
109LX_GDBPARSED(SLAB_RED_ZONE)
110LX_GDBPARSED(SLAB_POISON)
111LX_GDBPARSED(SLAB_KMALLOC)
112LX_GDBPARSED(SLAB_HWCACHE_ALIGN)
113LX_GDBPARSED(SLAB_CACHE_DMA)
114LX_GDBPARSED(SLAB_CACHE_DMA32)
115LX_GDBPARSED(SLAB_STORE_USER)
116LX_GDBPARSED(SLAB_PANIC)
117
118/* Kernel Configs */
119LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS)
120LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
121LX_CONFIG(CONFIG_HIGH_RES_TIMERS)
122LX_CONFIG(CONFIG_NR_CPUS)
123LX_CONFIG(CONFIG_OF)
124LX_CONFIG(CONFIG_TICK_ONESHOT)
125LX_CONFIG(CONFIG_GENERIC_IRQ_SHOW_LEVEL)
126LX_CONFIG(CONFIG_X86_LOCAL_APIC)
127LX_CONFIG(CONFIG_SMP)
128LX_CONFIG(CONFIG_X86_THERMAL_VECTOR)
129LX_CONFIG(CONFIG_X86_MCE_THRESHOLD)
130LX_CONFIG(CONFIG_X86_MCE_AMD)
131LX_CONFIG(CONFIG_X86_MCE)
132LX_CONFIG(CONFIG_X86_IO_APIC)
133LX_CONFIG(CONFIG_HAVE_KVM)
134LX_CONFIG(CONFIG_NUMA)
135LX_CONFIG(CONFIG_ARM64)
136LX_CONFIG(CONFIG_ARM64_4K_PAGES)
137LX_CONFIG(CONFIG_ARM64_16K_PAGES)
138LX_CONFIG(CONFIG_ARM64_64K_PAGES)
139if IS_BUILTIN(CONFIG_ARM64):
140    LX_VALUE(CONFIG_ARM64_PA_BITS)
141    LX_VALUE(CONFIG_ARM64_VA_BITS)
142    LX_VALUE(CONFIG_ARM64_PAGE_SHIFT)
143    LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER)
144LX_CONFIG(CONFIG_SPARSEMEM)
145LX_CONFIG(CONFIG_SPARSEMEM_EXTREME)
146LX_CONFIG(CONFIG_SPARSEMEM_VMEMMAP)
147LX_CONFIG(CONFIG_KASAN)
148LX_CONFIG(CONFIG_KASAN_GENERIC)
149LX_CONFIG(CONFIG_KASAN_SW_TAGS)
150LX_CONFIG(CONFIG_KASAN_HW_TAGS)
151if IS_BUILTIN(CONFIG_KASAN_GENERIC) or IS_BUILTIN(CONFIG_KASAN_SW_TAGS):
152    LX_VALUE(CONFIG_KASAN_SHADOW_OFFSET)
153LX_CONFIG(CONFIG_VMAP_STACK)
154if IS_BUILTIN(CONFIG_NUMA):
155    LX_VALUE(CONFIG_NODES_SHIFT)
156LX_CONFIG(CONFIG_DEBUG_VIRTUAL)
157LX_CONFIG(CONFIG_STACKDEPOT)
158LX_CONFIG(CONFIG_PAGE_OWNER)
159LX_CONFIG(CONFIG_SLUB_DEBUG)
160LX_CONFIG(CONFIG_SLAB_FREELIST_HARDENED)
161LX_CONFIG(CONFIG_MMU)
162