public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/4] compile: Constify some parameters
  2015-03-26 20:57 [PATCH 1/4] Code cleanup: Make parts of print_command_1 public Jan Kratochvil
@ 2015-03-26 20:57 ` Jan Kratochvil
  2015-04-06 17:28   ` obsolete: " Jan Kratochvil
  2015-03-26 20:57 ` [PATCH 2/4] compile: Add new field scope_data Jan Kratochvil
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-26 20:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

gdb/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile.c (compile_to_object): Make the cmd_string parameter
	const.  Use new variables for the const compatibility.
        (eval_compile_command): Make the cmd_string parameter const.
	* compile/compile.h (eval_compile_command): Make the cmd_string
	parameter const.
---
 gdb/compile/compile.c |   15 +++++++++------
 gdb/compile/compile.h |    3 ++-
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 7fe556d..7589f2a 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -415,11 +415,12 @@ print_callback (void *ignore, const char *message)
    freeing both strings.  */
 
 static char *
-compile_to_object (struct command_line *cmd, char *cmd_string,
+compile_to_object (struct command_line *cmd, const char *cmd_string,
 		   enum compile_i_scope_types scope,
 		   char **source_filep)
 {
   char *code;
+  const char *input;
   char *source_file, *object_file;
   struct compile_instance *compiler;
   struct cleanup *cleanup, *inner_cleanup;
@@ -459,6 +460,7 @@ compile_to_object (struct command_line *cmd, char *cmd_string,
     {
       struct ui_file *stream = mem_fileopen ();
       struct command_line *iter;
+      char *stream_buf;
 
       make_cleanup_ui_file_delete (stream);
       for (iter = cmd->body_list[0]; iter; iter = iter->next)
@@ -467,15 +469,16 @@ compile_to_object (struct command_line *cmd, char *cmd_string,
 	  fputs_unfiltered ("\n", stream);
 	}
 
-      code = ui_file_xstrdup (stream, NULL);
-      make_cleanup (xfree, code);
+      stream_buf = ui_file_xstrdup (stream, NULL);
+      make_cleanup (xfree, stream_buf);
+      input = stream_buf;
     }
   else if (cmd_string != NULL)
-    code = cmd_string;
+    input = cmd_string;
   else
     error (_("Neither a simple expression, or a multi-line specified."));
 
-  code = current_language->la_compute_program (compiler, code, gdbarch,
+  code = current_language->la_compute_program (compiler, input, gdbarch,
 					       expr_block, expr_pc);
   make_cleanup (xfree, code);
   if (compile_debug)
@@ -554,7 +557,7 @@ compile_command (char *args, int from_tty)
 /* See compile.h.  */
 
 void
-eval_compile_command (struct command_line *cmd, char *cmd_string,
+eval_compile_command (struct command_line *cmd, const char *cmd_string,
 		      enum compile_i_scope_types scope, void *scope_data)
 {
   char *object_file, *source_file;
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index 93c4786..a973167 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -28,7 +28,8 @@ struct dynamic_prop;
    expression command.  GDB returns either a CMD, or a CMD_STRING, but
    never both.  */
 
-extern void eval_compile_command (struct command_line *cmd, char *cmd_string,
+extern void eval_compile_command (struct command_line *cmd,
+				  const char *cmd_string,
 				  enum compile_i_scope_types scope,
 				  void *scope_data);
 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 2/4] compile: Add new field scope_data
  2015-03-26 20:57 [PATCH 1/4] Code cleanup: Make parts of print_command_1 public Jan Kratochvil
  2015-03-26 20:57 ` [PATCH 3/4] compile: Constify some parameters Jan Kratochvil
@ 2015-03-26 20:57 ` Jan Kratochvil
  2015-04-06 17:28   ` obsolete: " Jan Kratochvil
  2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
  2015-03-27 20:06 ` [PATCH 1/4] v2: Code cleanup: Make parts of print_command_1 public Jan Kratochvil
  3 siblings, 1 reply; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-26 20:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

Provide a way to associate more data with enum compile_i_scope_types up to the
struct do_module_cleanup stage.

It should be all sub-classed but AFAIK GDB does not require C++ compiler yet.

gdb/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

        * cli/cli-script.c (execute_control_command): Update
	eval_compile_command caller.
	* compile/compile-object-load.h (struct compile_module): Add field
	scope_data.
	* compile/compile-object-run.c (struct do_module_cleanup): Add field
	scope_data.
        (compile_object_run): Propage the field scope_data.
	* compile/compile.c (compile_file_command, compile_code_command):
	Update eval_compile_command callers.
        (eval_compile_command): Add parameter scope_data.  Set it.
        * compile/compile.h (eval_compile_command): Add parameter scope_data.
        * defs.h (struct command_line): Add field scope_data.
---
 gdb/cli/cli-script.c              |    3 ++-
 gdb/compile/compile-object-load.h |    3 +++
 gdb/compile/compile-object-run.c  |    4 ++++
 gdb/compile/compile.c             |    7 ++++---
 gdb/compile/compile.h             |    3 ++-
 gdb/defs.h                        |    1 +
 6 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 7a4ed78..4bd18a7 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -615,7 +615,8 @@ execute_control_command (struct command_line *cmd)
       }
 
     case compile_control:
-      eval_compile_command (cmd, NULL, cmd->control_u.compile.scope);
+      eval_compile_command (cmd, NULL, cmd->control_u.compile.scope,
+			    cmd->control_u.compile.scope_data);
       ret = simple_control;
       break;
 
diff --git a/gdb/compile/compile-object-load.h b/gdb/compile/compile-object-load.h
index bef575e..ed3ac3a 100644
--- a/gdb/compile/compile-object-load.h
+++ b/gdb/compile/compile-object-load.h
@@ -31,6 +31,9 @@ struct compile_module
   /* Inferior registers address or NULL if the inferior function does not
      require any.  */
   CORE_ADDR regs_addr;
+
+  /* User data for enum compile_i_scope_types in use.  */
+  void *scope_data;
 };
 
 extern struct compile_module *compile_object_load (const char *object_file,
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 6738aad..0864712 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -36,6 +36,9 @@ struct do_module_cleanup
   /* .c file OBJFILE was built from.  It needs to be xfree-d.  */
   char *source_file;
 
+  /* User data for enum compile_i_scope_types in use.  */
+  void *scope_data;
+
   /* objfile_name of our objfile.  */
   char objfile_name_string[1];
 };
@@ -96,6 +99,7 @@ compile_object_run (struct compile_module *module)
   data->executedp = &executed;
   data->source_file = xstrdup (module->source_file);
   strcpy (data->objfile_name_string, objfile_name_s);
+  data->scope_data = module->scope_data;
 
   xfree (module->source_file);
   xfree (module);
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 1d342a0..7fe556d 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -117,7 +117,7 @@ compile_file_command (char *arg, int from_tty)
   make_cleanup (xfree, arg);
   buffer = xstrprintf ("#include \"%s\"\n", arg);
   make_cleanup (xfree, buffer);
-  eval_compile_command (NULL, buffer, scope);
+  eval_compile_command (NULL, buffer, scope, NULL);
   do_cleanups (cleanup);
 }
 
@@ -150,7 +150,7 @@ compile_code_command (char *arg, int from_tty)
     }
 
   if (arg && *arg)
-      eval_compile_command (NULL, arg, scope);
+    eval_compile_command (NULL, arg, scope, NULL);
   else
     {
       struct command_line *l = get_command_line (compile_control, "");
@@ -555,7 +555,7 @@ compile_command (char *args, int from_tty)
 
 void
 eval_compile_command (struct command_line *cmd, char *cmd_string,
-		      enum compile_i_scope_types scope)
+		      enum compile_i_scope_types scope, void *scope_data)
 {
   char *object_file, *source_file;
 
@@ -572,6 +572,7 @@ eval_compile_command (struct command_line *cmd, char *cmd_string,
       compile_module = compile_object_load (object_file, source_file);
       discard_cleanups (cleanup_unlink);
       do_cleanups (cleanup_xfree);
+      compile_module->scope_data = scope_data;
       compile_object_run (compile_module);
     }
 }
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index 1e3f934..93c4786 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -29,7 +29,8 @@ struct dynamic_prop;
    never both.  */
 
 extern void eval_compile_command (struct command_line *cmd, char *cmd_string,
-				  enum compile_i_scope_types scope);
+				  enum compile_i_scope_types scope,
+				  void *scope_data);
 
 /* Compile a DWARF location expression to C, suitable for use by the
    compiler.
diff --git a/gdb/defs.h b/gdb/defs.h
index 72512f6..6476f80 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -400,6 +400,7 @@ struct command_line
 	struct
 	  {
 	    enum compile_i_scope_types scope;
+	    void *scope_data;
 	  }
 	compile;
       }

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/4] Code cleanup: Make parts of print_command_1 public
@ 2015-03-26 20:57 Jan Kratochvil
  2015-03-26 20:57 ` [PATCH 3/4] compile: Constify some parameters Jan Kratochvil
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-26 20:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

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-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* printcmd.c (print_command_parse_format, print_value): New functions
	from ...
	(print_command_1): ... here.  Call them.
	* valprint.h (struct format_data, print_command_parse_format)
	(print_value): New declarations.
