3 Copyright (C) 2000-2023 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"
29 #include "gdbthread.h"
32 #include "mi-getopt.h"
33 #include "mi-console.h"
37 #include "gdbsupport/event-loop.h"
38 #include "event-top.h"
44 #include "mi-interp.h"
48 #include "gdbsupport/gdb_splay_tree.h"
49 #include "tracepoint.h"
52 #include "extension.h"
54 #include "observable.h"
55 #include "gdbsupport/gdb_optional.h"
56 #include "gdbsupport/byte-vector.h"
59 #include "gdbsupport/run-time-clock.h"
61 #include "progspace-and-thread.h"
62 #include "gdbsupport/rsp-low.h"
73 static int mi_debug_p
;
75 /* This is used to pass the current command timestamp down to
76 continuation routines. */
77 static struct mi_timestamp
*current_command_ts
;
79 static int do_timings
= 0;
81 /* Few commands would like to know if options like --thread-group were
82 explicitly specified. This variable keeps the current parsed
83 command including all option, and make it possible. */
84 static struct mi_parse
*current_context
;
86 static void mi_cmd_execute (struct mi_parse
*parse
);
88 static void mi_execute_async_cli_command (const char *cli_command
,
89 const char *const *argv
, int argc
);
90 static bool register_changed_p (int regnum
, readonly_detached_regcache
*,
91 readonly_detached_regcache
*);
92 static void output_register (frame_info_ptr
, int regnum
, int format
,
93 int skip_unavailable
);
95 /* Controls whether the frontend wants MI in async mode. */
96 static bool mi_async
= false;
98 /* The set command writes to this variable. If the inferior is
99 executing, mi_async is *not* updated. */
100 static bool mi_async_1
= false;
103 set_mi_async_command (const char *args
, int from_tty
,
104 struct cmd_list_element
*c
)
106 if (have_live_inferiors ())
108 mi_async_1
= mi_async
;
109 error (_("Cannot change this setting while the inferior is running."));
112 mi_async
= mi_async_1
;
116 show_mi_async_command (struct ui_file
*file
, int from_tty
,
117 struct cmd_list_element
*c
,
121 _("Whether MI is in asynchronous mode is %s.\n"),
125 /* A wrapper for target_can_async_p that takes the MI setting into
131 return mi_async
&& target_can_async_p ();
134 /* Command implementations. FIXME: Is this libgdb? No. This is the MI
135 layer that calls libgdb. Any operation used in the below should be
138 static void timestamp (struct mi_timestamp
*tv
);
140 static void print_diff (struct ui_file
*file
, struct mi_timestamp
*start
,
141 struct mi_timestamp
*end
);
144 mi_cmd_gdb_exit (const char *command
, const char *const *argv
, int argc
)
146 struct mi_interp
*mi
= as_mi_interp (current_interpreter ());
148 /* If the current interpreter is not an MI interpreter, then just
149 don't bother printing anything. This case can arise from using
150 the Python gdb.execute_mi function -- but here the result does
151 not matter, as gdb is about to exit anyway. */
154 /* We have to print everything right here because we never return. */
155 if (mi
->current_token
)
156 gdb_puts (mi
->current_token
, mi
->raw_stdout
);
157 gdb_puts ("^exit\n", mi
->raw_stdout
);
158 mi_out_put (current_uiout
, mi
->raw_stdout
);
159 gdb_flush (mi
->raw_stdout
);
161 /* FIXME: The function called is not yet a formal libgdb function. */
162 quit_force (NULL
, FROM_TTY
);
166 mi_cmd_exec_next (const char *command
, const char *const *argv
, int argc
)
168 /* FIXME: Should call a libgdb function, not a cli wrapper. */
169 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
170 mi_execute_async_cli_command ("reverse-next", argv
+ 1, argc
- 1);
172 mi_execute_async_cli_command ("next", argv
, argc
);
176 mi_cmd_exec_next_instruction (const char *command
, const char *const *argv
,
179 /* FIXME: Should call a libgdb function, not a cli wrapper. */
180 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
181 mi_execute_async_cli_command ("reverse-nexti", argv
+ 1, argc
- 1);
183 mi_execute_async_cli_command ("nexti", argv
, argc
);
187 mi_cmd_exec_step (const char *command
, const char *const *argv
, int argc
)
189 /* FIXME: Should call a libgdb function, not a cli wrapper. */
190 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
191 mi_execute_async_cli_command ("reverse-step", argv
+ 1, argc
- 1);
193 mi_execute_async_cli_command ("step", argv
, argc
);
197 mi_cmd_exec_step_instruction (const char *command
, const char *const *argv
,
200 /* FIXME: Should call a libgdb function, not a cli wrapper. */
201 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
202 mi_execute_async_cli_command ("reverse-stepi", argv
+ 1, argc
- 1);
204 mi_execute_async_cli_command ("stepi", argv
, argc
);
208 mi_cmd_exec_finish (const char *command
, const char *const *argv
, int argc
)
210 /* FIXME: Should call a libgdb function, not a cli wrapper. */
211 if (argc
> 0 && strcmp(argv
[0], "--reverse") == 0)
212 mi_execute_async_cli_command ("reverse-finish", argv
+ 1, argc
- 1);
214 mi_execute_async_cli_command ("finish", argv
, argc
);
218 mi_cmd_exec_return (const char *command
, const char *const *argv
, int argc
)
220 /* This command doesn't really execute the target, it just pops the
221 specified number of frames. */
223 /* Call return_command with from_tty argument equal to 0 so as to
224 avoid being queried. */
225 return_command (*argv
, 0);
227 /* Call return_command with from_tty argument equal to 0 so as to
228 avoid being queried. */
229 return_command (NULL
, 0);
231 /* Because we have called return_command with from_tty = 0, we need
232 to print the frame here. */
233 print_stack_frame (get_selected_frame (NULL
), 1, LOC_AND_ADDRESS
, 1);
237 mi_cmd_exec_jump (const char *args
, const char *const *argv
, int argc
)
239 /* FIXME: Should call a libgdb function, not a cli wrapper. */
240 mi_execute_async_cli_command ("jump", argv
, argc
);
244 proceed_thread (struct thread_info
*thread
, int pid
)
246 if (thread
->state
!= THREAD_STOPPED
)
249 if (pid
!= 0 && thread
->ptid
.pid () != pid
)
252 switch_to_thread (thread
);
253 clear_proceed_status (0);
254 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
258 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
260 int pid
= *(int *)arg
;
262 proceed_thread (thread
, pid
);
267 exec_continue (const char *const *argv
, int argc
)
269 prepare_execution_command (current_inferior ()->top_target (), mi_async_p ());
274 /* In non-stop mode, 'resume' always resumes a single thread.
275 Therefore, to resume all threads of the current inferior, or
276 all threads in all inferiors, we need to iterate over
279 See comment on infcmd.c:proceed_thread_callback for rationale. */
280 if (current_context
->all
|| current_context
->thread_group
!= -1)
282 scoped_restore_current_thread restore_thread
;
283 scoped_disable_commit_resumed disable_commit_resumed
284 ("MI continue all threads in non-stop");
287 if (!current_context
->all
)
290 = find_inferior_id (current_context
->thread_group
);
295 iterate_over_threads (proceed_thread_callback
, &pid
);
296 disable_commit_resumed
.reset_and_commit ();
305 scoped_restore save_multi
= make_scoped_restore (&sched_multi
);
307 if (current_context
->all
)
314 /* In all-stop mode, -exec-continue traditionally resumed
315 either all threads, or one thread, depending on the
316 'scheduler-locking' variable. Let's continue to do the
324 exec_reverse_continue (const char *const *argv
, int argc
)
326 enum exec_direction_kind dir
= execution_direction
;
328 if (dir
== EXEC_REVERSE
)
329 error (_("Already in reverse mode."));
331 if (!target_can_execute_reverse ())
332 error (_("Target %s does not support this command."), target_shortname ());
334 scoped_restore save_exec_dir
= make_scoped_restore (&execution_direction
,
336 exec_continue (argv
, argc
);
340 mi_cmd_exec_continue (const char *command
, const char *const *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 (thread
->state
!= THREAD_RUNNING
)
356 if (thread
->ptid
.pid () != 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 (const char *command
, const char *const *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 scoped_disable_commit_resumed disable_commit_resumed
390 ("interrupting all threads of thread group");
392 iterate_over_threads (interrupt_thread_callback
, &inf
->pid
);
396 /* Interrupt just the current thread -- either explicitly
397 specified via --thread or whatever was current before
398 MI command was sent. */
399 interrupt_target_1 (0);
403 /* Start the execution of the given inferior.
405 START_P indicates whether the program should be stopped when reaching the
406 main subprogram (similar to what the CLI "start" command does). */
409 run_one_inferior (inferior
*inf
, bool start_p
)
411 const char *run_cmd
= start_p
? "start" : "run";
412 struct target_ops
*run_target
= find_run_target ();
413 bool async_p
= mi_async
&& target_can_async_p (run_target
);
417 thread_info
*tp
= any_thread_of_inferior (inf
);
419 error (_("Inferior has no threads."));
421 switch_to_thread (tp
);
424 switch_to_inferior_no_thread (inf
);
425 mi_execute_cli_command (run_cmd
, async_p
,
426 async_p
? "&" : NULL
);
430 mi_cmd_exec_run (const char *command
, const char *const *argv
, int argc
)
434 /* Parse the command options. */
439 static const struct mi_opt opts
[] =
441 {"-start", START_OPT
, 0},
450 int opt
= mi_getopt ("-exec-run", argc
, argv
, opts
, &oind
, &oarg
);
454 switch ((enum opt
) opt
)
462 /* This command does not accept any argument. Make sure the user
463 did not provide any. */
465 error (_("Invalid argument: %s"), argv
[oind
]);
467 if (current_context
->all
)
469 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
471 for (inferior
*inf
: all_inferiors ())
472 run_one_inferior (inf
, start_p
);
476 const char *run_cmd
= start_p
? "start" : "run";
477 struct target_ops
*run_target
= find_run_target ();
478 bool async_p
= mi_async
&& target_can_async_p (run_target
);
480 mi_execute_cli_command (run_cmd
, async_p
,
481 async_p
? "&" : NULL
);
487 find_thread_of_process (struct thread_info
*ti
, void *p
)
491 if (ti
->ptid
.pid () == pid
&& ti
->state
!= THREAD_EXITED
)
498 mi_cmd_target_detach (const char *command
, const char *const *argv
, int argc
)
500 if (argc
!= 0 && argc
!= 1)
501 error (_("Usage: -target-detach [pid | thread-group]"));
505 struct thread_info
*tp
;
509 /* First see if we are dealing with a thread-group id. */
512 struct inferior
*inf
;
513 int id
= strtoul (argv
[0] + 1, &end
, 0);
516 error (_("Invalid syntax of thread-group id '%s'"), argv
[0]);
518 inf
= find_inferior_id (id
);
520 error (_("Non-existent thread-group id '%d'"), id
);
526 /* We must be dealing with a pid. */
527 pid
= strtol (argv
[0], &end
, 10);
530 error (_("Invalid identifier '%s'"), argv
[0]);
533 /* Pick any thread in the desired process. Current
534 target_detach detaches from the parent of inferior_ptid. */
535 tp
= iterate_over_threads (find_thread_of_process
, &pid
);
537 error (_("Thread group is empty"));
539 switch_to_thread (tp
);
542 detach_command (NULL
, 0);
546 mi_cmd_target_flash_erase (const char *command
, const char *const *argv
,
549 flash_erase_command (NULL
, 0);
553 mi_cmd_thread_select (const char *command
, const char *const *argv
, int argc
)
556 error (_("-thread-select: USAGE: threadnum."));
558 int num
= value_as_long (parse_and_eval (argv
[0]));
559 thread_info
*thr
= find_thread_global_id (num
);
561 error (_("Thread ID %d not known."), num
);
563 thread_select (argv
[0], thr
);
565 print_selected_thread_frame (current_uiout
,
566 USER_SELECTED_THREAD
| USER_SELECTED_FRAME
);
570 mi_cmd_thread_list_ids (const char *command
, const char *const *argv
, int argc
)
573 error (_("-thread-list-ids: No arguments required."));
576 int current_thread
= -1;
578 update_thread_list ();
581 ui_out_emit_tuple
tuple_emitter (current_uiout
, "thread-ids");
583 for (thread_info
*tp
: all_non_exited_threads ())
585 if (tp
->ptid
== inferior_ptid
)
586 current_thread
= tp
->global_num
;
589 current_uiout
->field_signed ("thread-id", tp
->global_num
);
593 if (current_thread
!= -1)
594 current_uiout
->field_signed ("current-thread-id", current_thread
);
595 current_uiout
->field_signed ("number-of-threads", num
);
599 mi_cmd_thread_info (const char *command
, const char *const *argv
, int argc
)
601 if (argc
!= 0 && argc
!= 1)
602 error (_("Invalid MI command"));
604 print_thread_info (current_uiout
, argv
[0], -1);
607 struct collect_cores_data
614 collect_cores (struct thread_info
*ti
, void *xdata
)
616 struct collect_cores_data
*data
= (struct collect_cores_data
*) xdata
;
618 if (ti
->ptid
.pid () == data
->pid
)
620 int core
= target_core_of_thread (ti
->ptid
);
623 data
->cores
.insert (core
);
629 struct print_one_inferior_data
632 const std::set
<int> *inferiors
;
636 print_one_inferior (struct inferior
*inferior
, bool recurse
,
637 const std::set
<int> &ids
)
639 struct ui_out
*uiout
= current_uiout
;
641 if (ids
.empty () || (ids
.find (inferior
->pid
) != ids
.end ()))
643 struct collect_cores_data data
;
644 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
646 uiout
->field_fmt ("id", "i%d", inferior
->num
);
647 uiout
->field_string ("type", "process");
648 if (inferior
->has_exit_code
)
649 uiout
->field_string ("exit-code",
650 int_string (inferior
->exit_code
, 8, 0, 0, 1));
651 if (inferior
->pid
!= 0)
652 uiout
->field_signed ("pid", inferior
->pid
);
654 if (inferior
->pspace
->exec_filename
!= nullptr)
656 uiout
->field_string ("executable",
657 inferior
->pspace
->exec_filename
.get ());
660 if (inferior
->pid
!= 0)
662 data
.pid
= inferior
->pid
;
663 iterate_over_threads (collect_cores
, &data
);
666 if (!data
.cores
.empty ())
668 ui_out_emit_list
list_emitter (uiout
, "cores");
670 for (int b
: data
.cores
)
671 uiout
->field_signed (NULL
, b
);
675 print_thread_info (uiout
, NULL
, inferior
->pid
);
679 /* Output a field named 'cores' with a list as the value. The
680 elements of the list are obtained by splitting 'cores' on
684 output_cores (struct ui_out
*uiout
, const char *field_name
, const char *xcores
)
686 ui_out_emit_list
list_emitter (uiout
, field_name
);
687 auto cores
= make_unique_xstrdup (xcores
);
688 char *p
= cores
.get ();
691 for (p
= strtok_r (p
, ",", &saveptr
); p
; p
= strtok_r (NULL
, ",", &saveptr
))
692 uiout
->field_string (NULL
, p
);
696 list_available_thread_groups (const std::set
<int> &ids
, int recurse
)
698 struct ui_out
*uiout
= current_uiout
;
700 /* This keeps a map from integer (pid) to vector of struct osdata_item.
701 The vector contains information about all threads for the given pid. */
702 std::map
<int, std::vector
<osdata_item
>> tree
;
704 /* get_osdata will throw if it cannot return data. */
705 std::unique_ptr
<osdata
> data
= get_osdata ("processes");
709 std::unique_ptr
<osdata
> threads
= get_osdata ("threads");
711 for (const osdata_item
&item
: threads
->items
)
713 const std::string
*pid
= get_osdata_column (item
, "pid");
714 int pid_i
= strtoul (pid
->c_str (), NULL
, 0);
716 tree
[pid_i
].push_back (item
);
720 ui_out_emit_list
list_emitter (uiout
, "groups");
722 for (const osdata_item
&item
: data
->items
)
724 const std::string
*pid
= get_osdata_column (item
, "pid");
725 const std::string
*cmd
= get_osdata_column (item
, "command");
726 const std::string
*user
= get_osdata_column (item
, "user");
727 const std::string
*cores
= get_osdata_column (item
, "cores");
729 int pid_i
= strtoul (pid
->c_str (), NULL
, 0);
731 /* At present, the target will return all available processes
732 and if information about specific ones was required, we filter
733 undesired processes here. */
734 if (!ids
.empty () && ids
.find (pid_i
) == ids
.end ())
737 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
739 uiout
->field_string ("id", *pid
);
740 uiout
->field_string ("type", "process");
742 uiout
->field_string ("description", *cmd
);
744 uiout
->field_string ("user", *user
);
746 output_cores (uiout
, "cores", cores
->c_str ());
750 auto n
= tree
.find (pid_i
);
751 if (n
!= tree
.end ())
753 std::vector
<osdata_item
> &children
= n
->second
;
755 ui_out_emit_list
thread_list_emitter (uiout
, "threads");
757 for (const osdata_item
&child
: children
)
759 ui_out_emit_tuple
inner_tuple_emitter (uiout
, NULL
);
760 const std::string
*tid
= get_osdata_column (child
, "tid");
761 const std::string
*tcore
= get_osdata_column (child
, "core");
763 uiout
->field_string ("id", *tid
);
765 uiout
->field_string ("core", *tcore
);
773 mi_cmd_list_thread_groups (const char *command
, const char *const *argv
,
776 struct ui_out
*uiout
= current_uiout
;
783 AVAILABLE_OPT
, RECURSE_OPT
785 static const struct mi_opt opts
[] =
787 {"-available", AVAILABLE_OPT
, 0},
788 {"-recurse", RECURSE_OPT
, 1},
797 int opt
= mi_getopt ("-list-thread-groups", argc
, argv
, opts
,
802 switch ((enum opt
) opt
)
808 if (strcmp (oarg
, "0") == 0)
810 else if (strcmp (oarg
, "1") == 0)
813 error (_("only '0' and '1' are valid values "
814 "for the '--recurse' option"));
819 for (; oind
< argc
; ++oind
)
824 if (*(argv
[oind
]) != 'i')
825 error (_("invalid syntax of group id '%s'"), argv
[oind
]);
827 inf
= strtoul (argv
[oind
] + 1, &end
, 0);
830 error (_("invalid syntax of group id '%s'"), argv
[oind
]);
836 list_available_thread_groups (ids
, recurse
);
838 else if (ids
.size () == 1)
840 /* Local thread groups, single id. */
841 int id
= *(ids
.begin ());
842 struct inferior
*inf
= find_inferior_id (id
);
845 error (_("Non-existent thread group id '%d'"), id
);
847 print_thread_info (uiout
, NULL
, inf
->pid
);
851 /* Local thread groups. Either no explicit ids -- and we
852 print everything, or several explicit ids. In both cases,
853 we print more than one group, and have to use 'groups'
854 as the top-level element. */
855 ui_out_emit_list
list_emitter (uiout
, "groups");
856 update_thread_list ();
857 for (inferior
*inf
: all_inferiors ())
858 print_one_inferior (inf
, recurse
, ids
);
863 mi_cmd_data_list_register_names (const char *command
, const char *const *argv
,
866 struct gdbarch
*gdbarch
;
867 struct ui_out
*uiout
= current_uiout
;
871 /* Note that the test for a valid register must include checking the
872 gdbarch_register_name because gdbarch_num_regs may be allocated
873 for the union of the register sets within a family of related
874 processors. In this case, some entries of gdbarch_register_name
875 will change depending upon the particular processor being
878 gdbarch
= get_current_arch ();
879 numregs
= gdbarch_num_cooked_regs (gdbarch
);
881 ui_out_emit_list
list_emitter (uiout
, "register-names");
883 if (argc
== 0) /* No args, just do all the regs. */
889 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
890 uiout
->field_string (NULL
, "");
892 uiout
->field_string (NULL
, gdbarch_register_name (gdbarch
, regnum
));
896 /* Else, list of register #s, just do listed regs. */
897 for (i
= 0; i
< argc
; i
++)
899 regnum
= atoi (argv
[i
]);
900 if (regnum
< 0 || regnum
>= numregs
)
901 error (_("bad register number"));
903 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
904 uiout
->field_string (NULL
, "");
906 uiout
->field_string (NULL
, gdbarch_register_name (gdbarch
, regnum
));
911 mi_cmd_data_list_changed_registers (const char *command
,
912 const char *const *argv
, int argc
)
914 static std::unique_ptr
<readonly_detached_regcache
> this_regs
;
915 struct ui_out
*uiout
= current_uiout
;
916 std::unique_ptr
<readonly_detached_regcache
> prev_regs
;
917 struct gdbarch
*gdbarch
;
921 /* The last time we visited this function, the current frame's
922 register contents were saved in THIS_REGS. Move THIS_REGS over
923 to PREV_REGS, and refresh THIS_REGS with the now-current register
926 prev_regs
= std::move (this_regs
);
927 this_regs
= frame_save_as_regcache (get_selected_frame (NULL
));
929 /* Note that the test for a valid register must include checking the
930 gdbarch_register_name because gdbarch_num_regs may be allocated
931 for the union of the register sets within a family of related
932 processors. In this case, some entries of gdbarch_register_name
933 will change depending upon the particular processor being
936 gdbarch
= this_regs
->arch ();
937 numregs
= gdbarch_num_cooked_regs (gdbarch
);
939 ui_out_emit_list
list_emitter (uiout
, "changed-registers");
943 /* No args, just do all the regs. */
948 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
951 if (register_changed_p (regnum
, prev_regs
.get (),
953 uiout
->field_signed (NULL
, regnum
);
957 /* Else, list of register #s, just do listed regs. */
958 for (i
= 0; i
< argc
; i
++)
960 regnum
= atoi (argv
[i
]);
964 && *gdbarch_register_name (gdbarch
, regnum
) != '\000')
966 if (register_changed_p (regnum
, prev_regs
.get (),
968 uiout
->field_signed (NULL
, regnum
);
971 error (_("bad register number"));
976 register_changed_p (int regnum
, readonly_detached_regcache
*prev_regs
,
977 readonly_detached_regcache
*this_regs
)
979 struct gdbarch
*gdbarch
= this_regs
->arch ();
980 struct value
*prev_value
, *this_value
;
982 /* First time through or after gdbarch change consider all registers
984 if (!prev_regs
|| prev_regs
->arch () != gdbarch
)
987 /* Get register contents and compare. */
988 prev_value
= prev_regs
->cooked_read_value (regnum
);
989 this_value
= this_regs
->cooked_read_value (regnum
);
990 gdb_assert (prev_value
!= NULL
);
991 gdb_assert (this_value
!= NULL
);
993 auto ret
= !prev_value
->contents_eq (0, this_value
, 0,
994 register_size (gdbarch
, regnum
));
996 release_value (prev_value
);
997 release_value (this_value
);
1001 /* Return a list of register number and value pairs. The valid
1002 arguments expected are: a letter indicating the format in which to
1003 display the registers contents. This can be one of: x
1004 (hexadecimal), d (decimal), N (natural), t (binary), o (octal), r
1005 (raw). After the format argument there can be a sequence of
1006 numbers, indicating which registers to fetch the content of. If
1007 the format is the only argument, a list of all the registers with
1008 their values is returned. */
1011 mi_cmd_data_list_register_values (const char *command
, const char *const *argv
,
1014 struct ui_out
*uiout
= current_uiout
;
1015 frame_info_ptr frame
;
1016 struct gdbarch
*gdbarch
;
1017 int regnum
, numregs
, format
;
1019 int skip_unavailable
= 0;
1025 static const struct mi_opt opts
[] =
1027 {"-skip-unavailable", SKIP_UNAVAILABLE
, 0},
1031 /* Note that the test for a valid register must include checking the
1032 gdbarch_register_name because gdbarch_num_regs may be allocated
1033 for the union of the register sets within a family of related
1034 processors. In this case, some entries of gdbarch_register_name
1035 will change depending upon the particular processor being
1041 int opt
= mi_getopt ("-data-list-register-values", argc
, argv
,
1042 opts
, &oind
, &oarg
);
1046 switch ((enum opt
) opt
)
1048 case SKIP_UNAVAILABLE
:
1049 skip_unavailable
= 1;
1054 if (argc
- oind
< 1)
1055 error (_("-data-list-register-values: Usage: "
1056 "-data-list-register-values [--skip-unavailable] <format>"
1057 " [<regnum1>...<regnumN>]"));
1059 format
= (int) argv
[oind
][0];
1061 frame
= get_selected_frame (NULL
);
1062 gdbarch
= get_frame_arch (frame
);
1063 numregs
= gdbarch_num_cooked_regs (gdbarch
);
1065 ui_out_emit_list
list_emitter (uiout
, "register-values");
1067 if (argc
- oind
== 1)
1069 /* No args, beside the format: do all the regs. */
1074 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
1077 output_register (frame
, regnum
, format
, skip_unavailable
);
1081 /* Else, list of register #s, just do listed regs. */
1082 for (i
= 1 + oind
; i
< argc
; i
++)
1084 regnum
= atoi (argv
[i
]);
1088 && *gdbarch_register_name (gdbarch
, regnum
) != '\000')
1089 output_register (frame
, regnum
, format
, skip_unavailable
);
1091 error (_("bad register number"));
1095 /* Output one register REGNUM's contents in the desired FORMAT. If
1096 SKIP_UNAVAILABLE is true, skip the register if it is
1100 output_register (frame_info_ptr frame
, int regnum
, int format
,
1101 int skip_unavailable
)
1103 struct ui_out
*uiout
= current_uiout
;
1104 struct value
*val
= value_of_register (regnum
, frame
);
1105 struct value_print_options opts
;
1107 if (skip_unavailable
&& !val
->entirely_available ())
1110 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1111 uiout
->field_signed ("number", regnum
);
1121 get_formatted_print_options (&opts
, format
);
1122 opts
.deref_ref
= true;
1123 common_val_print (val
, &stb
, 0, &opts
, current_language
);
1124 uiout
->field_stream ("value", stb
);
1127 /* Write given values into registers. The registers and values are
1128 given as pairs. The corresponding MI command is
1129 -data-write-register-values <format>
1130 [<regnum1> <value1>...<regnumN> <valueN>] */
1132 mi_cmd_data_write_register_values (const char *command
,
1133 const char *const *argv
, int argc
)
1135 struct regcache
*regcache
;
1136 struct gdbarch
*gdbarch
;
1139 /* Note that the test for a valid register must include checking the
1140 gdbarch_register_name because gdbarch_num_regs may be allocated
1141 for the union of the register sets within a family of related
1142 processors. In this case, some entries of gdbarch_register_name
1143 will change depending upon the particular processor being
1146 regcache
= get_current_regcache ();
1147 gdbarch
= regcache
->arch ();
1148 numregs
= gdbarch_num_cooked_regs (gdbarch
);
1151 error (_("-data-write-register-values: Usage: -data-write-register-"
1152 "values <format> [<regnum1> <value1>...<regnumN> <valueN>]"));
1154 if (!target_has_registers ())
1155 error (_("-data-write-register-values: No registers."));
1158 error (_("-data-write-register-values: No regs and values specified."));
1161 error (_("-data-write-register-values: "
1162 "Regs and vals are not in pairs."));
1164 for (i
= 1; i
< argc
; i
= i
+ 2)
1166 int regnum
= atoi (argv
[i
]);
1168 if (regnum
>= 0 && regnum
< numregs
1169 && *gdbarch_register_name (gdbarch
, regnum
) != '\0')
1173 /* Get the value as a number. */
1174 value
= parse_and_eval_address (argv
[i
+ 1]);
1176 /* Write it down. */
1177 regcache_cooked_write_signed (regcache
, regnum
, value
);
1180 error (_("bad register number"));
1184 /* Evaluate the value of the argument. The argument is an
1185 expression. If the expression contains spaces it needs to be
1186 included in double quotes. */
1189 mi_cmd_data_evaluate_expression (const char *command
, const char *const *argv
,
1193 struct value_print_options opts
;
1194 struct ui_out
*uiout
= current_uiout
;
1197 error (_("-data-evaluate-expression: "
1198 "Usage: -data-evaluate-expression expression"));
1200 expression_up expr
= parse_expression (argv
[0]);
1202 val
= expr
->evaluate ();
1206 /* Print the result of the expression evaluation. */
1207 get_user_print_options (&opts
);
1208 opts
.deref_ref
= false;
1209 common_val_print (val
, &stb
, 0, &opts
, current_language
);
1211 uiout
->field_stream ("value", stb
);
1214 /* This is the -data-read-memory command.
1216 ADDR: start address of data to be dumped.
1217 WORD-FORMAT: a char indicating format for the ``word''. See
1219 WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes.
1220 NR_ROW: Number of rows.
1221 NR_COL: The number of columns (words per row).
1222 ASCHAR: (OPTIONAL) Append an ascii character dump to each row. Use
1223 ASCHAR for unprintable characters.
1225 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
1226 displays them. Returns:
1228 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
1231 The number of bytes read is SIZE*ROW*COL. */
1234 mi_cmd_data_read_memory (const char *command
, const char *const *argv
,
1237 struct gdbarch
*gdbarch
= get_current_arch ();
1238 struct ui_out
*uiout
= current_uiout
;
1240 long total_bytes
, nr_cols
, nr_rows
;
1242 struct type
*word_type
;
1254 static const struct mi_opt opts
[] =
1256 {"o", OFFSET_OPT
, 1},
1262 int opt
= mi_getopt ("-data-read-memory", argc
, argv
, opts
,
1267 switch ((enum opt
) opt
)
1270 offset
= atol (oarg
);
1277 if (argc
< 5 || argc
> 6)
1278 error (_("-data-read-memory: Usage: "
1279 "ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR]."));
1281 /* Extract all the arguments. */
1283 /* Start address of the memory dump. */
1284 addr
= parse_and_eval_address (argv
[0]) + offset
;
1285 /* The format character to use when displaying a memory word. See
1286 the ``x'' command. */
1287 word_format
= argv
[1][0];
1288 /* The size of the memory word. */
1289 word_size
= atol (argv
[2]);
1293 word_type
= builtin_type (gdbarch
)->builtin_int8
;
1297 word_type
= builtin_type (gdbarch
)->builtin_int16
;
1301 word_type
= builtin_type (gdbarch
)->builtin_int32
;
1305 word_type
= builtin_type (gdbarch
)->builtin_int64
;
1309 word_type
= builtin_type (gdbarch
)->builtin_int8
;
1312 /* The number of rows. */
1313 nr_rows
= atol (argv
[3]);
1315 error (_("-data-read-memory: invalid number of rows."));
1317 /* Number of bytes per row. */
1318 nr_cols
= atol (argv
[4]);
1320 error (_("-data-read-memory: invalid number of columns."));
1322 /* The un-printable character when printing ascii. */
1328 /* Create a buffer and read it in. */
1329 total_bytes
= word_size
* nr_rows
* nr_cols
;
1331 gdb::byte_vector
mbuf (total_bytes
);
1333 nr_bytes
= target_read (current_inferior ()->top_target (),
1334 TARGET_OBJECT_MEMORY
, NULL
,
1335 mbuf
.data (), addr
, total_bytes
);
1337 error (_("Unable to read memory."));
1339 /* Output the header information. */
1340 uiout
->field_core_addr ("addr", gdbarch
, addr
);
1341 uiout
->field_signed ("nr-bytes", nr_bytes
);
1342 uiout
->field_signed ("total-bytes", total_bytes
);
1343 uiout
->field_core_addr ("next-row", gdbarch
, addr
+ word_size
* nr_cols
);
1344 uiout
->field_core_addr ("prev-row", gdbarch
, addr
- word_size
* nr_cols
);
1345 uiout
->field_core_addr ("next-page", gdbarch
, addr
+ total_bytes
);
1346 uiout
->field_core_addr ("prev-page", gdbarch
, addr
- total_bytes
);
1348 /* Build the result as a two dimensional table. */
1355 ui_out_emit_list
list_emitter (uiout
, "memory");
1356 for (row
= 0, row_byte
= 0;
1358 row
++, row_byte
+= nr_cols
* word_size
)
1362 struct value_print_options print_opts
;
1364 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1365 uiout
->field_core_addr ("addr", gdbarch
, addr
+ row_byte
);
1366 /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr +
1369 ui_out_emit_list
list_data_emitter (uiout
, "data");
1370 get_formatted_print_options (&print_opts
, word_format
);
1371 for (col
= 0, col_byte
= row_byte
;
1373 col
++, col_byte
+= word_size
)
1375 if (col_byte
+ word_size
> nr_bytes
)
1377 uiout
->field_string (NULL
, "N/A");
1382 print_scalar_formatted (&mbuf
[col_byte
], word_type
,
1383 &print_opts
, word_asize
, &stream
);
1384 uiout
->field_stream (NULL
, stream
);
1394 for (byte
= row_byte
;
1395 byte
< row_byte
+ word_size
* nr_cols
; byte
++)
1397 if (byte
>= nr_bytes
)
1399 else if (mbuf
[byte
] < 32 || mbuf
[byte
] > 126)
1400 stream
.putc (aschar
);
1402 stream
.putc (mbuf
[byte
]);
1404 uiout
->field_stream ("ascii", stream
);
1411 mi_cmd_data_read_memory_bytes (const char *command
, const char *const *argv
,
1414 struct gdbarch
*gdbarch
= get_current_arch ();
1415 struct ui_out
*uiout
= current_uiout
;
1419 int unit_size
= gdbarch_addressable_memory_unit_size (gdbarch
);
1426 static const struct mi_opt opts
[] =
1428 {"o", OFFSET_OPT
, 1},
1434 int opt
= mi_getopt ("-data-read-memory-bytes", argc
, argv
, opts
,
1438 switch ((enum opt
) opt
)
1441 offset
= atol (oarg
);
1449 error (_("Usage: [ -o OFFSET ] ADDR LENGTH."));
1451 addr
= parse_and_eval_address (argv
[0]) + offset
;
1452 length
= atol (argv
[1]);
1454 std::vector
<memory_read_result
> result
1455 = read_memory_robust (current_inferior ()->top_target (), addr
, length
);
1457 if (result
.size () == 0)
1458 error (_("Unable to read memory."));
1460 ui_out_emit_list
list_emitter (uiout
, "memory");
1461 for (const memory_read_result
&read_result
: result
)
1463 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1465 uiout
->field_core_addr ("begin", gdbarch
, read_result
.begin
);
1466 uiout
->field_core_addr ("offset", gdbarch
, read_result
.begin
- addr
);
1467 uiout
->field_core_addr ("end", gdbarch
, read_result
.end
);
1469 std::string data
= bin2hex (read_result
.data
.get (),
1470 (read_result
.end
- read_result
.begin
)
1472 uiout
->field_string ("contents", data
);
1476 /* Implementation of the -data-write_memory command.
1478 COLUMN_OFFSET: optional argument. Must be preceded by '-o'. The
1479 offset from the beginning of the memory grid row where the cell to
1481 ADDR: start address of the row in the memory grid where the memory
1482 cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
1483 the location to write to.
1484 FORMAT: a char indicating format for the ``word''. See
1486 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
1487 VALUE: value to be written into the memory address.
1489 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
1494 mi_cmd_data_write_memory (const char *command
, const char *const *argv
,
1497 struct gdbarch
*gdbarch
= get_current_arch ();
1498 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1501 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
1502 enough when using a compiler other than GCC. */
1511 static const struct mi_opt opts
[] =
1513 {"o", OFFSET_OPT
, 1},
1519 int opt
= mi_getopt ("-data-write-memory", argc
, argv
, opts
,
1524 switch ((enum opt
) opt
)
1527 offset
= atol (oarg
);
1535 error (_("-data-write-memory: Usage: "
1536 "[-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE."));
1538 /* Extract all the arguments. */
1539 /* Start address of the memory dump. */
1540 addr
= parse_and_eval_address (argv
[0]);
1541 /* The size of the memory word. */
1542 word_size
= atol (argv
[2]);
1544 /* Calculate the real address of the write destination. */
1545 addr
+= (offset
* word_size
);
1547 /* Get the value as a number. */
1548 value
= parse_and_eval_address (argv
[3]);
1549 /* Get the value into an array. */
1550 gdb::byte_vector
buffer (word_size
);
1551 store_signed_integer (buffer
.data (), word_size
, byte_order
, value
);
1552 /* Write it down to memory. */
1553 write_memory_with_notification (addr
, buffer
.data (), word_size
);
1556 /* Implementation of the -data-write-memory-bytes command.
1559 DATA: string of bytes to write at that address
1560 COUNT: number of bytes to be filled (decimal integer). */
1563 mi_cmd_data_write_memory_bytes (const char *command
, const char *const *argv
,
1568 size_t len_hex
, len_bytes
, len_units
, i
, steps
, remaining_units
;
1569 long int count_units
;
1572 if (argc
!= 2 && argc
!= 3)
1573 error (_("Usage: ADDR DATA [COUNT]."));
1575 addr
= parse_and_eval_address (argv
[0]);
1577 len_hex
= strlen (cdata
);
1578 unit_size
= gdbarch_addressable_memory_unit_size (get_current_arch ());
1580 if (len_hex
% (unit_size
* 2) != 0)
1581 error (_("Hex-encoded '%s' must represent an integral number of "
1582 "addressable memory units."),
1585 len_bytes
= len_hex
/ 2;
1586 len_units
= len_bytes
/ unit_size
;
1589 count_units
= strtoul (argv
[2], NULL
, 10);
1591 count_units
= len_units
;
1593 gdb::byte_vector
databuf (len_bytes
);
1595 for (i
= 0; i
< len_bytes
; ++i
)
1598 if (sscanf (cdata
+ i
* 2, "%02x", &x
) != 1)
1599 error (_("Invalid argument"));
1600 databuf
[i
] = (gdb_byte
) x
;
1603 gdb::byte_vector data
;
1604 if (len_units
< count_units
)
1606 /* Pattern is made of less units than count:
1607 repeat pattern to fill memory. */
1608 data
= gdb::byte_vector (count_units
* unit_size
);
1610 /* Number of times the pattern is entirely repeated. */
1611 steps
= count_units
/ len_units
;
1612 /* Number of remaining addressable memory units. */
1613 remaining_units
= count_units
% len_units
;
1614 for (i
= 0; i
< steps
; i
++)
1615 memcpy (&data
[i
* len_bytes
], &databuf
[0], len_bytes
);
1617 if (remaining_units
> 0)
1618 memcpy (&data
[steps
* len_bytes
], &databuf
[0],
1619 remaining_units
* unit_size
);
1623 /* Pattern is longer than or equal to count:
1624 just copy count addressable memory units. */
1625 data
= std::move (databuf
);
1628 write_memory_with_notification (addr
, data
.data (), count_units
);
1632 mi_cmd_enable_timings (const char *command
, const char *const *argv
, int argc
)
1638 if (strcmp (argv
[0], "yes") == 0)
1640 else if (strcmp (argv
[0], "no") == 0)
1651 error (_("-enable-timings: Usage: %s {yes|no}"), command
);
1655 mi_cmd_list_features (const char *command
, const char *const *argv
, int argc
)
1659 struct ui_out
*uiout
= current_uiout
;
1661 ui_out_emit_list
list_emitter (uiout
, "features");
1662 uiout
->field_string (NULL
, "frozen-varobjs");
1663 uiout
->field_string (NULL
, "pending-breakpoints");
1664 uiout
->field_string (NULL
, "thread-info");
1665 uiout
->field_string (NULL
, "data-read-memory-bytes");
1666 uiout
->field_string (NULL
, "breakpoint-notifications");
1667 uiout
->field_string (NULL
, "ada-task-info");
1668 uiout
->field_string (NULL
, "language-option");
1669 uiout
->field_string (NULL
, "info-gdb-mi-command");
1670 uiout
->field_string (NULL
, "undefined-command-error-code");
1671 uiout
->field_string (NULL
, "exec-run-start-option");
1672 uiout
->field_string (NULL
, "data-disassemble-a-option");
1673 uiout
->field_string (NULL
, "simple-values-ref-types");
1675 if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON
)))
1676 uiout
->field_string (NULL
, "python");
1681 error (_("-list-features should be passed no arguments"));
1685 mi_cmd_list_target_features (const char *command
, const char *const *argv
,
1690 struct ui_out
*uiout
= current_uiout
;
1692 ui_out_emit_list
list_emitter (uiout
, "features");
1694 uiout
->field_string (NULL
, "async");
1695 if (target_can_execute_reverse ())
1696 uiout
->field_string (NULL
, "reverse");
1700 error (_("-list-target-features should be passed no arguments"));
1704 mi_cmd_add_inferior (const char *command
, const char *const *argv
, int argc
)
1706 bool no_connection
= false;
1708 /* Parse the command options. */
1713 static const struct mi_opt opts
[] =
1715 {"-no-connection", NO_CONNECTION_OPT
, 0},
1724 int opt
= mi_getopt ("-add-inferior", argc
, argv
, opts
, &oind
, &oarg
);
1728 switch ((enum opt
) opt
)
1730 case NO_CONNECTION_OPT
:
1731 no_connection
= true;
1736 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
1738 inferior
*inf
= add_inferior_with_spaces ();
1740 switch_to_inferior_and_push_target (inf
, no_connection
,
1741 current_inferior ());
1743 current_uiout
->field_fmt ("inferior", "i%d", inf
->num
);
1745 process_stratum_target
*proc_target
= inf
->process_target ();
1747 if (proc_target
!= nullptr)
1749 ui_out_emit_tuple
tuple_emitter (current_uiout
, "connection");
1750 current_uiout
->field_unsigned ("number", proc_target
->connection_number
);
1751 current_uiout
->field_string ("name", proc_target
->shortname ());
1756 mi_cmd_remove_inferior (const char *command
, const char *const *argv
, int argc
)
1759 struct inferior
*inf_to_remove
;
1762 error (_("-remove-inferior should be passed a single argument"));
1764 id
= mi_parse_thread_group_id (argv
[0]);
1766 inf_to_remove
= find_inferior_id (id
);
1767 if (inf_to_remove
== NULL
)
1768 error (_("the specified thread group does not exist"));
1770 if (inf_to_remove
->pid
!= 0)
1771 error (_("cannot remove an active inferior"));
1773 if (inf_to_remove
== current_inferior ())
1775 struct thread_info
*tp
= 0;
1776 struct inferior
*new_inferior
= NULL
;
1778 for (inferior
*inf
: all_inferiors ())
1780 if (inf
!= inf_to_remove
)
1784 if (new_inferior
== NULL
)
1785 error (_("Cannot remove last inferior"));
1787 set_current_inferior (new_inferior
);
1788 if (new_inferior
->pid
!= 0)
1789 tp
= any_thread_of_inferior (new_inferior
);
1791 switch_to_thread (tp
);
1793 switch_to_no_thread ();
1794 set_current_program_space (new_inferior
->pspace
);
1797 delete_inferior (inf_to_remove
);
1802 /* Execute a command within a safe environment.
1803 Return <0 for error; >=0 for ok.
1805 args->action will tell mi_execute_command what action
1806 to perform after the given command has executed (display/suppress
1807 prompt, display error). */
1810 captured_mi_execute_command (struct mi_interp
*mi
, struct ui_out
*uiout
,
1811 struct mi_parse
*context
)
1814 current_command_ts
= context
->cmd_start
;
1816 scoped_restore save_token
1817 = make_scoped_restore (&mi
->current_token
, context
->token
.c_str ());
1819 mi
->running_result_record_printed
= 0;
1820 mi
->mi_proceeded
= 0;
1821 switch (context
->op
)
1824 /* A MI command was read from the input stream. */
1826 gdb_printf (gdb_stdlog
,
1827 " token=`%s' command=`%s' args=`%s'\n",
1828 context
->token
.c_str (), context
->command
.get (),
1831 mi_cmd_execute (context
);
1833 /* Print the result if there were no errors.
1835 Remember that on the way out of executing a command, you have
1836 to directly use the mi_interp's uiout, since the command
1837 could have reset the interpreter, in which case the current
1838 uiout will most likely crash in the mi_out_* routines. */
1839 if (!mi
->running_result_record_printed
)
1841 gdb_puts (context
->token
.c_str (), mi
->raw_stdout
);
1842 /* There's no particularly good reason why target-connect results
1843 in not ^done. Should kill ^connected for MI3. */
1844 gdb_puts (strcmp (context
->command
.get (), "target-select") == 0
1845 ? "^connected" : "^done", mi
->raw_stdout
);
1846 mi_out_put (uiout
, mi
->raw_stdout
);
1847 mi_out_rewind (uiout
);
1848 mi_print_timing_maybe (mi
->raw_stdout
);
1849 gdb_puts ("\n", mi
->raw_stdout
);
1852 /* The command does not want anything to be printed. In that
1853 case, the command probably should not have written anything
1854 to uiout, but in case it has written something, discard it. */
1855 mi_out_rewind (uiout
);
1860 const char *argv
[2];
1862 /* A CLI command was read from the input stream. */
1863 /* This "feature" will be removed as soon as we have a
1864 complete set of mi commands. */
1865 /* Echo the command on the console. */
1866 gdb_printf (gdb_stdlog
, "%s\n", context
->command
.get ());
1867 /* Call the "console" interpreter. */
1868 argv
[0] = INTERP_CONSOLE
;
1869 argv
[1] = context
->command
.get ();
1870 mi_cmd_interpreter_exec ("-interpreter-exec", argv
, 2);
1872 /* If we changed interpreters, DON'T print out anything. */
1873 if (current_interp_named_p (INTERP_MI
)
1874 || current_interp_named_p (INTERP_MI2
)
1875 || current_interp_named_p (INTERP_MI3
)
1876 || current_interp_named_p (INTERP_MI4
))
1878 if (!mi
->running_result_record_printed
)
1880 gdb_puts (context
->token
.c_str (), mi
->raw_stdout
);
1881 gdb_puts ("^done", mi
->raw_stdout
);
1882 mi_out_put (uiout
, mi
->raw_stdout
);
1883 mi_out_rewind (uiout
);
1884 mi_print_timing_maybe (mi
->raw_stdout
);
1885 gdb_puts ("\n", mi
->raw_stdout
);
1888 mi_out_rewind (uiout
);
1895 /* Print a gdb exception to the MI output stream. */
1898 mi_print_exception (struct mi_interp
*mi
, const char *token
,
1899 const struct gdb_exception
&exception
)
1901 gdb_puts (token
, mi
->raw_stdout
);
1902 gdb_puts ("^error,msg=\"", mi
->raw_stdout
);
1903 if (exception
.message
== NULL
)
1904 gdb_puts ("unknown error", mi
->raw_stdout
);
1906 mi
->raw_stdout
->putstr (exception
.what (), '"');
1907 gdb_puts ("\"", mi
->raw_stdout
);
1909 switch (exception
.error
)
1911 case UNDEFINED_COMMAND_ERROR
:
1912 gdb_puts (",code=\"undefined-command\"", mi
->raw_stdout
);
1916 gdb_puts ("\n", mi
->raw_stdout
);
1920 mi_execute_command (const char *cmd
, int from_tty
)
1923 std::unique_ptr
<struct mi_parse
> command
;
1925 /* This is to handle EOF (^D). We just quit gdb. */
1926 /* FIXME: we should call some API function here. */
1928 quit_force (NULL
, from_tty
);
1930 target_log_command (cmd
);
1932 struct mi_interp
*mi
1933 = gdb::checked_static_cast
<mi_interp
*> (command_interp ());
1936 command
= gdb::make_unique
<mi_parse
> (cmd
, &token
);
1938 catch (const gdb_exception
&exception
)
1940 mi_print_exception (mi
, token
.c_str (), exception
);
1943 if (command
!= NULL
)
1945 command
->token
= std::move (token
);
1949 command
->cmd_start
= new mi_timestamp ();
1950 timestamp (command
->cmd_start
);
1955 captured_mi_execute_command (mi
, current_uiout
, command
.get ());
1957 catch (const gdb_exception
&result
)
1959 /* Like in start_event_loop, enable input and force display
1960 of the prompt. Otherwise, any command that calls
1961 async_disable_stdin, and then throws, will leave input
1963 async_enable_stdin ();
1964 current_ui
->prompt_state
= PROMPT_NEEDED
;
1966 /* The command execution failed and error() was called
1968 mi_print_exception (mi
, command
->token
.c_str (), result
);
1969 mi_out_rewind (current_uiout
);
1971 /* Throw to a higher level catch for SIGTERM sent to GDB. */
1972 if (result
.reason
== RETURN_FORCED_QUIT
)
1976 bpstat_do_actions ();
1981 /* See mi-cmds.h. */
1984 mi_execute_command (mi_parse
*context
)
1986 if (context
->op
!= MI_COMMAND
)
1987 error (_("Command is not an MI command"));
1989 mi_interp
*mi
= as_mi_interp (current_interpreter ());
1991 /* The current interpreter may not be MI, for instance when using
1992 the Python gdb.execute_mi function. */
1994 scoped_restore save_token
= make_scoped_restore (&mi
->current_token
,
1995 context
->token
.c_str ());
1997 scoped_restore save_debug
= make_scoped_restore (&mi_debug_p
, 0);
1999 mi_cmd_execute (context
);
2002 /* Captures the current user selected context state, that is the current
2003 thread and frame. Later we can then check if the user selected context
2004 has changed at all. */
2006 struct user_selected_context
2009 user_selected_context ()
2010 : m_previous_ptid (inferior_ptid
)
2012 save_selected_frame (&m_previous_frame_id
, &m_previous_frame_level
);
2015 /* Return true if the user selected context has changed since this object
2017 bool has_changed () const
2019 /* Did the selected thread change? */
2020 if (m_previous_ptid
!= null_ptid
&& inferior_ptid
!= null_ptid
2021 && m_previous_ptid
!= inferior_ptid
)
2024 /* Grab details of the currently selected frame, for comparison. */
2025 frame_id current_frame_id
;
2026 int current_frame_level
;
2027 save_selected_frame (¤t_frame_id
, ¤t_frame_level
);
2029 /* Did the selected frame level change? */
2030 if (current_frame_level
!= m_previous_frame_level
)
2033 /* Did the selected frame id change? If the innermost frame is
2034 selected then the level will be -1, and the frame-id will be
2035 null_frame_id. As comparing null_frame_id with itself always
2036 reports not-equal, we only do the equality test if we have something
2037 other than the innermost frame selected. */
2038 if (current_frame_level
!= -1
2039 && current_frame_id
!= m_previous_frame_id
)
2042 /* Nothing changed! */
2046 /* The previously selected thread. This might be null_ptid if there was
2047 no previously selected thread. */
2048 ptid_t m_previous_ptid
;
2050 /* The previously selected frame. If the innermost frame is selected, or
2051 no frame is selected, then the frame_id will be null_frame_id, and the
2052 level will be -1. */
2053 frame_id m_previous_frame_id
;
2054 int m_previous_frame_level
;
2058 mi_cmd_execute (struct mi_parse
*parse
)
2060 scoped_value_mark cleanup
= prepare_execute_command ();
2062 if (parse
->all
&& parse
->thread_group
!= -1)
2063 error (_("Cannot specify --thread-group together with --all"));
2065 if (parse
->all
&& parse
->thread
!= -1)
2066 error (_("Cannot specify --thread together with --all"));
2068 if (parse
->thread_group
!= -1 && parse
->thread
!= -1)
2069 error (_("Cannot specify --thread together with --thread-group"));
2071 if (parse
->frame
!= -1 && parse
->thread
== -1)
2072 error (_("Cannot specify --frame without --thread"));
2074 if (parse
->thread_group
!= -1)
2076 struct inferior
*inf
= find_inferior_id (parse
->thread_group
);
2077 struct thread_info
*tp
= 0;
2080 error (_("Invalid thread group for the --thread-group option"));
2082 set_current_inferior (inf
);
2083 /* This behaviour means that if --thread-group option identifies
2084 an inferior with multiple threads, then a random one will be
2085 picked. This is not a problem -- frontend should always
2086 provide --thread if it wishes to operate on a specific
2089 tp
= any_live_thread_of_inferior (inf
);
2091 switch_to_thread (tp
);
2093 switch_to_no_thread ();
2094 set_current_program_space (inf
->pspace
);
2097 user_selected_context current_user_selected_context
;
2099 gdb::optional
<scoped_restore_current_thread
> thread_saver
;
2100 if (parse
->thread
!= -1)
2102 thread_info
*tp
= find_thread_global_id (parse
->thread
);
2105 error (_("Invalid thread id: %d"), parse
->thread
);
2107 if (tp
->state
== THREAD_EXITED
)
2108 error (_("Thread id: %d has terminated"), parse
->thread
);
2110 if (parse
->cmd
->preserve_user_selected_context ())
2111 thread_saver
.emplace ();
2113 switch_to_thread (tp
);
2116 gdb::optional
<scoped_restore_selected_frame
> frame_saver
;
2117 if (parse
->frame
!= -1)
2120 int frame
= parse
->frame
;
2122 fid
= find_relative_frame (get_current_frame (), &frame
);
2125 if (parse
->cmd
->preserve_user_selected_context ())
2126 frame_saver
.emplace ();
2131 error (_("Invalid frame id: %d"), frame
);
2134 gdb::optional
<scoped_restore_current_language
> lang_saver
;
2135 if (parse
->language
!= language_unknown
)
2137 lang_saver
.emplace ();
2138 set_language (parse
->language
);
2141 current_context
= parse
;
2143 gdb_assert (parse
->cmd
!= nullptr);
2145 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress_notification
2146 = parse
->cmd
->do_suppress_notification ();
2148 parse
->cmd
->invoke (parse
);
2150 if (!parse
->cmd
->preserve_user_selected_context ()
2151 && current_user_selected_context
.has_changed ())
2152 interps_notify_user_selected_context_changed
2153 (USER_SELECTED_THREAD
| USER_SELECTED_FRAME
);
2156 /* See mi-main.h. */
2159 mi_execute_cli_command (const char *cmd
, bool args_p
, const char *args
)
2163 std::string
run (cmd
);
2166 run
= run
+ " " + args
;
2168 gdb_assert (args
== nullptr);
2171 gdb_printf (gdb_stdlog
, "cli=%s run=%s\n",
2174 execute_command (run
.c_str (), 0 /* from_tty */ );
2179 mi_execute_async_cli_command (const char *cli_command
, const char *const *argv
,
2182 std::string run
= cli_command
;
2185 run
= run
+ " " + *argv
;
2189 execute_command (run
.c_str (), 0 /* from_tty */ );
2193 mi_load_progress (const char *section_name
,
2194 unsigned long sent_so_far
,
2195 unsigned long total_section
,
2196 unsigned long total_sent
,
2197 unsigned long grand_total
)
2199 using namespace std::chrono
;
2200 static steady_clock::time_point last_update
;
2201 static char *previous_sect_name
= NULL
;
2203 struct mi_interp
*mi
= as_mi_interp (current_interpreter ());
2205 /* If the current interpreter is not an MI interpreter, then just
2206 don't bother printing anything. */
2210 /* This function is called through deprecated_show_load_progress
2211 which means uiout may not be correct. Fix it for the duration
2212 of this function. */
2214 auto uiout
= mi_out_new (current_interpreter ()->name ());
2215 if (uiout
== nullptr)
2218 scoped_restore save_uiout
2219 = make_scoped_restore (¤t_uiout
, uiout
.get ());
2221 new_section
= (previous_sect_name
?
2222 strcmp (previous_sect_name
, section_name
) : 1);
2225 xfree (previous_sect_name
);
2226 previous_sect_name
= xstrdup (section_name
);
2228 if (mi
->current_token
)
2229 gdb_puts (mi
->current_token
, mi
->raw_stdout
);
2230 gdb_puts ("+download", mi
->raw_stdout
);
2232 ui_out_emit_tuple
tuple_emitter (uiout
.get (), NULL
);
2233 uiout
->field_string ("section", section_name
);
2234 uiout
->field_signed ("section-size", total_section
);
2235 uiout
->field_signed ("total-size", grand_total
);
2237 mi_out_put (uiout
.get (), mi
->raw_stdout
);
2238 gdb_puts ("\n", mi
->raw_stdout
);
2239 gdb_flush (mi
->raw_stdout
);
2242 steady_clock::time_point time_now
= steady_clock::now ();
2243 if (time_now
- last_update
> milliseconds (500))
2245 last_update
= time_now
;
2246 if (mi
->current_token
)
2247 gdb_puts (mi
->current_token
, mi
->raw_stdout
);
2248 gdb_puts ("+download", mi
->raw_stdout
);
2250 ui_out_emit_tuple
tuple_emitter (uiout
.get (), NULL
);
2251 uiout
->field_string ("section", section_name
);
2252 uiout
->field_signed ("section-sent", sent_so_far
);
2253 uiout
->field_signed ("section-size", total_section
);
2254 uiout
->field_signed ("total-sent", total_sent
);
2255 uiout
->field_signed ("total-size", grand_total
);
2257 mi_out_put (uiout
.get (), mi
->raw_stdout
);
2258 gdb_puts ("\n", mi
->raw_stdout
);
2259 gdb_flush (mi
->raw_stdout
);
2264 timestamp (struct mi_timestamp
*tv
)
2266 using namespace std::chrono
;
2268 tv
->wallclock
= steady_clock::now ();
2269 run_time_clock::now (tv
->utime
, tv
->stime
);
2273 print_diff_now (struct ui_file
*file
, struct mi_timestamp
*start
)
2275 struct mi_timestamp now
;
2278 print_diff (file
, start
, &now
);
2282 mi_print_timing_maybe (struct ui_file
*file
)
2284 /* If the command is -enable-timing then do_timings may be true
2285 whilst current_command_ts is not initialized. */
2286 if (do_timings
&& current_command_ts
)
2287 print_diff_now (file
, current_command_ts
);
2291 print_diff (struct ui_file
*file
, struct mi_timestamp
*start
,
2292 struct mi_timestamp
*end
)
2294 using namespace std::chrono
;
2296 duration
<double> wallclock
= end
->wallclock
- start
->wallclock
;
2297 duration
<double> utime
= end
->utime
- start
->utime
;
2298 duration
<double> stime
= end
->stime
- start
->stime
;
2302 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
2303 wallclock
.count (), utime
.count (), stime
.count ());
2307 mi_cmd_trace_define_variable (const char *command
, const char *const *argv
,
2310 LONGEST initval
= 0;
2311 struct trace_state_variable
*tsv
;
2314 if (argc
!= 1 && argc
!= 2)
2315 error (_("Usage: -trace-define-variable VARIABLE [VALUE]"));
2319 error (_("Name of trace variable should start with '$'"));
2321 validate_trace_state_variable_name (name
);
2323 tsv
= find_trace_state_variable (name
);
2325 tsv
= create_trace_state_variable (name
);
2328 initval
= value_as_long (parse_and_eval (argv
[1]));
2330 tsv
->initial_value
= initval
;
2334 mi_cmd_trace_list_variables (const char *command
, const char *const *argv
,
2338 error (_("-trace-list-variables: no arguments allowed"));
2340 tvariables_info_1 ();
2344 mi_cmd_trace_find (const char *command
, const char *const *argv
, int argc
)
2349 error (_("trace selection mode is required"));
2353 if (strcmp (mode
, "none") == 0)
2355 tfind_1 (tfind_number
, -1, 0, 0, 0);
2359 check_trace_running (current_trace_status ());
2361 if (strcmp (mode
, "frame-number") == 0)
2364 error (_("frame number is required"));
2365 tfind_1 (tfind_number
, atoi (argv
[1]), 0, 0, 0);
2367 else if (strcmp (mode
, "tracepoint-number") == 0)
2370 error (_("tracepoint number is required"));
2371 tfind_1 (tfind_tp
, atoi (argv
[1]), 0, 0, 0);
2373 else if (strcmp (mode
, "pc") == 0)
2376 error (_("PC is required"));
2377 tfind_1 (tfind_pc
, 0, parse_and_eval_address (argv
[1]), 0, 0);
2379 else if (strcmp (mode
, "pc-inside-range") == 0)
2382 error (_("Start and end PC are required"));
2383 tfind_1 (tfind_range
, 0, parse_and_eval_address (argv
[1]),
2384 parse_and_eval_address (argv
[2]), 0);
2386 else if (strcmp (mode
, "pc-outside-range") == 0)
2389 error (_("Start and end PC are required"));
2390 tfind_1 (tfind_outside
, 0, parse_and_eval_address (argv
[1]),
2391 parse_and_eval_address (argv
[2]), 0);
2393 else if (strcmp (mode
, "line") == 0)
2396 error (_("Line is required"));
2398 std::vector
<symtab_and_line
> sals
2399 = decode_line_with_current_source (argv
[1],
2400 DECODE_LINE_FUNFIRSTLINE
);
2401 const symtab_and_line
&sal
= sals
[0];
2403 if (sal
.symtab
== 0)
2404 error (_("Could not find the specified line"));
2406 CORE_ADDR start_pc
, end_pc
;
2407 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2408 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, 0);
2410 error (_("Could not find the specified line"));
2413 error (_("Invalid mode '%s'"), mode
);
2415 if (has_stack_frames () || get_traceframe_number () >= 0)
2416 print_stack_frame (get_selected_frame (NULL
), 1, LOC_AND_ADDRESS
, 1);
2420 mi_cmd_trace_save (const char *command
, const char *const *argv
, int argc
)
2422 int target_saves
= 0;
2423 int generate_ctf
= 0;
2424 const char *filename
;
2430 TARGET_SAVE_OPT
, CTF_OPT
2432 static const struct mi_opt opts
[] =
2434 {"r", TARGET_SAVE_OPT
, 0},
2435 {"ctf", CTF_OPT
, 0},
2441 int opt
= mi_getopt ("-trace-save", argc
, argv
, opts
,
2446 switch ((enum opt
) opt
)
2448 case TARGET_SAVE_OPT
:
2457 if (argc
- oind
!= 1)
2458 error (_("Exactly one argument required "
2459 "(file in which to save trace data)"));
2461 filename
= argv
[oind
];
2464 trace_save_ctf (filename
, target_saves
);
2466 trace_save_tfile (filename
, target_saves
);
2470 mi_cmd_trace_start (const char *command
, const char *const *argv
, int argc
)
2472 start_tracing (NULL
);
2476 mi_cmd_trace_status (const char *command
, const char *const *argv
, int argc
)
2478 trace_status_mi (0);
2482 mi_cmd_trace_stop (const char *command
, const char *const *argv
, int argc
)
2484 stop_tracing (NULL
);
2485 trace_status_mi (1);
2488 /* Implement the "-ada-task-info" command. */
2491 mi_cmd_ada_task_info (const char *command
, const char *const *argv
, int argc
)
2493 if (argc
!= 0 && argc
!= 1)
2494 error (_("Invalid MI command"));
2496 print_ada_task_info (current_uiout
, argv
[0], current_inferior ());
2499 /* Print EXPRESSION according to VALUES. */
2502 print_variable_or_computed (const char *expression
, enum print_values values
)
2505 struct ui_out
*uiout
= current_uiout
;
2509 expression_up expr
= parse_expression (expression
);
2511 if (values
== PRINT_SIMPLE_VALUES
)
2512 val
= expr
->evaluate_type ();
2514 val
= expr
->evaluate ();
2516 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
2517 if (values
!= PRINT_NO_VALUES
)
2518 tuple_emitter
.emplace (uiout
, nullptr);
2519 uiout
->field_string ("name", expression
);
2523 case PRINT_SIMPLE_VALUES
:
2524 type_print (val
->type (), "", &stb
, -1);
2525 uiout
->field_stream ("type", stb
);
2526 if (mi_simple_type_p (val
->type ()))
2528 struct value_print_options opts
;
2530 get_no_prettyformat_print_options (&opts
);
2531 opts
.deref_ref
= true;
2532 common_val_print (val
, &stb
, 0, &opts
, current_language
);
2533 uiout
->field_stream ("value", stb
);
2536 case PRINT_ALL_VALUES
:
2538 struct value_print_options opts
;
2540 get_no_prettyformat_print_options (&opts
);
2541 opts
.deref_ref
= true;
2542 common_val_print (val
, &stb
, 0, &opts
, current_language
);
2543 uiout
->field_stream ("value", stb
);
2549 /* Implement the "-trace-frame-collected" command. */
2552 mi_cmd_trace_frame_collected (const char *command
, const char *const *argv
,
2555 struct bp_location
*tloc
;
2557 struct collection_list
*clist
;
2558 struct collection_list tracepoint_list
, stepping_list
;
2559 struct traceframe_info
*tinfo
;
2561 enum print_values var_print_values
= PRINT_ALL_VALUES
;
2562 enum print_values comp_print_values
= PRINT_ALL_VALUES
;
2563 int registers_format
= 'x';
2564 int memory_contents
= 0;
2565 struct ui_out
*uiout
= current_uiout
;
2573 static const struct mi_opt opts
[] =
2575 {"-var-print-values", VAR_PRINT_VALUES
, 1},
2576 {"-comp-print-values", COMP_PRINT_VALUES
, 1},
2577 {"-registers-format", REGISTERS_FORMAT
, 1},
2578 {"-memory-contents", MEMORY_CONTENTS
, 0},
2585 int opt
= mi_getopt ("-trace-frame-collected", argc
, argv
, opts
,
2589 switch ((enum opt
) opt
)
2591 case VAR_PRINT_VALUES
:
2592 var_print_values
= mi_parse_print_values (oarg
);
2594 case COMP_PRINT_VALUES
:
2595 comp_print_values
= mi_parse_print_values (oarg
);
2597 case REGISTERS_FORMAT
:
2598 registers_format
= oarg
[0];
2600 case MEMORY_CONTENTS
:
2601 memory_contents
= 1;
2607 error (_("Usage: -trace-frame-collected "
2608 "[--var-print-values PRINT_VALUES] "
2609 "[--comp-print-values PRINT_VALUES] "
2610 "[--registers-format FORMAT]"
2611 "[--memory-contents]"));
2613 /* This throws an error is not inspecting a trace frame. */
2614 tloc
= get_traceframe_location (&stepping_frame
);
2616 /* This command only makes sense for the current frame, not the
2618 scoped_restore_current_thread restore_thread
;
2619 select_frame (get_current_frame ());
2621 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
2624 clist
= &stepping_list
;
2626 clist
= &tracepoint_list
;
2628 tinfo
= get_traceframe_info ();
2630 /* Explicitly wholly collected variables. */
2632 ui_out_emit_list
list_emitter (uiout
, "explicit-variables");
2633 const std::vector
<std::string
> &wholly_collected
2634 = clist
->wholly_collected ();
2635 for (size_t i
= 0; i
< wholly_collected
.size (); i
++)
2637 const std::string
&str
= wholly_collected
[i
];
2638 print_variable_or_computed (str
.c_str (), var_print_values
);
2642 /* Computed expressions. */
2644 ui_out_emit_list
list_emitter (uiout
, "computed-expressions");
2646 const std::vector
<std::string
> &computed
= clist
->computed ();
2647 for (size_t i
= 0; i
< computed
.size (); i
++)
2649 const std::string
&str
= computed
[i
];
2650 print_variable_or_computed (str
.c_str (), comp_print_values
);
2654 /* Registers. Given pseudo-registers, and that some architectures
2655 (like MIPS) actually hide the raw registers, we don't go through
2656 the trace frame info, but instead consult the register cache for
2657 register availability. */
2659 frame_info_ptr frame
;
2660 struct gdbarch
*gdbarch
;
2664 ui_out_emit_list
list_emitter (uiout
, "registers");
2666 frame
= get_selected_frame (NULL
);
2667 gdbarch
= get_frame_arch (frame
);
2668 numregs
= gdbarch_num_cooked_regs (gdbarch
);
2670 for (regnum
= 0; regnum
< numregs
; regnum
++)
2672 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
2675 output_register (frame
, regnum
, registers_format
, 1);
2679 /* Trace state variables. */
2681 ui_out_emit_list
list_emitter (uiout
, "tvars");
2683 for (int tvar
: tinfo
->tvars
)
2685 struct trace_state_variable
*tsv
;
2687 tsv
= find_trace_state_variable_by_number (tvar
);
2689 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
2693 uiout
->field_fmt ("name", "$%s", tsv
->name
.c_str ());
2695 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
2697 uiout
->field_signed ("current", tsv
->value
);
2701 uiout
->field_skip ("name");
2702 uiout
->field_skip ("current");
2709 std::vector
<mem_range
> available_memory
;
2711 traceframe_available_memory (&available_memory
, 0, ULONGEST_MAX
);
2713 ui_out_emit_list
list_emitter (uiout
, "memory");
2715 for (const mem_range
&r
: available_memory
)
2717 gdbarch
*gdbarch
= current_inferior ()->arch ();
2719 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
2721 uiout
->field_core_addr ("address", gdbarch
, r
.start
);
2722 uiout
->field_signed ("length", r
.length
);
2724 gdb::byte_vector
data (r
.length
);
2726 if (memory_contents
)
2728 if (target_read_memory (r
.start
, data
.data (), r
.length
) == 0)
2730 std::string data_str
= bin2hex (data
.data (), r
.length
);
2731 uiout
->field_string ("contents", data_str
);
2734 uiout
->field_skip ("contents");
2740 /* See mi/mi-main.h. */
2743 mi_cmd_fix_multi_location_breakpoint_output (const char *command
,
2744 const char *const *argv
,
2747 fix_multi_location_breakpoint_output_globally
= true;
2750 /* See mi/mi-main.h. */
2753 mi_cmd_fix_breakpoint_script_output (const char *command
,
2754 const char *const *argv
, int argc
)
2756 fix_breakpoint_script_output_globally
= true;
2759 /* Implement the "-complete" command. */
2762 mi_cmd_complete (const char *command
, const char *const *argv
, int argc
)
2765 error (_("Usage: -complete COMMAND"));
2767 if (max_completions
== 0)
2768 error (_("max-completions is zero, completion is disabled."));
2770 int quote_char
= '\0';
2773 completion_result result
= complete (argv
[0], &word
, "e_char
);
2775 std::string
arg_prefix (argv
[0], word
- argv
[0]);
2777 struct ui_out
*uiout
= current_uiout
;
2779 if (result
.number_matches
> 0)
2780 uiout
->field_fmt ("completion", "%s%s",
2781 arg_prefix
.c_str (),result
.match_list
[0]);
2784 ui_out_emit_list
completions_emitter (uiout
, "matches");
2786 if (result
.number_matches
== 1)
2787 uiout
->field_fmt (NULL
, "%s%s",
2788 arg_prefix
.c_str (), result
.match_list
[0]);
2791 result
.sort_match_list ();
2792 for (size_t i
= 0; i
< result
.number_matches
; i
++)
2794 uiout
->field_fmt (NULL
, "%s%s",
2795 arg_prefix
.c_str (), result
.match_list
[i
+ 1]);
2799 uiout
->field_string ("max_completions_reached",
2800 result
.number_matches
== max_completions
? "1" : "0");
2803 /* See mi-main.h. */
2805 mi_parse_thread_group_id (const char *id
)
2808 error (_("thread group id should start with an 'i'"));
2811 long num
= strtol (id
+ 1, &end
, 10);
2813 if (*end
!= '\0' || num
> INT_MAX
)
2814 error (_("invalid thread group id '%s'"), id
);
2819 void _initialize_mi_main ();
2821 _initialize_mi_main ()
2823 set_show_commands mi_async_cmds
2824 = add_setshow_boolean_cmd ("mi-async", class_run
,
2826 Set whether MI asynchronous mode is enabled."), _("\
2827 Show whether MI asynchronous mode is enabled."), _("\
2828 Tells GDB whether MI should be in asynchronous mode."),
2829 set_mi_async_command
,
2830 show_mi_async_command
,
2831 &setlist
, &showlist
);
2833 /* Alias old "target-async" to "mi-async". */
2834 cmd_list_element
*set_target_async_cmd
2835 = add_alias_cmd ("target-async", mi_async_cmds
.set
, class_run
, 0, &setlist
);
2836 deprecate_cmd (set_target_async_cmd
, "set mi-async");
2838 cmd_list_element
*show_target_async_cmd
2839 = add_alias_cmd ("target-async", mi_async_cmds
.show
, class_run
, 0,
2841 deprecate_cmd (show_target_async_cmd
, "show mi-async");