29 #include "readline/readline.h"
39 if ((*cmd) == NULL || (**cmd) ==
'\0')
41 char *exp = xstrdup (def);
51 end = (*cmd) + strcspn (*cmd,
" \t");
72 error (
_(
"Missing filename."));
73 filename = xstrdup (defname);
82 end = *cmd + strcspn (*cmd,
" \t");
89 fullname = tilde_expand (filename);
113 error (
_(
"Failed to open %s: %s."), filename,
114 bfd_errmsg (bfd_get_error ()));
117 if (!bfd_check_format (ibfd, bfd_object))
118 error (
_(
"'%s' is not a recognized file format."), filename);
133 error (
_(
"Failed to open %s: %s."), filename,
134 bfd_errmsg (bfd_get_error ()));
136 if (!bfd_set_format (obfd, bfd_object))
137 error (
_(
"bfd_openw_with_cleanup: %s."), bfd_errmsg (bfd_get_error ()));
139 else if (*mode ==
'a')
141 error (
_(
"bfd_openw does not work with append."));
144 error (
_(
"bfd_openw_with_cleanup: unknown mode %s."), mode);
180 status = fwrite (buf, len, 1, file);
194 osection = bfd_make_section_anyway (obfd,
".newsec");
195 bfd_set_section_size (obfd, osection, len);
196 bfd_set_section_vma (obfd, osection, vaddr);
197 bfd_set_section_alignment (obfd, osection, 0);
198 bfd_set_section_flags (obfd, osection, (SEC_HAS_CONTENTS
201 osection->entsize = 0;
202 if (!bfd_set_section_contents (obfd, osection, buf, 0, len))
203 warning (
_(
"writing dump file '%s' (%s)"), filename,
204 bfd_errmsg (bfd_get_error ()));
214 const char *filename;
223 if (cmd == NULL || *cmd ==
'\0')
224 error (
_(
"Missing start address."));
228 if (cmd == NULL || *cmd ==
'\0')
229 error (
_(
"Missing stop address."));
235 error (
_(
"Invalid memory address range (start >= end)."));
245 if (file_format == NULL || strcmp (file_format,
"binary") == 0)
268 const char *filename;
274 if (cmd == NULL || *cmd ==
'\0')
275 error (
_(
"No value to %s."), *mode ==
'a' ?
"append" :
"dump");
278 error (
_(
"Invalid expression."));
281 if (file_format == NULL || strcmp (file_format,
"binary") == 0)
297 warning (
_(
"value is not an lval: address assumed to be zero"));
426 if ( c->
doc[0] ==
'W'
432 c->
doc = concat (
"Append ", c->
doc + 6, (
char *)NULL);
451 bfd_vma sec_start = bfd_section_vma (ibfd, isec);
452 bfd_size_type
size = bfd_section_size (ibfd, isec);
453 bfd_vma sec_end = sec_start +
size;
454 bfd_size_type sec_offset = 0;
455 bfd_size_type sec_load_count =
size;
461 if (!(bfd_get_section_flags (ibfd, isec) & SEC_LOAD))
465 if (sec_end <= data->load_start
470 bfd_section_name (ibfd, isec));
477 if (sec_start < data->load_start)
480 sec_load_count -= sec_offset;
482 sec_load_count -= sec_end - data->
load_end;
487 if (!bfd_get_section_contents (ibfd, isec, buf, 0, size))
488 error (
_(
"Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
489 bfd_errmsg (bfd_get_error ()));
492 bfd_section_name (ibfd, isec),
493 (
unsigned long) sec_start,
494 (
unsigned long) sec_end);
499 (
unsigned long) sec_start
502 (
unsigned long) sec_start + sec_offset
509 buf + sec_offset, sec_load_count);
525 if (fseek (file, 0, SEEK_END) == 0)
534 if (len <= data->load_start)
535 error (
_(
"Start address is greater than length of binary file %s."),
546 (
"Restoring binary file %s into memory (0x%lx to 0x%lx)\n",
558 if (fread (buf, 1, len, file) != len)
575 const char *args = args_in;
586 if (args != NULL && *args !=
'\0')
588 char *binary_string =
"binary";
594 args += strlen (binary_string);
598 if (args != NULL && *args !=
'\0')
601 if (args != NULL && *args !=
'\0')
606 if (args != NULL && *args !=
'\0')
611 error (
_(
"Start must be less than end."));
617 printf_filtered (
"Restore file %s offset 0x%lx start 0x%lx end 0x%lx\n",
688 _(
"Dump target code/data to a local file."),
689 &dump_cmdlist,
"dump ",
693 _(
"Append target code/data to a local file."),
694 &append_cmdlist,
"append ",
699 Write contents of memory to a raw binary file.\n\
700 Arguments are FILE START STOP. Writes the contents of memory within the\n\
701 range [START .. STOP) to the specified FILE in raw target ordered bytes.");
704 Write the value of an expression to a raw binary file.\n\
705 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION to\n\
706 the specified FILE in raw target ordered bytes.");
709 _(
"Write target code/data to an srec file."),
710 &srec_cmdlist,
"dump srec ",
715 _(
"Write target code/data to an intel hex file."),
716 &ihex_cmdlist,
"dump ihex ",
721 _(
"Write target code/data to a verilog hex file."),
722 &verilog_cmdlist,
"dump verilog ",
727 _(
"Write target code/data to a tekhex file."),
728 &tekhex_cmdlist,
"dump tekhex ",
733 _(
"Write target code/data to a raw binary file."),
734 &binary_dump_cmdlist,
"dump binary ",
739 _(
"Append target code/data to a raw binary file."),
740 &binary_append_cmdlist,
"append binary ",
745 Write contents of memory to an srec file.\n\
746 Arguments are FILE START STOP. Writes the contents of memory\n\
747 within the range [START .. STOP) to the specified FILE in srec format."),
751 Write the value of an expression to an srec file.\n\
752 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
753 to the specified FILE in srec format."),
757 Write contents of memory to an ihex file.\n\
758 Arguments are FILE START STOP. Writes the contents of memory within\n\
759 the range [START .. STOP) to the specified FILE in intel hex format."),
763 Write the value of an expression to an ihex file.\n\
764 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
765 to the specified FILE in intel hex format."),
769 Write contents of memory to a verilog hex file.\n\
770 Arguments are FILE START STOP. Writes the contents of memory within\n\
771 the range [START .. STOP) to the specified FILE in verilog hex format."),
775 Write the value of an expression to a verilog hex file.\n\
776 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
777 to the specified FILE in verilog hex format."),
781 Write contents of memory to a tekhex file.\n\
782 Arguments are FILE START STOP. Writes the contents of memory\n\
783 within the range [START .. STOP) to the specified FILE in tekhex format."),
787 Write the value of an expression to a tekhex file.\n\
788 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
789 to the specified FILE in tekhex format."),
793 Write contents of memory to a raw binary file.\n\
794 Arguments are FILE START STOP. Writes the contents of memory\n\
795 within the range [START .. STOP) to the specified FILE in binary format."),
796 &binary_dump_cmdlist);
799 Write the value of an expression to a raw binary file.\n\
800 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
801 to the specified FILE in raw target ordered bytes."),
802 &binary_dump_cmdlist);
805 Append contents of memory to a raw binary file.\n\
806 Arguments are FILE START STOP. Writes the contents of memory within the\n\
807 range [START .. STOP) to the specified FILE in raw target ordered bytes."),
808 &binary_append_cmdlist);
811 Append the value of an expression to a raw binary file.\n\
812 Arguments are FILE EXPRESSION. Writes the value of EXPRESSION\n\
813 to the specified FILE in raw target ordered bytes."),
814 &binary_append_cmdlist);
817 Restore the contents of FILE to target memory.\n\
818 Arguments are FILE OFFSET START END where all except FILE are optional.\n\
819 OFFSET will be added to the base address of the file (default zero).\n\
820 If START and END are given, only the file contents within that range\n\
821 (file relative) will be restored to target memory."));
struct gdbarch * target_gdbarch(void)
void set_cmd_context(struct cmd_list_element *cmd, void *context)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
void(* func)(char *cmd, char *mode)
static struct cmd_list_element * binary_append_cmdlist
static void restore_binary_file(const char *filename, struct callback_data *data)
void * get_cmd_context(struct cmd_list_element *cmd)
static struct cmd_list_element * srec_cmdlist
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
static void dump_command(char *cmd, int from_tty)
void warning(const char *fmt,...)
static void restore_section_callback(bfd *ibfd, asection *isec, void *args)
struct ui_file * gdb_stdout
static FILE * fopen_with_cleanup(const char *filename, const char *mode)
static void dump_verilog_value(char *args, int from_tty)
static void dump_bfd_file(const char *filename, const char *mode, const char *target, CORE_ADDR vaddr, const bfd_byte *buf, ULONGEST len)
static void ihex_dump_command(char *cmd, int from_tty)
static void dump_tekhex_memory(char *args, int from_tty)
struct cmd_list_element * cmdlist
FILE * gdb_fopen_cloexec(const char *filename, const char *opentype)
static void append_binary_memory(char *args, int from_tty)
static void dump_tekhex_value(char *args, int from_tty)
static void dump_value_to_file(const char *cmd, const char *mode, const char *file_format)
static bfd * bfd_openr_with_cleanup(const char *filename, const char *target)
static void restore_command(char *args_in, int from_tty)
static struct cmd_list_element * verilog_cmdlist
static void binary_dump_command(char *cmd, int from_tty)
void printf_filtered(const char *format,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void null_cleanup(void *arg)
initialize_file_ftype _initialize_cli_dump
static void dump_srec_memory(char *args, int from_tty)
static void tekhex_dump_command(char *cmd, int from_tty)
static void binary_append_command(char *cmd, int from_tty)
const gdb_byte * value_contents(struct value *value)
static struct cmd_list_element * tekhex_cmdlist
static char * scan_filename_with_cleanup(const char **cmd, const char *defname)
static void append_binary_value(char *args, int from_tty)
void initialize_file_ftype(void)
static void append_command(char *cmd, int from_tty)
static void dump_value_command(char *cmd, char *mode)
const char * skip_spaces_const(const char *chp)
static void verilog_dump_command(char *cmd, int from_tty)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
void puts_filtered(const char *string)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
static bfd * bfd_openw_with_cleanup(const char *filename, const char *target, const char *mode)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static void dump_ihex_value(char *args, int from_tty)
static int startswith(const char *string, const char *pattern)
#define target_has_execution
static void dump_memory_to_file(const char *cmd, const char *mode, const char *file_format)
static void dump_verilog_memory(char *args, int from_tty)
void printf_unfiltered(const char *format,...)
static void dump_binary_value(char *args, int from_tty)
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
static struct cmd_list_element * dump_cmdlist
static void add_dump_command(char *name, void(*func)(char *args, char *mode), char *descr)
static struct cmd_list_element * binary_dump_cmdlist
bfd * gdb_bfd_openw(const char *filename, const char *target)
struct cleanup * make_cleanup_fclose(FILE *file)
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
static void srec_dump_command(char *cmd, int from_tty)
static void dump_ihex_memory(char *args, int from_tty)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
CORE_ADDR parse_and_eval_address(const char *exp)
char * safe_strerror(int)
void(* func)(struct cmd_list_element *c, char *args, int from_tty)
struct value * parse_and_eval(const char *exp)
unsigned long long ULONGEST
char * savestring(const char *ptr, size_t len)
bfd * gdb_bfd_openr(const char *filename, const char *target)
static void call_dump_func(struct cmd_list_element *c, char *args, int from_tty)
struct type * value_type(const struct value *value)
static void dump_memory_command(char *cmd, char *mode)
static struct cmd_list_element * ihex_cmdlist
static void dump_binary_file(const char *filename, const char *mode, const bfd_byte *buf, ULONGEST len)
#define TYPE_LENGTH(thistype)
static void dump_srec_value(char *args, int from_tty)
static struct cmd_list_element * append_cmdlist
static void dump_binary_memory(char *args, int from_tty)
completer_ftype * completer
CORE_ADDR value_address(const struct value *value)
static const char * scan_expression_with_cleanup(const char **cmd, const char *def)
void error(const char *fmt,...)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
void do_cleanups(struct cleanup *old_chain)
const ULONGEST const LONGEST len
LONGEST parse_and_eval_long(const char *exp)