Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy
[deliverable/binutils-gdb.git] / gdb / mi / mi-main.c
1 /* MI Command Set.
2
3 Copyright (C) 2000-2017 Free Software Foundation, Inc.
4
5 Contributed by Cygnus Solutions (a Red Hat company).
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "target.h"
25 #include "inferior.h"
26 #include "infrun.h"
27 #include "top.h"
28 #include "gdbthread.h"
29 #include "mi-cmds.h"
30 #include "mi-parse.h"
31 #include "mi-getopt.h"
32 #include "mi-console.h"
33 #include "ui-out.h"
34 #include "mi-out.h"
35 #include "interps.h"
36 #include "event-loop.h"
37 #include "event-top.h"
38 #include "gdbcore.h" /* For write_memory(). */
39 #include "value.h"
40 #include "regcache.h"
41 #include "gdb.h"
42 #include "frame.h"
43 #include "mi-main.h"
44 #include "mi-common.h"
45 #include "language.h"
46 #include "valprint.h"
47 #include "inferior.h"
48 #include "osdata.h"
49 #include "splay-tree.h"
50 #include "tracepoint.h"
51 #include "ctf.h"
52 #include "ada-lang.h"
53 #include "linespec.h"
54 #include "extension.h"
55 #include "gdbcmd.h"
56 #include "observer.h"
57
58 #include <ctype.h>
59 #include "run-time-clock.h"
60 #include <chrono>
61
62 enum
63 {
64 FROM_TTY = 0
65 };
66
67 int mi_debug_p;
68
69 /* This is used to pass the current command timestamp down to
70 continuation routines. */
71 static struct mi_timestamp *current_command_ts;
72
73 static int do_timings = 0;
74
75 char *current_token;
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;
80
81 int running_result_record_printed = 1;
82
83 /* Flag indicating that the target has proceeded since the last
84 command was issued. */
85 int mi_proceeded;
86
87 extern void _initialize_mi_main (void);
88 static void mi_cmd_execute (struct mi_parse *parse);
89
90 static void mi_execute_cli_command (const char *cmd, int args_p,
91 const char *args);
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 *,
95 struct regcache *);
96 static void output_register (struct frame_info *, int regnum, int format,
97 int skip_unavailable);
98
99 /* Controls whether the frontend wants MI in async mode. */
100 static int mi_async = 0;
101
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;
105
106 static void
107 set_mi_async_command (char *args, int from_tty,
108 struct cmd_list_element *c)
109 {
110 if (have_live_inferiors ())
111 {
112 mi_async_1 = mi_async;
113 error (_("Cannot change this setting while the inferior is running."));
114 }
115
116 mi_async = mi_async_1;
117 }
118
119 static void
120 show_mi_async_command (struct ui_file *file, int from_tty,
121 struct cmd_list_element *c,
122 const char *value)
123 {
124 fprintf_filtered (file,
125 _("Whether MI is in asynchronous mode is %s.\n"),
126 value);
127 }
128
129 /* A wrapper for target_can_async_p that takes the MI setting into
130 account. */
131
132 int
133 mi_async_p (void)
134 {
135 return mi_async && target_can_async_p ();
136 }
137
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
140 formalized. */
141
142 static void timestamp (struct mi_timestamp *tv);
143
144 static void print_diff (struct ui_file *file, struct mi_timestamp *start,
145 struct mi_timestamp *end);
146
147 void
148 mi_cmd_gdb_exit (char *command, char **argv, int argc)
149 {
150 struct mi_interp *mi
151 = (struct mi_interp *) interp_data (current_interpreter ());
152
153 /* We have to print everything right here because we never return. */
154 if (current_token)
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);
161 }
162
163 void
164 mi_cmd_exec_next (char *command, char **argv, int argc)
165 {
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);
169 else
170 mi_execute_async_cli_command ("next", argv, argc);
171 }
172
173 void
174 mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
175 {
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);
179 else
180 mi_execute_async_cli_command ("nexti", argv, argc);
181 }
182
183 void
184 mi_cmd_exec_step (char *command, char **argv, int argc)
185 {
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);
189 else
190 mi_execute_async_cli_command ("step", argv, argc);
191 }
192
193 void
194 mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
195 {
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);
199 else
200 mi_execute_async_cli_command ("stepi", argv, argc);
201 }
202
203 void
204 mi_cmd_exec_finish (char *command, char **argv, int argc)
205 {
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);
209 else
210 mi_execute_async_cli_command ("finish", argv, argc);
211 }
212
213 void
214 mi_cmd_exec_return (char *command, char **argv, int argc)
215 {
216 /* This command doesn't really execute the target, it just pops the
217 specified number of frames. */
218 if (argc)
219 /* Call return_command with from_tty argument equal to 0 so as to
220 avoid being queried. */
221 return_command (*argv, 0);
222 else
223 /* Call return_command with from_tty argument equal to 0 so as to
224 avoid being queried. */
225 return_command (NULL, 0);
226
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);
230 }
231
232 void
233 mi_cmd_exec_jump (char *args, char **argv, int argc)
234 {
235 /* FIXME: Should call a libgdb function, not a cli wrapper. */
236 mi_execute_async_cli_command ("jump", argv, argc);
237 }
238
239 static void
240 proceed_thread (struct thread_info *thread, int pid)
241 {
242 if (!is_stopped (thread->ptid))
243 return;
244
245 if (pid != 0 && ptid_get_pid (thread->ptid) != pid)
246 return;
247
248 switch_to_thread (thread->ptid);
249 clear_proceed_status (0);
250 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
251 }
252
253 static int
254 proceed_thread_callback (struct thread_info *thread, void *arg)
255 {
256 int pid = *(int *)arg;
257
258 proceed_thread (thread, pid);
259 return 0;
260 }
261
262 static void
263 exec_continue (char **argv, int argc)
264 {
265 prepare_execution_command (&current_target, mi_async_p ());
266
267 if (non_stop)
268 {
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
272 threads.
273
274 See comment on infcmd.c:proceed_thread_callback for rationale. */
275 if (current_context->all || current_context->thread_group != -1)
276 {
277 int pid = 0;
278 struct cleanup *back_to = make_cleanup_restore_current_thread ();
279
280 if (!current_context->all)
281 {
282 struct inferior *inf
283 = find_inferior_id (current_context->thread_group);
284
285 pid = inf->pid;
286 }
287 iterate_over_threads (proceed_thread_callback, &pid);
288 do_cleanups (back_to);
289 }
290 else
291 {
292 continue_1 (0);
293 }
294 }
295 else
296 {
297 scoped_restore save_multi = make_scoped_restore (&sched_multi);
298
299 if (current_context->all)
300 {
301 sched_multi = 1;
302 continue_1 (0);
303 }
304 else
305 {
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
309 same. */
310 continue_1 (1);
311 }
312 }
313 }
314
315 static void
316 exec_direction_forward (void *notused)
317 {
318 execution_direction = EXEC_FORWARD;
319 }
320
321 static void
322 exec_reverse_continue (char **argv, int argc)
323 {
324 enum exec_direction_kind dir = execution_direction;
325 struct cleanup *old_chain;
326
327 if (dir == EXEC_REVERSE)
328 error (_("Already in reverse mode."));
329
330 if (!target_can_execute_reverse)
331 error (_("Target %s does not support this command."), target_shortname);
332
333 old_chain = make_cleanup (exec_direction_forward, NULL);
334 execution_direction = EXEC_REVERSE;
335 exec_continue (argv, argc);
336 do_cleanups (old_chain);
337 }
338
339 void
340 mi_cmd_exec_continue (char *command, char **argv, int argc)
341 {
342 if (argc > 0 && strcmp (argv[0], "--reverse") == 0)
343 exec_reverse_continue (argv + 1, argc - 1);
344 else
345 exec_continue (argv, argc);
346 }
347
348 static int
349 interrupt_thread_callback (struct thread_info *thread, void *arg)
350 {
351 int pid = *(int *)arg;
352
353 if (!is_running (thread->ptid))
354 return 0;
355
356 if (ptid_get_pid (thread->ptid) != pid)
357 return 0;
358
359 target_stop (thread->ptid);
360 return 0;
361 }
362
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
367 mi_cmd_execute. */
368
369 void
370 mi_cmd_exec_interrupt (char *command, char **argv, int argc)
371 {
372 /* In all-stop mode, everything stops, so we don't need to try
373 anything specific. */
374 if (!non_stop)
375 {
376 interrupt_target_1 (0);
377 return;
378 }
379
380 if (current_context->all)
381 {
382 /* This will interrupt all threads in all inferiors. */
383 interrupt_target_1 (1);
384 }
385 else if (current_context->thread_group != -1)
386 {
387 struct inferior *inf = find_inferior_id (current_context->thread_group);
388
389 iterate_over_threads (interrupt_thread_callback, &inf->pid);
390 }
391 else
392 {
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);
397 }
398 }
399
400 /* Callback for iterate_over_inferiors which starts the execution
401 of the given inferior.
402
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). */
406
407 static int
408 run_one_inferior (struct inferior *inf, void *arg)
409 {
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);
414
415 if (inf->pid != 0)
416 {
417 if (inf->pid != ptid_get_pid (inferior_ptid))
418 {
419 struct thread_info *tp;
420
421 tp = any_thread_of_process (inf->pid);
422 if (!tp)
423 error (_("Inferior has no threads."));
424
425 switch_to_thread (tp->ptid);
426 }
427 }
428 else
429 {
430 set_current_inferior (inf);
431 switch_to_thread (null_ptid);
432 set_current_program_space (inf->pspace);
433 }
434 mi_execute_cli_command (run_cmd, async_p,
435 async_p ? "&" : NULL);
436 return 0;
437 }
438
439 void
440 mi_cmd_exec_run (char *command, char **argv, int argc)
441 {
442 int start_p = 0;
443
444 /* Parse the command options. */
445 enum opt
446 {
447 START_OPT,
448 };
449 static const struct mi_opt opts[] =
450 {
451 {"-start", START_OPT, 0},
452 {NULL, 0, 0},
453 };
454
455 int oind = 0;
456 char *oarg;
457
458 while (1)
459 {
460 int opt = mi_getopt ("-exec-run", argc, argv, opts, &oind, &oarg);
461
462 if (opt < 0)
463 break;
464 switch ((enum opt) opt)
465 {
466 case START_OPT:
467 start_p = 1;
468 break;
469 }
470 }
471
472 /* This command does not accept any argument. Make sure the user
473 did not provide any. */
474 if (oind != argc)
475 error (_("Invalid argument: %s"), argv[oind]);
476
477 if (current_context->all)
478 {
479 struct cleanup *back_to = save_current_space_and_thread ();
480
481 iterate_over_inferiors (run_one_inferior, &start_p);
482 do_cleanups (back_to);
483 }
484 else
485 {
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);
489
490 mi_execute_cli_command (run_cmd, async_p,
491 async_p ? "&" : NULL);
492 }
493 }
494
495
496 static int
497 find_thread_of_process (struct thread_info *ti, void *p)
498 {
499 int pid = *(int *)p;
500
501 if (ptid_get_pid (ti->ptid) == pid && !is_exited (ti->ptid))
502 return 1;
503
504 return 0;
505 }
506
507 void
508 mi_cmd_target_detach (char *command, char **argv, int argc)
509 {
510 if (argc != 0 && argc != 1)
511 error (_("Usage: -target-detach [pid | thread-group]"));
512
513 if (argc == 1)
514 {
515 struct thread_info *tp;
516 char *end = argv[0];
517 int pid;
518
519 /* First see if we are dealing with a thread-group id. */
520 if (*argv[0] == 'i')
521 {
522 struct inferior *inf;
523 int id = strtoul (argv[0] + 1, &end, 0);
524
525 if (*end != '\0')
526 error (_("Invalid syntax of thread-group id '%s'"), argv[0]);
527
528 inf = find_inferior_id (id);
529 if (!inf)
530 error (_("Non-existent thread-group id '%d'"), id);
531
532 pid = inf->pid;
533 }
534 else
535 {
536 /* We must be dealing with a pid. */
537 pid = strtol (argv[0], &end, 10);
538
539 if (*end != '\0')
540 error (_("Invalid identifier '%s'"), argv[0]);
541 }
542
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);
546 if (!tp)
547 error (_("Thread group is empty"));
548
549 switch_to_thread (tp->ptid);
550 }
551
552 detach_command (NULL, 0);
553 }
554
555 void
556 mi_cmd_target_flash_erase (char *command, char **argv, int argc)
557 {
558 flash_erase_command (NULL, 0);
559 }
560
561 void
562 mi_cmd_thread_select (char *command, char **argv, int argc)
563 {
564 enum gdb_rc rc;
565 char *mi_error_message;
566 ptid_t previous_ptid = inferior_ptid;
567
568 if (argc != 1)
569 error (_("-thread-select: USAGE: threadnum."));
570
571 rc = gdb_thread_select (current_uiout, argv[0], &mi_error_message);
572
573 /* If thread switch did not succeed don't notify or print. */
574 if (rc == GDB_RC_FAIL)
575 {
576 make_cleanup (xfree, mi_error_message);
577 error ("%s", mi_error_message);
578 }
579
580 print_selected_thread_frame (current_uiout,
581 USER_SELECTED_THREAD | USER_SELECTED_FRAME);
582
583 /* Notify if the thread has effectively changed. */
584 if (!ptid_equal (inferior_ptid, previous_ptid))
585 {
586 observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
587 | USER_SELECTED_FRAME);
588 }
589 }
590
591 void
592 mi_cmd_thread_list_ids (char *command, char **argv, int argc)
593 {
594 enum gdb_rc rc;
595 char *mi_error_message;
596
597 if (argc != 0)
598 error (_("-thread-list-ids: No arguments required."));
599
600 rc = gdb_list_thread_ids (current_uiout, &mi_error_message);
601
602 if (rc == GDB_RC_FAIL)
603 {
604 make_cleanup (xfree, mi_error_message);
605 error ("%s", mi_error_message);
606 }
607 }
608
609 void
610 mi_cmd_thread_info (char *command, char **argv, int argc)
611 {
612 if (argc != 0 && argc != 1)
613 error (_("Invalid MI command"));
614
615 print_thread_info (current_uiout, argv[0], -1);
616 }
617
618 struct collect_cores_data
619 {
620 int pid;
621
622 VEC (int) *cores;
623 };
624
625 static int
626 collect_cores (struct thread_info *ti, void *xdata)
627 {
628 struct collect_cores_data *data = (struct collect_cores_data *) xdata;
629
630 if (ptid_get_pid (ti->ptid) == data->pid)
631 {
632 int core = target_core_of_thread (ti->ptid);
633
634 if (core != -1)
635 VEC_safe_push (int, data->cores, core);
636 }
637
638 return 0;
639 }
640
641 static int *
642 unique (int *b, int *e)
643 {
644 int *d = b;
645
646 while (++b != e)
647 if (*d != *b)
648 *++d = *b;
649 return ++d;
650 }
651
652 struct print_one_inferior_data
653 {
654 int recurse;
655 VEC (int) *inferiors;
656 };
657
658 static int
659 print_one_inferior (struct inferior *inferior, void *xdata)
660 {
661 struct print_one_inferior_data *top_data
662 = (struct print_one_inferior_data *) xdata;
663 struct ui_out *uiout = current_uiout;
664
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))
669 {
670 struct collect_cores_data data;
671 struct cleanup *back_to
672 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
673
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);
681
682 if (inferior->pspace->pspace_exec_filename != NULL)
683 {
684 uiout->field_string ("executable",
685 inferior->pspace->pspace_exec_filename);
686 }
687
688 data.cores = 0;
689 if (inferior->pid != 0)
690 {
691 data.pid = inferior->pid;
692 iterate_over_threads (collect_cores, &data);
693 }
694
695 if (!VEC_empty (int, data.cores))
696 {
697 int *b, *e;
698 struct cleanup *back_to_2 =
699 make_cleanup_ui_out_list_begin_end (uiout, "cores");
700
701 qsort (VEC_address (int, data.cores),
702 VEC_length (int, data.cores), sizeof (int),
703 compare_positive_ints);
704
705 b = VEC_address (int, data.cores);
706 e = b + VEC_length (int, data.cores);
707 e = unique (b, e);
708
709 for (; b != e; ++b)
710 uiout->field_int (NULL, *b);
711
712 do_cleanups (back_to_2);
713 }
714
715 if (top_data->recurse)
716 print_thread_info (uiout, NULL, inferior->pid);
717
718 do_cleanups (back_to);
719 }
720
721 return 0;
722 }
723
724 /* Output a field named 'cores' with a list as the value. The
725 elements of the list are obtained by splitting 'cores' on
726 comma. */
727
728 static void
729 output_cores (struct ui_out *uiout, const char *field_name, const char *xcores)
730 {
731 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
732 field_name);
733 char *cores = xstrdup (xcores);
734 char *p = cores;
735
736 make_cleanup (xfree, cores);
737
738 for (p = strtok (p, ","); p; p = strtok (NULL, ","))
739 uiout->field_string (NULL, p);
740
741 do_cleanups (back_to);
742 }
743
744 static void
745 free_vector_of_ints (void *xvector)
746 {
747 VEC (int) **vector = (VEC (int) **) xvector;
748
749 VEC_free (int, *vector);
750 }
751
752 static void
753 do_nothing (splay_tree_key k)
754 {
755 }
756
757 static void
758 free_vector_of_osdata_items (splay_tree_value xvalue)
759 {
760 VEC (osdata_item_s) *value = (VEC (osdata_item_s) *) xvalue;
761
762 /* We don't free the items itself, it will be done separately. */
763 VEC_free (osdata_item_s, value);
764 }
765
766 static int
767 splay_tree_int_comparator (splay_tree_key xa, splay_tree_key xb)
768 {
769 int a = xa;
770 int b = xb;
771
772 return a - b;
773 }
774
775 static void
776 free_splay_tree (void *xt)
777 {
778 splay_tree t = (splay_tree) xt;
779 splay_tree_delete (t);
780 }
781
782 static void
783 list_available_thread_groups (VEC (int) *ids, int recurse)
784 {
785 struct osdata *data;
786 struct osdata_item *item;
787 int ix_items;
788 struct ui_out *uiout = current_uiout;
789 struct cleanup *cleanup;
790
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"
794 warning from gcc. */
795 splay_tree tree = NULL;
796
797 /* get_osdata will throw if it cannot return data. */
798 data = get_osdata ("processes");
799 cleanup = make_cleanup_osdata_free (data);
800
801 if (recurse)
802 {
803 struct osdata *threads = get_osdata ("threads");
804
805 make_cleanup_osdata_free (threads);
806 tree = splay_tree_new (splay_tree_int_comparator,
807 do_nothing,
808 free_vector_of_osdata_items);
809 make_cleanup (free_splay_tree, tree);
810
811 for (ix_items = 0;
812 VEC_iterate (osdata_item_s, threads->items,
813 ix_items, item);
814 ix_items++)
815 {
816 const char *pid = get_osdata_column (item, "pid");
817 int pid_i = strtoul (pid, NULL, 0);
818 VEC (osdata_item_s) *vec = 0;
819
820 splay_tree_node n = splay_tree_lookup (tree, pid_i);
821 if (!n)
822 {
823 VEC_safe_push (osdata_item_s, vec, item);
824 splay_tree_insert (tree, pid_i, (splay_tree_value)vec);
825 }
826 else
827 {
828 vec = (VEC (osdata_item_s) *) n->value;
829 VEC_safe_push (osdata_item_s, vec, item);
830 n->value = (splay_tree_value) vec;
831 }
832 }
833 }
834
835 make_cleanup_ui_out_list_begin_end (uiout, "groups");
836
837 for (ix_items = 0;
838 VEC_iterate (osdata_item_s, data->items,
839 ix_items, item);
840 ix_items++)
841 {
842 struct cleanup *back_to;
843
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");
848
849 int pid_i = strtoul (pid, NULL, 0);
850
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)
857 continue;
858
859
860 back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
861
862 uiout->field_fmt ("id", "%s", pid);
863 uiout->field_string ("type", "process");
864 if (cmd)
865 uiout->field_string ("description", cmd);
866 if (user)
867 uiout->field_string ("user", user);
868 if (cores)
869 output_cores (uiout, "cores", cores);
870
871 if (recurse)
872 {
873 splay_tree_node n = splay_tree_lookup (tree, pid_i);
874 if (n)
875 {
876 VEC (osdata_item_s) *children = (VEC (osdata_item_s) *) n->value;
877 struct osdata_item *child;
878 int ix_child;
879
880 make_cleanup_ui_out_list_begin_end (uiout, "threads");
881
882 for (ix_child = 0;
883 VEC_iterate (osdata_item_s, children, ix_child, child);
884 ++ix_child)
885 {
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");
890
891 uiout->field_string ("id", tid);
892 if (tcore)
893 uiout->field_string ("core", tcore);
894
895 do_cleanups (back_to_2);
896 }
897 }
898 }
899
900 do_cleanups (back_to);
901 }
902
903 do_cleanups (cleanup);
904 }
905
906 void
907 mi_cmd_list_thread_groups (char *command, char **argv, int argc)
908 {
909 struct ui_out *uiout = current_uiout;
910 struct cleanup *back_to;
911 int available = 0;
912 int recurse = 0;
913 VEC (int) *ids = 0;
914
915 enum opt
916 {
917 AVAILABLE_OPT, RECURSE_OPT
918 };
919 static const struct mi_opt opts[] =
920 {
921 {"-available", AVAILABLE_OPT, 0},
922 {"-recurse", RECURSE_OPT, 1},
923 { 0, 0, 0 }
924 };
925
926 int oind = 0;
927 char *oarg;
928
929 while (1)
930 {
931 int opt = mi_getopt ("-list-thread-groups", argc, argv, opts,
932 &oind, &oarg);
933
934 if (opt < 0)
935 break;
936 switch ((enum opt) opt)
937 {
938 case AVAILABLE_OPT:
939 available = 1;
940 break;
941 case RECURSE_OPT:
942 if (strcmp (oarg, "0") == 0)
943 ;
944 else if (strcmp (oarg, "1") == 0)
945 recurse = 1;
946 else
947 error (_("only '0' and '1' are valid values "
948 "for the '--recurse' option"));
949 break;
950 }
951 }
952
953 for (; oind < argc; ++oind)
954 {
955 char *end;
956 int inf;
957
958 if (*(argv[oind]) != 'i')
959 error (_("invalid syntax of group id '%s'"), argv[oind]);
960
961 inf = strtoul (argv[oind] + 1, &end, 0);
962
963 if (*end != '\0')
964 error (_("invalid syntax of group id '%s'"), argv[oind]);
965 VEC_safe_push (int, ids, inf);
966 }
967 if (VEC_length (int, ids) > 1)
968 qsort (VEC_address (int, ids),
969 VEC_length (int, ids),
970 sizeof (int), compare_positive_ints);
971
972 back_to = make_cleanup (free_vector_of_ints, &ids);
973
974 if (available)
975 {
976 list_available_thread_groups (ids, recurse);
977 }
978 else if (VEC_length (int, ids) == 1)
979 {
980 /* Local thread groups, single id. */
981 int id = *VEC_address (int, ids);
982 struct inferior *inf = find_inferior_id (id);
983
984 if (!inf)
985 error (_("Non-existent thread group id '%d'"), id);
986
987 print_thread_info (uiout, NULL, inf->pid);
988 }
989 else
990 {
991 struct print_one_inferior_data data;
992
993 data.recurse = recurse;
994 data.inferiors = ids;
995
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);
1003 }
1004
1005 do_cleanups (back_to);
1006 }
1007
1008 void
1009 mi_cmd_data_list_register_names (char *command, char **argv, int argc)
1010 {
1011 struct gdbarch *gdbarch;
1012 struct ui_out *uiout = current_uiout;
1013 int regnum, numregs;
1014 int i;
1015 struct cleanup *cleanup;
1016
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
1022 debugged. */
1023
1024 gdbarch = get_current_arch ();
1025 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1026
1027 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-names");
1028
1029 if (argc == 0) /* No args, just do all the regs. */
1030 {
1031 for (regnum = 0;
1032 regnum < numregs;
1033 regnum++)
1034 {
1035 if (gdbarch_register_name (gdbarch, regnum) == NULL
1036 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1037 uiout->field_string (NULL, "");
1038 else
1039 uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum));
1040 }
1041 }
1042
1043 /* Else, list of register #s, just do listed regs. */
1044 for (i = 0; i < argc; i++)
1045 {
1046 regnum = atoi (argv[i]);
1047 if (regnum < 0 || regnum >= numregs)
1048 error (_("bad register number"));
1049
1050 if (gdbarch_register_name (gdbarch, regnum) == NULL
1051 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1052 uiout->field_string (NULL, "");
1053 else
1054 uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum));
1055 }
1056 do_cleanups (cleanup);
1057 }
1058
1059 void
1060 mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
1061 {
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;
1067 int i;
1068 struct cleanup *cleanup;
1069
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
1073 contents. */
1074
1075 prev_regs = this_regs;
1076 this_regs = frame_save_as_regcache (get_selected_frame (NULL));
1077 cleanup = make_cleanup_regcache_xfree (prev_regs);
1078
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
1084 debugged. */
1085
1086 gdbarch = get_regcache_arch (this_regs);
1087 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1088
1089 make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
1090
1091 if (argc == 0)
1092 {
1093 /* No args, just do all the regs. */
1094 for (regnum = 0;
1095 regnum < numregs;
1096 regnum++)
1097 {
1098 if (gdbarch_register_name (gdbarch, regnum) == NULL
1099 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1100 continue;
1101 changed = register_changed_p (regnum, prev_regs, this_regs);
1102 if (changed < 0)
1103 error (_("-data-list-changed-registers: "
1104 "Unable to read register contents."));
1105 else if (changed)
1106 uiout->field_int (NULL, regnum);
1107 }
1108 }
1109
1110 /* Else, list of register #s, just do listed regs. */
1111 for (i = 0; i < argc; i++)
1112 {
1113 regnum = atoi (argv[i]);
1114
1115 if (regnum >= 0
1116 && regnum < numregs
1117 && gdbarch_register_name (gdbarch, regnum) != NULL
1118 && *gdbarch_register_name (gdbarch, regnum) != '\000')
1119 {
1120 changed = register_changed_p (regnum, prev_regs, this_regs);
1121 if (changed < 0)
1122 error (_("-data-list-changed-registers: "
1123 "Unable to read register contents."));
1124 else if (changed)
1125 uiout->field_int (NULL, regnum);
1126 }
1127 else
1128 error (_("bad register number"));
1129 }
1130 do_cleanups (cleanup);
1131 }
1132
1133 static int
1134 register_changed_p (int regnum, struct regcache *prev_regs,
1135 struct regcache *this_regs)
1136 {
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;
1142
1143 /* First time through or after gdbarch change consider all registers
1144 as changed. */
1145 if (!prev_regs || get_regcache_arch (prev_regs) != gdbarch)
1146 return 1;
1147
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);
1151
1152 if (this_status != prev_status)
1153 return 1;
1154 else if (this_status == REG_VALID)
1155 return memcmp (prev_buffer, this_buffer,
1156 register_size (gdbarch, regnum)) != 0;
1157 else
1158 return 0;
1159 }
1160
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. */
1169
1170 void
1171 mi_cmd_data_list_register_values (char *command, char **argv, int argc)
1172 {
1173 struct ui_out *uiout = current_uiout;
1174 struct frame_info *frame;
1175 struct gdbarch *gdbarch;
1176 int regnum, numregs, format;
1177 int i;
1178 struct cleanup *list_cleanup;
1179 int skip_unavailable = 0;
1180 int oind = 0;
1181 enum opt
1182 {
1183 SKIP_UNAVAILABLE,
1184 };
1185 static const struct mi_opt opts[] =
1186 {
1187 {"-skip-unavailable", SKIP_UNAVAILABLE, 0},
1188 { 0, 0, 0 }
1189 };
1190
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
1196 debugged. */
1197
1198 while (1)
1199 {
1200 char *oarg;
1201 int opt = mi_getopt ("-data-list-register-values", argc, argv,
1202 opts, &oind, &oarg);
1203
1204 if (opt < 0)
1205 break;
1206 switch ((enum opt) opt)
1207 {
1208 case SKIP_UNAVAILABLE:
1209 skip_unavailable = 1;
1210 break;
1211 }
1212 }
1213
1214 if (argc - oind < 1)
1215 error (_("-data-list-register-values: Usage: "
1216 "-data-list-register-values [--skip-unavailable] <format>"
1217 " [<regnum1>...<regnumN>]"));
1218
1219 format = (int) argv[oind][0];
1220
1221 frame = get_selected_frame (NULL);
1222 gdbarch = get_frame_arch (frame);
1223 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1224
1225 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-values");
1226
1227 if (argc - oind == 1)
1228 {
1229 /* No args, beside the format: do all the regs. */
1230 for (regnum = 0;
1231 regnum < numregs;
1232 regnum++)
1233 {
1234 if (gdbarch_register_name (gdbarch, regnum) == NULL
1235 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1236 continue;
1237
1238 output_register (frame, regnum, format, skip_unavailable);
1239 }
1240 }
1241
1242 /* Else, list of register #s, just do listed regs. */
1243 for (i = 1 + oind; i < argc; i++)
1244 {
1245 regnum = atoi (argv[i]);
1246
1247 if (regnum >= 0
1248 && regnum < numregs
1249 && gdbarch_register_name (gdbarch, regnum) != NULL
1250 && *gdbarch_register_name (gdbarch, regnum) != '\000')
1251 output_register (frame, regnum, format, skip_unavailable);
1252 else
1253 error (_("bad register number"));
1254 }
1255 do_cleanups (list_cleanup);
1256 }
1257
1258 /* Output one register REGNUM's contents in the desired FORMAT. If
1259 SKIP_UNAVAILABLE is true, skip the register if it is
1260 unavailable. */
1261
1262 static void
1263 output_register (struct frame_info *frame, int regnum, int format,
1264 int skip_unavailable)
1265 {
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;
1270
1271 if (skip_unavailable && !value_entirely_available (val))
1272 return;
1273
1274 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1275 uiout->field_int ("number", regnum);
1276
1277 if (format == 'N')
1278 format = 0;
1279
1280 if (format == 'r')
1281 format = 'z';
1282
1283 string_file stb;
1284
1285 get_formatted_print_options (&opts, format);
1286 opts.deref_ref = 1;
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);
1291
1292 do_cleanups (tuple_cleanup);
1293 }
1294
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>] */
1299 void
1300 mi_cmd_data_write_register_values (char *command, char **argv, int argc)
1301 {
1302 struct regcache *regcache;
1303 struct gdbarch *gdbarch;
1304 int numregs, i;
1305
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
1311 debugged. */
1312
1313 regcache = get_current_regcache ();
1314 gdbarch = get_regcache_arch (regcache);
1315 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1316
1317 if (argc == 0)
1318 error (_("-data-write-register-values: Usage: -data-write-register-"
1319 "values <format> [<regnum1> <value1>...<regnumN> <valueN>]"));
1320
1321 if (!target_has_registers)
1322 error (_("-data-write-register-values: No registers."));
1323
1324 if (!(argc - 1))
1325 error (_("-data-write-register-values: No regs and values specified."));
1326
1327 if ((argc - 1) % 2)
1328 error (_("-data-write-register-values: "
1329 "Regs and vals are not in pairs."));
1330
1331 for (i = 1; i < argc; i = i + 2)
1332 {
1333 int regnum = atoi (argv[i]);
1334
1335 if (regnum >= 0 && regnum < numregs
1336 && gdbarch_register_name (gdbarch, regnum)
1337 && *gdbarch_register_name (gdbarch, regnum))
1338 {
1339 LONGEST value;
1340
1341 /* Get the value as a number. */
1342 value = parse_and_eval_address (argv[i + 1]);
1343
1344 /* Write it down. */
1345 regcache_cooked_write_signed (regcache, regnum, value);
1346 }
1347 else
1348 error (_("bad register number"));
1349 }
1350 }
1351
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. */
1355
1356 void
1357 mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
1358 {
1359 struct value *val;
1360 struct value_print_options opts;
1361 struct ui_out *uiout = current_uiout;
1362
1363 if (argc != 1)
1364 error (_("-data-evaluate-expression: "
1365 "Usage: -data-evaluate-expression expression"));
1366
1367 expression_up expr = parse_expression (argv[0]);
1368
1369 val = evaluate_expression (expr.get ());
1370
1371 string_file stb;
1372
1373 /* Print the result of the expression evaluation. */
1374 get_user_print_options (&opts);
1375 opts.deref_ref = 0;
1376 common_val_print (val, &stb, 0, &opts, current_language);
1377
1378 uiout->field_stream ("value", stb);
1379 }
1380
1381 /* This is the -data-read-memory command.
1382
1383 ADDR: start address of data to be dumped.
1384 WORD-FORMAT: a char indicating format for the ``word''. See
1385 the ``x'' command.
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.
1391
1392 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
1393 displayes them. Returns:
1394
1395 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
1396
1397 Returns:
1398 The number of bytes read is SIZE*ROW*COL. */
1399
1400 void
1401 mi_cmd_data_read_memory (char *command, char **argv, int argc)
1402 {
1403 struct gdbarch *gdbarch = get_current_arch ();
1404 struct ui_out *uiout = current_uiout;
1405 CORE_ADDR addr;
1406 long total_bytes, nr_cols, nr_rows;
1407 char word_format;
1408 struct type *word_type;
1409 long word_size;
1410 char word_asize;
1411 char aschar;
1412 int nr_bytes;
1413 long offset = 0;
1414 int oind = 0;
1415 char *oarg;
1416 enum opt
1417 {
1418 OFFSET_OPT
1419 };
1420 static const struct mi_opt opts[] =
1421 {
1422 {"o", OFFSET_OPT, 1},
1423 { 0, 0, 0 }
1424 };
1425
1426 while (1)
1427 {
1428 int opt = mi_getopt ("-data-read-memory", argc, argv, opts,
1429 &oind, &oarg);
1430
1431 if (opt < 0)
1432 break;
1433 switch ((enum opt) opt)
1434 {
1435 case OFFSET_OPT:
1436 offset = atol (oarg);
1437 break;
1438 }
1439 }
1440 argv += oind;
1441 argc -= oind;
1442
1443 if (argc < 5 || argc > 6)
1444 error (_("-data-read-memory: Usage: "
1445 "ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR]."));
1446
1447 /* Extract all the arguments. */
1448
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]);
1456 switch (word_size)
1457 {
1458 case 1:
1459 word_type = builtin_type (gdbarch)->builtin_int8;
1460 word_asize = 'b';
1461 break;
1462 case 2:
1463 word_type = builtin_type (gdbarch)->builtin_int16;
1464 word_asize = 'h';
1465 break;
1466 case 4:
1467 word_type = builtin_type (gdbarch)->builtin_int32;
1468 word_asize = 'w';
1469 break;
1470 case 8:
1471 word_type = builtin_type (gdbarch)->builtin_int64;
1472 word_asize = 'g';
1473 break;
1474 default:
1475 word_type = builtin_type (gdbarch)->builtin_int8;
1476 word_asize = 'b';
1477 }
1478 /* The number of rows. */
1479 nr_rows = atol (argv[3]);
1480 if (nr_rows <= 0)
1481 error (_("-data-read-memory: invalid number of rows."));
1482
1483 /* Number of bytes per row. */
1484 nr_cols = atol (argv[4]);
1485 if (nr_cols <= 0)
1486 error (_("-data-read-memory: invalid number of columns."));
1487
1488 /* The un-printable character when printing ascii. */
1489 if (argc == 6)
1490 aschar = *argv[5];
1491 else
1492 aschar = 0;
1493
1494 /* Create a buffer and read it in. */
1495 total_bytes = word_size * nr_rows * nr_cols;
1496
1497 std::unique_ptr<gdb_byte[]> mbuf (new gdb_byte[total_bytes]);
1498
1499 /* Dispatch memory reads to the topmost target, not the flattened
1500 current_target. */
1501 nr_bytes = target_read (current_target.beneath,
1502 TARGET_OBJECT_MEMORY, NULL, mbuf.get (),
1503 addr, total_bytes);
1504 if (nr_bytes <= 0)
1505 error (_("Unable to read memory."));
1506
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);
1515
1516 /* Build the result as a two dimentional table. */
1517 {
1518 int row;
1519 int row_byte;
1520 struct cleanup *cleanup_list;
1521
1522 string_file stream;
1523
1524 cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, "memory");
1525 for (row = 0, row_byte = 0;
1526 row < nr_rows;
1527 row++, row_byte += nr_cols * word_size)
1528 {
1529 int col;
1530 int col_byte;
1531 struct cleanup *cleanup_tuple;
1532 struct cleanup *cleanup_list_data;
1533 struct value_print_options opts;
1534
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 +
1538 row_byte); */
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;
1542 col < nr_cols;
1543 col++, col_byte += word_size)
1544 {
1545 if (col_byte + word_size > nr_bytes)
1546 {
1547 uiout->field_string (NULL, "N/A");
1548 }
1549 else
1550 {
1551 stream.clear ();
1552 print_scalar_formatted (&mbuf[col_byte], word_type, &opts,
1553 word_asize, &stream);
1554 uiout->field_stream (NULL, stream);
1555 }
1556 }
1557 do_cleanups (cleanup_list_data);
1558 if (aschar)
1559 {
1560 int byte;
1561
1562 stream.clear ();
1563 for (byte = row_byte;
1564 byte < row_byte + word_size * nr_cols; byte++)
1565 {
1566 if (byte >= nr_bytes)
1567 stream.putc ('X');
1568 else if (mbuf[byte] < 32 || mbuf[byte] > 126)
1569 stream.putc (aschar);
1570 else
1571 stream.putc (mbuf[byte]);
1572 }
1573 uiout->field_stream ("ascii", stream);
1574 }
1575 do_cleanups (cleanup_tuple);
1576 }
1577 do_cleanups (cleanup_list);
1578 }
1579 }
1580
1581 void
1582 mi_cmd_data_read_memory_bytes (char *command, char **argv, int argc)
1583 {
1584 struct gdbarch *gdbarch = get_current_arch ();
1585 struct ui_out *uiout = current_uiout;
1586 struct cleanup *cleanups;
1587 CORE_ADDR addr;
1588 LONGEST length;
1589 memory_read_result_s *read_result;
1590 int ix;
1591 VEC(memory_read_result_s) *result;
1592 long offset = 0;
1593 int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
1594 int oind = 0;
1595 char *oarg;
1596 enum opt
1597 {
1598 OFFSET_OPT
1599 };
1600 static const struct mi_opt opts[] =
1601 {
1602 {"o", OFFSET_OPT, 1},
1603 { 0, 0, 0 }
1604 };
1605
1606 while (1)
1607 {
1608 int opt = mi_getopt ("-data-read-memory-bytes", argc, argv, opts,
1609 &oind, &oarg);
1610 if (opt < 0)
1611 break;
1612 switch ((enum opt) opt)
1613 {
1614 case OFFSET_OPT:
1615 offset = atol (oarg);
1616 break;
1617 }
1618 }
1619 argv += oind;
1620 argc -= oind;
1621
1622 if (argc != 2)
1623 error (_("Usage: [ -o OFFSET ] ADDR LENGTH."));
1624
1625 addr = parse_and_eval_address (argv[0]) + offset;
1626 length = atol (argv[1]);
1627
1628 result = read_memory_robust (current_target.beneath, addr, length);
1629
1630 cleanups = make_cleanup (free_memory_read_result_vector, &result);
1631
1632 if (VEC_length (memory_read_result_s, result) == 0)
1633 error (_("Unable to read memory."));
1634
1635 make_cleanup_ui_out_list_begin_end (uiout, "memory");
1636 for (ix = 0;
1637 VEC_iterate (memory_read_result_s, result, ix, read_result);
1638 ++ix)
1639 {
1640 struct cleanup *t = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1641 char *data, *p;
1642 int i;
1643 int alloc_len;
1644
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);
1648
1649 alloc_len = (read_result->end - read_result->begin) * 2 * unit_size + 1;
1650 data = (char *) xmalloc (alloc_len);
1651
1652 for (i = 0, p = data;
1653 i < ((read_result->end - read_result->begin) * unit_size);
1654 ++i, p += 2)
1655 {
1656 sprintf (p, "%02x", read_result->data[i]);
1657 }
1658 uiout->field_string ("contents", data);
1659 xfree (data);
1660 do_cleanups (t);
1661 }
1662 do_cleanups (cleanups);
1663 }
1664
1665 /* Implementation of the -data-write_memory command.
1666
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
1669 be written is.
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
1674 the ``x'' command.
1675 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
1676 VALUE: value to be written into the memory address.
1677
1678 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
1679
1680 Prints nothing. */
1681
1682 void
1683 mi_cmd_data_write_memory (char *command, char **argv, int argc)
1684 {
1685 struct gdbarch *gdbarch = get_current_arch ();
1686 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1687 CORE_ADDR addr;
1688 long word_size;
1689 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
1690 enough when using a compiler other than GCC. */
1691 LONGEST value;
1692 gdb_byte *buffer;
1693 struct cleanup *old_chain;
1694 long offset = 0;
1695 int oind = 0;
1696 char *oarg;
1697 enum opt
1698 {
1699 OFFSET_OPT
1700 };
1701 static const struct mi_opt opts[] =
1702 {
1703 {"o", OFFSET_OPT, 1},
1704 { 0, 0, 0 }
1705 };
1706
1707 while (1)
1708 {
1709 int opt = mi_getopt ("-data-write-memory", argc, argv, opts,
1710 &oind, &oarg);
1711
1712 if (opt < 0)
1713 break;
1714 switch ((enum opt) opt)
1715 {
1716 case OFFSET_OPT:
1717 offset = atol (oarg);
1718 break;
1719 }
1720 }
1721 argv += oind;
1722 argc -= oind;
1723
1724 if (argc != 4)
1725 error (_("-data-write-memory: Usage: "
1726 "[-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE."));
1727
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]);
1733
1734 /* Calculate the real address of the write destination. */
1735 addr += (offset * word_size);
1736
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);
1747 }
1748
1749 /* Implementation of the -data-write-memory-bytes command.
1750
1751 ADDR: start address
1752 DATA: string of bytes to write at that address
1753 COUNT: number of bytes to be filled (decimal integer). */
1754
1755 void
1756 mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
1757 {
1758 CORE_ADDR addr;
1759 char *cdata;
1760 gdb_byte *data;
1761 gdb_byte *databuf;
1762 size_t len_hex, len_bytes, len_units, i, steps, remaining_units;
1763 long int count_units;
1764 struct cleanup *back_to;
1765 int unit_size;
1766
1767 if (argc != 2 && argc != 3)
1768 error (_("Usage: ADDR DATA [COUNT]."));
1769
1770 addr = parse_and_eval_address (argv[0]);
1771 cdata = argv[1];
1772 len_hex = strlen (cdata);
1773 unit_size = gdbarch_addressable_memory_unit_size (get_current_arch ());
1774
1775 if (len_hex % (unit_size * 2) != 0)
1776 error (_("Hex-encoded '%s' must represent an integral number of "
1777 "addressable memory units."),
1778 cdata);
1779
1780 len_bytes = len_hex / 2;
1781 len_units = len_bytes / unit_size;
1782
1783 if (argc == 3)
1784 count_units = strtoul (argv[2], NULL, 10);
1785 else
1786 count_units = len_units;
1787
1788 databuf = XNEWVEC (gdb_byte, len_bytes);
1789 back_to = make_cleanup (xfree, databuf);
1790
1791 for (i = 0; i < len_bytes; ++i)
1792 {
1793 int x;
1794 if (sscanf (cdata + i * 2, "%02x", &x) != 1)
1795 error (_("Invalid argument"));
1796 databuf[i] = (gdb_byte) x;
1797 }
1798
1799 if (len_units < count_units)
1800 {
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);
1805
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);
1812
1813 if (remaining_units > 0)
1814 memcpy (data + steps * len_bytes, databuf,
1815 remaining_units * unit_size);
1816 }
1817 else
1818 {
1819 /* Pattern is longer than or equal to count:
1820 just copy count addressable memory units. */
1821 data = databuf;
1822 }
1823
1824 write_memory_with_notification (addr, data, count_units);
1825
1826 do_cleanups (back_to);
1827 }
1828
1829 void
1830 mi_cmd_enable_timings (char *command, char **argv, int argc)
1831 {
1832 if (argc == 0)
1833 do_timings = 1;
1834 else if (argc == 1)
1835 {
1836 if (strcmp (argv[0], "yes") == 0)
1837 do_timings = 1;
1838 else if (strcmp (argv[0], "no") == 0)
1839 do_timings = 0;
1840 else
1841 goto usage_error;
1842 }
1843 else
1844 goto usage_error;
1845
1846 return;
1847
1848 usage_error:
1849 error (_("-enable-timings: Usage: %s {yes|no}"), command);
1850 }
1851
1852 void
1853 mi_cmd_list_features (char *command, char **argv, int argc)
1854 {
1855 if (argc == 0)
1856 {
1857 struct cleanup *cleanup = NULL;
1858 struct ui_out *uiout = current_uiout;
1859
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");
1871
1872 if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
1873 uiout->field_string (NULL, "python");
1874
1875 do_cleanups (cleanup);
1876 return;
1877 }
1878
1879 error (_("-list-features should be passed no arguments"));
1880 }
1881
1882 void
1883 mi_cmd_list_target_features (char *command, char **argv, int argc)
1884 {
1885 if (argc == 0)
1886 {
1887 struct cleanup *cleanup = NULL;
1888 struct ui_out *uiout = current_uiout;
1889
1890 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1891 if (mi_async_p ())
1892 uiout->field_string (NULL, "async");
1893 if (target_can_execute_reverse)
1894 uiout->field_string (NULL, "reverse");
1895 do_cleanups (cleanup);
1896 return;
1897 }
1898
1899 error (_("-list-target-features should be passed no arguments"));
1900 }
1901
1902 void
1903 mi_cmd_add_inferior (char *command, char **argv, int argc)
1904 {
1905 struct inferior *inf;
1906
1907 if (argc != 0)
1908 error (_("-add-inferior should be passed no arguments"));
1909
1910 inf = add_inferior_with_spaces ();
1911
1912 current_uiout->field_fmt ("inferior", "i%d", inf->num);
1913 }
1914
1915 /* Callback used to find the first inferior other than the current
1916 one. */
1917
1918 static int
1919 get_other_inferior (struct inferior *inf, void *arg)
1920 {
1921 if (inf == current_inferior ())
1922 return 0;
1923
1924 return 1;
1925 }
1926
1927 void
1928 mi_cmd_remove_inferior (char *command, char **argv, int argc)
1929 {
1930 int id;
1931 struct inferior *inf;
1932
1933 if (argc != 1)
1934 error (_("-remove-inferior should be passed a single argument"));
1935
1936 if (sscanf (argv[0], "i%d", &id) != 1)
1937 error (_("the thread group id is syntactically invalid"));
1938
1939 inf = find_inferior_id (id);
1940 if (!inf)
1941 error (_("the specified thread group does not exist"));
1942
1943 if (inf->pid != 0)
1944 error (_("cannot remove an active inferior"));
1945
1946 if (inf == current_inferior ())
1947 {
1948 struct thread_info *tp = 0;
1949 struct inferior *new_inferior
1950 = iterate_over_inferiors (get_other_inferior, NULL);
1951
1952 if (new_inferior == NULL)
1953 error (_("Cannot remove last inferior"));
1954
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);
1960 }
1961
1962 delete_inferior (inf);
1963 }
1964
1965 \f
1966
1967 /* Execute a command within a safe environment.
1968 Return <0 for error; >=0 for ok.
1969
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). */
1973
1974 static void
1975 captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
1976 {
1977 struct mi_interp *mi = (struct mi_interp *) interp_data (command_interp ());
1978 struct cleanup *cleanup;
1979
1980 if (do_timings)
1981 current_command_ts = context->cmd_start;
1982
1983 current_token = xstrdup (context->token);
1984 cleanup = make_cleanup (free_current_contents, &current_token);
1985
1986 running_result_record_printed = 0;
1987 mi_proceeded = 0;
1988 switch (context->op)
1989 {
1990 case MI_COMMAND:
1991 /* A MI command was read from the input stream. */
1992 if (mi_debug_p)
1993 /* FIXME: gdb_???? */
1994 fprintf_unfiltered (mi->raw_stdout,
1995 " token=`%s' command=`%s' args=`%s'\n",
1996 context->token, context->command, context->args);
1997
1998 mi_cmd_execute (context);
1999
2000 /* Print the result if there were no errors.
2001
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)
2007 {
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);
2017 }
2018 else
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);
2023 break;
2024
2025 case CLI_COMMAND:
2026 {
2027 char *argv[2];
2028
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);
2038
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))
2044 {
2045 if (!running_result_record_printed)
2046 {
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);
2053 }
2054 else
2055 mi_out_rewind (uiout);
2056 }
2057 break;
2058 }
2059 }
2060
2061 do_cleanups (cleanup);
2062 }
2063
2064 /* Print a gdb exception to the MI output stream. */
2065
2066 static void
2067 mi_print_exception (const char *token, struct gdb_exception exception)
2068 {
2069 struct mi_interp *mi
2070 = (struct mi_interp *) interp_data (current_interpreter ());
2071
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);
2076 else
2077 fputstr_unfiltered (exception.message, '"', mi->raw_stdout);
2078 fputs_unfiltered ("\"", mi->raw_stdout);
2079
2080 switch (exception.error)
2081 {
2082 case UNDEFINED_COMMAND_ERROR:
2083 fputs_unfiltered (",code=\"undefined-command\"", mi->raw_stdout);
2084 break;
2085 }
2086
2087 fputs_unfiltered ("\n", mi->raw_stdout);
2088 }
2089
2090 /* Determine whether the parsed command already notifies the
2091 user_selected_context_changed observer. */
2092
2093 static int
2094 command_notifies_uscc_observer (struct mi_parse *command)
2095 {
2096 if (command->op == CLI_COMMAND)
2097 {
2098 /* CLI commands "thread" and "inferior" already send it. */
2099 return (strncmp (command->command, "thread ", 7) == 0
2100 || strncmp (command->command, "inferior ", 9) == 0);
2101 }
2102 else /* MI_COMMAND */
2103 {
2104 if (strcmp (command->command, "interpreter-exec") == 0
2105 && command->argc > 1)
2106 {
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);
2110 }
2111
2112 else
2113 /* -thread-select already sends it. */
2114 return strcmp (command->command, "thread-select") == 0;
2115 }
2116 }
2117
2118 void
2119 mi_execute_command (const char *cmd, int from_tty)
2120 {
2121 char *token;
2122 struct mi_parse *command = NULL;
2123
2124 /* This is to handle EOF (^D). We just quit gdb. */
2125 /* FIXME: we should call some API function here. */
2126 if (cmd == 0)
2127 quit_force (NULL, from_tty);
2128
2129 target_log_command (cmd);
2130
2131 TRY
2132 {
2133 command = mi_parse (cmd, &token);
2134 }
2135 CATCH (exception, RETURN_MASK_ALL)
2136 {
2137 mi_print_exception (token, exception);
2138 xfree (token);
2139 }
2140 END_CATCH
2141
2142 if (command != NULL)
2143 {
2144 ptid_t previous_ptid = inferior_ptid;
2145 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
2146
2147 command->token = token;
2148
2149 if (command->cmd != NULL && command->cmd->suppress_notification != NULL)
2150 {
2151 make_cleanup_restore_integer (command->cmd->suppress_notification);
2152 *command->cmd->suppress_notification = 1;
2153 }
2154
2155 if (do_timings)
2156 {
2157 command->cmd_start = new mi_timestamp ();
2158 timestamp (command->cmd_start);
2159 }
2160
2161 TRY
2162 {
2163 captured_mi_execute_command (current_uiout, command);
2164 }
2165 CATCH (result, RETURN_MASK_ALL)
2166 {
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
2170 disabled. */
2171 async_enable_stdin ();
2172 current_ui->prompt_state = PROMPT_NEEDED;
2173
2174 /* The command execution failed and error() was called
2175 somewhere. */
2176 mi_print_exception (command->token, result);
2177 mi_out_rewind (current_uiout);
2178 }
2179 END_CATCH
2180
2181 bpstat_do_actions ();
2182
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
2190 again. */
2191 && !command_notifies_uscc_observer (command))
2192 {
2193 struct mi_interp *mi
2194 = (struct mi_interp *) top_level_interpreter_data ();
2195 int report_change = 0;
2196
2197 if (command->thread == -1)
2198 {
2199 report_change = (!ptid_equal (previous_ptid, null_ptid)
2200 && !ptid_equal (inferior_ptid, previous_ptid)
2201 && !ptid_equal (inferior_ptid, null_ptid));
2202 }
2203 else if (!ptid_equal (inferior_ptid, null_ptid))
2204 {
2205 struct thread_info *ti = inferior_thread ();
2206
2207 report_change = (ti->global_num != command->thread);
2208 }
2209
2210 if (report_change)
2211 {
2212 observer_notify_user_selected_context_changed
2213 (USER_SELECTED_THREAD | USER_SELECTED_FRAME);
2214 }
2215 }
2216
2217 mi_parse_free (command);
2218
2219 do_cleanups (cleanup);
2220 }
2221 }
2222
2223 static void
2224 mi_cmd_execute (struct mi_parse *parse)
2225 {
2226 struct cleanup *cleanup;
2227
2228 cleanup = prepare_execute_command ();
2229
2230 if (parse->all && parse->thread_group != -1)
2231 error (_("Cannot specify --thread-group together with --all"));
2232
2233 if (parse->all && parse->thread != -1)
2234 error (_("Cannot specify --thread together with --all"));
2235
2236 if (parse->thread_group != -1 && parse->thread != -1)
2237 error (_("Cannot specify --thread together with --thread-group"));
2238
2239 if (parse->frame != -1 && parse->thread == -1)
2240 error (_("Cannot specify --frame without --thread"));
2241
2242 if (parse->thread_group != -1)
2243 {
2244 struct inferior *inf = find_inferior_id (parse->thread_group);
2245 struct thread_info *tp = 0;
2246
2247 if (!inf)
2248 error (_("Invalid thread group for the --thread-group option"));
2249
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
2255 thread. */
2256 if (inf->pid != 0)
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);
2260 }
2261
2262 if (parse->thread != -1)
2263 {
2264 struct thread_info *tp = find_thread_global_id (parse->thread);
2265
2266 if (!tp)
2267 error (_("Invalid thread id: %d"), parse->thread);
2268
2269 if (is_exited (tp->ptid))
2270 error (_("Thread id: %d has terminated"), parse->thread);
2271
2272 switch_to_thread (tp->ptid);
2273 }
2274
2275 if (parse->frame != -1)
2276 {
2277 struct frame_info *fid;
2278 int frame = parse->frame;
2279
2280 fid = find_relative_frame (get_current_frame (), &frame);
2281 if (frame == 0)
2282 /* find_relative_frame was successful */
2283 select_frame (fid);
2284 else
2285 error (_("Invalid frame id: %d"), frame);
2286 }
2287
2288 if (parse->language != language_unknown)
2289 {
2290 make_cleanup_restore_current_language ();
2291 set_language (parse->language);
2292 }
2293
2294 current_context = parse;
2295
2296 if (parse->cmd->argv_func != NULL)
2297 {
2298 parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
2299 }
2300 else if (parse->cmd->cli.cmd != 0)
2301 {
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,
2306 parse->args);
2307 }
2308 else
2309 {
2310 /* FIXME: DELETE THIS. */
2311 string_file stb;
2312
2313 stb.puts ("Undefined mi command: ");
2314 stb.putstr (parse->command, '"');
2315 stb.puts (" (missing implementation)");
2316
2317 error_stream (stb);
2318 }
2319 do_cleanups (cleanup);
2320 }
2321
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. */
2325
2326 void
2327 mi_execute_cli_command (const char *cmd, int args_p, const char *args)
2328 {
2329 if (cmd != 0)
2330 {
2331 struct cleanup *old_cleanups;
2332 char *run;
2333
2334 if (args_p)
2335 run = xstrprintf ("%s %s", cmd, args);
2336 else
2337 run = xstrdup (cmd);
2338 if (mi_debug_p)
2339 /* FIXME: gdb_???? */
2340 fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
2341 cmd, run);
2342 old_cleanups = make_cleanup (xfree, run);
2343 execute_command (run, 0 /* from_tty */ );
2344 do_cleanups (old_cleanups);
2345 return;
2346 }
2347 }
2348
2349 void
2350 mi_execute_async_cli_command (char *cli_command, char **argv, int argc)
2351 {
2352 struct cleanup *old_cleanups;
2353 char *run;
2354
2355 if (mi_async_p ())
2356 run = xstrprintf ("%s %s&", cli_command, argc ? *argv : "");
2357 else
2358 run = xstrprintf ("%s %s", cli_command, argc ? *argv : "");
2359 old_cleanups = make_cleanup (xfree, run);
2360
2361 execute_command (run, 0 /* from_tty */ );
2362
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);
2366 }
2367
2368 void
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)
2374 {
2375 using namespace std::chrono;
2376 static steady_clock::time_point last_update;
2377 static char *previous_sect_name = NULL;
2378 int new_section;
2379 struct ui_out *saved_uiout;
2380 struct ui_out *uiout;
2381 struct mi_interp *mi
2382 = (struct mi_interp *) interp_data (current_interpreter ());
2383
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;
2388
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);
2396 else
2397 return;
2398
2399 uiout = current_uiout;
2400
2401 new_section = (previous_sect_name ?
2402 strcmp (previous_sect_name, section_name) : 1);
2403 if (new_section)
2404 {
2405 struct cleanup *cleanup_tuple;
2406
2407 xfree (previous_sect_name);
2408 previous_sect_name = xstrdup (section_name);
2409
2410 if (current_token)
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);
2421 }
2422
2423 steady_clock::time_point time_now = steady_clock::now ();
2424 if (time_now - last_update > milliseconds (500))
2425 {
2426 struct cleanup *cleanup_tuple;
2427
2428 last_update = time_now;
2429 if (current_token)
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);
2442 }
2443
2444 xfree (uiout);
2445 current_uiout = saved_uiout;
2446 }
2447
2448 static void
2449 timestamp (struct mi_timestamp *tv)
2450 {
2451 using namespace std::chrono;
2452
2453 tv->wallclock = steady_clock::now ();
2454 run_time_clock::now (tv->utime, tv->stime);
2455 }
2456
2457 static void
2458 print_diff_now (struct ui_file *file, struct mi_timestamp *start)
2459 {
2460 struct mi_timestamp now;
2461
2462 timestamp (&now);
2463 print_diff (file, start, &now);
2464 }
2465
2466 void
2467 mi_print_timing_maybe (struct ui_file *file)
2468 {
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);
2473 }
2474
2475 static void
2476 print_diff (struct ui_file *file, struct mi_timestamp *start,
2477 struct mi_timestamp *end)
2478 {
2479 using namespace std::chrono;
2480
2481 duration<double> wallclock = end->wallclock - start->wallclock;
2482 duration<double> utime = end->utime - start->utime;
2483 duration<double> stime = end->stime - start->stime;
2484
2485 fprintf_unfiltered
2486 (file,
2487 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
2488 wallclock.count (), utime.count (), stime.count ());
2489 }
2490
2491 void
2492 mi_cmd_trace_define_variable (char *command, char **argv, int argc)
2493 {
2494 LONGEST initval = 0;
2495 struct trace_state_variable *tsv;
2496 char *name = 0;
2497
2498 if (argc != 1 && argc != 2)
2499 error (_("Usage: -trace-define-variable VARIABLE [VALUE]"));
2500
2501 name = argv[0];
2502 if (*name++ != '$')
2503 error (_("Name of trace variable should start with '$'"));
2504
2505 validate_trace_state_variable_name (name);
2506
2507 tsv = find_trace_state_variable (name);
2508 if (!tsv)
2509 tsv = create_trace_state_variable (name);
2510
2511 if (argc == 2)
2512 initval = value_as_long (parse_and_eval (argv[1]));
2513
2514 tsv->initial_value = initval;
2515 }
2516
2517 void
2518 mi_cmd_trace_list_variables (char *command, char **argv, int argc)
2519 {
2520 if (argc != 0)
2521 error (_("-trace-list-variables: no arguments allowed"));
2522
2523 tvariables_info_1 ();
2524 }
2525
2526 void
2527 mi_cmd_trace_find (char *command, char **argv, int argc)
2528 {
2529 char *mode;
2530
2531 if (argc == 0)
2532 error (_("trace selection mode is required"));
2533
2534 mode = argv[0];
2535
2536 if (strcmp (mode, "none") == 0)
2537 {
2538 tfind_1 (tfind_number, -1, 0, 0, 0);
2539 return;
2540 }
2541
2542 check_trace_running (current_trace_status ());
2543
2544 if (strcmp (mode, "frame-number") == 0)
2545 {
2546 if (argc != 2)
2547 error (_("frame number is required"));
2548 tfind_1 (tfind_number, atoi (argv[1]), 0, 0, 0);
2549 }
2550 else if (strcmp (mode, "tracepoint-number") == 0)
2551 {
2552 if (argc != 2)
2553 error (_("tracepoint number is required"));
2554 tfind_1 (tfind_tp, atoi (argv[1]), 0, 0, 0);
2555 }
2556 else if (strcmp (mode, "pc") == 0)
2557 {
2558 if (argc != 2)
2559 error (_("PC is required"));
2560 tfind_1 (tfind_pc, 0, parse_and_eval_address (argv[1]), 0, 0);
2561 }
2562 else if (strcmp (mode, "pc-inside-range") == 0)
2563 {
2564 if (argc != 3)
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);
2568 }
2569 else if (strcmp (mode, "pc-outside-range") == 0)
2570 {
2571 if (argc != 3)
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);
2575 }
2576 else if (strcmp (mode, "line") == 0)
2577 {
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;
2582
2583 if (argc != 2)
2584 error (_("Line is required"));
2585
2586 sals = decode_line_with_current_source (argv[1],
2587 DECODE_LINE_FUNFIRSTLINE);
2588 back_to = make_cleanup (xfree, sals.sals);
2589
2590 sal = sals.sals[0];
2591
2592 if (sal.symtab == 0)
2593 error (_("Could not find the specified line"));
2594
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);
2597 else
2598 error (_("Could not find the specified line"));
2599
2600 do_cleanups (back_to);
2601 }
2602 else
2603 error (_("Invalid mode '%s'"), mode);
2604
2605 if (has_stack_frames () || get_traceframe_number () >= 0)
2606 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS, 1);
2607 }
2608
2609 void
2610 mi_cmd_trace_save (char *command, char **argv, int argc)
2611 {
2612 int target_saves = 0;
2613 int generate_ctf = 0;
2614 char *filename;
2615 int oind = 0;
2616 char *oarg;
2617
2618 enum opt
2619 {
2620 TARGET_SAVE_OPT, CTF_OPT
2621 };
2622 static const struct mi_opt opts[] =
2623 {
2624 {"r", TARGET_SAVE_OPT, 0},
2625 {"ctf", CTF_OPT, 0},
2626 { 0, 0, 0 }
2627 };
2628
2629 while (1)
2630 {
2631 int opt = mi_getopt ("-trace-save", argc, argv, opts,
2632 &oind, &oarg);
2633
2634 if (opt < 0)
2635 break;
2636 switch ((enum opt) opt)
2637 {
2638 case TARGET_SAVE_OPT:
2639 target_saves = 1;
2640 break;
2641 case CTF_OPT:
2642 generate_ctf = 1;
2643 break;
2644 }
2645 }
2646
2647 if (argc - oind != 1)
2648 error (_("Exactly one argument required "
2649 "(file in which to save trace data)"));
2650
2651 filename = argv[oind];
2652
2653 if (generate_ctf)
2654 trace_save_ctf (filename, target_saves);
2655 else
2656 trace_save_tfile (filename, target_saves);
2657 }
2658
2659 void
2660 mi_cmd_trace_start (char *command, char **argv, int argc)
2661 {
2662 start_tracing (NULL);
2663 }
2664
2665 void
2666 mi_cmd_trace_status (char *command, char **argv, int argc)
2667 {
2668 trace_status_mi (0);
2669 }
2670
2671 void
2672 mi_cmd_trace_stop (char *command, char **argv, int argc)
2673 {
2674 stop_tracing (NULL);
2675 trace_status_mi (1);
2676 }
2677
2678 /* Implement the "-ada-task-info" command. */
2679
2680 void
2681 mi_cmd_ada_task_info (char *command, char **argv, int argc)
2682 {
2683 if (argc != 0 && argc != 1)
2684 error (_("Invalid MI command"));
2685
2686 print_ada_task_info (current_uiout, argv[0], current_inferior ());
2687 }
2688
2689 /* Print EXPRESSION according to VALUES. */
2690
2691 static void
2692 print_variable_or_computed (const char *expression, enum print_values values)
2693 {
2694 struct cleanup *old_chain;
2695 struct value *val;
2696 struct type *type;
2697 struct ui_out *uiout = current_uiout;
2698
2699 string_file stb;
2700
2701 expression_up expr = parse_expression (expression);
2702
2703 if (values == PRINT_SIMPLE_VALUES)
2704 val = evaluate_type (expr.get ());
2705 else
2706 val = evaluate_expression (expr.get ());
2707
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);
2712
2713 switch (values)
2714 {
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)
2722 {
2723 struct value_print_options opts;
2724
2725 get_no_prettyformat_print_options (&opts);
2726 opts.deref_ref = 1;
2727 common_val_print (val, &stb, 0, &opts, current_language);
2728 uiout->field_stream ("value", stb);
2729 }
2730 break;
2731 case PRINT_ALL_VALUES:
2732 {
2733 struct value_print_options opts;
2734
2735 get_no_prettyformat_print_options (&opts);
2736 opts.deref_ref = 1;
2737 common_val_print (val, &stb, 0, &opts, current_language);
2738 uiout->field_stream ("value", stb);
2739 }
2740 break;
2741 }
2742
2743 do_cleanups (old_chain);
2744 }
2745
2746 /* Implement the "-trace-frame-collected" command. */
2747
2748 void
2749 mi_cmd_trace_frame_collected (char *command, char **argv, int argc)
2750 {
2751 struct cleanup *old_chain;
2752 struct bp_location *tloc;
2753 int stepping_frame;
2754 struct collection_list *clist;
2755 struct collection_list tracepoint_list, stepping_list;
2756 struct traceframe_info *tinfo;
2757 int oind = 0;
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;
2763 enum opt
2764 {
2765 VAR_PRINT_VALUES,
2766 COMP_PRINT_VALUES,
2767 REGISTERS_FORMAT,
2768 MEMORY_CONTENTS,
2769 };
2770 static const struct mi_opt opts[] =
2771 {
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},
2776 { 0, 0, 0 }
2777 };
2778
2779 while (1)
2780 {
2781 char *oarg;
2782 int opt = mi_getopt ("-trace-frame-collected", argc, argv, opts,
2783 &oind, &oarg);
2784 if (opt < 0)
2785 break;
2786 switch ((enum opt) opt)
2787 {
2788 case VAR_PRINT_VALUES:
2789 var_print_values = mi_parse_print_values (oarg);
2790 break;
2791 case COMP_PRINT_VALUES:
2792 comp_print_values = mi_parse_print_values (oarg);
2793 break;
2794 case REGISTERS_FORMAT:
2795 registers_format = oarg[0];
2796 case MEMORY_CONTENTS:
2797 memory_contents = 1;
2798 break;
2799 }
2800 }
2801
2802 if (oind != argc)
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]"));
2808
2809 /* This throws an error is not inspecting a trace frame. */
2810 tloc = get_traceframe_location (&stepping_frame);
2811
2812 /* This command only makes sense for the current frame, not the
2813 selected frame. */
2814 old_chain = make_cleanup_restore_current_thread ();
2815 select_frame (get_current_frame ());
2816
2817 encode_actions (tloc, &tracepoint_list, &stepping_list);
2818
2819 if (stepping_frame)
2820 clist = &stepping_list;
2821 else
2822 clist = &tracepoint_list;
2823
2824 tinfo = get_traceframe_info ();
2825
2826 /* Explicitly wholly collected variables. */
2827 {
2828 struct cleanup *list_cleanup;
2829 int i;
2830
2831 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout,
2832 "explicit-variables");
2833
2834 const std::vector<std::string> &wholly_collected
2835 = clist->wholly_collected ();
2836 for (size_t i = 0; i < wholly_collected.size (); i++)
2837 {
2838 const std::string &str = wholly_collected[i];
2839 print_variable_or_computed (str.c_str (), var_print_values);
2840 }
2841
2842 do_cleanups (list_cleanup);
2843 }
2844
2845 /* Computed expressions. */
2846 {
2847 struct cleanup *list_cleanup;
2848 char *p;
2849 int i;
2850
2851 list_cleanup
2852 = make_cleanup_ui_out_list_begin_end (uiout,
2853 "computed-expressions");
2854
2855 const std::vector<std::string> &computed = clist->computed ();
2856 for (size_t i = 0; i < computed.size (); i++)
2857 {
2858 const std::string &str = computed[i];
2859 print_variable_or_computed (str.c_str (), comp_print_values);
2860 }
2861
2862 do_cleanups (list_cleanup);
2863 }
2864
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. */
2869 {
2870 struct cleanup *list_cleanup;
2871 struct frame_info *frame;
2872 struct gdbarch *gdbarch;
2873 int regnum;
2874 int numregs;
2875
2876 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "registers");
2877
2878 frame = get_selected_frame (NULL);
2879 gdbarch = get_frame_arch (frame);
2880 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
2881
2882 for (regnum = 0; regnum < numregs; regnum++)
2883 {
2884 if (gdbarch_register_name (gdbarch, regnum) == NULL
2885 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
2886 continue;
2887
2888 output_register (frame, regnum, registers_format, 1);
2889 }
2890
2891 do_cleanups (list_cleanup);
2892 }
2893
2894 /* Trace state variables. */
2895 {
2896 struct cleanup *list_cleanup;
2897 int tvar;
2898 char *tsvname;
2899 int i;
2900
2901 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "tvars");
2902
2903 tsvname = NULL;
2904 make_cleanup (free_current_contents, &tsvname);
2905
2906 for (i = 0; VEC_iterate (int, tinfo->tvars, i, tvar); i++)
2907 {
2908 struct cleanup *cleanup_child;
2909 struct trace_state_variable *tsv;
2910
2911 tsv = find_trace_state_variable_by_number (tvar);
2912
2913 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2914
2915 if (tsv != NULL)
2916 {
2917 tsvname = (char *) xrealloc (tsvname, strlen (tsv->name) + 2);
2918 tsvname[0] = '$';
2919 strcpy (tsvname + 1, tsv->name);
2920 uiout->field_string ("name", tsvname);
2921
2922 tsv->value_known = target_get_trace_state_variable_value (tsv->number,
2923 &tsv->value);
2924 uiout->field_int ("current", tsv->value);
2925 }
2926 else
2927 {
2928 uiout->field_skip ("name");
2929 uiout->field_skip ("current");
2930 }
2931
2932 do_cleanups (cleanup_child);
2933 }
2934
2935 do_cleanups (list_cleanup);
2936 }
2937
2938 /* Memory. */
2939 {
2940 struct cleanup *list_cleanup;
2941 VEC(mem_range_s) *available_memory = NULL;
2942 struct mem_range *r;
2943 int i;
2944
2945 traceframe_available_memory (&available_memory, 0, ULONGEST_MAX);
2946 make_cleanup (VEC_cleanup(mem_range_s), &available_memory);
2947
2948 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "memory");
2949
2950 for (i = 0; VEC_iterate (mem_range_s, available_memory, i, r); i++)
2951 {
2952 struct cleanup *cleanup_child;
2953 gdb_byte *data;
2954 struct gdbarch *gdbarch = target_gdbarch ();
2955
2956 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2957
2958 uiout->field_core_addr ("address", gdbarch, r->start);
2959 uiout->field_int ("length", r->length);
2960
2961 data = (gdb_byte *) xmalloc (r->length);
2962 make_cleanup (xfree, data);
2963
2964 if (memory_contents)
2965 {
2966 if (target_read_memory (r->start, data, r->length) == 0)
2967 {
2968 int m;
2969 char *data_str, *p;
2970
2971 data_str = (char *) xmalloc (r->length * 2 + 1);
2972 make_cleanup (xfree, data_str);
2973
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);
2977 }
2978 else
2979 uiout->field_skip ("contents");
2980 }
2981 do_cleanups (cleanup_child);
2982 }
2983
2984 do_cleanups (list_cleanup);
2985 }
2986
2987 do_cleanups (old_chain);
2988 }
2989
2990 void
2991 _initialize_mi_main (void)
2992 {
2993 struct cmd_list_element *c;
2994
2995 add_setshow_boolean_cmd ("mi-async", class_run,
2996 &mi_async_1, _("\
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,
3002 &setlist,
3003 &showlist);
3004
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");
3010 }
This page took 0.140325 seconds and 5 git commands to generate.