summaryrefslogtreecommitdiff
path: root/drivers/misc/kernel_debugger.c
diff options
context:
space:
mode:
authorBrian Swetland <swetland@google.com>2008-04-08 22:34:46 -0700
committerArve Hjønnevåg <arve@android.com>2009-04-07 16:43:32 -0700
commit74c157f41e288ca89fcb71f8a809e966bd88ba89 (patch)
tree75c0aa472392233a4723244d6714c83415ea1f2a /drivers/misc/kernel_debugger.c
parente500cd364086cfc018b100d08c97b2fdf229d029 (diff)
kernel_debugger_core: add interrupt-context debugger core
This provides kernel_debugger() which can be called from an interrupt context low level debugger wedge to execute commands that inspect kernel state. It doesn't do much on its own. Signed-off-by: Brian Swetland <swetland@google.com>
Diffstat (limited to 'drivers/misc/kernel_debugger.c')
-rw-r--r--drivers/misc/kernel_debugger.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/drivers/misc/kernel_debugger.c b/drivers/misc/kernel_debugger.c
new file mode 100644
index 000000000000..4c479d8af1c0
--- /dev/null
+++ b/drivers/misc/kernel_debugger.c
@@ -0,0 +1,55 @@
+/* drivers/android/kernel_debugger.c
+ *
+ * Guts of the kernel debugger.
+ * Needs something to actually push commands to it.
+ *
+ * Copyright (C) 2007-2008 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/ctype.h>
+#include <linux/device.h>
+#include <linux/sched.h>
+#include <linux/spinlock.h>
+#include <linux/kernel_debugger.h>
+
+#define dprintf(fmt...) (ctxt->printf(ctxt->cookie, fmt))
+
+static void do_ps(struct kdbg_ctxt *ctxt)
+{
+ struct task_struct *g, *p;
+ unsigned state;
+ static const char stat_nam[] = "RSDTtZX";
+
+ dprintf("pid ppid prio task pc\n");
+ read_lock(&tasklist_lock);
+ do_each_thread(g, p) {
+ state = p->state ? __ffs(p->state) + 1 : 0;
+ dprintf("%5d %5d %4d ", p->pid, p->parent->pid, p->prio);
+ dprintf("%-13.13s %c", p->comm,
+ state >= sizeof(stat_nam) ? '?' : stat_nam[state]);
+ if (state == TASK_RUNNING)
+ dprintf(" running\n");
+ else
+ dprintf(" %08lx\n", thread_saved_pc(p));
+ } while_each_thread(g, p);
+ read_unlock(&tasklist_lock);
+}
+
+int kernel_debugger(struct kdbg_ctxt *ctxt, char *cmd)
+{
+ if (!strcmp(cmd, "ps"))
+ do_ps(ctxt);
+
+ return 0;
+}
+