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 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
125 mi_execute_async_cli_command ("reverse-next", argv + 1, argc - 1);
127 mi_execute_async_cli_command ("next", argv, argc);
131 mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
133 /* FIXME: Should call a libgdb function, not a cli wrapper. */
134 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
135 mi_execute_async_cli_command ("reverse-nexti", argv + 1, argc - 1);
137 mi_execute_async_cli_command ("nexti", argv, argc);
141 mi_cmd_exec_step (char *command, char **argv, int argc)
143 /* FIXME: Should call a libgdb function, not a cli wrapper. */
144 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
145 mi_execute_async_cli_command ("reverse-step", argv + 1, argc - 1);
147 mi_execute_async_cli_command ("step", argv, argc);
151 mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
153 /* FIXME: Should call a libgdb function, not a cli wrapper. */
154 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
155 mi_execute_async_cli_command ("reverse-stepi", argv + 1, argc - 1);
157 mi_execute_async_cli_command ("stepi", argv, argc);
161 mi_cmd_exec_finish (char *command, char **argv, int argc)
163 /* FIXME: Should call a libgdb function, not a cli wrapper. */
164 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
165 mi_execute_async_cli_command ("reverse-finish", argv + 1, argc - 1);
167 mi_execute_async_cli_command ("finish", argv, argc);
171 mi_cmd_exec_return (char *command, char **argv, int argc)
173 /* This command doesn't really execute the target, it just pops the
174 specified number of frames. */
176 /* Call return_command with from_tty argument equal to 0 so as to
177 avoid being queried. */
178 return_command (*argv, 0);
180 /* Call return_command with from_tty argument equal to 0 so as to
181 avoid being queried. */
182 return_command (NULL, 0);
184 /* Because we have called return_command with from_tty = 0, we need
185 to print the frame here. */
186 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS);
190 mi_cmd_exec_jump (char *args, char **argv, int argc)
192 /* FIXME: Should call a libgdb function, not a cli wrapper. */
193 mi_execute_async_cli_command ("jump", argv, argc);
197 proceed_thread_callback (struct thread_info *thread, void *arg)
199 int pid = *(int *)arg;
201 if (!is_stopped (thread->ptid))
204 if (PIDGET (thread->ptid) != pid)
207 switch_to_thread (thread->ptid);
208 clear_proceed_status ();
209 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
214 exec_continue (char **argv, int argc)
218 else if (argc == 1 && strcmp (argv[0], "--all") == 0)
220 else if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
222 struct cleanup *old_chain;
224 if (argv[1] == NULL || argv[1] == '\0')
225 error ("Thread group id not specified");
226 pid = atoi (argv[1]);
227 if (!in_inferior_list (pid))
228 error ("Invalid thread group id '%s'", argv[1]);
230 old_chain = make_cleanup_restore_current_thread ();
231 iterate_over_threads (proceed_thread_callback, &pid);
232 do_cleanups (old_chain);
235 error ("Usage: -exec-continue [--reverse] [--all|--thread-group id]");
238 /* continue in reverse direction:
239 XXX: code duplicated from reverse.c */
242 exec_direction_default (void *notused)
244 /* Return execution direction to default state. */
245 execution_direction = EXEC_FORWARD;
249 exec_reverse_continue (char **argv, int argc)
251 enum exec_direction_kind dir = execution_direction;
252 struct cleanup *old_chain;
254 if (dir == EXEC_ERROR)
255 error (_("Target %s does not support this command."), target_shortname);
257 if (dir == EXEC_REVERSE)
258 error (_("Already in reverse mode."));
260 if (!target_can_execute_reverse)
261 error (_("Target %s does not support this command."), target_shortname);
263 old_chain = make_cleanup (exec_direction_default, NULL);
264 execution_direction = EXEC_REVERSE;
265 exec_continue (argv, argc);
266 do_cleanups (old_chain);
270 mi_cmd_exec_continue (char *command, char **argv, int argc)
272 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
273 exec_reverse_continue (argv + 1, argc - 1);
275 exec_continue (argv, argc);
279 interrupt_thread_callback (struct thread_info *thread, void *arg)
281 int pid = *(int *)arg;
283 if (!is_running (thread->ptid))
286 if (PIDGET (thread->ptid) != pid)
289 target_stop (thread->ptid);
293 /* Interrupt the execution of the target. Note how we must play around
294 with the token variables, in order to display the current token in
295 the result of the interrupt command, and the previous execution
296 token when the target finally stops. See comments in
299 mi_cmd_exec_interrupt (char *command, char **argv, int argc)
303 if (!is_running (inferior_ptid))
304 error ("Current thread is not running.");
306 interrupt_target_1 (0);
308 else if (argc == 1 && strcmp (argv[0], "--all") == 0)
311 error ("Inferior not running.");
313 interrupt_target_1 (1);
315 else if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
317 struct cleanup *old_chain;
319 if (argv[1] == NULL || argv[1] == '\0')
320 error ("Thread group id not specified");
321 pid = atoi (argv[1]);
322 if (!in_inferior_list (pid))
323 error ("Invalid thread group id '%s'", argv[1]);
325 old_chain = make_cleanup_restore_current_thread ();
326 iterate_over_threads (interrupt_thread_callback, &pid);
327 do_cleanups (old_chain);
330 error ("Usage: -exec-interrupt [--all|--thread-group id]");
334 mi_cmd_exec_run (char *command, char **argv, int argc)
336 mi_execute_cli_command ("run", target_can_async_p (),
337 target_can_async_p () ? "&" : NULL);
341 find_thread_of_process (struct thread_info *ti, void *p)
344 if (PIDGET (ti->ptid) == pid && !is_exited (ti->ptid))
351 mi_cmd_target_detach (char *command, char **argv, int argc)
353 if (argc != 0 && argc != 1)
354 error ("Usage: -target-detach [thread-group]");
358 struct thread_info *tp;
360 int pid = strtol (argv[0], &end, 10);
362 error (_("Cannot parse thread group id '%s'"), argv[0]);
364 /* Pick any thread in the desired process. Current
365 target_detach deteches from the parent of inferior_ptid. */
366 tp = iterate_over_threads (find_thread_of_process, &pid);
368 error (_("Thread group is empty"));
370 switch_to_thread (tp->ptid);
373 detach_command (NULL, 0);
377 mi_cmd_thread_select (char *command, char **argv, int argc)
380 char *mi_error_message;
383 error ("mi_cmd_thread_select: USAGE: threadnum.");
385 rc = gdb_thread_select (uiout, argv[0], &mi_error_message);
387 if (rc == GDB_RC_FAIL)
389 make_cleanup (xfree, mi_error_message);
390 error ("%s", mi_error_message);
395 mi_cmd_thread_list_ids (char *command, char **argv, int argc)
398 char *mi_error_message;
401 error ("mi_cmd_thread_list_ids: No arguments required.");
403 rc = gdb_list_thread_ids (uiout, &mi_error_message);
405 if (rc == GDB_RC_FAIL)
407 make_cleanup (xfree, mi_error_message);
408 error ("%s", mi_error_message);
413 mi_cmd_thread_info (char *command, char **argv, int argc)
417 if (argc != 0 && argc != 1)
418 error ("Invalid MI command");
421 thread = atoi (argv[0]);
423 print_thread_info (uiout, thread, -1);
426 struct collect_cores_data
434 collect_cores (struct thread_info *ti, void *xdata)
436 struct collect_cores_data *data = xdata;
438 if (ptid_get_pid (ti->ptid) == data->pid)
440 int core = target_core_of_thread (ti->ptid);
442 VEC_safe_push (int, data->cores, core);
449 unique (int *b, int *e)
458 struct print_one_inferior_data
461 VEC (int) *inferiors;
465 print_one_inferior (struct inferior *inferior, void *xdata)
467 struct print_one_inferior_data *top_data = xdata;
469 if (VEC_empty (int, top_data->inferiors)
470 || bsearch (&(inferior->pid), VEC_address (int, top_data->inferiors),
471 VEC_length (int, top_data->inferiors), sizeof (int),
472 compare_positive_ints))
474 struct collect_cores_data data;
475 struct cleanup *back_to
476 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
478 ui_out_field_fmt (uiout, "id", "%d", inferior->pid);
479 ui_out_field_string (uiout, "type", "process");
480 ui_out_field_int (uiout, "pid", inferior->pid);
482 data.pid = inferior->pid;
484 iterate_over_threads (collect_cores, &data);
486 if (!VEC_empty (int, data.cores))
491 struct cleanup *back_to_2 =
492 make_cleanup_ui_out_list_begin_end (uiout, "cores");
494 qsort (VEC_address (int, data.cores),
495 VEC_length (int, data.cores), sizeof (int),
496 compare_positive_ints);
498 b = VEC_address (int, data.cores);
499 e = b + VEC_length (int, data.cores);
503 ui_out_field_int (uiout, NULL, *b);
505 do_cleanups (back_to_2);
508 if (top_data->recurse)
509 print_thread_info (uiout, -1, inferior->pid);
511 do_cleanups (back_to);
517 /* Output a field named 'cores' with a list as the value. The elements of
518 the list are obtained by splitting 'cores' on comma. */
521 output_cores (struct ui_out *uiout, const char *field_name, const char *xcores)
523 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
525 char *cores = xstrdup (xcores);
528 make_cleanup (xfree, cores);
530 for (p = strtok (p, ","); p; p = strtok (NULL, ","))
531 ui_out_field_string (uiout, NULL, p);
533 do_cleanups (back_to);
537 free_vector_of_ints (void *xvector)
539 VEC (int) **vector = xvector;
540 VEC_free (int, *vector);
544 do_nothing (splay_tree_key k)
549 free_vector_of_osdata_items (splay_tree_value xvalue)
551 VEC (osdata_item_s) *value = (VEC (osdata_item_s) *) xvalue;
552 /* We don't free the items itself, it will be done separately. */
553 VEC_free (osdata_item_s, value);
557 splay_tree_int_comparator (splay_tree_key xa, splay_tree_key xb)
565 free_splay_tree (void *xt)
568 splay_tree_delete (t);
572 list_available_thread_groups (VEC (int) *ids, int recurse)
575 struct osdata_item *item;
577 /* This keeps a map from integer (pid) to VEC (struct osdata_item *)*
578 The vector contains information about all threads for the given pid.
579 This is assigned an initial value to avoid "may be used uninitialized"
581 splay_tree tree = NULL;
583 /* get_osdata will throw if it cannot return data. */
584 data = get_osdata ("processes");
585 make_cleanup_osdata_free (data);
589 struct osdata *threads = get_osdata ("threads");
590 make_cleanup_osdata_free (threads);
592 tree = splay_tree_new (splay_tree_int_comparator,
594 free_vector_of_osdata_items);
595 make_cleanup (free_splay_tree, tree);
598 VEC_iterate (osdata_item_s, threads->items,
602 const char *pid = get_osdata_column (item, "pid");
603 int pid_i = strtoul (pid, NULL, 0);
604 VEC (osdata_item_s) *vec = 0;
606 splay_tree_node n = splay_tree_lookup (tree, pid_i);
609 VEC_safe_push (osdata_item_s, vec, item);
610 splay_tree_insert (tree, pid_i, (splay_tree_value)vec);
614 vec = (VEC (osdata_item_s) *) n->value;
615 VEC_safe_push (osdata_item_s, vec, item);
616 n->value = (splay_tree_value) vec;
621 make_cleanup_ui_out_list_begin_end (uiout, "groups");
624 VEC_iterate (osdata_item_s, data->items,
628 struct cleanup *back_to;
630 const char *pid = get_osdata_column (item, "pid");
631 const char *cmd = get_osdata_column (item, "command");
632 const char *user = get_osdata_column (item, "user");
633 const char *cores = get_osdata_column (item, "cores");
635 int pid_i = strtoul (pid, NULL, 0);
637 /* At present, the target will return all available processes
638 and if information about specific ones was required, we filter
639 undesired processes here. */
640 if (ids && bsearch (&pid_i, VEC_address (int, ids),
641 VEC_length (int, ids),
642 sizeof (int), compare_positive_ints) == NULL)
646 back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
648 ui_out_field_fmt (uiout, "id", "%s", pid);
649 ui_out_field_string (uiout, "type", "process");
651 ui_out_field_string (uiout, "description", cmd);
653 ui_out_field_string (uiout, "user", user);
655 output_cores (uiout, "cores", cores);
659 splay_tree_node n = splay_tree_lookup (tree, pid_i);
662 VEC (osdata_item_s) *children = (VEC (osdata_item_s) *) n->value;
663 struct osdata_item *child;
666 make_cleanup_ui_out_list_begin_end (uiout, "threads");
669 VEC_iterate (osdata_item_s, children, ix_child, child);
672 struct cleanup *back_to_2 =
673 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
675 const char *tid = get_osdata_column (child, "tid");
676 const char *tcore = get_osdata_column (child, "core");
677 ui_out_field_string (uiout, "id", tid);
679 ui_out_field_string (uiout, "core", tcore);
681 do_cleanups (back_to_2);
686 do_cleanups (back_to);
691 mi_cmd_list_thread_groups (char *command, char **argv, int argc)
693 struct cleanup *back_to;
700 AVAILABLE_OPT, RECURSE_OPT
702 static struct mi_opt opts[] =
704 {"-available", AVAILABLE_OPT, 0},
705 {"-recurse", RECURSE_OPT, 1},
714 int opt = mi_getopt ("-list-thread-groups", argc, argv, opts,
718 switch ((enum opt) opt)
724 if (strcmp (optarg, "0") == 0)
726 else if (strcmp (optarg, "1") == 0)
729 error ("only '0' and '1' are valid values for the '--recurse' option");
734 for (; optind < argc; ++optind)
737 int inf = strtoul (argv[optind], &end, 0);
739 error ("invalid group id '%s'", argv[optind]);
740 VEC_safe_push (int, ids, inf);
742 if (VEC_length (int, ids) > 1)
743 qsort (VEC_address (int, ids),
744 VEC_length (int, ids),
745 sizeof (int), compare_positive_ints);
747 back_to = make_cleanup (free_vector_of_ints, &ids);
751 list_available_thread_groups (ids, recurse);
753 else if (VEC_length (int, ids) == 1)
755 /* Local thread groups, single id. */
756 int pid = *VEC_address (int, ids);
757 if (!in_inferior_list (pid))
758 error ("Invalid thread group id '%d'", pid);
759 print_thread_info (uiout, -1, pid);
763 struct print_one_inferior_data data;
764 data.recurse = recurse;
765 data.inferiors = ids;
767 /* Local thread groups. Either no explicit ids -- and we
768 print everything, or several explicit ids. In both cases,
769 we print more than one group, and have to use 'groups'
770 as the top-level element. */
771 make_cleanup_ui_out_list_begin_end (uiout, "groups");
772 update_thread_list ();
773 iterate_over_inferiors (print_one_inferior, &data);
776 do_cleanups (back_to);
780 mi_cmd_data_list_register_names (char *command, char **argv, int argc)
782 struct frame_info *frame;
783 struct gdbarch *gdbarch;
786 struct cleanup *cleanup;
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 frame = get_selected_frame (NULL);
795 gdbarch = get_frame_arch (frame);
796 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
798 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-names");
800 if (argc == 0) /* No args, just do all the regs. */
806 if (gdbarch_register_name (gdbarch, regnum) == NULL
807 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
808 ui_out_field_string (uiout, NULL, "");
810 ui_out_field_string (uiout, NULL,
811 gdbarch_register_name (gdbarch, regnum));
815 /* Else, list of register #s, just do listed regs. */
816 for (i = 0; i < argc; i++)
818 regnum = atoi (argv[i]);
819 if (regnum < 0 || regnum >= numregs)
820 error ("bad register number");
822 if (gdbarch_register_name (gdbarch, regnum) == NULL
823 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
824 ui_out_field_string (uiout, NULL, "");
826 ui_out_field_string (uiout, NULL,
827 gdbarch_register_name (gdbarch, regnum));
829 do_cleanups (cleanup);
833 mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
835 static struct regcache *this_regs = NULL;
836 struct regcache *prev_regs;
837 struct gdbarch *gdbarch;
838 int regnum, numregs, changed;
840 struct cleanup *cleanup;
842 /* The last time we visited this function, the current frame's register
843 contents were saved in THIS_REGS. Move THIS_REGS over to PREV_REGS,
844 and refresh THIS_REGS with the now-current register contents. */
846 prev_regs = this_regs;
847 this_regs = frame_save_as_regcache (get_selected_frame (NULL));
848 cleanup = make_cleanup_regcache_xfree (prev_regs);
850 /* Note that the test for a valid register must include checking the
851 gdbarch_register_name because gdbarch_num_regs may be allocated for
852 the union of the register sets within a family of related processors.
853 In this case, some entries of gdbarch_register_name will change depending
854 upon the particular processor being debugged. */
856 gdbarch = get_regcache_arch (this_regs);
857 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
859 make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
861 if (argc == 0) /* No args, just do all the regs. */
867 if (gdbarch_register_name (gdbarch, regnum) == NULL
868 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
870 changed = register_changed_p (regnum, prev_regs, this_regs);
872 error ("mi_cmd_data_list_changed_registers: Unable to read register contents.");
874 ui_out_field_int (uiout, NULL, regnum);
878 /* Else, list of register #s, just do listed regs. */
879 for (i = 0; i < argc; i++)
881 regnum = atoi (argv[i]);
885 && gdbarch_register_name (gdbarch, regnum) != NULL
886 && *gdbarch_register_name (gdbarch, regnum) != '\000')
888 changed = register_changed_p (regnum, prev_regs, this_regs);
890 error ("mi_cmd_data_list_register_change: Unable to read register contents.");
892 ui_out_field_int (uiout, NULL, regnum);
895 error ("bad register number");
897 do_cleanups (cleanup);
901 register_changed_p (int regnum, struct regcache *prev_regs,
902 struct regcache *this_regs)
904 struct gdbarch *gdbarch = get_regcache_arch (this_regs);
905 gdb_byte prev_buffer[MAX_REGISTER_SIZE];
906 gdb_byte this_buffer[MAX_REGISTER_SIZE];
908 /* Registers not valid in this frame return count as unchanged. */
909 if (!regcache_valid_p (this_regs, regnum))
912 /* First time through or after gdbarch change consider all registers as
913 changed. Same for registers not valid in the previous frame. */
914 if (!prev_regs || get_regcache_arch (prev_regs) != gdbarch
915 || !regcache_valid_p (prev_regs, regnum))
918 /* Get register contents and compare. */
919 regcache_cooked_read (prev_regs, regnum, prev_buffer);
920 regcache_cooked_read (this_regs, regnum, this_buffer);
922 return memcmp (prev_buffer, this_buffer,
923 register_size (gdbarch, regnum)) != 0;
926 /* Return a list of register number and value pairs. The valid
927 arguments expected are: a letter indicating the format in which to
928 display the registers contents. This can be one of: x (hexadecimal), d
929 (decimal), N (natural), t (binary), o (octal), r (raw). After the
930 format argumetn there can be a sequence of numbers, indicating which
931 registers to fetch the content of. If the format is the only argument,
932 a list of all the registers with their values is returned. */
934 mi_cmd_data_list_register_values (char *command, char **argv, int argc)
936 struct frame_info *frame;
937 struct gdbarch *gdbarch;
938 int regnum, numregs, format;
940 struct cleanup *list_cleanup, *tuple_cleanup;
942 /* Note that the test for a valid register must include checking the
943 gdbarch_register_name because gdbarch_num_regs may be allocated for
944 the union of the register sets within a family of related processors.
945 In this case, some entries of gdbarch_register_name will change depending
946 upon the particular processor being debugged. */
949 error ("mi_cmd_data_list_register_values: Usage: -data-list-register-values <format> [<regnum1>...<regnumN>]");
951 format = (int) argv[0][0];
953 frame = get_selected_frame (NULL);
954 gdbarch = get_frame_arch (frame);
955 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
957 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-values");
959 if (argc == 1) /* No args, beside the format: do all the regs. */
965 if (gdbarch_register_name (gdbarch, regnum) == NULL
966 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
968 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
969 ui_out_field_int (uiout, "number", regnum);
970 get_register (frame, regnum, format);
971 do_cleanups (tuple_cleanup);
975 /* Else, list of register #s, just do listed regs. */
976 for (i = 1; i < argc; i++)
978 regnum = atoi (argv[i]);
982 && gdbarch_register_name (gdbarch, regnum) != NULL
983 && *gdbarch_register_name (gdbarch, regnum) != '\000')
985 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
986 ui_out_field_int (uiout, "number", regnum);
987 get_register (frame, regnum, format);
988 do_cleanups (tuple_cleanup);
991 error ("bad register number");
993 do_cleanups (list_cleanup);
996 /* Output one register's contents in the desired format. */
998 get_register (struct frame_info *frame, int regnum, int format)
1000 struct gdbarch *gdbarch = get_frame_arch (frame);
1001 gdb_byte buffer[MAX_REGISTER_SIZE];
1005 enum lval_type lval;
1006 static struct ui_stream *stb = NULL;
1008 stb = ui_out_stream_new (uiout);
1013 frame_register (frame, regnum, &optim, &lval, &addr, &realnum, buffer);
1016 error ("Optimized out");
1021 char *ptr, buf[1024];
1025 for (j = 0; j < register_size (gdbarch, regnum); j++)
1027 int idx = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ?
1028 j : register_size (gdbarch, regnum) - 1 - j;
1029 sprintf (ptr, "%02x", (unsigned char) buffer[idx]);
1032 ui_out_field_string (uiout, "value", buf);
1033 /*fputs_filtered (buf, gdb_stdout); */
1037 struct value_print_options opts;
1038 get_formatted_print_options (&opts, format);
1040 val_print (register_type (gdbarch, regnum), buffer, 0, 0,
1041 stb->stream, 0, &opts, current_language);
1042 ui_out_field_stream (uiout, "value", stb);
1043 ui_out_stream_delete (stb);
1047 /* Write given values into registers. The registers and values are
1048 given as pairs. The corresponding MI command is
1049 -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]*/
1051 mi_cmd_data_write_register_values (char *command, char **argv, int argc)
1053 struct regcache *regcache;
1054 struct gdbarch *gdbarch;
1058 /* Note that the test for a valid register must include checking the
1059 gdbarch_register_name because gdbarch_num_regs may be allocated for
1060 the union of the register sets within a family of related processors.
1061 In this case, some entries of gdbarch_register_name will change depending
1062 upon the particular processor being debugged. */
1064 regcache = get_current_regcache ();
1065 gdbarch = get_regcache_arch (regcache);
1066 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1069 error ("mi_cmd_data_write_register_values: Usage: -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]");
1071 format = (int) argv[0][0];
1073 if (!target_has_registers)
1074 error ("mi_cmd_data_write_register_values: No registers.");
1077 error ("mi_cmd_data_write_register_values: No regs and values specified.");
1080 error ("mi_cmd_data_write_register_values: Regs and vals are not in pairs.");
1082 for (i = 1; i < argc; i = i + 2)
1084 int regnum = atoi (argv[i]);
1086 if (regnum >= 0 && regnum < numregs
1087 && gdbarch_register_name (gdbarch, regnum)
1088 && *gdbarch_register_name (gdbarch, regnum))
1092 /* Get the value as a number. */
1093 value = parse_and_eval_address (argv[i + 1]);
1095 /* Write it down. */
1096 regcache_cooked_write_signed (regcache, regnum, value);
1099 error ("bad register number");
1103 /* Evaluate the value of the argument. The argument is an
1104 expression. If the expression contains spaces it needs to be
1105 included in double quotes. */
1107 mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
1109 struct expression *expr;
1110 struct cleanup *old_chain = NULL;
1112 struct ui_stream *stb = NULL;
1113 struct value_print_options opts;
1115 stb = ui_out_stream_new (uiout);
1119 ui_out_stream_delete (stb);
1120 error ("mi_cmd_data_evaluate_expression: Usage: -data-evaluate-expression expression");
1123 expr = parse_expression (argv[0]);
1125 old_chain = make_cleanup (free_current_contents, &expr);
1127 val = evaluate_expression (expr);
1129 /* Print the result of the expression evaluation. */
1130 get_user_print_options (&opts);
1132 val_print (value_type (val), value_contents (val),
1133 value_embedded_offset (val), value_address (val),
1134 stb->stream, 0, &opts, current_language);
1136 ui_out_field_stream (uiout, "value", stb);
1137 ui_out_stream_delete (stb);
1139 do_cleanups (old_chain);
1142 /* DATA-MEMORY-READ:
1144 ADDR: start address of data to be dumped.
1145 WORD-FORMAT: a char indicating format for the ``word''. See
1147 WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes.
1148 NR_ROW: Number of rows.
1149 NR_COL: The number of colums (words per row).
1150 ASCHAR: (OPTIONAL) Append an ascii character dump to each row. Use
1151 ASCHAR for unprintable characters.
1153 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
1154 displayes them. Returns:
1156 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
1159 The number of bytes read is SIZE*ROW*COL. */
1162 mi_cmd_data_read_memory (char *command, char **argv, int argc)
1164 struct gdbarch *gdbarch = get_current_arch ();
1165 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1171 struct type *word_type;
1184 static struct mi_opt opts[] =
1186 {"o", OFFSET_OPT, 1},
1192 int opt = mi_getopt ("mi_cmd_data_read_memory", argc, argv, opts,
1196 switch ((enum opt) opt)
1199 offset = atol (optarg);
1206 if (argc < 5 || argc > 6)
1207 error ("mi_cmd_data_read_memory: Usage: ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR].");
1209 /* Extract all the arguments. */
1211 /* Start address of the memory dump. */
1212 addr = parse_and_eval_address (argv[0]) + offset;
1213 /* The format character to use when displaying a memory word. See
1214 the ``x'' command. */
1215 word_format = argv[1][0];
1216 /* The size of the memory word. */
1217 word_size = atol (argv[2]);
1221 word_type = builtin_type (gdbarch)->builtin_int8;
1225 word_type = builtin_type (gdbarch)->builtin_int16;
1229 word_type = builtin_type (gdbarch)->builtin_int32;
1233 word_type = builtin_type (gdbarch)->builtin_int64;
1237 word_type = builtin_type (gdbarch)->builtin_int8;
1240 /* The number of rows. */
1241 nr_rows = atol (argv[3]);
1243 error ("mi_cmd_data_read_memory: invalid number of rows.");
1245 /* Number of bytes per row. */
1246 nr_cols = atol (argv[4]);
1248 error ("mi_cmd_data_read_memory: invalid number of columns.");
1250 /* The un-printable character when printing ascii. */
1256 /* Create a buffer and read it in. */
1257 total_bytes = word_size * nr_rows * nr_cols;
1258 mbuf = xcalloc (total_bytes, 1);
1259 make_cleanup (xfree, mbuf);
1261 /* Dispatch memory reads to the topmost target, not the flattened
1263 nr_bytes = target_read_until_error (current_target.beneath,
1264 TARGET_OBJECT_MEMORY, NULL, mbuf,
1267 error ("Unable to read memory.");
1269 /* Output the header information. */
1270 ui_out_field_core_addr (uiout, "addr", gdbarch, addr);
1271 ui_out_field_int (uiout, "nr-bytes", nr_bytes);
1272 ui_out_field_int (uiout, "total-bytes", total_bytes);
1273 ui_out_field_core_addr (uiout, "next-row",
1274 gdbarch, addr + word_size * nr_cols);
1275 ui_out_field_core_addr (uiout, "prev-row",
1276 gdbarch, addr - word_size * nr_cols);
1277 ui_out_field_core_addr (uiout, "next-page", gdbarch, addr + total_bytes);
1278 ui_out_field_core_addr (uiout, "prev-page", gdbarch, addr - total_bytes);
1280 /* Build the result as a two dimentional table. */
1282 struct ui_stream *stream = ui_out_stream_new (uiout);
1283 struct cleanup *cleanup_list_memory;
1286 cleanup_list_memory = make_cleanup_ui_out_list_begin_end (uiout, "memory");
1287 for (row = 0, row_byte = 0;
1289 row++, row_byte += nr_cols * word_size)
1293 struct cleanup *cleanup_tuple;
1294 struct cleanup *cleanup_list_data;
1295 struct value_print_options opts;
1297 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1298 ui_out_field_core_addr (uiout, "addr", gdbarch, addr + row_byte);
1299 /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr + row_byte); */
1300 cleanup_list_data = make_cleanup_ui_out_list_begin_end (uiout, "data");
1301 get_formatted_print_options (&opts, word_format);
1302 for (col = 0, col_byte = row_byte;
1304 col++, col_byte += word_size)
1306 if (col_byte + word_size > nr_bytes)
1308 ui_out_field_string (uiout, NULL, "N/A");
1312 ui_file_rewind (stream->stream);
1313 print_scalar_formatted (mbuf + col_byte, word_type, &opts,
1314 word_asize, stream->stream);
1315 ui_out_field_stream (uiout, NULL, stream);
1318 do_cleanups (cleanup_list_data);
1322 ui_file_rewind (stream->stream);
1323 for (byte = row_byte; byte < row_byte + word_size * nr_cols; byte++)
1325 if (byte >= nr_bytes)
1327 fputc_unfiltered ('X', stream->stream);
1329 else if (mbuf[byte] < 32 || mbuf[byte] > 126)
1331 fputc_unfiltered (aschar, stream->stream);
1334 fputc_unfiltered (mbuf[byte], stream->stream);
1336 ui_out_field_stream (uiout, "ascii", stream);
1338 do_cleanups (cleanup_tuple);
1340 ui_out_stream_delete (stream);
1341 do_cleanups (cleanup_list_memory);
1343 do_cleanups (cleanups);
1346 /* DATA-MEMORY-WRITE:
1348 COLUMN_OFFSET: optional argument. Must be preceeded by '-o'. The
1349 offset from the beginning of the memory grid row where the cell to
1351 ADDR: start address of the row in the memory grid where the memory
1352 cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
1353 the location to write to.
1354 FORMAT: a char indicating format for the ``word''. See
1356 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
1357 VALUE: value to be written into the memory address.
1359 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
1363 mi_cmd_data_write_memory (char *command, char **argv, int argc)
1365 struct gdbarch *gdbarch = get_current_arch ();
1366 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1370 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
1371 enough when using a compiler other than GCC. */
1374 struct cleanup *old_chain;
1382 static struct mi_opt opts[] =
1384 {"o", OFFSET_OPT, 1},
1390 int opt = mi_getopt ("mi_cmd_data_write_memory", argc, argv, opts,
1394 switch ((enum opt) opt)
1397 offset = atol (optarg);
1405 error ("mi_cmd_data_write_memory: Usage: [-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE.");
1407 /* Extract all the arguments. */
1408 /* Start address of the memory dump. */
1409 addr = parse_and_eval_address (argv[0]);
1410 /* The format character to use when displaying a memory word. See
1411 the ``x'' command. */
1412 word_format = argv[1][0];
1413 /* The size of the memory word. */
1414 word_size = atol (argv[2]);
1416 /* Calculate the real address of the write destination. */
1417 addr += (offset * word_size);
1419 /* Get the value as a number. */
1420 value = parse_and_eval_address (argv[3]);
1421 /* Get the value into an array. */
1422 buffer = xmalloc (word_size);
1423 old_chain = make_cleanup (xfree, buffer);
1424 store_signed_integer (buffer, word_size, byte_order, value);
1425 /* Write it down to memory. */
1426 write_memory (addr, buffer, word_size);
1427 /* Free the buffer. */
1428 do_cleanups (old_chain);
1432 mi_cmd_enable_timings (char *command, char **argv, int argc)
1438 if (strcmp (argv[0], "yes") == 0)
1440 else if (strcmp (argv[0], "no") == 0)
1451 error ("mi_cmd_enable_timings: Usage: %s {yes|no}", command);
1455 mi_cmd_list_features (char *command, char **argv, int argc)
1459 struct cleanup *cleanup = NULL;
1460 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1462 ui_out_field_string (uiout, NULL, "frozen-varobjs");
1463 ui_out_field_string (uiout, NULL, "pending-breakpoints");
1464 ui_out_field_string (uiout, NULL, "thread-info");
1467 ui_out_field_string (uiout, NULL, "python");
1470 do_cleanups (cleanup);
1474 error ("-list-features should be passed no arguments");
1478 mi_cmd_list_target_features (char *command, char **argv, int argc)
1482 struct cleanup *cleanup = NULL;
1483 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1485 if (target_can_async_p ())
1486 ui_out_field_string (uiout, NULL, "async");
1488 do_cleanups (cleanup);
1492 error ("-list-target-features should be passed no arguments");
1495 /* Execute a command within a safe environment.
1496 Return <0 for error; >=0 for ok.
1498 args->action will tell mi_execute_command what action
1499 to perfrom after the given command has executed (display/suppress
1500 prompt, display error). */
1503 captured_mi_execute_command (struct ui_out *uiout, void *data)
1505 struct cleanup *cleanup;
1506 struct mi_parse *context = (struct mi_parse *) data;
1509 current_command_ts = context->cmd_start;
1511 current_token = xstrdup (context->token);
1512 cleanup = make_cleanup (free_current_contents, ¤t_token);
1514 running_result_record_printed = 0;
1516 switch (context->op)
1519 /* A MI command was read from the input stream. */
1521 /* FIXME: gdb_???? */
1522 fprintf_unfiltered (raw_stdout, " token=`%s' command=`%s' args=`%s'\n",
1523 context->token, context->command, context->args);
1526 mi_cmd_execute (context);
1528 /* Print the result if there were no errors.
1530 Remember that on the way out of executing a command, you have
1531 to directly use the mi_interp's uiout, since the command could
1532 have reset the interpreter, in which case the current uiout
1533 will most likely crash in the mi_out_* routines. */
1534 if (!running_result_record_printed)
1536 fputs_unfiltered (context->token, raw_stdout);
1537 /* There's no particularly good reason why target-connect results
1538 in not ^done. Should kill ^connected for MI3. */
1539 fputs_unfiltered (strcmp (context->command, "target-select") == 0
1540 ? "^connected" : "^done", raw_stdout);
1541 mi_out_put (uiout, raw_stdout);
1542 mi_out_rewind (uiout);
1543 mi_print_timing_maybe ();
1544 fputs_unfiltered ("\n", raw_stdout);
1547 /* The command does not want anything to be printed. In that
1548 case, the command probably should not have written anything
1549 to uiout, but in case it has written something, discard it. */
1550 mi_out_rewind (uiout);
1556 /* A CLI command was read from the input stream. */
1557 /* This "feature" will be removed as soon as we have a
1558 complete set of mi commands. */
1559 /* Echo the command on the console. */
1560 fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
1561 /* Call the "console" interpreter. */
1562 argv[0] = "console";
1563 argv[1] = context->command;
1564 mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
1566 /* If we changed interpreters, DON'T print out anything. */
1567 if (current_interp_named_p (INTERP_MI)
1568 || current_interp_named_p (INTERP_MI1)
1569 || current_interp_named_p (INTERP_MI2)
1570 || current_interp_named_p (INTERP_MI3))
1572 if (!running_result_record_printed)
1574 fputs_unfiltered (context->token, raw_stdout);
1575 fputs_unfiltered ("^done", raw_stdout);
1576 mi_out_put (uiout, raw_stdout);
1577 mi_out_rewind (uiout);
1578 mi_print_timing_maybe ();
1579 fputs_unfiltered ("\n", raw_stdout);
1582 mi_out_rewind (uiout);
1589 do_cleanups (cleanup);
1596 mi_execute_command (char *cmd, int from_tty)
1598 struct mi_parse *command;
1599 struct ui_out *saved_uiout = uiout;
1601 /* This is to handle EOF (^D). We just quit gdb. */
1602 /* FIXME: we should call some API function here. */
1604 quit_force (NULL, from_tty);
1606 target_log_command (cmd);
1608 command = mi_parse (cmd);
1610 if (command != NULL)
1612 struct gdb_exception result;
1613 ptid_t previous_ptid = inferior_ptid;
1617 command->cmd_start = (struct mi_timestamp *)
1618 xmalloc (sizeof (struct mi_timestamp));
1619 timestamp (command->cmd_start);
1622 result = catch_exception (uiout, captured_mi_execute_command, command,
1624 if (result.reason < 0)
1626 /* The command execution failed and error() was called
1628 fputs_unfiltered (command->token, raw_stdout);
1629 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1630 if (result.message == NULL)
1631 fputs_unfiltered ("unknown error", raw_stdout);
1633 fputstr_unfiltered (result.message, '"', raw_stdout);
1634 fputs_unfiltered ("\"\n", raw_stdout);
1635 mi_out_rewind (uiout);
1638 bpstat_do_actions ();
1640 if (/* The notifications are only output when the top-level
1641 interpreter (specified on the command line) is MI. */
1642 ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ()))
1643 /* Don't try report anything if there are no threads --
1644 the program is dead. */
1645 && thread_count () != 0
1646 /* -thread-select explicitly changes thread. If frontend uses that
1647 internally, we don't want to emit =thread-selected, since
1648 =thread-selected is supposed to indicate user's intentions. */
1649 && strcmp (command->command, "thread-select") != 0)
1651 struct mi_interp *mi = top_level_interpreter_data ();
1652 int report_change = 0;
1654 if (command->thread == -1)
1656 report_change = (!ptid_equal (previous_ptid, null_ptid)
1657 && !ptid_equal (inferior_ptid, previous_ptid)
1658 && !ptid_equal (inferior_ptid, null_ptid));
1660 else if (!ptid_equal (inferior_ptid, null_ptid))
1662 struct thread_info *ti = inferior_thread ();
1663 report_change = (ti->num != command->thread);
1668 struct thread_info *ti = inferior_thread ();
1669 target_terminal_ours ();
1670 fprintf_unfiltered (mi->event_channel,
1671 "thread-selected,id=\"%d\"",
1673 gdb_flush (mi->event_channel);
1677 mi_parse_free (command);
1680 fputs_unfiltered ("(gdb) \n", raw_stdout);
1681 gdb_flush (raw_stdout);
1682 /* Print any buffered hook code. */
1687 mi_cmd_execute (struct mi_parse *parse)
1689 struct cleanup *cleanup;
1692 prepare_execute_command ();
1694 cleanup = make_cleanup (null_cleanup, NULL);
1696 if (parse->frame != -1 && parse->thread == -1)
1697 error (_("Cannot specify --frame without --thread"));
1699 if (parse->thread != -1)
1701 struct thread_info *tp = find_thread_id (parse->thread);
1703 error (_("Invalid thread id: %d"), parse->thread);
1705 if (is_exited (tp->ptid))
1706 error (_("Thread id: %d has terminated"), parse->thread);
1708 switch_to_thread (tp->ptid);
1711 if (parse->frame != -1)
1713 struct frame_info *fid;
1714 int frame = parse->frame;
1715 fid = find_relative_frame (get_current_frame (), &frame);
1717 /* find_relative_frame was successful */
1720 error (_("Invalid frame id: %d"), frame);
1723 if (parse->cmd->argv_func != NULL)
1724 parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
1725 else if (parse->cmd->cli.cmd != 0)
1727 /* FIXME: DELETE THIS. */
1728 /* The operation is still implemented by a cli command. */
1729 /* Must be a synchronous one. */
1730 mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
1735 /* FIXME: DELETE THIS. */
1736 struct ui_file *stb;
1738 stb = mem_fileopen ();
1740 fputs_unfiltered ("Undefined mi command: ", stb);
1741 fputstr_unfiltered (parse->command, '"', stb);
1742 fputs_unfiltered (" (missing implementation)", stb);
1744 make_cleanup_ui_file_delete (stb);
1747 do_cleanups (cleanup);
1750 /* FIXME: This is just a hack so we can get some extra commands going.
1751 We don't want to channel things through the CLI, but call libgdb directly.
1752 Use only for synchronous commands. */
1755 mi_execute_cli_command (const char *cmd, int args_p, const char *args)
1759 struct cleanup *old_cleanups;
1762 run = xstrprintf ("%s %s", cmd, args);
1764 run = xstrdup (cmd);
1766 /* FIXME: gdb_???? */
1767 fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
1769 old_cleanups = make_cleanup (xfree, run);
1770 execute_command ( /*ui */ run, 0 /*from_tty */ );
1771 do_cleanups (old_cleanups);
1777 mi_execute_async_cli_command (char *cli_command, char **argv, int argc)
1779 struct cleanup *old_cleanups;
1782 if (target_can_async_p ())
1783 run = xstrprintf ("%s %s&", cli_command, argc ? *argv : "");
1785 run = xstrprintf ("%s %s", cli_command, argc ? *argv : "");
1786 old_cleanups = make_cleanup (xfree, run);
1788 execute_command ( /*ui */ run, 0 /*from_tty */ );
1790 if (target_can_async_p ())
1792 /* If we're not executing, an exception should have been throw. */
1793 gdb_assert (is_running (inferior_ptid));
1794 do_cleanups (old_cleanups);
1798 /* Do this before doing any printing. It would appear that some
1799 print code leaves garbage around in the buffer. */
1800 do_cleanups (old_cleanups);
1805 mi_load_progress (const char *section_name,
1806 unsigned long sent_so_far,
1807 unsigned long total_section,
1808 unsigned long total_sent,
1809 unsigned long grand_total)
1811 struct timeval time_now, delta, update_threshold;
1812 static struct timeval last_update;
1813 static char *previous_sect_name = NULL;
1815 struct ui_out *saved_uiout;
1817 /* This function is called through deprecated_show_load_progress
1818 which means uiout may not be correct. Fix it for the duration
1819 of this function. */
1820 saved_uiout = uiout;
1822 if (current_interp_named_p (INTERP_MI)
1823 || current_interp_named_p (INTERP_MI2))
1824 uiout = mi_out_new (2);
1825 else if (current_interp_named_p (INTERP_MI1))
1826 uiout = mi_out_new (1);
1827 else if (current_interp_named_p (INTERP_MI3))
1828 uiout = mi_out_new (3);
1832 update_threshold.tv_sec = 0;
1833 update_threshold.tv_usec = 500000;
1834 gettimeofday (&time_now, NULL);
1836 delta.tv_usec = time_now.tv_usec - last_update.tv_usec;
1837 delta.tv_sec = time_now.tv_sec - last_update.tv_sec;
1839 if (delta.tv_usec < 0)
1842 delta.tv_usec += 1000000L;
1845 new_section = (previous_sect_name ?
1846 strcmp (previous_sect_name, section_name) : 1);
1849 struct cleanup *cleanup_tuple;
1850 xfree (previous_sect_name);
1851 previous_sect_name = xstrdup (section_name);
1854 fputs_unfiltered (current_token, raw_stdout);
1855 fputs_unfiltered ("+download", raw_stdout);
1856 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1857 ui_out_field_string (uiout, "section", section_name);
1858 ui_out_field_int (uiout, "section-size", total_section);
1859 ui_out_field_int (uiout, "total-size", grand_total);
1860 do_cleanups (cleanup_tuple);
1861 mi_out_put (uiout, raw_stdout);
1862 fputs_unfiltered ("\n", raw_stdout);
1863 gdb_flush (raw_stdout);
1866 if (delta.tv_sec >= update_threshold.tv_sec &&
1867 delta.tv_usec >= update_threshold.tv_usec)
1869 struct cleanup *cleanup_tuple;
1870 last_update.tv_sec = time_now.tv_sec;
1871 last_update.tv_usec = time_now.tv_usec;
1873 fputs_unfiltered (current_token, raw_stdout);
1874 fputs_unfiltered ("+download", raw_stdout);
1875 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1876 ui_out_field_string (uiout, "section", section_name);
1877 ui_out_field_int (uiout, "section-sent", sent_so_far);
1878 ui_out_field_int (uiout, "section-size", total_section);
1879 ui_out_field_int (uiout, "total-sent", total_sent);
1880 ui_out_field_int (uiout, "total-size", grand_total);
1881 do_cleanups (cleanup_tuple);
1882 mi_out_put (uiout, raw_stdout);
1883 fputs_unfiltered ("\n", raw_stdout);
1884 gdb_flush (raw_stdout);
1888 uiout = saved_uiout;
1892 timestamp (struct mi_timestamp *tv)
1895 gettimeofday (&tv->wallclock, NULL);
1896 #ifdef HAVE_GETRUSAGE
1897 getrusage (RUSAGE_SELF, &rusage);
1898 tv->utime.tv_sec = rusage.ru_utime.tv_sec;
1899 tv->utime.tv_usec = rusage.ru_utime.tv_usec;
1900 tv->stime.tv_sec = rusage.ru_stime.tv_sec;
1901 tv->stime.tv_usec = rusage.ru_stime.tv_usec;
1903 usec = get_run_time ();
1904 tv->utime.tv_sec = usec/1000000L;
1905 tv->utime.tv_usec = usec - 1000000L*tv->utime.tv_sec;
1906 tv->stime.tv_sec = 0;
1907 tv->stime.tv_usec = 0;
1912 print_diff_now (struct mi_timestamp *start)
1914 struct mi_timestamp now;
1916 print_diff (start, &now);
1920 mi_print_timing_maybe (void)
1922 /* If the command is -enable-timing then do_timings may be
1923 true whilst current_command_ts is not initialized. */
1924 if (do_timings && current_command_ts)
1925 print_diff_now (current_command_ts);
1929 timeval_diff (struct timeval start, struct timeval end)
1931 return ((end.tv_sec - start.tv_sec) * 1000000L)
1932 + (end.tv_usec - start.tv_usec);
1936 print_diff (struct mi_timestamp *start, struct mi_timestamp *end)
1940 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
1941 timeval_diff (start->wallclock, end->wallclock) / 1000000.0,
1942 timeval_diff (start->utime, end->utime) / 1000000.0,
1943 timeval_diff (start->stime, end->stime) / 1000000.0);