---
 gdb/printcmd.c |   89 +++++++++++++++++++++++++++++++++-----------------------
 gdb/valprint.h |    5 +++
 2 files changed, 58 insertions(+), 36 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a1451f8..4efdf1b 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -939,6 +939,56 @@ validate_format (struct format_data fmt, const char *cmdname)
 	   fmt.format, cmdname);
 }
 
+/* Parse print command format string and update *EXPP, return it allocated,
+   caller has to call xfree for it.  Return NULL if no format string has been
+   found.  CMDNAME should name the current command.  */
+
+struct format_data *
+print_command_parse_format (const char **expp, const char *cmdname)
+{
+  struct format_data *fmtp;
+  const char *exp = *expp;
+  struct cleanup *cleanup;
+
+  if (exp == NULL || *exp != '/')
+    return NULL;
+  exp++;
+
+  fmtp = xmalloc (sizeof (*fmtp));
+  cleanup = make_cleanup (xfree, fmtp);
+  *fmtp = decode_format (&exp, last_format, 0);
+  validate_format (*fmtp, cmdname);
+  last_format = fmtp->format;
+
+  discard_cleanups (cleanup);
+  *expp = exp;
+  return fmtp;
+}
+
+
+/* Print VAL to console, 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 == NULL ? 0 : fmtp->format));
+  opts.raw = (fmtp == NULL ? 0 : fmtp->raw);
+
+  print_formatted (val, (fmtp == NULL ? 0 : 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).  */
@@ -946,25 +996,9 @@ validate_format (struct format_data fmt, const char *cmdname)
 static void
 print_command_1 (const char *exp, int voidprint)
 {
-  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;
-    }
+  struct format_data *fmtp = print_command_parse_format (&exp, "print");
+  struct cleanup *old_chain = make_cleanup (xfree, fmtp);
 
   if (exp && *exp)
     {
@@ -979,24 +1013,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, fmtp);
 
   do_cleanups (old_chain);
 }
diff --git a/gdb/valprint.h b/gdb/valprint.h
index e3d0137..3ab531f 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -217,4 +217,9 @@ extern void output_command_const (const char *args, int from_tty);
 
 extern int val_print_scalar_type_p (struct type *type);
 
+struct format_data;
+extern struct format_data *print_command_parse_format (const char **expp,
+						       const char *cmdname);
+extern void print_value (struct value *val, const struct format_data *fmtp);
+
 #endif

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 4/4] compile: New 'compile print'
  2015-03-26 20:57 [PATCH 1/4] Code cleanup: Make parts of print_command_1 public Jan Kratochvil
  2015-03-26 20:57 ` [PATCH 3/4] compile: Constify some parameters Jan Kratochvil
  2015-03-26 20:57 ` [PATCH 2/4] compile: Add new field scope_data Jan Kratochvil
@ 2015-03-26 20:58 ` Jan Kratochvil
  2015-03-26 20:59   ` Jan Kratochvil
                     ` (3 more replies)
  2015-03-27 20:06 ` [PATCH 1/4] v2: Code cleanup: Make parts of print_command_1 public Jan Kratochvil
  3 siblings, 4 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-26 20:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

It is planned the existing GDB command 'print' will be able to evaluate its
expressions using the compiler.  There will be some option to choose between
the existing GDB evaluation and the compiler evaluation.  But as an
intermediate step this patch provides the expression printing feature as a new
command.

I can imagine it could be also called 'maintenance compile print' as in the
future one should be able to use its functionality by the normal 'print'
command.

Support for the GDB '@' operator to create arrays is going to be submitted for
GCC, currently the patch is the top commit at:
	https://github.com/jankratochvil/gcc/tree/jankratochvil/atsign

gdb/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (Changes since GDB 7.9): Add compile print.
	* compile/compile-c-support.c (add_code_header, add_code_footer)
	(c_compute_program): Add COMPILE_I_PRINT_SCOPE.
	* compile/compile-internal.h (COMPILE_I_PRINT_OUT_ARG_TYPE)
	(COMPILE_I_PRINT_OUT_ARG, COMPILE_I_PRINT_EXPR_TAKE_ADDRESS_TYPE)
	(COMPILE_I_PRINT_EXPR_TAKE_ADDRESS, COMPILE_I_EXPR_VAL)
	(COMPILE_I_EXPR_PTR_TYPE): New.
	* compile/compile-object-load.c: Include block.h.
	(get_out_value_type): New function.
	(get_regs_type): Add support for COMPILE_I_PRINT_EXPR_TAKE_ADDRESS.
	(compile_object_load): Add parameter has_out_arg.  Set compile_module's
	OUT_VALUE_ADDR, OUT_VALUE_TYPE and OUT_VALUE_TAKE_ADDRESS.
	* compile/compile-object-load.h (struct compile_module): Add fields
	out_value_addr, out_value_take_address and out_value_type.
	(compile_object_load): Add parameter has_out_arg.
	* compile/compile-object-run.c: Include valprint.h and compile.h.
	(struct do_module_cleanup): Add fields out_value_addr and
	out_value_type.
	(do_module_cleanup): Call compile_print_value for OUT_VALUE_ADDR.
	(compile_object_run): Pass out_value_addr and out_value_take_address.
	* compile/compile.c: Include valprint.h.
	(compile_print_value, compile_print_command): New functions.
	(eval_compile_command): Update compile_object_load caller.
	(_initialize_compile): Install compile_print_command.
	* compile/compile.h (compile_print_value): New prototype.
	* defs.h (enum compile_i_scope_types): Add COMPILE_I_PRINT_SCOPE.

gdb/doc/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Compiling and Injecting Code): Add compile print.

gdb/testsuite/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.compile/compile-print.c: New file.
	* gdb.compile/compile-print.exp: New file.
---
 gdb/NEWS                                    |    3 +
 gdb/compile/compile-c-support.c             |   41 +++++++-
 gdb/compile/compile-internal.h              |    6 +
 gdb/compile/compile-object-load.c           |  143 ++++++++++++++++++++++++++-
 gdb/compile/compile-object-load.h           |   15 +++
 gdb/compile/compile-object-run.c            |   60 ++++++++++-
 gdb/compile/compile.c                       |   71 +++++++++++++
 gdb/compile/compile.h                       |    2 
 gdb/defs.h                                  |    5 +
 gdb/doc/gdb.texinfo                         |   19 ++++
 gdb/testsuite/gdb.compile/compile-print.c   |   28 +++++
 gdb/testsuite/gdb.compile/compile-print.exp |   56 +++++++++++
 12 files changed, 435 insertions(+), 14 deletions(-)
 create mode 100644 gdb/testsuite/gdb.compile/compile-print.c
 create mode 100644 gdb/testsuite/gdb.compile/compile-print.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index 3fa33c9..0aa6365 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -32,6 +32,9 @@ record btrace bts
 record bts
   Start branch trace recording using Branch Trace Store (BTS) format.
 
