cli-dump.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /* Dump-to-file commands, for GDB, the GNU debugger.
  2. Copyright (C) 2002-2022 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/tilde.h"
  23. #include "gdbcore.h"
  24. #include "cli/cli-utils.h"
  25. #include "gdb_bfd.h"
  26. #include "gdbsupport/filestuff.h"
  27. #include "gdbsupport/byte-vector.h"
  28. #include "gdbarch.h"
  29. static gdb::unique_xmalloc_ptr<char>
  30. scan_expression (const char **cmd, const char *def)
  31. {
  32. if ((*cmd) == NULL || (**cmd) == '\0')
  33. return make_unique_xstrdup (def);
  34. else
  35. {
  36. char *exp;
  37. const char *end;
  38. end = (*cmd) + strcspn (*cmd, " \t");
  39. exp = savestring ((*cmd), end - (*cmd));
  40. (*cmd) = skip_spaces (end);
  41. return gdb::unique_xmalloc_ptr<char> (exp);
  42. }
  43. }
  44. static gdb::unique_xmalloc_ptr<char>
  45. scan_filename (const char **cmd, const char *defname)
  46. {
  47. gdb::unique_xmalloc_ptr<char> filename;
  48. /* FIXME: Need to get the ``/a(ppend)'' flag from somewhere. */
  49. /* File. */
  50. if ((*cmd) == NULL)
  51. {
  52. if (defname == NULL)
  53. error (_("Missing filename."));
  54. filename.reset (xstrdup (defname));
  55. }
  56. else
  57. {
  58. /* FIXME: should parse a possibly quoted string. */
  59. const char *end;
  60. (*cmd) = skip_spaces (*cmd);
  61. end = *cmd + strcspn (*cmd, " \t");
  62. filename.reset (savestring ((*cmd), end - (*cmd)));
  63. (*cmd) = skip_spaces (end);
  64. }
  65. gdb_assert (filename != NULL);
  66. return gdb::unique_xmalloc_ptr<char> (tilde_expand (filename.get ()));
  67. }
  68. static gdb_bfd_ref_ptr
  69. bfd_openr_or_error (const char *filename, const char *target)
  70. {
  71. gdb_bfd_ref_ptr ibfd (gdb_bfd_openr (filename, target));
  72. if (ibfd == NULL)
  73. error (_("Failed to open %s: %s."), filename,
  74. bfd_errmsg (bfd_get_error ()));
  75. if (!bfd_check_format (ibfd.get (), bfd_object))
  76. error (_("'%s' is not a recognized file format."), filename);
  77. return ibfd;
  78. }
  79. static gdb_bfd_ref_ptr
  80. bfd_openw_or_error (const char *filename, const char *target, const char *mode)
  81. {
  82. gdb_bfd_ref_ptr obfd;
  83. if (*mode == 'w') /* Write: create new file */
  84. {
  85. obfd = gdb_bfd_openw (filename, target);
  86. if (obfd == NULL)
  87. error (_("Failed to open %s: %s."), filename,
  88. bfd_errmsg (bfd_get_error ()));
  89. if (!bfd_set_format (obfd.get (), bfd_object))
  90. error (_("bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
  91. }
  92. else if (*mode == 'a') /* Append to existing file. */
  93. { /* FIXME -- doesn't work... */
  94. error (_("bfd_openw does not work with append."));
  95. }
  96. else
  97. error (_("bfd_openw_or_error: unknown mode %s."), mode);
  98. return obfd;
  99. }
  100. static struct cmd_list_element *dump_cmdlist;
  101. static struct cmd_list_element *append_cmdlist;
  102. static struct cmd_list_element *srec_cmdlist;
  103. static struct cmd_list_element *ihex_cmdlist;
  104. static struct cmd_list_element *verilog_cmdlist;
  105. static struct cmd_list_element *tekhex_cmdlist;
  106. static struct cmd_list_element *binary_dump_cmdlist;
  107. static struct cmd_list_element *binary_append_cmdlist;
  108. static void
  109. dump_binary_file (const char *filename, const char *mode,
  110. const bfd_byte *buf, ULONGEST len)
  111. {
  112. int status;
  113. gdb_file_up file = gdb_fopen_cloexec (filename, mode);
  114. if (file == nullptr)
  115. perror_with_name (filename);
  116. status = fwrite (buf, len, 1, file.get ());
  117. if (status != 1)
  118. perror_with_name (filename);
  119. }
  120. static void
  121. dump_bfd_file (const char *filename, const char *mode,
  122. const char *target, CORE_ADDR vaddr,
  123. const bfd_byte *buf, ULONGEST len)
  124. {
  125. asection *osection;
  126. gdb_bfd_ref_ptr obfd (bfd_openw_or_error (filename, target, mode));
  127. osection = bfd_make_section_anyway (obfd.get (), ".newsec");
  128. bfd_set_section_size (osection, len);
  129. bfd_set_section_vma (osection, vaddr);
  130. bfd_set_section_alignment (osection, 0);
  131. bfd_set_section_flags (osection, (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD));
  132. osection->entsize = 0;
  133. if (!bfd_set_section_contents (obfd.get (), osection, buf, 0, len))
  134. warning (_("writing dump file '%s' (%s)"), filename,
  135. bfd_errmsg (bfd_get_error ()));
  136. }
  137. static void
  138. dump_memory_to_file (const char *cmd, const char *mode, const char *file_format)
  139. {
  140. CORE_ADDR lo;
  141. CORE_ADDR hi;
  142. ULONGEST count;
  143. const char *hi_exp;
  144. /* Open the file. */
  145. gdb::unique_xmalloc_ptr<char> filename = scan_filename (&cmd, NULL);
  146. /* Find the low address. */
  147. if (cmd == NULL || *cmd == '\0')
  148. error (_("Missing start address."));
  149. gdb::unique_xmalloc_ptr<char> lo_exp = scan_expression (&cmd, NULL);
  150. /* Find the second address - rest of line. */
  151. if (cmd == NULL || *cmd == '\0')
  152. error (_("Missing stop address."));
  153. hi_exp = cmd;
  154. lo = parse_and_eval_address (lo_exp.get ());
  155. hi = parse_and_eval_address (hi_exp);
  156. if (hi <= lo)
  157. error (_("Invalid memory address range (start >= end)."));
  158. count = hi - lo;
  159. /* FIXME: Should use read_memory_partial() and a magic blocking
  160. value. */
  161. gdb::byte_vector buf (count);
  162. read_memory (lo, buf.data (), count);
  163. /* Have everything. Open/write the data. */
  164. if (file_format == NULL || strcmp (file_format, "binary") == 0)
  165. dump_binary_file (filename.get (), mode, buf.data (), count);
  166. else
  167. dump_bfd_file (filename.get (), mode, file_format, lo, buf.data (), count);
  168. }
  169. static void
  170. dump_memory_command (const char *cmd, const char *mode)
  171. {
  172. dump_memory_to_file (cmd, mode, "binary");
  173. }
  174. static void
  175. dump_value_to_file (const char *cmd, const char *mode, const char *file_format)
  176. {
  177. struct value *val;
  178. /* Open the file. */
  179. gdb::unique_xmalloc_ptr<char> filename = scan_filename (&cmd, NULL);
  180. /* Find the value. */
  181. if (cmd == NULL || *cmd == '\0')
  182. error (_("No value to %s."), *mode == 'a' ? "append" : "dump");
  183. val = parse_and_eval (cmd);
  184. if (val == NULL)
  185. error (_("Invalid expression."));
  186. /* Have everything. Open/write the data. */
  187. if (file_format == NULL || strcmp (file_format, "binary") == 0)
  188. dump_binary_file (filename.get (), mode, value_contents (val).data (),
  189. TYPE_LENGTH (value_type (val)));
  190. else
  191. {
  192. CORE_ADDR vaddr;
  193. if (VALUE_LVAL (val))
  194. {
  195. vaddr = value_address (val);
  196. }
  197. else
  198. {
  199. vaddr = 0;
  200. warning (_("value is not an lval: address assumed to be zero"));
  201. }
  202. dump_bfd_file (filename.get (), mode, file_format, vaddr,
  203. value_contents (val).data (),
  204. TYPE_LENGTH (value_type (val)));
  205. }
  206. }
  207. static void
  208. dump_value_command (const char *cmd, const char *mode)
  209. {
  210. dump_value_to_file (cmd, mode, "binary");
  211. }
  212. static void
  213. dump_srec_memory (const char *args, int from_tty)
  214. {
  215. dump_memory_to_file (args, FOPEN_WB, "srec");
  216. }
  217. static void
  218. dump_srec_value (const char *args, int from_tty)
  219. {
  220. dump_value_to_file (args, FOPEN_WB, "srec");
  221. }
  222. static void
  223. dump_ihex_memory (const char *args, int from_tty)
  224. {
  225. dump_memory_to_file (args, FOPEN_WB, "ihex");
  226. }
  227. static void
  228. dump_ihex_value (const char *args, int from_tty)
  229. {
  230. dump_value_to_file (args, FOPEN_WB, "ihex");
  231. }
  232. static void
  233. dump_verilog_memory (const char *args, int from_tty)
  234. {
  235. dump_memory_to_file (args, FOPEN_WB, "verilog");
  236. }
  237. static void
  238. dump_verilog_value (const char *args, int from_tty)
  239. {
  240. dump_value_to_file (args, FOPEN_WB, "verilog");
  241. }
  242. static void
  243. dump_tekhex_memory (const char *args, int from_tty)
  244. {
  245. dump_memory_to_file (args, FOPEN_WB, "tekhex");
  246. }
  247. static void
  248. dump_tekhex_value (const char *args, int from_tty)
  249. {
  250. dump_value_to_file (args, FOPEN_WB, "tekhex");
  251. }
  252. static void
  253. dump_binary_memory (const char *args, int from_tty)
  254. {
  255. dump_memory_to_file (args, FOPEN_WB, "binary");
  256. }
  257. static void
  258. dump_binary_value (const char *args, int from_tty)
  259. {
  260. dump_value_to_file (args, FOPEN_WB, "binary");
  261. }
  262. static void
  263. append_binary_memory (const char *args, int from_tty)
  264. {
  265. dump_memory_to_file (args, FOPEN_AB, "binary");
  266. }
  267. static void
  268. append_binary_value (const char *args, int from_tty)
  269. {
  270. dump_value_to_file (args, FOPEN_AB, "binary");
  271. }
  272. struct dump_context
  273. {
  274. void (*func) (const char *cmd, const char *mode);
  275. const char *mode;
  276. };
  277. static void
  278. call_dump_func (const char *args, int from_tty, cmd_list_element *c)
  279. {
  280. struct dump_context *d = (struct dump_context *) c->context ();
  281. d->func (args, d->mode);
  282. }
  283. static void
  284. add_dump_command (const char *name,
  285. void (*func) (const char *args, const char *mode),
  286. const char *descr)
  287. {
  288. struct cmd_list_element *c;
  289. struct dump_context *d;
  290. c = add_cmd (name, all_commands, descr, &dump_cmdlist);
  291. c->completer = filename_completer;
  292. d = XNEW (struct dump_context);
  293. d->func = func;
  294. d->mode = FOPEN_WB;
  295. c->set_context (d);
  296. c->func = call_dump_func;
  297. c = add_cmd (name, all_commands, descr, &append_cmdlist);
  298. c->completer = filename_completer;
  299. d = XNEW (struct dump_context);
  300. d->func = func;
  301. d->mode = FOPEN_AB;
  302. c->set_context (d);
  303. c->func = call_dump_func;
  304. /* Replace "Dump " at start of docstring with "Append " (borrowed
  305. from [deleted] deprecated_add_show_from_set). */
  306. if ( c->doc[0] == 'W'
  307. && c->doc[1] == 'r'
  308. && c->doc[2] == 'i'
  309. && c->doc[3] == 't'
  310. && c->doc[4] == 'e'
  311. && c->doc[5] == ' ')
  312. c->doc = concat ("Append ", c->doc + 6, (char *)NULL);
  313. }
  314. /* Selectively loads the sections into memory. */
  315. static void
  316. restore_one_section (bfd *ibfd, asection *isec,
  317. CORE_ADDR load_offset,
  318. CORE_ADDR load_start,
  319. CORE_ADDR load_end)
  320. {
  321. bfd_vma sec_start = bfd_section_vma (isec);
  322. bfd_size_type size = bfd_section_size (isec);
  323. bfd_vma sec_end = sec_start + size;
  324. bfd_size_type sec_offset = 0;
  325. bfd_size_type sec_load_count = size;
  326. int ret;
  327. /* Ignore non-loadable sections, eg. from elf files. */
  328. if (!(bfd_section_flags (isec) & SEC_LOAD))
  329. return;
  330. /* Does the section overlap with the desired restore range? */
  331. if (sec_end <= load_start
  332. || (load_end > 0 && sec_start >= load_end))
  333. {
  334. /* No, no useable data in this section. */
  335. gdb_printf (_("skipping section %s...\n"),
  336. bfd_section_name (isec));
  337. return;
  338. }
  339. /* Compare section address range with user-requested
  340. address range (if any). Compute where the actual
  341. transfer should start and end. */
  342. if (sec_start < load_start)
  343. sec_offset = load_start - sec_start;
  344. /* Size of a partial transfer. */
  345. sec_load_count -= sec_offset;
  346. if (load_end > 0 && sec_end > load_end)
  347. sec_load_count -= sec_end - load_end;
  348. /* Get the data. */
  349. gdb::byte_vector buf (size);
  350. if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size))
  351. error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
  352. bfd_errmsg (bfd_get_error ()));
  353. gdb_printf ("Restoring section %s (0x%lx to 0x%lx)",
  354. bfd_section_name (isec),
  355. (unsigned long) sec_start,
  356. (unsigned long) sec_end);
  357. if (load_offset != 0 || load_start != 0 || load_end != 0)
  358. gdb_printf (" into memory (%s to %s)\n",
  359. paddress (target_gdbarch (),
  360. (unsigned long) sec_start
  361. + sec_offset + load_offset),
  362. paddress (target_gdbarch (),
  363. (unsigned long) sec_start + sec_offset
  364. + load_offset + sec_load_count));
  365. else
  366. gdb_puts ("\n");
  367. /* Write the data. */
  368. ret = target_write_memory (sec_start + sec_offset + load_offset,
  369. &buf[sec_offset], sec_load_count);
  370. if (ret != 0)
  371. warning (_("restore: memory write failed (%s)."), safe_strerror (ret));
  372. }
  373. static void
  374. restore_binary_file (const char *filename, CORE_ADDR load_offset,
  375. CORE_ADDR load_start, CORE_ADDR load_end)
  376. {
  377. gdb_file_up file = gdb_fopen_cloexec (filename, FOPEN_RB);
  378. long len;
  379. if (file == NULL)
  380. error (_("Failed to open %s: %s"), filename, safe_strerror (errno));
  381. /* Get the file size for reading. */
  382. if (fseek (file.get (), 0, SEEK_END) == 0)
  383. {
  384. len = ftell (file.get ());
  385. if (len < 0)
  386. perror_with_name (filename);
  387. }
  388. else
  389. perror_with_name (filename);
  390. if (len <= load_start)
  391. error (_("Start address is greater than length of binary file %s."),
  392. filename);
  393. /* Chop off "len" if it exceeds the requested load_end addr. */
  394. if (load_end != 0 && load_end < len)
  395. len = load_end;
  396. /* Chop off "len" if the requested load_start addr skips some bytes. */
  397. if (load_start > 0)
  398. len -= load_start;
  399. gdb_printf
  400. ("Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
  401. filename,
  402. (unsigned long) (load_start + load_offset),
  403. (unsigned long) (load_start + load_offset + len));
  404. /* Now set the file pos to the requested load start pos. */
  405. if (fseek (file.get (), load_start, SEEK_SET) != 0)
  406. perror_with_name (filename);
  407. /* Now allocate a buffer and read the file contents. */
  408. gdb::byte_vector buf (len);
  409. if (fread (buf.data (), 1, len, file.get ()) != len)
  410. perror_with_name (filename);
  411. /* Now write the buffer into target memory. */
  412. len = target_write_memory (load_start + load_offset, buf.data (), len);
  413. if (len != 0)
  414. warning (_("restore: memory write failed (%s)."), safe_strerror (len));
  415. }
  416. static void
  417. restore_command (const char *args, int from_tty)
  418. {
  419. int binary_flag = 0;
  420. if (!target_has_execution ())
  421. noprocess ();
  422. CORE_ADDR load_offset = 0;
  423. CORE_ADDR load_start = 0;
  424. CORE_ADDR load_end = 0;
  425. /* Parse the input arguments. First is filename (required). */
  426. gdb::unique_xmalloc_ptr<char> filename = scan_filename (&args, NULL);
  427. if (args != NULL && *args != '\0')
  428. {
  429. static const char binary_string[] = "binary";
  430. /* Look for optional "binary" flag. */
  431. if (startswith (args, binary_string))
  432. {
  433. binary_flag = 1;
  434. args += strlen (binary_string);
  435. args = skip_spaces (args);
  436. }
  437. /* Parse offset (optional). */
  438. if (args != NULL && *args != '\0')
  439. load_offset
  440. = (binary_flag
  441. ? parse_and_eval_address (scan_expression (&args, NULL).get ())
  442. : parse_and_eval_long (scan_expression (&args, NULL).get ()));
  443. if (args != NULL && *args != '\0')
  444. {
  445. /* Parse start address (optional). */
  446. load_start =
  447. parse_and_eval_long (scan_expression (&args, NULL).get ());
  448. if (args != NULL && *args != '\0')
  449. {
  450. /* Parse end address (optional). */
  451. load_end = parse_and_eval_long (args);
  452. if (load_end <= load_start)
  453. error (_("Start must be less than end."));
  454. }
  455. }
  456. }
  457. if (info_verbose)
  458. gdb_printf ("Restore file %s offset 0x%lx start 0x%lx end 0x%lx\n",
  459. filename.get (), (unsigned long) load_offset,
  460. (unsigned long) load_start,
  461. (unsigned long) load_end);
  462. if (binary_flag)
  463. {
  464. restore_binary_file (filename.get (), load_offset, load_start,
  465. load_end);
  466. }
  467. else
  468. {
  469. /* Open the file for loading. */
  470. gdb_bfd_ref_ptr ibfd (bfd_openr_or_error (filename.get (), NULL));
  471. /* Process the sections. */
  472. for (asection *sect : gdb_bfd_sections (ibfd))
  473. restore_one_section (ibfd.get (), sect, load_offset, load_start,
  474. load_end);
  475. }
  476. }
  477. void _initialize_cli_dump ();
  478. void
  479. _initialize_cli_dump ()
  480. {
  481. struct cmd_list_element *c;
  482. add_basic_prefix_cmd ("dump", class_vars,
  483. _("Dump target code/data to a local file."),
  484. &dump_cmdlist,
  485. 0/*allow-unknown*/,
  486. &cmdlist);
  487. add_basic_prefix_cmd ("append", class_vars,
  488. _("Append target code/data to a local file."),
  489. &append_cmdlist,
  490. 0/*allow-unknown*/,
  491. &cmdlist);
  492. add_dump_command ("memory", dump_memory_command, "\
  493. Write contents of memory to a raw binary file.\n\
  494. Arguments are FILE START STOP. Writes the contents of memory within the\n\
  495. range [START .. STOP) to the specified FILE in raw target ordered bytes.");
  496. add_dump_command ("value", dump_value_command, "\
  497. Write the value of an expression to a raw binary file.\n\
  498. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION to\n\
  499. the specified FILE in raw target ordered bytes.");
  500. add_basic_prefix_cmd ("srec", all_commands,
  501. _("Write target code/data to an srec file."),
  502. &srec_cmdlist,
  503. 0 /*allow-unknown*/,
  504. &dump_cmdlist);
  505. add_basic_prefix_cmd ("ihex", all_commands,
  506. _("Write target code/data to an intel hex file."),
  507. &ihex_cmdlist,
  508. 0 /*allow-unknown*/,
  509. &dump_cmdlist);
  510. add_basic_prefix_cmd ("verilog", all_commands,
  511. _("Write target code/data to a verilog hex file."),
  512. &verilog_cmdlist,
  513. 0 /*allow-unknown*/,
  514. &dump_cmdlist);
  515. add_basic_prefix_cmd ("tekhex", all_commands,
  516. _("Write target code/data to a tekhex file."),
  517. &tekhex_cmdlist,
  518. 0 /*allow-unknown*/,
  519. &dump_cmdlist);
  520. add_basic_prefix_cmd ("binary", all_commands,
  521. _("Write target code/data to a raw binary file."),
  522. &binary_dump_cmdlist,
  523. 0 /*allow-unknown*/,
  524. &dump_cmdlist);
  525. add_basic_prefix_cmd ("binary", all_commands,
  526. _("Append target code/data to a raw binary file."),
  527. &binary_append_cmdlist,
  528. 0 /*allow-unknown*/,
  529. &append_cmdlist);
  530. add_cmd ("memory", all_commands, dump_srec_memory, _("\
  531. Write contents of memory to an srec file.\n\
  532. Arguments are FILE START STOP. Writes the contents of memory\n\
  533. within the range [START .. STOP) to the specified FILE in srec format."),
  534. &srec_cmdlist);
  535. add_cmd ("value", all_commands, dump_srec_value, _("\
  536. Write the value of an expression to an srec file.\n\
  537. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
  538. to the specified FILE in srec format."),
  539. &srec_cmdlist);
  540. add_cmd ("memory", all_commands, dump_ihex_memory, _("\
  541. Write contents of memory to an ihex file.\n\
  542. Arguments are FILE START STOP. Writes the contents of memory within\n\
  543. the range [START .. STOP) to the specified FILE in intel hex format."),
  544. &ihex_cmdlist);
  545. add_cmd ("value", all_commands, dump_ihex_value, _("\
  546. Write the value of an expression to an ihex file.\n\
  547. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
  548. to the specified FILE in intel hex format."),
  549. &ihex_cmdlist);
  550. add_cmd ("memory", all_commands, dump_verilog_memory, _("\
  551. Write contents of memory to a verilog hex file.\n\
  552. Arguments are FILE START STOP. Writes the contents of memory within\n\
  553. the range [START .. STOP) to the specified FILE in verilog hex format."),
  554. &verilog_cmdlist);
  555. add_cmd ("value", all_commands, dump_verilog_value, _("\
  556. Write the value of an expression to a verilog hex file.\n\
  557. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
  558. to the specified FILE in verilog hex format."),
  559. &verilog_cmdlist);
  560. add_cmd ("memory", all_commands, dump_tekhex_memory, _("\
  561. Write contents of memory to a tekhex file.\n\
  562. Arguments are FILE START STOP. Writes the contents of memory\n\
  563. within the range [START .. STOP) to the specified FILE in tekhex format."),
  564. &tekhex_cmdlist);
  565. add_cmd ("value", all_commands, dump_tekhex_value, _("\
  566. Write the value of an expression to a tekhex file.\n\
  567. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
  568. to the specified FILE in tekhex format."),
  569. &tekhex_cmdlist);
  570. add_cmd ("memory", all_commands, dump_binary_memory, _("\
  571. Write contents of memory to a raw binary file.\n\
  572. Arguments are FILE START STOP. Writes the contents of memory\n\
  573. within the range [START .. STOP) to the specified FILE in binary format."),
  574. &binary_dump_cmdlist);
  575. add_cmd ("value", all_commands, dump_binary_value, _("\
  576. Write the value of an expression to a raw binary file.\n\
  577. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
  578. to the specified FILE in raw target ordered bytes."),
  579. &binary_dump_cmdlist);
  580. add_cmd ("memory", all_commands, append_binary_memory, _("\
  581. Append contents of memory to a raw binary file.\n\
  582. Arguments are FILE START STOP. Writes the contents of memory within the\n\
  583. range [START .. STOP) to the specified FILE in raw target ordered bytes."),
  584. &binary_append_cmdlist);
  585. add_cmd ("value", all_commands, append_binary_value, _("\
  586. Append the value of an expression to a raw binary file.\n\
  587. Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
  588. to the specified FILE in raw target ordered bytes."),
  589. &binary_append_cmdlist);
  590. c = add_com ("restore", class_vars, restore_command, _("\
  591. Restore the contents of FILE to target memory.\n\
  592. Arguments are FILE OFFSET START END where all except FILE are optional.\n\
  593. OFFSET will be added to the base address of the file (default zero).\n\
  594. If START and END are given, only the file contents within that range\n\
  595. (file relative) will be restored to target memory."));
  596. c->completer = filename_completer;
  597. /* FIXME: completers for other commands. */
  598. }