* dwarf2expr.c (get_signed_type): New function.
[deliverable/binutils-gdb.git] / gdb / mi / mi-interp.c
CommitLineData
4a8f6654
AC
1/* MI Interpreter Definitions and Commands for GDB, the GNU debugger.
2
7b6bb8da 3 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
9b254dd1 4 Free Software Foundation, Inc.
4a8f6654
AC
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
4a8f6654
AC
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4a8f6654
AC
20
21#include "defs.h"
22#include "gdb_string.h"
23#include "interps.h"
24#include "event-top.h"
25#include "event-loop.h"
26#include "inferior.h"
27#include "ui-out.h"
28#include "top.h"
c1043fc2 29#include "exceptions.h"
4a8f6654
AC
30#include "mi-main.h"
31#include "mi-cmds.h"
32#include "mi-out.h"
33#include "mi-console.h"
66bb093b 34#include "mi-common.h"
683f2885
VP
35#include "observer.h"
36#include "gdbthread.h"
c86cf029 37#include "solist.h"
8d3788bd 38#include "gdb.h"
4a8f6654 39
4a8f6654
AC
40/* These are the interpreter setup, etc. functions for the MI interpreter */
41static void mi_execute_command_wrapper (char *cmd);
42static void mi_command_loop (int mi_version);
4a8f6654
AC
43
44/* These are hooks that we put in place while doing interpreter_exec
45 so we can report interesting things that happened "behind the mi's
46 back" in this command */
bee0189a 47static int mi_interp_query_hook (const char *ctlstr, va_list ap)
a0b31db1 48 ATTRIBUTE_PRINTF (1, 0);
4a8f6654 49
f786f615 50static void mi3_command_loop (void);
4a8f6654
AC
51static void mi2_command_loop (void);
52static void mi1_command_loop (void);
53
54static void mi_insert_notify_hooks (void);
55static void mi_remove_notify_hooks (void);
1d33d6ba 56static void mi_on_normal_stop (struct bpstats *bs, int print_frame);
4a8f6654 57
683f2885 58static void mi_new_thread (struct thread_info *t);
a07daef3 59static void mi_thread_exit (struct thread_info *t, int silent);
a79b8f6e
VP
60static void mi_inferior_added (struct inferior *inf);
61static void mi_inferior_appeared (struct inferior *inf);
62static void mi_inferior_exit (struct inferior *inf);
63static void mi_inferior_removed (struct inferior *inf);
e1ac3328 64static void mi_on_resume (ptid_t ptid);
c86cf029
VP
65static void mi_solib_loaded (struct so_list *solib);
66static void mi_solib_unloaded (struct so_list *solib);
f3b1572e 67static void mi_about_to_proceed (void);
8d3788bd
VP
68static void mi_breakpoint_created (struct breakpoint *b);
69static void mi_breakpoint_deleted (struct breakpoint *b);
70static void mi_breakpoint_modified (struct breakpoint *b);
683f2885 71
a79b8f6e
VP
72static int report_initial_inferior (struct inferior *inf, void *closure);
73
4a8f6654 74static void *
683f2885 75mi_interpreter_init (int top_level)
4a8f6654
AC
76{
77 struct mi_interp *mi = XMALLOC (struct mi_interp);
78
4a8f6654
AC
79 /* HACK: We need to force stdout/stderr to point at the console. This avoids
80 any potential side effects caused by legacy code that is still
81 using the TUI / fputs_unfiltered_hook. So we set up output channels for
82 this now, and swap them in when we are run. */
83
84 raw_stdout = stdio_fileopen (stdout);
85
86 /* Create MI channels */
87 mi->out = mi_console_file_new (raw_stdout, "~", '"');
88 mi->err = mi_console_file_new (raw_stdout, "&", '"');
89 mi->log = mi->err;
90 mi->targ = mi_console_file_new (raw_stdout, "@", '"');
91 mi->event_channel = mi_console_file_new (raw_stdout, "=", 0);
92
683f2885 93 if (top_level)
063bfe2e
VP
94 {
95 observer_attach_new_thread (mi_new_thread);
96 observer_attach_thread_exit (mi_thread_exit);
a79b8f6e 97 observer_attach_inferior_added (mi_inferior_added);
6c95b8df 98 observer_attach_inferior_appeared (mi_inferior_appeared);
4a92f99b 99 observer_attach_inferior_exit (mi_inferior_exit);
a79b8f6e 100 observer_attach_inferior_removed (mi_inferior_removed);
f7f9a841 101 observer_attach_normal_stop (mi_on_normal_stop);
e1ac3328 102 observer_attach_target_resumed (mi_on_resume);
c86cf029
VP
103 observer_attach_solib_loaded (mi_solib_loaded);
104 observer_attach_solib_unloaded (mi_solib_unloaded);
f3b1572e 105 observer_attach_about_to_proceed (mi_about_to_proceed);
8d3788bd
VP
106 observer_attach_breakpoint_created (mi_breakpoint_created);
107 observer_attach_breakpoint_deleted (mi_breakpoint_deleted);
108 observer_attach_breakpoint_modified (mi_breakpoint_modified);
a79b8f6e
VP
109
110 /* The initial inferior is created before this function is called, so we
111 need to report it explicitly. Use iteration in case future version
112 of GDB creates more than one inferior up-front. */
113 iterate_over_inferiors (report_initial_inferior, mi);
063bfe2e 114 }
683f2885 115
4a8f6654
AC
116 return mi;
117}
118
119static int
120mi_interpreter_resume (void *data)
121{
122 struct mi_interp *mi = data;
4a8f6654 123
102040f0 124 /* As per hack note in mi_interpreter_init, swap in the output channels... */
4a8f6654
AC
125 gdb_setup_readline ();
126
362646f5
AC
127 /* These overwrite some of the initialization done in
128 _intialize_event_loop. */
129 call_readline = gdb_readline2;
130 input_handler = mi_execute_command_wrapper;
131 add_file_handler (input_fd, stdin_event_handler, 0);
132 async_command_editing_p = 0;
133 /* FIXME: This is a total hack for now. PB's use of the MI
134 implicitly relies on a bug in the async support which allows
135 asynchronous commands to leak through the commmand loop. The bug
136 involves (but is not limited to) the fact that sync_execution was
137 erroneously initialized to 0. Duplicate by initializing it thus
138 here... */
139 sync_execution = 0;
4a8f6654
AC
140
141 gdb_stdout = mi->out;
142 /* Route error and log output through the MI */
143 gdb_stderr = mi->err;
144 gdb_stdlog = mi->log;
145 /* Route target output through the MI. */
146 gdb_stdtarg = mi->targ;
1f20321b
FR
147 /* Route target error through the MI as well. */
148 gdb_stdtargerr = mi->targ;
4a8f6654
AC
149
150 /* Replace all the hooks that we know about. There really needs to
151 be a better way of doing this... */
152 clear_interpreter_hooks ();
153
9a4105ab 154 deprecated_show_load_progress = mi_load_progress;
4a8f6654
AC
155
156 /* If we're _the_ interpreter, take control. */
157 if (current_interp_named_p (INTERP_MI1))
9a4105ab 158 deprecated_command_loop_hook = mi1_command_loop;
f786f615 159 else if (current_interp_named_p (INTERP_MI2))
9a4105ab 160 deprecated_command_loop_hook = mi2_command_loop;
f786f615 161 else if (current_interp_named_p (INTERP_MI3))
9a4105ab 162 deprecated_command_loop_hook = mi3_command_loop;
4a8f6654 163 else
9a4105ab 164 deprecated_command_loop_hook = mi2_command_loop;
4a8f6654
AC
165
166 return 1;
167}
168
169static int
170mi_interpreter_suspend (void *data)
171{
172 gdb_disable_readline ();
173 return 1;
174}
175
71fff37b 176static struct gdb_exception
4a8f6654
AC
177mi_interpreter_exec (void *data, const char *command)
178{
179 char *tmp = alloca (strlen (command) + 1);
102040f0 180
4a8f6654
AC
181 strcpy (tmp, command);
182 mi_execute_command_wrapper (tmp);
c1043fc2 183 return exception_none;
4a8f6654
AC
184}
185
186/* Never display the default gdb prompt in mi case. */
187static int
188mi_interpreter_prompt_p (void *data)
189{
190 return 0;
191}
192
ce8f13f8 193void
4a8f6654
AC
194mi_cmd_interpreter_exec (char *command, char **argv, int argc)
195{
196 struct interp *interp_to_use;
4a8f6654 197 int i;
a13e061a
PA
198 char *mi_error_message = NULL;
199 struct cleanup *old_chain;
4a8f6654
AC
200
201 if (argc < 2)
1b05df00 202 error (_("-interpreter-exec: "
9b20d036 203 "Usage: -interpreter-exec interp command"));
4a8f6654
AC
204
205 interp_to_use = interp_lookup (argv[0]);
206 if (interp_to_use == NULL)
1b05df00 207 error (_("-interpreter-exec: could not find interpreter \"%s\""),
9a2b4c1b 208 argv[0]);
4a8f6654
AC
209
210 if (!interp_exec_p (interp_to_use))
1b05df00 211 error (_("-interpreter-exec: interpreter \"%s\" "
9b20d036 212 "does not support command execution"),
a13e061a 213 argv[0]);
4a8f6654
AC
214
215 /* Insert the MI out hooks, making sure to also call the interpreter's hooks
216 if it has any. */
217 /* KRS: We shouldn't need this... Events should be installed and they should
218 just ALWAYS fire something out down the MI channel... */
219 mi_insert_notify_hooks ();
220
221 /* Now run the code... */
222
a13e061a 223 old_chain = make_cleanup (null_cleanup, 0);
4a8f6654
AC
224 for (i = 1; i < argc; i++)
225 {
32c1e744 226 struct gdb_exception e = interp_exec (interp_to_use, argv[i]);
102040f0 227
32c1e744
VP
228 if (e.reason < 0)
229 {
230 mi_error_message = xstrdup (e.message);
a13e061a 231 make_cleanup (xfree, mi_error_message);
32c1e744
VP
232 break;
233 }
4a8f6654
AC
234 }
235
236 mi_remove_notify_hooks ();
237
a13e061a
PA
238 if (mi_error_message != NULL)
239 error ("%s", mi_error_message);
240 do_cleanups (old_chain);
4a8f6654
AC
241}
242
243/*
9a2b4c1b
MS
244 * mi_insert_notify_hooks - This inserts a number of hooks that are
245 * meant to produce async-notify ("=") MI messages while running
246 * commands in another interpreter using mi_interpreter_exec. The
247 * canonical use for this is to allow access to the gdb CLI
248 * interpreter from within the MI, while still producing MI style
249 * output when actions in the CLI command change gdb's state.
4a8f6654
AC
250*/
251
252static void
253mi_insert_notify_hooks (void)
254{
9a4105ab 255 deprecated_query_hook = mi_interp_query_hook;
4a8f6654
AC
256}
257
258static void
11308a41 259mi_remove_notify_hooks (void)
4a8f6654 260{
9a4105ab 261 deprecated_query_hook = NULL;
4a8f6654
AC
262}
263
264static int
265mi_interp_query_hook (const char *ctlstr, va_list ap)
266{
267 return 1;
268}
269
4a8f6654
AC
270static void
271mi_execute_command_wrapper (char *cmd)
272{
273 mi_execute_command (cmd, stdin == instream);
274}
275
276static void
277mi1_command_loop (void)
278{
279 mi_command_loop (1);
280}
281
282static void
283mi2_command_loop (void)
284{
285 mi_command_loop (2);
286}
287
f786f615
AC
288static void
289mi3_command_loop (void)
290{
291 mi_command_loop (3);
292}
293
4a8f6654
AC
294static void
295mi_command_loop (int mi_version)
296{
4a8f6654
AC
297 /* Turn off 8 bit strings in quoted output. Any character with the
298 high bit set is printed using C's octal format. */
299 sevenbit_strings = 1;
300 /* Tell the world that we're alive */
301 fputs_unfiltered ("(gdb) \n", raw_stdout);
302 gdb_flush (raw_stdout);
362646f5 303 start_event_loop ();
4a8f6654
AC
304}
305
683f2885
VP
306static void
307mi_new_thread (struct thread_info *t)
308{
309 struct mi_interp *mi = top_level_interpreter_data ();
a79b8f6e
VP
310 struct inferior *inf = find_inferior_pid (ptid_get_pid (t->ptid));
311
312 gdb_assert (inf);
683f2885 313
3d043ef6 314 fprintf_unfiltered (mi->event_channel,
a79b8f6e
VP
315 "thread-created,id=\"%d\",group-id=\"i%d\"",
316 t->num, inf->num);
683f2885
VP
317 gdb_flush (mi->event_channel);
318}
319
063bfe2e 320static void
a07daef3 321mi_thread_exit (struct thread_info *t, int silent)
063bfe2e 322{
a07daef3 323 struct mi_interp *mi;
a79b8f6e 324 struct inferior *inf;
a07daef3
PA
325
326 if (silent)
327 return;
328
a79b8f6e
VP
329 inf = find_inferior_pid (ptid_get_pid (t->ptid));
330
a07daef3 331 mi = top_level_interpreter_data ();
063bfe2e 332 target_terminal_ours ();
3d043ef6 333 fprintf_unfiltered (mi->event_channel,
a79b8f6e
VP
334 "thread-exited,id=\"%d\",group-id=\"i%d\"",
335 t->num, inf->num);
063bfe2e
VP
336 gdb_flush (mi->event_channel);
337}
338
a79b8f6e
VP
339static void
340mi_inferior_added (struct inferior *inf)
341{
342 struct mi_interp *mi = top_level_interpreter_data ();
102040f0 343
a79b8f6e
VP
344 target_terminal_ours ();
345 fprintf_unfiltered (mi->event_channel,
346 "thread-group-added,id=\"i%d\"",
347 inf->num);
348 gdb_flush (mi->event_channel);
349}
350
351static void
352mi_inferior_appeared (struct inferior *inf)
4a92f99b
VP
353{
354 struct mi_interp *mi = top_level_interpreter_data ();
102040f0 355
4a92f99b 356 target_terminal_ours ();
a79b8f6e
VP
357 fprintf_unfiltered (mi->event_channel,
358 "thread-group-started,id=\"i%d\",pid=\"%d\"",
359 inf->num, inf->pid);
4a92f99b
VP
360 gdb_flush (mi->event_channel);
361}
362
363static void
a79b8f6e 364mi_inferior_exit (struct inferior *inf)
4a92f99b
VP
365{
366 struct mi_interp *mi = top_level_interpreter_data ();
102040f0 367
4a92f99b 368 target_terminal_ours ();
a79b8f6e
VP
369 fprintf_unfiltered (mi->event_channel, "thread-group-exited,id=\"i%d\"",
370 inf->num);
4a92f99b
VP
371 gdb_flush (mi->event_channel);
372}
373
a79b8f6e
VP
374static void
375mi_inferior_removed (struct inferior *inf)
376{
377 struct mi_interp *mi = top_level_interpreter_data ();
102040f0 378
a79b8f6e
VP
379 target_terminal_ours ();
380 fprintf_unfiltered (mi->event_channel,
381 "thread-group-removed,id=\"i%d\"",
382 inf->num);
383 gdb_flush (mi->event_channel);
384}
385
f7f9a841 386static void
1d33d6ba 387mi_on_normal_stop (struct bpstats *bs, int print_frame)
f7f9a841
VP
388{
389 /* Since this can be called when CLI command is executing,
390 using cli interpreter, be sure to use MI uiout for output,
391 not the current one. */
1d33d6ba 392 struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ());
f7f9a841 393
1d33d6ba
VP
394 if (print_frame)
395 {
dc146f7c 396 int core;
102040f0 397
1d33d6ba
VP
398 if (uiout != mi_uiout)
399 {
400 /* The normal_stop function has printed frame information into
401 CLI uiout, or some other non-MI uiout. There's no way we
402 can extract proper fields from random uiout object, so we print
403 the frame again. In practice, this can only happen when running
404 a CLI command in MI. */
405 struct ui_out *saved_uiout = uiout;
102040f0 406
1d33d6ba
VP
407 uiout = mi_uiout;
408 print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC);
409 uiout = saved_uiout;
410 }
411
412 ui_out_field_int (mi_uiout, "thread-id",
413 pid_to_thread_id (inferior_ptid));
414 if (non_stop)
415 {
416 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end
417 (mi_uiout, "stopped-threads");
102040f0 418
1d33d6ba 419 ui_out_field_int (mi_uiout, NULL,
102040f0 420 pid_to_thread_id (inferior_ptid));
1d33d6ba
VP
421 do_cleanups (back_to);
422 }
423 else
424 ui_out_field_string (mi_uiout, "stopped-threads", "all");
dc146f7c
VP
425
426 core = target_core_of_thread (inferior_ptid);
427 if (core != -1)
428 ui_out_field_int (mi_uiout, "core", core);
1d33d6ba
VP
429 }
430
f7f9a841 431 fputs_unfiltered ("*stopped", raw_stdout);
1d33d6ba
VP
432 mi_out_put (mi_uiout, raw_stdout);
433 mi_out_rewind (mi_uiout);
4333ada3 434 mi_print_timing_maybe ();
f7f9a841
VP
435 fputs_unfiltered ("\n", raw_stdout);
436 gdb_flush (raw_stdout);
437}
438
f3b1572e
PA
439static void
440mi_about_to_proceed (void)
441{
442 /* Suppress output while calling an inferior function. */
443
444 if (!ptid_equal (inferior_ptid, null_ptid))
445 {
446 struct thread_info *tp = inferior_thread ();
102040f0 447
16c381f0 448 if (tp->control.in_infcall)
f3b1572e
PA
449 return;
450 }
451
452 mi_proceeded = 1;
453}
454
8d3788bd
VP
455/* When non-zero, no MI notifications will be emitted in
456 response to breakpoint change observers. */
457int mi_suppress_breakpoint_notifications = 0;
458
459/* Emit notification about a created breakpoint. */
460static void
461mi_breakpoint_created (struct breakpoint *b)
462{
463 struct mi_interp *mi = top_level_interpreter_data ();
464 struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ());
465 struct gdb_exception e;
466
467 if (mi_suppress_breakpoint_notifications)
468 return;
469
470 if (b->number <= 0)
471 return;
472
473 target_terminal_ours ();
474 fprintf_unfiltered (mi->event_channel,
475 "breakpoint-created");
476 /* We want the output from gdb_breakpoint_query to go to
477 mi->event_channel. One approach would be to just
478 call gdb_breakpoint_query, and then use mi_out_put to
479 send the current content of mi_outout into mi->event_channel.
480 However, that will break if anything is output to mi_uiout
481 prior the calling the breakpoint_created notifications.
482 So, we use ui_out_redirect. */
483 ui_out_redirect (mi_uiout, mi->event_channel);
484 TRY_CATCH (e, RETURN_MASK_ERROR)
485 gdb_breakpoint_query (mi_uiout, b->number, NULL);
486 ui_out_redirect (mi_uiout, NULL);
487
488 gdb_flush (mi->event_channel);
489}
490
491/* Emit notification about deleted breakpoint. */
492static void
493mi_breakpoint_deleted (struct breakpoint *b)
494{
495 struct mi_interp *mi = top_level_interpreter_data ();
496
497 if (mi_suppress_breakpoint_notifications)
498 return;
499
500 if (b->number <= 0)
501 return;
502
503 target_terminal_ours ();
504
505 fprintf_unfiltered (mi->event_channel, "breakpoint-deleted,id=\"%d\"",
506 b->number);
507
508 gdb_flush (mi->event_channel);
509}
510
511/* Emit notification about modified breakpoint. */
512static void
513mi_breakpoint_modified (struct breakpoint *b)
514{
515 struct mi_interp *mi = top_level_interpreter_data ();
516 struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ());
517 struct gdb_exception e;
518
519 if (mi_suppress_breakpoint_notifications)
520 return;
521
522 if (b->number <= 0)
523 return;
524
525 target_terminal_ours ();
526 fprintf_unfiltered (mi->event_channel,
527 "breakpoint-modified");
528 /* We want the output from gdb_breakpoint_query to go to
529 mi->event_channel. One approach would be to just
530 call gdb_breakpoint_query, and then use mi_out_put to
531 send the current content of mi_outout into mi->event_channel.
532 However, that will break if anything is output to mi_uiout
533 prior the calling the breakpoint_created notifications.
534 So, we use ui_out_redirect. */
535 ui_out_redirect (mi_uiout, mi->event_channel);
536 TRY_CATCH (e, RETURN_MASK_ERROR)
537 gdb_breakpoint_query (mi_uiout, b->number, NULL);
538 ui_out_redirect (mi_uiout, NULL);
539
540 gdb_flush (mi->event_channel);
541}
542
543
d90e17a7
PA
544static int
545mi_output_running_pid (struct thread_info *info, void *arg)
546{
547 ptid_t *ptid = arg;
548
549 if (ptid_get_pid (*ptid) == ptid_get_pid (info->ptid))
550 fprintf_unfiltered (raw_stdout,
551 "*running,thread-id=\"%d\"\n",
552 info->num);
553
554 return 0;
555}
556
557static int
558mi_inferior_count (struct inferior *inf, void *arg)
559{
560 if (inf->pid != 0)
561 {
562 int *count_p = arg;
563 (*count_p)++;
564 }
565
566 return 0;
567}
568
e1ac3328
VP
569static void
570mi_on_resume (ptid_t ptid)
571{
c5a4d20b
PA
572 struct thread_info *tp = NULL;
573
9944e9c2 574 if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
c5a4d20b
PA
575 tp = inferior_thread ();
576 else
e09875d4 577 tp = find_thread_ptid (ptid);
c5a4d20b
PA
578
579 /* Suppress output while calling an inferior function. */
16c381f0 580 if (tp->control.in_infcall)
c5a4d20b
PA
581 return;
582
a2840c35
VP
583 /* To cater for older frontends, emit ^running, but do it only once
584 per each command. We do it here, since at this point we know
585 that the target was successfully resumed, and in non-async mode,
586 we won't return back to MI interpreter code until the target
587 is done running, so delaying the output of "^running" until then
588 will make it impossible for frontend to know what's going on.
589
590 In future (MI3), we'll be outputting "^done" here. */
f3b1572e 591 if (!running_result_record_printed && mi_proceeded)
a2840c35 592 {
c271b6e2
VP
593 fprintf_unfiltered (raw_stdout, "%s^running\n",
594 current_token ? current_token : "");
a2840c35
VP
595 }
596
e1ac3328
VP
597 if (PIDGET (ptid) == -1)
598 fprintf_unfiltered (raw_stdout, "*running,thread-id=\"all\"\n");
d90e17a7 599 else if (ptid_is_pid (ptid))
bb599c81 600 {
ab730e72 601 int count = 0;
d90e17a7
PA
602
603 /* Backwards compatibility. If there's only one inferior,
604 output "all", otherwise, output each resumed thread
605 individually. */
606 iterate_over_inferiors (mi_inferior_count, &count);
607
608 if (count == 1)
609 fprintf_unfiltered (raw_stdout, "*running,thread-id=\"all\"\n");
610 else
611 iterate_over_threads (mi_output_running_pid, &ptid);
bb599c81 612 }
e1ac3328
VP
613 else
614 {
e09875d4 615 struct thread_info *ti = find_thread_ptid (ptid);
102040f0 616
e1ac3328
VP
617 gdb_assert (ti);
618 fprintf_unfiltered (raw_stdout, "*running,thread-id=\"%d\"\n", ti->num);
619 }
a2840c35 620
f3b1572e 621 if (!running_result_record_printed && mi_proceeded)
a2840c35
VP
622 {
623 running_result_record_printed = 1;
624 /* This is what gdb used to do historically -- printing prompt even if
625 it cannot actually accept any input. This will be surely removed
626 for MI3, and may be removed even earler. */
627 /* FIXME: review the use of target_is_async_p here -- is that
628 what we want? */
629 if (!target_is_async_p ())
630 fputs_unfiltered ("(gdb) \n", raw_stdout);
631 }
c1828f25 632 gdb_flush (raw_stdout);
e1ac3328
VP
633}
634
c86cf029
VP
635static void
636mi_solib_loaded (struct so_list *solib)
637{
638 struct mi_interp *mi = top_level_interpreter_data ();
102040f0 639
c86cf029 640 target_terminal_ours ();
a79b8f6e
VP
641 if (gdbarch_has_global_solist (target_gdbarch))
642 fprintf_unfiltered (mi->event_channel,
643 "library-loaded,id=\"%s\",target-name=\"%s\","
644 "host-name=\"%s\",symbols-loaded=\"%d\"",
645 solib->so_original_name, solib->so_original_name,
646 solib->so_name, solib->symbols_loaded);
647 else
648 fprintf_unfiltered (mi->event_channel,
649 "library-loaded,id=\"%s\",target-name=\"%s\","
650 "host-name=\"%s\",symbols-loaded=\"%d\","
651 "thread-group=\"i%d\"",
652 solib->so_original_name, solib->so_original_name,
653 solib->so_name, solib->symbols_loaded,
654 current_inferior ()->num);
655
c86cf029
VP
656 gdb_flush (mi->event_channel);
657}
658
659static void
660mi_solib_unloaded (struct so_list *solib)
661{
662 struct mi_interp *mi = top_level_interpreter_data ();
102040f0 663
c86cf029 664 target_terminal_ours ();
a79b8f6e
VP
665 if (gdbarch_has_global_solist (target_gdbarch))
666 fprintf_unfiltered (mi->event_channel,
667 "library-unloaded,id=\"%s\",target-name=\"%s\","
668 "host-name=\"%s\"",
669 solib->so_original_name, solib->so_original_name,
670 solib->so_name);
671 else
672 fprintf_unfiltered (mi->event_channel,
673 "library-unloaded,id=\"%s\",target-name=\"%s\","
674 "host-name=\"%s\",thread-group=\"i%d\"",
675 solib->so_original_name, solib->so_original_name,
676 solib->so_name, current_inferior ()->num);
677
c86cf029
VP
678 gdb_flush (mi->event_channel);
679}
680
a79b8f6e
VP
681static int
682report_initial_inferior (struct inferior *inf, void *closure)
683{
684 /* This function is called from mi_intepreter_init, and since
685 mi_inferior_added assumes that inferior is fully initialized
686 and top_level_interpreter_data is set, we cannot call
687 it here. */
688 struct mi_interp *mi = closure;
102040f0 689
a79b8f6e
VP
690 target_terminal_ours ();
691 fprintf_unfiltered (mi->event_channel,
692 "thread-group-added,id=\"i%d\"",
693 inf->num);
694 gdb_flush (mi->event_channel);
695 return 0;
696}
c86cf029 697
b9362cc7
AC
698extern initialize_file_ftype _initialize_mi_interp; /* -Wmissing-prototypes */
699
4a8f6654
AC
700void
701_initialize_mi_interp (void)
702{
703 static const struct interp_procs procs =
704 {
705 mi_interpreter_init, /* init_proc */
706 mi_interpreter_resume, /* resume_proc */
707 mi_interpreter_suspend, /* suspend_proc */
708 mi_interpreter_exec, /* exec_proc */
709 mi_interpreter_prompt_p /* prompt_proc_p */
710 };
711
2fcf52f0 712 /* The various interpreter levels. */
4a8f6654 713 interp_add (interp_new (INTERP_MI1, NULL, mi_out_new (1), &procs));
2fcf52f0
AC
714 interp_add (interp_new (INTERP_MI2, NULL, mi_out_new (2), &procs));
715 interp_add (interp_new (INTERP_MI3, NULL, mi_out_new (3), &procs));
4a8f6654 716
2fcf52f0
AC
717 /* "mi" selects the most recent released version. "mi2" was
718 released as part of GDB 6.0. */
719 interp_add (interp_new (INTERP_MI, NULL, mi_out_new (2), &procs));
4a8f6654 720}
This page took 0.751701 seconds and 4 git commands to generate.