public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Phil Muldoon <pmuldoon@redhat.com>
Subject: [PATCH v4 02/11] Code cleanup: Make parts of print_command_1 public
Date: Sun, 03 May 2015 14:07:00 -0000	[thread overview]
Message-ID: <20150503140704.18583.66258.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150503140647.18583.2012.stgit@host1.jankratochvil.net>

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  <jan.kratochvil@redhat.com>

	* 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

  parent reply	other threads:[~2015-05-03 14:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-03 14:06 [PATCH v4 00/11] compile: compile print&printf Jan Kratochvil
2015-05-03 14:07 ` [PATCH v4 07/11] Code cleanup: compile: func_addr -> func_sym Jan Kratochvil
2015-05-03 14:07 ` [PATCH v4 03/11] compile: Distribute scope, add scope_data Jan Kratochvil
2015-05-03 14:07 ` [PATCH v4 01/11] compile: Add one debug message Jan Kratochvil
2015-05-03 14:07 ` [PATCH v4 06/11] compile: Use -Wall, not -w Jan Kratochvil
2015-05-03 14:07 ` [PATCH v4 04/11] Code cleanup: compile: Constify some parameters Jan Kratochvil
2015-05-03 14:07 ` [PATCH v4 05/11] compile: Support relocation to GNU-IFUNCs Jan Kratochvil
2015-05-03 14:07 ` Jan Kratochvil [this message]
2015-05-03 14:07 ` [PATCH v4 08/11] compile: New 'compile print' Jan Kratochvil
2015-05-03 14:08 ` [PATCH v4 09/11] compile: New compile printf Jan Kratochvil
2015-05-03 14:08 ` [PATCH v4 11/11] RFC only: compile: Use also inferior munmap Jan Kratochvil
2015-05-06 15:21   ` Pedro Alves
2015-05-06 19:32     ` Jan Kratochvil
2015-05-08 20:23       ` Jan Kratochvil
2015-05-03 14:08 ` [PATCH v4 10/11] compile: compile printf: gdbserver support Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150503140704.18583.66258.stgit@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pmuldoon@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).