Introduce and use make_unique_xstrdup
[deliverable/binutils-gdb.git] / gdb / cli / cli-dump.c
CommitLineData
f02df580
MS
1/* Dump-to-file commands, for GDB, the GNU debugger.
2
42a4f53d 3 Copyright (C) 2002-2019 Free Software Foundation, Inc.
f02df580
MS
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f02df580
MS
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
f02df580
MS
21
22#include "defs.h"
f02df580
MS
23#include "cli/cli-decode.h"
24#include "cli/cli-cmds.h"
25#include "value.h"
26#include "completer.h"
f02df580
MS
27#include <ctype.h>
28#include "target.h"
dbda9972 29#include "readline/readline.h"
c0ac0ec7 30#include "gdbcore.h"
e9cafbcc 31#include "cli/cli-utils.h"
cbb099e8 32#include "gdb_bfd.h"
0747795c 33#include "common/filestuff.h"
d5722aa2 34#include "common/byte-vector.h"
f02df580 35
ee0c3293
TT
36static gdb::unique_xmalloc_ptr<char>
37scan_expression (const char **cmd, const char *def)
f02df580
MS
38{
39 if ((*cmd) == NULL || (**cmd) == '\0')
b02f78f9 40 return make_unique_xstrdup (def);
f02df580
MS
41 else
42 {
43 char *exp;
93db0d79 44 const char *end;
f02df580
MS
45
46 end = (*cmd) + strcspn (*cmd, " \t");
47 exp = savestring ((*cmd), end - (*cmd));
f1735a53 48 (*cmd) = skip_spaces (end);
ee0c3293 49 return gdb::unique_xmalloc_ptr<char> (exp);
f02df580
MS
50 }
51}
52
53
ee0c3293
TT
54static gdb::unique_xmalloc_ptr<char>
55scan_filename (const char **cmd, const char *defname)
f02df580 56{
ee0c3293 57 gdb::unique_xmalloc_ptr<char> filename;
f02df580
MS
58
59 /* FIXME: Need to get the ``/a(ppend)'' flag from somewhere. */
60
61 /* File. */
62 if ((*cmd) == NULL)
63 {
64 if (defname == NULL)
8a3fe4f8 65 error (_("Missing filename."));
ee0c3293 66 filename.reset (xstrdup (defname));
f02df580
MS
67 }
68 else
69 {
70 /* FIXME: should parse a possibly quoted string. */
93db0d79 71 const char *end;
f02df580 72
f1735a53 73 (*cmd) = skip_spaces (*cmd);
f02df580 74 end = *cmd + strcspn (*cmd, " \t");
ee0c3293 75 filename.reset (savestring ((*cmd), end - (*cmd)));
f1735a53 76 (*cmd) = skip_spaces (end);
f02df580
MS
77 }
78 gdb_assert (filename != NULL);
79
ee0c3293 80 return gdb::unique_xmalloc_ptr<char> (tilde_expand (filename.get ()));
f02df580
MS
81}
82
192b62ce
TT
83static gdb_bfd_ref_ptr
84bfd_openr_or_error (const char *filename, const char *target)
f02df580 85{
192b62ce 86 gdb_bfd_ref_ptr ibfd (gdb_bfd_openr (filename, target));
5cb316ef 87 if (ibfd == NULL)
192b62ce 88 error (_("Failed to open %s: %s."), filename,
f02df580
MS
89 bfd_errmsg (bfd_get_error ()));
90
192b62ce 91 if (!bfd_check_format (ibfd.get (), bfd_object))
8a3fe4f8 92 error (_("'%s' is not a recognized file format."), filename);
f02df580
MS
93
94 return ibfd;
95}
96
192b62ce
TT
97static gdb_bfd_ref_ptr
98bfd_openw_or_error (const char *filename, const char *target, const char *mode)
f02df580 99{
192b62ce 100 gdb_bfd_ref_ptr obfd;
f02df580
MS
101
102 if (*mode == 'w') /* Write: create new file */
103 {
64c31149 104 obfd = gdb_bfd_openw (filename, target);
5cb316ef 105 if (obfd == NULL)
192b62ce 106 error (_("Failed to open %s: %s."), filename,
f02df580 107 bfd_errmsg (bfd_get_error ()));
192b62ce
TT
108 if (!bfd_set_format (obfd.get (), bfd_object))
109 error (_("bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
f02df580 110 }
ebcd3b23
MS
111 else if (*mode == 'a') /* Append to existing file. */
112 { /* FIXME -- doesn't work... */
8a3fe4f8 113 error (_("bfd_openw does not work with append."));
f02df580
MS
114 }
115 else
192b62ce 116 error (_("bfd_openw_or_error: unknown mode %s."), mode);
f02df580
MS
117
118 return obfd;
119}
120
28578e6b
YQ
121static struct cmd_list_element *dump_cmdlist;
122static struct cmd_list_element *append_cmdlist;
123static struct cmd_list_element *srec_cmdlist;
124static struct cmd_list_element *ihex_cmdlist;
cf75d6c3 125static struct cmd_list_element *verilog_cmdlist;
28578e6b
YQ
126static struct cmd_list_element *tekhex_cmdlist;
127static struct cmd_list_element *binary_dump_cmdlist;
128static struct cmd_list_element *binary_append_cmdlist;
f02df580
MS
129
130static void
981a3fb3 131dump_command (const char *cmd, int from_tty)
f02df580 132{
a3f17187 133 printf_unfiltered (_("\"dump\" must be followed by a subcommand.\n\n"));
635c7e8a 134 help_list (dump_cmdlist, "dump ", all_commands, gdb_stdout);
f02df580
MS
135}
136
137static void
981a3fb3 138append_command (const char *cmd, int from_tty)
f02df580 139{
a3f17187 140 printf_unfiltered (_("\"append\" must be followed by a subcommand.\n\n"));
635c7e8a 141 help_list (dump_cmdlist, "append ", all_commands, gdb_stdout);
f02df580
MS
142}
143
144static void
c26b8e3b 145dump_binary_file (const char *filename, const char *mode,
5005c8a9 146 const bfd_byte *buf, ULONGEST len)
f02df580 147{
f02df580
MS
148 int status;
149
d419f42d
TT
150 gdb_file_up file = gdb_fopen_cloexec (filename, mode);
151 status = fwrite (buf, len, 1, file.get ());
f02df580
MS
152 if (status != 1)
153 perror_with_name (filename);
154}
155
156static void
c26b8e3b
AC
157dump_bfd_file (const char *filename, const char *mode,
158 const char *target, CORE_ADDR vaddr,
5005c8a9 159 const bfd_byte *buf, ULONGEST len)
f02df580 160{
f02df580
MS
161 asection *osection;
162
192b62ce
TT
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));
f02df580 171 osection->entsize = 0;
192b62ce
TT
172 if (!bfd_set_section_contents (obfd.get (), osection, buf, 0, len))
173 warning (_("writing dump file '%s' (%s)"), filename,
53624a93 174 bfd_errmsg (bfd_get_error ()));
f02df580
MS
175}
176
177static void
93db0d79 178dump_memory_to_file (const char *cmd, const char *mode, const char *file_format)
f02df580 179{
f02df580
MS
180 CORE_ADDR lo;
181 CORE_ADDR hi;
182 ULONGEST count;
93db0d79 183 const char *hi_exp;
f02df580
MS
184
185 /* Open the file. */
ee0c3293 186 gdb::unique_xmalloc_ptr<char> filename = scan_filename (&cmd, NULL);
f02df580
MS
187
188 /* Find the low address. */
189 if (cmd == NULL || *cmd == '\0')
8a3fe4f8 190 error (_("Missing start address."));
ee0c3293 191 gdb::unique_xmalloc_ptr<char> lo_exp = scan_expression (&cmd, NULL);
f02df580
MS
192
193 /* Find the second address - rest of line. */
194 if (cmd == NULL || *cmd == '\0')
8a3fe4f8 195 error (_("Missing stop address."));
f02df580
MS
196 hi_exp = cmd;
197
ee0c3293 198 lo = parse_and_eval_address (lo_exp.get ());
f02df580
MS
199 hi = parse_and_eval_address (hi_exp);
200 if (hi <= lo)
8a3fe4f8 201 error (_("Invalid memory address range (start >= end)."));
f02df580
MS
202 count = hi - lo;
203
204 /* FIXME: Should use read_memory_partial() and a magic blocking
205 value. */
d5722aa2
PA
206 gdb::byte_vector buf (count);
207 read_memory (lo, buf.data (), count);
f02df580
MS
208
209 /* Have everything. Open/write the data. */
210 if (file_format == NULL || strcmp (file_format, "binary") == 0)
ee0c3293 211 dump_binary_file (filename.get (), mode, buf.data (), count);
f02df580 212 else
ee0c3293 213 dump_bfd_file (filename.get (), mode, file_format, lo, buf.data (), count);
f02df580
MS
214}
215
216static void
2d0ac106 217dump_memory_command (const char *cmd, const char *mode)
f02df580
MS
218{
219 dump_memory_to_file (cmd, mode, "binary");
220}
221
222static void
93db0d79 223dump_value_to_file (const char *cmd, const char *mode, const char *file_format)
f02df580 224{
f02df580 225 struct value *val;
f02df580
MS
226
227 /* Open the file. */
ee0c3293 228 gdb::unique_xmalloc_ptr<char> filename = scan_filename (&cmd, NULL);
f02df580
MS
229
230 /* Find the value. */
231 if (cmd == NULL || *cmd == '\0')
8a3fe4f8 232 error (_("No value to %s."), *mode == 'a' ? "append" : "dump");
f02df580
MS
233 val = parse_and_eval (cmd);
234 if (val == NULL)
8a3fe4f8 235 error (_("Invalid expression."));
f02df580
MS
236
237 /* Have everything. Open/write the data. */
238 if (file_format == NULL || strcmp (file_format, "binary") == 0)
ee0c3293
TT
239 dump_binary_file (filename.get (), mode, value_contents (val),
240 TYPE_LENGTH (value_type (val)));
f02df580
MS
241 else
242 {
243 CORE_ADDR vaddr;
244
245 if (VALUE_LVAL (val))
246 {
42ae5230 247 vaddr = value_address (val);
f02df580
MS
248 }
249 else
250 {
251 vaddr = 0;
8a3fe4f8 252 warning (_("value is not an lval: address assumed to be zero"));
f02df580
MS
253 }
254
ee0c3293 255 dump_bfd_file (filename.get (), mode, file_format, vaddr,
0fd88904 256 value_contents (val),
df407dfe 257 TYPE_LENGTH (value_type (val)));
f02df580 258 }
f02df580
MS
259}
260
261static void
2d0ac106 262dump_value_command (const char *cmd, const char *mode)
f02df580
MS
263{
264 dump_value_to_file (cmd, mode, "binary");
265}
266
f02df580 267static void
2d0ac106 268dump_srec_memory (const char *args, int from_tty)
f02df580 269{
5d1d95de 270 dump_memory_to_file (args, FOPEN_WB, "srec");
f02df580
MS
271}
272
273static void
2d0ac106 274dump_srec_value (const char *args, int from_tty)
f02df580 275{
5d1d95de 276 dump_value_to_file (args, FOPEN_WB, "srec");
f02df580
MS
277}
278
279static void
2d0ac106 280dump_ihex_memory (const char *args, int from_tty)
f02df580 281{
5d1d95de 282 dump_memory_to_file (args, FOPEN_WB, "ihex");
f02df580
MS
283}
284
285static void
2d0ac106 286dump_ihex_value (const char *args, int from_tty)
f02df580 287{
5d1d95de 288 dump_value_to_file (args, FOPEN_WB, "ihex");
f02df580
MS
289}
290
cf75d6c3 291static void
2d0ac106 292dump_verilog_memory (const char *args, int from_tty)
cf75d6c3
AB
293{
294 dump_memory_to_file (args, FOPEN_WB, "verilog");
295}
296
297static void
2d0ac106 298dump_verilog_value (const char *args, int from_tty)
cf75d6c3
AB
299{
300 dump_value_to_file (args, FOPEN_WB, "verilog");
301}
302
f02df580 303static void
2d0ac106 304dump_tekhex_memory (const char *args, int from_tty)
f02df580 305{
5d1d95de 306 dump_memory_to_file (args, FOPEN_WB, "tekhex");
f02df580
MS
307}
308
309static void
2d0ac106 310dump_tekhex_value (const char *args, int from_tty)
f02df580 311{
5d1d95de 312 dump_value_to_file (args, FOPEN_WB, "tekhex");
f02df580
MS
313}
314
315static void
2d0ac106 316dump_binary_memory (const char *args, int from_tty)
f02df580 317{
5d1d95de 318 dump_memory_to_file (args, FOPEN_WB, "binary");
f02df580
MS
319}
320
321static void
2d0ac106 322dump_binary_value (const char *args, int from_tty)
f02df580 323{
5d1d95de 324 dump_value_to_file (args, FOPEN_WB, "binary");
f02df580
MS
325}
326
327static void
2d0ac106 328append_binary_memory (const char *args, int from_tty)
f02df580 329{
5d1d95de 330 dump_memory_to_file (args, FOPEN_AB, "binary");
f02df580
MS
331}
332
333static void
2d0ac106 334append_binary_value (const char *args, int from_tty)
f02df580 335{
5d1d95de 336 dump_value_to_file (args, FOPEN_AB, "binary");
f02df580
MS
337}
338
339struct dump_context
340{
2d0ac106 341 void (*func) (const char *cmd, const char *mode);
a121b7c1 342 const char *mode;
f02df580
MS
343};
344
345static void
95a6b0a1 346call_dump_func (struct cmd_list_element *c, const char *args, int from_tty)
f02df580 347{
9a3c8263 348 struct dump_context *d = (struct dump_context *) get_cmd_context (c);
cdb27c12 349
f02df580
MS
350 d->func (args, d->mode);
351}
352
db229724 353static void
a121b7c1 354add_dump_command (const char *name,
2d0ac106 355 void (*func) (const char *args, const char *mode),
a121b7c1 356 const char *descr)
f02df580
MS
357
358{
359 struct cmd_list_element *c;
360 struct dump_context *d;
361
0450cc4c 362 c = add_cmd (name, all_commands, descr, &dump_cmdlist);
f02df580 363 c->completer = filename_completer;
70ba0933 364 d = XNEW (struct dump_context);
f02df580 365 d->func = func;
5d1d95de 366 d->mode = FOPEN_WB;
f02df580
MS
367 set_cmd_context (c, d);
368 c->func = call_dump_func;
369
0450cc4c 370 c = add_cmd (name, all_commands, descr, &append_cmdlist);
f02df580 371 c->completer = filename_completer;
70ba0933 372 d = XNEW (struct dump_context);
f02df580 373 d->func = func;
5d1d95de 374 d->mode = FOPEN_AB;
f02df580
MS
375 set_cmd_context (c, d);
376 c->func = call_dump_func;
377
cb1a6d5f 378 /* Replace "Dump " at start of docstring with "Append " (borrowed
eefe576e 379 from [deleted] deprecated_add_show_from_set). */
f02df580
MS
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] == ' ')
1754f103 386 c->doc = concat ("Append ", c->doc + 6, (char *)NULL);
f02df580
MS
387}
388
ebcd3b23 389/* Opaque data for restore_section_callback. */
f02df580 390struct callback_data {
1fac167a 391 CORE_ADDR load_offset;
f02df580
MS
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
401static void
402restore_section_callback (bfd *ibfd, asection *isec, void *args)
403{
9a3c8263 404 struct callback_data *data = (struct callback_data *) args;
f02df580
MS
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;
f02df580
MS
410 int ret;
411
ebcd3b23 412 /* Ignore non-loadable sections, eg. from elf files. */
f02df580
MS
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 {
ebcd3b23 420 /* No, no useable data in this section. */
a3f17187 421 printf_filtered (_("skipping section %s...\n"),
f02df580
MS
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;
ebcd3b23 431 /* Size of a partial transfer. */
f02df580
MS
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. */
26fcd5d7
TT
437 gdb::byte_vector buf (size);
438 if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size))
8a3fe4f8 439 error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
f02df580
MS
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)
5af949e3 448 printf_filtered (" into memory (%s to %s)\n",
f5656ead 449 paddress (target_gdbarch (),
5af949e3 450 (unsigned long) sec_start
f5db4da3 451 + sec_offset + data->load_offset),
f5656ead 452 paddress (target_gdbarch (),
5af949e3
UW
453 (unsigned long) sec_start + sec_offset
454 + data->load_offset + sec_load_count));
f02df580
MS
455 else
456 puts_filtered ("\n");
457
458 /* Write the data. */
459 ret = target_write_memory (sec_start + sec_offset + data->load_offset,
26fcd5d7 460 &buf[sec_offset], sec_load_count);
f02df580 461 if (ret != 0)
8a3fe4f8 462 warning (_("restore: memory write failed (%s)."), safe_strerror (ret));
f02df580
MS
463}
464
465static void
93db0d79 466restore_binary_file (const char *filename, struct callback_data *data)
f02df580 467{
d419f42d 468 gdb_file_up file = gdb_fopen_cloexec (filename, FOPEN_RB);
f02df580
MS
469 long len;
470
94c18618
SDJ
471 if (file == NULL)
472 error (_("Failed to open %s: %s"), filename, safe_strerror (errno));
473
f02df580 474 /* Get the file size for reading. */
d419f42d 475 if (fseek (file.get (), 0, SEEK_END) == 0)
5e9e105f 476 {
d419f42d 477 len = ftell (file.get ());
5e9e105f
MS
478 if (len < 0)
479 perror_with_name (filename);
480 }
f02df580
MS
481 else
482 perror_with_name (filename);
483
484 if (len <= data->load_start)
8a3fe4f8 485 error (_("Start address is greater than length of binary file %s."),
f02df580
MS
486 filename);
487
ebcd3b23 488 /* Chop off "len" if it exceeds the requested load_end addr. */
f02df580
MS
489 if (data->load_end != 0 && data->load_end < len)
490 len = data->load_end;
ebcd3b23 491 /* Chop off "len" if the requested load_start addr skips some bytes. */
f02df580
MS
492 if (data->load_start > 0)
493 len -= data->load_start;
494
495 printf_filtered
496 ("Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
497 filename,
1fac167a
UW
498 (unsigned long) (data->load_start + data->load_offset),
499 (unsigned long) (data->load_start + data->load_offset + len));
f02df580
MS
500
501 /* Now set the file pos to the requested load start pos. */
d419f42d 502 if (fseek (file.get (), data->load_start, SEEK_SET) != 0)
f02df580
MS
503 perror_with_name (filename);
504
505 /* Now allocate a buffer and read the file contents. */
d5722aa2 506 gdb::byte_vector buf (len);
d419f42d 507 if (fread (buf.data (), 1, len, file.get ()) != len)
f02df580
MS
508 perror_with_name (filename);
509
ebcd3b23 510 /* Now write the buffer into target memory. */
cd9da5b0 511 len = target_write_memory (data->load_start + data->load_offset,
d5722aa2 512 buf.data (), len);
f02df580 513 if (len != 0)
8a3fe4f8 514 warning (_("restore: memory write failed (%s)."), safe_strerror (len));
f02df580
MS
515}
516
517static void
0b39b52e 518restore_command (const char *args, int from_tty)
f02df580 519{
f02df580 520 struct callback_data data;
f02df580
MS
521 int binary_flag = 0;
522
523 if (!target_has_execution)
524 noprocess ();
525
526 data.load_offset = 0;
527 data.load_start = 0;
528 data.load_end = 0;
529
ebcd3b23 530 /* Parse the input arguments. First is filename (required). */
ee0c3293 531 gdb::unique_xmalloc_ptr<char> filename = scan_filename (&args, NULL);
f02df580
MS
532 if (args != NULL && *args != '\0')
533 {
a121b7c1 534 static const char binary_string[] = "binary";
f02df580
MS
535
536 /* Look for optional "binary" flag. */
61012eef 537 if (startswith (args, binary_string))
f02df580
MS
538 {
539 binary_flag = 1;
540 args += strlen (binary_string);
f1735a53 541 args = skip_spaces (args);
f02df580 542 }
ebcd3b23 543 /* Parse offset (optional). */
f02df580 544 if (args != NULL && *args != '\0')
cbd641ed 545 data.load_offset = binary_flag ?
ee0c3293
TT
546 parse_and_eval_address (scan_expression (&args, NULL).get ()) :
547 parse_and_eval_long (scan_expression (&args, NULL).get ());
f02df580
MS
548 if (args != NULL && *args != '\0')
549 {
ebcd3b23 550 /* Parse start address (optional). */
f02df580 551 data.load_start =
ee0c3293 552 parse_and_eval_long (scan_expression (&args, NULL).get ());
f02df580
MS
553 if (args != NULL && *args != '\0')
554 {
ebcd3b23 555 /* Parse end address (optional). */
de530e84 556 data.load_end = parse_and_eval_long (args);
f02df580 557 if (data.load_end <= data.load_start)
8a3fe4f8 558 error (_("Start must be less than end."));
f02df580
MS
559 }
560 }
561 }
562
563 if (info_verbose)
564 printf_filtered ("Restore file %s offset 0x%lx start 0x%lx end 0x%lx\n",
ee0c3293 565 filename.get (), (unsigned long) data.load_offset,
f02df580
MS
566 (unsigned long) data.load_start,
567 (unsigned long) data.load_end);
568
569 if (binary_flag)
570 {
ee0c3293 571 restore_binary_file (filename.get (), &data);
f02df580
MS
572 }
573 else
574 {
ebcd3b23 575 /* Open the file for loading. */
ee0c3293 576 gdb_bfd_ref_ptr ibfd (bfd_openr_or_error (filename.get (), NULL));
f02df580 577
ebcd3b23 578 /* Process the sections. */
192b62ce 579 bfd_map_over_sections (ibfd.get (), restore_section_callback, &data);
f02df580 580 }
f02df580
MS
581}
582
583static void
981a3fb3 584srec_dump_command (const char *cmd, int from_tty)
f02df580 585{
6faec16b 586 printf_unfiltered (_("\"dump srec\" must be followed by a subcommand.\n"));
635c7e8a 587 help_list (srec_cmdlist, "dump srec ", all_commands, gdb_stdout);
f02df580
MS
588}
589
590static void
981a3fb3 591ihex_dump_command (const char *cmd, int from_tty)
f02df580 592{
6faec16b 593 printf_unfiltered (_("\"dump ihex\" must be followed by a subcommand.\n"));
635c7e8a 594 help_list (ihex_cmdlist, "dump ihex ", all_commands, gdb_stdout);
f02df580
MS
595}
596
cf75d6c3 597static void
981a3fb3 598verilog_dump_command (const char *cmd, int from_tty)
cf75d6c3
AB
599{
600 printf_unfiltered (_("\"dump verilog\" must be followed by a subcommand.\n"));
601 help_list (verilog_cmdlist, "dump verilog ", all_commands, gdb_stdout);
602}
603
f02df580 604static void
981a3fb3 605tekhex_dump_command (const char *cmd, int from_tty)
f02df580 606{
6faec16b 607 printf_unfiltered (_("\"dump tekhex\" must be followed by a subcommand.\n"));
635c7e8a 608 help_list (tekhex_cmdlist, "dump tekhex ", all_commands, gdb_stdout);
f02df580
MS
609}
610
611static void
981a3fb3 612binary_dump_command (const char *cmd, int from_tty)
f02df580 613{
6faec16b 614 printf_unfiltered (_("\"dump binary\" must be followed by a subcommand.\n"));
635c7e8a 615 help_list (binary_dump_cmdlist, "dump binary ", all_commands, gdb_stdout);
f02df580
MS
616}
617
618static void
981a3fb3 619binary_append_command (const char *cmd, int from_tty)
f02df580 620{
6faec16b 621 printf_unfiltered (_("\"append binary\" must be followed by a subcommand.\n"));
635c7e8a
TT
622 help_list (binary_append_cmdlist, "append binary ", all_commands,
623 gdb_stdout);
f02df580
MS
624}
625
626void
627_initialize_cli_dump (void)
628{
629 struct cmd_list_element *c;
cdb27c12 630
9a2b4c1b
MS
631 add_prefix_cmd ("dump", class_vars, dump_command,
632 _("Dump target code/data to a local file."),
f02df580
MS
633 &dump_cmdlist, "dump ",
634 0/*allow-unknown*/,
635 &cmdlist);
9a2b4c1b
MS
636 add_prefix_cmd ("append", class_vars, append_command,
637 _("Append target code/data to a local file."),
f02df580
MS
638 &append_cmdlist, "append ",
639 0/*allow-unknown*/,
640 &cmdlist);
641
642 add_dump_command ("memory", dump_memory_command, "\
643Write contents of memory to a raw binary file.\n\
644Arguments are FILE START STOP. Writes the contents of memory within the\n\
64b9b334 645range [START .. STOP) to the specified FILE in raw target ordered bytes.");
f02df580
MS
646
647 add_dump_command ("value", dump_value_command, "\
648Write the value of an expression to a raw binary file.\n\
649Arguments are FILE EXPRESSION. Writes the value of EXPRESSION to\n\
650the specified FILE in raw target ordered bytes.");
651
9a2b4c1b
MS
652 add_prefix_cmd ("srec", all_commands, srec_dump_command,
653 _("Write target code/data to an srec file."),
f02df580
MS
654 &srec_cmdlist, "dump srec ",
655 0 /*allow-unknown*/,
656 &dump_cmdlist);
657
9a2b4c1b
MS
658 add_prefix_cmd ("ihex", all_commands, ihex_dump_command,
659 _("Write target code/data to an intel hex file."),
f02df580
MS
660 &ihex_cmdlist, "dump ihex ",
661 0 /*allow-unknown*/,
662 &dump_cmdlist);
663
cf75d6c3
AB
664 add_prefix_cmd ("verilog", all_commands, verilog_dump_command,
665 _("Write target code/data to a verilog hex file."),
666 &verilog_cmdlist, "dump verilog ",
667 0 /*allow-unknown*/,
668 &dump_cmdlist);
669
9a2b4c1b
MS
670 add_prefix_cmd ("tekhex", all_commands, tekhex_dump_command,
671 _("Write target code/data to a tekhex file."),
f02df580
MS
672 &tekhex_cmdlist, "dump tekhex ",
673 0 /*allow-unknown*/,
674 &dump_cmdlist);
675
9a2b4c1b
MS
676 add_prefix_cmd ("binary", all_commands, binary_dump_command,
677 _("Write target code/data to a raw binary file."),
f02df580
MS
678 &binary_dump_cmdlist, "dump binary ",
679 0 /*allow-unknown*/,
680 &dump_cmdlist);
681
9a2b4c1b
MS
682 add_prefix_cmd ("binary", all_commands, binary_append_command,
683 _("Append target code/data to a raw binary file."),
f02df580
MS
684 &binary_append_cmdlist, "append binary ",
685 0 /*allow-unknown*/,
686 &append_cmdlist);
687
1a966eab 688 add_cmd ("memory", all_commands, dump_srec_memory, _("\
f02df580
MS
689Write contents of memory to an srec file.\n\
690Arguments are FILE START STOP. Writes the contents of memory\n\
64b9b334 691within the range [START .. STOP) to the specified FILE in srec format."),
f02df580
MS
692 &srec_cmdlist);
693
1a966eab 694 add_cmd ("value", all_commands, dump_srec_value, _("\
f02df580
MS
695Write the value of an expression to an srec file.\n\
696Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
1a966eab 697to the specified FILE in srec format."),
f02df580
MS
698 &srec_cmdlist);
699
1a966eab 700 add_cmd ("memory", all_commands, dump_ihex_memory, _("\
f02df580
MS
701Write contents of memory to an ihex file.\n\
702Arguments are FILE START STOP. Writes the contents of memory within\n\
64b9b334 703the range [START .. STOP) to the specified FILE in intel hex format."),
f02df580
MS
704 &ihex_cmdlist);
705
1a966eab 706 add_cmd ("value", all_commands, dump_ihex_value, _("\
f02df580
MS
707Write the value of an expression to an ihex file.\n\
708Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
1a966eab 709to the specified FILE in intel hex format."),
f02df580
MS
710 &ihex_cmdlist);
711
cf75d6c3
AB
712 add_cmd ("memory", all_commands, dump_verilog_memory, _("\
713Write contents of memory to a verilog hex file.\n\
714Arguments are FILE START STOP. Writes the contents of memory within\n\
715the range [START .. STOP) to the specified FILE in verilog hex format."),
716 &verilog_cmdlist);
717
718 add_cmd ("value", all_commands, dump_verilog_value, _("\
719Write the value of an expression to a verilog hex file.\n\
720Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
721to the specified FILE in verilog hex format."),
722 &verilog_cmdlist);
723
1a966eab 724 add_cmd ("memory", all_commands, dump_tekhex_memory, _("\
f02df580
MS
725Write contents of memory to a tekhex file.\n\
726Arguments are FILE START STOP. Writes the contents of memory\n\
64b9b334 727within the range [START .. STOP) to the specified FILE in tekhex format."),
f02df580
MS
728 &tekhex_cmdlist);
729
1a966eab 730 add_cmd ("value", all_commands, dump_tekhex_value, _("\
f02df580
MS
731Write the value of an expression to a tekhex file.\n\
732Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
1a966eab 733to the specified FILE in tekhex format."),
f02df580
MS
734 &tekhex_cmdlist);
735
1a966eab 736 add_cmd ("memory", all_commands, dump_binary_memory, _("\
f02df580
MS
737Write contents of memory to a raw binary file.\n\
738Arguments are FILE START STOP. Writes the contents of memory\n\
64b9b334 739within the range [START .. STOP) to the specified FILE in binary format."),
f02df580
MS
740 &binary_dump_cmdlist);
741
1a966eab 742 add_cmd ("value", all_commands, dump_binary_value, _("\
f02df580
MS
743Write the value of an expression to a raw binary file.\n\
744Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
1a966eab 745to the specified FILE in raw target ordered bytes."),
f02df580
MS
746 &binary_dump_cmdlist);
747
1a966eab 748 add_cmd ("memory", all_commands, append_binary_memory, _("\
f02df580
MS
749Append contents of memory to a raw binary file.\n\
750Arguments are FILE START STOP. Writes the contents of memory within the\n\
64b9b334 751range [START .. STOP) to the specified FILE in raw target ordered bytes."),
f02df580
MS
752 &binary_append_cmdlist);
753
1a966eab 754 add_cmd ("value", all_commands, append_binary_value, _("\
f02df580
MS
755Append the value of an expression to a raw binary file.\n\
756Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
1a966eab 757to the specified FILE in raw target ordered bytes."),
f02df580
MS
758 &binary_append_cmdlist);
759
1bedd215
AC
760 c = add_com ("restore", class_vars, restore_command, _("\
761Restore the contents of FILE to target memory.\n\
f02df580
MS
762Arguments are FILE OFFSET START END where all except FILE are optional.\n\
763OFFSET will be added to the base address of the file (default zero).\n\
9eb6e5a1 764If START and END are given, only the file contents within that range\n\
1bedd215 765(file relative) will be restored to target memory."));
f02df580 766 c->completer = filename_completer;
ebcd3b23 767 /* FIXME: completers for other commands. */
f02df580 768}
This page took 1.122986 seconds and 4 git commands to generate.