+compile print
+  Evaluate expression with the compiler and print result.
+
 * New options
 
 set max-completions
diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c
index 1711cda..027b678 100644
--- a/gdb/compile/compile-c-support.c
+++ b/gdb/compile/compile-c-support.c
@@ -188,6 +188,25 @@ add_code_header (enum compile_i_scope_types type, struct ui_file *buf)
 			") {\n",
 			buf);
       break;
+    case COMPILE_I_PRINT_SCOPE:
+      fputs_unfiltered ("void "
+			GCC_FE_WRAPPER_FUNCTION
+			" (struct "
+			COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG
+			" *"
+			COMPILE_I_SIMPLE_REGISTER_ARG_NAME
+			", "
+			COMPILE_I_PRINT_OUT_ARG_TYPE
+			" "
+			COMPILE_I_PRINT_OUT_ARG
+			", "
+			COMPILE_I_PRINT_EXPR_TAKE_ADDRESS_TYPE
+			" "
+			COMPILE_I_PRINT_EXPR_TAKE_ADDRESS
+			") {\n",
+			buf);
+      break;
+
     case COMPILE_I_RAW_SCOPE:
       break;
     default:
@@ -205,6 +224,7 @@ add_code_footer (enum compile_i_scope_types type, struct ui_file *buf)
   switch (type)
     {
     case COMPILE_I_SIMPLE_SCOPE:
+    case COMPILE_I_PRINT_SCOPE:
       fputs_unfiltered ("}\n", buf);
       break;
     case COMPILE_I_RAW_SCOPE:
@@ -367,7 +387,8 @@ c_compute_program (struct compile_instance *inst,
 
   add_code_header (inst->scope, buf);
 
-  if (inst->scope == COMPILE_I_SIMPLE_SCOPE)
+  if (inst->scope == COMPILE_I_SIMPLE_SCOPE
+      || inst->scope == COMPILE_I_PRINT_SCOPE)
     {
       ui_file_put (var_stream, ui_file_write_for_put, buf);
       fputs_unfiltered ("#pragma GCC user_expression\n", buf);
@@ -381,7 +402,23 @@ c_compute_program (struct compile_instance *inst,
     fputs_unfiltered ("{\n", buf);
 
   fputs_unfiltered ("#line 1 \"gdb command line\"\n", buf);
-  fputs_unfiltered (input, buf);
+
+  if (inst->scope == COMPILE_I_PRINT_SCOPE)
+    {
+      fprintf_unfiltered (buf,
+"__auto_type " COMPILE_I_EXPR_VAL " = %s;\n"
+"typeof (%s) *" COMPILE_I_EXPR_PTR_TYPE ";\n"
+"if (" COMPILE_I_PRINT_EXPR_TAKE_ADDRESS ")\n"
+"\tmemcpy (" COMPILE_I_PRINT_OUT_ARG ", &" COMPILE_I_EXPR_VAL ",\n"
+	   "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n"
+"else\n"
+"\tmemcpy (" COMPILE_I_PRINT_OUT_ARG ", "  COMPILE_I_EXPR_VAL ",\n"
+	   "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n"
+			  , input, input);
+    }
+  else
+    fputs_unfiltered (input, buf);
+
   fputs_unfiltered ("\n", buf);
 
   /* For larger user expressions the automatic semicolons may be
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index c369d46..a5893b2 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -84,6 +84,12 @@ struct compile_c_instance
 #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs"
 #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs"
 #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy"
+#define COMPILE_I_PRINT_OUT_ARG_TYPE "void *"
+#define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param"
+#define COMPILE_I_PRINT_EXPR_TAKE_ADDRESS_TYPE "int"
+#define COMPILE_I_PRINT_EXPR_TAKE_ADDRESS "__gdb_expr_take_address"
+#define COMPILE_I_EXPR_VAL "__gdb_expr_val"
+#define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type"
 
 /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
    to a form suitable for the compiler source.  The register names
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 8a7f232..f57b34e 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -29,6 +29,7 @@
 #include "regcache.h"
 #include "inferior.h"
 #include "compile.h"
+#include "block.h"
 #include "arch-utils.h"
 
 /* Helper data for setup_sections.  */
@@ -354,6 +355,114 @@ copy_sections (bfd *abfd, asection *sect, void *data)
   do_cleanups (cleanups);
 }
 
+/* Fetch the type of COMPILE_I_EXPR_PTR_TYPE and COMPILE_I_EXPR_VAL
+   symbols in OBJFILE so we can calculate how much memory to allocate
+   for the out parameter.  This avoids needing a malloc in the generated
+   code.  Throw an error if anything fails.
+   Set *OUT_VALUE_TAKE_ADDRESSP depending whether inferior code should
+   copy COMPILE_I_EXPR_VAL or its address - this depends on __auto_type
+   array-to-pointer type conversion of COMPILE_I_EXPR_VAL, as detected
+   by COMPILE_I_EXPR_PTR_TYPE preserving the array type.  */
+
+static struct type *
+get_out_value_type (struct objfile *objfile, int *out_value_take_addressp)
+{
+  struct symbol *func_sym, *gdb_ptr_type_sym, *gdb_val_sym;
+  struct type *gdb_ptr_type, *gdb_type_from_ptr, *gdb_type, *retval;
+  const struct block *block;
+  const struct blockvector *bv;
+  int nblocks = 0;
+  int block_loop = 0;
+
+  func_sym = lookup_global_symbol_from_objfile (objfile,
+						GCC_FE_WRAPPER_FUNCTION,
+						VAR_DOMAIN);
+  if (func_sym == NULL)
+    error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
+	   GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
+
+  bv = SYMTAB_BLOCKVECTOR (func_sym->owner.symtab);
+  nblocks = BLOCKVECTOR_NBLOCKS (bv);
+
+  gdb_ptr_type_sym = NULL;
+  for (block_loop = 0; block_loop < nblocks; block_loop++)
+    {
+      struct symbol *function;
+      const struct block *function_block;
+
+      block = BLOCKVECTOR_BLOCK (bv, block_loop);
+      if (BLOCK_FUNCTION (block) != NULL)
+	continue;
+      gdb_ptr_type_sym = block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE,
+					      VAR_DOMAIN);
+      if (gdb_ptr_type_sym == NULL)
+	continue;
+
+      function_block = block;
+      while (function_block != BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)
+	     && function_block != BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))
+	{
+	  function_block = BLOCK_SUPERBLOCK (function_block);
+	  function = BLOCK_FUNCTION (function_block);
+	  if (function != NULL)
+	    break;
+	}
+      if (function != NULL
+	  && (BLOCK_SUPERBLOCK (function_block)
+	      == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
+	  && (strcmp (SYMBOL_LINKAGE_NAME (function), GCC_FE_WRAPPER_FUNCTION)
+	      == 0))
+	break;
+    }
+  if (block_loop == nblocks)
+    error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE);
+
+  gdb_ptr_type = SYMBOL_TYPE (gdb_ptr_type_sym);
+  CHECK_TYPEDEF (gdb_ptr_type);
+  if (TYPE_CODE (gdb_ptr_type) != TYPE_CODE_PTR)
+    error (_("Type of \"%s\" is not a pointer"), COMPILE_I_EXPR_PTR_TYPE);
+  gdb_type_from_ptr = TYPE_TARGET_TYPE (gdb_ptr_type);
+
+  gdb_val_sym = block_lookup_symbol (block, COMPILE_I_EXPR_VAL, VAR_DOMAIN);
+  if (gdb_val_sym == NULL)
+    error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_VAL);
+  gdb_type = SYMBOL_TYPE (gdb_val_sym);
+  CHECK_TYPEDEF (gdb_type);
+
+  *out_value_take_addressp = types_deeply_equal (gdb_type, gdb_type_from_ptr);
+  if (*out_value_take_addressp)
+    return gdb_type;
+
+  if (TYPE_CODE (gdb_type) != TYPE_CODE_PTR)
+    error (_("Invalid type code %d of symbol \"%s\" "
+	     "in compiled module \"%s\"."),
+	   TYPE_CODE (gdb_type_from_ptr), COMPILE_I_EXPR_VAL,
+	   objfile_name (objfile));
+  
+  switch (TYPE_CODE (gdb_type_from_ptr))
+    {
+    case TYPE_CODE_ARRAY:
+      retval = gdb_type_from_ptr;
+      gdb_type_from_ptr = TYPE_TARGET_TYPE (gdb_type_from_ptr);
+      break;
+    case TYPE_CODE_FUNC:
+      retval = gdb_type_from_ptr;
+      break;
+    default:
+      error (_("Invalid type code %d of symbol \"%s\" "
+	       "in compiled module \"%s\"."),
+	     TYPE_CODE (gdb_type_from_ptr), COMPILE_I_EXPR_PTR_TYPE,
+	     objfile_name (objfile));
+    }
+  if (!types_deeply_equal (gdb_type_from_ptr,
+			   TYPE_TARGET_TYPE (gdb_type)))
+    error (_("Referenced types do not match for symbols \"%s\" and \"%s\" "
+	     "in compiled module \"%s\"."),
+	   COMPILE_I_EXPR_PTR_TYPE, COMPILE_I_EXPR_VAL,
+	   objfile_name (objfile));
+  return retval;
+}
+
 /* Fetch the type of first parameter of GCC_FE_WRAPPER_FUNCTION.
    Return NULL if GCC_FE_WRAPPER_FUNCTION has no parameters.
    Throw an error otherwise.  */
