From patchwork Tue Apr 29 14:30:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 29358 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D14FB202FE for ; Tue, 29 Apr 2014 14:31:18 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id kq14sf1235107pab.9 for ; Tue, 29 Apr 2014 07:31:13 -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=LNWylqae/laT8qbE46tTrRouYB2BPjv/12a9Q3nK/ao=; b=FwSqC5N5drxOE2xK82pGrnRrbX8J3XKSW+punL1iMQmv00ZHJ/+cV+yQq9dDlNxAOK bKk4iZ04gPH+KpfD5GpBzqan2nG0XJWCy56iVEdi4xVHeG8D/LGC5MkoJ0/Ie9iPov9u cx+0hfZvAix1RhojHwzlbqS5C954uKE9l9WiDqMdJjADgtItnADOgk1IPp4+gzrQUEcn kwyVr1l94HtmmiTd+q+TwP5nsO22/UtC7olLVyhldpHVK/qXJUK2GQ9/3RydtB3BWyq2 BZdz/HbxG8drW9161JHf79mkqU/ChBbv8uWToY2JjQHTJiujiyE/IfpAu7U38VIu5LBS 0lEg== X-Gm-Message-State: ALoCoQld0IiI73dVr1Crd0/qNpR2nj3ln+x8sbxZRgJsyMUykWbOFbO9a2oasJ0WYaX8bQTyWTJh X-Received: by 10.66.232.229 with SMTP id tr5mr4961546pac.16.1398781871556; Tue, 29 Apr 2014 07:31:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.180 with SMTP id w49ls126888qge.3.gmail; Tue, 29 Apr 2014 07:31:11 -0700 (PDT) X-Received: by 10.220.191.134 with SMTP id dm6mr30020795vcb.16.1398781871435; Tue, 29 Apr 2014 07:31:11 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id jb7si4543626vec.197.2014.04.29.07.31.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 07:31:11 -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.220.182; Received: by mail-vc0-f182.google.com with SMTP id lf12so370278vcb.41 for ; Tue, 29 Apr 2014 07:31:11 -0700 (PDT) X-Received: by 10.58.185.145 with SMTP id fc17mr30688830vec.14.1398781871366; Tue, 29 Apr 2014 07:31:11 -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 ib8csp202442vcb; Tue, 29 Apr 2014 07:31:10 -0700 (PDT) X-Received: by 10.180.94.8 with SMTP id cy8mr20684195wib.29.1398781870375; Tue, 29 Apr 2014 07:31:10 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by mx.google.com with ESMTPS id dq1si1438120wid.113.2014.04.29.07.31.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 07:31:10 -0700 (PDT) Received-SPF: none (google.com: daniel.thompson@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.177; Received: by mail-wi0-f177.google.com with SMTP id cc10so552828wib.4 for ; Tue, 29 Apr 2014 07:31:09 -0700 (PDT) X-Received: by 10.180.94.37 with SMTP id cz5mr20817233wib.19.1398781869798; Tue, 29 Apr 2014 07:31:09 -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 uc3sm5389589wib.10.2014.04.29.07.31.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Apr 2014 07:31:08 -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: Tue, 29 Apr 2014 15:30:38 +0100 Message-Id: <1398781841-15152-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1398781841-15152-1-git-send-email-daniel.thompson@linaro.org> References: <1398781841-15152-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 | 3 +++ kernel/debug/kdb/kdb_io.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/linux/kdb.h b/include/linux/kdb.h index 290db12..2607893 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 */ 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; +}