29 #include "readline/readline.h" 39 if ((*cmd) == NULL || (**cmd) ==
'\0')
46 end = (*cmd) + strcspn (*cmd,
" \t");
65 error (
_(
"Missing filename."));
66 filename.reset (xstrdup (defname));
74 end = *cmd + strcspn (*cmd,
" \t");
75 filename.reset (
savestring ((*cmd), end - (*cmd)));
88 error (
_(
"Failed to open %s: %s."), filename,
89 bfd_errmsg (bfd_get_error ()));
91 if (!bfd_check_format (ibfd.
get (), bfd_object))
92 error (
_(
"'%s' is not a recognized file format."), filename);
106 error (
_(
"Failed to open %s: %s."), filename,
107 bfd_errmsg (bfd_get_error ()));
108 if (!bfd_set_format (obfd.
get (), bfd_object))
109 error (
_(
"bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
111 else if (*mode ==
'a')
113 error (
_(
"bfd_openw does not work with append."));
116 error (
_(
"bfd_openw_or_error: unknown mode %s."), mode);
151 status = fwrite (buf, len, 1, file.get ());
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
171 osection->entsize = 0;
172 if (!bfd_set_section_contents (obfd.
get (), osection, buf, 0, len))
173 warning (
_(
"writing dump file '%s' (%s)"), filename,
174 bfd_errmsg (bfd_get_error ()));
189 if (cmd == NULL || *cmd ==
'\0')
190 error (
_(
"Missing start address."));
194 if (cmd == NULL || *cmd ==
'\0')
195 error (
_(
"Missing stop address."));
201 error (
_(
"Invalid memory address range (start >= end)."));
210 if (file_format == NULL || strcmp (file_format,
"binary") == 0)
213 dump_bfd_file (filename.get (), mode, file_format, lo, buf.data (), count);
231 if (cmd == NULL || *cmd ==
'\0')
232 error (
_(
"No value to %s."), *mode ==
'a' ?
"append" :
"dump");
235 error (
_(
"Invalid expression."));
238 if (file_format == NULL || strcmp (file_format,
"binary") == 0)
252 warning (
_(
"value is not an lval: address assumed to be zero"));
355 void (*
func) (
const char *args,
const char *
mode),
380 if ( c->
doc[0] ==
'W' 386 c->
doc = concat (
"Append ", c->
doc + 6, (
char *)NULL);
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;
413 if (!(bfd_get_section_flags (ibfd, isec) & SEC_LOAD))
422 bfd_section_name (ibfd, isec));
432 sec_load_count -= sec_offset;
434 sec_load_count -= sec_end - data->
load_end;
438 if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0,
size))
439 error (
_(
"Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
440 bfd_errmsg (bfd_get_error ()));
443 bfd_section_name (ibfd, isec),
444 (
unsigned long) sec_start,
445 (
unsigned long) sec_end);
450 (
unsigned long) sec_start
453 (
unsigned long) sec_start + sec_offset
460 &buf[sec_offset], sec_load_count);
472 if (fseek (file.get (), 0, SEEK_END) == 0)
474 len = ftell (file.get ());
482 error (
_(
"Start address is greater than length of binary file %s."),
493 (
"Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
504 if (fread (buf.data (), 1, len, file.get ()) != len)
529 if (args != NULL && *args !=
'\0')
531 static const char binary_string[] =
"binary";
537 args += strlen (binary_string);
541 if (args != NULL && *args !=
'\0')
545 if (args != NULL && *args !=
'\0')
550 if (args != NULL && *args !=
'\0')
555 error (
_(
"Start must be less than end."));
561 printf_filtered (
"Restore file %s offset 0x%lx start 0x%lx end 0x%lx\n",
629 _(
"Dump target code/data to a local file."),
634 _(
"Append target code/data to a local file."),
640 Write contents of memory to a raw binary file.\n\ 641 Arguments are FILE START STOP. Writes the contents of memory within the\n\ 642 range [START .. STOP) to the specified FILE in raw target ordered bytes.");
645 Write the value of an expression to a raw binary file.\n\ 646 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION to\n\ 647 the specified FILE in raw target ordered bytes.");
650 _(
"Write target code/data to an srec file."),
656 _(
"Write target code/data to an intel hex file."),
662 _(
"Write target code/data to a verilog hex file."),
668 _(
"Write target code/data to a tekhex file."),
674 _(
"Write target code/data to a raw binary file."),
680 _(
"Append target code/data to a raw binary file."),
686 Write contents of memory to an srec file.\n\ 687 Arguments are FILE START STOP. Writes the contents of memory\n\ 688 within the range [START .. STOP) to the specified FILE in srec format."),
692 Write the value of an expression to an srec file.\n\ 693 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ 694 to the specified FILE in srec format."),
698 Write contents of memory to an ihex file.\n\ 699 Arguments are FILE START STOP. Writes the contents of memory within\n\ 700 the range [START .. STOP) to the specified FILE in intel hex format."),
704 Write the value of an expression to an ihex file.\n\ 705 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ 706 to the specified FILE in intel hex format."),
710 Write contents of memory to a verilog hex file.\n\ 711 Arguments are FILE START STOP. Writes the contents of memory within\n\ 712 the range [START .. STOP) to the specified FILE in verilog hex format."),
716 Write the value of an expression to a verilog hex file.\n\ 717 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ 718 to the specified FILE in verilog hex format."),
722 Write contents of memory to a tekhex file.\n\ 723 Arguments are FILE START STOP. Writes the contents of memory\n\ 724 within the range [START .. STOP) to the specified FILE in tekhex format."),
728 Write the value of an expression to a tekhex file.\n\ 729 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ 730 to the specified FILE in tekhex format."),
734 Write contents of memory to a raw binary file.\n\ 735 Arguments are FILE START STOP. Writes the contents of memory\n\ 736 within the range [START .. STOP) to the specified FILE in binary format."),
740 Write the value of an expression to a raw binary file.\n\ 741 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ 742 to the specified FILE in raw target ordered bytes."),
746 Append contents of memory to a raw binary file.\n\ 747 Arguments are FILE START STOP. Writes the contents of memory within the\n\ 748 range [START .. STOP) to the specified FILE in raw target ordered bytes."),
752 Append the value of an expression to a raw binary file.\n\ 753 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\ 754 to the specified FILE in raw target ordered bytes."),
758 Restore the contents of FILE to target memory.\n\ 759 Arguments are FILE OFFSET START END where all except FILE are optional.\n\ 760 OFFSET will be added to the base address of the file (default zero).\n\ 761 If START and END are given, only the file contents within that range\n\ 762 (file relative) will be restored to target memory."));
struct gdbarch * target_gdbarch(void)
void set_cmd_context(struct cmd_list_element *cmd, void *context)
static void dump_binary_value(const char *args, int from_tty)
static gdb::unique_xmalloc_ptr< char > scan_expression(const char **cmd, const char *def)
static struct cmd_list_element * binary_append_cmdlist
static void restore_binary_file(const char *filename, struct callback_data *data)
static void restore_command(const char *args, int from_tty)
void * get_cmd_context(struct cmd_list_element *cmd)
static void dump_ihex_value(const char *args, int from_tty)
static struct cmd_list_element * srec_cmdlist
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
static void dump_srec_value(const char *args, int from_tty)
void warning(const char *fmt,...)
static void restore_section_callback(bfd *ibfd, asection *isec, void *args)
static void binary_dump_command(const char *cmd, int from_tty)
static void dump_tekhex_value(const char *args, int from_tty)
void(* func)(const char *cmd, const char *mode)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
static void dump_bfd_file(const char *filename, const char *mode, const char *target, CORE_ADDR vaddr, const bfd_byte *buf, ULONGEST len)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
static void add_dump_command(const char *name, void(*func)(const char *args, const char *mode), const char *descr)
struct cmd_list_element * cmdlist
char * skip_spaces(char *chp)
static void dump_verilog_memory(const char *args, int from_tty)
static gdb::unique_xmalloc_ptr< char > scan_filename(const char **cmd, const char *defname)
static void dump_value_to_file(const char *cmd, const char *mode, const char *file_format)
static void append_binary_memory(const char *args, int from_tty)
static struct cmd_list_element * verilog_cmdlist
void printf_filtered(const char *format,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
static void verilog_dump_command(const char *cmd, int from_tty)
static void dump_value_command(const char *cmd, const char *mode)
const gdb_byte * value_contents(struct value *value)
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
static struct cmd_list_element * tekhex_cmdlist
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void puts_filtered(const char *string)
static void append_binary_value(const char *args, int from_tty)
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
static int startswith(const char *string, const char *pattern)
void _initialize_cli_dump(void)
#define target_has_execution
static void dump_memory_command(const char *cmd, const char *mode)
static void dump_memory_to_file(const char *cmd, const char *mode, const char *file_format)
void printf_unfiltered(const char *format,...)
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
static struct cmd_list_element * dump_cmdlist
static void srec_dump_command(const char *cmd, int from_tty)
static struct cmd_list_element * binary_dump_cmdlist
static void ihex_dump_command(const char *cmd, int from_tty)
static void dump_verilog_value(const char *args, int from_tty)
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
static void binary_append_command(const char *cmd, int from_tty)
static void call_dump_func(struct cmd_list_element *c, const char *args, int from_tty)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
static void dump_ihex_memory(const char *args, int from_tty)
gdb_bfd_ref_ptr gdb_bfd_openr(const char *filename, const char *target)
CORE_ADDR parse_and_eval_address(const char *exp)
static void dump_tekhex_memory(const char *args, int from_tty)
char * safe_strerror(int)
static void tekhex_dump_command(const char *cmd, int from_tty)
void(* func)(struct cmd_list_element *c, const char *args, int from_tty)
gdb::def_vector< gdb_byte > byte_vector
struct value * parse_and_eval(const char *exp)
unsigned long long ULONGEST
char * savestring(const char *ptr, size_t len)
struct type * value_type(const struct value *value)
gdb_bfd_ref_ptr gdb_bfd_openw(const char *filename, const char *target)
static gdb_bfd_ref_ptr bfd_openr_or_error(const char *filename, const char *target)
static struct cmd_list_element * ihex_cmdlist
static void dump_binary_file(const char *filename, const char *mode, const bfd_byte *buf, ULONGEST len)
static void dump_srec_memory(const char *args, int from_tty)
#define TYPE_LENGTH(thistype)
static struct cmd_list_element * append_cmdlist
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
completer_ftype * completer
CORE_ADDR value_address(const struct value *value)
static void dump_binary_memory(const char *args, int from_tty)
static void dump_command(const char *cmd, int from_tty)
static gdb_bfd_ref_ptr bfd_openw_or_error(const char *filename, const char *target, const char *mode)
void error(const char *fmt,...)
static void append_command(const char *cmd, int from_tty)
LONGEST parse_and_eval_long(const char *exp)