PR remote/1966
[deliverable/binutils-gdb.git] / gdb / mi / mi-main.c
1 /* MI Command Set.
2
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
4 Foundation, Inc.
5
6 Contributed by Cygnus Solutions (a Red Hat company).
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
24
25 /* Work in progress */
26
27 #include "defs.h"
28 #include "target.h"
29 #include "inferior.h"
30 #include "gdb_string.h"
31 #include "exceptions.h"
32 #include "top.h"
33 #include "gdbthread.h"
34 #include "mi-cmds.h"
35 #include "mi-parse.h"
36 #include "mi-getopt.h"
37 #include "mi-console.h"
38 #include "ui-out.h"
39 #include "mi-out.h"
40 #include "interps.h"
41 #include "event-loop.h"
42 #include "event-top.h"
43 #include "gdbcore.h" /* for write_memory() */
44 #include "value.h" /* for deprecated_write_register_bytes() */
45 #include "regcache.h"
46 #include "gdb.h"
47 #include "frame.h"
48 #include "mi-main.h"
49
50 #include <ctype.h>
51 #include <sys/time.h>
52
53 enum
54 {
55 FROM_TTY = 0
56 };
57
58 /* Enumerations of the actions that may result from calling
59 captured_mi_execute_command */
60
61 enum captured_mi_execute_command_actions
62 {
63 EXECUTE_COMMAND_DISPLAY_PROMPT,
64 EXECUTE_COMMAND_SUPRESS_PROMPT
65 };
66
67 /* This structure is used to pass information from captured_mi_execute_command
68 to mi_execute_command. */
69 struct captured_mi_execute_command_args
70 {
71 /* This return result of the MI command (output) */
72 enum mi_cmd_result rc;
73
74 /* What action to perform when the call is finished (output) */
75 enum captured_mi_execute_command_actions action;
76
77 /* The command context to be executed (input) */
78 struct mi_parse *command;
79 };
80
81 int mi_debug_p;
82 struct ui_file *raw_stdout;
83
84 /* The token of the last asynchronous command */
85 static char *last_async_command;
86 static char *previous_async_command;
87 char *mi_error_message;
88 static char *old_regs;
89
90 extern void _initialize_mi_main (void);
91 static enum mi_cmd_result mi_cmd_execute (struct mi_parse *parse);
92
93 static void mi_execute_cli_command (const char *cmd, int args_p,
94 const char *args);
95 static enum mi_cmd_result mi_execute_async_cli_command (char *mi, char *args, int from_tty);
96
97 static void mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg);
98
99 static int register_changed_p (int regnum);
100 static int get_register (int regnum, int format);
101
102 /* Command implementations. FIXME: Is this libgdb? No. This is the MI
103 layer that calls libgdb. Any operation used in the below should be
104 formalized. */
105
106 enum mi_cmd_result
107 mi_cmd_gdb_exit (char *command, char **argv, int argc)
108 {
109 /* We have to print everything right here because we never return */
110 if (last_async_command)
111 fputs_unfiltered (last_async_command, raw_stdout);
112 fputs_unfiltered ("^exit\n", raw_stdout);
113 mi_out_put (uiout, raw_stdout);
114 /* FIXME: The function called is not yet a formal libgdb function */
115 quit_force (NULL, FROM_TTY);
116 return MI_CMD_DONE;
117 }
118
119 enum mi_cmd_result
120 mi_cmd_exec_run (char *args, int from_tty)
121 {
122 /* FIXME: Should call a libgdb function, not a cli wrapper */
123 return mi_execute_async_cli_command ("run", args, from_tty);
124 }
125
126 enum mi_cmd_result
127 mi_cmd_exec_next (char *args, int from_tty)
128 {
129 /* FIXME: Should call a libgdb function, not a cli wrapper */
130 return mi_execute_async_cli_command ("next", args, from_tty);
131 }
132
133 enum mi_cmd_result
134 mi_cmd_exec_next_instruction (char *args, int from_tty)
135 {
136 /* FIXME: Should call a libgdb function, not a cli wrapper */
137 return mi_execute_async_cli_command ("nexti", args, from_tty);
138 }
139
140 enum mi_cmd_result
141 mi_cmd_exec_step (char *args, int from_tty)
142 {
143 /* FIXME: Should call a libgdb function, not a cli wrapper */
144 return mi_execute_async_cli_command ("step", args, from_tty);
145 }
146
147 enum mi_cmd_result
148 mi_cmd_exec_step_instruction (char *args, int from_tty)
149 {
150 /* FIXME: Should call a libgdb function, not a cli wrapper */
151 return mi_execute_async_cli_command ("stepi", args, from_tty);
152 }
153
154 enum mi_cmd_result
155 mi_cmd_exec_finish (char *args, int from_tty)
156 {
157 /* FIXME: Should call a libgdb function, not a cli wrapper */
158 return mi_execute_async_cli_command ("finish", args, from_tty);
159 }
160
161 enum mi_cmd_result
162 mi_cmd_exec_until (char *args, int from_tty)
163 {
164 /* FIXME: Should call a libgdb function, not a cli wrapper */
165 return mi_execute_async_cli_command ("until", args, from_tty);
166 }
167
168 enum mi_cmd_result
169 mi_cmd_exec_return (char *args, int from_tty)
170 {
171 /* This command doesn't really execute the target, it just pops the
172 specified number of frames. */
173 if (*args)
174 /* Call return_command with from_tty argument equal to 0 so as to
175 avoid being queried. */
176 return_command (args, 0);
177 else
178 /* Call return_command with from_tty argument equal to 0 so as to
179 avoid being queried. */
180 return_command (NULL, 0);
181
182 /* Because we have called return_command with from_tty = 0, we need
183 to print the frame here. */
184 print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS);
185
186 return MI_CMD_DONE;
187 }
188
189 enum mi_cmd_result
190 mi_cmd_exec_continue (char *args, int from_tty)
191 {
192 /* FIXME: Should call a libgdb function, not a cli wrapper */
193 return mi_execute_async_cli_command ("continue", args, from_tty);
194 }
195
196 /* Interrupt the execution of the target. Note how we must play around
197 with the token varialbes, in order to display the current token in
198 the result of the interrupt command, and the previous execution
199 token when the target finally stops. See comments in
200 mi_cmd_execute. */
201 enum mi_cmd_result
202 mi_cmd_exec_interrupt (char *args, int from_tty)
203 {
204 if (!target_executing)
205 {
206 mi_error_message = xstrprintf ("mi_cmd_exec_interrupt: Inferior not executing.");
207 return MI_CMD_ERROR;
208 }
209 interrupt_target_command (args, from_tty);
210 if (last_async_command)
211 fputs_unfiltered (last_async_command, raw_stdout);
212 fputs_unfiltered ("^done", raw_stdout);
213 xfree (last_async_command);
214 if (previous_async_command)
215 last_async_command = xstrdup (previous_async_command);
216 xfree (previous_async_command);
217 previous_async_command = NULL;
218 mi_out_put (uiout, raw_stdout);
219 mi_out_rewind (uiout);
220 fputs_unfiltered ("\n", raw_stdout);
221 return MI_CMD_QUIET;
222 }
223
224 enum mi_cmd_result
225 mi_cmd_thread_select (char *command, char **argv, int argc)
226 {
227 enum gdb_rc rc;
228
229 if (argc != 1)
230 {
231 mi_error_message = xstrprintf ("mi_cmd_thread_select: USAGE: threadnum.");
232 return MI_CMD_ERROR;
233 }
234 else
235 rc = gdb_thread_select (uiout, argv[0], &mi_error_message);
236
237 /* RC is enum gdb_rc if it is successful (>=0)
238 enum return_reason if not (<0). */
239 if ((int) rc < 0 && (enum return_reason) rc == RETURN_ERROR)
240 return MI_CMD_ERROR;
241 else if ((int) rc >= 0 && rc == GDB_RC_FAIL)
242 return MI_CMD_ERROR;
243 else
244 return MI_CMD_DONE;
245 }
246
247 enum mi_cmd_result
248 mi_cmd_thread_list_ids (char *command, char **argv, int argc)
249 {
250 enum gdb_rc rc = MI_CMD_DONE;
251
252 if (argc != 0)
253 {
254 mi_error_message = xstrprintf ("mi_cmd_thread_list_ids: No arguments required.");
255 return MI_CMD_ERROR;
256 }
257 else
258 rc = gdb_list_thread_ids (uiout, &mi_error_message);
259
260 if (rc == GDB_RC_FAIL)
261 return MI_CMD_ERROR;
262 else
263 return MI_CMD_DONE;
264 }
265
266 enum mi_cmd_result
267 mi_cmd_data_list_register_names (char *command, char **argv, int argc)
268 {
269 int regnum, numregs;
270 int i;
271 struct cleanup *cleanup;
272
273 /* Note that the test for a valid register must include checking the
274 REGISTER_NAME because NUM_REGS may be allocated for the union of
275 the register sets within a family of related processors. In this
276 case, some entries of REGISTER_NAME will change depending upon
277 the particular processor being debugged. */
278
279 numregs = NUM_REGS + NUM_PSEUDO_REGS;
280
281 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-names");
282
283 if (argc == 0) /* No args, just do all the regs */
284 {
285 for (regnum = 0;
286 regnum < numregs;
287 regnum++)
288 {
289 if (REGISTER_NAME (regnum) == NULL
290 || *(REGISTER_NAME (regnum)) == '\0')
291 ui_out_field_string (uiout, NULL, "");
292 else
293 ui_out_field_string (uiout, NULL, REGISTER_NAME (regnum));
294 }
295 }
296
297 /* Else, list of register #s, just do listed regs */
298 for (i = 0; i < argc; i++)
299 {
300 regnum = atoi (argv[i]);
301 if (regnum < 0 || regnum >= numregs)
302 {
303 do_cleanups (cleanup);
304 mi_error_message = xstrprintf ("bad register number");
305 return MI_CMD_ERROR;
306 }
307 if (REGISTER_NAME (regnum) == NULL
308 || *(REGISTER_NAME (regnum)) == '\0')
309 ui_out_field_string (uiout, NULL, "");
310 else
311 ui_out_field_string (uiout, NULL, REGISTER_NAME (regnum));
312 }
313 do_cleanups (cleanup);
314 return MI_CMD_DONE;
315 }
316
317 enum mi_cmd_result
318 mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
319 {
320 int regnum, numregs, changed;
321 int i;
322 struct cleanup *cleanup;
323
324 /* Note that the test for a valid register must include checking the
325 REGISTER_NAME because NUM_REGS may be allocated for the union of
326 the register sets within a family of related processors. In this
327 case, some entries of REGISTER_NAME will change depending upon
328 the particular processor being debugged. */
329
330 numregs = NUM_REGS + NUM_PSEUDO_REGS;
331
332 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
333
334 if (argc == 0) /* No args, just do all the regs */
335 {
336 for (regnum = 0;
337 regnum < numregs;
338 regnum++)
339 {
340 if (REGISTER_NAME (regnum) == NULL
341 || *(REGISTER_NAME (regnum)) == '\0')
342 continue;
343 changed = register_changed_p (regnum);
344 if (changed < 0)
345 {
346 do_cleanups (cleanup);
347 mi_error_message = xstrprintf ("mi_cmd_data_list_changed_registers: Unable to read register contents.");
348 return MI_CMD_ERROR;
349 }
350 else if (changed)
351 ui_out_field_int (uiout, NULL, regnum);
352 }
353 }
354
355 /* Else, list of register #s, just do listed regs */
356 for (i = 0; i < argc; i++)
357 {
358 regnum = atoi (argv[i]);
359
360 if (regnum >= 0
361 && regnum < numregs
362 && REGISTER_NAME (regnum) != NULL
363 && *REGISTER_NAME (regnum) != '\000')
364 {
365 changed = register_changed_p (regnum);
366 if (changed < 0)
367 {
368 do_cleanups (cleanup);
369 mi_error_message = xstrprintf ("mi_cmd_data_list_register_change: Unable to read register contents.");
370 return MI_CMD_ERROR;
371 }
372 else if (changed)
373 ui_out_field_int (uiout, NULL, regnum);
374 }
375 else
376 {
377 do_cleanups (cleanup);
378 mi_error_message = xstrprintf ("bad register number");
379 return MI_CMD_ERROR;
380 }
381 }
382 do_cleanups (cleanup);
383 return MI_CMD_DONE;
384 }
385
386 static int
387 register_changed_p (int regnum)
388 {
389 gdb_byte raw_buffer[MAX_REGISTER_SIZE];
390
391 if (! frame_register_read (get_selected_frame (NULL), regnum, raw_buffer))
392 return -1;
393
394 if (memcmp (&old_regs[DEPRECATED_REGISTER_BYTE (regnum)], raw_buffer,
395 register_size (current_gdbarch, regnum)) == 0)
396 return 0;
397
398 /* Found a changed register. Return 1. */
399
400 memcpy (&old_regs[DEPRECATED_REGISTER_BYTE (regnum)], raw_buffer,
401 register_size (current_gdbarch, regnum));
402
403 return 1;
404 }
405
406 /* Return a list of register number and value pairs. The valid
407 arguments expected are: a letter indicating the format in which to
408 display the registers contents. This can be one of: x (hexadecimal), d
409 (decimal), N (natural), t (binary), o (octal), r (raw). After the
410 format argumetn there can be a sequence of numbers, indicating which
411 registers to fetch the content of. If the format is the only argument,
412 a list of all the registers with their values is returned. */
413 enum mi_cmd_result
414 mi_cmd_data_list_register_values (char *command, char **argv, int argc)
415 {
416 int regnum, numregs, format, result;
417 int i;
418 struct cleanup *list_cleanup, *tuple_cleanup;
419
420 /* Note that the test for a valid register must include checking the
421 REGISTER_NAME because NUM_REGS may be allocated for the union of
422 the register sets within a family of related processors. In this
423 case, some entries of REGISTER_NAME will change depending upon
424 the particular processor being debugged. */
425
426 numregs = NUM_REGS + NUM_PSEUDO_REGS;
427
428 if (argc == 0)
429 {
430 mi_error_message = xstrprintf ("mi_cmd_data_list_register_values: Usage: -data-list-register-values <format> [<regnum1>...<regnumN>]");
431 return MI_CMD_ERROR;
432 }
433
434 format = (int) argv[0][0];
435
436 list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-values");
437
438 if (argc == 1) /* No args, beside the format: do all the regs */
439 {
440 for (regnum = 0;
441 regnum < numregs;
442 regnum++)
443 {
444 if (REGISTER_NAME (regnum) == NULL
445 || *(REGISTER_NAME (regnum)) == '\0')
446 continue;
447 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
448 ui_out_field_int (uiout, "number", regnum);
449 result = get_register (regnum, format);
450 if (result == -1)
451 {
452 do_cleanups (list_cleanup);
453 return MI_CMD_ERROR;
454 }
455 do_cleanups (tuple_cleanup);
456 }
457 }
458
459 /* Else, list of register #s, just do listed regs */
460 for (i = 1; i < argc; i++)
461 {
462 regnum = atoi (argv[i]);
463
464 if (regnum >= 0
465 && regnum < numregs
466 && REGISTER_NAME (regnum) != NULL
467 && *REGISTER_NAME (regnum) != '\000')
468 {
469 tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
470 ui_out_field_int (uiout, "number", regnum);
471 result = get_register (regnum, format);
472 if (result == -1)
473 {
474 do_cleanups (list_cleanup);
475 return MI_CMD_ERROR;
476 }
477 do_cleanups (tuple_cleanup);
478 }
479 else
480 {
481 do_cleanups (list_cleanup);
482 mi_error_message = xstrprintf ("bad register number");
483 return MI_CMD_ERROR;
484 }
485 }
486 do_cleanups (list_cleanup);
487 return MI_CMD_DONE;
488 }
489
490 /* Output one register's contents in the desired format. */
491 static int
492 get_register (int regnum, int format)
493 {
494 gdb_byte buffer[MAX_REGISTER_SIZE];
495 int optim;
496 int realnum;
497 CORE_ADDR addr;
498 enum lval_type lval;
499 static struct ui_stream *stb = NULL;
500
501 stb = ui_out_stream_new (uiout);
502
503 if (format == 'N')
504 format = 0;
505
506 frame_register (get_selected_frame (NULL), regnum, &optim, &lval, &addr,
507 &realnum, buffer);
508
509 if (optim)
510 {
511 mi_error_message = xstrprintf ("Optimized out");
512 return -1;
513 }
514
515 if (format == 'r')
516 {
517 int j;
518 char *ptr, buf[1024];
519
520 strcpy (buf, "0x");
521 ptr = buf + 2;
522 for (j = 0; j < register_size (current_gdbarch, regnum); j++)
523 {
524 int idx = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? j
525 : register_size (current_gdbarch, regnum) - 1 - j;
526 sprintf (ptr, "%02x", (unsigned char) buffer[idx]);
527 ptr += 2;
528 }
529 ui_out_field_string (uiout, "value", buf);
530 /*fputs_filtered (buf, gdb_stdout); */
531 }
532 else
533 {
534 val_print (register_type (current_gdbarch, regnum), buffer, 0, 0,
535 stb->stream, format, 1, 0, Val_pretty_default);
536 ui_out_field_stream (uiout, "value", stb);
537 ui_out_stream_delete (stb);
538 }
539 return 1;
540 }
541
542 /* Write given values into registers. The registers and values are
543 given as pairs. The corresponding MI command is
544 -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]*/
545 enum mi_cmd_result
546 mi_cmd_data_write_register_values (char *command, char **argv, int argc)
547 {
548 int regnum;
549 int i;
550 int numregs;
551 LONGEST value;
552 char format;
553
554 /* Note that the test for a valid register must include checking the
555 REGISTER_NAME because NUM_REGS may be allocated for the union of
556 the register sets within a family of related processors. In this
557 case, some entries of REGISTER_NAME will change depending upon
558 the particular processor being debugged. */
559
560 numregs = NUM_REGS + NUM_PSEUDO_REGS;
561
562 if (argc == 0)
563 {
564 mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: Usage: -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]");
565 return MI_CMD_ERROR;
566 }
567
568 format = (int) argv[0][0];
569
570 if (!target_has_registers)
571 {
572 mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: No registers.");
573 return MI_CMD_ERROR;
574 }
575
576 if (!(argc - 1))
577 {
578 mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: No regs and values specified.");
579 return MI_CMD_ERROR;
580 }
581
582 if ((argc - 1) % 2)
583 {
584 mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: Regs and vals are not in pairs.");
585 return MI_CMD_ERROR;
586 }
587
588 for (i = 1; i < argc; i = i + 2)
589 {
590 regnum = atoi (argv[i]);
591
592 if (regnum >= 0
593 && regnum < numregs
594 && REGISTER_NAME (regnum) != NULL
595 && *REGISTER_NAME (regnum) != '\000')
596 {
597 void *buffer;
598 struct cleanup *old_chain;
599
600 /* Get the value as a number */
601 value = parse_and_eval_address (argv[i + 1]);
602 /* Get the value into an array */
603 buffer = xmalloc (DEPRECATED_REGISTER_SIZE);
604 old_chain = make_cleanup (xfree, buffer);
605 store_signed_integer (buffer, DEPRECATED_REGISTER_SIZE, value);
606 /* Write it down */
607 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (regnum), buffer, register_size (current_gdbarch, regnum));
608 /* Free the buffer. */
609 do_cleanups (old_chain);
610 }
611 else
612 {
613 mi_error_message = xstrprintf ("bad register number");
614 return MI_CMD_ERROR;
615 }
616 }
617 return MI_CMD_DONE;
618 }
619
620 #if 0
621 /*This is commented out because we decided it was not useful. I leave
622 it, just in case. ezannoni:1999-12-08 */
623
624 /* Assign a value to a variable. The expression argument must be in
625 the form A=2 or "A = 2" (I.e. if there are spaces it needs to be
626 quoted. */
627 enum mi_cmd_result
628 mi_cmd_data_assign (char *command, char **argv, int argc)
629 {
630 struct expression *expr;
631 struct cleanup *old_chain;
632
633 if (argc != 1)
634 {
635 mi_error_message = xstrprintf ("mi_cmd_data_assign: Usage: -data-assign expression");
636 return MI_CMD_ERROR;
637 }
638
639 /* NOTE what follows is a clone of set_command(). FIXME: ezannoni
640 01-12-1999: Need to decide what to do with this for libgdb purposes. */
641
642 expr = parse_expression (argv[0]);
643 old_chain = make_cleanup (free_current_contents, &expr);
644 evaluate_expression (expr);
645 do_cleanups (old_chain);
646 return MI_CMD_DONE;
647 }
648 #endif
649
650 /* Evaluate the value of the argument. The argument is an
651 expression. If the expression contains spaces it needs to be
652 included in double quotes. */
653 enum mi_cmd_result
654 mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
655 {
656 struct expression *expr;
657 struct cleanup *old_chain = NULL;
658 struct value *val;
659 struct ui_stream *stb = NULL;
660
661 stb = ui_out_stream_new (uiout);
662
663 if (argc != 1)
664 {
665 mi_error_message = xstrprintf ("mi_cmd_data_evaluate_expression: Usage: -data-evaluate-expression expression");
666 return MI_CMD_ERROR;
667 }
668
669 expr = parse_expression (argv[0]);
670
671 old_chain = make_cleanup (free_current_contents, &expr);
672
673 val = evaluate_expression (expr);
674
675 /* Print the result of the expression evaluation. */
676 val_print (value_type (val), value_contents (val),
677 value_embedded_offset (val), VALUE_ADDRESS (val),
678 stb->stream, 0, 0, 0, 0);
679
680 ui_out_field_stream (uiout, "value", stb);
681 ui_out_stream_delete (stb);
682
683 do_cleanups (old_chain);
684
685 return MI_CMD_DONE;
686 }
687
688 enum mi_cmd_result
689 mi_cmd_target_download (char *args, int from_tty)
690 {
691 char *run;
692 struct cleanup *old_cleanups = NULL;
693
694 run = xstrprintf ("load %s", args);
695 old_cleanups = make_cleanup (xfree, run);
696 execute_command (run, from_tty);
697
698 do_cleanups (old_cleanups);
699 return MI_CMD_DONE;
700 }
701
702 /* Connect to the remote target. */
703 enum mi_cmd_result
704 mi_cmd_target_select (char *args, int from_tty)
705 {
706 char *run;
707 struct cleanup *old_cleanups = NULL;
708
709 run = xstrprintf ("target %s", args);
710 old_cleanups = make_cleanup (xfree, run);
711
712 /* target-select is always synchronous. once the call has returned
713 we know that we are connected. */
714 /* NOTE: At present all targets that are connected are also
715 (implicitly) talking to a halted target. In the future this may
716 change. */
717 execute_command (run, from_tty);
718
719 do_cleanups (old_cleanups);
720
721 /* Issue the completion message here. */
722 if (last_async_command)
723 fputs_unfiltered (last_async_command, raw_stdout);
724 fputs_unfiltered ("^connected", raw_stdout);
725 mi_out_put (uiout, raw_stdout);
726 mi_out_rewind (uiout);
727 fputs_unfiltered ("\n", raw_stdout);
728 do_exec_cleanups (ALL_CLEANUPS);
729 return MI_CMD_QUIET;
730 }
731
732 /* DATA-MEMORY-READ:
733
734 ADDR: start address of data to be dumped.
735 WORD-FORMAT: a char indicating format for the ``word''. See
736 the ``x'' command.
737 WORD-SIZE: size of each ``word''; 1,2,4, or 8 bytes
738 NR_ROW: Number of rows.
739 NR_COL: The number of colums (words per row).
740 ASCHAR: (OPTIONAL) Append an ascii character dump to each row. Use
741 ASCHAR for unprintable characters.
742
743 Reads SIZE*NR_ROW*NR_COL bytes starting at ADDR from memory and
744 displayes them. Returns:
745
746 {addr="...",rowN={wordN="..." ,... [,ascii="..."]}, ...}
747
748 Returns:
749 The number of bytes read is SIZE*ROW*COL. */
750
751 enum mi_cmd_result
752 mi_cmd_data_read_memory (char *command, char **argv, int argc)
753 {
754 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
755 CORE_ADDR addr;
756 long total_bytes;
757 long nr_cols;
758 long nr_rows;
759 char word_format;
760 struct type *word_type;
761 long word_size;
762 char word_asize;
763 char aschar;
764 gdb_byte *mbuf;
765 int nr_bytes;
766 long offset = 0;
767 int optind = 0;
768 char *optarg;
769 enum opt
770 {
771 OFFSET_OPT
772 };
773 static struct mi_opt opts[] =
774 {
775 {"o", OFFSET_OPT, 1},
776 0
777 };
778
779 while (1)
780 {
781 int opt = mi_getopt ("mi_cmd_data_read_memory", argc, argv, opts,
782 &optind, &optarg);
783 if (opt < 0)
784 break;
785 switch ((enum opt) opt)
786 {
787 case OFFSET_OPT:
788 offset = atol (optarg);
789 break;
790 }
791 }
792 argv += optind;
793 argc -= optind;
794
795 if (argc < 5 || argc > 6)
796 {
797 mi_error_message = xstrprintf ("mi_cmd_data_read_memory: Usage: ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR].");
798 return MI_CMD_ERROR;
799 }
800
801 /* Extract all the arguments. */
802
803 /* Start address of the memory dump. */
804 addr = parse_and_eval_address (argv[0]) + offset;
805 /* The format character to use when displaying a memory word. See
806 the ``x'' command. */
807 word_format = argv[1][0];
808 /* The size of the memory word. */
809 word_size = atol (argv[2]);
810 switch (word_size)
811 {
812 case 1:
813 word_type = builtin_type_int8;
814 word_asize = 'b';
815 break;
816 case 2:
817 word_type = builtin_type_int16;
818 word_asize = 'h';
819 break;
820 case 4:
821 word_type = builtin_type_int32;
822 word_asize = 'w';
823 break;
824 case 8:
825 word_type = builtin_type_int64;
826 word_asize = 'g';
827 break;
828 default:
829 word_type = builtin_type_int8;
830 word_asize = 'b';
831 }
832 /* The number of rows */
833 nr_rows = atol (argv[3]);
834 if (nr_rows <= 0)
835 {
836 mi_error_message = xstrprintf ("mi_cmd_data_read_memory: invalid number of rows.");
837 return MI_CMD_ERROR;
838 }
839 /* number of bytes per row. */
840 nr_cols = atol (argv[4]);
841 if (nr_cols <= 0)
842 {
843 mi_error_message = xstrprintf ("mi_cmd_data_read_memory: invalid number of columns.");
844 return MI_CMD_ERROR;
845 }
846 /* The un-printable character when printing ascii. */
847 if (argc == 6)
848 aschar = *argv[5];
849 else
850 aschar = 0;
851
852 /* create a buffer and read it in. */
853 total_bytes = word_size * nr_rows * nr_cols;
854 mbuf = xcalloc (total_bytes, 1);
855 make_cleanup (xfree, mbuf);
856
857 nr_bytes = target_read (&current_target, TARGET_OBJECT_MEMORY, NULL,
858 mbuf, addr, total_bytes);
859 if (nr_bytes <= 0)
860 {
861 do_cleanups (cleanups);
862 mi_error_message = xstrdup ("Unable to read memory.");
863 return MI_CMD_ERROR;
864 }
865
866 /* output the header information. */
867 ui_out_field_core_addr (uiout, "addr", addr);
868 ui_out_field_int (uiout, "nr-bytes", nr_bytes);
869 ui_out_field_int (uiout, "total-bytes", total_bytes);
870 ui_out_field_core_addr (uiout, "next-row", addr + word_size * nr_cols);
871 ui_out_field_core_addr (uiout, "prev-row", addr - word_size * nr_cols);
872 ui_out_field_core_addr (uiout, "next-page", addr + total_bytes);
873 ui_out_field_core_addr (uiout, "prev-page", addr - total_bytes);
874
875 /* Build the result as a two dimentional table. */
876 {
877 struct ui_stream *stream = ui_out_stream_new (uiout);
878 struct cleanup *cleanup_list_memory;
879 int row;
880 int row_byte;
881 cleanup_list_memory = make_cleanup_ui_out_list_begin_end (uiout, "memory");
882 for (row = 0, row_byte = 0;
883 row < nr_rows;
884 row++, row_byte += nr_cols * word_size)
885 {
886 int col;
887 int col_byte;
888 struct cleanup *cleanup_tuple;
889 struct cleanup *cleanup_list_data;
890 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
891 ui_out_field_core_addr (uiout, "addr", addr + row_byte);
892 /* ui_out_field_core_addr_symbolic (uiout, "saddr", addr + row_byte); */
893 cleanup_list_data = make_cleanup_ui_out_list_begin_end (uiout, "data");
894 for (col = 0, col_byte = row_byte;
895 col < nr_cols;
896 col++, col_byte += word_size)
897 {
898 if (col_byte + word_size > nr_bytes)
899 {
900 ui_out_field_string (uiout, NULL, "N/A");
901 }
902 else
903 {
904 ui_file_rewind (stream->stream);
905 print_scalar_formatted (mbuf + col_byte, word_type, word_format,
906 word_asize, stream->stream);
907 ui_out_field_stream (uiout, NULL, stream);
908 }
909 }
910 do_cleanups (cleanup_list_data);
911 if (aschar)
912 {
913 int byte;
914 ui_file_rewind (stream->stream);
915 for (byte = row_byte; byte < row_byte + word_size * nr_cols; byte++)
916 {
917 if (byte >= nr_bytes)
918 {
919 fputc_unfiltered ('X', stream->stream);
920 }
921 else if (mbuf[byte] < 32 || mbuf[byte] > 126)
922 {
923 fputc_unfiltered (aschar, stream->stream);
924 }
925 else
926 fputc_unfiltered (mbuf[byte], stream->stream);
927 }
928 ui_out_field_stream (uiout, "ascii", stream);
929 }
930 do_cleanups (cleanup_tuple);
931 }
932 ui_out_stream_delete (stream);
933 do_cleanups (cleanup_list_memory);
934 }
935 do_cleanups (cleanups);
936 return MI_CMD_DONE;
937 }
938
939 /* DATA-MEMORY-WRITE:
940
941 COLUMN_OFFSET: optional argument. Must be preceeded by '-o'. The
942 offset from the beginning of the memory grid row where the cell to
943 be written is.
944 ADDR: start address of the row in the memory grid where the memory
945 cell is, if OFFSET_COLUMN is specified. Otherwise, the address of
946 the location to write to.
947 FORMAT: a char indicating format for the ``word''. See
948 the ``x'' command.
949 WORD_SIZE: size of each ``word''; 1,2,4, or 8 bytes
950 VALUE: value to be written into the memory address.
951
952 Writes VALUE into ADDR + (COLUMN_OFFSET * WORD_SIZE).
953
954 Prints nothing. */
955 enum mi_cmd_result
956 mi_cmd_data_write_memory (char *command, char **argv, int argc)
957 {
958 CORE_ADDR addr;
959 char word_format;
960 long word_size;
961 /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
962 enough when using a compiler other than GCC. */
963 LONGEST value;
964 void *buffer;
965 struct cleanup *old_chain;
966 long offset = 0;
967 int optind = 0;
968 char *optarg;
969 enum opt
970 {
971 OFFSET_OPT
972 };
973 static struct mi_opt opts[] =
974 {
975 {"o", OFFSET_OPT, 1},
976 0
977 };
978
979 while (1)
980 {
981 int opt = mi_getopt ("mi_cmd_data_write_memory", argc, argv, opts,
982 &optind, &optarg);
983 if (opt < 0)
984 break;
985 switch ((enum opt) opt)
986 {
987 case OFFSET_OPT:
988 offset = atol (optarg);
989 break;
990 }
991 }
992 argv += optind;
993 argc -= optind;
994
995 if (argc != 4)
996 {
997 mi_error_message = xstrprintf ("mi_cmd_data_write_memory: Usage: [-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE.");
998 return MI_CMD_ERROR;
999 }
1000
1001 /* Extract all the arguments. */
1002 /* Start address of the memory dump. */
1003 addr = parse_and_eval_address (argv[0]);
1004 /* The format character to use when displaying a memory word. See
1005 the ``x'' command. */
1006 word_format = argv[1][0];
1007 /* The size of the memory word. */
1008 word_size = atol (argv[2]);
1009
1010 /* Calculate the real address of the write destination. */
1011 addr += (offset * word_size);
1012
1013 /* Get the value as a number */
1014 value = parse_and_eval_address (argv[3]);
1015 /* Get the value into an array */
1016 buffer = xmalloc (word_size);
1017 old_chain = make_cleanup (xfree, buffer);
1018 store_signed_integer (buffer, word_size, value);
1019 /* Write it down to memory */
1020 write_memory (addr, buffer, word_size);
1021 /* Free the buffer. */
1022 do_cleanups (old_chain);
1023
1024 return MI_CMD_DONE;
1025 }
1026
1027 /* Execute a command within a safe environment.
1028 Return <0 for error; >=0 for ok.
1029
1030 args->action will tell mi_execute_command what action
1031 to perfrom after the given command has executed (display/supress
1032 prompt, display error). */
1033
1034 static void
1035 captured_mi_execute_command (struct ui_out *uiout, void *data)
1036 {
1037 struct captured_mi_execute_command_args *args =
1038 (struct captured_mi_execute_command_args *) data;
1039 struct mi_parse *context = args->command;
1040
1041 switch (context->op)
1042 {
1043
1044 case MI_COMMAND:
1045 /* A MI command was read from the input stream */
1046 if (mi_debug_p)
1047 /* FIXME: gdb_???? */
1048 fprintf_unfiltered (raw_stdout, " token=`%s' command=`%s' args=`%s'\n",
1049 context->token, context->command, context->args);
1050 /* FIXME: cagney/1999-09-25: Rather than this convoluted
1051 condition expression, each function should return an
1052 indication of what action is required and then switch on
1053 that. */
1054 args->action = EXECUTE_COMMAND_DISPLAY_PROMPT;
1055 args->rc = mi_cmd_execute (context);
1056
1057 if (!target_can_async_p () || !target_executing)
1058 {
1059 /* print the result if there were no errors
1060
1061 Remember that on the way out of executing a command, you have
1062 to directly use the mi_interp's uiout, since the command could
1063 have reset the interpreter, in which case the current uiout
1064 will most likely crash in the mi_out_* routines. */
1065 if (args->rc == MI_CMD_DONE)
1066 {
1067 fputs_unfiltered (context->token, raw_stdout);
1068 fputs_unfiltered ("^done", raw_stdout);
1069 mi_out_put (uiout, raw_stdout);
1070 mi_out_rewind (uiout);
1071 fputs_unfiltered ("\n", raw_stdout);
1072 }
1073 else if (args->rc == MI_CMD_ERROR)
1074 {
1075 if (mi_error_message)
1076 {
1077 fputs_unfiltered (context->token, raw_stdout);
1078 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1079 fputstr_unfiltered (mi_error_message, '"', raw_stdout);
1080 xfree (mi_error_message);
1081 fputs_unfiltered ("\"\n", raw_stdout);
1082 }
1083 mi_out_rewind (uiout);
1084 }
1085 else
1086 mi_out_rewind (uiout);
1087 }
1088 else if (sync_execution)
1089 {
1090 /* Don't print the prompt. We are executing the target in
1091 synchronous mode. */
1092 args->action = EXECUTE_COMMAND_SUPRESS_PROMPT;
1093 return;
1094 }
1095 break;
1096
1097 case CLI_COMMAND:
1098 {
1099 char *argv[2];
1100 /* A CLI command was read from the input stream. */
1101 /* This "feature" will be removed as soon as we have a
1102 complete set of mi commands. */
1103 /* Echo the command on the console. */
1104 fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
1105 /* Call the "console" interpreter. */
1106 argv[0] = "console";
1107 argv[1] = context->command;
1108 args->rc = mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
1109
1110 /* If we changed interpreters, DON'T print out anything. */
1111 if (current_interp_named_p (INTERP_MI)
1112 || current_interp_named_p (INTERP_MI1)
1113 || current_interp_named_p (INTERP_MI2)
1114 || current_interp_named_p (INTERP_MI3))
1115 {
1116 if (args->rc == MI_CMD_DONE)
1117 {
1118 fputs_unfiltered (context->token, raw_stdout);
1119 fputs_unfiltered ("^done", raw_stdout);
1120 mi_out_put (uiout, raw_stdout);
1121 mi_out_rewind (uiout);
1122 fputs_unfiltered ("\n", raw_stdout);
1123 args->action = EXECUTE_COMMAND_DISPLAY_PROMPT;
1124 }
1125 else if (args->rc == MI_CMD_ERROR)
1126 {
1127 if (mi_error_message)
1128 {
1129 fputs_unfiltered (context->token, raw_stdout);
1130 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1131 fputstr_unfiltered (mi_error_message, '"', raw_stdout);
1132 xfree (mi_error_message);
1133 fputs_unfiltered ("\"\n", raw_stdout);
1134 }
1135 mi_out_rewind (uiout);
1136 }
1137 else
1138 mi_out_rewind (uiout);
1139 }
1140 break;
1141 }
1142
1143 }
1144
1145 return;
1146 }
1147
1148
1149 void
1150 mi_execute_command (char *cmd, int from_tty)
1151 {
1152 struct mi_parse *command;
1153 struct captured_mi_execute_command_args args;
1154 struct ui_out *saved_uiout = uiout;
1155
1156 /* This is to handle EOF (^D). We just quit gdb. */
1157 /* FIXME: we should call some API function here. */
1158 if (cmd == 0)
1159 quit_force (NULL, from_tty);
1160
1161 command = mi_parse (cmd);
1162
1163 if (command != NULL)
1164 {
1165 struct gdb_exception result;
1166 /* FIXME: cagney/1999-11-04: Can this use of catch_exceptions either
1167 be pushed even further down or even eliminated? */
1168 args.command = command;
1169 result = catch_exception (uiout, captured_mi_execute_command, &args,
1170 RETURN_MASK_ALL);
1171 exception_print (gdb_stderr, result);
1172
1173 if (args.action == EXECUTE_COMMAND_SUPRESS_PROMPT)
1174 {
1175 /* The command is executing synchronously. Bail out early
1176 suppressing the finished prompt. */
1177 mi_parse_free (command);
1178 return;
1179 }
1180 if (result.reason < 0)
1181 {
1182 /* The command execution failed and error() was called
1183 somewhere. */
1184 fputs_unfiltered (command->token, raw_stdout);
1185 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1186 fputstr_unfiltered (result.message, '"', raw_stdout);
1187 fputs_unfiltered ("\"\n", raw_stdout);
1188 mi_out_rewind (uiout);
1189 }
1190 mi_parse_free (command);
1191 }
1192
1193 fputs_unfiltered ("(gdb) \n", raw_stdout);
1194 gdb_flush (raw_stdout);
1195 /* print any buffered hook code */
1196 /* ..... */
1197 }
1198
1199 static enum mi_cmd_result
1200 mi_cmd_execute (struct mi_parse *parse)
1201 {
1202 if (parse->cmd->argv_func != NULL
1203 || parse->cmd->args_func != NULL)
1204 {
1205 /* FIXME: We need to save the token because the command executed
1206 may be asynchronous and need to print the token again.
1207 In the future we can pass the token down to the func
1208 and get rid of the last_async_command */
1209 /* The problem here is to keep the token around when we launch
1210 the target, and we want to interrupt it later on. The
1211 interrupt command will have its own token, but when the
1212 target stops, we must display the token corresponding to the
1213 last execution command given. So we have another string where
1214 we copy the token (previous_async_command), if this was
1215 indeed the token of an execution command, and when we stop we
1216 print that one. This is possible because the interrupt
1217 command, when over, will copy that token back into the
1218 default token string (last_async_command). */
1219
1220 if (target_executing)
1221 {
1222 if (!previous_async_command)
1223 previous_async_command = xstrdup (last_async_command);
1224 if (strcmp (parse->command, "exec-interrupt"))
1225 {
1226 fputs_unfiltered (parse->token, raw_stdout);
1227 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1228 fputs_unfiltered ("Cannot execute command ", raw_stdout);
1229 fputstr_unfiltered (parse->command, '"', raw_stdout);
1230 fputs_unfiltered (" while target running", raw_stdout);
1231 fputs_unfiltered ("\"\n", raw_stdout);
1232 return MI_CMD_ERROR;
1233 }
1234 }
1235 last_async_command = xstrdup (parse->token);
1236 make_exec_cleanup (free_current_contents, &last_async_command);
1237 /* FIXME: DELETE THIS! */
1238 if (parse->cmd->args_func != NULL)
1239 return parse->cmd->args_func (parse->args, 0 /*from_tty */ );
1240 return parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
1241 }
1242 else if (parse->cmd->cli.cmd != 0)
1243 {
1244 /* FIXME: DELETE THIS. */
1245 /* The operation is still implemented by a cli command */
1246 /* Must be a synchronous one */
1247 mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
1248 parse->args);
1249 return MI_CMD_DONE;
1250 }
1251 else
1252 {
1253 /* FIXME: DELETE THIS. */
1254 fputs_unfiltered (parse->token, raw_stdout);
1255 fputs_unfiltered ("^error,msg=\"", raw_stdout);
1256 fputs_unfiltered ("Undefined mi command: ", raw_stdout);
1257 fputstr_unfiltered (parse->command, '"', raw_stdout);
1258 fputs_unfiltered (" (missing implementation)", raw_stdout);
1259 fputs_unfiltered ("\"\n", raw_stdout);
1260 return MI_CMD_ERROR;
1261 }
1262 }
1263
1264 /* FIXME: This is just a hack so we can get some extra commands going.
1265 We don't want to channel things through the CLI, but call libgdb directly */
1266 /* Use only for synchronous commands */
1267
1268 void
1269 mi_execute_cli_command (const char *cmd, int args_p, const char *args)
1270 {
1271 if (cmd != 0)
1272 {
1273 struct cleanup *old_cleanups;
1274 char *run;
1275 if (args_p)
1276 run = xstrprintf ("%s %s", cmd, args);
1277 else
1278 run = xstrdup (cmd);
1279 if (mi_debug_p)
1280 /* FIXME: gdb_???? */
1281 fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
1282 cmd, run);
1283 old_cleanups = make_cleanup (xfree, run);
1284 execute_command ( /*ui */ run, 0 /*from_tty */ );
1285 do_cleanups (old_cleanups);
1286 return;
1287 }
1288 }
1289
1290 enum mi_cmd_result
1291 mi_execute_async_cli_command (char *mi, char *args, int from_tty)
1292 {
1293 struct cleanup *old_cleanups;
1294 char *run;
1295 char *async_args;
1296
1297 if (target_can_async_p ())
1298 {
1299 async_args = (char *) xmalloc (strlen (args) + 2);
1300 make_exec_cleanup (free, async_args);
1301 strcpy (async_args, args);
1302 strcat (async_args, "&");
1303 run = xstrprintf ("%s %s", mi, async_args);
1304 make_exec_cleanup (free, run);
1305 add_continuation (mi_exec_async_cli_cmd_continuation, NULL);
1306 old_cleanups = NULL;
1307 }
1308 else
1309 {
1310 run = xstrprintf ("%s %s", mi, args);
1311 old_cleanups = make_cleanup (xfree, run);
1312 }
1313
1314 if (!target_can_async_p ())
1315 {
1316 /* NOTE: For synchronous targets asynchronous behavour is faked by
1317 printing out the GDB prompt before we even try to execute the
1318 command. */
1319 if (last_async_command)
1320 fputs_unfiltered (last_async_command, raw_stdout);
1321 fputs_unfiltered ("^running\n", raw_stdout);
1322 fputs_unfiltered ("(gdb) \n", raw_stdout);
1323 gdb_flush (raw_stdout);
1324 }
1325 else
1326 {
1327 /* FIXME: cagney/1999-11-29: Printing this message before
1328 calling execute_command is wrong. It should only be printed
1329 once gdb has confirmed that it really has managed to send a
1330 run command to the target. */
1331 if (last_async_command)
1332 fputs_unfiltered (last_async_command, raw_stdout);
1333 fputs_unfiltered ("^running\n", raw_stdout);
1334 }
1335
1336 execute_command ( /*ui */ run, 0 /*from_tty */ );
1337
1338 if (!target_can_async_p ())
1339 {
1340 /* Do this before doing any printing. It would appear that some
1341 print code leaves garbage around in the buffer. */
1342 do_cleanups (old_cleanups);
1343 /* If the target was doing the operation synchronously we fake
1344 the stopped message. */
1345 if (last_async_command)
1346 fputs_unfiltered (last_async_command, raw_stdout);
1347 fputs_unfiltered ("*stopped", raw_stdout);
1348 mi_out_put (uiout, raw_stdout);
1349 mi_out_rewind (uiout);
1350 fputs_unfiltered ("\n", raw_stdout);
1351 return MI_CMD_QUIET;
1352 }
1353 return MI_CMD_DONE;
1354 }
1355
1356 void
1357 mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg)
1358 {
1359 if (last_async_command)
1360 fputs_unfiltered (last_async_command, raw_stdout);
1361 fputs_unfiltered ("*stopped", raw_stdout);
1362 mi_out_put (uiout, raw_stdout);
1363 fputs_unfiltered ("\n", raw_stdout);
1364 fputs_unfiltered ("(gdb) \n", raw_stdout);
1365 gdb_flush (raw_stdout);
1366 do_exec_cleanups (ALL_CLEANUPS);
1367 }
1368
1369 void
1370 mi_load_progress (const char *section_name,
1371 unsigned long sent_so_far,
1372 unsigned long total_section,
1373 unsigned long total_sent,
1374 unsigned long grand_total)
1375 {
1376 struct timeval time_now, delta, update_threshold;
1377 static struct timeval last_update;
1378 static char *previous_sect_name = NULL;
1379 int new_section;
1380 struct ui_out *saved_uiout;
1381
1382 /* This function is called through deprecated_show_load_progress
1383 which means uiout may not be correct. Fix it for the duration
1384 of this function. */
1385 saved_uiout = uiout;
1386
1387 if (current_interp_named_p (INTERP_MI))
1388 uiout = mi_out_new (2);
1389 else if (current_interp_named_p (INTERP_MI1))
1390 uiout = mi_out_new (1);
1391 else
1392 return;
1393
1394 update_threshold.tv_sec = 0;
1395 update_threshold.tv_usec = 500000;
1396 gettimeofday (&time_now, NULL);
1397
1398 delta.tv_usec = time_now.tv_usec - last_update.tv_usec;
1399 delta.tv_sec = time_now.tv_sec - last_update.tv_sec;
1400
1401 if (delta.tv_usec < 0)
1402 {
1403 delta.tv_sec -= 1;
1404 delta.tv_usec += 1000000;
1405 }
1406
1407 new_section = (previous_sect_name ?
1408 strcmp (previous_sect_name, section_name) : 1);
1409 if (new_section)
1410 {
1411 struct cleanup *cleanup_tuple;
1412 xfree (previous_sect_name);
1413 previous_sect_name = xstrdup (section_name);
1414
1415 if (last_async_command)
1416 fputs_unfiltered (last_async_command, raw_stdout);
1417 fputs_unfiltered ("+download", raw_stdout);
1418 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1419 ui_out_field_string (uiout, "section", section_name);
1420 ui_out_field_int (uiout, "section-size", total_section);
1421 ui_out_field_int (uiout, "total-size", grand_total);
1422 do_cleanups (cleanup_tuple);
1423 mi_out_put (uiout, raw_stdout);
1424 fputs_unfiltered ("\n", raw_stdout);
1425 gdb_flush (raw_stdout);
1426 }
1427
1428 if (delta.tv_sec >= update_threshold.tv_sec &&
1429 delta.tv_usec >= update_threshold.tv_usec)
1430 {
1431 struct cleanup *cleanup_tuple;
1432 last_update.tv_sec = time_now.tv_sec;
1433 last_update.tv_usec = time_now.tv_usec;
1434 if (last_async_command)
1435 fputs_unfiltered (last_async_command, raw_stdout);
1436 fputs_unfiltered ("+download", raw_stdout);
1437 cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
1438 ui_out_field_string (uiout, "section", section_name);
1439 ui_out_field_int (uiout, "section-sent", sent_so_far);
1440 ui_out_field_int (uiout, "section-size", total_section);
1441 ui_out_field_int (uiout, "total-sent", total_sent);
1442 ui_out_field_int (uiout, "total-size", grand_total);
1443 do_cleanups (cleanup_tuple);
1444 mi_out_put (uiout, raw_stdout);
1445 fputs_unfiltered ("\n", raw_stdout);
1446 gdb_flush (raw_stdout);
1447 }
1448
1449 xfree (uiout);
1450 uiout = saved_uiout;
1451 }
1452
1453 void
1454 mi_setup_architecture_data (void)
1455 {
1456 old_regs = xmalloc ((NUM_REGS + NUM_PSEUDO_REGS) * MAX_REGISTER_SIZE + 1);
1457 memset (old_regs, 0, (NUM_REGS + NUM_PSEUDO_REGS) * MAX_REGISTER_SIZE + 1);
1458 }
1459
1460 void
1461 _initialize_mi_main (void)
1462 {
1463 DEPRECATED_REGISTER_GDBARCH_SWAP (old_regs);
1464 deprecated_register_gdbarch_swap (NULL, 0, mi_setup_architecture_data);
1465 }
This page took 0.058226 seconds and 4 git commands to generate.