@@ -362,7 +471,7 @@ static struct type *
 get_regs_type (struct objfile *objfile)
 {
   struct symbol *func_sym;
-  struct type *func_type, *regsp_type, *regs_type;
+  struct type *func_type, *regsp_type, *regs_type, *take_address_type;
 
   func_sym = lookup_global_symbol_from_objfile (objfile,
 						GCC_FE_WRAPPER_FUNCTION,
@@ -382,7 +491,7 @@ get_regs_type (struct objfile *objfile)
   if (TYPE_NFIELDS (func_type) == 0)
     return NULL;
 
-  if (TYPE_NFIELDS (func_type) != 1)
+  if (TYPE_NFIELDS (func_type) != 1 && TYPE_NFIELDS (func_type) != 3)
     error (_("Invalid %d parameters of function \"%s\" in compiled "
 	     "module \"%s\"."),
 	   TYPE_NFIELDS (func_type), GCC_FE_WRAPPER_FUNCTION,
@@ -402,6 +511,16 @@ get_regs_type (struct objfile *objfile)
 	   TYPE_CODE (regs_type), GCC_FE_WRAPPER_FUNCTION,
 	   objfile_name (objfile));
 
+  if (TYPE_NFIELDS (func_type) == 3)
+    {
+      take_address_type = check_typedef (TYPE_FIELD_TYPE (func_type, 2));
+      if (TYPE_CODE (take_address_type) != TYPE_CODE_INT)
+	error (_("Invalid type code %d of third parameter of function \"%s\" "
+		 "in compiled module \"%s\"."),
+	       TYPE_CODE (take_address_type), GCC_FE_WRAPPER_FUNCTION,
+	       objfile_name (objfile));
+    }
+
   return regs_type;
 }
 
@@ -464,12 +583,13 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base)
    function returns.  */
 
 struct compile_module *
-compile_object_load (const char *object_file, const char *source_file)
+compile_object_load (const char *object_file, const char *source_file,
+		     const int has_out_arg)
 {
   struct cleanup *cleanups, *cleanups_free_objfile;
   bfd *abfd;
   struct setup_sections_data setup_sections_data;
-  CORE_ADDR addr, func_addr, regs_addr;
+  CORE_ADDR addr, func_addr, regs_addr, out_value_addr = 0;
   struct bound_minimal_symbol bmsym;
   long storage_needed;
   asymbol **symbol_table, **symp;
@@ -477,7 +597,8 @@ compile_object_load (const char *object_file, const char *source_file)
   struct type *dptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
   unsigned dptr_type_len = TYPE_LENGTH (dptr_type);
   struct compile_module *retval;
-  struct type *regs_type;
+  struct type *regs_type, *out_value_type = NULL;
+  int out_value_take_address;
   char *filename, **matching;
   struct objfile *objfile;
 
@@ -579,6 +700,15 @@ compile_object_load (const char *object_file, const char *source_file)
       store_regs (regs_type, regs_addr);
     }
 
+  if (has_out_arg)
+    {
+      out_value_type = get_out_value_type (objfile, &out_value_take_address);
+      check_typedef (out_value_type);
+      out_value_addr = gdbarch_infcall_mmap (target_gdbarch (),
+					     TYPE_LENGTH (out_value_type), 6);
+      gdb_assert (out_value_addr != 0);
+    }
+
   discard_cleanups (cleanups_free_objfile);
   do_cleanups (cleanups);
 
@@ -587,5 +717,8 @@ compile_object_load (const char *object_file, const char *source_file)
   retval->source_file = xstrdup (source_file);
   retval->func_addr = func_addr;
   retval->regs_addr = regs_addr;
+  retval->out_value_addr = out_value_addr;
+  retval->out_value_type = out_value_type;
+  retval->out_value_take_address = out_value_take_address;
   return retval;
 }
diff --git a/gdb/compile/compile-object-load.h b/gdb/compile/compile-object-load.h
index ed3ac3a..be9cc65 100644
--- a/gdb/compile/compile-object-load.h
+++ b/gdb/compile/compile-object-load.h
@@ -32,11 +32,24 @@ struct compile_module
      require any.  */
   CORE_ADDR regs_addr;
 
+  /* Inferior parameter out value address or NULL if the inferior function does not
+     have one.  */
+  CORE_ADDR out_value_addr;
+
+  /* Should we memcpy address of the value or the value itself
+     (for coerced arrays)?  */
+  int out_value_take_address;
+
+  /* Inferior parameter out value type or NULL if the inferior function does not
+     have one.  */
+  struct type *out_value_type;
+
   /* User data for enum compile_i_scope_types in use.  */
   void *scope_data;
 };
 
 extern struct compile_module *compile_object_load (const char *object_file,
-						   const char *source_file);
+						   const char *source_file,
+						   const int has_out_arg);
 
 #endif /* GDB_COMPILE_OBJECT_LOAD_H */
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 0864712..d2b176c 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -24,6 +24,8 @@
 #include "objfiles.h"
 #include "compile-internal.h"
 #include "dummy-frame.h"
+#include "valprint.h"
+#include "compile.h"
 
 /* Helper for do_module_cleanup.  */
 
@@ -36,6 +38,10 @@ struct do_module_cleanup
   /* .c file OBJFILE was built from.  It needs to be xfree-d.  */
   char *source_file;
 
+  /* Copy from struct compile_module.  */
+  CORE_ADDR out_value_addr;
+  struct type *out_value_type;
+
   /* User data for enum compile_i_scope_types in use.  */
   void *scope_data;
 
@@ -54,7 +60,20 @@ do_module_cleanup (void *arg)
   struct objfile *objfile;
 
   if (data->executedp != NULL)
