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