GDB (xrefs)

cli-dump.c
Go to the documentation of this file.
1 /* Dump-to-file commands, for GDB, the GNU debugger.
2
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4
5 Contributed by Red Hat.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "cli/cli-decode.h"
24 #include "cli/cli-cmds.h"
25 #include "value.h"
26 #include "completer.h"
27 #include <ctype.h>
28 #include "target.h"
29 #include "readline/readline.h"
30 #include "gdbcore.h"
31 #include "cli/cli-utils.h"
32 #include "gdb_bfd.h"
33 #include "filestuff.h"
34 #include "common/byte-vector.h"
35
36 static gdb::unique_xmalloc_ptr<char>
37 scan_expression (const char **cmd, const char *def)
38 {
39 if ((*cmd) == NULL || (**cmd) == '\0')
40 return gdb::unique_xmalloc_ptr<char> (xstrdup (def));
41 else
42 {
43 char *exp;
44 const char *end;
45
46 end = (*cmd) + strcspn (*cmd, " \t");
47 exp = savestring ((*cmd), end - (*cmd));
48 (*cmd) = skip_spaces (end);
49 return gdb::unique_xmalloc_ptr<char> (exp);
50 }
51 }
52
53
54 static gdb::unique_xmalloc_ptr<char>
55 scan_filename (const char **cmd, const char *defname)
56 {
57 gdb::unique_xmalloc_ptr<char> filename;
58
59 /* FIXME: Need to get the ``/a(ppend)'' flag from somewhere. */
60
61 /* File. */
62 if ((*cmd) == NULL)
63 {
64 if (defname == NULL)
65 error (_("Missing filename."));
66 filename.reset (xstrdup (defname));
67 }
68 else
69 {
70 /* FIXME: should parse a possibly quoted string. */
71 const char *end;
72
73 (*cmd) = skip_spaces (*cmd);
74 end = *cmd + strcspn (*cmd, " \t");
75 filename.reset (savestring ((*cmd), end - (*cmd)));
76 (*cmd) = skip_spaces (end);
77 }
78 gdb_assert (filename != NULL);
79
80 return gdb::unique_xmalloc_ptr<char> (tilde_expand (filename.get ()));
81 }
82
83 static gdb_bfd_ref_ptr
84 bfd_openr_or_error (const char *filename, const char *target)
85 {
86 gdb_bfd_ref_ptr ibfd (gdb_bfd_openr (filename, target));
87 if (ibfd == NULL)
88 error (_("Failed to open %s: %s."), filename,
89 bfd_errmsg (bfd_get_error ()));
90
91 if (!bfd_check_format (ibfd.get (), bfd_object))
92 error (_("'%s' is not a recognized file format."), filename);
93
94 return ibfd;
95 }
96
97 static gdb_bfd_ref_ptr
98 bfd_openw_or_error (const char *filename, const char *target, const char *mode)
99 {
100 gdb_bfd_ref_ptr obfd;
101
102 if (*mode == 'w') /* Write: create new file */
103 {
104 obfd = gdb_bfd_openw (filename, target);
105 if (obfd == NULL)
106 error (_("Failed to open %s: %s."), filename,
107 bfd_errmsg (bfd_get_error ()));
108 if (!bfd_set_format (obfd.get (), bfd_object))
109 error (_("bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
110 }
111 else if (*mode == 'a') /* Append to existing file. */
112 { /* FIXME -- doesn't work... */
113 error (_("bfd_openw does not work with append."));
114 }
115 else
116 error (_("bfd_openw_or_error: unknown mode %s."), mode);
117
118 return obfd;
119 }
120
121 static struct cmd_list_element *dump_cmdlist;
122 static struct cmd_list_element *append_cmdlist;
123 static struct cmd_list_element *srec_cmdlist;
124 static struct cmd_list_element *ihex_cmdlist;
125 static struct cmd_list_element *verilog_cmdlist;
126 static struct cmd_list_element *tekhex_cmdlist;
127 static struct cmd_list_element *binary_dump_cmdlist;
128 static struct cmd_list_element *binary_append_cmdlist;
129
130 static void
131 dump_command (const char *cmd, int from_tty)
132 {
133 printf_unfiltered (_("\"dump\" must be followed by a subcommand.\n\n"));
134 help_list (dump_cmdlist, "dump ", all_commands, gdb_stdout);
135 }
136
137 static void
138 append_command (const char *cmd, int from_tty)
139 {
140 printf_unfiltered (_("\"append\" must be followed by a subcommand.\n\n"));
141 help_list (dump_cmdlist, "append ", all_commands, gdb_stdout);
142 }
143
144 static void
145 dump_binary_file (const char *filename, const char *mode,
146 const bfd_byte *buf, ULONGEST len)
147 {
148 int status;
149
150 gdb_file_up file = gdb_fopen_cloexec (filename, mode);
151 status = fwrite (buf, len, 1, file.get ());
152 if (status != 1)
153 perror_with_name (filename);
154 }
155
156 static void
157 dump_bfd_file (const char *filename, const char *mode,
158 const char *target, CORE_ADDR vaddr,
159 const bfd_byte *buf, ULONGEST len)
160 {
161 asection *osection;
162
163 gdb_bfd_ref_ptr obfd (bfd_openw_or_error (filename, target, mode));
164 osection = bfd_make_section_anyway (obfd.get (), ".newsec");
165 bfd_set_section_size (obfd.get (), osection, len);
166 bfd_set_section_vma (obfd.get (), osection, vaddr);
167 bfd_set_section_alignment (obfd.get (), osection, 0);
168 bfd_set_section_flags (obfd.get (), osection, (SEC_HAS_CONTENTS
169 | SEC_ALLOC
170 | SEC_LOAD));
171 osection->entsize = 0;
172 if (!bfd_set_section_contents (obfd.get (), osection, buf, 0, len))
173 warning (_("writing dump file '%s' (%s)"), filename,
174 bfd_errmsg (bfd_get_error ()));
175 }
176
177 static void
178 dump_memory_to_file (const char *cmd, const char *mode, const char *file_format)
179 {
180 CORE_ADDR lo;
181 CORE_ADDR hi;
182 ULONGEST count;
183 const char *hi_exp;
184
185 /* Open the file. */
186 gdb::unique_xmalloc_ptr<char> filename = scan_filename (&cmd, NULL);
187
188 /* Find the low address. */
189 if (cmd == NULL || *cmd == '\0')
190 error (_("Missing start address."));
191 gdb::unique_xmalloc_ptr<char> lo_exp = scan_expression (&cmd, NULL);
192
193 /* Find the second address - rest of line. */
194 if (cmd == NULL || *cmd == '\0')
195 error (_("Missing stop address."));
196 hi_exp = cmd;
197
198 lo = parse_and_eval_address (lo_exp.get ());
199 hi = parse_and_eval_address (hi_exp);
200 if (hi <= lo)
201 error (_("Invalid memory address range (start >= end)."));
202 count = hi - lo;
203
204 /* FIXME: Should use read_memory_partial() and a magic blocking
205 value. */
206 gdb::byte_vector buf (count);
207 read_memory (lo, buf.data (), count);
208
209 /* Have everything. Open/write the data. */
210 if (file_format == NULL || strcmp (file_format, "binary") == 0)
211 dump_binary_file (filename.get (), mode, buf.data (), count);
212 else
213 dump_bfd_file (filename.get (), mode, file_format, lo, buf.data (), count);
214 }
215
216 static void
217 dump_memory_command (const char *cmd, const char *mode)
218 {
219 dump_memory_to_file (cmd, mode, "binary");
220 }
221
222 static void
223 dump_value_to_file (const char *cmd, const char *mode, const char *file_format)
224 {
225 struct value *val;
226
227 /* Open the file. */
228 gdb::unique_xmalloc_ptr<char> filename = scan_filename (&cmd, NULL);
229
230 /* Find the value. */
231 if (cmd == NULL || *cmd == '\0')
232 error (_("No value to %s."), *mode == 'a' ? "append" : "dump");
233 val = parse_and_eval (cmd);
234 if (val == NULL)
235 error (_("Invalid expression."));
236
237 /* Have everything. Open/write the data. */
238 if (file_format == NULL || strcmp (file_format, "binary") == 0)
239 dump_binary_file (filename.get (), mode, value_contents (val),
240 TYPE_LENGTH (value_type (val)));
241 else
242 {
243 CORE_ADDR vaddr;
244
245 if (VALUE_LVAL (val))
246 {
247 vaddr = value_address (val);
248 }
249 else
250 {
251 vaddr = 0;
252 warning (_("value is not an lval: address assumed to be zero"));
253 }
254
255 dump_bfd_file (filename.get (), mode, file_format, vaddr,
256 value_contents (val),
257 TYPE_LENGTH (value_type (val)));
258 }
259 }
260
261 static void
262 dump_value_command (const char *cmd, const char *mode)
263 {
264 dump_value_to_file (cmd, mode, "binary");
265 }
266
267 static void
268 dump_srec_memory (const char *args, int from_tty)
269 {
270 dump_memory_to_file (args, FOPEN_WB, "srec");
271 }
272
273 static void
274 dump_srec_value (const char *args, int from_tty)
275 {
276 dump_value_to_file (args, FOPEN_WB, "srec");
277 }
278
279 static void
280 dump_ihex_memory (const char *args, int from_tty)
281 {
282 dump_memory_to_file (args, FOPEN_WB, "ihex");
283 }
284
285 static void
286 dump_ihex_value (const char *args, int from_tty)
287 {
288 dump_value_to_file (args, FOPEN_WB, "ihex");
289 }
290
291 static void
292 dump_verilog_memory (const char *args, int from_tty)
293 {
294 dump_memory_to_file (args, FOPEN_WB, "verilog");
295 }
296
297 static void
298 dump_verilog_value (const char *args, int from_tty)
299 {
300 dump_value_to_file (args, FOPEN_WB, "verilog");
301 }
302
303 static void
304 dump_tekhex_memory (const char *args, int from_tty)
305 {
306 dump_memory_to_file (args, FOPEN_WB, "tekhex");
307 }
308
309 static void
310 dump_tekhex_value (const char *args, int from_tty)
311 {
312 dump_value_to_file (args, FOPEN_WB, "tekhex");
313 }
314
315 static void
316 dump_binary_memory (const char *args, int from_tty)
317 {
318 dump_memory_to_file (args, FOPEN_WB, "binary");
319 }
320
321 static void
322 dump_binary_value (const char *args, int from_tty)
323 {
324 dump_value_to_file (args, FOPEN_WB, "binary");
325 }
326
327 static void
328 append_binary_memory (const char *args, int from_tty)
329 {
330 dump_memory_to_file (args, FOPEN_AB, "binary");
331 }
332
333 static void
334 append_binary_value (const char *args, int from_tty)
335 {
336 dump_value_to_file (args, FOPEN_AB, "binary");
337 }
338
339 struct dump_context
340 {
341 void (*func) (const char *cmd, const char *mode);
342 const char *mode;
343 };
344
345 static void
346 call_dump_func (struct cmd_list_element *c, const char *args, int from_tty)
347 {
348 struct dump_context *d = (struct dump_context *) get_cmd_context (c);
349
350 d->func (args, d->mode);
351 }
352
353 static void
354 add_dump_command (const char *name,
355 void (*func) (const char *args, const char *mode),
356 const char *descr)
357
358 {
359 struct cmd_list_element *c;
360 struct dump_context *d;
361
362 c = add_cmd (name, all_commands, descr, &dump_cmdlist);
363 c->completer = filename_completer;
364 d = XNEW (struct dump_context);
365 d->func = func;
366 d->mode = FOPEN_WB;
367 set_cmd_context (c, d);
368 c->func = call_dump_func;
369
370 c = add_cmd (name, all_commands, descr, &append_cmdlist);
371 c->completer = filename_completer;
372 d = XNEW (struct dump_context);
373 d->func = func;
374 d->mode = FOPEN_AB;
375 set_cmd_context (c, d);
376 c->func = call_dump_func;
377
378 /* Replace "Dump " at start of docstring with "Append " (borrowed
379 from [deleted] deprecated_add_show_from_set). */
380 if ( c->doc[0] == 'W'
381 && c->doc[1] == 'r'
382 && c->doc[2] == 'i'
383 && c->doc[3] == 't'
384 && c->doc[4] == 'e'
385 && c->doc[5] == ' ')
386 c->doc = concat ("Append ", c->doc + 6, (char *)NULL);
387 }
388
389 /* Opaque data for restore_section_callback. */
390 struct callback_data {
391 CORE_ADDR load_offset;
392 CORE_ADDR load_start;
393 CORE_ADDR load_end;
394 };
395
396 /* Function: restore_section_callback.
397
398 Callback function for bfd_map_over_sections.
399 Selectively loads the sections into memory. */
400
401 static void
402 restore_section_callback (bfd *ibfd, asection *isec, void *args)
403 {
404 struct callback_data *data = (struct callback_data *) args;
405 bfd_vma sec_start = bfd_section_vma (ibfd, isec);
406 bfd_size_type size = bfd_section_size (ibfd, isec);
407 bfd_vma sec_end = sec_start + size;
408 bfd_size_type sec_offset = 0;
409 bfd_size_type sec_load_count = size;
410 int ret;
411
412 /* Ignore non-loadable sections, eg. from elf files. */
413 if (!(bfd_get_section_flags (ibfd, isec) & SEC_LOAD))
414 return;
415
416 /* Does the section overlap with the desired restore range? */
417 if (sec_end <= data->load_start
418 || (data->load_end > 0 && sec_start >= data->load_end))
419 {
420 /* No, no useable data in this section. */
421 printf_filtered (_("skipping section %s...\n"),
422 bfd_section_name (ibfd, isec));
423 return;
424 }
425
426 /* Compare section address range with user-requested
427 address range (if any). Compute where the actual
428 transfer should start and end. */
429 if (sec_start < data->load_start)
430 sec_offset = data->load_start - sec_start;
431 /* Size of a partial transfer. */
432 sec_load_count -= sec_offset;
433 if (data->load_end > 0 && sec_end > data->load_end)
434 sec_load_count -= sec_end - data->load_end;
435
436 /* Get the data. */
437 gdb::byte_vector buf (size);
438 if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size))
439 error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
440 bfd_errmsg (bfd_get_error ()));
441
442 printf_filtered ("Restoring section %s (0x%lx to 0x%lx)",
443 bfd_section_name (ibfd, isec),
444 (unsigned long) sec_start,
445 (unsigned long) sec_end);
446
447 if (data->load_offset != 0 || data->load_start != 0 || data->load_end != 0)
448 printf_filtered (" into memory (%s to %s)\n",
449 paddress (target_gdbarch (),
450 (unsigned long) sec_start
451 + sec_offset + data->load_offset),
452 paddress (target_gdbarch (),
453 (unsigned long) sec_start + sec_offset
454 + data->load_offset + sec_load_count));
455 else
456 puts_filtered ("\n");
457
458 /* Write the data. */
459 ret = target_write_memory (sec_start + sec_offset + data->load_offset,
460 &buf[sec_offset], sec_load_count);
461 if (ret != 0)
462 warning (_("restore: memory write failed (%s)."), safe_strerror (ret));
463 }
464
465 static void
466 restore_binary_file (const char *filename, struct callback_data *data)
467 {
468 gdb_file_up file = gdb_fopen_cloexec (filename, FOPEN_RB);
469 long len;
470
471 /* Get the file size for reading. */
472 if (fseek (file.get (), 0, SEEK_END) == 0)
473 {
474 len = ftell (file.get ());
475 if (len < 0)
476 perror_with_name (filename);
477 }
478 else
479 perror_with_name (filename);
480
481 if (len <= data->load_start)
482 error (_("Start address is greater than length of binary file %s."),
483 filename);
484
485 /* Chop off "len" if it exceeds the requested load_end addr. */
486 if (data->load_end != 0 && data->load_end < len)
487 len = data->load_end;
488 /* Chop off "len" if the requested load_start addr skips some bytes. */
489 if (data->load_start > 0)
490 len -= data->load_start;
491
492 printf_filtered
493 ("Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
494 filename,
495 (unsigned long) (data->load_start + data->load_offset),
496 (unsigned long) (data->load_start + data->load_offset + len));
497
498 /* Now set the file pos to the requested load start pos. */
499 if (fseek (file.get (), data->load_start, SEEK_SET) != 0)
500 perror_with_name (filename);
501
502 /* Now allocate a buffer and read the file contents. */
503 gdb::byte_vector buf (len);
504 if (fread (buf.data (), 1, len, file.get ()) != len)
505 perror_with_name (filename);
506
507 /* Now write the buffer into target memory. */
508 len = target_write_memory (data->load_start + data->load_offset,
509 buf.data (), len);
510 if (len != 0)
511 warning (_("restore: memory write failed (%s)."), safe_strerror (len));
512 }
513
514 static void
515 restore_command (const char *args, int from_tty)
516 {
517 struct callback_data data;
518 int binary_flag = 0;
519
520 if (!target_has_execution)
521 noprocess ();
522
523 data.load_offset = 0;
524 data.load_start = 0;
525 data.load_end = 0;
526
527 /* Parse the input arguments. First is filename (required). */
528 gdb::unique_xmalloc_ptr<char> filename = scan_filename (&args, NULL);
529 if (args != NULL && *args != '\0')
530 {
531 static const char binary_string[] = "binary";
532
533 /* Look for optional "binary" flag. */
534 if (startswith (args, binary_string))
535 {
536 binary_flag = 1;
537 args += strlen (binary_string);
538 args = skip_spaces (args);
539 }
540 /* Parse offset (optional). */
541 if (args != NULL && *args != '\0')
542 data.load_offset = binary_flag ?
543 parse_and_eval_address (scan_expression (&args, NULL).get ()) :
544 parse_and_eval_long (scan_expression (&args, NULL).get ());
545 if (args != NULL && *args != '\0')
546 {
547 /* Parse start address (optional). */
548 data.load_start =
549 parse_and_eval_long (scan_expression (&args, NULL).get ());
550 if (args != NULL && *args != '\0')
551 {
552 /* Parse end address (optional). */
553 data.load_end = parse_and_eval_long (args);
554 if (data.load_end <= data.load_start)
555 error (_("Start must be less than end."));
556 }
557 }
558 }
559
560 if (info_verbose)
561 printf_filtered ("Restore file %s offset 0x%lx start 0x%lx end 0x%lx\n",
562 filename.get (), (unsigned long) data.load_offset,
563 (unsigned long) data.load_start,
564 (unsigned long) data.load_end);
565
566 if (binary_flag)
567 {
568 restore_binary_file (filename.get (), &data);
569 }
570 else
571 {
572 /* Open the file for loading. */
573 gdb_bfd_ref_ptr ibfd (bfd_openr_or_error (filename.get (), NULL));
574
575 /* Process the sections. */
576 bfd_map_over_sections (ibfd.get (), restore_section_callback, &data);
577 }
578 }
579
580 static void
581 srec_dump_command (const char *cmd, int from_tty)
582 {
583 printf_unfiltered (_("\"dump srec\" must be followed by a subcommand.\n"));
584 help_list (srec_cmdlist, "dump srec ", all_commands, gdb_stdout);
585 }
586
587 static void
588 ihex_dump_command (const char *cmd, int from_tty)
589 {
590 printf_unfiltered (_("\"dump ihex\" must be followed by a subcommand.\n"));
591 help_list (ihex_cmdlist, "dump ihex ", all_commands, gdb_stdout);
592 }
593
594 static void
595 verilog_dump_command (const char *cmd, int from_tty)
596 {
597 printf_unfiltered (_("\"dump verilog\" must be followed by a subcommand.\n"));
598 help_list (verilog_cmdlist, "dump verilog ", all_commands, gdb_stdout);
599 }
600
601 static void
602 tekhex_dump_command (const char *cmd, int from_tty)
603 {
604 printf_unfiltered (_("\"dump tekhex\" must be followed by a subcommand.\n"));
605 help_list (tekhex_cmdlist, "dump tekhex ", all_commands, gdb_stdout);
606 }
607
608 static void
609 binary_dump_command (const char *cmd, int from_tty)
610 {
611 printf_unfiltered (_("\"dump binary\" must be followed by a subcommand.\n"));
612 help_list (binary_dump_cmdlist, "dump binary ", all_commands, gdb_stdout);
613 }
614
615 static void
616 binary_append_command (const char *cmd, int from_tty)
617 {
618 printf_unfiltered (_("\"append binary\" must be followed by a subcommand.\n"));
619 help_list (binary_append_cmdlist, "append binary ", all_commands,
620 gdb_stdout);
621 }
622
623 void
624 _initialize_cli_dump (void)
625 {
626 struct cmd_list_element *c;
627
628 add_prefix_cmd ("dump", class_vars, dump_command,
629 _("Dump target code/data to a local file."),
630 &dump_cmdlist, "dump ",
631 0/*allow-unknown*/,
632 &cmdlist);
633 add_prefix_cmd ("append", class_vars, append_command,
634 _("Append target code/data to a local file."),
635 &append_cmdlist, "append ",
636 0/*allow-unknown*/,
637 &cmdlist);
638
639 add_dump_command ("memory", dump_memory_command, "\
640 Write contents of memory to a raw binary file.\n\
641 Arguments are FILE START STOP. Writes the contents of memory within the\n\
642 range [START .. STOP) to the specified FILE in raw target ordered bytes.");
643
644 add_dump_command ("value", dump_value_command, "\
645 Write the value of an expression to a raw binary file.\n\
646 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION to\n\
647 the specified FILE in raw target ordered bytes.");
648
649 add_prefix_cmd ("srec", all_commands, srec_dump_command,
650 _("Write target code/data to an srec file."),
651 &srec_cmdlist, "dump srec ",
652 0 /*allow-unknown*/,
653 &dump_cmdlist);
654
655 add_prefix_cmd ("ihex", all_commands, ihex_dump_command,
656 _("Write target code/data to an intel hex file."),
657 &ihex_cmdlist, "dump ihex ",
658 0 /*allow-unknown*/,
659 &dump_cmdlist);
660
661 add_prefix_cmd ("verilog", all_commands, verilog_dump_command,
662 _("Write target code/data to a verilog hex file."),
663 &verilog_cmdlist, "dump verilog ",
664 0 /*allow-unknown*/,
665 &dump_cmdlist);
666
667 add_prefix_cmd ("tekhex", all_commands, tekhex_dump_command,
668 _("Write target code/data to a tekhex file."),
669 &tekhex_cmdlist, "dump tekhex ",
670 0 /*allow-unknown*/,
671 &dump_cmdlist);
672
673 add_prefix_cmd ("binary", all_commands, binary_dump_command,
674 _("Write target code/data to a raw binary file."),
675 &binary_dump_cmdlist, "dump binary ",
676 0 /*allow-unknown*/,
677 &dump_cmdlist);
678
679 add_prefix_cmd ("binary", all_commands, binary_append_command,
680 _("Append target code/data to a raw binary file."),
681 &binary_append_cmdlist, "append binary ",
682 0 /*allow-unknown*/,
683 &append_cmdlist);
684
685 add_cmd ("memory", all_commands, dump_srec_memory, _("\
686 Write contents of memory to an srec file.\n\
687 Arguments are FILE START STOP. Writes the contents of memory\n\
688 within the range [START .. STOP) to the specified FILE in srec format."),
689 &srec_cmdlist);
690
691 add_cmd ("value", all_commands, dump_srec_value, _("\
692 Write the value of an expression to an srec file.\n\
693 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
694 to the specified FILE in srec format."),
695 &srec_cmdlist);
696
697 add_cmd ("memory", all_commands, dump_ihex_memory, _("\
698 Write contents of memory to an ihex file.\n\
699 Arguments are FILE START STOP. Writes the contents of memory within\n\
700 the range [START .. STOP) to the specified FILE in intel hex format."),
701 &ihex_cmdlist);
702
703 add_cmd ("value", all_commands, dump_ihex_value, _("\
704 Write the value of an expression to an ihex file.\n\
705 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
706 to the specified FILE in intel hex format."),
707 &ihex_cmdlist);
708
709 add_cmd ("memory", all_commands, dump_verilog_memory, _("\
710 Write contents of memory to a verilog hex file.\n\
711 Arguments are FILE START STOP. Writes the contents of memory within\n\
712 the range [START .. STOP) to the specified FILE in verilog hex format."),
713 &verilog_cmdlist);
714
715 add_cmd ("value", all_commands, dump_verilog_value, _("\
716 Write the value of an expression to a verilog hex file.\n\
717 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
718 to the specified FILE in verilog hex format."),
719 &verilog_cmdlist);
720
721 add_cmd ("memory", all_commands, dump_tekhex_memory, _("\
722 Write contents of memory to a tekhex file.\n\
723 Arguments are FILE START STOP. Writes the contents of memory\n\
724 within the range [START .. STOP) to the specified FILE in tekhex format."),
725 &tekhex_cmdlist);
726
727 add_cmd ("value", all_commands, dump_tekhex_value, _("\
728 Write the value of an expression to a tekhex file.\n\
729 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
730 to the specified FILE in tekhex format."),
731 &tekhex_cmdlist);
732
733 add_cmd ("memory", all_commands, dump_binary_memory, _("\
734 Write contents of memory to a raw binary file.\n\
735 Arguments are FILE START STOP. Writes the contents of memory\n\
736 within the range [START .. STOP) to the specified FILE in binary format."),
737 &binary_dump_cmdlist);
738
739 add_cmd ("value", all_commands, dump_binary_value, _("\
740 Write the value of an expression to a raw binary file.\n\
741 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
742 to the specified FILE in raw target ordered bytes."),
743 &binary_dump_cmdlist);
744
745 add_cmd ("memory", all_commands, append_binary_memory, _("\
746 Append contents of memory to a raw binary file.\n\
747 Arguments are FILE START STOP. Writes the contents of memory within the\n\
748 range [START .. STOP) to the specified FILE in raw target ordered bytes."),
749 &binary_append_cmdlist);
750
751 add_cmd ("value", all_commands, append_binary_value, _("\
752 Append the value of an expression to a raw binary file.\n\
753 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
754 to the specified FILE in raw target ordered bytes."),
755 &binary_append_cmdlist);
756
757 c = add_com ("restore", class_vars, restore_command, _("\
758 Restore the contents of FILE to target memory.\n\
759 Arguments are FILE OFFSET START END where all except FILE are optional.\n\
760 OFFSET will be added to the base address of the file (default zero).\n\
761 If START and END are given, only the file contents within that range\n\
762 (file relative) will be restored to target memory."));
763 c->completer = filename_completer;
764 /* FIXME: completers for other commands. */
765 }
target_gdbarch
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5467
set_cmd_context
void set_cmd_context(struct cmd_list_element *cmd, void *context)
Definition: cli-decode.c:142
dump_binary_value
static void dump_binary_value(const char *args, int from_tty)
Definition: cli-dump.c:322
completer.h
scan_expression
static gdb::unique_xmalloc_ptr< char > scan_expression(const char **cmd, const char *def)
Definition: cli-dump.c:37
binary_append_cmdlist
static struct cmd_list_element * binary_append_cmdlist
Definition: cli-dump.c:128
restore_binary_file
static void restore_binary_file(const char *filename, struct callback_data *data)
Definition: cli-dump.c:466
restore_command
static void restore_command(const char *args, int from_tty)
Definition: cli-dump.c:515
get_cmd_context
void * get_cmd_context(struct cmd_list_element *cmd)
Definition: cli-decode.c:148
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
dump_ihex_value
static void dump_ihex_value(const char *args, int from_tty)
Definition: cli-dump.c:286
srec_cmdlist
static struct cmd_list_element * srec_cmdlist
Definition: cli-dump.c:123
target_write_memory
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition: target.c:1451
dump_srec_value
static void dump_srec_value(const char *args, int from_tty)
Definition: cli-dump.c:274
cmd_list_element
Definition: cli-decode.h:46
func
void(* func)(char *)
Definition: remote-fileio.c:1104
warning
void warning(const char *fmt,...)
Definition: errors.c:26
restore_section_callback
static void restore_section_callback(bfd *ibfd, asection *isec, void *args)
Definition: cli-dump.c:402
binary_dump_command
static void binary_dump_command(const char *cmd, int from_tty)
Definition: cli-dump.c:609
dump_tekhex_value
static void dump_tekhex_value(const char *args, int from_tty)
Definition: cli-dump.c:310
callback_data::load_offset
CORE_ADDR load_offset
Definition: cli-dump.c:391
info_verbose
int info_verbose
Definition: top.c:1791
dump_context::func
void(* func)(const char *cmd, const char *mode)
Definition: cli-dump.c:341
cli-cmds.h
add_cmd
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:262
dump_bfd_file
static void dump_bfd_file(const char *filename, const char *mode, const char *target, CORE_ADDR vaddr, const bfd_byte *buf, ULONGEST len)
Definition: cli-dump.c:157
class_vars
Definition: command.h:41
filename_completer
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition: completer.c:152
add_dump_command
static void add_dump_command(const char *name, void(*func)(const char *args, const char *mode), const char *descr)
Definition: cli-dump.c:354
cmdlist
struct cmd_list_element * cmdlist
Definition: cli-cmds.c:79
skip_spaces
char * skip_spaces(char *chp)
Definition: common-utils.c:337
_
#define _(String)
Definition: gdb_locale.h:35
gdb_bfd.h
dump_verilog_memory
static void dump_verilog_memory(const char *args, int from_tty)
Definition: cli-dump.c:292
scan_filename
static gdb::unique_xmalloc_ptr< char > scan_filename(const char **cmd, const char *defname)
Definition: cli-dump.c:55
defs.h
dump_value_to_file
static void dump_value_to_file(const char *cmd, const char *mode, const char *file_format)
Definition: cli-dump.c:223
append_binary_memory
static void append_binary_memory(const char *args, int from_tty)
Definition: cli-dump.c:328
VALUE_LVAL
#define VALUE_LVAL(val)
Definition: value.h:414
dump_context::mode
const char * mode
Definition: cli-dump.c:342
verilog_cmdlist
static struct cmd_list_element * verilog_cmdlist
Definition: cli-dump.c:125
callback_data::load_start
CORE_ADDR load_start
Definition: cli-dump.c:392
printf_filtered
void printf_filtered(const char *format,...)
Definition: utils.c:2045
paddress
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2745
cli-decode.h
XNEW
#define XNEW(T)
Definition: poison.h:109
add_prefix_cmd
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:367
verilog_dump_command
static void verilog_dump_command(const char *cmd, int from_tty)
Definition: cli-dump.c:595
name
const char *const name
Definition: aarch64-tdep.c:76
dump_value_command
static void dump_value_command(const char *cmd, const char *mode)
Definition: cli-dump.c:262
gdb::ref_ptr
Definition: gdb_ref_ptr.h:49
value_contents
const gdb_byte * value_contents(struct value *value)
Definition: value.c:1407
gdb_file_up
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
Definition: filestuff.h:59
tekhex_cmdlist
static struct cmd_list_element * tekhex_cmdlist
Definition: cli-dump.c:126
gdb::unique_xmalloc_ptr
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
Definition: gdb_unique_ptr.h:48
cli-utils.h
puts_filtered
void puts_filtered(const char *string)
Definition: utils.c:2085
append_binary_value
static void append_binary_value(const char *args, int from_tty)
Definition: cli-dump.c:334
callback_data
Definition: cli-dump.c:390
byte-vector.h
gdb_fopen_cloexec
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
Definition: filestuff.c:296
status
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition: gnu-nat.c:1822
startswith
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:107
_initialize_cli_dump
void _initialize_cli_dump(void)
Definition: cli-dump.c:624
target_has_execution
#define target_has_execution
Definition: target.h:1756
gdb.printer.bound_registers.long
long
Definition: bound_registers.py:24
dump_memory_command
static void dump_memory_command(const char *cmd, const char *mode)
Definition: cli-dump.c:217
dump_memory_to_file
static void dump_memory_to_file(const char *cmd, const char *mode, const char *file_format)
Definition: cli-dump.c:178
printf_unfiltered
void printf_unfiltered(const char *format,...)
Definition: utils.c:2056
read_memory
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
dump_cmdlist
static struct cmd_list_element * dump_cmdlist
Definition: cli-dump.c:121
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
value
Definition: value.c:169
srec_dump_command
static void srec_dump_command(const char *cmd, int from_tty)
Definition: cli-dump.c:581
binary_dump_cmdlist
static struct cmd_list_element * binary_dump_cmdlist
Definition: cli-dump.c:127
ihex_dump_command
static void ihex_dump_command(const char *cmd, int from_tty)
Definition: cli-dump.c:588
dump_verilog_value
static void dump_verilog_value(const char *args, int from_tty)
Definition: cli-dump.c:298
help_list
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
Definition: cli-decode.c:1071
binary_append_command
static void binary_append_command(const char *cmd, int from_tty)
Definition: cli-dump.c:616
call_dump_func
static void call_dump_func(struct cmd_list_element *c, const char *args, int from_tty)
Definition: cli-dump.c:346
perror_with_name
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
dump_ihex_memory
static void dump_ihex_memory(const char *args, int from_tty)
Definition: cli-dump.c:280
gdb_bfd_openr
gdb_bfd_ref_ptr gdb_bfd_openr(const char *filename, const char *target)
Definition: gdb_bfd.c:784
SEEK_SET
#define SEEK_SET
Definition: defs.h:93
gdbcore.h
parse_and_eval_address
CORE_ADDR parse_and_eval_address(const char *exp)
Definition: eval.c:101
dump_tekhex_memory
static void dump_tekhex_memory(const char *args, int from_tty)
Definition: cli-dump.c:304
safe_strerror
char * safe_strerror(int)
Definition: mingw-strerror.c:32
tekhex_dump_command
static void tekhex_dump_command(const char *cmd, int from_tty)
Definition: cli-dump.c:602
callback_data::load_end
CORE_ADDR load_end
Definition: cli-dump.c:393
target.h
gdb::ref_ptr::get
T * get() const
Definition: gdb_ref_ptr.h:130
value.h
cmd_list_element::func
void(* func)(struct cmd_list_element *c, const char *args, int from_tty)
Definition: cli-decode.h:110
gdb::byte_vector
gdb::def_vector< gdb_byte > byte_vector
Definition: byte-vector.h:58
parse_and_eval
struct value * parse_and_eval(const char *exp)
Definition: eval.c:119
ULONGEST
unsigned long long ULONGEST
Definition: common-types.h:53
savestring
char * savestring(const char *ptr, size_t len)
Definition: common-utils.c:226
value_type
struct type * value_type(const struct value *value)
Definition: value.c:1095
gdb_bfd_openw
gdb_bfd_ref_ptr gdb_bfd_openw(const char *filename, const char *target)
Definition: gdb_bfd.c:794
bfd_openr_or_error
static gdb_bfd_ref_ptr bfd_openr_or_error(const char *filename, const char *target)
Definition: cli-dump.c:84
cmd_list_element::doc
const char * doc
Definition: cli-decode.h:130
all_commands
Definition: command.h:39
ihex_cmdlist
static struct cmd_list_element * ihex_cmdlist
Definition: cli-dump.c:124
dump_binary_file
static void dump_binary_file(const char *filename, const char *mode, const bfd_byte *buf, ULONGEST len)
Definition: cli-dump.c:145
dump_srec_memory
static void dump_srec_memory(const char *args, int from_tty)
Definition: cli-dump.c:268
TYPE_LENGTH
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1235
dump_context
Definition: cli-dump.c:339
filestuff.h
append_cmdlist
static struct cmd_list_element * append_cmdlist
Definition: cli-dump.c:122
add_com
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:902
cmd_list_element::completer
completer_ftype * completer
Definition: cli-decode.h:164
value_address
CORE_ADDR value_address(const struct value *value)
Definition: value.c:1529
dump_binary_memory
static void dump_binary_memory(const char *args, int from_tty)
Definition: cli-dump.c:316
dump_command
static void dump_command(const char *cmd, int from_tty)
Definition: cli-dump.c:131
bfd_openw_or_error
static gdb_bfd_ref_ptr bfd_openw_or_error(const char *filename, const char *target, const char *mode)
Definition: cli-dump.c:98
noprocess
void noprocess(void)
Definition: target.c:548
error
void error(const char *fmt,...)
Definition: errors.c:38
size
size_t size
Definition: go32-nat.c:242
append_command
static void append_command(const char *cmd, int from_tty)
Definition: cli-dump.c:138
gdb_stdout
#define gdb_stdout
Definition: utils.h:340
parse_and_eval_long
LONGEST parse_and_eval_long(const char *exp)
Definition: eval.c:111