-    *data->executedp = 1;
+    {
+      *data->executedp = 1;
+
+      /* This code cannot be in compile_object_run as OUT_VALUE_TYPE
+	 no longer exists there.  */
+      if (data->out_value_addr != 0)
+	{
+	  struct value *addr_value;
+	  struct type *ptr_type = lookup_pointer_type (data->out_value_type);
+
+	  addr_value = value_from_pointer (ptr_type, data->out_value_addr);
+	  compile_print_value (value_ind (addr_value), data->scope_data);
+	}
+    }
 
   ALL_OBJFILES (objfile)
     if ((objfile->flags & OBJF_USERLOADED) == 0
@@ -91,36 +110,67 @@ compile_object_run (struct compile_module *module)
   struct cleanup *cleanups;
   struct do_module_cleanup *data;
   const char *objfile_name_s = objfile_name (module->objfile);
-  int dtor_found, executed = 0;
+  int dtor_found, executed = 0, args_count = 0;
   CORE_ADDR func_addr = module->func_addr;
   CORE_ADDR regs_addr = module->regs_addr;
+  CORE_ADDR out_value_addr = module->out_value_addr;
+  int out_value_take_address = module->out_value_take_address;
+  struct type *out_value_type = module->out_value_type;
 
   data = xmalloc (sizeof (*data) + strlen (objfile_name_s));
   data->executedp = &executed;
   data->source_file = xstrdup (module->source_file);
   strcpy (data->objfile_name_string, objfile_name_s);
+  data->out_value_addr = module->out_value_addr;
+  data->out_value_type = module->out_value_type;
   data->scope_data = module->scope_data;
 
   xfree (module->source_file);
   xfree (module);
 
+  if (regs_addr != 0)
+    args_count++;
+
+  if (out_value_addr != 0)
+    args_count += 2;
+
   TRY
     {
       func_val = value_from_pointer
 		 (builtin_type (target_gdbarch ())->builtin_func_ptr,
 		  func_addr);
 
-      if (regs_addr == 0)
+      if (args_count == 0)
 	call_function_by_hand_dummy (func_val, 0, NULL,
 				     do_module_cleanup, data);
       else
 	{
 	  struct value *arg_val;
+	  int current_arg = 0;
+	  struct value **vargs = NULL;
+
+	  vargs = alloca (sizeof (struct value *) * args_count);
 
-	  arg_val = value_from_pointer
+	  if (regs_addr != 0)
+	    {
+	      vargs[current_arg] = value_from_pointer
 		    (builtin_type (target_gdbarch ())->builtin_func_ptr,
 		     regs_addr);
-	  call_function_by_hand_dummy (func_val, 1, &arg_val,
+	      current_arg++;
+	    }
+	  if (out_value_addr != 0)
+	    {
+	      vargs[current_arg] = value_from_pointer
+		(builtin_type (target_gdbarch ())->builtin_func_ptr,
+		 out_value_addr);
+	      current_arg++;
+	      vargs[current_arg] = value_from_longest
+		(builtin_type (target_gdbarch ())->builtin_int,
+		 out_value_take_address);
+	      current_arg++;
+	    }
+
+	  call_function_by_hand_dummy (func_val, args_count, vargs,
 				       do_module_cleanup, data);
 	}
     }
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 7589f2a..8c01b54 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -38,6 +38,7 @@
 #include "target.h"
 #include "osabi.h"
 #include "gdb_wait.h"
+#include "valprint.h"
 
 \f
 
@@ -163,6 +164,49 @@ compile_code_command (char *arg, int from_tty)
   do_cleanups (cleanup);
 }
 
+/* Callback for compile_print_command.  */
+
+void
+compile_print_value (struct value *val, void *data_voidp)
+{
+  const struct format_data *fmtp = data_voidp;
+
+  print_value (val, fmtp);
+}
+
+/* Handle the input from the 'compile print' command.  The "compile
+   print" command is used to evaluate and print an expression that may
+   contain calls to the GCC compiler.  The language expected in this
+   compile command is the language currently set in GDB.  */
+
+static void
+compile_print_command (char *arg_param, int from_tty)
+{
+  const char *arg = arg_param;
+  struct cleanup *cleanup;
+  enum compile_i_scope_types scope = COMPILE_I_PRINT_SCOPE;
+  struct format_data *fmtp;
+
+  cleanup = make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
+  fmtp = print_command_parse_format (&arg, "compile print");
+
+  if (arg && *arg)
+    eval_compile_command (NULL, arg, scope, fmtp);
+  else
+    {
+      struct command_line *l = get_command_line (compile_control, "");
+
+      make_cleanup_free_command_lines (&l);
+      l->control_u.compile.scope = scope;
+      l->control_u.compile.scope_data = fmtp;
+      execute_control_command_untraced (l);
+    }
+
+  do_cleanups (cleanup);
+}
+
 /* A cleanup function to remove a directory and all its contents.  */
 
 static void
@@ -561,6 +605,10 @@ eval_compile_command (struct command_line *cmd, const char *cmd_string,
 		      enum compile_i_scope_types scope, void *scope_data)
 {
   char *object_file, *source_file;
+  int has_out_arg = 0;
+
+  if (scope == COMPILE_I_PRINT_SCOPE)
+    has_out_arg = 1;
 
   object_file = compile_to_object (cmd, cmd_string, scope, &source_file);
   if (object_file != NULL)
@@ -572,7 +620,7 @@ eval_compile_command (struct command_line *cmd, const char *cmd_string,
       make_cleanup (xfree, source_file);
       cleanup_unlink = make_cleanup (cleanup_unlink_file, object_file);
       make_cleanup (cleanup_unlink_file, source_file);
-      compile_module = compile_object_load (object_file, source_file);
+      compile_module = compile_object_load (object_file, source_file, has_out_arg);
       discard_cleanups (cleanup_unlink);
       do_cleanups (cleanup_xfree);
       compile_module->scope_data = scope_data;
@@ -652,6 +700,27 @@ Usage: compile file [-r|-raw] [filename]\n\
 	       &compile_command_list);
   set_cmd_completer (c, filename_completer);
 
+  add_cmd ("print", class_obscure, compile_print_command,
+	   _("\
+Evaluate a EXPR with the compiler and print result.\n\
+\n\
+Usage: compile print[/FMT] [EXPR]\n\
+\n\
+The expression may be specified in one line, e.g.:\n\
+\n\
+    compile print i\n\
+\n\
+Alternatively, you can type the expression interactively.\n\
+You can invoke this mode when no argument is given to the command\n\
+(i.e.,\"compile print\" is typed with nothing after it).  An\n\
+interactive prompt will be shown allowing you to enter multiple\n\
+lines of source code.  Type a line containing \"end\" to indicate\n\
+the end of the source code.\n\
+\n\
+EXPR may be preceded with /FMT, where FMT is a format letter\n\
+but no count or size letter (see \"x\" command)."),
+	   &compile_command_list);
+
   add_setshow_boolean_cmd ("compile", class_maintenance, &compile_debug, _("\
 Set compile command debugging."), _("\
 Show compile command debugging."), _("\
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index a973167..6e108c7 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -101,4 +101,6 @@ extern void compile_dwarf_bounds_to_c (struct ui_file *stream,
 				       const gdb_byte *op_end,
 				       struct dwarf2_per_cu_data *per_cu);
 
+extern void compile_print_value (struct value *val, void *data_voidp);
+
 #endif /* GDB_COMPILE_H */
diff --git a/gdb/defs.h b/gdb/defs.h
index 6476f80..849adf2 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -70,6 +70,11 @@ enum compile_i_scope_types
     /* Do not wrap the expression,
        it has to provide function "_gdb_expr" on its own.  */
     COMPILE_I_RAW_SCOPE,
+
+    /* A printable expression scope.  Wrap an expression into a scope
+       suitable for the "compile print" command.  It uses the generic
+       function name "_gdb_expr". */
+    COMPILE_I_PRINT_SCOPE,
   };
 
 /* Just in case they're not defined in stdio.h.  */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c03ecb0..b866117 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17182,6 +17182,25 @@ compile file /home/user/example.c
 @end smallexample
 @end table
 
+@table @code
+@item compile print @var{expr}
+@itemx compile print /@var{f} @var{expr}
+Compile @var{expr} with the compiler language found as the current
+language in @value{GDBN} (@pxref{Languages}).  By default the
+value of @var{expr} is printed in a format appropriate to its data type;
+you can choose a different format by specifying @samp{/@var{f}}, where
+@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
+Formats}.
+
+@item compile print
+@itemx compile print /@var{f}
+@cindex reprint the last value
+Alternatively you can enter the expression (source code producing it) as
+multiple lines of text.  To enter this mode, invoke the @samp{compile print}
+command without any text following the command.  This will start the
+multiple-line editor.
+@end table
+
 @subsection Caveats when using the @code{compile} command
 
 There are a few caveats to keep in mind when using the @code{compile}
diff --git a/gdb/testsuite/gdb.compile/compile-print.c b/gdb/testsuite/gdb.compile/compile-print.c
new file mode 100644
index 0000000..773871c
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-print.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+
+int varint = 10;
+int vararray[] = { 1, 2, 3, 4, 5 };
+int *vararrayp = vararray;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-print.exp b/gdb/testsuite/gdb.compile/compile-print.exp
new file mode 100644
index 0000000..0e7c8fe
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-print.exp
@@ -0,0 +1,56 @@
+# Copyright 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if { [prepare_for_testing ${testfile}.exp "$testfile"] } {
+    return -1
+}
+
+if ![runto_main] {
+    return -1
+}
+
+if {[skip_compile_feature_tests]} {
+    untested "compile command not supported (could not find libcc1 shared library?)"
+    return -1
+}
+
+gdb_test "compile print varint" " = 10"
+gdb_test "compile print vararray" " = \\{1, 2, 3, 4, 5\\}"
+gdb_test "compile print main" " = \\{int \\(void\\)\\} 0x\[0-9a-f\]+"
+
+set test "compile print *vararray@3"
+gdb_test_multiple $test $test {
+    -re " = \\{1, 2, 3\\}\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re ": error: stray '@' in program\r\n.*\r\n$gdb_prompt $" {
+	xfail "$test (gcc does not support '@')"
+    }
+}
+
+set test "compile print *vararrayp@3"
+gdb_test_multiple $test $test {
+    -re " = \\{1, 2, 3\\}\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re ": error: stray '@' in program\r\n.*\r\n$gdb_prompt $" {
+	xfail "$test (gcc does not support '@')"
+    }
+}
+
+gdb_test "compile print/x 256" " = 0x100"
+gdb_test {print $} " = 256"

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
@ 2015-03-26 20:59   ` Jan Kratochvil
  2015-03-27  7:18   ` Eli Zaretskii
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-26 20:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

