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