From: Daniel Thompson <daniel.thompson@linaro.org>
To: kgdb-bugreport@lists.sourceforge.net,
Jason Wessel <jason.wessel@windriver.com>
Cc: patches@linaro.org, linaro-kernel@lists.linaro.org,
Daniel Thompson <daniel.thompson@linaro.org>,
linux-kernel@vger.kernel.org,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Travis <travis@sgi.com>, Dimitri Sivanich <sivanich@sgi.com>,
Hedi Berriche <hedi@sgi.com>,
John Stultz <john.stultz@linaro.org>,
Anton Vorontsov <anton.vorontsov@linaro.org>,
Colin Cross <ccross@android.com>,
kernel-team@android.com
Subject: [PATCH 1/3] kdb: Add framework to display sequence files
Date: Wed, 30 Apr 2014 16:40:25 +0100 [thread overview]
Message-ID: <1398872427-18435-2-git-send-email-daniel.thompson@linaro.org> (raw)
In-Reply-To: <1398872427-18435-1-git-send-email-daniel.thompson@linaro.org>
Lots of useful information about the system is held in pseudo filesystems
and presented using the seq_file mechanism. Unfortunately during both boot
up and kernel panic (both good times to break out kdb) it is difficult to
examine these files. This patch introduces a means to display sequence
files via kdb.
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
---
include/linux/kdb.h | 5 +++++
kernel/debug/kdb/kdb_io.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/include/linux/kdb.h b/include/linux/kdb.h
index 290db12..fb46dd4 100644
--- a/include/linux/kdb.h
+++ b/include/linux/kdb.h
@@ -25,6 +25,7 @@ typedef int (*kdb_func_t)(int, const char **);
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/atomic.h>
+#include <linux/seq_file.h>
#define KDB_POLL_FUNC_MAX 5
extern int kdb_poll_idx;
@@ -117,6 +118,8 @@ extern __printf(1, 0) int vkdb_printf(const char *fmt, va_list args);
extern __printf(1, 2) int kdb_printf(const char *, ...);
typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
+extern int kdb_print_seq_file(const struct seq_operations *ops);
+
extern void kdb_init(int level);
/* Access to kdb specific polling devices */
@@ -151,6 +154,8 @@ extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
extern int kdb_unregister(char *);
#else /* ! CONFIG_KGDB_KDB */
static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
+static inline int
+kdb_print_seq_file(const struct seq_operations *ops) { return 0; }
static inline void kdb_init(int level) {}
static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
char *help, short minlen) { return 0; }
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 14ff484..c68c223 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -850,3 +850,54 @@ int kdb_printf(const char *fmt, ...)
return r;
}
EXPORT_SYMBOL_GPL(kdb_printf);
+
+/*
+ * Display a seq_file on the kdb console.
+ */
+
+static int __kdb_print_seq_file(struct seq_file *m, void *v)
+{
+ int i, res;
+
+ res = m->op->show(m, v);
+ if (0 != res)
+ return KDB_BADLENGTH;
+
+ for (i = 0; i < m->count && !KDB_FLAG(CMD_INTERRUPT); i++)
+ kdb_printf("%c", m->buf[i]);
+ m->count = 0;
+
+ return 0;
+}
+
+int kdb_print_seq_file(const struct seq_operations *ops)
+{
+ static char seq_buf[4096];
+ static DEFINE_SPINLOCK(seq_buf_lock);
+ unsigned long flags;
+ struct seq_file m = {
+ .buf = seq_buf,
+ .size = sizeof(seq_buf),
+ /* .lock is deliberately uninitialized to help reveal
+ * unsupportable show methods
+ */
+ .op = ops,
+ };
+ loff_t pos = 0;
+ void *v;
+ int res = 0;
+
+ v = ops->start(&m, &pos);
+ while (v) {
+ spin_lock_irqsave(&seq_buf_lock, flags);
+ res = __kdb_print_seq_file(&m, v);
+ spin_unlock_irqrestore(&seq_buf_lock, flags);
+ if (res != 0 || KDB_FLAG(CMD_INTERRUPT))
+ break;
+
+ v = ops->next(&m, v, &pos);
+ }
+ ops->stop(&m, v);
+
+ return res;
+}
--
1.9.0
next prev parent reply other threads:[~2014-04-30 15:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-29 14:30 [PATCH 0/3] kdb: Infrastructure " Daniel Thompson
2014-04-29 14:30 ` [PATCH 1/3] kdb: Add framework " Daniel Thompson
2014-04-29 14:30 ` [PATCH 2/3] proc: Provide access to /proc/interrupts from kdb Daniel Thompson
2014-04-29 14:30 ` [PATCH 3/3] kdb: Implement seq_file command Daniel Thompson
2014-04-30 15:40 ` [PATCH 0/3] kdb: Infrastructure to display sequence files Daniel Thompson
2014-04-30 15:40 ` Daniel Thompson [this message]
2014-04-30 15:40 ` [PATCH 2/3] proc: Provide access to /proc/interrupts from kdb Daniel Thompson
2014-04-30 15:40 ` [PATCH 3/3] kdb: Implement seq_file command Daniel Thompson
2014-08-19 14:37 ` [PATCH v3 0/3] kdb: Infrastructure to display sequence files Daniel Thompson
2014-08-19 14:37 ` [PATCH v3 1/3] kdb: Add framework " Daniel Thompson
2014-08-19 14:37 ` [PATCH v3 2/3] proc: Provide access to /proc/interrupts from kdb Daniel Thompson
2014-08-19 14:37 ` [PATCH v3 3/3] kdb: Implement seq_file command Daniel Thompson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1398872427-18435-2-git-send-email-daniel.thompson@linaro.org \
--to=daniel.thompson@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=anton.vorontsov@linaro.org \
--cc=ccross@android.com \
--cc=hedi@sgi.com \
--cc=jason.wessel@windriver.com \
--cc=john.stultz@linaro.org \
--cc=kernel-team@android.com \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@linaro.org \
--cc=paul.gortmaker@windriver.com \
--cc=sivanich@sgi.com \
--cc=travis@sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®