On Thu, 26 Mar 2015 21:57:52 +0100, Jan Kratochvil wrote:
> gdb/ChangeLog
> 2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

I will fix up the primary patch author should be:
	Phil Muldoon <pmuldoon@redhat.com>


Jan

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
  2015-03-26 20:59   ` Jan Kratochvil
@ 2015-03-27  7:18   ` Eli Zaretskii
  2015-03-27  7:33     ` Jan Kratochvil
  2015-04-05 17:01   ` cancel: " Jan Kratochvil
  2015-04-06 17:29   ` obsolete: " Jan Kratochvil
  3 siblings, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27  7:18 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, pmuldoon

> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Phil Muldoon <pmuldoon@redhat.com>
> Date: Thu, 26 Mar 2015 21:57:52 +0100
> 
> It is planned the existing GDB command 'print' will be able to evaluate its
> expressions using the compiler.  There will be some option to choose between
> the existing GDB evaluation and the compiler evaluation.  But as an
> intermediate step this patch provides the expression printing feature as a new
> command.
> 
> I can imagine it could be also called 'maintenance compile print' as in the
> future one should be able to use its functionality by the normal 'print'
> command.

I suggest a different name for this command.  Unfortunately, "eval" is
already taken, but perhaps "parse" or "parse-eval"?  Or maybe a new
switch to "print"?  "compile print" sounds awkward and unintuitive to
me.

> +  add_cmd ("print", class_obscure, compile_print_command,
> +	   _("\
> +Evaluate a EXPR with the compiler and print result.\n\

Suggest to drop the "a" part, it just makes this sentence harder to
read.

> +The expression may be specified in one line, e.g.:\n\

"on the same line as the command" sounds more clear to me.

Otherwise, the documentation parts are OK.

Thanks.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  7:18   ` Eli Zaretskii
@ 2015-03-27  7:33     ` Jan Kratochvil
  2015-03-27  7:41       ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-27  7:33 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches, pmuldoon

On Fri, 27 Mar 2015 08:18:43 +0100, Eli Zaretskii wrote:
> I suggest a different name for this command.  Unfortunately, "eval" is
> already taken, but perhaps "parse" or "parse-eval"?  Or maybe a new
> switch to "print"?  "compile print" sounds awkward and unintuitive to
> me.

FYI there is already "compile code" and "compile file".


> > +  add_cmd ("print", class_obscure, compile_print_command,
> > +	   _("\
> > +Evaluate a EXPR with the compiler and print result.\n\
> 
> Suggest to drop the "a" part, it just makes this sentence harder to
> read.

OK, it will be changed upon check-in.


> > +The expression may be specified in one line, e.g.:\n\
> 
> "on the same line as the command" sounds more clear to me.

OK, it will be changed upon check-in.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  7:33     ` Jan Kratochvil
@ 2015-03-27  7:41       ` Eli Zaretskii
  2015-03-27  7:56         ` Phil Muldoon
  0 siblings, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27  7:41 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, pmuldoon

> Date: Fri, 27 Mar 2015 08:33:33 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: gdb-patches@sourceware.org, pmuldoon@redhat.com
> 
> On Fri, 27 Mar 2015 08:18:43 +0100, Eli Zaretskii wrote:
> > I suggest a different name for this command.  Unfortunately, "eval" is
> > already taken, but perhaps "parse" or "parse-eval"?  Or maybe a new
> > switch to "print"?  "compile print" sounds awkward and unintuitive to
> > me.
> 
> FYI there is already "compile code" and "compile file".

Yes, I know.  But this command is different AFAIU: it doesn't compile
any code at all.  So prefixing it with "compile" doesn't sound right
to me.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  7:41       ` Eli Zaretskii
@ 2015-03-27  7:56         ` Phil Muldoon
  2015-03-27  9:08           ` Eli Zaretskii
  2015-03-27  9:10           ` Eli Zaretskii
  0 siblings, 2 replies; 24+ messages in thread
From: Phil Muldoon @ 2015-03-27  7:56 UTC (permalink / raw)
  To: Eli Zaretskii, Jan Kratochvil; +Cc: gdb-patches

On 27/03/15 07:41, Eli Zaretskii wrote:
>> Date: Fri, 27 Mar 2015 08:33:33 +0100
>> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>> Cc: gdb-patches@sourceware.org, pmuldoon@redhat.com
>>
>> On Fri, 27 Mar 2015 08:18:43 +0100, Eli Zaretskii wrote:
>>> I suggest a different name for this command.  Unfortunately, "eval" is
>>> already taken, but perhaps "parse" or "parse-eval"?  Or maybe a new
>>> switch to "print"?  "compile print" sounds awkward and unintuitive to
>>> me.
>> FYI there is already "compile code" and "compile file".
> Yes, I know.  But this command is different AFAIU: it doesn't compile
> any code at all.  So prefixing it with "compile" doesn't sound right
> to me.
It does. It repackages the expression typed by the user into compilable form (with a scope, various bits of stack mapping, address translation, etc), send it to the compiler plugin that compiles it. GDB then runs the code in the inferior and captures the evaluated output and type and prints it.

Cheers

