Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 1d51b370a0f8f642f4fc84c795fbedac0fcdbbd2 239 lines 7.8 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _KDB_H 3#define _KDB_H 4 5/* 6 * Kernel Debugger Architecture Independent Global Headers 7 * 8 * Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved. 9 * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com> 10 * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com> 11 */ 12 13#include <linux/list.h> 14#include <linux/smp.h> 15 16/* Shifted versions of the command enable bits are be used if the command 17 * has no arguments (see kdb_check_flags). This allows commands, such as 18 * go, to have different permissions depending upon whether it is called 19 * with an argument. 20 */ 21#define KDB_ENABLE_NO_ARGS_SHIFT 10 22 23typedef enum { 24 KDB_ENABLE_ALL = (1 << 0), /* Enable everything */ 25 KDB_ENABLE_MEM_READ = (1 << 1), 26 KDB_ENABLE_MEM_WRITE = (1 << 2), 27 KDB_ENABLE_REG_READ = (1 << 3), 28 KDB_ENABLE_REG_WRITE = (1 << 4), 29 KDB_ENABLE_INSPECT = (1 << 5), 30 KDB_ENABLE_FLOW_CTRL = (1 << 6), 31 KDB_ENABLE_SIGNAL = (1 << 7), 32 KDB_ENABLE_REBOOT = (1 << 8), 33 /* User exposed values stop here, all remaining flags are 34 * exclusively used to describe a commands behaviour. 35 */ 36 37 KDB_ENABLE_ALWAYS_SAFE = (1 << 9), 38 KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1, 39 40 KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT, 41 KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ 42 << KDB_ENABLE_NO_ARGS_SHIFT, 43 KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE 44 << KDB_ENABLE_NO_ARGS_SHIFT, 45 KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ 46 << KDB_ENABLE_NO_ARGS_SHIFT, 47 KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE 48 << KDB_ENABLE_NO_ARGS_SHIFT, 49 KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT 50 << KDB_ENABLE_NO_ARGS_SHIFT, 51 KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL 52 << KDB_ENABLE_NO_ARGS_SHIFT, 53 KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL 54 << KDB_ENABLE_NO_ARGS_SHIFT, 55 KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT 56 << KDB_ENABLE_NO_ARGS_SHIFT, 57 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE 58 << KDB_ENABLE_NO_ARGS_SHIFT, 59 KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT, 60 61 KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */ 62 KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */ 63} kdb_cmdflags_t; 64 65typedef int (*kdb_func_t)(int, const char **); 66 67/* The KDB shell command table */ 68typedef struct _kdbtab { 69 char *name; /* Command name */ 70 kdb_func_t func; /* Function to execute command */ 71 char *usage; /* Usage String for this command */ 72 char *help; /* Help message for this command */ 73 short minlen; /* Minimum legal # cmd chars required */ 74 kdb_cmdflags_t flags; /* Command behaviour flags */ 75 struct list_head list_node; /* Command list */ 76} kdbtab_t; 77 78#ifdef CONFIG_KGDB_KDB 79#include <linux/init.h> 80#include <linux/sched.h> 81#include <linux/atomic.h> 82 83#define KDB_POLL_FUNC_MAX 5 84extern int kdb_poll_idx; 85 86/* 87 * kdb_initial_cpu is initialized to -1, and is set to the cpu 88 * number whenever the kernel debugger is entered. 89 */ 90extern int kdb_initial_cpu; 91 92/* Types and messages used for dynamically added kdb shell commands */ 93 94#define KDB_MAXARGS 16 /* Maximum number of arguments to a function */ 95 96/* KDB return codes from a command or internal kdb function */ 97#define KDB_NOTFOUND (-1) 98#define KDB_ARGCOUNT (-2) 99#define KDB_BADWIDTH (-3) 100#define KDB_BADRADIX (-4) 101#define KDB_NOTENV (-5) 102#define KDB_NOENVVALUE (-6) 103#define KDB_NOTIMP (-7) 104#define KDB_ENVFULL (-8) 105#define KDB_KMALLOCFAILED (-9) 106#define KDB_TOOMANYBPT (-10) 107#define KDB_TOOMANYDBREGS (-11) 108#define KDB_DUPBPT (-12) 109#define KDB_BPTNOTFOUND (-13) 110#define KDB_BADMODE (-14) 111#define KDB_BADINT (-15) 112#define KDB_INVADDRFMT (-16) 113#define KDB_BADREG (-17) 114#define KDB_BADCPUNUM (-18) 115#define KDB_BADLENGTH (-19) 116#define KDB_NOBP (-20) 117#define KDB_BADADDR (-21) 118#define KDB_NOPERM (-22) 119 120/* 121 * kdb_diemsg 122 * 123 * Contains a pointer to the last string supplied to the 124 * kernel 'die' panic function. 125 */ 126extern const char *kdb_diemsg; 127 128#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */ 129#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */ 130#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */ 131#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */ 132#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available, 133 * kdb is disabled */ 134#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do 135 * not use keyboard */ 136#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do 137 * not use keyboard */ 138 139extern unsigned int kdb_flags; /* Global flags, see kdb_state for per cpu state */ 140 141#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag) 142#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag)) 143#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag)) 144 145/* 146 * External entry point for the kernel debugger. The pt_regs 147 * at the time of entry are supplied along with the reason for 148 * entry to the kernel debugger. 149 */ 150 151typedef enum { 152 KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */ 153 KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */ 154 KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */ 155 KDB_REASON_DEBUG, /* Debug Fault - regs valid */ 156 KDB_REASON_OOPS, /* Kernel Oops - regs valid */ 157 KDB_REASON_SWITCH, /* CPU switch - regs valid*/ 158 KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */ 159 KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */ 160 KDB_REASON_RECURSE, /* Recursive entry to kdb; 161 * regs probably valid */ 162 KDB_REASON_SSTEP, /* Single Step trap. - regs valid */ 163 KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */ 164} kdb_reason_t; 165 166enum kdb_msgsrc { 167 KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */ 168 KDB_MSGSRC_PRINTK, /* trapped from printk() */ 169}; 170 171extern int kdb_trap_printk; 172extern int kdb_printf_cpu; 173extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt, 174 va_list args); 175extern __printf(1, 2) int kdb_printf(const char *, ...); 176typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...); 177 178extern void kdb_init(int level); 179 180/* Access to kdb specific polling devices */ 181typedef int (*get_char_func)(void); 182extern get_char_func kdb_poll_funcs[]; 183extern int kdb_get_kbd_char(void); 184 185static inline 186int kdb_process_cpu(const struct task_struct *p) 187{ 188 unsigned int cpu = task_cpu(p); 189 if (cpu > num_possible_cpus()) 190 cpu = 0; 191 return cpu; 192} 193 194extern void kdb_send_sig(struct task_struct *p, int sig); 195 196#ifdef CONFIG_KALLSYMS 197extern const char *kdb_walk_kallsyms(loff_t *pos); 198#else /* ! CONFIG_KALLSYMS */ 199static inline const char *kdb_walk_kallsyms(loff_t *pos) 200{ 201 return NULL; 202} 203#endif /* ! CONFIG_KALLSYMS */ 204 205/* Dynamic kdb shell command registration */ 206extern int kdb_register(kdbtab_t *cmd); 207extern void kdb_unregister(kdbtab_t *cmd); 208 209/* Return true when KDB as locked for printing a message on this CPU. */ 210static inline 211bool kdb_printf_on_this_cpu(void) 212{ 213 /* 214 * We can use raw_smp_processor_id() here because the task could 215 * not get migrated when KDB has locked for printing on this CPU. 216 */ 217 return unlikely(READ_ONCE(kdb_printf_cpu) == raw_smp_processor_id()); 218} 219 220#else /* ! CONFIG_KGDB_KDB */ 221static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; } 222static inline void kdb_init(int level) {} 223static inline int kdb_register(kdbtab_t *cmd) { return 0; } 224static inline void kdb_unregister(kdbtab_t *cmd) {} 225 226static inline bool kdb_printf_on_this_cpu(void) { return false; } 227 228#endif /* CONFIG_KGDB_KDB */ 229enum { 230 KDB_NOT_INITIALIZED, 231 KDB_INIT_EARLY, 232 KDB_INIT_FULL, 233}; 234 235extern int kdbgetintenv(const char *, int *); 236extern int kdb_set(int, const char **); 237int kdb_lsmod(int argc, const char **argv); 238 239#endif /* !_KDB_H */