From patchwork Wed May 13 20:16:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 6713 Received: (qmail 8736 invoked by alias); 13 May 2015 20:16:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 8722 invoked by uid 89); 13 May 2015 20:16:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 13 May 2015 20:16:37 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id ED3913F0A4 for ; Wed, 13 May 2015 20:16:35 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4DKGYw7026387; Wed, 13 May 2015 16:16:34 -0400 Subject: [PATCH v5 2/7] Code cleanup: Make parts of print_command_1 public From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Phil Muldoon Date: Wed, 13 May 2015 22:16:33 +0200 Message-ID: <20150513201633.4051.19277.stgit@host1.jankratochvil.net> In-Reply-To: <20150513201615.4051.5261.stgit@host1.jankratochvil.net> References: <20150513201615.4051.5261.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes The later 'compile print' command should share its behavior with the existing 'print' command. Make the needed existing parts of print_command_1 public. gdb/ChangeLog 2015-05-03 Jan Kratochvil * printcmd.c (struct format_data): Move it to valprint.h. (print_command_parse_format, print_value): New functions from ... (print_command_1): ... here. Call them. * valprint.h (struct format_data): Move it here from printcmd.c. (print_command_parse_format, print_value): New declarations. --- gdb/printcmd.c | 97 +++++++++++++++++++++++++++++++------------------------- gdb/valprint.h | 15 +++++++++ 2 files changed, 68 insertions(+), 44 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index deb501a..0ae402f 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -52,17 +52,6 @@ #include "tui/tui.h" /* For tui_active et al. */ #endif -struct format_data - { - int count; - char format; - char size; - - /* True if the value should be printed raw -- that is, bypassing - python-based formatters. */ - unsigned char raw; - }; - /* Last specified output format. */ static char last_format = 0; @@ -939,6 +928,57 @@ validate_format (struct format_data fmt, const char *cmdname) fmt.format, cmdname); } +/* Parse print command format string into *FMTP and update *EXPP. + CMDNAME should name the current command. */ + +void +print_command_parse_format (const char **expp, const char *cmdname, + struct format_data *fmtp) +{ + const char *exp = *expp; + + if (exp && *exp == '/') + { + exp++; + *fmtp = decode_format (&exp, last_format, 0); + validate_format (*fmtp, cmdname); + last_format = fmtp->format; + } + else + { + fmtp->count = 1; + fmtp->format = 0; + fmtp->size = 0; + fmtp->raw = 0; + } + + *expp = exp; +} + +/* Print VAL to console according to *FMTP, including recording it to + the history. */ + +void +print_value (struct value *val, const struct format_data *fmtp) +{ + struct value_print_options opts; + int histindex = record_latest_value (val); + + annotate_value_history_begin (histindex, value_type (val)); + + printf_filtered ("$%d = ", histindex); + + annotate_value_history_value (); + + get_formatted_print_options (&opts, fmtp->format); + opts.raw = fmtp->raw; + + print_formatted (val, fmtp->size, &opts, gdb_stdout); + printf_filtered ("\n"); + + annotate_value_history_end (); +} + /* Evaluate string EXP as an expression in the current language and print the resulting value. EXP may contain a format specifier as the first argument ("/x myvar" for example, to print myvar in hex). */ @@ -948,24 +988,10 @@ print_command_1 (const char *exp, int voidprint) { struct expression *expr; struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); - char format = 0; struct value *val; struct format_data fmt; - if (exp && *exp == '/') - { - exp++; - fmt = decode_format (&exp, last_format, 0); - validate_format (fmt, "print"); - last_format = format = fmt.format; - } - else - { - fmt.count = 1; - fmt.format = 0; - fmt.size = 0; - fmt.raw = 0; - } + print_command_parse_format (&exp, "print", &fmt); if (exp && *exp) { @@ -978,24 +1004,7 @@ print_command_1 (const char *exp, int voidprint) if (voidprint || (val && value_type (val) && TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) - { - struct value_print_options opts; - int histindex = record_latest_value (val); - - annotate_value_history_begin (histindex, value_type (val)); - - printf_filtered ("$%d = ", histindex); - - annotate_value_history_value (); - - get_formatted_print_options (&opts, format); - opts.raw = fmt.raw; - - print_formatted (val, fmt.size, &opts, gdb_stdout); - printf_filtered ("\n"); - - annotate_value_history_end (); - } + print_value (val, &fmt); do_cleanups (old_chain); } diff --git a/gdb/valprint.h b/gdb/valprint.h index e3d0137..ed4964f 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -217,4 +217,19 @@ extern void output_command_const (const char *args, int from_tty); extern int val_print_scalar_type_p (struct type *type); +struct format_data + { + int count; + char format; + char size; + + /* True if the value should be printed raw -- that is, bypassing + python-based formatters. */ + unsigned char raw; + }; + +extern void print_command_parse_format (const char **expp, const char *cmdname, + struct format_data *fmtp); +extern void print_value (struct value *val, const struct format_data *fmtp); + #endif