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