From patchwork Wed Apr 30 15:40:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 29431 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7FE21203F3 for ; Wed, 30 Apr 2014 15:41:12 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf7597226pdj.0 for ; Wed, 30 Apr 2014 08:41:08 -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=w8Cf6CIHoxrDN30bYDqqwVZrp8y6sEZ7Y22pL8CXgZY=; b=YSEcqcNy9ucvS1jfrW7gB3ZPBxH0zfxP6bAACQwLH539wh27/gUkgUKZiI5BY6164C WHffDUDyiGwxmB15QmeLRotgdSORNdtwNFepvyEJIZXUMLXKdKm0TberPcHZR/UFgrkP Lm2O72uZZ0YY+eEnne/VSRdi+n7eepXCytdOvo+6dQt7FZ1eZI6RKyA5ea+pSf/JQK++ Jk+Ys7SDHUApMjLd8sqeCdmRZ1DxWp4zxEG1dBapwZItwnMHwXTiChmJd/HCzM5ydkTk 4PfYxVY51lBxr7XI81SnIvs5nXrTzB+RS8/4/dy8w+iY/YtmO3EQOCsn/FqG5J1xWqEW nJXA== X-Gm-Message-State: ALoCoQkaw3ivvxz270G9rDQ7D4K0fkREaqTUgHVbtJpWMHk337Ax2KjemqZUYcNrOe8tVFhP7Ewb X-Received: by 10.67.4.202 with SMTP id cg10mr2632259pad.42.1398872466679; Wed, 30 Apr 2014 08:41:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.9 with SMTP id 9ls583154qgg.75.gmail; Wed, 30 Apr 2014 08:41:06 -0700 (PDT) X-Received: by 10.53.1.69 with SMTP id be5mr3600446vdd.27.1398872466542; Wed, 30 Apr 2014 08:41:06 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id be7si5393740vcb.143.2014.04.30.08.41.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 08:41:06 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id oz11so2348649veb.20 for ; Wed, 30 Apr 2014 08:41:06 -0700 (PDT) X-Received: by 10.52.34.4 with SMTP id v4mr778147vdi.42.1398872466478; Wed, 30 Apr 2014 08:41:06 -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.220.221.72 with SMTP id ib8csp289248vcb; Wed, 30 Apr 2014 08:41:06 -0700 (PDT) X-Received: by 10.194.48.80 with SMTP id j16mr4585158wjn.44.1398872465639; Wed, 30 Apr 2014 08:41:05 -0700 (PDT) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by mx.google.com with ESMTPS id gn16si9656200wjc.136.2014.04.30.08.41.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 08:41:05 -0700 (PDT) Received-SPF: none (google.com: daniel.thompson@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.174; Received: by mail-wi0-f174.google.com with SMTP id d1so9393342wiv.1 for ; Wed, 30 Apr 2014 08:41:05 -0700 (PDT) X-Received: by 10.180.8.40 with SMTP id o8mr4271793wia.25.1398872465122; Wed, 30 Apr 2014 08:41:05 -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 hp5sm36719389wjb.0.2014.04.30.08.41.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Apr 2014 08:41:04 -0700 (PDT) From: Daniel Thompson To: kgdb-bugreport@lists.sourceforge.net, Jason Wessel Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, Daniel Thompson , 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 1/3] kdb: Add framework to display sequence files Date: Wed, 30 Apr 2014 16:40:25 +0100 Message-Id: <1398872427-18435-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1398872427-18435-1-git-send-email-daniel.thompson@linaro.org> References: <1398781841-15152-1-git-send-email-daniel.thompson@linaro.org> <1398872427-18435-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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 | 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 #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 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; +}