+
+/* Print the result of a function at the end of a 'finish' command. */
+static void
+print_return_value (int structure_return, struct type *value_type)
+{
+ register value_ptr value;
+#ifdef UI_OUT
+ static struct ui_stream *stb = NULL;
+#endif /* UI_OUT */
+
+ if (!structure_return)
+ {
+ value = value_being_returned (value_type, stop_registers, structure_return);
+#ifdef UI_OUT
+ stb = ui_out_stream_new (uiout);
+ ui_out_text (uiout, "Value returned is ");
+ ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value));
+ ui_out_text (uiout, "= ");
+ value_print (value, stb->stream, 0, Val_no_prettyprint);
+ ui_out_field_stream (uiout, "return-value", stb);
+ ui_out_text (uiout, "\n");
+#else /* UI_OUT */
+ printf_filtered ("Value returned is $%d = ", record_latest_value (value));
+ value_print (value, gdb_stdout, 0, Val_no_prettyprint);
+ printf_filtered ("\n");
+#endif /* UI_OUT */
+ }
+ else
+ {
+ /* We cannot determine the contents of the structure because
+ it is on the stack, and we don't know where, since we did not
+ initiate the call, as opposed to the call_function_by_hand case */
+#ifdef VALUE_RETURNED_FROM_STACK
+ value = 0;
+#ifdef UI_OUT
+ ui_out_text (uiout, "Value returned has type: ");
+ ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
+ ui_out_text (uiout, ".");
+ ui_out_text (uiout, " Cannot determine contents\n");
+#else /* UI_OUT */
+ printf_filtered ("Value returned has type: %s.", TYPE_NAME (value_type));
+ printf_filtered (" Cannot determine contents\n");
+#endif /* UI_OUT */
+#else
+ value = value_being_returned (value_type, stop_registers, structure_return);
+#ifdef UI_OUT
+ stb = ui_out_stream_new (uiout);
+ ui_out_text (uiout, "Value returned is ");
+ ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value));
+ ui_out_text (uiout, "= ");
+ value_print (value, stb->stream, 0, Val_no_prettyprint);
+ ui_out_field_stream (uiout, "return-value", stb);
+ ui_out_text (uiout, "\n");
+#else
+ printf_filtered ("Value returned is $%d = ", record_latest_value (value));
+ value_print (value, gdb_stdout, 0, Val_no_prettyprint);
+ printf_filtered ("\n");
+#endif
+#endif
+ }
+}
+
+/* Stuff that needs to be done by the finish command after the target
+ has stopped. In asynchronous mode, we wait for the target to stop in
+ the call to poll or select in the event loop, so it is impossible to
+ do all the stuff as part of the finish_command function itself. The
+ only chance we have to complete this command is in
+ fetch_inferior_event, which is called by the event loop as soon as it
+ detects that the target has stopped. This function is called via the
+ cmd_continaution pointer. */
+void
+finish_command_continuation (arg)
+ struct continuation_arg *arg;
+{
+ register struct symbol *function;
+ struct breakpoint *breakpoint;
+ struct cleanup *cleanups;
+
+ breakpoint = (struct breakpoint *) arg->data.pointer;
+ function = (struct symbol *) arg->next->data.pointer;
+ cleanups = (struct cleanup *) arg->next->next->data.pointer;
+
+ if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
+ && function != 0)
+ {
+ struct type *value_type;
+ CORE_ADDR funcaddr;
+ int struct_return;
+
+ value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
+ if (!value_type)
+ internal_error ("finish_command: function has no target type");
+
+ if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
+ {
+ do_exec_cleanups (cleanups);
+ return;
+ }
+
+ funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
+
+ struct_return = using_struct_return (value_of_variable (function, NULL),
+ funcaddr,
+ check_typedef (value_type),
+ BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)));
+
+ print_return_value (struct_return, value_type);
+ }
+ do_exec_cleanups (cleanups);
+}
+