From patchwork Tue Aug 19 14:37:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 35606 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 91089201EF for ; Tue, 19 Aug 2014 14:38:18 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id eu11sf54609389pac.3 for ; Tue, 19 Aug 2014 07:38:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=mYnUE4H3QTlw1X7lH6hwvgEHqJeHxx60Ew3hnFfwRwI=; b=E9qhPVfpmSSno4aycu3eI1KR5fdWGqK/mlEo/Ym+DF9N4mtU6rH+LqXHo2UF4vnzfF jaoTFqoK4NBhWMHaYhb9BSCfDhasxmZZxSvf8q4+QO/xNG4mz449o5TVSrKhQ+Mnboci m2CldRkAKgC+zMP7caY0VhW5Bcb+MkM9Nk9t7eJaU17KHhCCyQlhk575k67jP9EKIKSO 40jbgPU9R5GQF8rsGFNZlZL2lgy0wFZ5eYAvSWko1b14KzIHz4IDZWyrgR50jkV7e7w0 KugTxMflDLLa3E7QqY15IbHW7Te0i1ImUD/QMlXZmzrq9600ryWN646hy/t7WYxkC0cb cEfw== X-Gm-Message-State: ALoCoQmdAikgrtPmehNLN24FoeyUWxMJbmi2NLEn66OJWvNFtthimz8BVNhsHs7KVhe6UBy2pIHk X-Received: by 10.70.90.47 with SMTP id bt15mr22071977pdb.4.1408459089133; Tue, 19 Aug 2014 07:38:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.108 with SMTP id 99ls3053078qgg.29.gmail; Tue, 19 Aug 2014 07:38:08 -0700 (PDT) X-Received: by 10.52.36.131 with SMTP id q3mr488901vdj.90.1408459088919; Tue, 19 Aug 2014 07:38:08 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id qi1si4561508vcb.53.2014.08.19.07.38.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 07:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id hy10so7531288vcb.18 for ; Tue, 19 Aug 2014 07:38:08 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr1392563vdb.27.1408459088849; Tue, 19 Aug 2014 07:38:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp244007vcb; Tue, 19 Aug 2014 07:38:08 -0700 (PDT) X-Received: by 10.194.63.37 with SMTP id d5mr36306526wjs.92.1408459087571; Tue, 19 Aug 2014 07:38:07 -0700 (PDT) Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com [74.125.82.49]) by mx.google.com with ESMTPS id bf5si22689296wib.102.2014.08.19.07.38.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 07:38:06 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 74.125.82.49 as permitted sender) client-ip=74.125.82.49; Received: by mail-wg0-f49.google.com with SMTP id k14so6621768wgh.32 for ; Tue, 19 Aug 2014 07:38:06 -0700 (PDT) X-Received: by 10.194.95.166 with SMTP id dl6mr17802770wjb.115.1408459086388; Tue, 19 Aug 2014 07:38:06 -0700 (PDT) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id k6sm50920144wjq.5.2014.08.19.07.38.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Aug 2014 07:38:05 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, patches@linaro.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, Paul Gortmaker , Andrew Morton , Mike Travis , Dimitri Sivanich , Hedi Berriche , John Stultz , Anton Vorontsov , Colin Cross , kernel-team@android.com Subject: [PATCH v3 1/3] kdb: Add framework to display sequence files Date: Tue, 19 Aug 2014 15:37:40 +0100 Message-Id: <1408459062-19120-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1408459062-19120-1-git-send-email-daniel.thompson@linaro.org> References: <1398872427-18435-1-git-send-email-daniel.thompson@linaro.org> <1408459062-19120-1-git-send-email-daniel.thompson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- include/linux/kdb.h | 5 +++++ kernel/debug/kdb/kdb_io.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 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 #include #include +#include #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 7c70812..46aae57 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -850,3 +850,56 @@ 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 left uninitialized because it is + * used by seq_file read/lseek wrapper functions. It cannot be + * used from any of the seq_operations (assuming the ops are + * deadlock free with the normal interface). + */ + .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; +}