Phil

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  7:56         ` Phil Muldoon
@ 2015-03-27  9:08           ` Eli Zaretskii
  2015-03-27  9:10           ` Eli Zaretskii
  1 sibling, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27  9:08 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: jan.kratochvil, gdb-patches

> Date: Fri, 27 Mar 2015 07:56:08 +0000
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: gdb-patches@sourceware.org
> 
> On 27/03/15 07:41, Eli Zaretskii wrote:
> >> Date: Fri, 27 Mar 2015 08:33:33 +0100
> >> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> >> Cc: gdb-patches@sourceware.org, pmuldoon@redhat.com
> >>
> >> On Fri, 27 Mar 2015 08:18:43 +0100, Eli Zaretskii wrote:
> >>> I suggest a different name for this command.  Unfortunately, "eval" is
> >>> already taken, but perhaps "parse" or "parse-eval"?  Or maybe a new
> >>> switch to "print"?  "compile print" sounds awkward and unintuitive to
> >>> me.
> >> FYI there is already "compile code" and "compile file".
> > Yes, I know.  But this command is different AFAIU: it doesn't compile
> > any code at all.  So prefixing it with "compile" doesn't sound right
> > to me.
> It does. It repackages the expression typed by the user into compilable form (with a scope, various bits of stack mapping, address translation, etc), send it to the compiler plugin that compiles it. GDB then runs the code in the inferior and captures the evaluated output and type and prints it.

You are talking about implementation, while I'm talking about the
user's perspective.  From the user's POV, no code was compiled and
run.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  7:56         ` Phil Muldoon
  2015-03-27  9:08           ` Eli Zaretskii
@ 2015-03-27  9:10           ` Eli Zaretskii
  2015-03-27  9:16             ` Jan Kratochvil
  1 sibling, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27  9:10 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: jan.kratochvil, gdb-patches

> Date: Fri, 27 Mar 2015 07:56:08 +0000
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: gdb-patches@sourceware.org
> 
> It repackages the expression typed by the user into compilable form (with a scope, various bits of stack mapping, address translation, etc), send it to the compiler plugin that compiles it. GDB then runs the code in the inferior and captures the evaluated output and type and prints it.

Btw, what does this fact mean for what can and cannot be in the
expression?  Can it include calls to standard functions?  Can it
call functions from libraries other than libc?  What about functions
defined by the inferior?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  9:10           ` Eli Zaretskii
@ 2015-03-27  9:16             ` Jan Kratochvil
  2015-03-27  9:56               ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-27  9:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Phil Muldoon, gdb-patches

On Fri, 27 Mar 2015 10:10:40 +0100, Eli Zaretskii wrote:
> Btw, what does this fact mean for what can and cannot be in the
> expression?

Anything that can be in the inferior code.  GDB extensions are not yet
implemented, except for '@' (which is not a part of this patchset).


> Can it include calls to standard functions?  Can it call functions from
> libraries other than libc?  What about functions defined by the inferior?

yes, yes (as long as the library is already DT_NEEDEDed or dlopen()ed by the
inferior), yes.


Jan

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  9:16             ` Jan Kratochvil
@ 2015-03-27  9:56               ` Eli Zaretskii
  2015-03-27 10:11                 ` Jan Kratochvil
                                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27  9:56 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: pmuldoon, gdb-patches

> Date: Fri, 27 Mar 2015 10:16:17 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Phil Muldoon <pmuldoon@redhat.com>, gdb-patches@sourceware.org
> 
> > Can it include calls to standard functions?  Can it call functions from
> > libraries other than libc?  What about functions defined by the inferior?
> 
> yes, yes (as long as the library is already DT_NEEDEDed or dlopen()ed by the
> inferior), yes.

Are you sure the last part (calling functions in the inferior) will
work on all platforms?  How does the GCC plugin know to resolve the
address of the inferior's functions correctly?  Won't it need some
kind of import library on Windows?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  9:56               ` Eli Zaretskii
@ 2015-03-27 10:11                 ` Jan Kratochvil
  2015-03-27 10:20                 ` Phil Muldoon
  2015-03-27 10:24                 ` Jan Kratochvil
  2 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-27 10:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: pmuldoon, gdb-patches

On Fri, 27 Mar 2015 10:56:18 +0100, Eli Zaretskii wrote:
> Are you sure the last part (calling functions in the inferior) will
> work

Yes, as 'compile print' is almost the same as 'compile code' and for 'compile
code' it is already a part of the gdb.compile/ GDB testsuite.


> on all platforms?  Won't it need some kind of import library on Windows?

I really have no idea(+interest+duties).  Have you tried it?


> How does the GCC plugin know to resolve the address of the inferior's
> functions correctly?  

compile_object_load() contains relocator for mst_text references.
Additionally convert_one_symbol()/convert_symbol_bmsym()/etc. provide symbol
addresses during compilation of the module.  Some symbol types are resolved
that way, other symbols types the other way, it is partially interchangeable.


Jan

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  9:56               ` Eli Zaretskii
  2015-03-27 10:11                 ` Jan Kratochvil
@ 2015-03-27 10:20                 ` Phil Muldoon
  2015-03-27 13:09                   ` Eli Zaretskii
  2015-03-27 10:24                 ` Jan Kratochvil
  2 siblings, 1 reply; 24+ messages in thread
From: Phil Muldoon @ 2015-03-27 10:20 UTC (permalink / raw)
  To: Eli Zaretskii, Jan Kratochvil; +Cc: gdb-patches

On 27/03/15 09:56, Eli Zaretskii wrote:
>> Date: Fri, 27 Mar 2015 10:16:17 +0100
>> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>> Cc: Phil Muldoon <pmuldoon@redhat.com>, gdb-patches@sourceware.org
>>
>>> Can it include calls to standard functions?  Can it call functions from
>>> libraries other than libc?  What about functions defined by the inferior?
>>
q>> yes, yes (as long as the library is already DT_NEEDEDed or dlopen()ed by the
>> inferior), yes.
>
> Are you sure the last part (calling functions in the inferior) will
> work on all platforms?  How does the GCC plugin know to resolve the
> address of the inferior's functions correctly?  Won't it need some
> kind of import library on Windows?

Via the address translation oracle. This is no different from the
compile code/file mechanism that was reviewed and committed some
months ago. Does it work on all platforms? I can't answer that as I do
not have access to all platforms. Few people, I suspect, do. But this
is pretty much true of every patch submitted in GDB. But if it doesn't
work then the error handling mechanisms of GDB and GCC plugin should
handle it. Just like any other platform dependent bugs. As always if
people on those platforms file bugs, we will always gladly help fix
them.

On the issue of compile print and preconceived notions by users
regarding the utility of the function, then it is a documentation
issue. Your assertion of what the user "might think" can easily be
remedied by documentation fixes to the help command and/or the
manual. This will help correct any previous notions, and guide them to
what they should think of the command.

Other than the edits you have suggested (thank you for those!) do you
have any additional documentation edits that might help to address the
preconceived notions the user might have?

Cheers

Phil

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27  9:56               ` Eli Zaretskii
  2015-03-27 10:11                 ` Jan Kratochvil
  2015-03-27 10:20                 ` Phil Muldoon
@ 2015-03-27 10:24                 ` Jan Kratochvil
  2015-03-27 13:12                   ` Eli Zaretskii
  2 siblings, 1 reply; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-27 10:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: pmuldoon, gdb-patches

On Fri, 27 Mar 2015 10:56:18 +0100, Eli Zaretskii wrote:
> How does the GCC plugin know to resolve the address of the inferior's
> functions correctly?

In fact it should be also described here:
	https://sourceware.org/gdb/wiki/GCCCompileAndExecute


Jan

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27 10:20                 ` Phil Muldoon
@ 2015-03-27 13:09                   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27 13:09 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: jan.kratochvil, gdb-patches

> Date: Fri, 27 Mar 2015 10:20:29 +0000
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: gdb-patches@sourceware.org
> 
> Other than the edits you have suggested (thank you for those!) do you
> have any additional documentation edits that might help to address the
> preconceived notions the user might have?

No.  I don't think it's an issue that documentation can solve.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] compile: New 'compile print'
  2015-03-27 10:24                 ` Jan Kratochvil
@ 2015-03-27 13:12                   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2015-03-27 13:12 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: pmuldoon, gdb-patches

> Date: Fri, 27 Mar 2015 11:23:54 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: pmuldoon@redhat.com, gdb-patches@sourceware.org
> 
> On Fri, 27 Mar 2015 10:56:18 +0100, Eli Zaretskii wrote:
> > How does the GCC plugin know to resolve the address of the inferior's
> > functions correctly?
> 
> In fact it should be also described here:
> 	https://sourceware.org/gdb/wiki/GCCCompileAndExecute

