From patchwork Thu Feb 25 17:57:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8425661 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 548FDC0553 for ; Thu, 25 Feb 2016 18:01:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8041520279 for ; Thu, 25 Feb 2016 18:01:09 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9809320263 for ; Thu, 25 Feb 2016 18:01:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZ0Aj-0005wN-MR; Thu, 25 Feb 2016 17:57:53 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZ0Ai-0005vy-8Q for xen-devel@lists.xen.org; Thu, 25 Feb 2016 17:57:52 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 9F/FA-23864-F904FC65; Thu, 25 Feb 2016 17:57:51 +0000 X-Env-Sender: prvs=856d69d10=Andrew.Cooper3@citrix.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1456423069!24561573!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 59235 invoked from network); 25 Feb 2016 17:57:50 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 25 Feb 2016 17:57:50 -0000 X-IronPort-AV: E=Sophos;i="5.22,498,1449532800"; d="scan'208";a="334552618" From: Andrew Cooper To: Xen-devel Date: Thu, 25 Feb 2016 17:57:32 +0000 Message-ID: <1456423052-19300-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Tim Deegan , Ian Campbell , Jan Beulich Subject: [Xen-devel] [PATCH] xen: Introduce separator modifiers for the %ph custom printk X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The printk formats %*ph{C,D,N} are chosen to be compatible with their Linux counterparts. Sample: (XEN) buf: 00 01 03 07 78 65 6e 00 (XEN) buf: 00:01:03:07:78:65:6e:00 (XEN) buf: 00-01-03-07-78-65-6e-00 (XEN) buf: 0001030778656e00 Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell CC: Konrad Rzeszutek Wilk --- docs/misc/printk-formats.txt | 9 +++++++-- xen/common/vsprintf.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt index dee0f3e..525108f 100644 --- a/docs/misc/printk-formats.txt +++ b/docs/misc/printk-formats.txt @@ -5,8 +5,13 @@ pointers are fine. Numbers should make use of the _p() macro. Raw buffer as hex string: - %*ph Up to 64 characters, printed as "00 01 02 ... ff". Buffer length - expected via the field_width paramter. i.e. printk("%*ph", 8, buffer); + %*ph 00 01 02 ... 3f + %*phC 00:01:02: ... :3f + %*phD 00-01-02- ... -3f + %*phN 000102 ... 3f + + Up to 64 characters. Buffer length expected via the field_width + paramter. i.e. printk("%*ph", 8, buffer); Symbol/Function pointers: diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index 51b5e4e..18d2634 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -275,6 +275,7 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, case 'h': /* Raw buffer as hex string. */ { const uint8_t *hex_buffer = arg; + char sep = ' '; /* Separator character. */ unsigned int i; /* Consumed 'h' from the format string. */ @@ -286,6 +287,28 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, if ( field_width > 64 ) field_width = 64; + /* + * Peek ahead in the format string to see if a recognised separator + * modifier is present. + */ + switch ( fmt[2] ) + { + case 'C': /* Colons. */ + ++*fmt_ptr; + sep = ':'; + break; + + case 'D': /* Dashes. */ + ++*fmt_ptr; + sep = '-'; + break; + + case 'N': /* No separator. */ + ++*fmt_ptr; + sep = 0; + break; + } + for ( i = 0; ; ) { /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */ @@ -294,9 +317,12 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, if ( ++i == field_width ) return str; - if ( str < end ) - *str = ' '; - ++str; + if ( sep ) + { + if ( str < end ) + *str = sep; + ++str; + } } }