C++ify mi_parse
[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 (const 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 (const char *command, char **argv, int argc)
149 {
150 struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
151
152 /* We have to print everything right here because we never return. */
153 if (current_token)
154 fputs_unfiltered (current_token, mi->raw_stdout);
155 fputs_unfiltered ("^exit\n", mi->raw_stdout);
156 mi_out_put (current_uiout, mi->raw_stdout);
157 gdb_flush (mi->raw_stdout);
158 /* FIXME: The function called is not yet a formal libgdb function. */
159 quit_force (NULL, FROM_TTY);
160 }
161
162 void
163 mi_cmd_exec_next (const char *command, char **argv, int argc)
164 {
165 /* FIXME: Should call a libgdb function, not a cli wrapper. */
166 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
167 mi_execute_async_cli_command ("reverse-next", argv + 1, argc - 1);
168 else
169 mi_execute_async_cli_command ("next", argv, argc);
170 }
171
172 void
173 mi_cmd_exec_next_instruction (const char *command, char **argv, int argc)
174 {
175 /* FIXME: Should call a libgdb function, not a cli wrapper. */
176 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
177 mi_execute_async_cli_command ("reverse-nexti", argv + 1, argc - 1);
178 else
179 mi_execute_async_cli_command ("nexti", argv, argc);
180 }
181
182 void
183 mi_cmd_exec_step (const char *command, char **argv, int argc)
184 {
185 /* FIXME: Should call a libgdb function, not a cli wrapper. */
186 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
187 mi_execute_async_cli_command ("reverse-step", argv + 1, argc - 1);
188 else
189 mi_execute_async_cli_command ("step", argv, argc);
190 }
191
192 void
193 mi_cmd_exec_step_instruction (const char *command, char **argv, int argc)
194 {
195 /* FIXME: Should call a libgdb function, not a cli wrapper. */
196 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
197 mi_execute_async_cli_command ("reverse-stepi", argv + 1, argc - 1);
198 else
199 mi_execute_async_cli_command ("stepi", argv, argc);
200 }
201
202 void
203 mi_cmd_exec_finish (const char *command, char **argv, int argc)
204 {
205 /* FIXME: Should call a libgdb function, not a cli wrapper. */
206 if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
207 mi_execute_async_cli_command ("reverse-finish", argv + 1, argc - 1);
208 else
209 mi_execute_async_cli_command ("finish", argv, argc);
210 }
211
212 void
213 mi_cmd_exec_return (const char *command, char **argv, int argc)
214 {
215 /* This command doesn't really execute the target, it just pops the
216 specified number of frames. */
217 if (argc)
218 /* Call return_command with from_tty argument equal to 0 so as to
219 avoid being queried. */
220 return_command (*argv, 0);
221 else
222 /* Call return_command with from_tty argument equal to 0 so as to
223 avoid being queried. */
224 return_command (NULL, 0);
225
226 /* Because we have called return_command with from_tty = 0, we need
227 to print the frame here. */
228 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS, 1);
229 }
230
231 void
232 mi_cmd_exec_jump (const char *args, char **argv, int argc)
233 {
234 /* FIXME: Should call a libgdb function, not a cli wrapper. */
235 mi_execute_async_cli_command ("jump", argv, argc);
236 }
237
238 static void
239 proceed_thread (struct thread_info *thread, int pid)
240 {
241 if (!is_stopped (thread->ptid))
242 return;
243
244 if (pid != 0 && ptid_get_pid (thread->ptid) != pid)
245 return;
246
247 switch_to_thread (thread->ptid);
248 clear_proceed_status (0);
249 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
250 }
251
252 static int
253 proceed_thread_callback (struct thread_info *thread, void *arg)
254 {
255 int pid = *(int *)arg;
256
257 proceed_thread (thread, pid);
258 return 0;
259 }
260
261 static void
262 exec_continue (char **argv, int argc)
263 {
264 prepare_execution_command (&current_target, mi_async_p ());
265
266 if (non_stop)
267 {
268 /* In non-stop mode, 'resume' always resumes a single thread.
269 Therefore, to resume all threads of the current inferior, or
270 all threads in all inferiors, we need to iterate over
271 threads.
272
273 See comment on infcmd.c:proceed_thread_callback for rationale. */
274 if (current_context->all || current_context->thread_group != -1)
275 {
276 int pid = 0;
277 struct cleanup *back_to = make_cleanup_restore_current_thread ();
278
279 if (!current_context->all)
280 {
281 struct inferior *inf
282 = find_inferior_id (current_context->thread_group);
283
284 pid = inf->pid;
285 }
286 iterate_over_threads (proceed_thread_callback, &pid);
287 do_cleanups (back_to);
288 }
289 else
290 {
291 continue_1 (0);
292 }
293 }
294 else
295 {
296 scoped_restore save_multi = make_scoped_restore (&sched_multi);
297
298 if (current_context->all)
299 {
300 sched_multi = 1;
301 continue_1 (0);
302 }
303 else
304 {
305 /* In all-stop mode, -exec-continue traditionally resumed
306 either all threads, or one thread, depending on the
307 'scheduler-locking' variable. Let's continue to do the
308 same. */
309 continue_1 (1);
310 }
311 }
312 }
313
314 static void
315 exec_direction_forward (void *notused)
316 {
317 execution_direction = EXEC_FORWARD;
318 }
319
320 static void
321 exec_reverse_continue (char **argv, int argc)
322 {
323 enum exec_direction_kind dir = execution_direction;
324 struct cleanup *old_chain;
325
326 if (dir == EXEC_REVERSE)
327 error (_("Already in reverse mode."));
328
329 if (!target_can_execute_reverse)
330 error (_("Target %s does not support this command."), target_shortname);
331
332 old_chain = make_cleanup (exec_direction_forward, NULL);
333 execution_direction = EXEC_REVERSE;
334 exec_continue (argv, argc);
335 do_cleanups (old_chain);
336 }
337
338 void
339 mi_cmd_exec_continue (const char *command, char **argv, int argc)
340 {
341 if (argc > 0 && strcmp (argv[0], "--reverse") == 0)
342 exec_reverse_continue (argv + 1, argc - 1);
343 else
344 exec_continue (argv, argc);
345 }
346
347 static int
348 interrupt_thread_callback (struct thread_info *thread, void *arg)
349 {
350 int pid = *(int *)arg;
351
352 if (!is_running (thread->ptid))
353 return 0;
354
355 if (ptid_get_pid (thread->ptid) != pid)
356 return 0;
357
358 target_stop (thread->ptid);
359 return 0;
360 }
361
362 /* Interrupt the execution of the target. Note how we must play
363 around with the token variables, in order to display the current
364 token in the result of the interrupt command, and the previous
365 execution token when the target finally stops. See comments in
366 mi_cmd_execute. */
367
368 void
369 mi_cmd_exec_interrupt (const char *command, char **argv, int argc)
370 {
371 /* In all-stop mode, everything stops, so we don't need to try
372 anything specific. */
373 if (!non_stop)
374 {
375 interrupt_target_1 (0);
376 return;
377 }
378
379 if (current_context->all)
380 {
381 /* This will interrupt all threads in all inferiors. */
382 interrupt_target_1 (1);
383 }
384 else if (current_context->thread_group != -1)
385 {
386 struct inferior *inf = find_inferior_id (current_context->thread_group);
387
388 iterate_over_threads (interrupt_thread_callback, &inf->pid);
389 }
390 else
391 {
392 /* Interrupt just the current thread -- either explicitly
393 specified via --thread or whatever was current before
394 MI command was sent. */
395 interrupt_target_1 (0);
396 }
397 }
398
399 /* Callback for iterate_over_inferiors which starts the execution
400 of the given inferior.
401
402 ARG is a pointer to an integer whose value, if non-zero, indicates
403 that the program should be stopped when reaching the main subprogram
404 (similar to what the CLI "start" command does). */
405
406 static int
407 run_one_inferior (struct inferior *inf, void *arg)
408 {
409 int start_p = *(int *) arg;
410 const char *run_cmd = start_p ? "start" : "run";
411 struct target_ops *run_target = find_run_target ();
412 int async_p = mi_async && run_target->to_can_async_p (run_target);
413
414 if (inf->pid != 0)
415 {
416 if (inf->pid != ptid_get_pid (inferior_ptid))
417 {
418 struct thread_info *tp;
419
420 tp = any_thread_of_process (inf->pid);
421 if (!tp)
422 error (_("Inferior has no threads."));
423
424 switch_to_thread (tp->ptid);
425 }
426 }
427 else
428 {
429 set_current_inferior (inf);
430 switch_to_thread (null_ptid);
431 set_current_program_space (inf->pspace);
432 }
433 mi_execute_cli_command (run_cmd, async_p,
434 async_p ? "&" : NULL);
435 return 0;
436 }
437
438 void
439 mi_cmd_exec_run (const char *command, char **argv, int argc)
440 {
441 int start_p = 0;
442
443 /* Parse the command options. */
444 enum opt
445 {
446 START_OPT,
447 };
448 static const struct mi_opt opts[] =
449 {
450 {"-start", START_OPT, 0},
451 {NULL, 0, 0},
452 };
453
454 int oind = 0;
455 char *oarg;
456
457 while (1)
458 {
459 int opt = mi_getopt ("-exec-run", argc, argv, opts, &oind, &oarg);
460
461 if (opt < 0)
462 break;
463 switch ((enum opt) opt)
464 {
465 case START_OPT:
466 start_p = 1;
467 break;
468 }
469 }
470
471 /* This command does not accept any argument. Make sure the user
472 did not provide any. */
473 if (oind != argc)
474 error (_("Invalid argument: %s"), argv[oind]);
475
476 if (current_context->all)
477 {
478 struct cleanup *back_to = save_current_space_and_thread ();
479
480 iterate_over_inferiors (run_one_inferior, &start_p);
481 do_cleanups (back_to);
482 }
483 else
484 {
485 const char *run_cmd = start_p ? "start" : "run";
486 struct target_ops *run_target = find_run_target ();
487 int async_p = mi_async && run_target->to_can_async_p (run_target);
488
489 mi_execute_cli_command (run_cmd, async_p,
490 async_p ? "&" : NULL);
491 }
492 }
493
494
495 static int
496 find_thread_of_process (struct thread_info *ti, void *p)
497 {
498 int pid = *(int *)p;
499
500 if (ptid_get_pid (ti->ptid) == pid && !is_exited (ti->ptid))
501 return 1;
502
503 return 0;
504 }
505
506 void
507 mi_cmd_target_detach (const char *command, char **argv, int argc)
508 {
509 if (argc != 0 && argc != 1)
510 error (_("Usage: -target-detach [pid | thread-group]"));
511
512 if (argc == 1)
513 {
514 struct thread_info *tp;
515 char *end = argv[0];
516 int pid;
517
518 /* First see if we are dealing with a thread-group id. */
519 if (*argv[0] == 'i')
520 {
521 struct inferior *inf;
522 int id = strtoul (argv[0] + 1, &end, 0);
523
524 if (*end != '\0')
525 error (_("Invalid syntax of thread-group id '%s'"), argv[0]);
526
527 inf = find_inferior_id (id);
528 if (!inf)
529 error (_("Non-existent thread-group id '%d'"), id);
530
531 pid = inf->pid;
532 }
533 else
534 {
535 /* We must be dealing with a pid. */
536 pid = strtol (argv[0], &end, 10);
537
538 if (*end != '\0')
539 error (_("Invalid identifier '%s'"), argv[0]);
540 }
541
542 /* Pick any thread in the desired process. Current
543 target_detach detaches from the parent of inferior_ptid. */
544 tp = iterate_over_threads (find_thread_of_process, &pid);
545 if (!tp)
546 error (_("Thread group is empty"));
547
548 switch_to_thread (tp->ptid);
549 }
550
551 detach_command (NULL, 0);
552 }
553
554 void
555 mi_cmd_target_flash_erase (const char *command, char **argv, int argc)
556 {
557 flash_erase_command (NULL, 0);
558 }
559
560 void
561 mi_cmd_thread_select (const char *command, char **argv, int argc)
562 {
563 enum gdb_rc rc;
564 char *mi_error_message;
565 ptid_t previous_ptid = inferior_ptid;
566
567 if (argc != 1)
568 error (_("-thread-select: USAGE: threadnum."));
569
570 rc = gdb_thread_select (current_uiout, argv[0], &mi_error_message);
571
572 /* If thread switch did not succeed don't notify or print. */
573 if (rc == GDB_RC_FAIL)
574 {
575 make_cleanup (xfree, mi_error_message);
576 error ("%s", mi_error_message);
577 }
578
579 print_selected_thread_frame (current_uiout,
580 USER_SELECTED_THREAD | USER_SELECTED_FRAME);
581
582 /* Notify if the thread has effectively changed. */
583 if (!ptid_equal (inferior_ptid, previous_ptid))
584 {
585 observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
586 | USER_SELECTED_FRAME);
587 }
588 }
589
590 void
591 mi_cmd_thread_list_ids (const char *command, char **argv, int argc)
592 {
593 enum gdb_rc rc;
594 char *mi_error_message;
595
596 if (argc != 0)
597 error (_("-thread-list-ids: No arguments required."));
598
599 rc = gdb_list_thread_ids (current_uiout, &mi_error_message);
600
601 if (rc == GDB_RC_FAIL)
602 {
603 make_cleanup (xfree, mi_error_message);
604 error ("%s", mi_error_message);
605 }
606 }
607
608 void
609 mi_cmd_thread_info (const char *command, char **argv, int argc)
610 {
611 if (argc != 0 && argc != 1)
612 error (_("Invalid MI command"));
613
614 print_thread_info (current_uiout, argv[0], -1);
615 }
616
617 struct collect_cores_data
618 {
619 int pid;
620
621 VEC (int) *cores;
622 };
623
624 static int
625 collect_cores (struct thread_info *ti, void *xdata)
626 {
627 struct collect_cores_data *data = (struct collect_cores_data *) xdata;
628
629 if (ptid_get_pid (ti->ptid) == data->pid)
630 {
631 int core = target_core_of_thread (ti->ptid);
632
633 if (core != -1)
634 VEC_safe_push (int, data->cores, core);
635 }
636
637 return 0;
638 }
639
640 static int *
641 unique (int *b, int *e)
642 {
643 int *d = b;
644
645 while (++b != e)
646 if (*d != *b)
647 *++d = *b;
648 return ++d;
649 }
650
651 struct print_one_inferior_data
652 {
653 int recurse;
654 VEC (int) *inferiors;
655 };
656
657 static int
658 print_one_inferior (struct inferior *inferior, void *xdata)
659 {
660 struct print_one_inferior_data *top_data
661 = (struct print_one_inferior_data *) xdata;
662 struct ui_out *uiout = current_uiout;
663
664 if (VEC_empty (int, top_data->inferiors)
665 || bsearch (&(inferior->pid), VEC_address (int, top_data->inferiors),
666 VEC_length (int, top_data->inferiors), sizeof (int),
667 compare_positive_ints))
668 {
669 struct collect_cores_data data;
670 struct cleanup *back_to
671 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
672
673 uiout->field_fmt ("id", "i%d", inferior->num);
674 uiout->field_string ("type", "process");
675 if (inferior->has_exit_code)
676 uiout->field_string ("exit-code",
677 int_string (inferior->exit_code, 8, 0, 0, 1));
678 if (inferior->pid != 0)
679 uiout->field_int ("pid", inferior->pid);
680
681 if (inferior->pspace->pspace_exec_filename != NULL)
682 {
683 uiout->field_string ("executable",
684 inferior->pspace->pspace_exec_filename);
685 }
686
687 data.cores = 0;
688 if (inferior->pid != 0)
689 {
690 data.pid = inferior->pid;
691 iterate_over_threads (collect_cores, &data);
692 }
693
694 if (!VEC_empty (int, data.cores))
695 {
696 int *b, *e;
697 struct cleanup *back_to_2 =
698 make_cleanup_ui_out_list_begin_end (uiout, "cores");
699
700 qsort (VEC_address (int, data.cores),
701 VEC_length (int, data.cores), sizeof (int),
702 compare_positive_ints);
703
704 b = VEC_address (int, data.cores);
705 e = b + VEC_length (int, data.cores);
706 e = unique (b, e);
707
708 for (; b != e; ++b)
709 uiout->field_int (NULL, *b);
710
711 do_cleanups (back_to_2);
712 }
713
714 if (top_data->recurse)
715 print_thread_info (uiout, NULL, inferior->pid);
716
717 do_cleanups (back_to);
718 }
719
720 return 0;
721 }
722
723 /* Output a field named 'cores' with a list as the value. The
724 elements of the list are obtained by splitting 'cores' on
725 comma. */
726
727 static void
728 output_cores (struct ui_out *uiout, const char *field_name, const char *xcores)
729 {
730 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
731 field_name);
732 char *cores = xstrdup (xcores);
733 char *p = cores;
734
735 make_cleanup (xfree, cores);
736
737 for (p = strtok (p, ","); p; p = strtok (NULL, ","))
738 uiout->field_string (NULL, p);
739
740 do_cleanups (back_to);
741 }
742
743 static void
744 free_vector_of_ints (void *xvector)
745 {
746 VEC (int) **vector = (VEC (int) **) xvector;
747
748 VEC_free (int, *vector);
749 }
750
751 static void
752 do_nothing (splay_tree_key k)
753 {
754 }
755
756 static void
757 free_vector_of_osdata_items (splay_tree_value xvalue)
758 {
759 VEC (osdata_item_s) *value = (VEC (osdata_item_s) *) xvalue;
760
761 /* We don't free the items itself, it will be done separately. */
762 VEC_free (osdata_item_s, value);
763 }
764
765 static int
766 splay_tree_int_comparator (splay_tree_key xa, splay_tree_key xb)
767 {
768 int a = xa;
769 int b = xb;
770
771 return a - b;
772 }
773
774 static void
775 free_splay_tree (void *xt)
776 {
777 splay_tree t = (splay_tree) xt;
778 splay_tree_delete (t);
779 }
780
781 static void
782 list_available_thread_groups (VEC (int) *ids, int recurse)
783 {
784 struct osdata *data;
785 struct osdata_item *item;
786 int ix_items;
787 struct ui_out *uiout = current_uiout;
788 struct cleanup *cleanup;
789
790 /* This keeps a map from integer (pid) to VEC (struct osdata_item *)*
791 The vector contains information about all threads for the given pid.
792 This is assigned an initial value to avoid "may be used uninitialized"
793 warning from gcc. */
794 splay_tree tree = NULL;
795
796 /* get_osdata will throw if it cannot return data. */
797 data = get_osdata ("processes");
798 cleanup = make_cleanup_osdata_free (data);
799
800 if (recurse)
801 {
802 struct osdata *threads = get_osdata ("threads");
803
804 make_cleanup_osdata_free (threads);
805 tree = splay_tree_new (splay_tree_int_comparator,
806 do_nothing,
807 free_vector_of_osdata_items);
808 make_cleanup (free_splay_tree, tree);
809
810 for (ix_items = 0;
811 VEC_iterate (osdata_item_s, threads->items,
812 ix_items, item);
813 ix_items++)
814 {
815 const char *pid = get_osdata_column (item, "pid");
816 int pid_i = strtoul (pid, NULL, 0);
817 VEC (osdata_item_s) *vec = 0;
818
819 splay_tree_node n = splay_tree_lookup (tree, pid_i);
820 if (!n)
821 {
822 VEC_safe_push (osdata_item_s, vec, item);
823 splay_tree_insert (tree, pid_i, (splay_tree_value)vec);
824 }
825 else
826 {
827 vec = (VEC (osdata_item_s) *) n->value;
828 VEC_safe_push (osdata_item_s, vec, item);
829 n->value = (splay_tree_value) vec;
830 }
831 }
832 }
833
834 make_cleanup_ui_out_list_begin_end (uiout, "groups");
835
836 for (ix_items = 0;
837 VEC_iterate (osdata_item_s, data->items,
838 ix_items, item);
839 ix_items++)
840 {
841 struct cleanup *back_to;
842
843 const char *pid = get_osdata_column (item, "pid");
844 const char *cmd = get_osdata_column (item, "command");
845 const char *user = get_osdata_column (item, "user");
846 const char *cores = get_osdata_column (item, "cores");
847
848 int pid_i = strtoul (pid, NULL, 0);
849
850 /* At present, the target will return all available processes
851 and if information about specific ones was required, we filter
852 undesired processes here. */
853 if (ids && bsearch (&pid_i, VEC_address (int, ids),
854 VEC_length (int, ids),
855 sizeof (int), compare_positive_ints) == NULL)
856 continue;
857
858
859 back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
860
861 uiout->field_fmt ("id", "%s", pid);
862 uiout->field_string ("type", "process");
863 if (cmd)
864 uiout->field_string ("description", cmd);
865 if (user)
866 uiout->field_string ("user", user);
867 if (cores)
868 output_cores (uiout, "cores", cores);
869
870 if (recurse)
871 {
872 splay_tree_node n = splay_tree_lookup (tree, pid_i);
873 if (n)
874 {
875 VEC (osdata_item_s) *children = (VEC (osdata_item_s) *) n->value;
876 struct osdata_item *child;
877 int ix_child;
878
879 make_cleanup_ui_out_list_begin_end (uiout, "threads");
880
881 for (ix_child = 0;
882 VEC_iterate (osdata_item_s, children, ix_child, child);
883 ++ix_child)
884 {
885 struct cleanup *back_to_2 =
886 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
887 const char *tid = get_osdata_column (child, "tid");
888 const char *tcore = get_osdata_column (child, "core");
889
890 uiout->field_string ("id", tid);
891 if (tcore)
892 uiout->field_string ("core", tcore);
893
894 do_cleanups (back_to_2);
895 }
896 }
897 }
898
899 do_cleanups (back_to);
900 }
901
902 do_cleanups (cleanup);
903 }
904
905 void
906 mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
907 {
908 struct ui_out *uiout = current_uiout;
909 struct cleanup *back_to;
910 int available = 0;
911 int recurse = 0;
912 VEC (int) *ids = 0;
913
914 enum opt
915 {
916 AVAILABLE_OPT, RECURSE_OPT
917 };
918 static const struct mi_opt opts[] =
919 {
920 {"-available", AVAILABLE_OPT, 0},
921 {"-recurse", RECURSE_OPT, 1},
922 { 0, 0, 0 }
923 };
924
925 int oind = 0;
926 char *oarg;
927
928 while (1)
929 {
930 int opt = mi_getopt ("-list-thread-groups", argc, argv, opts,
931 &oind, &oarg);
932
933 if (opt < 0)
934 break;
935 switch ((enum opt) opt)
936 {
937 case AVAILABLE_OPT:
938 available = 1;
939 break;
940 case RECURSE_OPT:
941 if (strcmp (oarg, "0") == 0)
942 ;
943 else if (strcmp (oarg, "1") == 0)
944 recurse = 1;
945 else
946 error (_("only '0' and '1' are valid values "
947 "for the '--recurse' option"));
948 break;
949 }
950 }
951
952 for (; oind < argc; ++oind)
953 {
954 char *end;
955 int inf;
956
957 if (*(argv[oind]) != 'i')
958 error (_("invalid syntax of group id '%s'"), argv[oind]);
959
960 inf = strtoul (argv[oind] + 1, &end, 0);
961
962 if (*end != '\0')
963 error (_("invalid syntax of group id '%s'"), argv[oind]);
964 VEC_safe_push (int, ids, inf);
965 }
966 if (VEC_length (int, ids) > 1)
967 qsort (VEC_address (int, ids),
968 VEC_length (int, ids),
969 sizeof (int), compare_positive_ints);
970
971 back_to = make_cleanup (free_vector_of_ints, &ids);
972
973 if (available)
974 {
975 list_available_thread_groups (ids, recurse);
976 }
977 else if (VEC_length (int, ids) == 1)
978 {
979 /* Local thread groups, single id. */
980 int id = *VEC_address (int, ids);
981 struct inferior *inf = find_inferior_id (id);
982
983 if (!inf)
984 error (_("Non-existent thread group id '%d'"), id);
985
986 print_thread_info (uiout, NULL, inf->pid);
987 }
988 else
989 {
990 struct print_one_inferior_data data;
991
992 data.recurse = recurse;
993 data.inferiors = ids;
994
995 /* Local thread groups. Either no explicit ids -- and we
996 print everything, or several explicit ids. In both cases,
997 we print more than one group, and have to use 'groups'
998 as the top-level element. */
999 make_cleanup_ui_out_list_begin_end (uiout, "groups");
1000 update_thread_list ();
1001 iterate_over_inferiors (print_one_inferior, &data);
1002 }
1003
1004 do_cleanups (back_to);
1005 }
1006
1007 void
1008 mi_cmd_data_list_register_names (const char *command, char **argv, int argc)
1009 {
1010 struct gdbarch *gdbarch;
1011 struct ui_out *uiout = current_uiout;
1012 int regnum, numregs;
1013 int i;
1014 struct cleanup *cleanup;
1015
1016 /* Note that the test for a valid register must include checking the
1017 gdbarch_register_name because gdbarch_num_regs may be allocated
1018 for the union of the register sets within a family of related
1019 processors. In this case, some entries of gdbarch_register_name
1020 will change depending upon the particular processor being
1021 debugged. */
1022
1023 gdbarch = get_current_arch ();
1024 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1025
1026 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-names");
1027
1028 if (argc == 0) /* No args, just do all the regs. */
1029 {
1030 for (regnum = 0;
1031 regnum < numregs;
1032 regnum++)
1033 {
1034 if (gdbarch_register_name (gdbarch, regnum) == NULL
1035 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1036 uiout->field_string (NULL, "");
1037 else
1038 uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum));
1039 }
1040 }
1041
1042 /* Else, list of register #s, just do listed regs. */
1043 for (i = 0; i < argc; i++)
1044 {
1045 regnum = atoi (argv[i]);
1046 if (regnum < 0 || regnum >= numregs)
1047 error (_("bad register number"));
1048
1049 if (gdbarch_register_name (gdbarch, regnum) == NULL
1050 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1051 uiout->field_string (NULL, "");
1052 else
1053 uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum));
1054 }
1055 do_cleanups (cleanup);
1056 }
1057
1058 void
1059 mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
1060 {
1061 static struct regcache *this_regs = NULL;
1062 struct ui_out *uiout = current_uiout;
1063 struct regcache *prev_regs;
1064 struct gdbarch *gdbarch;
1065 int regnum, numregs, changed;
1066 int i;
1067 struct cleanup *cleanup;
1068
1069 /* The last time we visited this function, the current frame's
1070 register contents were saved in THIS_REGS. Move THIS_REGS over
1071 to PREV_REGS, and refresh THIS_REGS with the now-current register
1072 contents. */
1073
1074 prev_regs = this_regs;
1075 this_regs = frame_save_as_regcache (get_selected_frame (NULL));
1076 cleanup = make_cleanup_regcache_xfree (prev_regs);
1077
1078 /* Note that the test for a valid register must include checking the
1079 gdbarch_register_name because gdbarch_num_regs may be allocated
1080 for the union of the register sets within a family of related
1081 processors. In this case, some entries of gdbarch_register_name
1082 will change depending upon the particular processor being
1083 debugged. */
1084
1085 gdbarch = get_regcache_arch (this_regs);
1086 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1087
1088 make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
1089
1090 if (argc == 0)
1091 {
1092 /* No args, just do all the regs. */
1093 for (regnum = 0;
1094 regnum < numregs;
1095 regnum++)
1096 {
1097 if (gdbarch_register_name (gdbarch, regnum) == NULL
1098 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1099 continue;
1100 changed = register_changed_p (regnum, prev_regs, this_regs);
1101 if (changed < 0)
1102 error (_("-data-list-changed-registers: "
1103 "Unable to read register contents."));
1104 else if (changed)
1105 uiout->field_int (NULL, regnum);
1106 }
1107 }
1108
1109 /* Else, list of register #s, just do listed regs. */
1110 for (i = 0; i < argc; i++)
1111 {
1112 regnum = atoi (argv[i]);
1113
1114 if (regnum >= 0
1115 && regnum < numregs
1116 && gdbarch_register_name (gdbarch, regnum) != NULL
1117 && *gdbarch_register_name (gdbarch, regnum) != '\000')
1118 {
1119 changed = register_changed_p (regnum, prev_regs, this_regs);
1120 if (changed < 0)
1121 error (_("-data-list-changed-registers: "
1122 "Unable to read register contents."));
1123 else if (changed)
1124 uiout->field_int (NULL, regnum);
1125 }
1126 else
1127 error (_("bad register number"));
1128 }
1129 do_cleanups (cleanup);
1130 }
1131
1132 static int
1133 register_changed_p (int regnum, struct regcache *prev_regs,
1134 struct regcache *this_regs)
1135 {
1136 struct gdbarch *gdbarch = get_regcache_arch (this_regs);
1137 gdb_byte prev_buffer[MAX_REGISTER_SIZE];
1138 gdb_byte this_buffer[MAX_REGISTER_SIZE];
1139 enum register_status prev_status;
1140 enum register_status this_status;
1141
1142 /* First time through or after gdbarch change consider all registers
1143 as changed. */
1144 if (!prev_regs || get_regcache_arch (prev_regs) != gdbarch)
1145 return 1;
1146
1147 /* Get register contents and compare. */
1148 prev_status = regcache_cooked_read (prev_regs, regnum, prev_buffer);
1149 this_status = regcache_cooked_read (this_regs, regnum, this_buffer);
1150
1151 if (this_status != prev_status)
1152 return 1;
1153 else if (this_status == REG_VALID)
1154 return memcmp (prev_buffer, this_buffer,
1155 register_size (gdbarch, regnum)) != 0;
1156 else
1157 return 0;
1158 }
1159
1160 /* Return a list of register number and value pairs. The valid
1161 arguments expected are: a letter indicating the format in which to
1162 display the registers contents. This can be one of: x
1163 (hexadecimal), d (decimal), N (natural), t (binary), o (octal), r
1164 (raw). After the format argument there can be a sequence of
1165 numbers, indicating which registers to fetch the content of. If
1166 the format is the only argument, a list of all the registers with
1167 their values is returned. */
1168
1169 void
1170 mi_cmd_data_list_register_values (const char *command, char **argv, int argc)
1171 {
1172 struct ui_out *uiout = current_uiout;
1173 struct frame_info *frame;
1174 struct gdbarch *gdbarch;
1175 int regnum, numregs, format;
1176 int i;
1177 struct cleanup *list_cleanup;
1178 int skip_unavailable = 0;
1179 int oind = 0;
1180 enum opt
1181 {
1182 SKIP_UNAVAILABLE,
1183 };
1184 static const struct mi_opt opts[] =
1185 {
1186 {"-skip-unavailable", SKIP_UNAVAILABLE, 0},
1187 { 0, 0, 0 }
1188 };
1189
1190 /* Note that the test for a valid register must include checking the
1191 gdbarch_register_name because gdbarch_num_regs may be allocated
1192 for the union of the register sets within a family of related
1193 processors. In this case, some entries of gdbarch_register_name
1194 will change depending upon the particular processor being
1195 debugged. */
1196
1197 while (1)
1198 {
1199 char *oarg;
1200 int opt = mi_getopt ("-data-list-register-values", argc, argv,
1201 opts, &oind, &oarg);
1202
1203 if (opt < 0)
1204 break;
1205 switch ((enum opt) opt)
1206 {
1207 case SKIP_UNAVAILABLE:
1208 skip_unavailable = 1;
1209 break;
1210 }
1211 }
1212
1213 if (argc - oind < 1)
1214 error (_("-data-list-register-values: Usage: "
1215 "-data-list-register-values [--skip-unavailable] <format>"
1216 " [<regnum1>...<regnumN>]"));
1217
1218 format = (int) argv[oind][0];
1219
1220 frame = get_selected_frame (NULL);
1221 gdbarch = get_frame_arch (frame);
1222 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1223
1224 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-values");
1225
1226 if (argc - oind == 1)
1227 {
1228 /* No args, beside the format: do all the regs. */
1229 for (regnum = 0;
1230 regnum < numregs;
1231 regnum++)
1232 {
1233 if (gdbarch_register_name (gdbarch, regnum) == NULL
1234 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
1235 continue;
1236
1237 output_register (frame, regnum, format, skip_unavailable);
1238 }
1239 }
1240
1241 /* Else, list of register #s, just do listed regs. */
1242 for (i = 1 + oind; i < argc; i++)
1243 {
1244 regnum = atoi (argv[i]);
1245
1246 if (regnum >= 0
1247 && regnum < numregs
1248 && gdbarch_register_name (gdbarch, regnum) != NULL
1249 && *gdbarch_register_name (gdbarch, regnum) != '\000')
1250 output_register (frame, regnum, format, skip_unavailable);
1251 else
1252 error (_("bad register number"));
1253 }
1254 do_cleanups (list_cleanup);
1255 }
1256
1257 /* Output one register REGNUM's contents in the desired FORMAT. If
1258 SKIP_UNAVAILABLE is true, skip the register if it is
1259 unavailable. */
1260
1261 static void
1262 output_register (struct frame_info *frame, int regnum, int format,
1263 int skip_unavailable)
1264 {
1265 struct ui_out *uiout = current_uiout;
1266 struct value *val = value_of_register (regnum, frame);
1267 struct cleanup *tuple_cleanup;
1268 struct value_print_options opts;
1269
1270 if (skip_unavailable && !value_entirely_available (val))
1271 return;
1272
1273 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1274 uiout->field_int ("number", regnum);
1275
1276 if (format == 'N')
1277 format = 0;
1278
1279 if (format == 'r')
1280 format = 'z';
1281
1282 string_file stb;
1283
1284 get_formatted_print_options (&opts, format);
1285 opts.deref_ref = 1;
1286 val_print (value_type (val),
1287 value_embedded_offset (val), 0,
1288 &stb, 0, val, &opts, current_language);
1289 uiout->field_stream ("value", stb);
1290
1291 do_cleanups (tuple_cleanup);
1292 }
1293
1294 /* Write given values into registers. The registers and values are
1295 given as pairs. The corresponding MI command is
1296 -data-write-register-values <format>
1297 [<regnum1> <value1>...<regnumN> <valueN>] */
1298 void
1299 mi_cmd_data_write_register_values (const char *command, char **argv, int argc)
1300 {
1301 struct regcache *regcache;
1302 struct gdbarch *gdbarch;
1303 int numregs, i;
1304
1305 /* Note that the test for a valid register must include checking the
1306 gdbarch_register_name because gdbarch_num_regs may be allocated
1307 for the union of the register sets within a family of related
1308 processors. In this case, some entries of gdbarch_register_name
1309 will change depending upon the particular processor being
1310 debugged. */
1311
1312 regcache = get_current_regcache ();
1313 gdbarch = get_regcache_arch (regcache);
1314 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1315
1316 if (argc == 0)
1317 error (_("-data-write-register-values: Usage: -data-write-register-"
1318 "values <format> [<regnum1> <value1>...<regnumN> <valueN>]"));
1319
1320 if (!target_has_registers)
1321 error (_("-data-write-register-values: No registers."));
1322
1323 if (!(argc - 1))
1324 error (_("-data-write-register-values: No regs and values specified."));
1325
1326 if ((argc - 1) % 2)
1327 error (_("-data-write-register-values: "
1328 "Regs and vals are not in pairs."));
1329
1330 for (i = 1; i < argc; i = i + 2)
1331 {
1332 int regnum = atoi (argv[i]);
1333
1334 if (regnum >= 0 && regnum < numregs
1335 && gdbarch_register_name (gdbarch, regnum)
1336 && *gdbarch_register_name (gdbarch, regnum))
1337 {
1338 LONGEST value;
1339
1340 /* Get the value as a number. */
1341 value = parse_and_eval_address (argv[i + 1]);
1342
1343 /* Write it down. */
1344 regcache_cooked_write_signed (regcache, regnum, value);
1345 }
1346 else
1347 error (_("bad register number"));
1348 }
1349 }
1350
1351 /* Evaluate the value of the argument. The argument is an
1352 expression. If the expression contains spaces it needs to be
1353 included in double quotes. */
1354
1355 void
1356 mi_cmd_data_evaluate_expression (const char *command, char **argv, int argc)
1357 {
1358 struct value *val;
1359 struct value_print_options opts;
1360 struct ui_out *uiout = current_uiout;
1361
1362 if (argc != 1)
1363 error (_("-data-evaluate-expression: "
1364 "Usage: -data-evaluate-expression expression"));
1365
1366 expression_up expr = parse_expression (argv[0]);
1367
1368 val = evaluate_expression (expr.get ());
1369
1370 string_file stb;
1371
1372 /* Print the result of the expression evaluation. */
1373 get_user_print_options (&opts);
1374 opts.deref_ref = 0;
1375 common_val_print (val, &stb, 0, &opts, current_language);
1376
1377 uiout->field_stream ("value", stb);
1378 }
1379
1380 /* This is the -data-read-memory command.
1381
1382 ADDR: start address of data to be dumped.
1383 WORD-FORMAT: a char indicating format for the ``word''. See
1384 the ``x'' command.
1385 WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes.
1386 NR_ROW: Number of rows.
1387 NR_COL: The number of colums (words per row).
1388 ASCHAR: (OPTIONAL) Append an ascii character dump to each row. Use
1389 ASCHAR for unprintable characters.
1390
1391 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
1392 displayes them. Returns:
1393
1394 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
1395
1396 Returns:
1397 The number of bytes read is SIZE*ROW*COL. */
1398
1399 void
1400 mi_cmd_data_read_memory (const char *command, char **argv, int argc)
1401 {
1402 struct gdbarch *gdbarch = get_current_arch ();
1403 struct ui_out *uiout = current_uiout;
1404 CORE_ADDR addr;
1405 long total_bytes, nr_cols, nr_rows;
1406 char word_format;
1407 struct type *word_type;
1408 long word_size;
1409 char word_asize;
1410 char aschar;
1411 int nr_bytes;
1412 long offset = 0;
1413 int oind = 0;
1414 char *oarg;
1415 enum opt
1416 {
1417 OFFSET_OPT
1418 };
1419 static const struct mi_opt opts[] =
1420 {
1421 {"o", OFFSET_OPT, 1},
1422 { 0, 0, 0 }
1423 };
1424
1425 while (1)
1426 {
1427 int opt = mi_getopt ("-data-read-memory", argc, argv, opts,
1428 &oind, &oarg);
1429
1430 if (opt < 0)
1431 break;
1432 switch ((enum opt) opt)
1433 {
1434 case OFFSET_OPT:
1435 offset = atol (oarg);
1436 break;
1437 }
1438 }
1439 argv += oind;
1440 argc -= oind;
1441
1442 if (argc < 5 || argc > 6)
1443 error (_("-data-read-memory: Usage: "
1444 "ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR]."));
1445
1446 /* Extract all the arguments. */
1447
1448 /* Start address of the memory dump. */
1449 addr = parse_and_eval_address (argv[0]) + offset;
1450 /* The format character to use when displaying a memory word. See
1451 the ``x'' command. */
1452 word_format = argv[1][0];
1453 /* The size of the memory word. */
1454 word_size = atol (argv[2]);
1455 switch (word_size)
1456 {
1457 case 1:
1458 word_type = builtin_type (gdbarch)->builtin_int8;
1459 word_asize = 'b';
1460 break;
1461 case 2:
1462 word_type = builtin_type (gdbarch)->builtin_int16;
1463 word_asize = 'h';
1464 break;
1465 case 4:
1466 word_type = builtin_type (gdbarch)->builtin_int32;
1467 word_asize = 'w';
1468 break;
1469 case 8:
1470 word_type = builtin_type (gdbarch)->builtin_int64;
1471 word_asize = 'g';
1472 break;
1473 default:
1474 word_type = builtin_type (gdbarch)->builtin_int8;
1475 word_asize = 'b';
1476 }
1477 /* The number of rows. */
1478 nr_rows = atol (argv[3]);
1479 if (nr_rows <= 0)
1480 error (_("-data-read-memory: invalid number of rows."));
1481
1482 /* Number of bytes per row. */
1483 nr_cols = atol (argv[4]);
1484 if (nr_cols <= 0)
1485 error (_("-data-read-memory: invalid number of columns."));
1486
1487 /* The un-printable character when printing ascii. */
1488 if (argc == 6)
1489 aschar = *argv[5];
1490 else
1491 aschar = 0;
1492
1493 /* Create a buffer and read it in. */
1494 total_bytes = word_size * nr_rows * nr_cols;
1495
1496 std::unique_ptr<gdb_byte[]> mbuf (new gdb_byte[total_bytes]);
1497
1498 /* Dispatch memory reads to the topmost target, not the flattened
1499 current_target. */
1500 nr_bytes = target_read (current_target.beneath,
1501 TARGET_OBJECT_MEMORY, NULL, mbuf.get (),
1502 addr, total_bytes);
1503 if (nr_bytes <= 0)
1504 error (_("Unable to read memory."));
1505
1506 /* Output the header information. */
1507 uiout->field_core_addr ("addr", gdbarch, addr);
1508 uiout->field_int ("nr-bytes", nr_bytes);
1509 uiout->field_int ("total-bytes", total_bytes);
1510 uiout->field_core_addr ("next-row", gdbarch, addr + word_size * nr_cols);
1511 uiout->field_core_addr ("prev-row", gdbarch, addr - word_size * nr_cols);
1512 uiout->field_core_addr ("next-page", gdbarch, addr + total_bytes);
1513 uiout->field_core_addr ("prev-page", gdbarch, addr - total_bytes);
1514
1515 /* Build the result as a two dimentional table. */
1516 {
1517 int row;
1518 int row_byte;
1519 struct cleanup *cleanup_list;
1520
1521 string_file stream;
1522
1523 cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, "memory");
1524 for (row = 0, row_byte = 0;
1525 row < nr_rows;
1526 row++, row_byte += nr_cols * word_size)
1527 {
1528 int col;
1529 int col_byte;
1530 struct cleanup *cleanup_tuple;
1531 struct cleanup *cleanup_list_data;
1532 struct value_print_options opts;
1533
1534 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1535 uiout->field_core_addr ("addr", gdbarch, addr + row_byte);
1536 /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr +
1537 row_byte); */
1538 cleanup_list_data = make_cleanup_ui_out_list_begin_end (uiout, "data");
1539 get_formatted_print_options (&opts, word_format);
1540 for (col = 0, col_byte = row_byte;
1541 col < nr_cols;
1542 col++, col_byte += word_size)
1543 {
1544 if (col_byte + word_size > nr_bytes)
1545 {
1546 uiout->field_string (NULL, "N/A");
1547 }
1548 else
1549 {
1550 stream.clear ();
1551 print_scalar_formatted (&mbuf[col_byte], word_type, &opts,
1552 word_asize, &stream);
1553 uiout->field_stream (NULL, stream);
1554 }
1555 }
1556 do_cleanups (cleanup_list_data);
1557 if (aschar)
1558 {
1559 int byte;
1560
1561 stream.clear ();
1562 for (byte = row_byte;
1563 byte < row_byte + word_size * nr_cols; byte++)
1564 {
1565 if (byte >= nr_bytes)
1566 stream.putc ('X');
1567 else if (mbuf[byte] < 32 || mbuf[byte] > 126)
1568 stream.putc (aschar);
1569 else
1570 stream.putc (mbuf[byte]);
1571 }
1572 uiout->field_stream ("ascii", stream);
1573 }
1574 do_cleanups (cleanup_tuple);
1575 }
1576 do_cleanups (cleanup_list);
1577 }
1578 }
1579
1580 void
1581 mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
1582 {
1583 struct gdbarch *gdbarch = get_current_arch ();
1584 struct ui_out *uiout = current_uiout;
1585 struct cleanup *cleanups;
1586 CORE_ADDR addr;
1587 LONGEST length;
1588 memory_read_result_s *read_result;
1589 int ix;
1590 VEC(memory_read_result_s) *result;
1591 long offset = 0;
1592 int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
1593 int oind = 0;
1594 char *oarg;
1595 enum opt
1596 {
1597 OFFSET_OPT
1598 };
1599 static const struct mi_opt opts[] =
1600 {
1601 {"o", OFFSET_OPT, 1},
1602 { 0, 0, 0 }
1603 };
1604
1605 while (1)
1606 {
1607 int opt = mi_getopt ("-data-read-memory-bytes", argc, argv, opts,
1608 &oind, &oarg);
1609 if (opt < 0)
1610 break;
1611 switch ((enum opt) opt)
1612 {
1613 case OFFSET_OPT:
1614 offset = atol (oarg);
1615 break;
1616 }
1617 }
1618 argv += oind;
1619 argc -= oind;
1620
1621 if (argc != 2)
1622 error (_("Usage: [ -o OFFSET ] ADDR LENGTH."));
1623
1624 addr = parse_and_eval_address (argv[0]) + offset;
1625 length = atol (argv[1]);
1626
1627 result = read_memory_robust (current_target.beneath, addr, length);
1628
1629 cleanups = make_cleanup (free_memory_read_result_vector, &result);
1630
1631 if (VEC_length (memory_read_result_s, result) == 0)
1632 error (_("Unable to read memory."));
1633
1634 make_cleanup_ui_out_list_begin_end (uiout, "memory");
1635 for (ix = 0;
1636 VEC_iterate (memory_read_result_s, result, ix, read_result);
1637 ++ix)
1638 {
1639 struct cleanup *t = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1640 char *data, *p;
1641 int i;
1642 int alloc_len;
1643
1644 uiout->field_core_addr ("begin", gdbarch, read_result->begin);
1645 uiout->field_core_addr ("offset", gdbarch, read_result->begin - addr);
1646 uiout->field_core_addr ("end", gdbarch, read_result->end);
1647
1648 alloc_len = (read_result->end - read_result->begin) * 2 * unit_size + 1;
1649 data = (char *) xmalloc (alloc_len);
1650
1651 for (i = 0, p = data;
1652 i < ((read_result->end - read_result->begin) * unit_size);
1653 ++i, p += 2)
1654 {
1655 sprintf (p, "%02x", read_result->data[i]);
1656 }
1657 uiout->field_string ("contents", data);
1658 xfree (data);
1659 do_cleanups (t);
1660 }
1661 do_cleanups (cleanups);
1662 }
1663
1664 /* Implementation of the -data-write_memory command.
1665
1666 COLUMN_OFFSET: optional argument. Must be preceded by '-o'. The
1667 offset from the beginning of the memory grid row where the cell to
1668 be written is.
1669 ADDR: start address of the row in the memory grid where the memory
1670 cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
1671 the location to write to.
1672 FORMAT: a char indicating format for the ``word''. See
1673 the ``x'' command.
1674 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
1675 VALUE: value to be written into the memory address.
1676
1677 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
1678
1679 Prints nothing. */
1680
1681 void
1682 mi_cmd_data_write_memory (const char *command, char **argv, int argc)
1683 {
1684 struct gdbarch *gdbarch = get_current_arch ();
1685 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1686 CORE_ADDR addr;
1687 long word_size;
1688 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
1689 enough when using a compiler other than GCC. */
1690 LONGEST value;
1691 gdb_byte *buffer;
1692 struct cleanup *old_chain;
1693 long offset = 0;
1694 int oind = 0;
1695 char *oarg;
1696 enum opt
1697 {
1698 OFFSET_OPT
1699 };
1700 static const struct mi_opt opts[] =
1701 {
1702 {"o", OFFSET_OPT, 1},
1703 { 0, 0, 0 }
1704 };
1705
1706 while (1)
1707 {
1708 int opt = mi_getopt ("-data-write-memory", argc, argv, opts,
1709 &oind, &oarg);
1710
1711 if (opt < 0)
1712 break;
1713 switch ((enum opt) opt)
1714 {
1715 case OFFSET_OPT:
1716 offset = atol (oarg);
1717 break;
1718 }
1719 }
1720 argv += oind;
1721 argc -= oind;
1722
1723 if (argc != 4)
1724 error (_("-data-write-memory: Usage: "
1725 "[-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE."));
1726
1727 /* Extract all the arguments. */
1728 /* Start address of the memory dump. */
1729 addr = parse_and_eval_address (argv[0]);
1730 /* The size of the memory word. */
1731 word_size = atol (argv[2]);
1732
1733 /* Calculate the real address of the write destination. */
1734 addr += (offset * word_size);
1735
1736 /* Get the value as a number. */
1737 value = parse_and_eval_address (argv[3]);
1738 /* Get the value into an array. */
1739 buffer = (gdb_byte *) xmalloc (word_size);
1740 old_chain = make_cleanup (xfree, buffer);
1741 store_signed_integer (buffer, word_size, byte_order, value);
1742 /* Write it down to memory. */
1743 write_memory_with_notification (addr, buffer, word_size);
1744 /* Free the buffer. */
1745 do_cleanups (old_chain);
1746 }
1747
1748 /* Implementation of the -data-write-memory-bytes command.
1749
1750 ADDR: start address
1751 DATA: string of bytes to write at that address
1752 COUNT: number of bytes to be filled (decimal integer). */
1753
1754 void
1755 mi_cmd_data_write_memory_bytes (const char *command, char **argv, int argc)
1756 {
1757 CORE_ADDR addr;
1758 char *cdata;
1759 gdb_byte *data;
1760 gdb_byte *databuf;
1761 size_t len_hex, len_bytes, len_units, i, steps, remaining_units;
1762 long int count_units;
1763 struct cleanup *back_to;
1764 int unit_size;
1765
1766 if (argc != 2 && argc != 3)
1767 error (_("Usage: ADDR DATA [COUNT]."));
1768
1769 addr = parse_and_eval_address (argv[0]);
1770 cdata = argv[1];
1771 len_hex = strlen (cdata);
1772 unit_size = gdbarch_addressable_memory_unit_size (get_current_arch ());
1773
1774 if (len_hex % (unit_size * 2) != 0)
1775 error (_("Hex-encoded '%s' must represent an integral number of "
1776 "addressable memory units."),
1777 cdata);
1778
1779 len_bytes = len_hex / 2;
1780 len_units = len_bytes / unit_size;
1781
1782 if (argc == 3)
1783 count_units = strtoul (argv[2], NULL, 10);
1784 else
1785 count_units = len_units;
1786
1787 databuf = XNEWVEC (gdb_byte, len_bytes);
1788 back_to = make_cleanup (xfree, databuf);
1789
1790 for (i = 0; i < len_bytes; ++i)
1791 {
1792 int x;
1793 if (sscanf (cdata + i * 2, "%02x", &x) != 1)
1794 error (_("Invalid argument"));
1795 databuf[i] = (gdb_byte) x;
1796 }
1797
1798 if (len_units < count_units)
1799 {
1800 /* Pattern is made of less units than count:
1801 repeat pattern to fill memory. */
1802 data = (gdb_byte *) xmalloc (count_units * unit_size);
1803 make_cleanup (xfree, data);
1804
1805 /* Number of times the pattern is entirely repeated. */
1806 steps = count_units / len_units;
1807 /* Number of remaining addressable memory units. */
1808 remaining_units = count_units % len_units;
1809 for (i = 0; i < steps; i++)
1810 memcpy (data + i * len_bytes, databuf, len_bytes);
1811
1812 if (remaining_units > 0)
1813 memcpy (data + steps * len_bytes, databuf,
1814 remaining_units * unit_size);
1815 }
1816 else
1817 {
1818 /* Pattern is longer than or equal to count:
1819 just copy count addressable memory units. */
1820 data = databuf;
1821 }
1822
1823 write_memory_with_notification (addr, data, count_units);
1824
1825 do_cleanups (back_to);
1826 }
1827
1828 void
1829 mi_cmd_enable_timings (const char *command, char **argv, int argc)
1830 {
1831 if (argc == 0)
1832 do_timings = 1;
1833 else if (argc == 1)
1834 {
1835 if (strcmp (argv[0], "yes") == 0)
1836 do_timings = 1;
1837 else if (strcmp (argv[0], "no") == 0)
1838 do_timings = 0;
1839 else
1840 goto usage_error;
1841 }
1842 else
1843 goto usage_error;
1844
1845 return;
1846
1847 usage_error:
1848 error (_("-enable-timings: Usage: %s {yes|no}"), command);
1849 }
1850
1851 void
1852 mi_cmd_list_features (const char *command, char **argv, int argc)
1853 {
1854 if (argc == 0)
1855 {
1856 struct cleanup *cleanup = NULL;
1857 struct ui_out *uiout = current_uiout;
1858
1859 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1860 uiout->field_string (NULL, "frozen-varobjs");
1861 uiout->field_string (NULL, "pending-breakpoints");
1862 uiout->field_string (NULL, "thread-info");
1863 uiout->field_string (NULL, "data-read-memory-bytes");
1864 uiout->field_string (NULL, "breakpoint-notifications");
1865 uiout->field_string (NULL, "ada-task-info");
1866 uiout->field_string (NULL, "language-option");
1867 uiout->field_string (NULL, "info-gdb-mi-command");
1868 uiout->field_string (NULL, "undefined-command-error-code");
1869 uiout->field_string (NULL, "exec-run-start-option");
1870
1871 if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
1872 uiout->field_string (NULL, "python");
1873
1874 do_cleanups (cleanup);
1875 return;
1876 }
1877
1878 error (_("-list-features should be passed no arguments"));
1879 }
1880
1881 void
1882 mi_cmd_list_target_features (const char *command, char **argv, int argc)
1883 {
1884 if (argc == 0)
1885 {
1886 struct cleanup *cleanup = NULL;
1887 struct ui_out *uiout = current_uiout;
1888
1889 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
1890 if (mi_async_p ())
1891 uiout->field_string (NULL, "async");
1892 if (target_can_execute_reverse)
1893 uiout->field_string (NULL, "reverse");
1894 do_cleanups (cleanup);
1895 return;
1896 }
1897
1898 error (_("-list-target-features should be passed no arguments"));
1899 }
1900
1901 void
1902 mi_cmd_add_inferior (const char *command, char **argv, int argc)
1903 {
1904 struct inferior *inf;
1905
1906 if (argc != 0)
1907 error (_("-add-inferior should be passed no arguments"));
1908
1909 inf = add_inferior_with_spaces ();
1910
1911 current_uiout->field_fmt ("inferior", "i%d", inf->num);
1912 }
1913
1914 /* Callback used to find the first inferior other than the current
1915 one. */
1916
1917 static int
1918 get_other_inferior (struct inferior *inf, void *arg)
1919 {
1920 if (inf == current_inferior ())
1921 return 0;
1922
1923 return 1;
1924 }
1925
1926 void
1927 mi_cmd_remove_inferior (const char *command, char **argv, int argc)
1928 {
1929 int id;
1930 struct inferior *inf;
1931
1932 if (argc != 1)
1933 error (_("-remove-inferior should be passed a single argument"));
1934
1935 if (sscanf (argv[0], "i%d", &id) != 1)
1936 error (_("the thread group id is syntactically invalid"));
1937
1938 inf = find_inferior_id (id);
1939 if (!inf)
1940 error (_("the specified thread group does not exist"));
1941
1942 if (inf->pid != 0)
1943 error (_("cannot remove an active inferior"));
1944
1945 if (inf == current_inferior ())
1946 {
1947 struct thread_info *tp = 0;
1948 struct inferior *new_inferior
1949 = iterate_over_inferiors (get_other_inferior, NULL);
1950
1951 if (new_inferior == NULL)
1952 error (_("Cannot remove last inferior"));
1953
1954 set_current_inferior (new_inferior);
1955 if (new_inferior->pid != 0)
1956 tp = any_thread_of_process (new_inferior->pid);
1957 switch_to_thread (tp ? tp->ptid : null_ptid);
1958 set_current_program_space (new_inferior->pspace);
1959 }
1960
1961 delete_inferior (inf);
1962 }
1963
1964 \f
1965
1966 /* Execute a command within a safe environment.
1967 Return <0 for error; >=0 for ok.
1968
1969 args->action will tell mi_execute_command what action
1970 to perfrom after the given command has executed (display/suppress
1971 prompt, display error). */
1972
1973 static void
1974 captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
1975 {
1976 struct mi_interp *mi = (struct mi_interp *) command_interp ();
1977 struct cleanup *cleanup;
1978
1979 if (do_timings)
1980 current_command_ts = context->cmd_start;
1981
1982 current_token = xstrdup (context->token);
1983 cleanup = make_cleanup (free_current_contents, &current_token);
1984
1985 running_result_record_printed = 0;
1986 mi_proceeded = 0;
1987 switch (context->op)
1988 {
1989 case MI_COMMAND:
1990 /* A MI command was read from the input stream. */
1991 if (mi_debug_p)
1992 /* FIXME: gdb_???? */
1993 fprintf_unfiltered (mi->raw_stdout,
1994 " token=`%s' command=`%s' args=`%s'\n",
1995 context->token, context->command, context->args);
1996
1997 mi_cmd_execute (context);
1998
1999 /* Print the result if there were no errors.
2000
2001 Remember that on the way out of executing a command, you have
2002 to directly use the mi_interp's uiout, since the command
2003 could have reset the interpreter, in which case the current
2004 uiout will most likely crash in the mi_out_* routines. */
2005 if (!running_result_record_printed)
2006 {
2007 fputs_unfiltered (context->token, mi->raw_stdout);
2008 /* There's no particularly good reason why target-connect results
2009 in not ^done. Should kill ^connected for MI3. */
2010 fputs_unfiltered (strcmp (context->command, "target-select") == 0
2011 ? "^connected" : "^done", mi->raw_stdout);
2012 mi_out_put (uiout, mi->raw_stdout);
2013 mi_out_rewind (uiout);
2014 mi_print_timing_maybe (mi->raw_stdout);
2015 fputs_unfiltered ("\n", mi->raw_stdout);
2016 }
2017 else
2018 /* The command does not want anything to be printed. In that
2019 case, the command probably should not have written anything
2020 to uiout, but in case it has written something, discard it. */
2021 mi_out_rewind (uiout);
2022 break;
2023
2024 case CLI_COMMAND:
2025 {
2026 char *argv[2];
2027
2028 /* A CLI command was read from the input stream. */
2029 /* This "feature" will be removed as soon as we have a
2030 complete set of mi commands. */
2031 /* Echo the command on the console. */
2032 fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
2033 /* Call the "console" interpreter. */
2034 argv[0] = (char *) INTERP_CONSOLE;
2035 argv[1] = context->command;
2036 mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
2037
2038 /* If we changed interpreters, DON'T print out anything. */
2039 if (current_interp_named_p (INTERP_MI)
2040 || current_interp_named_p (INTERP_MI1)
2041 || current_interp_named_p (INTERP_MI2)
2042 || current_interp_named_p (INTERP_MI3))
2043 {
2044 if (!running_result_record_printed)
2045 {
2046 fputs_unfiltered (context->token, mi->raw_stdout);
2047 fputs_unfiltered ("^done", mi->raw_stdout);
2048 mi_out_put (uiout, mi->raw_stdout);
2049 mi_out_rewind (uiout);
2050 mi_print_timing_maybe (mi->raw_stdout);
2051 fputs_unfiltered ("\n", mi->raw_stdout);
2052 }
2053 else
2054 mi_out_rewind (uiout);
2055 }
2056 break;
2057 }
2058 }
2059
2060 do_cleanups (cleanup);
2061 }
2062
2063 /* Print a gdb exception to the MI output stream. */
2064
2065 static void
2066 mi_print_exception (const char *token, struct gdb_exception exception)
2067 {
2068 struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
2069
2070 fputs_unfiltered (token, mi->raw_stdout);
2071 fputs_unfiltered ("^error,msg=\"", mi->raw_stdout);
2072 if (exception.message == NULL)
2073 fputs_unfiltered ("unknown error", mi->raw_stdout);
2074 else
2075 fputstr_unfiltered (exception.message, '"', mi->raw_stdout);
2076 fputs_unfiltered ("\"", mi->raw_stdout);
2077
2078 switch (exception.error)
2079 {
2080 case UNDEFINED_COMMAND_ERROR:
2081 fputs_unfiltered (",code=\"undefined-command\"", mi->raw_stdout);
2082 break;
2083 }
2084
2085 fputs_unfiltered ("\n", mi->raw_stdout);
2086 }
2087
2088 /* Determine whether the parsed command already notifies the
2089 user_selected_context_changed observer. */
2090
2091 static int
2092 command_notifies_uscc_observer (struct mi_parse *command)
2093 {
2094 if (command->op == CLI_COMMAND)
2095 {
2096 /* CLI commands "thread" and "inferior" already send it. */
2097 return (strncmp (command->command, "thread ", 7) == 0
2098 || strncmp (command->command, "inferior ", 9) == 0);
2099 }
2100 else /* MI_COMMAND */
2101 {
2102 if (strcmp (command->command, "interpreter-exec") == 0
2103 && command->argc > 1)
2104 {
2105 /* "thread" and "inferior" again, but through -interpreter-exec. */
2106 return (strncmp (command->argv[1], "thread ", 7) == 0
2107 || strncmp (command->argv[1], "inferior ", 9) == 0);
2108 }
2109
2110 else
2111 /* -thread-select already sends it. */
2112 return strcmp (command->command, "thread-select") == 0;
2113 }
2114 }
2115
2116 void
2117 mi_execute_command (const char *cmd, int from_tty)
2118 {
2119 char *token;
2120 std::unique_ptr<struct mi_parse> command;
2121
2122 /* This is to handle EOF (^D). We just quit gdb. */
2123 /* FIXME: we should call some API function here. */
2124 if (cmd == 0)
2125 quit_force (NULL, from_tty);
2126
2127 target_log_command (cmd);
2128
2129 TRY
2130 {
2131 command = mi_parse (cmd, &token);
2132 }
2133 CATCH (exception, RETURN_MASK_ALL)
2134 {
2135 mi_print_exception (token, exception);
2136 xfree (token);
2137 }
2138 END_CATCH
2139
2140 if (command != NULL)
2141 {
2142 ptid_t previous_ptid = inferior_ptid;
2143 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
2144
2145 command->token = token;
2146
2147 if (command->cmd != NULL && command->cmd->suppress_notification != NULL)
2148 {
2149 make_cleanup_restore_integer (command->cmd->suppress_notification);
2150 *command->cmd->suppress_notification = 1;
2151 }
2152
2153 if (do_timings)
2154 {
2155 command->cmd_start = new mi_timestamp ();
2156 timestamp (command->cmd_start);
2157 }
2158
2159 TRY
2160 {
2161 captured_mi_execute_command (current_uiout, command.get ());
2162 }
2163 CATCH (result, RETURN_MASK_ALL)
2164 {
2165 /* Like in start_event_loop, enable input and force display
2166 of the prompt. Otherwise, any command that calls
2167 async_disable_stdin, and then throws, will leave input
2168 disabled. */
2169 async_enable_stdin ();
2170 current_ui->prompt_state = PROMPT_NEEDED;
2171
2172 /* The command execution failed and error() was called
2173 somewhere. */
2174 mi_print_exception (command->token, result);
2175 mi_out_rewind (current_uiout);
2176 }
2177 END_CATCH
2178
2179 bpstat_do_actions ();
2180
2181 if (/* The notifications are only output when the top-level
2182 interpreter (specified on the command line) is MI. */
2183 interp_ui_out (top_level_interpreter ())->is_mi_like_p ()
2184 /* Don't try report anything if there are no threads --
2185 the program is dead. */
2186 && thread_count () != 0
2187 /* If the command already reports the thread change, no need to do it
2188 again. */
2189 && !command_notifies_uscc_observer (command.get ()))
2190 {
2191 struct mi_interp *mi = (struct mi_interp *) top_level_interpreter ();
2192 int report_change = 0;
2193
2194 if (command->thread == -1)
2195 {
2196 report_change = (!ptid_equal (previous_ptid, null_ptid)
2197 && !ptid_equal (inferior_ptid, previous_ptid)
2198 && !ptid_equal (inferior_ptid, null_ptid));
2199 }
2200 else if (!ptid_equal (inferior_ptid, null_ptid))
2201 {
2202 struct thread_info *ti = inferior_thread ();
2203
2204 report_change = (ti->global_num != command->thread);
2205 }
2206
2207 if (report_change)
2208 {
2209 observer_notify_user_selected_context_changed
2210 (USER_SELECTED_THREAD | USER_SELECTED_FRAME);
2211 }
2212 }
2213
2214 do_cleanups (cleanup);
2215 }
2216 }
2217
2218 static void
2219 mi_cmd_execute (struct mi_parse *parse)
2220 {
2221 struct cleanup *cleanup;
2222
2223 cleanup = prepare_execute_command ();
2224
2225 if (parse->all && parse->thread_group != -1)
2226 error (_("Cannot specify --thread-group together with --all"));
2227
2228 if (parse->all && parse->thread != -1)
2229 error (_("Cannot specify --thread together with --all"));
2230
2231 if (parse->thread_group != -1 && parse->thread != -1)
2232 error (_("Cannot specify --thread together with --thread-group"));
2233
2234 if (parse->frame != -1 && parse->thread == -1)
2235 error (_("Cannot specify --frame without --thread"));
2236
2237 if (parse->thread_group != -1)
2238 {
2239 struct inferior *inf = find_inferior_id (parse->thread_group);
2240 struct thread_info *tp = 0;
2241
2242 if (!inf)
2243 error (_("Invalid thread group for the --thread-group option"));
2244
2245 set_current_inferior (inf);
2246 /* This behaviour means that if --thread-group option identifies
2247 an inferior with multiple threads, then a random one will be
2248 picked. This is not a problem -- frontend should always
2249 provide --thread if it wishes to operate on a specific
2250 thread. */
2251 if (inf->pid != 0)
2252 tp = any_live_thread_of_process (inf->pid);
2253 switch_to_thread (tp ? tp->ptid : null_ptid);
2254 set_current_program_space (inf->pspace);
2255 }
2256
2257 if (parse->thread != -1)
2258 {
2259 struct thread_info *tp = find_thread_global_id (parse->thread);
2260
2261 if (!tp)
2262 error (_("Invalid thread id: %d"), parse->thread);
2263
2264 if (is_exited (tp->ptid))
2265 error (_("Thread id: %d has terminated"), parse->thread);
2266
2267 switch_to_thread (tp->ptid);
2268 }
2269
2270 if (parse->frame != -1)
2271 {
2272 struct frame_info *fid;
2273 int frame = parse->frame;
2274
2275 fid = find_relative_frame (get_current_frame (), &frame);
2276 if (frame == 0)
2277 /* find_relative_frame was successful */
2278 select_frame (fid);
2279 else
2280 error (_("Invalid frame id: %d"), frame);
2281 }
2282
2283 if (parse->language != language_unknown)
2284 {
2285 make_cleanup_restore_current_language ();
2286 set_language (parse->language);
2287 }
2288
2289 current_context = parse;
2290
2291 if (parse->cmd->argv_func != NULL)
2292 {
2293 parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
2294 }
2295 else if (parse->cmd->cli.cmd != 0)
2296 {
2297 /* FIXME: DELETE THIS. */
2298 /* The operation is still implemented by a cli command. */
2299 /* Must be a synchronous one. */
2300 mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
2301 parse->args);
2302 }
2303 else
2304 {
2305 /* FIXME: DELETE THIS. */
2306 string_file stb;
2307
2308 stb.puts ("Undefined mi command: ");
2309 stb.putstr (parse->command, '"');
2310 stb.puts (" (missing implementation)");
2311
2312 error_stream (stb);
2313 }
2314 do_cleanups (cleanup);
2315 }
2316
2317 /* FIXME: This is just a hack so we can get some extra commands going.
2318 We don't want to channel things through the CLI, but call libgdb directly.
2319 Use only for synchronous commands. */
2320
2321 void
2322 mi_execute_cli_command (const char *cmd, int args_p, const char *args)
2323 {
2324 if (cmd != 0)
2325 {
2326 struct cleanup *old_cleanups;
2327 char *run;
2328
2329 if (args_p)
2330 run = xstrprintf ("%s %s", cmd, args);
2331 else
2332 run = xstrdup (cmd);
2333 if (mi_debug_p)
2334 /* FIXME: gdb_???? */
2335 fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
2336 cmd, run);
2337 old_cleanups = make_cleanup (xfree, run);
2338 execute_command (run, 0 /* from_tty */ );
2339 do_cleanups (old_cleanups);
2340 return;
2341 }
2342 }
2343
2344 void
2345 mi_execute_async_cli_command (const char *cli_command, char **argv, int argc)
2346 {
2347 struct cleanup *old_cleanups;
2348 char *run;
2349
2350 if (mi_async_p ())
2351 run = xstrprintf ("%s %s&", cli_command, argc ? *argv : "");
2352 else
2353 run = xstrprintf ("%s %s", cli_command, argc ? *argv : "");
2354 old_cleanups = make_cleanup (xfree, run);
2355
2356 execute_command (run, 0 /* from_tty */ );
2357
2358 /* Do this before doing any printing. It would appear that some
2359 print code leaves garbage around in the buffer. */
2360 do_cleanups (old_cleanups);
2361 }
2362
2363 void
2364 mi_load_progress (const char *section_name,
2365 unsigned long sent_so_far,
2366 unsigned long total_section,
2367 unsigned long total_sent,
2368 unsigned long grand_total)
2369 {
2370 using namespace std::chrono;
2371 static steady_clock::time_point last_update;
2372 static char *previous_sect_name = NULL;
2373 int new_section;
2374 struct ui_out *saved_uiout;
2375 struct ui_out *uiout;
2376 struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
2377
2378 /* This function is called through deprecated_show_load_progress
2379 which means uiout may not be correct. Fix it for the duration
2380 of this function. */
2381 saved_uiout = current_uiout;
2382
2383 if (current_interp_named_p (INTERP_MI)
2384 || current_interp_named_p (INTERP_MI2))
2385 current_uiout = mi_out_new (2);
2386 else if (current_interp_named_p (INTERP_MI1))
2387 current_uiout = mi_out_new (1);
2388 else if (current_interp_named_p (INTERP_MI3))
2389 current_uiout = mi_out_new (3);
2390 else
2391 return;
2392
2393 uiout = current_uiout;
2394
2395 new_section = (previous_sect_name ?
2396 strcmp (previous_sect_name, section_name) : 1);
2397 if (new_section)
2398 {
2399 struct cleanup *cleanup_tuple;
2400
2401 xfree (previous_sect_name);
2402 previous_sect_name = xstrdup (section_name);
2403
2404 if (current_token)
2405 fputs_unfiltered (current_token, mi->raw_stdout);
2406 fputs_unfiltered ("+download", mi->raw_stdout);
2407 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2408 uiout->field_string ("section", section_name);
2409 uiout->field_int ("section-size", total_section);
2410 uiout->field_int ("total-size", grand_total);
2411 do_cleanups (cleanup_tuple);
2412 mi_out_put (uiout, mi->raw_stdout);
2413 fputs_unfiltered ("\n", mi->raw_stdout);
2414 gdb_flush (mi->raw_stdout);
2415 }
2416
2417 steady_clock::time_point time_now = steady_clock::now ();
2418 if (time_now - last_update > milliseconds (500))
2419 {
2420 struct cleanup *cleanup_tuple;
2421
2422 last_update = time_now;
2423 if (current_token)
2424 fputs_unfiltered (current_token, mi->raw_stdout);
2425 fputs_unfiltered ("+download", mi->raw_stdout);
2426 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2427 uiout->field_string ("section", section_name);
2428 uiout->field_int ("section-sent", sent_so_far);
2429 uiout->field_int ("section-size", total_section);
2430 uiout->field_int ("total-sent", total_sent);
2431 uiout->field_int ("total-size", grand_total);
2432 do_cleanups (cleanup_tuple);
2433 mi_out_put (uiout, mi->raw_stdout);
2434 fputs_unfiltered ("\n", mi->raw_stdout);
2435 gdb_flush (mi->raw_stdout);
2436 }
2437
2438 xfree (uiout);
2439 current_uiout = saved_uiout;
2440 }
2441
2442 static void
2443 timestamp (struct mi_timestamp *tv)
2444 {
2445 using namespace std::chrono;
2446
2447 tv->wallclock = steady_clock::now ();
2448 run_time_clock::now (tv->utime, tv->stime);
2449 }
2450
2451 static void
2452 print_diff_now (struct ui_file *file, struct mi_timestamp *start)
2453 {
2454 struct mi_timestamp now;
2455
2456 timestamp (&now);
2457 print_diff (file, start, &now);
2458 }
2459
2460 void
2461 mi_print_timing_maybe (struct ui_file *file)
2462 {
2463 /* If the command is -enable-timing then do_timings may be true
2464 whilst current_command_ts is not initialized. */
2465 if (do_timings && current_command_ts)
2466 print_diff_now (file, current_command_ts);
2467 }
2468
2469 static void
2470 print_diff (struct ui_file *file, struct mi_timestamp *start,
2471 struct mi_timestamp *end)
2472 {
2473 using namespace std::chrono;
2474
2475 duration<double> wallclock = end->wallclock - start->wallclock;
2476 duration<double> utime = end->utime - start->utime;
2477 duration<double> stime = end->stime - start->stime;
2478
2479 fprintf_unfiltered
2480 (file,
2481 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
2482 wallclock.count (), utime.count (), stime.count ());
2483 }
2484
2485 void
2486 mi_cmd_trace_define_variable (const char *command, char **argv, int argc)
2487 {
2488 LONGEST initval = 0;
2489 struct trace_state_variable *tsv;
2490 char *name = 0;
2491
2492 if (argc != 1 && argc != 2)
2493 error (_("Usage: -trace-define-variable VARIABLE [VALUE]"));
2494
2495 name = argv[0];
2496 if (*name++ != '$')
2497 error (_("Name of trace variable should start with '$'"));
2498
2499 validate_trace_state_variable_name (name);
2500
2501 tsv = find_trace_state_variable (name);
2502 if (!tsv)
2503 tsv = create_trace_state_variable (name);
2504
2505 if (argc == 2)
2506 initval = value_as_long (parse_and_eval (argv[1]));
2507
2508 tsv->initial_value = initval;
2509 }
2510
2511 void
2512 mi_cmd_trace_list_variables (const char *command, char **argv, int argc)
2513 {
2514 if (argc != 0)
2515 error (_("-trace-list-variables: no arguments allowed"));
2516
2517 tvariables_info_1 ();
2518 }
2519
2520 void
2521 mi_cmd_trace_find (const char *command, char **argv, int argc)
2522 {
2523 char *mode;
2524
2525 if (argc == 0)
2526 error (_("trace selection mode is required"));
2527
2528 mode = argv[0];
2529
2530 if (strcmp (mode, "none") == 0)
2531 {
2532 tfind_1 (tfind_number, -1, 0, 0, 0);
2533 return;
2534 }
2535
2536 check_trace_running (current_trace_status ());
2537
2538 if (strcmp (mode, "frame-number") == 0)
2539 {
2540 if (argc != 2)
2541 error (_("frame number is required"));
2542 tfind_1 (tfind_number, atoi (argv[1]), 0, 0, 0);
2543 }
2544 else if (strcmp (mode, "tracepoint-number") == 0)
2545 {
2546 if (argc != 2)
2547 error (_("tracepoint number is required"));
2548 tfind_1 (tfind_tp, atoi (argv[1]), 0, 0, 0);
2549 }
2550 else if (strcmp (mode, "pc") == 0)
2551 {
2552 if (argc != 2)
2553 error (_("PC is required"));
2554 tfind_1 (tfind_pc, 0, parse_and_eval_address (argv[1]), 0, 0);
2555 }
2556 else if (strcmp (mode, "pc-inside-range") == 0)
2557 {
2558 if (argc != 3)
2559 error (_("Start and end PC are required"));
2560 tfind_1 (tfind_range, 0, parse_and_eval_address (argv[1]),
2561 parse_and_eval_address (argv[2]), 0);
2562 }
2563 else if (strcmp (mode, "pc-outside-range") == 0)
2564 {
2565 if (argc != 3)
2566 error (_("Start and end PC are required"));
2567 tfind_1 (tfind_outside, 0, parse_and_eval_address (argv[1]),
2568 parse_and_eval_address (argv[2]), 0);
2569 }
2570 else if (strcmp (mode, "line") == 0)
2571 {
2572 struct symtabs_and_lines sals;
2573 struct symtab_and_line sal;
2574 static CORE_ADDR start_pc, end_pc;
2575 struct cleanup *back_to;
2576
2577 if (argc != 2)
2578 error (_("Line is required"));
2579
2580 sals = decode_line_with_current_source (argv[1],
2581 DECODE_LINE_FUNFIRSTLINE);
2582 back_to = make_cleanup (xfree, sals.sals);
2583
2584 sal = sals.sals[0];
2585
2586 if (sal.symtab == 0)
2587 error (_("Could not find the specified line"));
2588
2589 if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
2590 tfind_1 (tfind_range, 0, start_pc, end_pc - 1, 0);
2591 else
2592 error (_("Could not find the specified line"));
2593
2594 do_cleanups (back_to);
2595 }
2596 else
2597 error (_("Invalid mode '%s'"), mode);
2598
2599 if (has_stack_frames () || get_traceframe_number () >= 0)
2600 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS, 1);
2601 }
2602
2603 void
2604 mi_cmd_trace_save (const char *command, char **argv, int argc)
2605 {
2606 int target_saves = 0;
2607 int generate_ctf = 0;
2608 char *filename;
2609 int oind = 0;
2610 char *oarg;
2611
2612 enum opt
2613 {
2614 TARGET_SAVE_OPT, CTF_OPT
2615 };
2616 static const struct mi_opt opts[] =
2617 {
2618 {"r", TARGET_SAVE_OPT, 0},
2619 {"ctf", CTF_OPT, 0},
2620 { 0, 0, 0 }
2621 };
2622
2623 while (1)
2624 {
2625 int opt = mi_getopt ("-trace-save", argc, argv, opts,
2626 &oind, &oarg);
2627
2628 if (opt < 0)
2629 break;
2630 switch ((enum opt) opt)
2631 {
2632 case TARGET_SAVE_OPT:
2633 target_saves = 1;
2634 break;
2635 case CTF_OPT:
2636 generate_ctf = 1;
2637 break;
2638 }
2639 }
2640
2641 if (argc - oind != 1)
2642 error (_("Exactly one argument required "
2643 "(file in which to save trace data)"));
2644
2645 filename = argv[oind];
2646
2647 if (generate_ctf)
2648 trace_save_ctf (filename, target_saves);
2649 else
2650 trace_save_tfile (filename, target_saves);
2651 }
2652
2653 void
2654 mi_cmd_trace_start (const char *command, char **argv, int argc)
2655 {
2656 start_tracing (NULL);
2657 }
2658
2659 void
2660 mi_cmd_trace_status (const char *command, char **argv, int argc)
2661 {
2662 trace_status_mi (0);
2663 }
2664
2665 void
2666 mi_cmd_trace_stop (const char *command, char **argv, int argc)
2667 {
2668 stop_tracing (NULL);
2669 trace_status_mi (1);
2670 }
2671
2672 /* Implement the "-ada-task-info" command. */
2673
2674 void
2675 mi_cmd_ada_task_info (const char *command, char **argv, int argc)
2676 {
2677 if (argc != 0 && argc != 1)
2678 error (_("Invalid MI command"));
2679
2680 print_ada_task_info (current_uiout, argv[0], current_inferior ());
2681 }
2682
2683 /* Print EXPRESSION according to VALUES. */
2684
2685 static void
2686 print_variable_or_computed (const char *expression, enum print_values values)
2687 {
2688 struct cleanup *old_chain;
2689 struct value *val;
2690 struct type *type;
2691 struct ui_out *uiout = current_uiout;
2692
2693 string_file stb;
2694
2695 expression_up expr = parse_expression (expression);
2696
2697 if (values == PRINT_SIMPLE_VALUES)
2698 val = evaluate_type (expr.get ());
2699 else
2700 val = evaluate_expression (expr.get ());
2701
2702 old_chain = make_cleanup (null_cleanup, NULL);
2703 if (values != PRINT_NO_VALUES)
2704 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2705 uiout->field_string ("name", expression);
2706
2707 switch (values)
2708 {
2709 case PRINT_SIMPLE_VALUES:
2710 type = check_typedef (value_type (val));
2711 type_print (value_type (val), "", &stb, -1);
2712 uiout->field_stream ("type", stb);
2713 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
2714 && TYPE_CODE (type) != TYPE_CODE_STRUCT
2715 && TYPE_CODE (type) != TYPE_CODE_UNION)
2716 {
2717 struct value_print_options opts;
2718
2719 get_no_prettyformat_print_options (&opts);
2720 opts.deref_ref = 1;
2721 common_val_print (val, &stb, 0, &opts, current_language);
2722 uiout->field_stream ("value", stb);
2723 }
2724 break;
2725 case PRINT_ALL_VALUES:
2726 {
2727 struct value_print_options opts;
2728
2729 get_no_prettyformat_print_options (&opts);
2730 opts.deref_ref = 1;
2731 common_val_print (val, &stb, 0, &opts, current_language);
2732 uiout->field_stream ("value", stb);
2733 }
2734 break;
2735 }
2736
2737 do_cleanups (old_chain);
2738 }
2739
2740 /* Implement the "-trace-frame-collected" command. */
2741
2742 void
2743 mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
2744 {
2745 struct cleanup *old_chain;
2746 struct bp_location *tloc;
2747 int stepping_frame;
2748 struct collection_list *clist;
2749 struct collection_list tracepoint_list, stepping_list;
2750 struct traceframe_info *tinfo;
2751 int oind = 0;
2752 enum print_values var_print_values = PRINT_ALL_VALUES;
2753 enum print_values comp_print_values = PRINT_ALL_VALUES;
2754 int registers_format = 'x';
2755 int memory_contents = 0;
2756 struct ui_out *uiout = current_uiout;
2757 enum opt
2758 {
2759 VAR_PRINT_VALUES,
2760 COMP_PRINT_VALUES,
2761 REGISTERS_FORMAT,
2762 MEMORY_CONTENTS,
2763 };
2764 static const struct mi_opt opts[] =
2765 {
2766 {"-var-print-values", VAR_PRINT_VALUES, 1},
2767 {"-comp-print-values", COMP_PRINT_VALUES, 1},
2768 {"-registers-format", REGISTERS_FORMAT, 1},
2769 {"-memory-contents", MEMORY_CONTENTS, 0},
2770 { 0, 0, 0 }
2771 };
2772
2773 while (1)
2774 {
2775 char *oarg;
2776 int opt = mi_getopt ("-trace-frame-collected", argc, argv, opts,
2777 &oind, &oarg);
2778 if (opt < 0)
2779 break;
2780 switch ((enum opt) opt)
2781 {
2782 case VAR_PRINT_VALUES:
2783 var_print_values = mi_parse_print_values (oarg);
2784 break;
2785 case COMP_PRINT_VALUES:
2786 comp_print_values = mi_parse_print_values (oarg);
2787 break;
2788 case REGISTERS_FORMAT:
2789 registers_format = oarg[0];
2790 case MEMORY_CONTENTS:
2791 memory_contents = 1;
2792 break;
2793 }
2794 }
2795
2796 if (oind != argc)
2797 error (_("Usage: -trace-frame-collected "
2798 "[--var-print-values PRINT_VALUES] "
2799 "[--comp-print-values PRINT_VALUES] "
2800 "[--registers-format FORMAT]"
2801 "[--memory-contents]"));
2802
2803 /* This throws an error is not inspecting a trace frame. */
2804 tloc = get_traceframe_location (&stepping_frame);
2805
2806 /* This command only makes sense for the current frame, not the
2807 selected frame. */
2808 old_chain = make_cleanup_restore_current_thread ();
2809 select_frame (get_current_frame ());
2810
2811 encode_actions (tloc, &tracepoint_list, &stepping_list);
2812
2813 if (stepping_frame)
2814 clist = &stepping_list;
2815 else
2816 clist = &tracepoint_list;
2817
2818 tinfo = get_traceframe_info ();
2819
2820 /* Explicitly wholly collected variables. */
2821 {
2822 struct cleanup *list_cleanup;
2823 int i;
2824
2825 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout,
2826 "explicit-variables");
2827
2828 const std::vector<std::string> &wholly_collected
2829 = clist->wholly_collected ();
2830 for (size_t i = 0; i < wholly_collected.size (); i++)
2831 {
2832 const std::string &str = wholly_collected[i];
2833 print_variable_or_computed (str.c_str (), var_print_values);
2834 }
2835
2836 do_cleanups (list_cleanup);
2837 }
2838
2839 /* Computed expressions. */
2840 {
2841 struct cleanup *list_cleanup;
2842 char *p;
2843 int i;
2844
2845 list_cleanup
2846 = make_cleanup_ui_out_list_begin_end (uiout,
2847 "computed-expressions");
2848
2849 const std::vector<std::string> &computed = clist->computed ();
2850 for (size_t i = 0; i < computed.size (); i++)
2851 {
2852 const std::string &str = computed[i];
2853 print_variable_or_computed (str.c_str (), comp_print_values);
2854 }
2855
2856 do_cleanups (list_cleanup);
2857 }
2858
2859 /* Registers. Given pseudo-registers, and that some architectures
2860 (like MIPS) actually hide the raw registers, we don't go through
2861 the trace frame info, but instead consult the register cache for
2862 register availability. */
2863 {
2864 struct cleanup *list_cleanup;
2865 struct frame_info *frame;
2866 struct gdbarch *gdbarch;
2867 int regnum;
2868 int numregs;
2869
2870 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "registers");
2871
2872 frame = get_selected_frame (NULL);
2873 gdbarch = get_frame_arch (frame);
2874 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
2875
2876 for (regnum = 0; regnum < numregs; regnum++)
2877 {
2878 if (gdbarch_register_name (gdbarch, regnum) == NULL
2879 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
2880 continue;
2881
2882 output_register (frame, regnum, registers_format, 1);
2883 }
2884
2885 do_cleanups (list_cleanup);
2886 }
2887
2888 /* Trace state variables. */
2889 {
2890 struct cleanup *list_cleanup;
2891 int tvar;
2892 char *tsvname;
2893 int i;
2894
2895 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "tvars");
2896
2897 tsvname = NULL;
2898 make_cleanup (free_current_contents, &tsvname);
2899
2900 for (i = 0; VEC_iterate (int, tinfo->tvars, i, tvar); i++)
2901 {
2902 struct cleanup *cleanup_child;
2903 struct trace_state_variable *tsv;
2904
2905 tsv = find_trace_state_variable_by_number (tvar);
2906
2907 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2908
2909 if (tsv != NULL)
2910 {
2911 tsvname = (char *) xrealloc (tsvname, strlen (tsv->name) + 2);
2912 tsvname[0] = '$';
2913 strcpy (tsvname + 1, tsv->name);
2914 uiout->field_string ("name", tsvname);
2915
2916 tsv->value_known = target_get_trace_state_variable_value (tsv->number,
2917 &tsv->value);
2918 uiout->field_int ("current", tsv->value);
2919 }
2920 else
2921 {
2922 uiout->field_skip ("name");
2923 uiout->field_skip ("current");
2924 }
2925
2926 do_cleanups (cleanup_child);
2927 }
2928
2929 do_cleanups (list_cleanup);
2930 }
2931
2932 /* Memory. */
2933 {
2934 struct cleanup *list_cleanup;
2935 VEC(mem_range_s) *available_memory = NULL;
2936 struct mem_range *r;
2937 int i;
2938
2939 traceframe_available_memory (&available_memory, 0, ULONGEST_MAX);
2940 make_cleanup (VEC_cleanup(mem_range_s), &available_memory);
2941
2942 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "memory");
2943
2944 for (i = 0; VEC_iterate (mem_range_s, available_memory, i, r); i++)
2945 {
2946 struct cleanup *cleanup_child;
2947 gdb_byte *data;
2948 struct gdbarch *gdbarch = target_gdbarch ();
2949
2950 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2951
2952 uiout->field_core_addr ("address", gdbarch, r->start);
2953 uiout->field_int ("length", r->length);
2954
2955 data = (gdb_byte *) xmalloc (r->length);
2956 make_cleanup (xfree, data);
2957
2958 if (memory_contents)
2959 {
2960 if (target_read_memory (r->start, data, r->length) == 0)
2961 {
2962 int m;
2963 char *data_str, *p;
2964
2965 data_str = (char *) xmalloc (r->length * 2 + 1);
2966 make_cleanup (xfree, data_str);
2967
2968 for (m = 0, p = data_str; m < r->length; ++m, p += 2)
2969 sprintf (p, "%02x", data[m]);
2970 uiout->field_string ("contents", data_str);
2971 }
2972 else
2973 uiout->field_skip ("contents");
2974 }
2975 do_cleanups (cleanup_child);
2976 }
2977
2978 do_cleanups (list_cleanup);
2979 }
2980
2981 do_cleanups (old_chain);
2982 }
2983
2984 void
2985 _initialize_mi_main (void)
2986 {
2987 struct cmd_list_element *c;
2988
2989 add_setshow_boolean_cmd ("mi-async", class_run,
2990 &mi_async_1, _("\
2991 Set whether MI asynchronous mode is enabled."), _("\
2992 Show whether MI asynchronous mode is enabled."), _("\
2993 Tells GDB whether MI should be in asynchronous mode."),
2994 set_mi_async_command,
2995 show_mi_async_command,
2996 &setlist,
2997 &showlist);
2998
2999 /* Alias old "target-async" to "mi-async". */
3000 c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &setlist);
3001 deprecate_cmd (c, "set mi-async");
3002 c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &showlist);
3003 deprecate_cmd (c, "show mi-async");
3004 }
This page took 0.131524 seconds and 5 git commands to generate.