Thanks.  It's above my head, but that's nothing you should worry
about.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/4] v2: Code cleanup: Make parts of print_command_1 public
  2015-03-26 20:57 [PATCH 1/4] Code cleanup: Make parts of print_command_1 public Jan Kratochvil
                   ` (2 preceding siblings ...)
  2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
@ 2015-03-27 20:06 ` Jan Kratochvil
  2015-04-06 17:27   ` obsolete: " Jan Kratochvil
  3 siblings, 1 reply; 24+ messages in thread
From: Jan Kratochvil @ 2015-03-27 20:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

Hi,

updated for:
	Revert: [obv] Code cleanup: Move print_command_1 expr variable scope
	https://sourceware.org/ml/gdb-patches/2015-03/msg00922.html


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-03-27  Jan Kratochvil  <jan.kratochvil@redhat.com>

        * printcmd.c (print_command_parse_format, print_value): New functions
       	from ...
        (print_command_1): ... here.  Call them.
        * valprint.h (struct format_data, print_command_parse_format)
        (print_value): New declarations.

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index deb501a..d89e6df 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -939,6 +939,56 @@ validate_format (struct format_data fmt, const char *cmdname)
 	   fmt.format, cmdname);
 }
 
+/* Parse print command format string and update *EXPP, return it allocated,
+   caller has to call xfree for it.  Return NULL if no format string has been
+   found.  CMDNAME should name the current command.  */
+
+struct format_data *
+print_command_parse_format (const char **expp, const char *cmdname)
+{
+  struct format_data *fmtp;
+  const char *exp = *expp;
+  struct cleanup *cleanup;
+
+  if (exp == NULL || *exp != '/')
+    return NULL;
+  exp++;
+
+  fmtp = xmalloc (sizeof (*fmtp));
+  cleanup = make_cleanup (xfree, fmtp);
+  *fmtp = decode_format (&exp, last_format, 0);
+  validate_format (*fmtp, cmdname);
+  last_format = fmtp->format;
+
+  discard_cleanups (cleanup);
+  *expp = exp;
+  return fmtp;
+}
+
+
+/* Print VAL to console, 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 == NULL ? 0 : fmtp->format));
+  opts.raw = (fmtp == NULL ? 0 : fmtp->raw);
+
+  print_formatted (val, (fmtp == NULL ? 0 : 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).  */
@@ -947,25 +997,9 @@ static void
 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;
-    }
+  struct format_data *fmtp = print_command_parse_format (&exp, "print");
+  struct cleanup *old_chain = make_cleanup (xfree, fmtp);
 
   if (exp && *exp)
     {
@@ -978,24 +1012,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, fmtp);
 
   do_cleanups (old_chain);
 }
diff --git a/gdb/valprint.h b/gdb/valprint.h
index e3d0137..3ab531f 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -217,4 +217,9 @@ extern void output_command_const (const char *args, int from_tty);
 
 extern int val_print_scalar_type_p (struct type *type);
 
+struct format_data;
+extern struct format_data *print_command_parse_format (const char **expp,
+						       const char *cmdname);
+extern void print_value (struct value *val, const struct format_data *fmtp);
+
 #endif

^ permalink raw reply	[flat|nested] 24+ messages in thread

* cancel: [PATCH 4/4] compile: New 'compile print'
  2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
  2015-03-26 20:59   ` Jan Kratochvil
  2015-03-27  7:18   ` Eli Zaretskii
@ 2015-04-05 17:01   ` Jan Kratochvil
  2015-04-06 17:29   ` obsolete: " Jan Kratochvil
  3 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-04-05 17:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

On Thu, 26 Mar 2015 21:57:52 +0100, Jan Kratochvil wrote:
> +      fprintf_unfiltered (buf,
> +"__auto_type " COMPILE_I_EXPR_VAL " = %s;\n"
> +"typeof (%s) *" COMPILE_I_EXPR_PTR_TYPE ";\n"
> +"if (" COMPILE_I_PRINT_EXPR_TAKE_ADDRESS ")\n"
> +"\tmemcpy (" COMPILE_I_PRINT_OUT_ARG ", &" COMPILE_I_EXPR_VAL ",\n"
> +	   "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n"
> +"else\n"
> +"\tmemcpy (" COMPILE_I_PRINT_OUT_ARG ", "  COMPILE_I_EXPR_VAL ",\n"
> +	   "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n"
> +			  , input, input);

This cannot work, when trying to print struct variable GCC fails for the
second memcpy() with:
	gdb command line:7:2: error: cannot convert to a pointer type^M
It will need to perform two compilation steps (or just one if the first one is
the right kind).


Jan

^ permalink raw reply	[flat|nested] 24+ messages in thread

* obsolete: [PATCH 1/4] v2: Code cleanup: Make parts of print_command_1 public
  2015-03-27 20:06 ` [PATCH 1/4] v2: Code cleanup: Make parts of print_command_1 public Jan Kratochvil
@ 2015-04-06 17:27   ` Jan Kratochvil
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-04-06 17:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

obsoleted:
[PATCH v2 1/9] Code cleanup: Make parts of print_command_1 public
https://sourceware.org/ml/gdb-patches/2015-04/msg00156.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* obsolete: [PATCH 3/4] compile: Constify some parameters
  2015-03-26 20:57 ` [PATCH 3/4] compile: Constify some parameters Jan Kratochvil
@ 2015-04-06 17:28   ` Jan Kratochvil
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-04-06 17:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

obsoleted by:
[PATCH v2 3/9] Code cleanup: compile: Constify some parameters
https://sourceware.org/ml/gdb-patches/2015-04/msg00158.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* obsolete: [PATCH 2/4] compile: Add new field scope_data
  2015-03-26 20:57 ` [PATCH 2/4] compile: Add new field scope_data Jan Kratochvil
@ 2015-04-06 17:28   ` Jan Kratochvil
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-04-06 17:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

obsoleted:
[PATCH v2 2/9] compile: Distribute scope, add scope_data
https://sourceware.org/ml/gdb-patches/2015-04/msg00157.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* obsolete: [PATCH 4/4] compile: New 'compile print'
  2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
                     ` (2 preceding siblings ...)
  2015-04-05 17:01   ` cancel: " Jan Kratochvil
@ 2015-04-06 17:29   ` Jan Kratochvil
  3 siblings, 0 replies; 24+ messages in thread
From: Jan Kratochvil @ 2015-04-06 17:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Phil Muldoon

obsoleted by:
[PATCH v2 7/9] compile: New 'compile print'
https://sourceware.org/ml/gdb-patches/2015-04/msg00162.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-04-06 17:29 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 20:57 [PATCH 1/4] Code cleanup: Make parts of print_command_1 public Jan Kratochvil
2015-03-26 20:57 ` [PATCH 3/4] compile: Constify some parameters Jan Kratochvil
2015-04-06 17:28   ` obsolete: " Jan Kratochvil
2015-03-26 20:57 ` [PATCH 2/4] compile: Add new field scope_data Jan Kratochvil
2015-04-06 17:28   ` obsolete: " Jan Kratochvil
2015-03-26 20:58 ` [PATCH 4/4] compile: New 'compile print' Jan Kratochvil
2015-03-26 20:59   ` Jan Kratochvil
2015-03-27  7:18   ` Eli Zaretskii
2015-03-27  7:33     ` Jan Kratochvil
2015-03-27  7:41       ` Eli Zaretskii
2015-03-27  7:56         ` Phil Muldoon
2015-03-27  9:08           ` Eli Zaretskii
2015-03-27  9:10           ` Eli Zaretskii
2015-03-27  9:16             ` Jan Kratochvil
2015-03-27  9:56               ` Eli Zaretskii
2015-03-27 10:11                 ` Jan Kratochvil
2015-03-27 10:20                 ` Phil Muldoon
2015-03-27 13:09                   ` Eli Zaretskii
2015-03-27 10:24                 ` Jan Kratochvil
2015-03-27 13:12                   ` Eli Zaretskii
2015-04-05 17:01   ` cancel: " Jan Kratochvil
2015-04-06 17:29   ` obsolete: " Jan Kratochvil
2015-03-27 20:06 ` [PATCH 1/4] v2: Code cleanup: Make parts of print_command_1 public Jan Kratochvil
2015-04-06 17:27   ` obsolete: " Jan Kratochvil

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).