gdb/cli/cli-dump.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* Dump-to-file commands, for GDB, the GNU debugger.

  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.

  3.    Contributed by Red Hat.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "cli/cli-decode.h"
  17. #include "cli/cli-cmds.h"
  18. #include "value.h"
  19. #include "completer.h"
  20. #include <ctype.h>
  21. #include "target.h"
  22. #include "readline/readline.h"
  23. #include "gdbcore.h"
  24. #include "cli/cli-utils.h"
  25. #include "gdb_bfd.h"
  26. #include "filestuff.h"


  27. static const char *
  28. scan_expression_with_cleanup (const char **cmd, const char *def)
  29. {
  30.   if ((*cmd) == NULL || (**cmd) == '\0')
  31.     {
  32.       char *exp = xstrdup (def);

  33.       make_cleanup (xfree, exp);
  34.       return exp;
  35.     }
  36.   else
  37.     {
  38.       char *exp;
  39.       const char *end;

  40.       end = (*cmd) + strcspn (*cmd, " \t");
  41.       exp = savestring ((*cmd), end - (*cmd));
  42.       make_cleanup (xfree, exp);
  43.       (*cmd) = skip_spaces_const (end);
  44.       return exp;
  45.     }
  46. }


  47. static char *
  48. scan_filename_with_cleanup (const char **cmd, const char *defname)
  49. {
  50.   char *filename;
  51.   char *fullname;

  52.   /* FIXME: Need to get the ``/a(ppend)'' flag from somewhere.  */

  53.   /* File.  */
  54.   if ((*cmd) == NULL)
  55.     {
  56.       if (defname == NULL)
  57.         error (_("Missing filename."));
  58.       filename = xstrdup (defname);
  59.       make_cleanup (xfree, filename);
  60.     }
  61.   else
  62.     {
  63.       /* FIXME: should parse a possibly quoted string.  */
  64.       const char *end;

  65.       (*cmd) = skip_spaces_const (*cmd);
  66.       end = *cmd + strcspn (*cmd, " \t");
  67.       filename = savestring ((*cmd), end - (*cmd));
  68.       make_cleanup (xfree, filename);
  69.       (*cmd) = skip_spaces_const (end);
  70.     }
  71.   gdb_assert (filename != NULL);

  72.   fullname = tilde_expand (filename);
  73.   make_cleanup (xfree, fullname);

  74.   return fullname;
  75. }

  76. static FILE *
  77. fopen_with_cleanup (const char *filename, const char *mode)
  78. {
  79.   FILE *file = gdb_fopen_cloexec (filename, mode);

  80.   if (file == NULL)
  81.     perror_with_name (filename);
  82.   make_cleanup_fclose (file);
  83.   return file;
  84. }

  85. static bfd *
  86. bfd_openr_with_cleanup (const char *filename, const char *target)
  87. {
  88.   bfd *ibfd;

  89.   ibfd = gdb_bfd_openr (filename, target);
  90.   if (ibfd == NULL)
  91.     error (_("Failed to open %s: %s."), filename,
  92.            bfd_errmsg (bfd_get_error ()));

  93.   make_cleanup_bfd_unref (ibfd);
  94.   if (!bfd_check_format (ibfd, bfd_object))
  95.     error (_("'%s' is not a recognized file format."), filename);

  96.   return ibfd;
  97. }

  98. static bfd *
  99. bfd_openw_with_cleanup (const char *filename, const char *target,
  100.                         const char *mode)
  101. {
  102.   bfd *obfd;

  103.   if (*mode == 'w')        /* Write: create new file */
  104.     {
  105.       obfd = gdb_bfd_openw (filename, target);
  106.       if (obfd == NULL)
  107.         error (_("Failed to open %s: %s."), filename,
  108.                bfd_errmsg (bfd_get_error ()));
  109.       make_cleanup_bfd_unref (obfd);
  110.       if (!bfd_set_format (obfd, bfd_object))
  111.         error (_("bfd_openw_with_cleanup: %s."), bfd_errmsg (bfd_get_error ()));
  112.     }
  113.   else if (*mode == 'a')        /* Append to existing file.  */
  114.     {        /* FIXME -- doesn't work...  */
  115.       error (_("bfd_openw does not work with append."));
  116.     }
  117.   else
  118.     error (_("bfd_openw_with_cleanup: unknown mode %s."), mode);

  119.   return obfd;
  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 *tekhex_cmdlist;
  126. static struct cmd_list_element *binary_dump_cmdlist;
  127. static struct cmd_list_element *binary_append_cmdlist;

  128. static void
  129. dump_command (char *cmd, int from_tty)
  130. {
  131.   printf_unfiltered (_("\"dump\" must be followed by a subcommand.\n\n"));
  132.   help_list (dump_cmdlist, "dump ", all_commands, gdb_stdout);
  133. }

  134. static void
  135. append_command (char *cmd, int from_tty)
  136. {
  137.   printf_unfiltered (_("\"append\" must be followed by a subcommand.\n\n"));
  138.   help_list (dump_cmdlist, "append ", all_commands, gdb_stdout);
  139. }

  140. static void
  141. dump_binary_file (const char *filename, const char *mode,
  142.                   const bfd_byte *buf, ULONGEST len)
  143. {
  144.   FILE *file;
  145.   int status;

  146.   file = fopen_with_cleanup (filename, mode);
  147.   status = fwrite (buf, len, 1, file);
  148.   if (status != 1)
  149.     perror_with_name (filename);
  150. }

  151. static void
  152. dump_bfd_file (const char *filename, const char *mode,
  153.                const char *target, CORE_ADDR vaddr,
  154.                const bfd_byte *buf, ULONGEST len)
  155. {
  156.   bfd *obfd;
  157.   asection *osection;

  158.   obfd = bfd_openw_with_cleanup (filename, target, mode);
  159.   osection = bfd_make_section_anyway (obfd, ".newsec");
  160.   bfd_set_section_size (obfd, osection, len);
  161.   bfd_set_section_vma (obfd, osection, vaddr);
  162.   bfd_set_section_alignment (obfd, osection, 0);
  163.   bfd_set_section_flags (obfd, osection, (SEC_HAS_CONTENTS
  164.                                           | SEC_ALLOC
  165.                                           | SEC_LOAD));
  166.   osection->entsize = 0;
  167.   if (!bfd_set_section_contents (obfd, osection, buf, 0, len))
  168.     warning (_("writing dump file '%s' (%s)"), filename,
  169.              bfd_errmsg (bfd_get_error ()));
  170. }

  171. static void
  172. dump_memory_to_file (const char *cmd, const char *mode, const char *file_format)
  173. {
  174.   struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
  175.   CORE_ADDR lo;
  176.   CORE_ADDR hi;
  177.   ULONGEST count;
  178.   const char *filename;
  179.   void *buf;
  180.   const char *lo_exp;
  181.   const char *hi_exp;

  182.   /* Open the file.  */
  183.   filename = scan_filename_with_cleanup (&cmd, NULL);

  184.   /* Find the low address.  */
  185.   if (cmd == NULL || *cmd == '\0')
  186.     error (_("Missing start address."));
  187.   lo_exp = scan_expression_with_cleanup (&cmd, NULL);

  188.   /* Find the second address - rest of line.  */
  189.   if (cmd == NULL || *cmd == '\0')
  190.     error (_("Missing stop address."));
  191.   hi_exp = cmd;

  192.   lo = parse_and_eval_address (lo_exp);
  193.   hi = parse_and_eval_address (hi_exp);
  194.   if (hi <= lo)
  195.     error (_("Invalid memory address range (start >= end)."));
  196.   count = hi - lo;

  197.   /* FIXME: Should use read_memory_partial() and a magic blocking
  198.      value.  */
  199.   buf = xmalloc (count);
  200.   make_cleanup (xfree, buf);
  201.   read_memory (lo, buf, count);

  202.   /* Have everything.  Open/write the data.  */
  203.   if (file_format == NULL || strcmp (file_format, "binary") == 0)
  204.     {
  205.       dump_binary_file (filename, mode, buf, count);
  206.     }
  207.   else
  208.     {
  209.       dump_bfd_file (filename, mode, file_format, lo, buf, count);
  210.     }

  211.   do_cleanups (old_cleanups);
  212. }

  213. static void
  214. dump_memory_command (char *cmd, char *mode)
  215. {
  216.   dump_memory_to_file (cmd, mode, "binary");
  217. }

  218. static void
  219. dump_value_to_file (const char *cmd, const char *mode, const char *file_format)
  220. {
  221.   struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
  222.   struct value *val;
  223.   const char *filename;

  224.   /* Open the file.  */
  225.   filename = scan_filename_with_cleanup (&cmd, NULL);

  226.   /* Find the value.  */
  227.   if (cmd == NULL || *cmd == '\0')
  228.     error (_("No value to %s."), *mode == 'a' ? "append" : "dump");
  229.   val = parse_and_eval (cmd);
  230.   if (val == NULL)
  231.     error (_("Invalid expression."));

  232.   /* Have everything.  Open/write the data.  */
  233.   if (file_format == NULL || strcmp (file_format, "binary") == 0)
  234.     {
  235.       dump_binary_file (filename, mode, value_contents (val),
  236.                         TYPE_LENGTH (value_type (val)));
  237.     }
  238.   else
  239.     {
  240.       CORE_ADDR vaddr;

  241.       if (VALUE_LVAL (val))
  242.         {
  243.           vaddr = value_address (val);
  244.         }
  245.       else
  246.         {
  247.           vaddr = 0;
  248.           warning (_("value is not an lval: address assumed to be zero"));
  249.         }

  250.       dump_bfd_file (filename, mode, file_format, vaddr,
  251.                      value_contents (val),
  252.                      TYPE_LENGTH (value_type (val)));
  253.     }

  254.   do_cleanups (old_cleanups);
  255. }

  256. static void
  257. dump_value_command (char *cmd, char *mode)
  258. {
  259.   dump_value_to_file (cmd, mode, "binary");
  260. }

  261. static void
  262. dump_srec_memory (char *args, int from_tty)
  263. {
  264.   dump_memory_to_file (args, FOPEN_WB, "srec");
  265. }

  266. static void
  267. dump_srec_value (char *args, int from_tty)
  268. {
  269.   dump_value_to_file (args, FOPEN_WB, "srec");
  270. }

  271. static void
  272. dump_ihex_memory (char *args, int from_tty)
  273. {
  274.   dump_memory_to_file (args, FOPEN_WB, "ihex");
  275. }

  276. static void
  277. dump_ihex_value (char *args, int from_tty)
  278. {
  279.   dump_value_to_file (args, FOPEN_WB, "ihex");
  280. }

  281. static void
  282. dump_tekhex_memory (char *args, int from_tty)
  283. {
  284.   dump_memory_to_file (args, FOPEN_WB, "tekhex");
  285. }

  286. static void
  287. dump_tekhex_value (char *args, int from_tty)
  288. {
  289.   dump_value_to_file (args, FOPEN_WB, "tekhex");
  290. }

  291. static void
  292. dump_binary_memory (char *args, int from_tty)
  293. {
  294.   dump_memory_to_file (args, FOPEN_WB, "binary");
  295. }

  296. static void
  297. dump_binary_value (char *args, int from_tty)
  298. {
  299.   dump_value_to_file (args, FOPEN_WB, "binary");
  300. }

  301. static void
  302. append_binary_memory (char *args, int from_tty)
  303. {
  304.   dump_memory_to_file (args, FOPEN_AB, "binary");
  305. }

  306. static void
  307. append_binary_value (char *args, int from_tty)
  308. {
  309.   dump_value_to_file (args, FOPEN_AB, "binary");
  310. }

  311. struct dump_context
  312. {
  313.   void (*func) (char *cmd, char *mode);
  314.   char *mode;
  315. };

  316. static void
  317. call_dump_func (struct cmd_list_element *c, char *args, int from_tty)
  318. {
  319.   struct dump_context *d = get_cmd_context (c);

  320.   d->func (args, d->mode);
  321. }

  322. static void
  323. add_dump_command (char *name, void (*func) (char *args, char *mode),
  324.                   char *descr)

  325. {
  326.   struct cmd_list_element *c;
  327.   struct dump_context *d;

  328.   c = add_cmd (name, all_commands, NULL, descr, &dump_cmdlist);
  329.   c->completer =  filename_completer;
  330.   d = XNEW (struct dump_context);
  331.   d->func = func;
  332.   d->mode = FOPEN_WB;
  333.   set_cmd_context (c, d);
  334.   c->func = call_dump_func;

  335.   c = add_cmd (name, all_commands, NULL, descr, &append_cmdlist);
  336.   c->completer =  filename_completer;
  337.   d = XNEW (struct dump_context);
  338.   d->func = func;
  339.   d->mode = FOPEN_AB;
  340.   set_cmd_context (c, d);
  341.   c->func = call_dump_func;

  342.   /* Replace "Dump " at start of docstring with "Append " (borrowed
  343.      from [deleted] deprecated_add_show_from_set).  */
  344.   if (   c->doc[0] == 'W'
  345.       && c->doc[1] == 'r'
  346.       && c->doc[2] == 'i'
  347.       && c->doc[3] == 't'
  348.       && c->doc[4] == 'e'
  349.       && c->doc[5] == ' ')
  350.     c->doc = concat ("Append ", c->doc + 6, (char *)NULL);
  351. }

  352. /* Opaque data for restore_section_callback.  */
  353. struct callback_data {
  354.   CORE_ADDR load_offset;
  355.   CORE_ADDR load_start;
  356.   CORE_ADDR load_end;
  357. };

  358. /* Function: restore_section_callback.

  359.    Callback function for bfd_map_over_sections.
  360.    Selectively loads the sections into memory.  */

  361. static void
  362. restore_section_callback (bfd *ibfd, asection *isec, void *args)
  363. {
  364.   struct callback_data *data = args;
  365.   bfd_vma sec_start  = bfd_section_vma (ibfd, isec);
  366.   bfd_size_type size = bfd_section_size (ibfd, isec);
  367.   bfd_vma sec_end    = sec_start + size;
  368.   bfd_size_type sec_offset = 0;
  369.   bfd_size_type sec_load_count = size;
  370.   struct cleanup *old_chain;
  371.   gdb_byte *buf;
  372.   int ret;

  373.   /* Ignore non-loadable sections, eg. from elf files.  */
  374.   if (!(bfd_get_section_flags (ibfd, isec) & SEC_LOAD))
  375.     return;

  376.   /* Does the section overlap with the desired restore range? */
  377.   if (sec_end <= data->load_start
  378.       || (data->load_end > 0 && sec_start >= data->load_end))
  379.     {
  380.       /* No, no useable data in this section.  */
  381.       printf_filtered (_("skipping section %s...\n"),
  382.                        bfd_section_name (ibfd, isec));
  383.       return;
  384.     }

  385.   /* Compare section address range with user-requested
  386.      address range (if any).  Compute where the actual
  387.      transfer should start and end.  */
  388.   if (sec_start < data->load_start)
  389.     sec_offset = data->load_start - sec_start;
  390.   /* Size of a partial transfer.  */
  391.   sec_load_count -= sec_offset;
  392.   if (data->load_end > 0 && sec_end > data->load_end)
  393.     sec_load_count -= sec_end - data->load_end;

  394.   /* Get the data.  */
  395.   buf = xmalloc (size);
  396.   old_chain = make_cleanup (xfree, buf);
  397.   if (!bfd_get_section_contents (ibfd, isec, buf, 0, size))
  398.     error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
  399.            bfd_errmsg (bfd_get_error ()));

  400.   printf_filtered ("Restoring section %s (0x%lx to 0x%lx)",
  401.                    bfd_section_name (ibfd, isec),
  402.                    (unsigned long) sec_start,
  403.                    (unsigned long) sec_end);

  404.   if (data->load_offset != 0 || data->load_start != 0 || data->load_end != 0)
  405.     printf_filtered (" into memory (%s to %s)\n",
  406.                      paddress (target_gdbarch (),
  407.                                (unsigned long) sec_start
  408.                                + sec_offset + data->load_offset),
  409.                      paddress (target_gdbarch (),
  410.                                (unsigned long) sec_start + sec_offset
  411.                                 + data->load_offset + sec_load_count));
  412.   else
  413.     puts_filtered ("\n");

  414.   /* Write the data.  */
  415.   ret = target_write_memory (sec_start + sec_offset + data->load_offset,
  416.                              buf + sec_offset, sec_load_count);
  417.   if (ret != 0)
  418.     warning (_("restore: memory write failed (%s)."), safe_strerror (ret));
  419.   do_cleanups (old_chain);
  420.   return;
  421. }

  422. static void
  423. restore_binary_file (const char *filename, struct callback_data *data)
  424. {
  425.   struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
  426.   FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
  427.   gdb_byte *buf;
  428.   long len;

  429.   /* Get the file size for reading.  */
  430.   if (fseek (file, 0, SEEK_END) == 0)
  431.     {
  432.       len = ftell (file);
  433.       if (len < 0)
  434.         perror_with_name (filename);
  435.     }
  436.   else
  437.     perror_with_name (filename);

  438.   if (len <= data->load_start)
  439.     error (_("Start address is greater than length of binary file %s."),
  440.            filename);

  441.   /* Chop off "len" if it exceeds the requested load_end addr.  */
  442.   if (data->load_end != 0 && data->load_end < len)
  443.     len = data->load_end;
  444.   /* Chop off "len" if the requested load_start addr skips some bytes.  */
  445.   if (data->load_start > 0)
  446.     len -= data->load_start;

  447.   printf_filtered
  448.     ("Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
  449.      filename,
  450.      (unsigned long) (data->load_start + data->load_offset),
  451.      (unsigned long) (data->load_start + data->load_offset + len));

  452.   /* Now set the file pos to the requested load start pos.  */
  453.   if (fseek (file, data->load_start, SEEK_SET) != 0)
  454.     perror_with_name (filename);

  455.   /* Now allocate a buffer and read the file contents.  */
  456.   buf = xmalloc (len);
  457.   make_cleanup (xfree, buf);
  458.   if (fread (buf, 1, len, file) != len)
  459.     perror_with_name (filename);

  460.   /* Now write the buffer into target memory.  */
  461.   len = target_write_memory (data->load_start + data->load_offset, buf, len);
  462.   if (len != 0)
  463.     warning (_("restore: memory write failed (%s)."), safe_strerror (len));
  464.   do_cleanups (cleanup);
  465. }

  466. static void
  467. restore_command (char *args_in, int from_tty)
  468. {
  469.   char *filename;
  470.   struct callback_data data;
  471.   bfd *ibfd;
  472.   int binary_flag = 0;
  473.   const char *args = args_in;

  474.   if (!target_has_execution)
  475.     noprocess ();

  476.   data.load_offset = 0;
  477.   data.load_start  = 0;
  478.   data.load_end    = 0;

  479.   /* Parse the input arguments.  First is filename (required).  */
  480.   filename = scan_filename_with_cleanup (&args, NULL);
  481.   if (args != NULL && *args != '\0')
  482.     {
  483.       char *binary_string = "binary";

  484.       /* Look for optional "binary" flag.  */
  485.       if (strncmp (args, binary_string, strlen (binary_string)) == 0)
  486.         {
  487.           binary_flag = 1;
  488.           args += strlen (binary_string);
  489.           args = skip_spaces_const (args);
  490.         }
  491.       /* Parse offset (optional).  */
  492.       if (args != NULL && *args != '\0')
  493.       data.load_offset =
  494.         parse_and_eval_address (scan_expression_with_cleanup (&args, NULL));
  495.       if (args != NULL && *args != '\0')
  496.         {
  497.           /* Parse start address (optional).  */
  498.           data.load_start =
  499.             parse_and_eval_long (scan_expression_with_cleanup (&args, NULL));
  500.           if (args != NULL && *args != '\0')
  501.             {
  502.               /* Parse end address (optional).  */
  503.               data.load_end = parse_and_eval_long (args);
  504.               if (data.load_end <= data.load_start)
  505.                 error (_("Start must be less than end."));
  506.             }
  507.         }
  508.     }

  509.   if (info_verbose)
  510.     printf_filtered ("Restore file %s offset 0x%lx start 0x%lx end 0x%lx\n",
  511.                      filename, (unsigned long) data.load_offset,
  512.                      (unsigned long) data.load_start,
  513.                      (unsigned long) data.load_end);

  514.   if (binary_flag)
  515.     {
  516.       restore_binary_file (filename, &data);
  517.     }
  518.   else
  519.     {
  520.       /* Open the file for loading.  */
  521.       ibfd = bfd_openr_with_cleanup (filename, NULL);

  522.       /* Process the sections.  */
  523.       bfd_map_over_sections (ibfd, restore_section_callback, &data);
  524.     }
  525.   return;
  526. }

  527. static void
  528. srec_dump_command (char *cmd, int from_tty)
  529. {
  530.   printf_unfiltered ("\"dump srec\" must be followed by a subcommand.\n");
  531.   help_list (srec_cmdlist, "dump srec ", all_commands, gdb_stdout);
  532. }

  533. static void
  534. ihex_dump_command (char *cmd, int from_tty)
  535. {
  536.   printf_unfiltered ("\"dump ihex\" must be followed by a subcommand.\n");
  537.   help_list (ihex_cmdlist, "dump ihex ", all_commands, gdb_stdout);
  538. }

  539. static void
  540. tekhex_dump_command (char *cmd, int from_tty)
  541. {
  542.   printf_unfiltered ("\"dump tekhex\" must be followed by a subcommand.\n");
  543.   help_list (tekhex_cmdlist, "dump tekhex ", all_commands, gdb_stdout);
  544. }

  545. static void
  546. binary_dump_command (char *cmd, int from_tty)
  547. {
  548.   printf_unfiltered ("\"dump binary\" must be followed by a subcommand.\n");
  549.   help_list (binary_dump_cmdlist, "dump binary ", all_commands, gdb_stdout);
  550. }

  551. static void
  552. binary_append_command (char *cmd, int from_tty)
  553. {
  554.   printf_unfiltered ("\"append binary\" must be followed by a subcommand.\n");
  555.   help_list (binary_append_cmdlist, "append binary ", all_commands,
  556.              gdb_stdout);
  557. }

  558. extern initialize_file_ftype _initialize_cli_dump; /* -Wmissing-prototypes */

  559. void
  560. _initialize_cli_dump (void)
  561. {
  562.   struct cmd_list_element *c;

  563.   add_prefix_cmd ("dump", class_vars, dump_command,
  564.                   _("Dump target code/data to a local file."),
  565.                   &dump_cmdlist, "dump ",
  566.                   0/*allow-unknown*/,
  567.                   &cmdlist);
  568.   add_prefix_cmd ("append", class_vars, append_command,
  569.                   _("Append target code/data to a local file."),
  570.                   &append_cmdlist, "append ",
  571.                   0/*allow-unknown*/,
  572.                   &cmdlist);

  573.   add_dump_command ("memory", dump_memory_command, "\
  574. Write contents of memory to a raw binary file.\n\
  575. Arguments are FILE START STOP.  Writes the contents of memory within the\n\
  576. range [START .. STOP) to the specified FILE in raw target ordered bytes.");

  577.   add_dump_command ("value", dump_value_command, "\
  578. Write the value of an expression to a raw binary file.\n\
  579. Arguments are FILE EXPRESSION.  Writes the value of EXPRESSION to\n\
  580. the specified FILE in raw target ordered bytes.");

  581.   add_prefix_cmd ("srec", all_commands, srec_dump_command,
  582.                   _("Write target code/data to an srec file."),
  583.                   &srec_cmdlist, "dump srec ",
  584.                   0 /*allow-unknown*/,
  585.                   &dump_cmdlist);

  586.   add_prefix_cmd ("ihex", all_commands, ihex_dump_command,
  587.                   _("Write target code/data to an intel hex file."),
  588.                   &ihex_cmdlist, "dump ihex ",
  589.                   0 /*allow-unknown*/,
  590.                   &dump_cmdlist);

  591.   add_prefix_cmd ("tekhex", all_commands, tekhex_dump_command,
  592.                   _("Write target code/data to a tekhex file."),
  593.                   &tekhex_cmdlist, "dump tekhex ",
  594.                   0 /*allow-unknown*/,
  595.                   &dump_cmdlist);

  596.   add_prefix_cmd ("binary", all_commands, binary_dump_command,
  597.                   _("Write target code/data to a raw binary file."),
  598.                   &binary_dump_cmdlist, "dump binary ",
  599.                   0 /*allow-unknown*/,
  600.                   &dump_cmdlist);

  601.   add_prefix_cmd ("binary", all_commands, binary_append_command,
  602.                   _("Append target code/data to a raw binary file."),
  603.                   &binary_append_cmdlist, "append binary ",
  604.                   0 /*allow-unknown*/,
  605.                   &append_cmdlist);

  606.   add_cmd ("memory", all_commands, dump_srec_memory, _("\
  607. Write contents of memory to an srec file.\n\
  608. Arguments are FILE START STOP.  Writes the contents of memory\n\
  609. within the range [START .. STOP) to the specified FILE in srec format."),
  610.            &srec_cmdlist);

  611.   add_cmd ("value", all_commands, dump_srec_value, _("\
  612. Write the value of an expression to an srec file.\n\
  613. Arguments are FILE EXPRESSION.  Writes the value of EXPRESSION\n\
  614. to the specified FILE in srec format."),
  615.            &srec_cmdlist);

  616.   add_cmd ("memory", all_commands, dump_ihex_memory, _("\
  617. Write contents of memory to an ihex file.\n\
  618. Arguments are FILE START STOP.  Writes the contents of memory within\n\
  619. the range [START .. STOP) to the specified FILE in intel hex format."),
  620.            &ihex_cmdlist);

  621.   add_cmd ("value", all_commands, dump_ihex_value, _("\
  622. Write the value of an expression to an ihex file.\n\
  623. Arguments are FILE EXPRESSION.  Writes the value of EXPRESSION\n\
  624. to the specified FILE in intel hex format."),
  625.            &ihex_cmdlist);

  626.   add_cmd ("memory", all_commands, dump_tekhex_memory, _("\
  627. Write contents of memory to a tekhex file.\n\
  628. Arguments are FILE START STOP.  Writes the contents of memory\n\
  629. within the range [START .. STOP) to the specified FILE in tekhex format."),
  630.            &tekhex_cmdlist);

  631.   add_cmd ("value", all_commands, dump_tekhex_value, _("\
  632. Write the value of an expression to a tekhex file.\n\
  633. Arguments are FILE EXPRESSION.  Writes the value of EXPRESSION\n\
  634. to the specified FILE in tekhex format."),
  635.            &tekhex_cmdlist);

  636.   add_cmd ("memory", all_commands, dump_binary_memory, _("\
  637. Write contents of memory to a raw binary file.\n\
  638. Arguments are FILE START STOP.  Writes the contents of memory\n\
  639. within the range [START .. STOP) to the specified FILE in binary format."),
  640.            &binary_dump_cmdlist);

  641.   add_cmd ("value", all_commands, dump_binary_value, _("\
  642. Write the value of an expression to a raw binary file.\n\
  643. Arguments are FILE EXPRESSION.  Writes the value of EXPRESSION\n\
  644. to the specified FILE in raw target ordered bytes."),
  645.            &binary_dump_cmdlist);

  646.   add_cmd ("memory", all_commands, append_binary_memory, _("\
  647. Append contents of memory to a raw binary file.\n\
  648. Arguments are FILE START STOP.  Writes the contents of memory within the\n\
  649. range [START .. STOP) to the specified FILE in raw target ordered bytes."),
  650.            &binary_append_cmdlist);

  651.   add_cmd ("value", all_commands, append_binary_value, _("\
  652. Append the value of an expression to a raw binary file.\n\
  653. Arguments are FILE EXPRESSION.  Writes the value of EXPRESSION\n\
  654. to the specified FILE in raw target ordered bytes."),
  655.            &binary_append_cmdlist);

  656.   c = add_com ("restore", class_vars, restore_command, _("\
  657. Restore the contents of FILE to target memory.\n\
  658. Arguments are FILE OFFSET START END where all except FILE are optional.\n\
  659. OFFSET will be added to the base address of the file (default zero).\n\
  660. If START and END are given, only the file contents within that range\n\
  661. (file relative) will be restored to target memory."));
  662.   c->completer = filename_completer;
  663.   /* FIXME: completers for other commands.  */
  664. }