3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions (a Red Hat company).
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* Work in progress. */
26 #include "arch-utils.h"
29 #include "gdb_string.h"
30 #include "exceptions.h"
32 #include "gdbthread.h"
35 #include "mi-getopt.h"
36 #include "mi-console.h"
40 #include "event-loop.h"
41 #include "event-top.h"
42 #include "gdbcore.h" /* For write_memory(). */
48 #include "mi-common.h"
53 #include "splay-tree.h"
58 #if defined HAVE_SYS_RESOURCE_H
59 #include <sys/resource.h>
72 struct ui_file *raw_stdout;
74 /* This is used to pass the current command timestamp
75 down to continuation routines. */
76 static struct mi_timestamp *current_command_ts;
78 static int do_timings = 0;
81 int running_result_record_printed = 1;
83 /* Flag indicating that the target has proceeded since the last
84 command was issued. */
87 extern void _initialize_mi_main (void);
88 static void mi_cmd_execute (struct mi_parse *parse);
90 static void mi_execute_cli_command (const char *cmd, int args_p,
92 static void mi_execute_async_cli_command (char *cli_command,
93 char **argv, int argc);
94 static int register_changed_p (int regnum, struct regcache *,
96 static void get_register (struct frame_info *, int regnum, int format);
98 /* Command implementations. FIXME: Is this libgdb? No. This is the MI
99 layer that calls libgdb. Any operation used in the below should be
102 static void timestamp (struct mi_timestamp *tv);
104 static void print_diff_now (struct mi_timestamp *start);
105 static void print_diff (struct mi_timestamp *start, struct mi_timestamp *end);
108 mi_cmd_gdb_exit (char *command, char **argv, int argc)
110 /* We have to print everything right here because we never return. */
112 fputs_unfiltered (current_token, raw_stdout);
113 fputs_unfiltered ("^exit\n", raw_stdout);
114 mi_out_put (uiout, raw_stdout);
115 gdb_flush (raw_stdout);
116 /* FIXME: The function called is not yet a formal libgdb function. */
117 quit_force (NULL, FROM_TTY);
121 mi_cmd_exec_next (char *command, char **argv, int argc)
123 /* FIXME: Should call a libgdb function, not a cli wrapper. */
124 mi_execute_async_cli_command ("next", argv, argc);
128 mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
130 /* FIXME: Should call a libgdb function, not a cli wrapper. */
131 mi_execute_async_cli_command ("nexti", argv, argc);
135 mi_cmd_exec_step (char *command, char **argv, int argc)
137 /* FIXME: Should call a libgdb function, not a cli wrapper. */
138 mi_execute_async_cli_command ("step", argv, argc);
142 mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
144 /* FIXME: Should call a libgdb function, not a cli wrapper. */
145 mi_execute_async_cli_command ("stepi", argv, argc);
149 mi_cmd_exec_finish (char *command, char **argv, int argc)
151 /* FIXME: Should call a libgdb function, not a cli wrapper. */
152 mi_execute_async_cli_command ("finish", argv, argc);
156 mi_cmd_exec_return (char *command, char **argv, int argc)
158 /* This command doesn't really execute the target, it just pops the
159 specified number of frames. */
161 /* Call return_command with from_tty argument equal to 0 so as to
162 avoid being queried. */
163 return_command (*argv, 0);
165 /* Call return_command with from_tty argument equal to 0 so as to
166 avoid being queried. */
167 return_command (NULL, 0);
169 /* Because we have called return_command with from_tty = 0, we need
170 to print the frame here. */
171 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS);
175 mi_cmd_exec_jump (char *args, char **argv, int argc)
177 /* FIXME: Should call a libgdb function, not a cli wrapper. */
178 return mi_execute_async_cli_command ("jump", argv, argc);
182 proceed_thread_callback (struct thread_info *thread, void *arg)
184 int pid = *(int *)arg;
186 if (!is_stopped (thread->ptid))
189 if (PIDGET (thread->ptid) != pid)
192 switch_to_thread (thread->ptid);
193 clear_proceed_status ();
194 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
199 mi_cmd_exec_continue (char *command, char **argv, int argc)
203 else if (argc == 1 && strcmp (argv[0], "--all") == 0)
205 else if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
207 struct cleanup *old_chain;
209 if (argv[1] == NULL || argv[1] == '\0')
210 error ("Thread group id not specified");
211 pid = atoi (argv[1]);
212 if (!in_inferior_list (pid))
213 error ("Invalid thread group id '%s'", argv[1]);
215 old_chain = make_cleanup_restore_current_thread ();
216 iterate_over_threads (proceed_thread_callback, &pid);
217 do_cleanups (old_chain);
220 error ("Usage: -exec-continue [--all|--thread-group id]");
224 interrupt_thread_callback (struct thread_info *thread, void *arg)
226 int pid = *(int *)arg;
228 if (!is_running (thread->ptid))
231 if (PIDGET (thread->ptid) != pid)
234 target_stop (thread->ptid);
238 /* Interrupt the execution of the target. Note how we must play around
239 with the token variables, in order to display the current token in
240 the result of the interrupt command, and the previous execution
241 token when the target finally stops. See comments in
244 mi_cmd_exec_interrupt (char *command, char **argv, int argc)
248 if (!is_running (inferior_ptid))
249 error ("Current thread is not running.");
251 interrupt_target_1 (0);
253 else if (argc == 1 && strcmp (argv[0], "--all") == 0)
256 error ("Inferior not running.");
258 interrupt_target_1 (1);
260 else if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
262 struct cleanup *old_chain;
264 if (argv[1] == NULL || argv[1] == '\0')
265 error ("Thread group id not specified");
266 pid = atoi (argv[1]);
267 if (!in_inferior_list (pid))
268 error ("Invalid thread group id '%s'", argv[1]);
270 old_chain = make_cleanup_restore_current_thread ();
271 iterate_over_threads (interrupt_thread_callback, &pid);
272 do_cleanups (old_chain);
275 error ("Usage: -exec-interrupt [--all|--thread-group id]");
279 find_thread_of_process (struct thread_info *ti, void *p)
282 if (PIDGET (ti->ptid) == pid && !is_exited (ti->ptid))
289 mi_cmd_target_detach (char *command, char **argv, int argc)
291 if (argc != 0 && argc != 1)
292 error ("Usage: -target-detach [thread-group]");
296 struct thread_info *tp;
298 int pid = strtol (argv[0], &end, 10);
300 error (_("Cannot parse thread group id '%s'"), argv[0]);
302 /* Pick any thread in the desired process. Current
303 target_detach deteches from the parent of inferior_ptid. */
304 tp = iterate_over_threads (find_thread_of_process, &pid);
306 error (_("Thread group is empty"));
308 switch_to_thread (tp->ptid);
311 detach_command (NULL, 0);
315 mi_cmd_thread_select (char *command, char **argv, int argc)
318 char *mi_error_message;
321 error ("mi_cmd_thread_select: USAGE: threadnum.");
323 rc = gdb_thread_select (uiout, argv[0], &mi_error_message);
325 if (rc == GDB_RC_FAIL)
327 make_cleanup (xfree, mi_error_message);
328 error ("%s", mi_error_message);
333 mi_cmd_thread_list_ids (char *command, char **argv, int argc)
336 char *mi_error_message;
339 error ("mi_cmd_thread_list_ids: No arguments required.");
341 rc = gdb_list_thread_ids (uiout, &mi_error_message);
343 if (rc == GDB_RC_FAIL)
345 make_cleanup (xfree, mi_error_message);
346 error ("%s", mi_error_message);
351 mi_cmd_thread_info (char *command, char **argv, int argc)
355 if (argc != 0 && argc != 1)
356 error ("Invalid MI command");
359 thread = atoi (argv[0]);
361 print_thread_info (uiout, thread, -1);
364 struct collect_cores_data
372 collect_cores (struct thread_info *ti, void *xdata)
374 struct collect_cores_data *data = xdata;
376 if (ptid_get_pid (ti->ptid) == data->pid)
378 int core = target_core_of_thread (ti->ptid);
380 VEC_safe_push (int, data->cores, core);
387 unique (int *b, int *e)
396 struct print_one_inferior_data
399 VEC (int) *inferiors;
403 print_one_inferior (struct inferior *inferior, void *xdata)
405 struct print_one_inferior_data *top_data = xdata;
407 if (VEC_empty (int, top_data->inferiors)
408 || bsearch (&(inferior->pid), VEC_address (int, top_data->inferiors),
409 VEC_length (int, top_data->inferiors), sizeof (int),
410 compare_positive_ints))
412 struct collect_cores_data data;
413 struct cleanup *back_to
414 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
416 ui_out_field_fmt (uiout, "id", "%d", inferior->pid);
417 ui_out_field_string (uiout, "type", "process");
418 ui_out_field_int (uiout, "pid", inferior->pid);
420 data.pid = inferior->pid;
422 iterate_over_threads (collect_cores, &data);
424 if (!VEC_empty (int, data.cores))
429 struct cleanup *back_to_2 =
430 make_cleanup_ui_out_list_begin_end (uiout, "cores");
432 qsort (VEC_address (int, data.cores),
433 VEC_length (int, data.cores), sizeof (int),
434 compare_positive_ints);
436 b = VEC_address (int, data.cores);
437 e = b + VEC_length (int, data.cores);
441 ui_out_field_int (uiout, NULL, *b);
443 do_cleanups (back_to_2);
446 if (top_data->recurse)
447 print_thread_info (uiout, -1, inferior->pid);
449 do_cleanups (back_to);
455 /* Output a field named 'cores' with a list as the value. The elements of
456 the list are obtained by splitting 'cores' on comma. */
459 output_cores (struct ui_out *uiout, const char *field_name, const char *xcores)
461 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
463 char *cores = xstrdup (xcores);
466 make_cleanup (xfree, cores);
468 for (p = strtok (p, ","); p; p = strtok (NULL, ","))
469 ui_out_field_string (uiout, NULL, p);
471 do_cleanups (back_to);
475 free_vector_of_ints (void *xvector)
477 VEC (int) **vector = xvector;
478 VEC_free (int, *vector);
482 do_nothing (splay_tree_key k)
487 free_vector_of_osdata_items (splay_tree_value xvalue)
489 VEC (osdata_item_s) *value = (VEC (osdata_item_s) *) xvalue;
490 /* We don't free the items itself, it will be done separately. */
491 VEC_free (osdata_item_s, value);
495 splay_tree_int_comparator (splay_tree_key xa, splay_tree_key xb)
503 free_splay_tree (void *xt)
506 splay_tree_delete (t);
510 list_available_thread_groups (VEC (int) *ids, int recurse)
513 struct osdata_item *item;
515 /* This keeps a map from integer (pid) to VEC (struct osdata_item *)*
516 The vector contains information about all threads for the given pid.
517 This is assigned an initial value to avoid "may be used uninitialized"
519 splay_tree tree = NULL;
521 /* get_osdata will throw if it cannot return data. */
522 data = get_osdata ("processes");
523 make_cleanup_osdata_free (data);
527 struct osdata *threads = get_osdata ("threads");
528 make_cleanup_osdata_free (threads);
530 tree = splay_tree_new (splay_tree_int_comparator,
532 free_vector_of_osdata_items);
533 make_cleanup (free_splay_tree, tree);
536 VEC_iterate (osdata_item_s, threads->items,
540 const char *pid = get_osdata_column (item, "pid");
541 int pid_i = strtoul (pid, NULL, 0);
542 VEC (osdata_item_s) *vec = 0;
544 splay_tree_node n = splay_tree_lookup (tree, pid_i);
547 VEC_safe_push (osdata_item_s, vec, item);
548 splay_tree_insert (tree, pid_i, (splay_tree_value)vec);
552 vec = (VEC (osdata_item_s) *) n->value;
553 VEC_safe_push (osdata_item_s, vec, item);
554 n->value = (splay_tree_value) vec;
559 make_cleanup_ui_out_list_begin_end (uiout, "groups");
562 VEC_iterate (osdata_item_s, data->items,
566 struct cleanup *back_to;
568 const char *pid = get_osdata_column (item, "pid");
569 const char *cmd = get_osdata_column (item, "command");
570 const char *user = get_osdata_column (item, "user");
571 const char *cores = get_osdata_column (item, "cores");
573 int pid_i = strtoul (pid, NULL, 0);
575 /* At present, the target will return all available processes
576 and if information about specific ones was required, we filter
577 undesired processes here. */
578 if (ids && bsearch (&pid_i, VEC_address (int, ids),
579 VEC_length (int, ids),
580 sizeof (int), compare_positive_ints) == NULL)
584 back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
586 ui_out_field_fmt (uiout, "id", "%s", pid);
587 ui_out_field_string (uiout, "type", "process");
589 ui_out_field_string (uiout, "description", cmd);
591 ui_out_field_string (uiout, "user", user);
593 output_cores (uiout, "cores", cores);
597 splay_tree_node n = splay_tree_lookup (tree, pid_i);
600 VEC (osdata_item_s) *children = (VEC (osdata_item_s) *) n->value;
601 struct osdata_item *child;
604 make_cleanup_ui_out_list_begin_end (uiout, "threads");
607 VEC_iterate (osdata_item_s, children, ix_child, child);
610 struct cleanup *back_to_2 =
611 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
613 const char *tid = get_osdata_column (child, "tid");
614 const char *tcore = get_osdata_column (child, "core");
615 ui_out_field_string (uiout, "id", tid);
617 ui_out_field_string (uiout, "core", tcore);
619 do_cleanups (back_to_2);
624 do_cleanups (back_to);
629 mi_cmd_list_thread_groups (char *command, char **argv, int argc)
631 struct cleanup *back_to;
638 AVAILABLE_OPT, RECURSE_OPT
640 static struct mi_opt opts[] =
642 {"-available", AVAILABLE_OPT, 0},
643 {"-recurse", RECURSE_OPT, 1},
652 int opt = mi_getopt ("-list-thread-groups", argc, argv, opts,
656 switch ((enum opt) opt)
662 if (strcmp (optarg, "0") == 0)
664 else if (strcmp (optarg, "1") == 0)
667 error ("only '0' and '1' are valid values for the '--recurse' option");
672 for (; optind < argc; ++optind)
675 int inf = strtoul (argv[optind], &end, 0);
677 error ("invalid group id '%s'", argv[optind]);
678 VEC_safe_push (int, ids, inf);
680 if (VEC_length (int, ids) > 1)
681 qsort (VEC_address (int, ids),
682 VEC_length (int, ids),
683 sizeof (int), compare_positive_ints);
685 back_to = make_cleanup (free_vector_of_ints, &ids);
689 list_available_thread_groups (ids, recurse);
691 else if (VEC_length (int, ids) == 1)
693 /* Local thread groups, single id. */
694 int pid = *VEC_address (int, ids);
695 if (!in_inferior_list (pid))
696 error ("Invalid thread group id '%d'", pid);
697 print_thread_info (uiout, -1, pid);
701 struct print_one_inferior_data data;
702 data.recurse = recurse;
703 data.inferiors = ids;
705 /* Local thread groups. Either no explicit ids -- and we
706 print everything, or several explicit ids. In both cases,
707 we print more than one group, and have to use 'groups'
708 as the top-level element. */
709 make_cleanup_ui_out_list_begin_end (uiout, "groups");
710 update_thread_list ();
711 iterate_over_inferiors (print_one_inferior, &data);
714 do_cleanups (back_to);
718 mi_cmd_data_list_register_names (char *command, char **argv, int argc)
720 struct frame_info *frame;
721 struct gdbarch *gdbarch;
724 struct cleanup *cleanup;
726 /* Note that the test for a valid register must include checking the
727 gdbarch_register_name because gdbarch_num_regs may be allocated for
728 the union of the register sets within a family of related processors.
729 In this case, some entries of gdbarch_register_name will change depending
730 upon the particular processor being debugged. */
732 frame = get_selected_frame (NULL);
733 gdbarch = get_frame_arch (frame);
734 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
736 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-names");
738 if (argc == 0) /* No args, just do all the regs. */
744 if (gdbarch_register_name (gdbarch, regnum) == NULL
745 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
746 ui_out_field_string (uiout, NULL, "");
748 ui_out_field_string (uiout, NULL,
749 gdbarch_register_name (gdbarch, regnum));
753 /* Else, list of register #s, just do listed regs. */
754 for (i = 0; i < argc; i++)
756 regnum = atoi (argv[i]);
757 if (regnum < 0 || regnum >= numregs)
758 error ("bad register number");
760 if (gdbarch_register_name (gdbarch, regnum) == NULL
761 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
762 ui_out_field_string (uiout, NULL, "");
764 ui_out_field_string (uiout, NULL,
765 gdbarch_register_name (gdbarch, regnum));
767 do_cleanups (cleanup);
771 mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
773 static struct regcache *this_regs = NULL;
774 struct regcache *prev_regs;
775 struct gdbarch *gdbarch;
776 int regnum, numregs, changed;
778 struct cleanup *cleanup;
780 /* The last time we visited this function, the current frame's register
781 contents were saved in THIS_REGS. Move THIS_REGS over to PREV_REGS,
782 and refresh THIS_REGS with the now-current register contents. */
784 prev_regs = this_regs;
785 this_regs = frame_save_as_regcache (get_selected_frame (NULL));
786 cleanup = make_cleanup_regcache_xfree (prev_regs);
788 /* Note that the test for a valid register must include checking the
789 gdbarch_register_name because gdbarch_num_regs may be allocated for
790 the union of the register sets within a family of related processors.
791 In this case, some entries of gdbarch_register_name will change depending
792 upon the particular processor being debugged. */
794 gdbarch = get_regcache_arch (this_regs);
795 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
797 make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
799 if (argc == 0) /* No args, just do all the regs. */
805 if (gdbarch_register_name (gdbarch, regnum) == NULL
806 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
808 changed = register_changed_p (regnum, prev_regs, this_regs);
810 error ("mi_cmd_data_list_changed_registers: Unable to read register contents.");
812 ui_out_field_int (uiout, NULL, regnum);
816 /* Else, list of register #s, just do listed regs. */
817 for (i = 0; i < argc; i++)
819 regnum = atoi (argv[i]);
823 && gdbarch_register_name (gdbarch, regnum) != NULL
824 && *gdbarch_register_name (gdbarch, regnum) != '\000')
826 changed = register_changed_p (regnum, prev_regs, this_regs);
828 error ("mi_cmd_data_list_register_change: Unable to read register contents.");
830 ui_out_field_int (uiout, NULL, regnum);
833 error ("bad register number");
835 do_cleanups (cleanup);
839 register_changed_p (int regnum, struct regcache *prev_regs,
840 struct regcache *this_regs)
842 struct gdbarch *gdbarch = get_regcache_arch (this_regs);
843 gdb_byte prev_buffer[MAX_REGISTER_SIZE];
844 gdb_byte this_buffer[MAX_REGISTER_SIZE];
846 /* Registers not valid in this frame return count as unchanged. */
847 if (!regcache_valid_p (this_regs, regnum))
850 /* First time through or after gdbarch change consider all registers as
851 changed. Same for registers not valid in the previous frame. */
852 if (!prev_regs || get_regcache_arch (prev_regs) != gdbarch
853 || !regcache_valid_p (prev_regs, regnum))
856 /* Get register contents and compare. */
857 regcache_cooked_read (prev_regs, regnum, prev_buffer);
858 regcache_cooked_read (this_regs, regnum, this_buffer);
860 return memcmp (prev_buffer, this_buffer,
861 register_size (gdbarch, regnum)) != 0;
864 /* Return a list of register number and value pairs. The valid
865 arguments expected are: a letter indicating the format in which to
866 display the registers contents. This can be one of: x (hexadecimal), d
867 (decimal), N (natural), t (binary), o (octal), r (raw). After the
868 format argumetn there can be a sequence of numbers, indicating which
869 registers to fetch the content of. If the format is the only argument,
870 a list of all the registers with their values is returned. */
872 mi_cmd_data_list_register_values (char *command, char **argv, int argc)
874 struct frame_info *frame;
875 struct gdbarch *gdbarch;
876 int regnum, numregs, format;
878 struct cleanup *list_cleanup, *tuple_cleanup;
880 /* Note that the test for a valid register must include checking the
881 gdbarch_register_name because gdbarch_num_regs may be allocated for
882 the union of the register sets within a family of related processors.
883 In this case, some entries of gdbarch_register_name will change depending
884 upon the particular processor being debugged. */
887 error ("mi_cmd_data_list_register_values: Usage: -data-list-register-values <format> [<regnum1>...<regnumN>]");
889 format = (int) argv[0][0];
891 frame = get_selected_frame (NULL);
892 gdbarch = get_frame_arch (frame);
893 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
895 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-values");
897 if (argc == 1) /* No args, beside the format: do all the regs. */
903 if (gdbarch_register_name (gdbarch, regnum) == NULL
904 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
906 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
907 ui_out_field_int (uiout, "number", regnum);
908 get_register (frame, regnum, format);
909 do_cleanups (tuple_cleanup);
913 /* Else, list of register #s, just do listed regs. */
914 for (i = 1; i < argc; i++)
916 regnum = atoi (argv[i]);
920 && gdbarch_register_name (gdbarch, regnum) != NULL
921 && *gdbarch_register_name (gdbarch, regnum) != '\000')
923 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
924 ui_out_field_int (uiout, "number", regnum);
925 get_register (frame, regnum, format);
926 do_cleanups (tuple_cleanup);
929 error ("bad register number");
931 do_cleanups (list_cleanup);
934 /* Output one register's contents in the desired format. */
936 get_register (struct frame_info *frame, int regnum, int format)
938 struct gdbarch *gdbarch = get_frame_arch (frame);
939 gdb_byte buffer[MAX_REGISTER_SIZE];
944 static struct ui_stream *stb = NULL;
946 stb = ui_out_stream_new (uiout);
951 frame_register (frame, regnum, &optim, &lval, &addr, &realnum, buffer);
954 error ("Optimized out");
959 char *ptr, buf[1024];
963 for (j = 0; j < register_size (gdbarch, regnum); j++)
965 int idx = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ?
966 j : register_size (gdbarch, regnum) - 1 - j;
967 sprintf (ptr, "%02x", (unsigned char) buffer[idx]);
970 ui_out_field_string (uiout, "value", buf);
971 /*fputs_filtered (buf, gdb_stdout); */
975 struct value_print_options opts;
976 get_formatted_print_options (&opts, format);
978 val_print (register_type (gdbarch, regnum), buffer, 0, 0,
979 stb->stream, 0, &opts, current_language);
980 ui_out_field_stream (uiout, "value", stb);
981 ui_out_stream_delete (stb);
985 /* Write given values into registers. The registers and values are
986 given as pairs. The corresponding MI command is
987 -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]*/
989 mi_cmd_data_write_register_values (char *command, char **argv, int argc)
991 struct regcache *regcache;
992 struct gdbarch *gdbarch;
996 /* Note that the test for a valid register must include checking the
997 gdbarch_register_name because gdbarch_num_regs may be allocated for
998 the union of the register sets within a family of related processors.
999 In this case, some entries of gdbarch_register_name will change depending
1000 upon the particular processor being debugged. */
1002 regcache = get_current_regcache ();
1003 gdbarch = get_regcache_arch (regcache);
1004 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1007 error ("mi_cmd_data_write_register_values: Usage: -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]");
1009 format = (int) argv[0][0];
1011 if (!target_has_registers)
1012 error ("mi_cmd_data_write_register_values: No registers.");
1015 error ("mi_cmd_data_write_register_values: No regs and values specified.");
1018 error ("mi_cmd_data_write_register_values: Regs and vals are not in pairs.");
1020 for (i = 1; i < argc; i = i + 2)
1022 int regnum = atoi (argv[i]);
1024 if (regnum >= 0 && regnum < numregs
1025 && gdbarch_register_name (gdbarch, regnum)
1026 && *gdbarch_register_name (gdbarch, regnum))
1030 /* Get the value as a number. */
1031 value = parse_and_eval_address (argv[i + 1]);
1033 /* Write it down. */
1034 regcache_cooked_write_signed (regcache, regnum, value);
1037 error ("bad register number");
1041 /* Evaluate the value of the argument. The argument is an
1042 expression. If the expression contains spaces it needs to be
1043 included in double quotes. */
1045 mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
1047 struct expression *expr;
1048 struct cleanup *old_chain = NULL;
1050 struct ui_stream *stb = NULL;
1051 struct value_print_options opts;
1053 stb = ui_out_stream_new (uiout);
1057 ui_out_stream_delete (stb);
1058 error ("mi_cmd_data_evaluate_expression: Usage: -data-evaluate-expression expression");
1061 expr = parse_expression (argv[0]);
1063 old_chain = make_cleanup (free_current_contents, &expr);
1065 val = evaluate_expression (expr);
1067 /* Print the result of the expression evaluation. */
1068 get_user_print_options (&opts);
1070 val_print (value_type (val), value_contents (val),
1071 value_embedded_offset (val), value_address (val),
1072 stb->stream, 0, &opts, current_language);
1074 ui_out_field_stream (uiout, "value", stb);
1075 ui_out_stream_delete (stb);
1077 do_cleanups (old_chain);
1080 /* DATA-MEMORY-READ:
1082 ADDR: start address of data to be dumped.
1083 WORD-FORMAT: a char indicating format for the ``word''. See
1085 WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes.
1086 NR_ROW: Number of rows.
1087 NR_COL: The number of colums (words per row).
1088 ASCHAR: (OPTIONAL) Append an ascii character dump to each row. Use
1089 ASCHAR for unprintable characters.
1091 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
1092 displayes them. Returns:
1094 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
1097 The number of bytes read is SIZE*ROW*COL. */
1100 mi_cmd_data_read_memory (char *command, char **argv, int argc)
1102 struct gdbarch *gdbarch = get_current_arch ();
1103 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1109 struct type *word_type;
1122 static struct mi_opt opts[] =
1124 {"o", OFFSET_OPT, 1},
1130 int opt = mi_getopt ("mi_cmd_data_read_memory", argc, argv, opts,
1134 switch ((enum opt) opt)
1137 offset = atol (optarg);
1144 if (argc < 5 || argc > 6)
1145 error ("mi_cmd_data_read_memory: Usage: ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR].");
1147 /* Extract all the arguments. */
1149 /* Start address of the memory dump. */
1150 addr = parse_and_eval_address (argv[0]) + offset;
1151 /* The format character to use when displaying a memory word. See
1152 the ``x'' command. */
1153 word_format = argv[1][0];
1154 /* The size of the memory word. */
1155 word_size = atol (argv[2]);
1159 word_type = builtin_type (gdbarch)->builtin_int8;
1163 word_type = builtin_type (gdbarch)->builtin_int16;
1167 word_type = builtin_type (gdbarch)->builtin_int32;
1171 word_type = builtin_type (gdbarch)->builtin_int64;
1175 word_type = builtin_type (gdbarch)->builtin_int8;
1178 /* The number of rows. */
1179 nr_rows = atol (argv[3]);
1181 error ("mi_cmd_data_read_memory: invalid number of rows.");
1183 /* Number of bytes per row. */
1184 nr_cols = atol (argv[4]);
1186 error ("mi_cmd_data_read_memory: invalid number of columns.");
1188 /* The un-printable character when printing ascii. */
1194 /* Create a buffer and read it in. */
1195 total_bytes = word_size * nr_rows * nr_cols;
1196 mbuf = xcalloc (total_bytes, 1);
1197 make_cleanup (xfree, mbuf);
1199 /* Dispatch memory reads to the topmost target, not the flattened
1201 nr_bytes = target_read_until_error (current_target.beneath,
1202 TARGET_OBJECT_MEMORY, NULL, mbuf,
1205 error ("Unable to read memory.");
1207 /* Output the header information. */
1208 ui_out_field_core_addr (uiout, "addr", gdbarch, addr);
1209 ui_out_field_int (uiout, "nr-bytes", nr_bytes);
1210 ui_out_field_int (uiout, "total-bytes", total_bytes);
1211 ui_out_field_core_addr (uiout, "next-row",
1212 gdbarch, addr + word_size * nr_cols);
1213 ui_out_field_core_addr (uiout, "prev-row",
1214 gdbarch, addr - word_size * nr_cols);
1215 ui_out_field_core_addr (uiout, "next-page", gdbarch, addr + total_bytes);
1216 ui_out_field_core_addr (uiout, "prev-page", gdbarch, addr - total_bytes);
1218 /* Build the result as a two dimentional table. */
1220 struct ui_stream *stream = ui_out_stream_new (uiout);
1221 struct cleanup *cleanup_list_memory;
1224 cleanup_list_memory = make_cleanup_ui_out_list_begin_end (uiout, "memory");
1225 for (row = 0, row_byte = 0;
1227 row++, row_byte += nr_cols * word_size)
1231 struct cleanup *cleanup_tuple;
1232 struct cleanup *cleanup_list_data;
1233 struct value_print_options opts;
1235 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1236 ui_out_field_core_addr (uiout, "addr", gdbarch, addr + row_byte);
1237 /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr + row_byte); */
1238 cleanup_list_data = make_cleanup_ui_out_list_begin_end (uiout, "data");
1239 get_formatted_print_options (&opts, word_format);
1240 for (col = 0, col_byte = row_byte;
1242 col++, col_byte += word_size)
1244 if (col_byte + word_size > nr_bytes)
1246 ui_out_field_string (uiout, NULL, "N/A");
1250 ui_file_rewind (stream->stream);
1251 print_scalar_formatted (mbuf + col_byte, word_type, &opts,
1252 word_asize, stream->stream);
1253 ui_out_field_stream (uiout, NULL, stream);
1256 do_cleanups (cleanup_list_data);
1260 ui_file_rewind (stream->stream);
1261 for (byte = row_byte; byte < row_byte + word_size * nr_cols; byte++)
1263 if (byte >= nr_bytes)
1265 fputc_unfiltered ('X', stream->stream);
1267 else if (mbuf[byte] < 32 || mbuf[byte] > 126)
1269 fputc_unfiltered (aschar, stream->stream);
1272 fputc_unfiltered (mbuf[byte], stream->stream);
1274 ui_out_field_stream (uiout, "ascii", stream);
1276 do_cleanups (cleanup_tuple);
1278 ui_out_stream_delete (stream);
1279 do_cleanups (cleanup_list_memory);
1281 do_cleanups (cleanups);
1284 /* DATA-MEMORY-WRITE:
1286 COLUMN_OFFSET: optional argument. Must be preceeded by '-o'. The
1287 offset from the beginning of the memory grid row where the cell to
1289 ADDR: start address of the row in the memory grid where the memory
1290 cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
1291 the location to write to.
1292 FORMAT: a char indicating format for the ``word''. See
1294 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
1295 VALUE: value to be written into the memory address.
1297 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
1301 mi_cmd_data_write_memory (char *command, char **argv, int argc)
1303 struct gdbarch *gdbarch = get_current_arch ();
1304 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1308 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
1309 enough when using a compiler other than GCC. */
1312 struct cleanup *old_chain;
1320 static struct mi_opt opts[] =
1322 {"o", OFFSET_OPT, 1},
1328 int opt = mi_getopt ("mi_cmd_data_write_memory", argc, argv, opts,
1332 switch ((enum opt) opt)
1335 offset = atol (optarg);
1343 error ("mi_cmd_data_write_memory: Usage: [-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE.");
1345 /* Extract all the arguments. */
1346 /* Start address of the memory dump. */
1347 addr = parse_and_eval_address (argv[0]);
1348 /* The format character to use when displaying a memory word. See
1349 the ``x'' command. */
1350 word_format = argv[1][0];
1351 /* The size of the memory word. */
1352 word_size = atol (argv[2]);
1354 /* Calculate the real address of the write destination. */
1355 addr += (offset * word_size);
1357 /* Get the value as a number. */
1358 value = parse_and_eval_address (argv[3]);
1359 /* Get the value into an array. */
1360 buffer = xmalloc (word_size);
1361 old_chain = make_cleanup (xfree, buffer);
1362 store_signed_integer (buffer, word_size, byte_order, value);
1363 /* Write it down to memory. */
1364 write_memory (addr, buffer, word_size);
1365 /* Free the buffer. */
1366 do_cleanups (old_chain);
1370 mi_cmd_enable_timings (char *command, char **argv, int argc)
1376 if (strcmp (argv[0], "yes") == 0)
1378 else if (strcmp (argv[0], "no") == 0)
1389 error ("mi_cmd_enable_timings: Usage: %s {yes|no}", command);
1393 mi_cmd_list_features (char *command, char **argv, int argc)
1397 struct cleanup *cleanup = NULL;
1398 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1400 ui_out_field_string (uiout, NULL, "frozen-varobjs");
1401 ui_out_field_string (uiout, NULL, "pending-breakpoints");
1402 ui_out_field_string (uiout, NULL, "thread-info");
1405 ui_out_field_string (uiout, NULL, "python");
1408 do_cleanups (cleanup);
1412 error ("-list-features should be passed no arguments");
1416 mi_cmd_list_target_features (char *command, char **argv, int argc)
1420 struct cleanup *cleanup = NULL;
1421 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1423 if (target_can_async_p ())
1424 ui_out_field_string (uiout, NULL, "async");
1426 do_cleanups (cleanup);
1430 error ("-list-target-features should be passed no arguments");
1433 /* Execute a command within a safe environment.
1434 Return <0 for error; >=0 for ok.
1436 args->action will tell mi_execute_command what action
1437 to perfrom after the given command has executed (display/suppress
1438 prompt, display error). */
1441 captured_mi_execute_command (struct ui_out *uiout, void *data)
1443 struct cleanup *cleanup;
1444 struct mi_parse *context = (struct mi_parse *) data;
1447 current_command_ts = context->cmd_start;
1449 current_token = xstrdup (context->token);
1450 cleanup = make_cleanup (free_current_contents, ¤t_token);
1452 running_result_record_printed = 0;
1454 switch (context->op)
1457 /* A MI command was read from the input stream. */
1459 /* FIXME: gdb_???? */
1460 fprintf_unfiltered (raw_stdout, " token=`%s' command=`%s' args=`%s'\n",
1461 context->token, context->command, context->args);
1464 mi_cmd_execute (context);
1466 /* Print the result if there were no errors.
1468 Remember that on the way out of executing a command, you have
1469 to directly use the mi_interp's uiout, since the command could
1470 have reset the interpreter, in which case the current uiout
1471 will most likely crash in the mi_out_* routines. */
1472 if (!running_result_record_printed)
1474 fputs_unfiltered (context->token, raw_stdout);
1475 /* There's no particularly good reason why target-connect results
1476 in not ^done. Should kill ^connected for MI3. */
1477 fputs_unfiltered (strcmp (context->command, "target-select") == 0
1478 ? "^connected" : "^done", raw_stdout);
1479 mi_out_put (uiout, raw_stdout);
1480 mi_out_rewind (uiout);
1481 mi_print_timing_maybe ();
1482 fputs_unfiltered ("\n", raw_stdout);
1485 /* The command does not want anything to be printed. In that
1486 case, the command probably should not have written anything
1487 to uiout, but in case it has written something, discard it. */
1488 mi_out_rewind (uiout);
1494 /* A CLI command was read from the input stream. */
1495 /* This "feature" will be removed as soon as we have a
1496 complete set of mi commands. */
1497 /* Echo the command on the console. */
1498 fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
1499 /* Call the "console" interpreter. */
1500 argv[0] = "console";
1501 argv[1] = context->command;
1502 mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
1504 /* If we changed interpreters, DON'T print out anything. */
1505 if (current_interp_named_p (INTERP_MI)
1506 || current_interp_named_p (INTERP_MI1)
1507 || current_interp_named_p (INTERP_MI2)
1508 || current_interp_named_p (INTERP_MI3))
1510 if (!running_result_record_printed)
1512 fputs_unfiltered (context->token, raw_stdout);
1513 fputs_unfiltered ("^done", raw_stdout);
1514 mi_out_put (uiout, raw_stdout);
1515 mi_out_rewind (uiout);
1516 mi_print_timing_maybe ();
1517 fputs_unfiltered ("\n", raw_stdout);
1520 mi_out_rewind (uiout);
1527 do_cleanups (cleanup);
1534 mi_execute_command (char *cmd, int from_tty)
1536 struct mi_parse *command;
1537 struct ui_out *saved_uiout = uiout;
1539 /* This is to handle EOF (^D). We just quit gdb. */
1540 /* FIXME: we should call some API function here. */
1542 quit_force (NULL, from_tty);
1544 command = mi_parse (cmd);
1546 if (command != NULL)
1548 struct gdb_exception result;
1549 ptid_t previous_ptid = inferior_ptid;
1553 command->cmd_start = (struct mi_timestamp *)
1554 xmalloc (sizeof (struct mi_timestamp));
1555 timestamp (command->cmd_start);
1558 result = catch_exception (uiout, captured_mi_execute_command, command,
1560 if (result.reason < 0)
1562 /* The command execution failed and error() was called
1564 fputs_unfiltered (command->token, raw_stdout);
1565 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1566 if (result.message == NULL)
1567 fputs_unfiltered ("unknown error", raw_stdout);
1569 fputstr_unfiltered (result.message, '"', raw_stdout);
1570 fputs_unfiltered ("\"\n", raw_stdout);
1571 mi_out_rewind (uiout);
1574 bpstat_do_actions ();
1576 if (/* The notifications are only output when the top-level
1577 interpreter (specified on the command line) is MI. */
1578 ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ()))
1579 /* Don't try report anything if there are no threads --
1580 the program is dead. */
1581 && thread_count () != 0
1582 /* -thread-select explicitly changes thread. If frontend uses that
1583 internally, we don't want to emit =thread-selected, since
1584 =thread-selected is supposed to indicate user's intentions. */
1585 && strcmp (command->command, "thread-select") != 0)
1587 struct mi_interp *mi = top_level_interpreter_data ();
1588 int report_change = 0;
1590 if (command->thread == -1)
1592 report_change = (!ptid_equal (previous_ptid, null_ptid)
1593 && !ptid_equal (inferior_ptid, previous_ptid)
1594 && !ptid_equal (inferior_ptid, null_ptid));
1596 else if (!ptid_equal (inferior_ptid, null_ptid))
1598 struct thread_info *ti = inferior_thread ();
1599 report_change = (ti->num != command->thread);
1604 struct thread_info *ti = inferior_thread ();
1605 target_terminal_ours ();
1606 fprintf_unfiltered (mi->event_channel,
1607 "thread-selected,id=\"%d\"",
1609 gdb_flush (mi->event_channel);
1613 mi_parse_free (command);
1616 fputs_unfiltered ("(gdb) \n", raw_stdout);
1617 gdb_flush (raw_stdout);
1618 /* Print any buffered hook code. */
1623 mi_cmd_execute (struct mi_parse *parse)
1625 struct cleanup *cleanup;
1628 prepare_execute_command ();
1630 cleanup = make_cleanup (null_cleanup, NULL);
1632 if (parse->frame != -1 && parse->thread == -1)
1633 error (_("Cannot specify --frame without --thread"));
1635 if (parse->thread != -1)
1637 struct thread_info *tp = find_thread_id (parse->thread);
1639 error (_("Invalid thread id: %d"), parse->thread);
1641 if (is_exited (tp->ptid))
1642 error (_("Thread id: %d has terminated"), parse->thread);
1644 switch_to_thread (tp->ptid);
1647 if (parse->frame != -1)
1649 struct frame_info *fid;
1650 int frame = parse->frame;
1651 fid = find_relative_frame (get_current_frame (), &frame);
1653 /* find_relative_frame was successful */
1656 error (_("Invalid frame id: %d"), frame);
1659 if (parse->cmd->argv_func != NULL)
1660 parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
1661 else if (parse->cmd->cli.cmd != 0)
1663 /* FIXME: DELETE THIS. */
1664 /* The operation is still implemented by a cli command. */
1665 /* Must be a synchronous one. */
1666 mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
1671 /* FIXME: DELETE THIS. */
1672 struct ui_file *stb;
1674 stb = mem_fileopen ();
1676 fputs_unfiltered ("Undefined mi command: ", stb);
1677 fputstr_unfiltered (parse->command, '"', stb);
1678 fputs_unfiltered (" (missing implementation)", stb);
1680 make_cleanup_ui_file_delete (stb);
1683 do_cleanups (cleanup);
1686 /* FIXME: This is just a hack so we can get some extra commands going.
1687 We don't want to channel things through the CLI, but call libgdb directly.
1688 Use only for synchronous commands. */
1691 mi_execute_cli_command (const char *cmd, int args_p, const char *args)
1695 struct cleanup *old_cleanups;
1698 run = xstrprintf ("%s %s", cmd, args);
1700 run = xstrdup (cmd);
1702 /* FIXME: gdb_???? */
1703 fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
1705 old_cleanups = make_cleanup (xfree, run);
1706 execute_command ( /*ui */ run, 0 /*from_tty */ );
1707 do_cleanups (old_cleanups);
1713 mi_execute_async_cli_command (char *cli_command, char **argv, int argc)
1715 struct cleanup *old_cleanups;
1718 if (target_can_async_p ())
1719 run = xstrprintf ("%s %s&", cli_command, argc ? *argv : "");
1721 run = xstrprintf ("%s %s", cli_command, argc ? *argv : "");
1722 old_cleanups = make_cleanup (xfree, run);
1724 execute_command ( /*ui */ run, 0 /*from_tty */ );
1726 if (target_can_async_p ())
1728 /* If we're not executing, an exception should have been throw. */
1729 gdb_assert (is_running (inferior_ptid));
1730 do_cleanups (old_cleanups);
1734 /* Do this before doing any printing. It would appear that some
1735 print code leaves garbage around in the buffer. */
1736 do_cleanups (old_cleanups);
1741 mi_load_progress (const char *section_name,
1742 unsigned long sent_so_far,
1743 unsigned long total_section,
1744 unsigned long total_sent,
1745 unsigned long grand_total)
1747 struct timeval time_now, delta, update_threshold;
1748 static struct timeval last_update;
1749 static char *previous_sect_name = NULL;
1751 struct ui_out *saved_uiout;
1753 /* This function is called through deprecated_show_load_progress
1754 which means uiout may not be correct. Fix it for the duration
1755 of this function. */
1756 saved_uiout = uiout;
1758 if (current_interp_named_p (INTERP_MI)
1759 || current_interp_named_p (INTERP_MI2))
1760 uiout = mi_out_new (2);
1761 else if (current_interp_named_p (INTERP_MI1))
1762 uiout = mi_out_new (1);
1763 else if (current_interp_named_p (INTERP_MI3))
1764 uiout = mi_out_new (3);
1768 update_threshold.tv_sec = 0;
1769 update_threshold.tv_usec = 500000;
1770 gettimeofday (&time_now, NULL);
1772 delta.tv_usec = time_now.tv_usec - last_update.tv_usec;
1773 delta.tv_sec = time_now.tv_sec - last_update.tv_sec;
1775 if (delta.tv_usec < 0)
1778 delta.tv_usec += 1000000L;
1781 new_section = (previous_sect_name ?
1782 strcmp (previous_sect_name, section_name) : 1);
1785 struct cleanup *cleanup_tuple;
1786 xfree (previous_sect_name);
1787 previous_sect_name = xstrdup (section_name);
1790 fputs_unfiltered (current_token, raw_stdout);
1791 fputs_unfiltered ("+download", raw_stdout);
1792 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1793 ui_out_field_string (uiout, "section", section_name);
1794 ui_out_field_int (uiout, "section-size", total_section);
1795 ui_out_field_int (uiout, "total-size", grand_total);
1796 do_cleanups (cleanup_tuple);
1797 mi_out_put (uiout, raw_stdout);
1798 fputs_unfiltered ("\n", raw_stdout);
1799 gdb_flush (raw_stdout);
1802 if (delta.tv_sec >= update_threshold.tv_sec &&
1803 delta.tv_usec >= update_threshold.tv_usec)
1805 struct cleanup *cleanup_tuple;
1806 last_update.tv_sec = time_now.tv_sec;
1807 last_update.tv_usec = time_now.tv_usec;
1809 fputs_unfiltered (current_token, raw_stdout);
1810 fputs_unfiltered ("+download", raw_stdout);
1811 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1812 ui_out_field_string (uiout, "section", section_name);
1813 ui_out_field_int (uiout, "section-sent", sent_so_far);
1814 ui_out_field_int (uiout, "section-size", total_section);
1815 ui_out_field_int (uiout, "total-sent", total_sent);
1816 ui_out_field_int (uiout, "total-size", grand_total);
1817 do_cleanups (cleanup_tuple);
1818 mi_out_put (uiout, raw_stdout);
1819 fputs_unfiltered ("\n", raw_stdout);
1820 gdb_flush (raw_stdout);
1824 uiout = saved_uiout;
1828 timestamp (struct mi_timestamp *tv)
1831 gettimeofday (&tv->wallclock, NULL);
1832 #ifdef HAVE_GETRUSAGE
1833 getrusage (RUSAGE_SELF, &rusage);
1834 tv->utime.tv_sec = rusage.ru_utime.tv_sec;
1835 tv->utime.tv_usec = rusage.ru_utime.tv_usec;
1836 tv->stime.tv_sec = rusage.ru_stime.tv_sec;
1837 tv->stime.tv_usec = rusage.ru_stime.tv_usec;
1839 usec = get_run_time ();
1840 tv->utime.tv_sec = usec/1000000L;
1841 tv->utime.tv_usec = usec - 1000000L*tv->utime.tv_sec;
1842 tv->stime.tv_sec = 0;
1843 tv->stime.tv_usec = 0;
1848 print_diff_now (struct mi_timestamp *start)
1850 struct mi_timestamp now;
1852 print_diff (start, &now);
1856 mi_print_timing_maybe (void)
1858 /* If the command is -enable-timing then do_timings may be
1859 true whilst current_command_ts is not initialized. */
1860 if (do_timings && current_command_ts)
1861 print_diff_now (current_command_ts);
1865 timeval_diff (struct timeval start, struct timeval end)
1867 return ((end.tv_sec - start.tv_sec) * 1000000L)
1868 + (end.tv_usec - start.tv_usec);
1872 print_diff (struct mi_timestamp *start, struct mi_timestamp *end)
1876 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
1877 timeval_diff (start->wallclock, end->wallclock) / 1000000.0,
1878 timeval_diff (start->utime, end->utime) / 1000000.0,
1879 timeval_diff (start->stime, end->stime) / 1000000.0);