aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/debug
diff options
context:
space:
mode:
authorDaniel Thompson <daniel.thompson@linaro.org>2014-11-06 09:36:45 -0500
committerJason Wessel <jason.wessel@windriver.com>2014-11-11 10:31:52 -0500
commit9452e977ac17caf9f98a91b33d5e3c3357258c64 (patch)
tree7a218cc1706c3c3842f73b6c03d8afc6a34f61ae /kernel/debug
parente8ab24d9b0173ada3eeed31d7d7f982228efc2c5 (diff)
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>
Diffstat (limited to 'kernel/debug')
-rw-r--r--kernel/debug/kdb/kdb_bp.c21
-rw-r--r--kernel/debug/kdb/kdb_main.c120
2 files changed, 101 insertions, 40 deletions
diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c
index f8844fb55311..e1dbf4a2c69e 100644
--- a/kernel/debug/kdb/kdb_bp.c
+++ b/kernel/debug/kdb/kdb_bp.c
@@ -532,21 +532,28 @@ void __init kdb_initbptab(void)
532 bp->bp_free = 1; 532 bp->bp_free = 1;
533 533
534 kdb_register_flags("bp", kdb_bp, "[<vaddr>]", 534 kdb_register_flags("bp", kdb_bp, "[<vaddr>]",
535 "Set/Display breakpoints", 0, KDB_REPEAT_NO_ARGS); 535 "Set/Display breakpoints", 0,
536 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
536 kdb_register_flags("bl", kdb_bp, "[<vaddr>]", 537 kdb_register_flags("bl", kdb_bp, "[<vaddr>]",
537 "Display breakpoints", 0, KDB_REPEAT_NO_ARGS); 538 "Display breakpoints", 0,
539 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
538 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) 540 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT)
539 kdb_register_flags("bph", kdb_bp, "[<vaddr>]", 541 kdb_register_flags("bph", kdb_bp, "[<vaddr>]",
540 "[datar [length]|dataw [length]] Set hw brk", 0, KDB_REPEAT_NO_ARGS); 542 "[datar [length]|dataw [length]] Set hw brk", 0,
543 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
541 kdb_register_flags("bc", kdb_bc, "<bpnum>", 544 kdb_register_flags("bc", kdb_bc, "<bpnum>",
542 "Clear Breakpoint", 0, 0); 545 "Clear Breakpoint", 0,
546 KDB_ENABLE_FLOW_CTRL);
543 kdb_register_flags("be", kdb_bc, "<bpnum>", 547 kdb_register_flags("be", kdb_bc, "<bpnum>",
544 "Enable Breakpoint", 0, 0); 548 "Enable Breakpoint", 0,
549 KDB_ENABLE_FLOW_CTRL);
545 kdb_register_flags("bd", kdb_bc, "<bpnum>", 550 kdb_register_flags("bd", kdb_bc, "<bpnum>",
546 "Disable Breakpoint", 0, 0); 551 "Disable Breakpoint", 0,
552 KDB_ENABLE_FLOW_CTRL);
547 553
548 kdb_register_flags("ss", kdb_ss, "", 554 kdb_register_flags("ss", kdb_ss, "",
549 "Single Step", 1, KDB_REPEAT_NO_ARGS); 555 "Single Step", 1,
556 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
550 /* 557 /*
551 * Architecture dependent initialization. 558 * Architecture dependent initialization.
552 */ 559 */
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 538bf1dce26a..fae1fc3962f8 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -188,6 +188,26 @@ struct task_struct *kdb_curr_task(int cpu)
188} 188}
189 189
190/* 190/*
191 * Check whether the flags of the current command and the permissions
192 * of the kdb console has allow a command to be run.
193 */
194static inline bool kdb_check_flags(kdb_cmdflags_t flags, int permissions,
195 bool no_args)
196{
197 /* permissions comes from userspace so needs massaging slightly */
198 permissions &= KDB_ENABLE_MASK;
199 permissions |= KDB_ENABLE_ALWAYS_SAFE;
200
201 /* some commands change group when launched with no arguments */
202 if (no_args)
203 permissions |= permissions << KDB_ENABLE_NO_ARGS_SHIFT;
204
205 flags |= KDB_ENABLE_ALL;
206
207 return permissions & flags;
208}
209
210/*
191 * kdbgetenv - This function will return the character string value of 211 * kdbgetenv - This function will return the character string value of
192 * an environment variable. 212 * an environment variable.
193 * Parameters: 213 * Parameters:
@@ -641,8 +661,13 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
641 if (!s->count) 661 if (!s->count)
642 s->usable = 0; 662 s->usable = 0;
643 if (s->usable) 663 if (s->usable)
644 kdb_register(s->name, kdb_exec_defcmd, 664 /* macros are always safe because when executed each
645 s->usage, s->help, 0); 665 * internal command re-enters kdb_parse() and is
666 * safety checked individually.
667 */
668 kdb_register_flags(s->name, kdb_exec_defcmd, s->usage,
669 s->help, 0,
670 KDB_ENABLE_ALWAYS_SAFE);
646 return 0; 671 return 0;
647 } 672 }
648 if (!s->usable) 673 if (!s->usable)
@@ -2757,78 +2782,107 @@ static void __init kdb_inittab(void)
2757 2782
2758 kdb_register_flags("md", kdb_md, "<vaddr>", 2783 kdb_register_flags("md", kdb_md, "<vaddr>",
2759 "Display Memory Contents, also mdWcN, e.g. md8c1", 1, 2784 "Display Memory Contents, also mdWcN, e.g. md8c1", 1,
2760 KDB_REPEAT_NO_ARGS); 2785 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2761 kdb_register_flags("mdr", kdb_md, "<vaddr> <bytes>", 2786 kdb_register_flags("mdr", kdb_md, "<vaddr> <bytes>",
2762 "Display Raw Memory", 0, KDB_REPEAT_NO_ARGS); 2787 "Display Raw Memory", 0,
2788 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2763 kdb_register_flags("mdp", kdb_md, "<paddr> <bytes>", 2789 kdb_register_flags("mdp", kdb_md, "<paddr> <bytes>",
2764 "Display Physical Memory", 0, KDB_REPEAT_NO_ARGS); 2790 "Display Physical Memory", 0,
2791 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2765 kdb_register_flags("mds", kdb_md, "<vaddr>", 2792 kdb_register_flags("mds", kdb_md, "<vaddr>",
2766 "Display Memory Symbolically", 0, KDB_REPEAT_NO_ARGS); 2793 "Display Memory Symbolically", 0,
2794 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2767 kdb_register_flags("mm", kdb_mm, "<vaddr> <contents>", 2795 kdb_register_flags("mm", kdb_mm, "<vaddr> <contents>",
2768 "Modify Memory Contents", 0, KDB_REPEAT_NO_ARGS); 2796 "Modify Memory Contents", 0,
2797 KDB_ENABLE_MEM_WRITE | KDB_REPEAT_NO_ARGS);
2769 kdb_register_flags("go", kdb_go, "[<vaddr>]", 2798 kdb_register_flags("go", kdb_go, "[<vaddr>]",
2770 "Continue Execution", 1, 0); 2799 "Continue Execution", 1,
2800 KDB_ENABLE_REG_WRITE | KDB_ENABLE_ALWAYS_SAFE_NO_ARGS);
2771 kdb_register_flags("rd", kdb_rd, "", 2801 kdb_register_flags("rd", kdb_rd, "",
2772 "Display Registers", 0, 0); 2802 "Display Registers", 0,
2803 KDB_ENABLE_REG_READ);
2773 kdb_register_flags("rm", kdb_rm, "<reg> <contents>", 2804 kdb_register_flags("rm", kdb_rm, "<reg> <contents>",
2774 "Modify Registers", 0, 0); 2805 "Modify Registers", 0,
2806 KDB_ENABLE_REG_WRITE);
2775 kdb_register_flags("ef", kdb_ef, "<vaddr>", 2807 kdb_register_flags("ef", kdb_ef, "<vaddr>",
2776 "Display exception frame", 0, 0); 2808 "Display exception frame", 0,
2809 KDB_ENABLE_MEM_READ);
2777 kdb_register_flags("bt", kdb_bt, "[<vaddr>]", 2810 kdb_register_flags("bt", kdb_bt, "[<vaddr>]",
2778 "Stack traceback", 1, 0); 2811 "Stack traceback", 1,
2812 KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS);
2779 kdb_register_flags("btp", kdb_bt, "<pid>", 2813 kdb_register_flags("btp", kdb_bt, "<pid>",
2780 "Display stack for process <pid>", 0, 0); 2814 "Display stack for process <pid>", 0,
2815 KDB_ENABLE_INSPECT);
2781 kdb_register_flags("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]", 2816 kdb_register_flags("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]",
2782 "Backtrace all processes matching state flag", 0, 0); 2817 "Backtrace all processes matching state flag", 0,
2818 KDB_ENABLE_INSPECT);
2783 kdb_register_flags("btc", kdb_bt, "", 2819 kdb_register_flags("btc", kdb_bt, "",
2784 "Backtrace current process on each cpu", 0, 0); 2820 "Backtrace current process on each cpu", 0,
2821 KDB_ENABLE_INSPECT);
2785 kdb_register_flags("btt", kdb_bt, "<vaddr>", 2822 kdb_register_flags("btt", kdb_bt, "<vaddr>",
2786 "Backtrace process given its struct task address", 0, 2823 "Backtrace process given its struct task address", 0,
2787 0); 2824 KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS);
2788 kdb_register_flags("env", kdb_env, "", 2825 kdb_register_flags("env", kdb_env, "",
2789 "Show environment variables", 0, 0); 2826 "Show environment variables", 0,
2827 KDB_ENABLE_ALWAYS_SAFE);
2790 kdb_register_flags("set", kdb_set, "", 2828 kdb_register_flags("set", kdb_set, "",
2791 "Set environment variables", 0, 0); 2829 "Set environment variables", 0,
2830 KDB_ENABLE_ALWAYS_SAFE);
2792 kdb_register_flags("help", kdb_help, "", 2831 kdb_register_flags("help", kdb_help, "",
2793 "Display Help Message", 1, 0); 2832 "Display Help Message", 1,
2833 KDB_ENABLE_ALWAYS_SAFE);
2794 kdb_register_flags("?", kdb_help, "", 2834 kdb_register_flags("?", kdb_help, "",
2795 "Display Help Message", 0, 0); 2835 "Display Help Message", 0,
2836 KDB_ENABLE_ALWAYS_SAFE);
2796 kdb_register_flags("cpu", kdb_cpu, "<cpunum>", 2837 kdb_register_flags("cpu", kdb_cpu, "<cpunum>",
2797 "Switch to new cpu", 0, 0); 2838 "Switch to new cpu", 0,
2839 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS);
2798 kdb_register_flags("kgdb", kdb_kgdb, "", 2840 kdb_register_flags("kgdb", kdb_kgdb, "",
2799 "Enter kgdb mode", 0, 0); 2841 "Enter kgdb mode", 0, 0);
2800 kdb_register_flags("ps", kdb_ps, "[<flags>|A]", 2842 kdb_register_flags("ps", kdb_ps, "[<flags>|A]",
2801 "Display active task list", 0, 0); 2843 "Display active task list", 0,
2844 KDB_ENABLE_INSPECT);
2802 kdb_register_flags("pid", kdb_pid, "<pidnum>", 2845 kdb_register_flags("pid", kdb_pid, "<pidnum>",
2803 "Switch to another task", 0, 0); 2846 "Switch to another task", 0,
2847 KDB_ENABLE_INSPECT);
2804 kdb_register_flags("reboot", kdb_reboot, "", 2848 kdb_register_flags("reboot", kdb_reboot, "",
2805 "Reboot the machine immediately", 0, 0); 2849 "Reboot the machine immediately", 0,
2850 KDB_ENABLE_REBOOT);
2806#if defined(CONFIG_MODULES) 2851#if defined(CONFIG_MODULES)
2807 kdb_register_flags("lsmod", kdb_lsmod, "", 2852 kdb_register_flags("lsmod", kdb_lsmod, "",
2808 "List loaded kernel modules", 0, 0); 2853 "List loaded kernel modules", 0,
2854 KDB_ENABLE_INSPECT);
2809#endif 2855#endif
2810#if defined(CONFIG_MAGIC_SYSRQ) 2856#if defined(CONFIG_MAGIC_SYSRQ)
2811 kdb_register_flags("sr", kdb_sr, "<key>", 2857 kdb_register_flags("sr", kdb_sr, "<key>",
2812 "Magic SysRq key", 0, 0); 2858 "Magic SysRq key", 0,
2859 KDB_ENABLE_ALWAYS_SAFE);
2813#endif 2860#endif
2814#if defined(CONFIG_PRINTK) 2861#if defined(CONFIG_PRINTK)
2815 kdb_register_flags("dmesg", kdb_dmesg, "[lines]", 2862 kdb_register_flags("dmesg", kdb_dmesg, "[lines]",
2816 "Display syslog buffer", 0, 0); 2863 "Display syslog buffer", 0,
2864 KDB_ENABLE_ALWAYS_SAFE);
2817#endif 2865#endif
2818 if (arch_kgdb_ops.enable_nmi) { 2866 if (arch_kgdb_ops.enable_nmi) {
2819 kdb_register_flags("disable_nmi", kdb_disable_nmi, "", 2867 kdb_register_flags("disable_nmi", kdb_disable_nmi, "",
2820 "Disable NMI entry to KDB", 0, 0); 2868 "Disable NMI entry to KDB", 0,
2869 KDB_ENABLE_ALWAYS_SAFE);
2821 } 2870 }
2822 kdb_register_flags("defcmd", kdb_defcmd, "name \"usage\" \"help\"", 2871 kdb_register_flags("defcmd", kdb_defcmd, "name \"usage\" \"help\"",
2823 "Define a set of commands, down to endefcmd", 0, 0); 2872 "Define a set of commands, down to endefcmd", 0,
2873 KDB_ENABLE_ALWAYS_SAFE);
2824 kdb_register_flags("kill", kdb_kill, "<-signal> <pid>", 2874 kdb_register_flags("kill", kdb_kill, "<-signal> <pid>",
2825 "Send a signal to a process", 0, 0); 2875 "Send a signal to a process", 0,
2876 KDB_ENABLE_SIGNAL);
2826 kdb_register_flags("summary", kdb_summary, "", 2877 kdb_register_flags("summary", kdb_summary, "",
2827 "Summarize the system", 4, 0); 2878 "Summarize the system", 4,
2879 KDB_ENABLE_ALWAYS_SAFE);
2828 kdb_register_flags("per_cpu", kdb_per_cpu, "<sym> [<bytes>] [<cpu>]", 2880 kdb_register_flags("per_cpu", kdb_per_cpu, "<sym> [<bytes>] [<cpu>]",
2829 "Display per_cpu variables", 3, 0); 2881 "Display per_cpu variables", 3,
2882 KDB_ENABLE_MEM_READ);
2830 kdb_register_flags("grephelp", kdb_grep_help, "", 2883 kdb_register_flags("grephelp", kdb_grep_help, "",
2831 "Display help on | grep", 0, 0); 2884 "Display help on | grep", 0,
2885 KDB_ENABLE_ALWAYS_SAFE);
2832} 2886}
2833 2887
2834/* Execute any commands defined in kdb_cmds. */ 2888/* Execute any commands defined in kdb_cmds. */