kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
#ifndef _KDB_H
|
|
|
|
#define _KDB_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel Debugger Architecture Independent Global Headers
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
* Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
|
|
|
|
* Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com>
|
|
|
|
*/
|
|
|
|
|
2021-07-12 16:46:18 +03:00
|
|
|
#include <linux/list.h>
|
|
|
|
|
kdb: Categorize kdb commands (similar to SysRq categorization)
This patch introduces several new flags to collect kdb commands into
groups (later allowing them to be optionally disabled).
This follows similar prior art to enable/disable magic sysrq
commands.
The commands have been categorized as follows:
Always on: go (w/o args), env, set, help, ?, cpu (w/o args), sr,
dmesg, disable_nmi, defcmd, summary, grephelp
Mem read: md, mdr, mdp, mds, ef, bt (with args), per_cpu
Mem write: mm
Reg read: rd
Reg write: go (with args), rm
Inspect: bt (w/o args), btp, bta, btc, btt, ps, pid, lsmod
Flow ctrl: bp, bl, bph, bc, be, bd, ss
Signal: kill
Reboot: reboot
All: cpu, kgdb, (and all of the above), nmi_console
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
2014-11-06 17:36:45 +03:00
|
|
|
/* Shifted versions of the command enable bits are be used if the command
|
|
|
|
* has no arguments (see kdb_check_flags). This allows commands, such as
|
|
|
|
* go, to have different permissions depending upon whether it is called
|
|
|
|
* with an argument.
|
|
|
|
*/
|
|
|
|
#define KDB_ENABLE_NO_ARGS_SHIFT 10
|
|
|
|
|
2012-09-25 01:27:52 +04:00
|
|
|
typedef enum {
|
kdb: Categorize kdb commands (similar to SysRq categorization)
This patch introduces several new flags to collect kdb commands into
groups (later allowing them to be optionally disabled).
This follows similar prior art to enable/disable magic sysrq
commands.
The commands have been categorized as follows:
Always on: go (w/o args), env, set, help, ?, cpu (w/o args), sr,
dmesg, disable_nmi, defcmd, summary, grephelp
Mem read: md, mdr, mdp, mds, ef, bt (with args), per_cpu
Mem write: mm
Reg read: rd
Reg write: go (with args), rm
Inspect: bt (w/o args), btp, bta, btc, btt, ps, pid, lsmod
Flow ctrl: bp, bl, bph, bc, be, bd, ss
Signal: kill
Reboot: reboot
All: cpu, kgdb, (and all of the above), nmi_console
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
2014-11-06 17:36:45 +03:00
|
|
|
KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
|
|
|
|
KDB_ENABLE_MEM_READ = (1 << 1),
|
|
|
|
KDB_ENABLE_MEM_WRITE = (1 << 2),
|
|
|
|
KDB_ENABLE_REG_READ = (1 << 3),
|
|
|
|
KDB_ENABLE_REG_WRITE = (1 << 4),
|
|
|
|
KDB_ENABLE_INSPECT = (1 << 5),
|
|
|
|
KDB_ENABLE_FLOW_CTRL = (1 << 6),
|
|
|
|
KDB_ENABLE_SIGNAL = (1 << 7),
|
|
|
|
KDB_ENABLE_REBOOT = (1 << 8),
|
|
|
|
/* User exposed values stop here, all remaining flags are
|
|
|
|
* exclusively used to describe a commands behaviour.
|
|
|
|
*/
|
|
|
|
|
|
|
|
KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
|
|
|
|
KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,
|
|
|
|
|
|
|
|
KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
|
|
|
|
<< KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,
|
|
|
|
|
|
|
|
KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
|
|
|
|
KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
|
2014-11-06 17:36:41 +03:00
|
|
|
} kdb_cmdflags_t;
|
2012-09-25 01:27:52 +04:00
|
|
|
|
|
|
|
typedef int (*kdb_func_t)(int, const char **);
|
|
|
|
|
2021-07-12 16:46:18 +03:00
|
|
|
/* The KDB shell command table */
|
|
|
|
typedef struct _kdbtab {
|
2021-07-12 16:46:20 +03:00
|
|
|
char *name; /* Command name */
|
|
|
|
kdb_func_t func; /* Function to execute command */
|
|
|
|
char *usage; /* Usage String for this command */
|
|
|
|
char *help; /* Help message for this command */
|
|
|
|
short minlen; /* Minimum legal # cmd chars required */
|
|
|
|
kdb_cmdflags_t flags; /* Command behaviour flags */
|
2021-07-12 16:46:18 +03:00
|
|
|
struct list_head list_node; /* Command list */
|
|
|
|
} kdbtab_t;
|
|
|
|
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
#ifdef CONFIG_KGDB_KDB
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/sched.h>
|
2011-07-27 03:09:06 +04:00
|
|
|
#include <linux/atomic.h>
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
|
|
|
|
#define KDB_POLL_FUNC_MAX 5
|
2010-05-21 06:04:22 +04:00
|
|
|
extern int kdb_poll_idx;
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* kdb_initial_cpu is initialized to -1, and is set to the cpu
|
|
|
|
* number whenever the kernel debugger is entered.
|
|
|
|
*/
|
|
|
|
extern int kdb_initial_cpu;
|
|
|
|
|
2010-10-11 19:20:14 +04:00
|
|
|
/* Types and messages used for dynamically added kdb shell commands */
|
|
|
|
|
|
|
|
#define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
|
|
|
|
|
|
|
|
/* KDB return codes from a command or internal kdb function */
|
|
|
|
#define KDB_NOTFOUND (-1)
|
|
|
|
#define KDB_ARGCOUNT (-2)
|
|
|
|
#define KDB_BADWIDTH (-3)
|
|
|
|
#define KDB_BADRADIX (-4)
|
|
|
|
#define KDB_NOTENV (-5)
|
|
|
|
#define KDB_NOENVVALUE (-6)
|
|
|
|
#define KDB_NOTIMP (-7)
|
|
|
|
#define KDB_ENVFULL (-8)
|
|
|
|
#define KDB_ENVBUFFULL (-9)
|
|
|
|
#define KDB_TOOMANYBPT (-10)
|
|
|
|
#define KDB_TOOMANYDBREGS (-11)
|
|
|
|
#define KDB_DUPBPT (-12)
|
|
|
|
#define KDB_BPTNOTFOUND (-13)
|
|
|
|
#define KDB_BADMODE (-14)
|
|
|
|
#define KDB_BADINT (-15)
|
|
|
|
#define KDB_INVADDRFMT (-16)
|
|
|
|
#define KDB_BADREG (-17)
|
|
|
|
#define KDB_BADCPUNUM (-18)
|
|
|
|
#define KDB_BADLENGTH (-19)
|
|
|
|
#define KDB_NOBP (-20)
|
|
|
|
#define KDB_BADADDR (-21)
|
kdb: Add enable mask for groups of commands
Currently all kdb commands are enabled whenever kdb is deployed. This
makes it difficult to deploy kdb to help debug certain types of
systems.
Android phones provide one example; the FIQ debugger found on some
Android devices has a deliberately weak set of commands to allow the
debugger to enabled very late in the production cycle.
Certain kiosk environments offer another interesting case where an
engineer might wish to probe the system state using passive inspection
commands without providing sufficient power for a passer by to root it.
Without any restrictions, obtaining the root rights via KDB is a matter of
a few commands, and works everywhere. For example, log in as a normal
user:
cbou:~$ id
uid=1001(cbou) gid=1001(cbou) groups=1001(cbou)
Now enter KDB (for example via sysrq):
Entering kdb (current=0xffff8800065bc740, pid 920) due to Keyboard Entry
kdb> ps
23 sleeping system daemon (state M) processes suppressed,
use 'ps A' to see all.
Task Addr Pid Parent [*] cpu State Thread Command
0xffff8800065bc740 920 919 1 0 R 0xffff8800065bca20 *bash
0xffff880007078000 1 0 0 0 S 0xffff8800070782e0 init
[...snip...]
0xffff8800065be3c0 918 1 0 0 S 0xffff8800065be6a0 getty
0xffff8800065b9c80 919 1 0 0 S 0xffff8800065b9f60 login
0xffff8800065bc740 920 919 1 0 R 0xffff8800065bca20 *bash
All we need is the offset of cred pointers. We can look up the offset in
the distro's kernel source, but it is unnecessary. We can just start
dumping init's task_struct, until we see the process name:
kdb> md 0xffff880007078000
0xffff880007078000 0000000000000001 ffff88000703c000 ................
0xffff880007078010 0040210000000002 0000000000000000 .....!@.........
[...snip...]
0xffff8800070782b0 ffff8800073e0580 ffff8800073e0580 ..>.......>.....
0xffff8800070782c0 0000000074696e69 0000000000000000 init............
^ Here, 'init'. Creds are just above it, so the offset is 0x02b0.
Now we set up init's creds for our non-privileged shell:
kdb> mm 0xffff8800065bc740+0x02b0 0xffff8800073e0580
0xffff8800065bc9f0 = 0xffff8800073e0580
kdb> mm 0xffff8800065bc740+0x02b8 0xffff8800073e0580
0xffff8800065bc9f8 = 0xffff8800073e0580
And thus gaining the root:
kdb> go
cbou:~$ id
uid=0(root) gid=0(root) groups=0(root)
cbou:~$ bash
root:~#
p.s. No distro enables kdb by default (although, with a nice KDB-over-KMS
feature availability, I would expect at least some would enable it), so
it's not actually some kind of a major issue.
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
2014-11-06 17:36:46 +03:00
|
|
|
#define KDB_NOPERM (-22)
|
2010-10-11 19:20:14 +04:00
|
|
|
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
/*
|
|
|
|
* kdb_diemsg
|
|
|
|
*
|
|
|
|
* Contains a pointer to the last string supplied to the
|
|
|
|
* kernel 'die' panic function.
|
|
|
|
*/
|
|
|
|
extern const char *kdb_diemsg;
|
|
|
|
|
|
|
|
#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
|
|
|
|
#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
|
|
|
|
#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
|
|
|
|
#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
|
|
|
|
#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
|
|
|
|
* kdb is disabled */
|
|
|
|
#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
|
|
|
|
* not use keyboard */
|
|
|
|
#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
|
|
|
|
* not use keyboard */
|
|
|
|
|
2020-05-21 10:21:25 +03:00
|
|
|
extern unsigned int kdb_flags; /* Global flags, see kdb_state for per cpu state */
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
|
|
|
|
extern void kdb_save_flags(void);
|
|
|
|
extern void kdb_restore_flags(void);
|
|
|
|
|
|
|
|
#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
|
|
|
|
#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
|
|
|
|
#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* External entry point for the kernel debugger. The pt_regs
|
|
|
|
* at the time of entry are supplied along with the reason for
|
|
|
|
* entry to the kernel debugger.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
|
|
|
|
KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
|
|
|
|
KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
|
|
|
|
KDB_REASON_DEBUG, /* Debug Fault - regs valid */
|
|
|
|
KDB_REASON_OOPS, /* Kernel Oops - regs valid */
|
|
|
|
KDB_REASON_SWITCH, /* CPU switch - regs valid*/
|
|
|
|
KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
|
|
|
|
KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
|
|
|
|
KDB_REASON_RECURSE, /* Recursive entry to kdb;
|
|
|
|
* regs probably valid */
|
|
|
|
KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
|
2013-10-02 19:14:18 +04:00
|
|
|
KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
} kdb_reason_t;
|
|
|
|
|
2014-11-07 21:37:57 +03:00
|
|
|
enum kdb_msgsrc {
|
|
|
|
KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */
|
|
|
|
KDB_MSGSRC_PRINTK, /* trapped from printk() */
|
|
|
|
};
|
|
|
|
|
2010-05-21 06:04:27 +04:00
|
|
|
extern int kdb_trap_printk;
|
kdb: call vkdb_printf() from vprintk_default() only when wanted
kdb_trap_printk allows to pass normal printk() messages to kdb via
vkdb_printk(). For example, it is used to get backtrace using the
classic show_stack(), see kdb_show_stack().
vkdb_printf() tries to avoid a potential infinite loop by disabling the
trap. But this approach is racy, for example:
CPU1 CPU2
vkdb_printf()
// assume that kdb_trap_printk == 0
saved_trap_printk = kdb_trap_printk;
kdb_trap_printk = 0;
kdb_show_stack()
kdb_trap_printk++;
Problem1: Now, a nested printk() on CPU0 calls vkdb_printf()
even when it should have been disabled. It will not
cause a deadlock but...
// using the outdated saved value: 0
kdb_trap_printk = saved_trap_printk;
kdb_trap_printk--;
Problem2: Now, kdb_trap_printk == -1 and will stay like this.
It means that all messages will get passed to kdb from
now on.
This patch removes the racy saved_trap_printk handling. Instead, the
recursion is prevented by a check for the locked CPU.
The solution is still kind of racy. A non-related printk(), from
another process, might get trapped by vkdb_printf(). And the wanted
printk() might not get trapped because kdb_printf_cpu is assigned. But
this problem existed even with the original code.
A proper solution would be to get_cpu() before setting kdb_trap_printk
and trap messages only from this CPU. I am not sure if it is worth the
effort, though.
In fact, the race is very theoretical. When kdb is running any of the
commands that use kdb_trap_printk there is a single active CPU and the
other CPUs should be in a holding pen inside kgdb_cpu_enter().
The only time this is violated is when there is a timeout waiting for
the other CPUs to report to the holding pen.
Finally, note that the situation is a bit schizophrenic. vkdb_printf()
explicitly allows recursion but only from KDB code that calls
kdb_printf() directly. On the other hand, the generic printk()
recursion is not allowed because it might cause an infinite loop. This
is why we could not hide the decision inside vkdb_printf() easily.
Link: http://lkml.kernel.org/r/1480412276-16690-4-git-send-email-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-12-15 02:05:58 +03:00
|
|
|
extern int kdb_printf_cpu;
|
2014-11-07 21:37:57 +03:00
|
|
|
extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt,
|
|
|
|
va_list args);
|
2011-11-01 04:11:33 +04:00
|
|
|
extern __printf(1, 2) int kdb_printf(const char *, ...);
|
|
|
|
typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
|
|
|
|
extern void kdb_init(int level);
|
|
|
|
|
|
|
|
/* Access to kdb specific polling devices */
|
|
|
|
typedef int (*get_char_func)(void);
|
|
|
|
extern get_char_func kdb_poll_funcs[];
|
|
|
|
extern int kdb_get_kbd_char(void);
|
|
|
|
|
|
|
|
static inline
|
|
|
|
int kdb_process_cpu(const struct task_struct *p)
|
|
|
|
{
|
2016-07-29 01:48:20 +03:00
|
|
|
unsigned int cpu = task_cpu(p);
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
if (cpu > num_possible_cpus())
|
|
|
|
cpu = 0;
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:20:14 +04:00
|
|
|
#ifdef CONFIG_KALLSYMS
|
|
|
|
extern const char *kdb_walk_kallsyms(loff_t *pos);
|
|
|
|
#else /* ! CONFIG_KALLSYMS */
|
|
|
|
static inline const char *kdb_walk_kallsyms(loff_t *pos)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* ! CONFIG_KALLSYMS */
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
|
2010-10-11 19:20:14 +04:00
|
|
|
/* Dynamic kdb shell command registration */
|
2021-07-12 16:46:18 +03:00
|
|
|
extern int kdb_register(kdbtab_t *cmd);
|
|
|
|
extern void kdb_unregister(kdbtab_t *cmd);
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
#else /* ! CONFIG_KGDB_KDB */
|
2012-09-25 01:27:52 +04:00
|
|
|
static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
|
|
|
|
static inline void kdb_init(int level) {}
|
2021-07-12 16:46:18 +03:00
|
|
|
static inline int kdb_register(kdbtab_t *cmd) { return 0; }
|
|
|
|
static inline void kdb_unregister(kdbtab_t *cmd) {}
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
#endif /* CONFIG_KGDB_KDB */
|
|
|
|
enum {
|
|
|
|
KDB_NOT_INITIALIZED,
|
|
|
|
KDB_INIT_EARLY,
|
|
|
|
KDB_INIT_FULL,
|
|
|
|
};
|
2010-08-05 18:22:30 +04:00
|
|
|
|
|
|
|
extern int kdbgetintenv(const char *, int *);
|
|
|
|
extern int kdb_set(int, const char **);
|
|
|
|
|
kdb: core for kgdb back end (1 of 2)
This patch contains only the kdb core. Because the change set was
large, it was split. The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to
support x86. From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.
This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin. More archictectures can be added by implementing the
architecture specific kgdb functions.
[mort@sgi.com: Compile fix with hugepages enabled]
[mort@sgi.com: Clean breakpoint code renaming kdba_ -> kdb_]
[mort@sgi.com: fix new line after printing registers]
[mort@sgi.com: Remove the concept of global vs. local breakpoints]
[mort@sgi.com: Rework kdb_si_swapinfo to use more generic name]
[mort@sgi.com: fix the information dump macros, remove 'arch' from the names]
[sfr@canb.auug.org.au: include fixup to include linux/slab.h]
CC: linux-arch@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Martin Hicks <mort@sgi.com>
2010-05-21 06:04:20 +04:00
|
|
|
#endif /* !_KDB_H */
|