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