3 Copyright (C) 2000-2017 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions (a Red Hat company).
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "gdbthread.h"
31 #include "mi-getopt.h"
32 #include "mi-console.h"
36 #include "event-loop.h"
37 #include "event-top.h"
38 #include "gdbcore.h" /* For write_memory(). */
44 #include "mi-common.h"
49 #include "splay-tree.h"
50 #include "tracepoint.h"
54 #include "extension.h"
59 #include "run-time-clock.h"
69 /* This is used to pass the current command timestamp down to
70 continuation routines. */
71 static struct mi_timestamp
*current_command_ts
;
73 static int do_timings
= 0;
76 /* Few commands would like to know if options like --thread-group were
77 explicitly specified. This variable keeps the current parsed
78 command including all option, and make it possible. */
79 static struct mi_parse
*current_context
;
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 output_register (struct frame_info
*, int regnum
, int format
,
97 int skip_unavailable
);
99 /* Controls whether the frontend wants MI in async mode. */
100 static int mi_async
= 0;
102 /* The set command writes to this variable. If the inferior is
103 executing, mi_async is *not* updated. */
104 static int mi_async_1
= 0;
107 set_mi_async_command (char *args
, int from_tty
,
108 struct cmd_list_element
*c
)
110 if (have_live_inferiors ())
112 mi_async_1
= mi_async
;
113 error (_("Cannot change this setting while the inferior is running."));
116 mi_async
= mi_async_1
;
120 show_mi_async_command (struct ui_file
*file
, int from_tty
,
121 struct cmd_list_element
*c
,
124 fprintf_filtered (file
,
125 _("Whether MI is in asynchronous mode is %s.\n"),
129 /* A wrapper for target_can_async_p that takes the MI setting into
135 return mi_async
&& target_can_async_p ();
138 /* Command implementations. FIXME: Is this libgdb? No. This is the MI
139 layer that calls libgdb. Any operation used in the below should be
142 static void timestamp (struct mi_timestamp
*tv
);
144 static void print_diff (struct ui_file
*file
, struct mi_timestamp
*start
,
145 struct mi_timestamp
*end
);
148 mi_cmd_gdb_exit (char *command
, char **argv
, int argc
)
151 = (struct mi_interp
*) interp_data (current_interpreter ());
153 /* We have to print everything right here because we never return. */
155 fputs_unfiltered (current_token
, mi
->raw_stdout
);
156 fputs_unfiltered ("^exit\n", mi
->raw_stdout
);
157 mi_out_put (current_uiout
, mi
->raw_stdout
);
158 gdb_flush (mi
->raw_stdout
);
159 /* FIXME: The function called is not yet a formal libgdb function. */
160 quit_force (NULL
, FROM_TTY
);
164 mi_cmd_exec_next (char *command
, char **argv
, int argc
)
166 /* FIXME: Should call a libgdb function, not a cli wrapper. */
167 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
168 mi_execute_async_cli_command ("reverse-next", argv
+ 1, argc
- 1);
170 mi_execute_async_cli_command ("next", argv
, argc
);
174 mi_cmd_exec_next_instruction (char *command
, char **argv
, int argc
)
176 /* FIXME: Should call a libgdb function, not a cli wrapper. */
177 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
178 mi_execute_async_cli_command ("reverse-nexti", argv
+ 1, argc
- 1);
180 mi_execute_async_cli_command ("nexti", argv
, argc
);
184 mi_cmd_exec_step (char *command
, char **argv
, int argc
)
186 /* FIXME: Should call a libgdb function, not a cli wrapper. */
187 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
188 mi_execute_async_cli_command ("reverse-step", argv
+ 1, argc
- 1);
190 mi_execute_async_cli_command ("step", argv
, argc
);
194 mi_cmd_exec_step_instruction (char *command
, char **argv
, int argc
)
196 /* FIXME: Should call a libgdb function, not a cli wrapper. */
197 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
198 mi_execute_async_cli_command ("reverse-stepi", argv
+ 1, argc
- 1);
200 mi_execute_async_cli_command ("stepi", argv
, argc
);
204 mi_cmd_exec_finish (char *command
, char **argv
, int argc
)
206 /* FIXME: Should call a libgdb function, not a cli wrapper. */
207 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
208 mi_execute_async_cli_command ("reverse-finish", argv
+ 1, argc
- 1);
210 mi_execute_async_cli_command ("finish", argv
, argc
);
214 mi_cmd_exec_return (char *command
, char **argv
, int argc
)
216 /* This command doesn't really execute the target, it just pops the
217 specified number of frames. */
219 /* Call return_command with from_tty argument equal to 0 so as to
220 avoid being queried. */
221 return_command (*argv
, 0);
223 /* Call return_command with from_tty argument equal to 0 so as to
224 avoid being queried. */
225 return_command (NULL
, 0);
227 /* Because we have called return_command with from_tty = 0, we need
228 to print the frame here. */
229 print_stack_frame (get_selected_frame (NULL
), 1, LOC_AND_ADDRESS
, 1);
233 mi_cmd_exec_jump (char *args
, char **argv
, int argc
)
235 /* FIXME: Should call a libgdb function, not a cli wrapper. */
236 mi_execute_async_cli_command ("jump", argv
, argc
);
240 proceed_thread (struct thread_info
*thread
, int pid
)
242 if (!is_stopped (thread
->ptid
))
245 if (pid
!= 0 && ptid_get_pid (thread
->ptid
) != pid
)
248 switch_to_thread (thread
->ptid
);
249 clear_proceed_status (0);
250 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
254 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
256 int pid
= *(int *)arg
;
258 proceed_thread (thread
, pid
);
263 exec_continue (char **argv
, int argc
)
265 prepare_execution_command (¤t_target
, mi_async_p ());
269 /* In non-stop mode, 'resume' always resumes a single thread.
270 Therefore, to resume all threads of the current inferior, or
271 all threads in all inferiors, we need to iterate over
274 See comment on infcmd.c:proceed_thread_callback for rationale. */
275 if (current_context
->all
|| current_context
->thread_group
!= -1)
278 struct cleanup
*back_to
= make_cleanup_restore_current_thread ();
280 if (!current_context
->all
)
283 = find_inferior_id (current_context
->thread_group
);
287 iterate_over_threads (proceed_thread_callback
, &pid
);
288 do_cleanups (back_to
);
297 scoped_restore save_multi
= make_scoped_restore (&sched_multi
);
299 if (current_context
->all
)
306 /* In all-stop mode, -exec-continue traditionally resumed
307 either all threads, or one thread, depending on the
308 'scheduler-locking' variable. Let's continue to do the
316 exec_direction_forward (void *notused
)
318 execution_direction
= EXEC_FORWARD
;
322 exec_reverse_continue (char **argv
, int argc
)
324 enum exec_direction_kind dir
= execution_direction
;
325 struct cleanup
*old_chain
;
327 if (dir
== EXEC_REVERSE
)
328 error (_("Already in reverse mode."));
330 if (!target_can_execute_reverse
)
331 error (_("Target %s does not support this command."), target_shortname
);
333 old_chain
= make_cleanup (exec_direction_forward
, NULL
);
334 execution_direction
= EXEC_REVERSE
;
335 exec_continue (argv
, argc
);
336 do_cleanups (old_chain
);
340 mi_cmd_exec_continue (char *command
, char **argv
, int argc
)
342 if (argc
> 0 && strcmp (argv
[0], "--reverse") == 0)
343 exec_reverse_continue (argv
+ 1, argc
- 1);
345 exec_continue (argv
, argc
);
349 interrupt_thread_callback (struct thread_info
*thread
, void *arg
)
351 int pid
= *(int *)arg
;
353 if (!is_running (thread
->ptid
))
356 if (ptid_get_pid (thread
->ptid
) != pid
)
359 target_stop (thread
->ptid
);
363 /* Interrupt the execution of the target. Note how we must play
364 around with the token variables, in order to display the current
365 token in the result of the interrupt command, and the previous
366 execution token when the target finally stops. See comments in
370 mi_cmd_exec_interrupt (char *command
, char **argv
, int argc
)
372 /* In all-stop mode, everything stops, so we don't need to try
373 anything specific. */
376 interrupt_target_1 (0);
380 if (current_context
->all
)
382 /* This will interrupt all threads in all inferiors. */
383 interrupt_target_1 (1);
385 else if (current_context
->thread_group
!= -1)
387 struct inferior
*inf
= find_inferior_id (current_context
->thread_group
);
389 iterate_over_threads (interrupt_thread_callback
, &inf
->pid
);
393 /* Interrupt just the current thread -- either explicitly
394 specified via --thread or whatever was current before
395 MI command was sent. */
396 interrupt_target_1 (0);
400 /* Callback for iterate_over_inferiors which starts the execution
401 of the given inferior.
403 ARG is a pointer to an integer whose value, if non-zero, indicates
404 that the program should be stopped when reaching the main subprogram
405 (similar to what the CLI "start" command does). */
408 run_one_inferior (struct inferior
*inf
, void *arg
)
410 int start_p
= *(int *) arg
;
411 const char *run_cmd
= start_p
? "start" : "run";
412 struct target_ops
*run_target
= find_run_target ();
413 int async_p
= mi_async
&& run_target
->to_can_async_p (run_target
);
417 if (inf
->pid
!= ptid_get_pid (inferior_ptid
))
419 struct thread_info
*tp
;
421 tp
= any_thread_of_process (inf
->pid
);
423 error (_("Inferior has no threads."));
425 switch_to_thread (tp
->ptid
);
430 set_current_inferior (inf
);
431 switch_to_thread (null_ptid
);
432 set_current_program_space (inf
->pspace
);
434 mi_execute_cli_command (run_cmd
, async_p
,
435 async_p
? "&" : NULL
);
440 mi_cmd_exec_run (char *command
, char **argv
, int argc
)
444 /* Parse the command options. */
449 static const struct mi_opt opts
[] =
451 {"-start", START_OPT
, 0},
460 int opt
= mi_getopt ("-exec-run", argc
, argv
, opts
, &oind
, &oarg
);
464 switch ((enum opt
) opt
)
472 /* This command does not accept any argument. Make sure the user
473 did not provide any. */
475 error (_("Invalid argument: %s"), argv
[oind
]);
477 if (current_context
->all
)
479 struct cleanup
*back_to
= save_current_space_and_thread ();
481 iterate_over_inferiors (run_one_inferior
, &start_p
);
482 do_cleanups (back_to
);
486 const char *run_cmd
= start_p
? "start" : "run";
487 struct target_ops
*run_target
= find_run_target ();
488 int async_p
= mi_async
&& run_target
->to_can_async_p (run_target
);
490 mi_execute_cli_command (run_cmd
, async_p
,
491 async_p
? "&" : NULL
);
497 find_thread_of_process (struct thread_info
*ti
, void *p
)
501 if (ptid_get_pid (ti
->ptid
) == pid
&& !is_exited (ti
->ptid
))
508 mi_cmd_target_detach (char *command
, char **argv
, int argc
)
510 if (argc
!= 0 && argc
!= 1)
511 error (_("Usage: -target-detach [pid | thread-group]"));
515 struct thread_info
*tp
;
519 /* First see if we are dealing with a thread-group id. */
522 struct inferior
*inf
;
523 int id
= strtoul (argv
[0] + 1, &end
, 0);
526 error (_("Invalid syntax of thread-group id '%s'"), argv
[0]);
528 inf
= find_inferior_id (id
);
530 error (_("Non-existent thread-group id '%d'"), id
);
536 /* We must be dealing with a pid. */
537 pid
= strtol (argv
[0], &end
, 10);
540 error (_("Invalid identifier '%s'"), argv
[0]);
543 /* Pick any thread in the desired process. Current
544 target_detach detaches from the parent of inferior_ptid. */
545 tp
= iterate_over_threads (find_thread_of_process
, &pid
);
547 error (_("Thread group is empty"));
549 switch_to_thread (tp
->ptid
);
552 detach_command (NULL
, 0);
556 mi_cmd_target_flash_erase (char *command
, char **argv
, int argc
)
558 flash_erase_command (NULL
, 0);
562 mi_cmd_thread_select (char *command
, char **argv
, int argc
)
565 char *mi_error_message
;
566 ptid_t previous_ptid
= inferior_ptid
;
569 error (_("-thread-select: USAGE: threadnum."));
571 rc
= gdb_thread_select (current_uiout
, argv
[0], &mi_error_message
);
573 /* If thread switch did not succeed don't notify or print. */
574 if (rc
== GDB_RC_FAIL
)
576 make_cleanup (xfree
, mi_error_message
);
577 error ("%s", mi_error_message
);
580 print_selected_thread_frame (current_uiout
,
581 USER_SELECTED_THREAD
| USER_SELECTED_FRAME
);
583 /* Notify if the thread has effectively changed. */
584 if (!ptid_equal (inferior_ptid
, previous_ptid
))
586 observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
587 | USER_SELECTED_FRAME
);
592 mi_cmd_thread_list_ids (char *command
, char **argv
, int argc
)
595 char *mi_error_message
;
598 error (_("-thread-list-ids: No arguments required."));
600 rc
= gdb_list_thread_ids (current_uiout
, &mi_error_message
);
602 if (rc
== GDB_RC_FAIL
)
604 make_cleanup (xfree
, mi_error_message
);
605 error ("%s", mi_error_message
);
610 mi_cmd_thread_info (char *command
, char **argv
, int argc
)
612 if (argc
!= 0 && argc
!= 1)
613 error (_("Invalid MI command"));
615 print_thread_info (current_uiout
, argv
[0], -1);
618 struct collect_cores_data
626 collect_cores (struct thread_info
*ti
, void *xdata
)
628 struct collect_cores_data
*data
= (struct collect_cores_data
*) xdata
;
630 if (ptid_get_pid (ti
->ptid
) == data
->pid
)
632 int core
= target_core_of_thread (ti
->ptid
);
635 VEC_safe_push (int, data
->cores
, core
);
642 unique (int *b
, int *e
)
652 struct print_one_inferior_data
655 VEC (int) *inferiors
;
659 print_one_inferior (struct inferior
*inferior
, void *xdata
)
661 struct print_one_inferior_data
*top_data
662 = (struct print_one_inferior_data
*) xdata
;
663 struct ui_out
*uiout
= current_uiout
;
665 if (VEC_empty (int, top_data
->inferiors
)
666 || bsearch (&(inferior
->pid
), VEC_address (int, top_data
->inferiors
),
667 VEC_length (int, top_data
->inferiors
), sizeof (int),
668 compare_positive_ints
))
670 struct collect_cores_data data
;
671 struct cleanup
*back_to
672 = make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
674 uiout
->field_fmt ("id", "i%d", inferior
->num
);
675 uiout
->field_string ("type", "process");
676 if (inferior
->has_exit_code
)
677 uiout
->field_string ("exit-code",
678 int_string (inferior
->exit_code
, 8, 0, 0, 1));
679 if (inferior
->pid
!= 0)
680 uiout
->field_int ("pid", inferior
->pid
);
682 if (inferior
->pspace
->pspace_exec_filename
!= NULL
)
684 uiout
->field_string ("executable",
685 inferior
->pspace
->pspace_exec_filename
);
689 if (inferior
->pid
!= 0)
691 data
.pid
= inferior
->pid
;
692 iterate_over_threads (collect_cores
, &data
);
695 if (!VEC_empty (int, data
.cores
))
698 struct cleanup
*back_to_2
=
699 make_cleanup_ui_out_list_begin_end (uiout
, "cores");
701 qsort (VEC_address (int, data
.cores
),
702 VEC_length (int, data
.cores
), sizeof (int),
703 compare_positive_ints
);
705 b
= VEC_address (int, data
.cores
);
706 e
= b
+ VEC_length (int, data
.cores
);
710 uiout
->field_int (NULL
, *b
);
712 do_cleanups (back_to_2
);
715 if (top_data
->recurse
)
716 print_thread_info (uiout
, NULL
, inferior
->pid
);
718 do_cleanups (back_to
);
724 /* Output a field named 'cores' with a list as the value. The
725 elements of the list are obtained by splitting 'cores' on
729 output_cores (struct ui_out
*uiout
, const char *field_name
, const char *xcores
)
731 struct cleanup
*back_to
= make_cleanup_ui_out_list_begin_end (uiout
,
733 char *cores
= xstrdup (xcores
);
736 make_cleanup (xfree
, cores
);
738 for (p
= strtok (p
, ","); p
; p
= strtok (NULL
, ","))
739 uiout
->field_string (NULL
, p
);
741 do_cleanups (back_to
);
745 free_vector_of_ints (void *xvector
)
747 VEC (int) **vector
= (VEC (int) **) xvector
;
749 VEC_free (int, *vector
);
753 do_nothing (splay_tree_key k
)
758 free_vector_of_osdata_items (splay_tree_value xvalue
)
760 VEC (osdata_item_s
) *value
= (VEC (osdata_item_s
) *) xvalue
;
762 /* We don't free the items itself, it will be done separately. */
763 VEC_free (osdata_item_s
, value
);
767 splay_tree_int_comparator (splay_tree_key xa
, splay_tree_key xb
)
776 free_splay_tree (void *xt
)
778 splay_tree t
= (splay_tree
) xt
;
779 splay_tree_delete (t
);
783 list_available_thread_groups (VEC (int) *ids
, int recurse
)
786 struct osdata_item
*item
;
788 struct ui_out
*uiout
= current_uiout
;
789 struct cleanup
*cleanup
;
791 /* This keeps a map from integer (pid) to VEC (struct osdata_item *)*
792 The vector contains information about all threads for the given pid.
793 This is assigned an initial value to avoid "may be used uninitialized"
795 splay_tree tree
= NULL
;
797 /* get_osdata will throw if it cannot return data. */
798 data
= get_osdata ("processes");
799 cleanup
= make_cleanup_osdata_free (data
);
803 struct osdata
*threads
= get_osdata ("threads");
805 make_cleanup_osdata_free (threads
);
806 tree
= splay_tree_new (splay_tree_int_comparator
,
808 free_vector_of_osdata_items
);
809 make_cleanup (free_splay_tree
, tree
);
812 VEC_iterate (osdata_item_s
, threads
->items
,
816 const char *pid
= get_osdata_column (item
, "pid");
817 int pid_i
= strtoul (pid
, NULL
, 0);
818 VEC (osdata_item_s
) *vec
= 0;
820 splay_tree_node n
= splay_tree_lookup (tree
, pid_i
);
823 VEC_safe_push (osdata_item_s
, vec
, item
);
824 splay_tree_insert (tree
, pid_i
, (splay_tree_value
)vec
);
828 vec
= (VEC (osdata_item_s
) *) n
->value
;
829 VEC_safe_push (osdata_item_s
, vec
, item
);
830 n
->value
= (splay_tree_value
) vec
;
835 make_cleanup_ui_out_list_begin_end (uiout
, "groups");
838 VEC_iterate (osdata_item_s
, data
->items
,
842 struct cleanup
*back_to
;
844 const char *pid
= get_osdata_column (item
, "pid");
845 const char *cmd
= get_osdata_column (item
, "command");
846 const char *user
= get_osdata_column (item
, "user");
847 const char *cores
= get_osdata_column (item
, "cores");
849 int pid_i
= strtoul (pid
, NULL
, 0);
851 /* At present, the target will return all available processes
852 and if information about specific ones was required, we filter
853 undesired processes here. */
854 if (ids
&& bsearch (&pid_i
, VEC_address (int, ids
),
855 VEC_length (int, ids
),
856 sizeof (int), compare_positive_ints
) == NULL
)
860 back_to
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
862 uiout
->field_fmt ("id", "%s", pid
);
863 uiout
->field_string ("type", "process");
865 uiout
->field_string ("description", cmd
);
867 uiout
->field_string ("user", user
);
869 output_cores (uiout
, "cores", cores
);
873 splay_tree_node n
= splay_tree_lookup (tree
, pid_i
);
876 VEC (osdata_item_s
) *children
= (VEC (osdata_item_s
) *) n
->value
;
877 struct osdata_item
*child
;
880 make_cleanup_ui_out_list_begin_end (uiout
, "threads");
883 VEC_iterate (osdata_item_s
, children
, ix_child
, child
);
886 struct cleanup
*back_to_2
=
887 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
888 const char *tid
= get_osdata_column (child
, "tid");
889 const char *tcore
= get_osdata_column (child
, "core");
891 uiout
->field_string ("id", tid
);
893 uiout
->field_string ("core", tcore
);
895 do_cleanups (back_to_2
);
900 do_cleanups (back_to
);
903 do_cleanups (cleanup
);
907 mi_cmd_list_thread_groups (char *command
, char **argv
, int argc
)
909 struct ui_out
*uiout
= current_uiout
;
910 struct cleanup
*back_to
;
917 AVAILABLE_OPT
, RECURSE_OPT
919 static const struct mi_opt opts
[] =
921 {"-available", AVAILABLE_OPT
, 0},
922 {"-recurse", RECURSE_OPT
, 1},
931 int opt
= mi_getopt ("-list-thread-groups", argc
, argv
, opts
,
936 switch ((enum opt
) opt
)
942 if (strcmp (oarg
, "0") == 0)
944 else if (strcmp (oarg
, "1") == 0)
947 error (_("only '0' and '1' are valid values "
948 "for the '--recurse' option"));
953 for (; oind
< argc
; ++oind
)
958 if (*(argv
[oind
]) != 'i')
959 error (_("invalid syntax of group id '%s'"), argv
[oind
]);
961 inf
= strtoul (argv
[oind
] + 1, &end
, 0);
964 error (_("invalid syntax of group id '%s'"), argv
[oind
]);
965 VEC_safe_push (int, ids
, inf
);
967 if (VEC_length (int, ids
) > 1)
968 qsort (VEC_address (int, ids
),
969 VEC_length (int, ids
),
970 sizeof (int), compare_positive_ints
);
972 back_to
= make_cleanup (free_vector_of_ints
, &ids
);
976 list_available_thread_groups (ids
, recurse
);
978 else if (VEC_length (int, ids
) == 1)
980 /* Local thread groups, single id. */
981 int id
= *VEC_address (int, ids
);
982 struct inferior
*inf
= find_inferior_id (id
);
985 error (_("Non-existent thread group id '%d'"), id
);
987 print_thread_info (uiout
, NULL
, inf
->pid
);
991 struct print_one_inferior_data data
;
993 data
.recurse
= recurse
;
994 data
.inferiors
= ids
;
996 /* Local thread groups. Either no explicit ids -- and we
997 print everything, or several explicit ids. In both cases,
998 we print more than one group, and have to use 'groups'
999 as the top-level element. */
1000 make_cleanup_ui_out_list_begin_end (uiout
, "groups");
1001 update_thread_list ();
1002 iterate_over_inferiors (print_one_inferior
, &data
);
1005 do_cleanups (back_to
);
1009 mi_cmd_data_list_register_names (char *command
, char **argv
, int argc
)
1011 struct gdbarch
*gdbarch
;
1012 struct ui_out
*uiout
= current_uiout
;
1013 int regnum
, numregs
;
1015 struct cleanup
*cleanup
;
1017 /* Note that the test for a valid register must include checking the
1018 gdbarch_register_name because gdbarch_num_regs may be allocated
1019 for the union of the register sets within a family of related
1020 processors. In this case, some entries of gdbarch_register_name
1021 will change depending upon the particular processor being
1024 gdbarch
= get_current_arch ();
1025 numregs
= gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
1027 cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "register-names");
1029 if (argc
== 0) /* No args, just do all the regs. */
1035 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
1036 || *(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
1037 uiout
->field_string (NULL
, "");
1039 uiout
->field_string (NULL
, gdbarch_register_name (gdbarch
, regnum
));
1043 /* Else, list of register #s, just do listed regs. */
1044 for (i
= 0; i
< argc
; i
++)
1046 regnum
= atoi (argv
[i
]);
1047 if (regnum
< 0 || regnum
>= numregs
)
1048 error (_("bad register number"));
1050 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
1051 || *(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
1052 uiout
->field_string (NULL
, "");
1054 uiout
->field_string (NULL
, gdbarch_register_name (gdbarch
, regnum
));
1056 do_cleanups (cleanup
);
1060 mi_cmd_data_list_changed_registers (char *command
, char **argv
, int argc
)
1062 static struct regcache
*this_regs
= NULL
;
1063 struct ui_out
*uiout
= current_uiout
;
1064 struct regcache
*prev_regs
;
1065 struct gdbarch
*gdbarch
;
1066 int regnum
, numregs
, changed
;
1068 struct cleanup
*cleanup
;
1070 /* The last time we visited this function, the current frame's
1071 register contents were saved in THIS_REGS. Move THIS_REGS over
1072 to PREV_REGS, and refresh THIS_REGS with the now-current register
1075 prev_regs
= this_regs
;
1076 this_regs
= frame_save_as_regcache (get_selected_frame (NULL
));
1077 cleanup
= make_cleanup_regcache_xfree (prev_regs
);
1079 /* Note that the test for a valid register must include checking the
1080 gdbarch_register_name because gdbarch_num_regs may be allocated
1081 for the union of the register sets within a family of related
1082 processors. In this case, some entries of gdbarch_register_name
1083 will change depending upon the particular processor being
1086 gdbarch
= get_regcache_arch (this_regs
);
1087 numregs
= gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
1089 make_cleanup_ui_out_list_begin_end (uiout
, "changed-registers");
1093 /* No args, just do all the regs. */
1098 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
1099 || *(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
1101 changed
= register_changed_p (regnum
, prev_regs
, this_regs
);
1103 error (_("-data-list-changed-registers: "
1104 "Unable to read register contents."));
1106 uiout
->field_int (NULL
, regnum
);
1110 /* Else, list of register #s, just do listed regs. */
1111 for (i
= 0; i
< argc
; i
++)
1113 regnum
= atoi (argv
[i
]);
1117 && gdbarch_register_name (gdbarch
, regnum
) != NULL
1118 && *gdbarch_register_name (gdbarch
, regnum
) != '\000')
1120 changed
= register_changed_p (regnum
, prev_regs
, this_regs
);
1122 error (_("-data-list-changed-registers: "
1123 "Unable to read register contents."));
1125 uiout
->field_int (NULL
, regnum
);
1128 error (_("bad register number"));
1130 do_cleanups (cleanup
);
1134 register_changed_p (int regnum
, struct regcache
*prev_regs
,
1135 struct regcache
*this_regs
)
1137 struct gdbarch
*gdbarch
= get_regcache_arch (this_regs
);
1138 gdb_byte prev_buffer
[MAX_REGISTER_SIZE
];
1139 gdb_byte this_buffer
[MAX_REGISTER_SIZE
];
1140 enum register_status prev_status
;
1141 enum register_status this_status
;
1143 /* First time through or after gdbarch change consider all registers
1145 if (!prev_regs
|| get_regcache_arch (prev_regs
) != gdbarch
)
1148 /* Get register contents and compare. */
1149 prev_status
= regcache_cooked_read (prev_regs
, regnum
, prev_buffer
);
1150 this_status
= regcache_cooked_read (this_regs
, regnum
, this_buffer
);
1152 if (this_status
!= prev_status
)
1154 else if (this_status
== REG_VALID
)
1155 return memcmp (prev_buffer
, this_buffer
,
1156 register_size (gdbarch
, regnum
)) != 0;
1161 /* Return a list of register number and value pairs. The valid
1162 arguments expected are: a letter indicating the format in which to
1163 display the registers contents. This can be one of: x
1164 (hexadecimal), d (decimal), N (natural), t (binary), o (octal), r
1165 (raw). After the format argument there can be a sequence of
1166 numbers, indicating which registers to fetch the content of. If
1167 the format is the only argument, a list of all the registers with
1168 their values is returned. */
1171 mi_cmd_data_list_register_values (char *command
, char **argv
, int argc
)
1173 struct ui_out
*uiout
= current_uiout
;
1174 struct frame_info
*frame
;
1175 struct gdbarch
*gdbarch
;
1176 int regnum
, numregs
, format
;
1178 struct cleanup
*list_cleanup
;
1179 int skip_unavailable
= 0;
1185 static const struct mi_opt opts
[] =
1187 {"-skip-unavailable", SKIP_UNAVAILABLE
, 0},
1191 /* Note that the test for a valid register must include checking the
1192 gdbarch_register_name because gdbarch_num_regs may be allocated
1193 for the union of the register sets within a family of related
1194 processors. In this case, some entries of gdbarch_register_name
1195 will change depending upon the particular processor being
1201 int opt
= mi_getopt ("-data-list-register-values", argc
, argv
,
1202 opts
, &oind
, &oarg
);
1206 switch ((enum opt
) opt
)
1208 case SKIP_UNAVAILABLE
:
1209 skip_unavailable
= 1;
1214 if (argc
- oind
< 1)
1215 error (_("-data-list-register-values: Usage: "
1216 "-data-list-register-values [--skip-unavailable] <format>"
1217 " [<regnum1>...<regnumN>]"));
1219 format
= (int) argv
[oind
][0];
1221 frame
= get_selected_frame (NULL
);
1222 gdbarch
= get_frame_arch (frame
);
1223 numregs
= gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
1225 list_cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "register-values");
1227 if (argc
- oind
== 1)
1229 /* No args, beside the format: do all the regs. */
1234 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
1235 || *(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
1238 output_register (frame
, regnum
, format
, skip_unavailable
);
1242 /* Else, list of register #s, just do listed regs. */
1243 for (i
= 1 + oind
; i
< argc
; i
++)
1245 regnum
= atoi (argv
[i
]);
1249 && gdbarch_register_name (gdbarch
, regnum
) != NULL
1250 && *gdbarch_register_name (gdbarch
, regnum
) != '\000')
1251 output_register (frame
, regnum
, format
, skip_unavailable
);
1253 error (_("bad register number"));
1255 do_cleanups (list_cleanup
);
1258 /* Output one register REGNUM's contents in the desired FORMAT. If
1259 SKIP_UNAVAILABLE is true, skip the register if it is
1263 output_register (struct frame_info
*frame
, int regnum
, int format
,
1264 int skip_unavailable
)
1266 struct ui_out
*uiout
= current_uiout
;
1267 struct value
*val
= value_of_register (regnum
, frame
);
1268 struct cleanup
*tuple_cleanup
;
1269 struct value_print_options opts
;
1271 if (skip_unavailable
&& !value_entirely_available (val
))
1274 tuple_cleanup
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
1275 uiout
->field_int ("number", regnum
);
1285 get_formatted_print_options (&opts
, format
);
1287 val_print (value_type (val
),
1288 value_embedded_offset (val
), 0,
1289 &stb
, 0, val
, &opts
, current_language
);
1290 uiout
->field_stream ("value", stb
);
1292 do_cleanups (tuple_cleanup
);
1295 /* Write given values into registers. The registers and values are
1296 given as pairs. The corresponding MI command is
1297 -data-write-register-values <format>
1298 [<regnum1> <value1>...<regnumN> <valueN>] */
1300 mi_cmd_data_write_register_values (char *command
, char **argv
, int argc
)
1302 struct regcache
*regcache
;
1303 struct gdbarch
*gdbarch
;
1306 /* Note that the test for a valid register must include checking the
1307 gdbarch_register_name because gdbarch_num_regs may be allocated
1308 for the union of the register sets within a family of related
1309 processors. In this case, some entries of gdbarch_register_name
1310 will change depending upon the particular processor being
1313 regcache
= get_current_regcache ();
1314 gdbarch
= get_regcache_arch (regcache
);
1315 numregs
= gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
1318 error (_("-data-write-register-values: Usage: -data-write-register-"
1319 "values <format> [<regnum1> <value1>...<regnumN> <valueN>]"));
1321 if (!target_has_registers
)
1322 error (_("-data-write-register-values: No registers."));
1325 error (_("-data-write-register-values: No regs and values specified."));
1328 error (_("-data-write-register-values: "
1329 "Regs and vals are not in pairs."));
1331 for (i
= 1; i
< argc
; i
= i
+ 2)
1333 int regnum
= atoi (argv
[i
]);
1335 if (regnum
>= 0 && regnum
< numregs
1336 && gdbarch_register_name (gdbarch
, regnum
)
1337 && *gdbarch_register_name (gdbarch
, regnum
))
1341 /* Get the value as a number. */
1342 value
= parse_and_eval_address (argv
[i
+ 1]);
1344 /* Write it down. */
1345 regcache_cooked_write_signed (regcache
, regnum
, value
);
1348 error (_("bad register number"));
1352 /* Evaluate the value of the argument. The argument is an
1353 expression. If the expression contains spaces it needs to be
1354 included in double quotes. */
1357 mi_cmd_data_evaluate_expression (char *command
, char **argv
, int argc
)
1360 struct value_print_options opts
;
1361 struct ui_out
*uiout
= current_uiout
;
1364 error (_("-data-evaluate-expression: "
1365 "Usage: -data-evaluate-expression expression"));
1367 expression_up expr
= parse_expression (argv
[0]);
1369 val
= evaluate_expression (expr
.get ());
1373 /* Print the result of the expression evaluation. */
1374 get_user_print_options (&opts
);
1376 common_val_print (val
, &stb
, 0, &opts
, current_language
);
1378 uiout
->field_stream ("value", stb
);
1381 /* This is the -data-read-memory command.
1383 ADDR: start address of data to be dumped.
1384 WORD-FORMAT: a char indicating format for the ``word''. See
1386 WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes.
1387 NR_ROW: Number of rows.
1388 NR_COL: The number of colums (words per row).
1389 ASCHAR: (OPTIONAL) Append an ascii character dump to each row. Use
1390 ASCHAR for unprintable characters.
1392 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
1393 displayes them. Returns:
1395 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
1398 The number of bytes read is SIZE*ROW*COL. */
1401 mi_cmd_data_read_memory (char *command
, char **argv
, int argc
)
1403 struct gdbarch
*gdbarch
= get_current_arch ();
1404 struct ui_out
*uiout
= current_uiout
;
1406 long total_bytes
, nr_cols
, nr_rows
;
1408 struct type
*word_type
;
1420 static const struct mi_opt opts
[] =
1422 {"o", OFFSET_OPT
, 1},
1428 int opt
= mi_getopt ("-data-read-memory", argc
, argv
, opts
,
1433 switch ((enum opt
) opt
)
1436 offset
= atol (oarg
);
1443 if (argc
< 5 || argc
> 6)
1444 error (_("-data-read-memory: Usage: "
1445 "ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR]."));
1447 /* Extract all the arguments. */
1449 /* Start address of the memory dump. */
1450 addr
= parse_and_eval_address (argv
[0]) + offset
;
1451 /* The format character to use when displaying a memory word. See
1452 the ``x'' command. */
1453 word_format
= argv
[1][0];
1454 /* The size of the memory word. */
1455 word_size
= atol (argv
[2]);
1459 word_type
= builtin_type (gdbarch
)->builtin_int8
;
1463 word_type
= builtin_type (gdbarch
)->builtin_int16
;
1467 word_type
= builtin_type (gdbarch
)->builtin_int32
;
1471 word_type
= builtin_type (gdbarch
)->builtin_int64
;
1475 word_type
= builtin_type (gdbarch
)->builtin_int8
;
1478 /* The number of rows. */
1479 nr_rows
= atol (argv
[3]);
1481 error (_("-data-read-memory: invalid number of rows."));
1483 /* Number of bytes per row. */
1484 nr_cols
= atol (argv
[4]);
1486 error (_("-data-read-memory: invalid number of columns."));
1488 /* The un-printable character when printing ascii. */
1494 /* Create a buffer and read it in. */
1495 total_bytes
= word_size
* nr_rows
* nr_cols
;
1497 std::unique_ptr
<gdb_byte
[]> mbuf (new gdb_byte
[total_bytes
]);
1499 /* Dispatch memory reads to the topmost target, not the flattened
1501 nr_bytes
= target_read (current_target
.beneath
,
1502 TARGET_OBJECT_MEMORY
, NULL
, mbuf
.get (),
1505 error (_("Unable to read memory."));
1507 /* Output the header information. */
1508 uiout
->field_core_addr ("addr", gdbarch
, addr
);
1509 uiout
->field_int ("nr-bytes", nr_bytes
);
1510 uiout
->field_int ("total-bytes", total_bytes
);
1511 uiout
->field_core_addr ("next-row", gdbarch
, addr
+ word_size
* nr_cols
);
1512 uiout
->field_core_addr ("prev-row", gdbarch
, addr
- word_size
* nr_cols
);
1513 uiout
->field_core_addr ("next-page", gdbarch
, addr
+ total_bytes
);
1514 uiout
->field_core_addr ("prev-page", gdbarch
, addr
- total_bytes
);
1516 /* Build the result as a two dimentional table. */
1520 struct cleanup
*cleanup_list
;
1524 cleanup_list
= make_cleanup_ui_out_list_begin_end (uiout
, "memory");
1525 for (row
= 0, row_byte
= 0;
1527 row
++, row_byte
+= nr_cols
* word_size
)
1531 struct cleanup
*cleanup_tuple
;
1532 struct cleanup
*cleanup_list_data
;
1533 struct value_print_options opts
;
1535 cleanup_tuple
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
1536 uiout
->field_core_addr ("addr", gdbarch
, addr
+ row_byte
);
1537 /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr +
1539 cleanup_list_data
= make_cleanup_ui_out_list_begin_end (uiout
, "data");
1540 get_formatted_print_options (&opts
, word_format
);
1541 for (col
= 0, col_byte
= row_byte
;
1543 col
++, col_byte
+= word_size
)
1545 if (col_byte
+ word_size
> nr_bytes
)
1547 uiout
->field_string (NULL
, "N/A");
1552 print_scalar_formatted (&mbuf
[col_byte
], word_type
, &opts
,
1553 word_asize
, &stream
);
1554 uiout
->field_stream (NULL
, stream
);
1557 do_cleanups (cleanup_list_data
);
1563 for (byte
= row_byte
;
1564 byte
< row_byte
+ word_size
* nr_cols
; byte
++)
1566 if (byte
>= nr_bytes
)
1568 else if (mbuf
[byte
] < 32 || mbuf
[byte
] > 126)
1569 stream
.putc (aschar
);
1571 stream
.putc (mbuf
[byte
]);
1573 uiout
->field_stream ("ascii", stream
);
1575 do_cleanups (cleanup_tuple
);
1577 do_cleanups (cleanup_list
);
1582 mi_cmd_data_read_memory_bytes (char *command
, char **argv
, int argc
)
1584 struct gdbarch
*gdbarch
= get_current_arch ();
1585 struct ui_out
*uiout
= current_uiout
;
1586 struct cleanup
*cleanups
;
1589 memory_read_result_s
*read_result
;
1591 VEC(memory_read_result_s
) *result
;
1593 int unit_size
= gdbarch_addressable_memory_unit_size (gdbarch
);
1600 static const struct mi_opt opts
[] =
1602 {"o", OFFSET_OPT
, 1},
1608 int opt
= mi_getopt ("-data-read-memory-bytes", argc
, argv
, opts
,
1612 switch ((enum opt
) opt
)
1615 offset
= atol (oarg
);
1623 error (_("Usage: [ -o OFFSET ] ADDR LENGTH."));
1625 addr
= parse_and_eval_address (argv
[0]) + offset
;
1626 length
= atol (argv
[1]);
1628 result
= read_memory_robust (current_target
.beneath
, addr
, length
);
1630 cleanups
= make_cleanup (free_memory_read_result_vector
, &result
);
1632 if (VEC_length (memory_read_result_s
, result
) == 0)
1633 error (_("Unable to read memory."));
1635 make_cleanup_ui_out_list_begin_end (uiout
, "memory");
1637 VEC_iterate (memory_read_result_s
, result
, ix
, read_result
);
1640 struct cleanup
*t
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
1645 uiout
->field_core_addr ("begin", gdbarch
, read_result
->begin
);
1646 uiout
->field_core_addr ("offset", gdbarch
, read_result
->begin
- addr
);
1647 uiout
->field_core_addr ("end", gdbarch
, read_result
->end
);
1649 alloc_len
= (read_result
->end
- read_result
->begin
) * 2 * unit_size
+ 1;
1650 data
= (char *) xmalloc (alloc_len
);
1652 for (i
= 0, p
= data
;
1653 i
< ((read_result
->end
- read_result
->begin
) * unit_size
);
1656 sprintf (p
, "%02x", read_result
->data
[i
]);
1658 uiout
->field_string ("contents", data
);
1662 do_cleanups (cleanups
);
1665 /* Implementation of the -data-write_memory command.
1667 COLUMN_OFFSET: optional argument. Must be preceded by '-o'. The
1668 offset from the beginning of the memory grid row where the cell to
1670 ADDR: start address of the row in the memory grid where the memory
1671 cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
1672 the location to write to.
1673 FORMAT: a char indicating format for the ``word''. See
1675 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
1676 VALUE: value to be written into the memory address.
1678 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
1683 mi_cmd_data_write_memory (char *command
, char **argv
, int argc
)
1685 struct gdbarch
*gdbarch
= get_current_arch ();
1686 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1689 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
1690 enough when using a compiler other than GCC. */
1693 struct cleanup
*old_chain
;
1701 static const struct mi_opt opts
[] =
1703 {"o", OFFSET_OPT
, 1},
1709 int opt
= mi_getopt ("-data-write-memory", argc
, argv
, opts
,
1714 switch ((enum opt
) opt
)
1717 offset
= atol (oarg
);
1725 error (_("-data-write-memory: Usage: "
1726 "[-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE."));
1728 /* Extract all the arguments. */
1729 /* Start address of the memory dump. */
1730 addr
= parse_and_eval_address (argv
[0]);
1731 /* The size of the memory word. */
1732 word_size
= atol (argv
[2]);
1734 /* Calculate the real address of the write destination. */
1735 addr
+= (offset
* word_size
);
1737 /* Get the value as a number. */
1738 value
= parse_and_eval_address (argv
[3]);
1739 /* Get the value into an array. */
1740 buffer
= (gdb_byte
*) xmalloc (word_size
);
1741 old_chain
= make_cleanup (xfree
, buffer
);
1742 store_signed_integer (buffer
, word_size
, byte_order
, value
);
1743 /* Write it down to memory. */
1744 write_memory_with_notification (addr
, buffer
, word_size
);
1745 /* Free the buffer. */
1746 do_cleanups (old_chain
);
1749 /* Implementation of the -data-write-memory-bytes command.
1752 DATA: string of bytes to write at that address
1753 COUNT: number of bytes to be filled (decimal integer). */
1756 mi_cmd_data_write_memory_bytes (char *command
, char **argv
, int argc
)
1762 size_t len_hex
, len_bytes
, len_units
, i
, steps
, remaining_units
;
1763 long int count_units
;
1764 struct cleanup
*back_to
;
1767 if (argc
!= 2 && argc
!= 3)
1768 error (_("Usage: ADDR DATA [COUNT]."));
1770 addr
= parse_and_eval_address (argv
[0]);
1772 len_hex
= strlen (cdata
);
1773 unit_size
= gdbarch_addressable_memory_unit_size (get_current_arch ());
1775 if (len_hex
% (unit_size
* 2) != 0)
1776 error (_("Hex-encoded '%s' must represent an integral number of "
1777 "addressable memory units."),
1780 len_bytes
= len_hex
/ 2;
1781 len_units
= len_bytes
/ unit_size
;
1784 count_units
= strtoul (argv
[2], NULL
, 10);
1786 count_units
= len_units
;
1788 databuf
= XNEWVEC (gdb_byte
, len_bytes
);
1789 back_to
= make_cleanup (xfree
, databuf
);
1791 for (i
= 0; i
< len_bytes
; ++i
)
1794 if (sscanf (cdata
+ i
* 2, "%02x", &x
) != 1)
1795 error (_("Invalid argument"));
1796 databuf
[i
] = (gdb_byte
) x
;
1799 if (len_units
< count_units
)
1801 /* Pattern is made of less units than count:
1802 repeat pattern to fill memory. */
1803 data
= (gdb_byte
*) xmalloc (count_units
* unit_size
);
1804 make_cleanup (xfree
, data
);
1806 /* Number of times the pattern is entirely repeated. */
1807 steps
= count_units
/ len_units
;
1808 /* Number of remaining addressable memory units. */
1809 remaining_units
= count_units
% len_units
;
1810 for (i
= 0; i
< steps
; i
++)
1811 memcpy (data
+ i
* len_bytes
, databuf
, len_bytes
);
1813 if (remaining_units
> 0)
1814 memcpy (data
+ steps
* len_bytes
, databuf
,
1815 remaining_units
* unit_size
);
1819 /* Pattern is longer than or equal to count:
1820 just copy count addressable memory units. */
1824 write_memory_with_notification (addr
, data
, count_units
);
1826 do_cleanups (back_to
);
1830 mi_cmd_enable_timings (char *command
, char **argv
, int argc
)
1836 if (strcmp (argv
[0], "yes") == 0)
1838 else if (strcmp (argv
[0], "no") == 0)
1849 error (_("-enable-timings: Usage: %s {yes|no}"), command
);
1853 mi_cmd_list_features (char *command
, char **argv
, int argc
)
1857 struct cleanup
*cleanup
= NULL
;
1858 struct ui_out
*uiout
= current_uiout
;
1860 cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "features");
1861 uiout
->field_string (NULL
, "frozen-varobjs");
1862 uiout
->field_string (NULL
, "pending-breakpoints");
1863 uiout
->field_string (NULL
, "thread-info");
1864 uiout
->field_string (NULL
, "data-read-memory-bytes");
1865 uiout
->field_string (NULL
, "breakpoint-notifications");
1866 uiout
->field_string (NULL
, "ada-task-info");
1867 uiout
->field_string (NULL
, "language-option");
1868 uiout
->field_string (NULL
, "info-gdb-mi-command");
1869 uiout
->field_string (NULL
, "undefined-command-error-code");
1870 uiout
->field_string (NULL
, "exec-run-start-option");
1872 if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON
)))
1873 uiout
->field_string (NULL
, "python");
1875 do_cleanups (cleanup
);
1879 error (_("-list-features should be passed no arguments"));
1883 mi_cmd_list_target_features (char *command
, char **argv
, int argc
)
1887 struct cleanup
*cleanup
= NULL
;
1888 struct ui_out
*uiout
= current_uiout
;
1890 cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "features");
1892 uiout
->field_string (NULL
, "async");
1893 if (target_can_execute_reverse
)
1894 uiout
->field_string (NULL
, "reverse");
1895 do_cleanups (cleanup
);
1899 error (_("-list-target-features should be passed no arguments"));
1903 mi_cmd_add_inferior (char *command
, char **argv
, int argc
)
1905 struct inferior
*inf
;
1908 error (_("-add-inferior should be passed no arguments"));
1910 inf
= add_inferior_with_spaces ();
1912 current_uiout
->field_fmt ("inferior", "i%d", inf
->num
);
1915 /* Callback used to find the first inferior other than the current
1919 get_other_inferior (struct inferior
*inf
, void *arg
)
1921 if (inf
== current_inferior ())
1928 mi_cmd_remove_inferior (char *command
, char **argv
, int argc
)
1931 struct inferior
*inf
;
1934 error (_("-remove-inferior should be passed a single argument"));
1936 if (sscanf (argv
[0], "i%d", &id
) != 1)
1937 error (_("the thread group id is syntactically invalid"));
1939 inf
= find_inferior_id (id
);
1941 error (_("the specified thread group does not exist"));
1944 error (_("cannot remove an active inferior"));
1946 if (inf
== current_inferior ())
1948 struct thread_info
*tp
= 0;
1949 struct inferior
*new_inferior
1950 = iterate_over_inferiors (get_other_inferior
, NULL
);
1952 if (new_inferior
== NULL
)
1953 error (_("Cannot remove last inferior"));
1955 set_current_inferior (new_inferior
);
1956 if (new_inferior
->pid
!= 0)
1957 tp
= any_thread_of_process (new_inferior
->pid
);
1958 switch_to_thread (tp
? tp
->ptid
: null_ptid
);
1959 set_current_program_space (new_inferior
->pspace
);
1962 delete_inferior (inf
);
1967 /* Execute a command within a safe environment.
1968 Return <0 for error; >=0 for ok.
1970 args->action will tell mi_execute_command what action
1971 to perfrom after the given command has executed (display/suppress
1972 prompt, display error). */
1975 captured_mi_execute_command (struct ui_out
*uiout
, struct mi_parse
*context
)
1977 struct mi_interp
*mi
= (struct mi_interp
*) interp_data (command_interp ());
1978 struct cleanup
*cleanup
;
1981 current_command_ts
= context
->cmd_start
;
1983 current_token
= xstrdup (context
->token
);
1984 cleanup
= make_cleanup (free_current_contents
, ¤t_token
);
1986 running_result_record_printed
= 0;
1988 switch (context
->op
)
1991 /* A MI command was read from the input stream. */
1993 /* FIXME: gdb_???? */
1994 fprintf_unfiltered (mi
->raw_stdout
,
1995 " token=`%s' command=`%s' args=`%s'\n",
1996 context
->token
, context
->command
, context
->args
);
1998 mi_cmd_execute (context
);
2000 /* Print the result if there were no errors.
2002 Remember that on the way out of executing a command, you have
2003 to directly use the mi_interp's uiout, since the command
2004 could have reset the interpreter, in which case the current
2005 uiout will most likely crash in the mi_out_* routines. */
2006 if (!running_result_record_printed
)
2008 fputs_unfiltered (context
->token
, mi
->raw_stdout
);
2009 /* There's no particularly good reason why target-connect results
2010 in not ^done. Should kill ^connected for MI3. */
2011 fputs_unfiltered (strcmp (context
->command
, "target-select") == 0
2012 ? "^connected" : "^done", mi
->raw_stdout
);
2013 mi_out_put (uiout
, mi
->raw_stdout
);
2014 mi_out_rewind (uiout
);
2015 mi_print_timing_maybe (mi
->raw_stdout
);
2016 fputs_unfiltered ("\n", mi
->raw_stdout
);
2019 /* The command does not want anything to be printed. In that
2020 case, the command probably should not have written anything
2021 to uiout, but in case it has written something, discard it. */
2022 mi_out_rewind (uiout
);
2029 /* A CLI command was read from the input stream. */
2030 /* This "feature" will be removed as soon as we have a
2031 complete set of mi commands. */
2032 /* Echo the command on the console. */
2033 fprintf_unfiltered (gdb_stdlog
, "%s\n", context
->command
);
2034 /* Call the "console" interpreter. */
2035 argv
[0] = INTERP_CONSOLE
;
2036 argv
[1] = context
->command
;
2037 mi_cmd_interpreter_exec ("-interpreter-exec", argv
, 2);
2039 /* If we changed interpreters, DON'T print out anything. */
2040 if (current_interp_named_p (INTERP_MI
)
2041 || current_interp_named_p (INTERP_MI1
)
2042 || current_interp_named_p (INTERP_MI2
)
2043 || current_interp_named_p (INTERP_MI3
))
2045 if (!running_result_record_printed
)
2047 fputs_unfiltered (context
->token
, mi
->raw_stdout
);
2048 fputs_unfiltered ("^done", mi
->raw_stdout
);
2049 mi_out_put (uiout
, mi
->raw_stdout
);
2050 mi_out_rewind (uiout
);
2051 mi_print_timing_maybe (mi
->raw_stdout
);
2052 fputs_unfiltered ("\n", mi
->raw_stdout
);
2055 mi_out_rewind (uiout
);
2061 do_cleanups (cleanup
);
2064 /* Print a gdb exception to the MI output stream. */
2067 mi_print_exception (const char *token
, struct gdb_exception exception
)
2069 struct mi_interp
*mi
2070 = (struct mi_interp
*) interp_data (current_interpreter ());
2072 fputs_unfiltered (token
, mi
->raw_stdout
);
2073 fputs_unfiltered ("^error,msg=\"", mi
->raw_stdout
);
2074 if (exception
.message
== NULL
)
2075 fputs_unfiltered ("unknown error", mi
->raw_stdout
);
2077 fputstr_unfiltered (exception
.message
, '"', mi
->raw_stdout
);
2078 fputs_unfiltered ("\"", mi
->raw_stdout
);
2080 switch (exception
.error
)
2082 case UNDEFINED_COMMAND_ERROR
:
2083 fputs_unfiltered (",code=\"undefined-command\"", mi
->raw_stdout
);
2087 fputs_unfiltered ("\n", mi
->raw_stdout
);
2090 /* Determine whether the parsed command already notifies the
2091 user_selected_context_changed observer. */
2094 command_notifies_uscc_observer (struct mi_parse
*command
)
2096 if (command
->op
== CLI_COMMAND
)
2098 /* CLI commands "thread" and "inferior" already send it. */
2099 return (strncmp (command
->command
, "thread ", 7) == 0
2100 || strncmp (command
->command
, "inferior ", 9) == 0);
2102 else /* MI_COMMAND */
2104 if (strcmp (command
->command
, "interpreter-exec") == 0
2105 && command
->argc
> 1)
2107 /* "thread" and "inferior" again, but through -interpreter-exec. */
2108 return (strncmp (command
->argv
[1], "thread ", 7) == 0
2109 || strncmp (command
->argv
[1], "inferior ", 9) == 0);
2113 /* -thread-select already sends it. */
2114 return strcmp (command
->command
, "thread-select") == 0;
2119 mi_execute_command (const char *cmd
, int from_tty
)
2122 struct mi_parse
*command
= NULL
;
2124 /* This is to handle EOF (^D). We just quit gdb. */
2125 /* FIXME: we should call some API function here. */
2127 quit_force (NULL
, from_tty
);
2129 target_log_command (cmd
);
2133 command
= mi_parse (cmd
, &token
);
2135 CATCH (exception
, RETURN_MASK_ALL
)
2137 mi_print_exception (token
, exception
);
2142 if (command
!= NULL
)
2144 ptid_t previous_ptid
= inferior_ptid
;
2145 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
2147 command
->token
= token
;
2149 if (command
->cmd
!= NULL
&& command
->cmd
->suppress_notification
!= NULL
)
2151 make_cleanup_restore_integer (command
->cmd
->suppress_notification
);
2152 *command
->cmd
->suppress_notification
= 1;
2157 command
->cmd_start
= new mi_timestamp ();
2158 timestamp (command
->cmd_start
);
2163 captured_mi_execute_command (current_uiout
, command
);
2165 CATCH (result
, RETURN_MASK_ALL
)
2167 /* Like in start_event_loop, enable input and force display
2168 of the prompt. Otherwise, any command that calls
2169 async_disable_stdin, and then throws, will leave input
2171 async_enable_stdin ();
2172 current_ui
->prompt_state
= PROMPT_NEEDED
;
2174 /* The command execution failed and error() was called
2176 mi_print_exception (command
->token
, result
);
2177 mi_out_rewind (current_uiout
);
2181 bpstat_do_actions ();
2183 if (/* The notifications are only output when the top-level
2184 interpreter (specified on the command line) is MI. */
2185 interp_ui_out (top_level_interpreter ())->is_mi_like_p ()
2186 /* Don't try report anything if there are no threads --
2187 the program is dead. */
2188 && thread_count () != 0
2189 /* If the command already reports the thread change, no need to do it
2191 && !command_notifies_uscc_observer (command
))
2193 struct mi_interp
*mi
2194 = (struct mi_interp
*) top_level_interpreter_data ();
2195 int report_change
= 0;
2197 if (command
->thread
== -1)
2199 report_change
= (!ptid_equal (previous_ptid
, null_ptid
)
2200 && !ptid_equal (inferior_ptid
, previous_ptid
)
2201 && !ptid_equal (inferior_ptid
, null_ptid
));
2203 else if (!ptid_equal (inferior_ptid
, null_ptid
))
2205 struct thread_info
*ti
= inferior_thread ();
2207 report_change
= (ti
->global_num
!= command
->thread
);
2212 observer_notify_user_selected_context_changed
2213 (USER_SELECTED_THREAD
| USER_SELECTED_FRAME
);
2217 mi_parse_free (command
);
2219 do_cleanups (cleanup
);
2224 mi_cmd_execute (struct mi_parse
*parse
)
2226 struct cleanup
*cleanup
;
2228 cleanup
= prepare_execute_command ();
2230 if (parse
->all
&& parse
->thread_group
!= -1)
2231 error (_("Cannot specify --thread-group together with --all"));
2233 if (parse
->all
&& parse
->thread
!= -1)
2234 error (_("Cannot specify --thread together with --all"));
2236 if (parse
->thread_group
!= -1 && parse
->thread
!= -1)
2237 error (_("Cannot specify --thread together with --thread-group"));
2239 if (parse
->frame
!= -1 && parse
->thread
== -1)
2240 error (_("Cannot specify --frame without --thread"));
2242 if (parse
->thread_group
!= -1)
2244 struct inferior
*inf
= find_inferior_id (parse
->thread_group
);
2245 struct thread_info
*tp
= 0;
2248 error (_("Invalid thread group for the --thread-group option"));
2250 set_current_inferior (inf
);
2251 /* This behaviour means that if --thread-group option identifies
2252 an inferior with multiple threads, then a random one will be
2253 picked. This is not a problem -- frontend should always
2254 provide --thread if it wishes to operate on a specific
2257 tp
= any_live_thread_of_process (inf
->pid
);
2258 switch_to_thread (tp
? tp
->ptid
: null_ptid
);
2259 set_current_program_space (inf
->pspace
);
2262 if (parse
->thread
!= -1)
2264 struct thread_info
*tp
= find_thread_global_id (parse
->thread
);
2267 error (_("Invalid thread id: %d"), parse
->thread
);
2269 if (is_exited (tp
->ptid
))
2270 error (_("Thread id: %d has terminated"), parse
->thread
);
2272 switch_to_thread (tp
->ptid
);
2275 if (parse
->frame
!= -1)
2277 struct frame_info
*fid
;
2278 int frame
= parse
->frame
;
2280 fid
= find_relative_frame (get_current_frame (), &frame
);
2282 /* find_relative_frame was successful */
2285 error (_("Invalid frame id: %d"), frame
);
2288 if (parse
->language
!= language_unknown
)
2290 make_cleanup_restore_current_language ();
2291 set_language (parse
->language
);
2294 current_context
= parse
;
2296 if (parse
->cmd
->argv_func
!= NULL
)
2298 parse
->cmd
->argv_func (parse
->command
, parse
->argv
, parse
->argc
);
2300 else if (parse
->cmd
->cli
.cmd
!= 0)
2302 /* FIXME: DELETE THIS. */
2303 /* The operation is still implemented by a cli command. */
2304 /* Must be a synchronous one. */
2305 mi_execute_cli_command (parse
->cmd
->cli
.cmd
, parse
->cmd
->cli
.args_p
,
2310 /* FIXME: DELETE THIS. */
2313 stb
.puts ("Undefined mi command: ");
2314 stb
.putstr (parse
->command
, '"');
2315 stb
.puts (" (missing implementation)");
2319 do_cleanups (cleanup
);
2322 /* FIXME: This is just a hack so we can get some extra commands going.
2323 We don't want to channel things through the CLI, but call libgdb directly.
2324 Use only for synchronous commands. */
2327 mi_execute_cli_command (const char *cmd
, int args_p
, const char *args
)
2331 struct cleanup
*old_cleanups
;
2335 run
= xstrprintf ("%s %s", cmd
, args
);
2337 run
= xstrdup (cmd
);
2339 /* FIXME: gdb_???? */
2340 fprintf_unfiltered (gdb_stdout
, "cli=%s run=%s\n",
2342 old_cleanups
= make_cleanup (xfree
, run
);
2343 execute_command (run
, 0 /* from_tty */ );
2344 do_cleanups (old_cleanups
);
2350 mi_execute_async_cli_command (char *cli_command
, char **argv
, int argc
)
2352 struct cleanup
*old_cleanups
;
2356 run
= xstrprintf ("%s %s&", cli_command
, argc
? *argv
: "");
2358 run
= xstrprintf ("%s %s", cli_command
, argc
? *argv
: "");
2359 old_cleanups
= make_cleanup (xfree
, run
);
2361 execute_command (run
, 0 /* from_tty */ );
2363 /* Do this before doing any printing. It would appear that some
2364 print code leaves garbage around in the buffer. */
2365 do_cleanups (old_cleanups
);
2369 mi_load_progress (const char *section_name
,
2370 unsigned long sent_so_far
,
2371 unsigned long total_section
,
2372 unsigned long total_sent
,
2373 unsigned long grand_total
)
2375 using namespace std::chrono
;
2376 static steady_clock::time_point last_update
;
2377 static char *previous_sect_name
= NULL
;
2379 struct ui_out
*saved_uiout
;
2380 struct ui_out
*uiout
;
2381 struct mi_interp
*mi
2382 = (struct mi_interp
*) interp_data (current_interpreter ());
2384 /* This function is called through deprecated_show_load_progress
2385 which means uiout may not be correct. Fix it for the duration
2386 of this function. */
2387 saved_uiout
= current_uiout
;
2389 if (current_interp_named_p (INTERP_MI
)
2390 || current_interp_named_p (INTERP_MI2
))
2391 current_uiout
= mi_out_new (2);
2392 else if (current_interp_named_p (INTERP_MI1
))
2393 current_uiout
= mi_out_new (1);
2394 else if (current_interp_named_p (INTERP_MI3
))
2395 current_uiout
= mi_out_new (3);
2399 uiout
= current_uiout
;
2401 new_section
= (previous_sect_name
?
2402 strcmp (previous_sect_name
, section_name
) : 1);
2405 struct cleanup
*cleanup_tuple
;
2407 xfree (previous_sect_name
);
2408 previous_sect_name
= xstrdup (section_name
);
2411 fputs_unfiltered (current_token
, mi
->raw_stdout
);
2412 fputs_unfiltered ("+download", mi
->raw_stdout
);
2413 cleanup_tuple
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
2414 uiout
->field_string ("section", section_name
);
2415 uiout
->field_int ("section-size", total_section
);
2416 uiout
->field_int ("total-size", grand_total
);
2417 do_cleanups (cleanup_tuple
);
2418 mi_out_put (uiout
, mi
->raw_stdout
);
2419 fputs_unfiltered ("\n", mi
->raw_stdout
);
2420 gdb_flush (mi
->raw_stdout
);
2423 steady_clock::time_point time_now
= steady_clock::now ();
2424 if (time_now
- last_update
> milliseconds (500))
2426 struct cleanup
*cleanup_tuple
;
2428 last_update
= time_now
;
2430 fputs_unfiltered (current_token
, mi
->raw_stdout
);
2431 fputs_unfiltered ("+download", mi
->raw_stdout
);
2432 cleanup_tuple
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
2433 uiout
->field_string ("section", section_name
);
2434 uiout
->field_int ("section-sent", sent_so_far
);
2435 uiout
->field_int ("section-size", total_section
);
2436 uiout
->field_int ("total-sent", total_sent
);
2437 uiout
->field_int ("total-size", grand_total
);
2438 do_cleanups (cleanup_tuple
);
2439 mi_out_put (uiout
, mi
->raw_stdout
);
2440 fputs_unfiltered ("\n", mi
->raw_stdout
);
2441 gdb_flush (mi
->raw_stdout
);
2445 current_uiout
= saved_uiout
;
2449 timestamp (struct mi_timestamp
*tv
)
2451 using namespace std::chrono
;
2453 tv
->wallclock
= steady_clock::now ();
2454 run_time_clock::now (tv
->utime
, tv
->stime
);
2458 print_diff_now (struct ui_file
*file
, struct mi_timestamp
*start
)
2460 struct mi_timestamp now
;
2463 print_diff (file
, start
, &now
);
2467 mi_print_timing_maybe (struct ui_file
*file
)
2469 /* If the command is -enable-timing then do_timings may be true
2470 whilst current_command_ts is not initialized. */
2471 if (do_timings
&& current_command_ts
)
2472 print_diff_now (file
, current_command_ts
);
2476 print_diff (struct ui_file
*file
, struct mi_timestamp
*start
,
2477 struct mi_timestamp
*end
)
2479 using namespace std::chrono
;
2481 duration
<double> wallclock
= end
->wallclock
- start
->wallclock
;
2482 duration
<double> utime
= end
->utime
- start
->utime
;
2483 duration
<double> stime
= end
->stime
- start
->stime
;
2487 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
2488 wallclock
.count (), utime
.count (), stime
.count ());
2492 mi_cmd_trace_define_variable (char *command
, char **argv
, int argc
)
2494 LONGEST initval
= 0;
2495 struct trace_state_variable
*tsv
;
2498 if (argc
!= 1 && argc
!= 2)
2499 error (_("Usage: -trace-define-variable VARIABLE [VALUE]"));
2503 error (_("Name of trace variable should start with '$'"));
2505 validate_trace_state_variable_name (name
);
2507 tsv
= find_trace_state_variable (name
);
2509 tsv
= create_trace_state_variable (name
);
2512 initval
= value_as_long (parse_and_eval (argv
[1]));
2514 tsv
->initial_value
= initval
;
2518 mi_cmd_trace_list_variables (char *command
, char **argv
, int argc
)
2521 error (_("-trace-list-variables: no arguments allowed"));
2523 tvariables_info_1 ();
2527 mi_cmd_trace_find (char *command
, char **argv
, int argc
)
2532 error (_("trace selection mode is required"));
2536 if (strcmp (mode
, "none") == 0)
2538 tfind_1 (tfind_number
, -1, 0, 0, 0);
2542 check_trace_running (current_trace_status ());
2544 if (strcmp (mode
, "frame-number") == 0)
2547 error (_("frame number is required"));
2548 tfind_1 (tfind_number
, atoi (argv
[1]), 0, 0, 0);
2550 else if (strcmp (mode
, "tracepoint-number") == 0)
2553 error (_("tracepoint number is required"));
2554 tfind_1 (tfind_tp
, atoi (argv
[1]), 0, 0, 0);
2556 else if (strcmp (mode
, "pc") == 0)
2559 error (_("PC is required"));
2560 tfind_1 (tfind_pc
, 0, parse_and_eval_address (argv
[1]), 0, 0);
2562 else if (strcmp (mode
, "pc-inside-range") == 0)
2565 error (_("Start and end PC are required"));
2566 tfind_1 (tfind_range
, 0, parse_and_eval_address (argv
[1]),
2567 parse_and_eval_address (argv
[2]), 0);
2569 else if (strcmp (mode
, "pc-outside-range") == 0)
2572 error (_("Start and end PC are required"));
2573 tfind_1 (tfind_outside
, 0, parse_and_eval_address (argv
[1]),
2574 parse_and_eval_address (argv
[2]), 0);
2576 else if (strcmp (mode
, "line") == 0)
2578 struct symtabs_and_lines sals
;
2579 struct symtab_and_line sal
;
2580 static CORE_ADDR start_pc
, end_pc
;
2581 struct cleanup
*back_to
;
2584 error (_("Line is required"));
2586 sals
= decode_line_with_current_source (argv
[1],
2587 DECODE_LINE_FUNFIRSTLINE
);
2588 back_to
= make_cleanup (xfree
, sals
.sals
);
2592 if (sal
.symtab
== 0)
2593 error (_("Could not find the specified line"));
2595 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2596 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, 0);
2598 error (_("Could not find the specified line"));
2600 do_cleanups (back_to
);
2603 error (_("Invalid mode '%s'"), mode
);
2605 if (has_stack_frames () || get_traceframe_number () >= 0)
2606 print_stack_frame (get_selected_frame (NULL
), 1, LOC_AND_ADDRESS
, 1);
2610 mi_cmd_trace_save (char *command
, char **argv
, int argc
)
2612 int target_saves
= 0;
2613 int generate_ctf
= 0;
2620 TARGET_SAVE_OPT
, CTF_OPT
2622 static const struct mi_opt opts
[] =
2624 {"r", TARGET_SAVE_OPT
, 0},
2625 {"ctf", CTF_OPT
, 0},
2631 int opt
= mi_getopt ("-trace-save", argc
, argv
, opts
,
2636 switch ((enum opt
) opt
)
2638 case TARGET_SAVE_OPT
:
2647 if (argc
- oind
!= 1)
2648 error (_("Exactly one argument required "
2649 "(file in which to save trace data)"));
2651 filename
= argv
[oind
];
2654 trace_save_ctf (filename
, target_saves
);
2656 trace_save_tfile (filename
, target_saves
);
2660 mi_cmd_trace_start (char *command
, char **argv
, int argc
)
2662 start_tracing (NULL
);
2666 mi_cmd_trace_status (char *command
, char **argv
, int argc
)
2668 trace_status_mi (0);
2672 mi_cmd_trace_stop (char *command
, char **argv
, int argc
)
2674 stop_tracing (NULL
);
2675 trace_status_mi (1);
2678 /* Implement the "-ada-task-info" command. */
2681 mi_cmd_ada_task_info (char *command
, char **argv
, int argc
)
2683 if (argc
!= 0 && argc
!= 1)
2684 error (_("Invalid MI command"));
2686 print_ada_task_info (current_uiout
, argv
[0], current_inferior ());
2689 /* Print EXPRESSION according to VALUES. */
2692 print_variable_or_computed (const char *expression
, enum print_values values
)
2694 struct cleanup
*old_chain
;
2697 struct ui_out
*uiout
= current_uiout
;
2701 expression_up expr
= parse_expression (expression
);
2703 if (values
== PRINT_SIMPLE_VALUES
)
2704 val
= evaluate_type (expr
.get ());
2706 val
= evaluate_expression (expr
.get ());
2708 old_chain
= make_cleanup (null_cleanup
, NULL
);
2709 if (values
!= PRINT_NO_VALUES
)
2710 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
2711 uiout
->field_string ("name", expression
);
2715 case PRINT_SIMPLE_VALUES
:
2716 type
= check_typedef (value_type (val
));
2717 type_print (value_type (val
), "", &stb
, -1);
2718 uiout
->field_stream ("type", stb
);
2719 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
2720 && TYPE_CODE (type
) != TYPE_CODE_STRUCT
2721 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
2723 struct value_print_options opts
;
2725 get_no_prettyformat_print_options (&opts
);
2727 common_val_print (val
, &stb
, 0, &opts
, current_language
);
2728 uiout
->field_stream ("value", stb
);
2731 case PRINT_ALL_VALUES
:
2733 struct value_print_options opts
;
2735 get_no_prettyformat_print_options (&opts
);
2737 common_val_print (val
, &stb
, 0, &opts
, current_language
);
2738 uiout
->field_stream ("value", stb
);
2743 do_cleanups (old_chain
);
2746 /* Implement the "-trace-frame-collected" command. */
2749 mi_cmd_trace_frame_collected (char *command
, char **argv
, int argc
)
2751 struct cleanup
*old_chain
;
2752 struct bp_location
*tloc
;
2754 struct collection_list
*clist
;
2755 struct collection_list tracepoint_list
, stepping_list
;
2756 struct traceframe_info
*tinfo
;
2758 enum print_values var_print_values
= PRINT_ALL_VALUES
;
2759 enum print_values comp_print_values
= PRINT_ALL_VALUES
;
2760 int registers_format
= 'x';
2761 int memory_contents
= 0;
2762 struct ui_out
*uiout
= current_uiout
;
2770 static const struct mi_opt opts
[] =
2772 {"-var-print-values", VAR_PRINT_VALUES
, 1},
2773 {"-comp-print-values", COMP_PRINT_VALUES
, 1},
2774 {"-registers-format", REGISTERS_FORMAT
, 1},
2775 {"-memory-contents", MEMORY_CONTENTS
, 0},
2782 int opt
= mi_getopt ("-trace-frame-collected", argc
, argv
, opts
,
2786 switch ((enum opt
) opt
)
2788 case VAR_PRINT_VALUES
:
2789 var_print_values
= mi_parse_print_values (oarg
);
2791 case COMP_PRINT_VALUES
:
2792 comp_print_values
= mi_parse_print_values (oarg
);
2794 case REGISTERS_FORMAT
:
2795 registers_format
= oarg
[0];
2796 case MEMORY_CONTENTS
:
2797 memory_contents
= 1;
2803 error (_("Usage: -trace-frame-collected "
2804 "[--var-print-values PRINT_VALUES] "
2805 "[--comp-print-values PRINT_VALUES] "
2806 "[--registers-format FORMAT]"
2807 "[--memory-contents]"));
2809 /* This throws an error is not inspecting a trace frame. */
2810 tloc
= get_traceframe_location (&stepping_frame
);
2812 /* This command only makes sense for the current frame, not the
2814 old_chain
= make_cleanup_restore_current_thread ();
2815 select_frame (get_current_frame ());
2817 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
2820 clist
= &stepping_list
;
2822 clist
= &tracepoint_list
;
2824 tinfo
= get_traceframe_info ();
2826 /* Explicitly wholly collected variables. */
2828 struct cleanup
*list_cleanup
;
2831 list_cleanup
= make_cleanup_ui_out_list_begin_end (uiout
,
2832 "explicit-variables");
2834 const std::vector
<std::string
> &wholly_collected
2835 = clist
->wholly_collected ();
2836 for (size_t i
= 0; i
< wholly_collected
.size (); i
++)
2838 const std::string
&str
= wholly_collected
[i
];
2839 print_variable_or_computed (str
.c_str (), var_print_values
);
2842 do_cleanups (list_cleanup
);
2845 /* Computed expressions. */
2847 struct cleanup
*list_cleanup
;
2852 = make_cleanup_ui_out_list_begin_end (uiout
,
2853 "computed-expressions");
2855 const std::vector
<std::string
> &computed
= clist
->computed ();
2856 for (size_t i
= 0; i
< computed
.size (); i
++)
2858 const std::string
&str
= computed
[i
];
2859 print_variable_or_computed (str
.c_str (), comp_print_values
);
2862 do_cleanups (list_cleanup
);
2865 /* Registers. Given pseudo-registers, and that some architectures
2866 (like MIPS) actually hide the raw registers, we don't go through
2867 the trace frame info, but instead consult the register cache for
2868 register availability. */
2870 struct cleanup
*list_cleanup
;
2871 struct frame_info
*frame
;
2872 struct gdbarch
*gdbarch
;
2876 list_cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "registers");
2878 frame
= get_selected_frame (NULL
);
2879 gdbarch
= get_frame_arch (frame
);
2880 numregs
= gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
2882 for (regnum
= 0; regnum
< numregs
; regnum
++)
2884 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
2885 || *(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
2888 output_register (frame
, regnum
, registers_format
, 1);
2891 do_cleanups (list_cleanup
);
2894 /* Trace state variables. */
2896 struct cleanup
*list_cleanup
;
2901 list_cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "tvars");
2904 make_cleanup (free_current_contents
, &tsvname
);
2906 for (i
= 0; VEC_iterate (int, tinfo
->tvars
, i
, tvar
); i
++)
2908 struct cleanup
*cleanup_child
;
2909 struct trace_state_variable
*tsv
;
2911 tsv
= find_trace_state_variable_by_number (tvar
);
2913 cleanup_child
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
2917 tsvname
= (char *) xrealloc (tsvname
, strlen (tsv
->name
) + 2);
2919 strcpy (tsvname
+ 1, tsv
->name
);
2920 uiout
->field_string ("name", tsvname
);
2922 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
2924 uiout
->field_int ("current", tsv
->value
);
2928 uiout
->field_skip ("name");
2929 uiout
->field_skip ("current");
2932 do_cleanups (cleanup_child
);
2935 do_cleanups (list_cleanup
);
2940 struct cleanup
*list_cleanup
;
2941 VEC(mem_range_s
) *available_memory
= NULL
;
2942 struct mem_range
*r
;
2945 traceframe_available_memory (&available_memory
, 0, ULONGEST_MAX
);
2946 make_cleanup (VEC_cleanup(mem_range_s
), &available_memory
);
2948 list_cleanup
= make_cleanup_ui_out_list_begin_end (uiout
, "memory");
2950 for (i
= 0; VEC_iterate (mem_range_s
, available_memory
, i
, r
); i
++)
2952 struct cleanup
*cleanup_child
;
2954 struct gdbarch
*gdbarch
= target_gdbarch ();
2956 cleanup_child
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
2958 uiout
->field_core_addr ("address", gdbarch
, r
->start
);
2959 uiout
->field_int ("length", r
->length
);
2961 data
= (gdb_byte
*) xmalloc (r
->length
);
2962 make_cleanup (xfree
, data
);
2964 if (memory_contents
)
2966 if (target_read_memory (r
->start
, data
, r
->length
) == 0)
2971 data_str
= (char *) xmalloc (r
->length
* 2 + 1);
2972 make_cleanup (xfree
, data_str
);
2974 for (m
= 0, p
= data_str
; m
< r
->length
; ++m
, p
+= 2)
2975 sprintf (p
, "%02x", data
[m
]);
2976 uiout
->field_string ("contents", data_str
);
2979 uiout
->field_skip ("contents");
2981 do_cleanups (cleanup_child
);
2984 do_cleanups (list_cleanup
);
2987 do_cleanups (old_chain
);
2991 _initialize_mi_main (void)
2993 struct cmd_list_element
*c
;
2995 add_setshow_boolean_cmd ("mi-async", class_run
,
2997 Set whether MI asynchronous mode is enabled."), _("\
2998 Show whether MI asynchronous mode is enabled."), _("\
2999 Tells GDB whether MI should be in asynchronous mode."),
3000 set_mi_async_command
,
3001 show_mi_async_command
,
3005 /* Alias old "target-async" to "mi-async". */
3006 c
= add_alias_cmd ("target-async", "mi-async", class_run
, 0, &setlist
);
3007 deprecate_cmd (c
, "set mi-async");
3008 c
= add_alias_cmd ("target-async", "mi-async", class_run
, 0, &showlist
);
3009 deprecate_cmd (c
, "show mi-async");