-Wwrite-strings: More Solaris
[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 (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] = 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 struct mi_parse *command = NULL;
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);
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))
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 mi_parse_free (command);
2215
2216 do_cleanups (cleanup);
2217 }
2218 }
2219
2220 static void
2221 mi_cmd_execute (struct mi_parse *parse)
2222 {
2223 struct cleanup *cleanup;
2224
2225 cleanup = prepare_execute_command ();
2226
2227 if (parse->all && parse->thread_group != -1)
2228 error (_("Cannot specify --thread-group together with --all"));
2229
2230 if (parse->all && parse->thread != -1)
2231 error (_("Cannot specify --thread together with --all"));
2232
2233 if (parse->thread_group != -1 && parse->thread != -1)
2234 error (_("Cannot specify --thread together with --thread-group"));
2235
2236 if (parse->frame != -1 && parse->thread == -1)
2237 error (_("Cannot specify --frame without --thread"));
2238
2239 if (parse->thread_group != -1)
2240 {
2241 struct inferior *inf = find_inferior_id (parse->thread_group);
2242 struct thread_info *tp = 0;
2243
2244 if (!inf)
2245 error (_("Invalid thread group for the --thread-group option"));
2246
2247 set_current_inferior (inf);
2248 /* This behaviour means that if --thread-group option identifies
2249 an inferior with multiple threads, then a random one will be
2250 picked. This is not a problem -- frontend should always
2251 provide --thread if it wishes to operate on a specific
2252 thread. */
2253 if (inf->pid != 0)
2254 tp = any_live_thread_of_process (inf->pid);
2255 switch_to_thread (tp ? tp->ptid : null_ptid);
2256 set_current_program_space (inf->pspace);
2257 }
2258
2259 if (parse->thread != -1)
2260 {
2261 struct thread_info *tp = find_thread_global_id (parse->thread);
2262
2263 if (!tp)
2264 error (_("Invalid thread id: %d"), parse->thread);
2265
2266 if (is_exited (tp->ptid))
2267 error (_("Thread id: %d has terminated"), parse->thread);
2268
2269 switch_to_thread (tp->ptid);
2270 }
2271
2272 if (parse->frame != -1)
2273 {
2274 struct frame_info *fid;
2275 int frame = parse->frame;
2276
2277 fid = find_relative_frame (get_current_frame (), &frame);
2278 if (frame == 0)
2279 /* find_relative_frame was successful */
2280 select_frame (fid);
2281 else
2282 error (_("Invalid frame id: %d"), frame);
2283 }
2284
2285 if (parse->language != language_unknown)
2286 {
2287 make_cleanup_restore_current_language ();
2288 set_language (parse->language);
2289 }
2290
2291 current_context = parse;
2292
2293 if (parse->cmd->argv_func != NULL)
2294 {
2295 parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
2296 }
2297 else if (parse->cmd->cli.cmd != 0)
2298 {
2299 /* FIXME: DELETE THIS. */
2300 /* The operation is still implemented by a cli command. */
2301 /* Must be a synchronous one. */
2302 mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
2303 parse->args);
2304 }
2305 else
2306 {
2307 /* FIXME: DELETE THIS. */
2308 string_file stb;
2309
2310 stb.puts ("Undefined mi command: ");
2311 stb.putstr (parse->command, '"');
2312 stb.puts (" (missing implementation)");
2313
2314 error_stream (stb);
2315 }
2316 do_cleanups (cleanup);
2317 }
2318
2319 /* FIXME: This is just a hack so we can get some extra commands going.
2320 We don't want to channel things through the CLI, but call libgdb directly.
2321 Use only for synchronous commands. */
2322
2323 void
2324 mi_execute_cli_command (const char *cmd, int args_p, const char *args)
2325 {
2326 if (cmd != 0)
2327 {
2328 struct cleanup *old_cleanups;
2329 char *run;
2330
2331 if (args_p)
2332 run = xstrprintf ("%s %s", cmd, args);
2333 else
2334 run = xstrdup (cmd);
2335 if (mi_debug_p)
2336 /* FIXME: gdb_???? */
2337 fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
2338 cmd, run);
2339 old_cleanups = make_cleanup (xfree, run);
2340 execute_command (run, 0 /* from_tty */ );
2341 do_cleanups (old_cleanups);
2342 return;
2343 }
2344 }
2345
2346 void
2347 mi_execute_async_cli_command (char *cli_command, char **argv, int argc)
2348 {
2349 struct cleanup *old_cleanups;
2350 char *run;
2351
2352 if (mi_async_p ())
2353 run = xstrprintf ("%s %s&", cli_command, argc ? *argv : "");
2354 else
2355 run = xstrprintf ("%s %s", cli_command, argc ? *argv : "");
2356 old_cleanups = make_cleanup (xfree, run);
2357
2358 execute_command (run, 0 /* from_tty */ );
2359
2360 /* Do this before doing any printing. It would appear that some
2361 print code leaves garbage around in the buffer. */
2362 do_cleanups (old_cleanups);
2363 }
2364
2365 void
2366 mi_load_progress (const char *section_name,
2367 unsigned long sent_so_far,
2368 unsigned long total_section,
2369 unsigned long total_sent,
2370 unsigned long grand_total)
2371 {
2372 using namespace std::chrono;
2373 static steady_clock::time_point last_update;
2374 static char *previous_sect_name = NULL;
2375 int new_section;
2376 struct ui_out *saved_uiout;
2377 struct ui_out *uiout;
2378 struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
2379
2380 /* This function is called through deprecated_show_load_progress
2381 which means uiout may not be correct. Fix it for the duration
2382 of this function. */
2383 saved_uiout = current_uiout;
2384
2385 if (current_interp_named_p (INTERP_MI)
2386 || current_interp_named_p (INTERP_MI2))
2387 current_uiout = mi_out_new (2);
2388 else if (current_interp_named_p (INTERP_MI1))
2389 current_uiout = mi_out_new (1);
2390 else if (current_interp_named_p (INTERP_MI3))
2391 current_uiout = mi_out_new (3);
2392 else
2393 return;
2394
2395 uiout = current_uiout;
2396
2397 new_section = (previous_sect_name ?
2398 strcmp (previous_sect_name, section_name) : 1);
2399 if (new_section)
2400 {
2401 struct cleanup *cleanup_tuple;
2402
2403 xfree (previous_sect_name);
2404 previous_sect_name = xstrdup (section_name);
2405
2406 if (current_token)
2407 fputs_unfiltered (current_token, mi->raw_stdout);
2408 fputs_unfiltered ("+download", mi->raw_stdout);
2409 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2410 uiout->field_string ("section", section_name);
2411 uiout->field_int ("section-size", total_section);
2412 uiout->field_int ("total-size", grand_total);
2413 do_cleanups (cleanup_tuple);
2414 mi_out_put (uiout, mi->raw_stdout);
2415 fputs_unfiltered ("\n", mi->raw_stdout);
2416 gdb_flush (mi->raw_stdout);
2417 }
2418
2419 steady_clock::time_point time_now = steady_clock::now ();
2420 if (time_now - last_update > milliseconds (500))
2421 {
2422 struct cleanup *cleanup_tuple;
2423
2424 last_update = time_now;
2425 if (current_token)
2426 fputs_unfiltered (current_token, mi->raw_stdout);
2427 fputs_unfiltered ("+download", mi->raw_stdout);
2428 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2429 uiout->field_string ("section", section_name);
2430 uiout->field_int ("section-sent", sent_so_far);
2431 uiout->field_int ("section-size", total_section);
2432 uiout->field_int ("total-sent", total_sent);
2433 uiout->field_int ("total-size", grand_total);
2434 do_cleanups (cleanup_tuple);
2435 mi_out_put (uiout, mi->raw_stdout);
2436 fputs_unfiltered ("\n", mi->raw_stdout);
2437 gdb_flush (mi->raw_stdout);
2438 }
2439
2440 xfree (uiout);
2441 current_uiout = saved_uiout;
2442 }
2443
2444 static void
2445 timestamp (struct mi_timestamp *tv)
2446 {
2447 using namespace std::chrono;
2448
2449 tv->wallclock = steady_clock::now ();
2450 run_time_clock::now (tv->utime, tv->stime);
2451 }
2452
2453 static void
2454 print_diff_now (struct ui_file *file, struct mi_timestamp *start)
2455 {
2456 struct mi_timestamp now;
2457
2458 timestamp (&now);
2459 print_diff (file, start, &now);
2460 }
2461
2462 void
2463 mi_print_timing_maybe (struct ui_file *file)
2464 {
2465 /* If the command is -enable-timing then do_timings may be true
2466 whilst current_command_ts is not initialized. */
2467 if (do_timings && current_command_ts)
2468 print_diff_now (file, current_command_ts);
2469 }
2470
2471 static void
2472 print_diff (struct ui_file *file, struct mi_timestamp *start,
2473 struct mi_timestamp *end)
2474 {
2475 using namespace std::chrono;
2476
2477 duration<double> wallclock = end->wallclock - start->wallclock;
2478 duration<double> utime = end->utime - start->utime;
2479 duration<double> stime = end->stime - start->stime;
2480
2481 fprintf_unfiltered
2482 (file,
2483 ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
2484 wallclock.count (), utime.count (), stime.count ());
2485 }
2486
2487 void
2488 mi_cmd_trace_define_variable (const char *command, char **argv, int argc)
2489 {
2490 LONGEST initval = 0;
2491 struct trace_state_variable *tsv;
2492 char *name = 0;
2493
2494 if (argc != 1 && argc != 2)
2495 error (_("Usage: -trace-define-variable VARIABLE [VALUE]"));
2496
2497 name = argv[0];
2498 if (*name++ != '$')
2499 error (_("Name of trace variable should start with '$'"));
2500
2501 validate_trace_state_variable_name (name);
2502
2503 tsv = find_trace_state_variable (name);
2504 if (!tsv)
2505 tsv = create_trace_state_variable (name);
2506
2507 if (argc == 2)
2508 initval = value_as_long (parse_and_eval (argv[1]));
2509
2510 tsv->initial_value = initval;
2511 }
2512
2513 void
2514 mi_cmd_trace_list_variables (const char *command, char **argv, int argc)
2515 {
2516 if (argc != 0)
2517 error (_("-trace-list-variables: no arguments allowed"));
2518
2519 tvariables_info_1 ();
2520 }
2521
2522 void
2523 mi_cmd_trace_find (const char *command, char **argv, int argc)
2524 {
2525 char *mode;
2526
2527 if (argc == 0)
2528 error (_("trace selection mode is required"));
2529
2530 mode = argv[0];
2531
2532 if (strcmp (mode, "none") == 0)
2533 {
2534 tfind_1 (tfind_number, -1, 0, 0, 0);
2535 return;
2536 }
2537
2538 check_trace_running (current_trace_status ());
2539
2540 if (strcmp (mode, "frame-number") == 0)
2541 {
2542 if (argc != 2)
2543 error (_("frame number is required"));
2544 tfind_1 (tfind_number, atoi (argv[1]), 0, 0, 0);
2545 }
2546 else if (strcmp (mode, "tracepoint-number") == 0)
2547 {
2548 if (argc != 2)
2549 error (_("tracepoint number is required"));
2550 tfind_1 (tfind_tp, atoi (argv[1]), 0, 0, 0);
2551 }
2552 else if (strcmp (mode, "pc") == 0)
2553 {
2554 if (argc != 2)
2555 error (_("PC is required"));
2556 tfind_1 (tfind_pc, 0, parse_and_eval_address (argv[1]), 0, 0);
2557 }
2558 else if (strcmp (mode, "pc-inside-range") == 0)
2559 {
2560 if (argc != 3)
2561 error (_("Start and end PC are required"));
2562 tfind_1 (tfind_range, 0, parse_and_eval_address (argv[1]),
2563 parse_and_eval_address (argv[2]), 0);
2564 }
2565 else if (strcmp (mode, "pc-outside-range") == 0)
2566 {
2567 if (argc != 3)
2568 error (_("Start and end PC are required"));
2569 tfind_1 (tfind_outside, 0, parse_and_eval_address (argv[1]),
2570 parse_and_eval_address (argv[2]), 0);
2571 }
2572 else if (strcmp (mode, "line") == 0)
2573 {
2574 struct symtabs_and_lines sals;
2575 struct symtab_and_line sal;
2576 static CORE_ADDR start_pc, end_pc;
2577 struct cleanup *back_to;
2578
2579 if (argc != 2)
2580 error (_("Line is required"));
2581
2582 sals = decode_line_with_current_source (argv[1],
2583 DECODE_LINE_FUNFIRSTLINE);
2584 back_to = make_cleanup (xfree, sals.sals);
2585
2586 sal = sals.sals[0];
2587
2588 if (sal.symtab == 0)
2589 error (_("Could not find the specified line"));
2590
2591 if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
2592 tfind_1 (tfind_range, 0, start_pc, end_pc - 1, 0);
2593 else
2594 error (_("Could not find the specified line"));
2595
2596 do_cleanups (back_to);
2597 }
2598 else
2599 error (_("Invalid mode '%s'"), mode);
2600
2601 if (has_stack_frames () || get_traceframe_number () >= 0)
2602 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS, 1);
2603 }
2604
2605 void
2606 mi_cmd_trace_save (const char *command, char **argv, int argc)
2607 {
2608 int target_saves = 0;
2609 int generate_ctf = 0;
2610 char *filename;
2611 int oind = 0;
2612 char *oarg;
2613
2614 enum opt
2615 {
2616 TARGET_SAVE_OPT, CTF_OPT
2617 };
2618 static const struct mi_opt opts[] =
2619 {
2620 {"r", TARGET_SAVE_OPT, 0},
2621 {"ctf", CTF_OPT, 0},
2622 { 0, 0, 0 }
2623 };
2624
2625 while (1)
2626 {
2627 int opt = mi_getopt ("-trace-save", argc, argv, opts,
2628 &oind, &oarg);
2629
2630 if (opt < 0)
2631 break;
2632 switch ((enum opt) opt)
2633 {
2634 case TARGET_SAVE_OPT:
2635 target_saves = 1;
2636 break;
2637 case CTF_OPT:
2638 generate_ctf = 1;
2639 break;
2640 }
2641 }
2642
2643 if (argc - oind != 1)
2644 error (_("Exactly one argument required "
2645 "(file in which to save trace data)"));
2646
2647 filename = argv[oind];
2648
2649 if (generate_ctf)
2650 trace_save_ctf (filename, target_saves);
2651 else
2652 trace_save_tfile (filename, target_saves);
2653 }
2654
2655 void
2656 mi_cmd_trace_start (const char *command, char **argv, int argc)
2657 {
2658 start_tracing (NULL);
2659 }
2660
2661 void
2662 mi_cmd_trace_status (const char *command, char **argv, int argc)
2663 {
2664 trace_status_mi (0);
2665 }
2666
2667 void
2668 mi_cmd_trace_stop (const char *command, char **argv, int argc)
2669 {
2670 stop_tracing (NULL);
2671 trace_status_mi (1);
2672 }
2673
2674 /* Implement the "-ada-task-info" command. */
2675
2676 void
2677 mi_cmd_ada_task_info (const char *command, char **argv, int argc)
2678 {
2679 if (argc != 0 && argc != 1)
2680 error (_("Invalid MI command"));
2681
2682 print_ada_task_info (current_uiout, argv[0], current_inferior ());
2683 }
2684
2685 /* Print EXPRESSION according to VALUES. */
2686
2687 static void
2688 print_variable_or_computed (const char *expression, enum print_values values)
2689 {
2690 struct cleanup *old_chain;
2691 struct value *val;
2692 struct type *type;
2693 struct ui_out *uiout = current_uiout;
2694
2695 string_file stb;
2696
2697 expression_up expr = parse_expression (expression);
2698
2699 if (values == PRINT_SIMPLE_VALUES)
2700 val = evaluate_type (expr.get ());
2701 else
2702 val = evaluate_expression (expr.get ());
2703
2704 old_chain = make_cleanup (null_cleanup, NULL);
2705 if (values != PRINT_NO_VALUES)
2706 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2707 uiout->field_string ("name", expression);
2708
2709 switch (values)
2710 {
2711 case PRINT_SIMPLE_VALUES:
2712 type = check_typedef (value_type (val));
2713 type_print (value_type (val), "", &stb, -1);
2714 uiout->field_stream ("type", stb);
2715 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
2716 && TYPE_CODE (type) != TYPE_CODE_STRUCT
2717 && TYPE_CODE (type) != TYPE_CODE_UNION)
2718 {
2719 struct value_print_options opts;
2720
2721 get_no_prettyformat_print_options (&opts);
2722 opts.deref_ref = 1;
2723 common_val_print (val, &stb, 0, &opts, current_language);
2724 uiout->field_stream ("value", stb);
2725 }
2726 break;
2727 case PRINT_ALL_VALUES:
2728 {
2729 struct value_print_options opts;
2730
2731 get_no_prettyformat_print_options (&opts);
2732 opts.deref_ref = 1;
2733 common_val_print (val, &stb, 0, &opts, current_language);
2734 uiout->field_stream ("value", stb);
2735 }
2736 break;
2737 }
2738
2739 do_cleanups (old_chain);
2740 }
2741
2742 /* Implement the "-trace-frame-collected" command. */
2743
2744 void
2745 mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
2746 {
2747 struct cleanup *old_chain;
2748 struct bp_location *tloc;
2749 int stepping_frame;
2750 struct collection_list *clist;
2751 struct collection_list tracepoint_list, stepping_list;
2752 struct traceframe_info *tinfo;
2753 int oind = 0;
2754 enum print_values var_print_values = PRINT_ALL_VALUES;
2755 enum print_values comp_print_values = PRINT_ALL_VALUES;
2756 int registers_format = 'x';
2757 int memory_contents = 0;
2758 struct ui_out *uiout = current_uiout;
2759 enum opt
2760 {
2761 VAR_PRINT_VALUES,
2762 COMP_PRINT_VALUES,
2763 REGISTERS_FORMAT,
2764 MEMORY_CONTENTS,
2765 };
2766 static const struct mi_opt opts[] =
2767 {
2768 {"-var-print-values", VAR_PRINT_VALUES, 1},
2769 {"-comp-print-values", COMP_PRINT_VALUES, 1},
2770 {"-registers-format", REGISTERS_FORMAT, 1},
2771 {"-memory-contents", MEMORY_CONTENTS, 0},
2772 { 0, 0, 0 }
2773 };
2774
2775 while (1)
2776 {
2777 char *oarg;
2778 int opt = mi_getopt ("-trace-frame-collected", argc, argv, opts,
2779 &oind, &oarg);
2780 if (opt < 0)
2781 break;
2782 switch ((enum opt) opt)
2783 {
2784 case VAR_PRINT_VALUES:
2785 var_print_values = mi_parse_print_values (oarg);
2786 break;
2787 case COMP_PRINT_VALUES:
2788 comp_print_values = mi_parse_print_values (oarg);
2789 break;
2790 case REGISTERS_FORMAT:
2791 registers_format = oarg[0];
2792 case MEMORY_CONTENTS:
2793 memory_contents = 1;
2794 break;
2795 }
2796 }
2797
2798 if (oind != argc)
2799 error (_("Usage: -trace-frame-collected "
2800 "[--var-print-values PRINT_VALUES] "
2801 "[--comp-print-values PRINT_VALUES] "
2802 "[--registers-format FORMAT]"
2803 "[--memory-contents]"));
2804
2805 /* This throws an error is not inspecting a trace frame. */
2806 tloc = get_traceframe_location (&stepping_frame);
2807
2808 /* This command only makes sense for the current frame, not the
2809 selected frame. */
2810 old_chain = make_cleanup_restore_current_thread ();
2811 select_frame (get_current_frame ());
2812
2813 encode_actions (tloc, &tracepoint_list, &stepping_list);
2814
2815 if (stepping_frame)
2816 clist = &stepping_list;
2817 else
2818 clist = &tracepoint_list;
2819
2820 tinfo = get_traceframe_info ();
2821
2822 /* Explicitly wholly collected variables. */
2823 {
2824 struct cleanup *list_cleanup;
2825 int i;
2826
2827 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout,
2828 "explicit-variables");
2829
2830 const std::vector<std::string> &wholly_collected
2831 = clist->wholly_collected ();
2832 for (size_t i = 0; i < wholly_collected.size (); i++)
2833 {
2834 const std::string &str = wholly_collected[i];
2835 print_variable_or_computed (str.c_str (), var_print_values);
2836 }
2837
2838 do_cleanups (list_cleanup);
2839 }
2840
2841 /* Computed expressions. */
2842 {
2843 struct cleanup *list_cleanup;
2844 char *p;
2845 int i;
2846
2847 list_cleanup
2848 = make_cleanup_ui_out_list_begin_end (uiout,
2849 "computed-expressions");
2850
2851 const std::vector<std::string> &computed = clist->computed ();
2852 for (size_t i = 0; i < computed.size (); i++)
2853 {
2854 const std::string &str = computed[i];
2855 print_variable_or_computed (str.c_str (), comp_print_values);
2856 }
2857
2858 do_cleanups (list_cleanup);
2859 }
2860
2861 /* Registers. Given pseudo-registers, and that some architectures
2862 (like MIPS) actually hide the raw registers, we don't go through
2863 the trace frame info, but instead consult the register cache for
2864 register availability. */
2865 {
2866 struct cleanup *list_cleanup;
2867 struct frame_info *frame;
2868 struct gdbarch *gdbarch;
2869 int regnum;
2870 int numregs;
2871
2872 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "registers");
2873
2874 frame = get_selected_frame (NULL);
2875 gdbarch = get_frame_arch (frame);
2876 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
2877
2878 for (regnum = 0; regnum < numregs; regnum++)
2879 {
2880 if (gdbarch_register_name (gdbarch, regnum) == NULL
2881 || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
2882 continue;
2883
2884 output_register (frame, regnum, registers_format, 1);
2885 }
2886
2887 do_cleanups (list_cleanup);
2888 }
2889
2890 /* Trace state variables. */
2891 {
2892 struct cleanup *list_cleanup;
2893 int tvar;
2894 char *tsvname;
2895 int i;
2896
2897 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "tvars");
2898
2899 tsvname = NULL;
2900 make_cleanup (free_current_contents, &tsvname);
2901
2902 for (i = 0; VEC_iterate (int, tinfo->tvars, i, tvar); i++)
2903 {
2904 struct cleanup *cleanup_child;
2905 struct trace_state_variable *tsv;
2906
2907 tsv = find_trace_state_variable_by_number (tvar);
2908
2909 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2910
2911 if (tsv != NULL)
2912 {
2913 tsvname = (char *) xrealloc (tsvname, strlen (tsv->name) + 2);
2914 tsvname[0] = '$';
2915 strcpy (tsvname + 1, tsv->name);
2916 uiout->field_string ("name", tsvname);
2917
2918 tsv->value_known = target_get_trace_state_variable_value (tsv->number,
2919 &tsv->value);
2920 uiout->field_int ("current", tsv->value);
2921 }
2922 else
2923 {
2924 uiout->field_skip ("name");
2925 uiout->field_skip ("current");
2926 }
2927
2928 do_cleanups (cleanup_child);
2929 }
2930
2931 do_cleanups (list_cleanup);
2932 }
2933
2934 /* Memory. */
2935 {
2936 struct cleanup *list_cleanup;
2937 VEC(mem_range_s) *available_memory = NULL;
2938 struct mem_range *r;
2939 int i;
2940
2941 traceframe_available_memory (&available_memory, 0, ULONGEST_MAX);
2942 make_cleanup (VEC_cleanup(mem_range_s), &available_memory);
2943
2944 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "memory");
2945
2946 for (i = 0; VEC_iterate (mem_range_s, available_memory, i, r); i++)
2947 {
2948 struct cleanup *cleanup_child;
2949 gdb_byte *data;
2950 struct gdbarch *gdbarch = target_gdbarch ();
2951
2952 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
2953
2954 uiout->field_core_addr ("address", gdbarch, r->start);
2955 uiout->field_int ("length", r->length);
2956
2957 data = (gdb_byte *) xmalloc (r->length);
2958 make_cleanup (xfree, data);
2959
2960 if (memory_contents)
2961 {
2962 if (target_read_memory (r->start, data, r->length) == 0)
2963 {
2964 int m;
2965 char *data_str, *p;
2966
2967 data_str = (char *) xmalloc (r->length * 2 + 1);
2968 make_cleanup (xfree, data_str);
2969
2970 for (m = 0, p = data_str; m < r->length; ++m, p += 2)
2971 sprintf (p, "%02x", data[m]);
2972 uiout->field_string ("contents", data_str);
2973 }
2974 else
2975 uiout->field_skip ("contents");
2976 }
2977 do_cleanups (cleanup_child);
2978 }
2979
2980 do_cleanups (list_cleanup);
2981 }
2982
2983 do_cleanups (old_chain);
2984 }
2985
2986 void
2987 _initialize_mi_main (void)
2988 {
2989 struct cmd_list_element *c;
2990
2991 add_setshow_boolean_cmd ("mi-async", class_run,
2992 &mi_async_1, _("\
2993 Set whether MI asynchronous mode is enabled."), _("\
2994 Show whether MI asynchronous mode is enabled."), _("\
2995 Tells GDB whether MI should be in asynchronous mode."),
2996 set_mi_async_command,
2997 show_mi_async_command,
2998 &setlist,
2999 &showlist);
3000
3001 /* Alias old "target-async" to "mi-async". */
3002 c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &setlist);
3003 deprecate_cmd (c, "set mi-async");
3004 c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &showlist);
3005 deprecate_cmd (c, "show mi-async");
3006 }
This page took 0.117743 seconds and 5 git commands to generate.