36 #include "readline/tilde.h" 44 #define MAX_COPY_BYTES (1024 * 1024) 60 error (
_(
"Failed to open '%s' for output."), filename);
61 bfd_set_format (obfd.
get (), bfd_core);
73 asection *note_sec = NULL;
85 if (note_data == NULL || note_size == 0)
86 error (
_(
"Target does not support core file generation."));
89 note_sec = bfd_make_section_anyway_with_flags (obfd,
"note0",
94 error (
_(
"Failed to create 'note' section for corefile: %s"),
95 bfd_errmsg (bfd_get_error ()));
97 bfd_set_section_vma (obfd, note_sec, 0);
98 bfd_set_section_alignment (obfd, note_sec, 0);
99 bfd_set_section_size (obfd, note_sec, note_size);
103 error (
_(
"gcore: failed to get corefile memory sections from target."));
106 if (!bfd_set_section_contents (obfd, note_sec, note_data.get (), 0,
108 warning (
_(
"writing note section (%s)"), bfd_errmsg (bfd_get_error ()));
150 corefilename.reset (tilde_expand (args));
159 "Opening corefile '%s' for output.\n",
160 corefilename.get ());
187 return bfdarch->mach;
189 error (
_(
"Can't find default bfd machine type (need execfile)."));
195 static enum bfd_architecture
201 return bfdarch->arch;
203 error (
_(
"Can't find bfd architecture for corefile (need execfile)."));
280 struct value *target_sbrk_arg;
281 struct value *sbrk_fn, *ret;
322 bfd_vma top_of_data_memory = 0;
323 bfd_vma top_of_heap = 0;
324 bfd_size_type sec_size;
347 for (sec = abfd->sections; sec; sec = sec->next)
349 if (bfd_get_section_flags (abfd, sec) & SEC_DATA
350 || strcmp (
".bss", bfd_section_name (abfd, sec)) == 0)
352 sec_vaddr = bfd_get_section_vma (abfd, sec);
353 sec_size = bfd_get_section_size (sec);
354 if (sec_vaddr + sec_size > top_of_data_memory)
355 top_of_data_memory = sec_vaddr + sec_size;
360 if (top_of_heap == (bfd_vma) 0)
364 if (top_of_heap > top_of_data_memory)
366 *bottom = top_of_data_memory;
382 if (
startswith (bfd_section_name (obfd, osec),
"load"))
384 else if (
startswith (bfd_section_name (obfd, osec),
"note"))
390 if (!(bfd_get_section_flags (obfd, osec) & SEC_READONLY))
392 if (bfd_get_section_flags (obfd, osec) & SEC_CODE)
395 bfd_record_phdr (obfd, p_type, 1, p_flags, 0, 0, 0, 0, 1, &osec);
403 int write,
int exec,
int modified,
void *data)
405 bfd *obfd = (bfd *) data;
407 flagword
flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD;
412 if (
read == 0 && write == 0 && exec == 0 && modified == 0)
434 bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
447 && ((vaddr >= start && vaddr +
size <= end)
448 || (start >= vaddr && end <= vaddr +
size))
449 && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
451 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
460 flags |= SEC_READONLY;
467 osec = bfd_make_section_anyway_with_flags (obfd,
"load",
flags);
470 warning (
_(
"Couldn't make gcore segment: %s"),
471 bfd_errmsg (bfd_get_error ()));
481 bfd_set_section_size (obfd, osec,
size);
482 bfd_set_section_vma (obfd, osec, vaddr);
483 bfd_section_lma (obfd, osec) = 0;
494 bfd_vma temp_bottom, temp_top;
501 flagword
flags = bfd_get_section_flags (ibfd, isec);
507 if ((
flags & SEC_ALLOC) || (
flags & SEC_LOAD))
509 int size = bfd_section_size (ibfd, isec);
514 (
flags & SEC_READONLY) == 0,
515 (
flags & SEC_CODE) != 0,
525 (*
func) (temp_bottom, temp_top - temp_bottom,
534 (*
func) (temp_bottom, temp_top - temp_bottom,
547 bfd_size_type
size, total_size = bfd_section_size (obfd, osec);
551 if ((bfd_get_section_flags (obfd, osec) & SEC_LOAD) == 0)
555 if (!
startswith (bfd_section_name (obfd, osec),
"load"))
561 while (total_size > 0)
563 if (
size > total_size)
567 memhunk.data (),
size) != 0)
569 warning (
_(
"Memory read failed for corefile " 570 "section, %s bytes at %s."),
575 if (!bfd_set_section_contents (obfd, osec, memhunk.data (),
578 warning (
_(
"Failed to write corefile contents (%s)."),
579 bfd_errmsg (bfd_get_error ()));
613 Save a core file with the current state of the debugged process.\n\ 614 Argument is optional filename. Default filename is 'core.<process_id>'."));
struct gdbarch * target_gdbarch(void)
ssize_t read(int fd, void *buf, size_t count)
static int derive_heap_segment(bfd *abfd, bfd_vma *bottom, bfd_vma *top)
char * gdbarch_make_corefile_notes(struct gdbarch *gdbarch, bfd *obfd, int *note_size)
#define target_has_registers
static void make_output_phdrs(bfd *obfd, asection *osec, void *ignored)
struct frame_info * get_current_frame(void)
static bfd_vma call_target_sbrk(int sbrk_arg)
int ptid_get_pid(const ptid_t &ptid)
struct objfile * separate_debug_objfile_backlink
int gdbarch_inner_than(struct gdbarch *gdbarch, CORE_ADDR lhs, CORE_ADDR rhs)
struct frame_info * get_prev_frame(struct frame_info *this_frame)
LONGEST value_as_long(struct value *val)
struct bfd_section * the_bfd_section
void warning(const char *fmt,...)
#define target_find_memory_regions(FUNC, DATA)
char * plongest(LONGEST l)
void _initialize_gcore(void)
CORE_ADDR get_frame_sp(struct frame_info *this_frame)
#define obj_section_endaddr(s)
const struct gdb_exception exception_none
#define ALL_OBJSECTIONS(objfile, osect)
void target_prepare_to_generate_core(void)
gdb_bfd_ref_ptr create_gcore_bfd(const char *filename)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static unsigned long default_gcore_mach(void)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
const char * gdbarch_gcore_bfd_target(struct gdbarch *gdbarch)
int gdbarch_find_memory_regions(struct gdbarch *gdbarch, find_memory_region_ftype func, void *data)
#define CATCH(EXCEPTION, MASK)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
objfile(bfd *, const char *, objfile_flags)
int gdbarch_find_memory_regions_p(struct gdbarch *gdbarch)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
struct value * find_function_in_inferior(const char *name, struct objfile **objf_p)
struct cmd_list_element * add_com_alias(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
static enum bfd_architecture default_gcore_arch(void)
static const char * default_gcore_target(void)
struct value * value_from_longest(struct type *type, LONGEST num)
void write_gcore_file(bfd *obfd)
static int startswith(const char *string, const char *pattern)
#define target_has_execution
static int gcore_memory_sections(bfd *)
char * xstrprintf(const char *format,...)
int objfile_find_memory_regions(struct target_ops *self, find_memory_region_ftype func, void *obfd)
void throw_exception(struct gdb_exception exception)
static void write_gcore_file_1(bfd *obfd)
CORE_ADDR get_frame_base(struct frame_info *fi)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
#define obj_section_addr(s)
int gdbarch_make_corefile_notes_p(struct gdbarch *gdbarch)
static void gcore_copy_callback(bfd *obfd, asection *osec, void *ignored)
#define target_make_corefile_notes(BFD, SIZE_P)
void target_done_generating_core(void)
gdb::def_vector< gdb_byte > byte_vector
struct value * call_function_by_hand(struct value *function, type *default_return_type, int nargs, struct value **args)
static int gcore_create_callback(CORE_ADDR vaddr, unsigned long size, int read, int write, int exec, int modified, void *data)
gdb_bfd_ref_ptr gdb_bfd_openw(const char *filename, const char *target)
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
int gdbarch_gcore_bfd_target_p(struct gdbarch *gdbarch)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
static void gcore_command(const char *args, int from_tty)
int(* find_memory_region_ftype)(CORE_ADDR addr, unsigned long size, int read, int write, int exec, int modified, void *data)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
void error(const char *fmt,...)
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
int solib_keep_data_in_core(CORE_ADDR vaddr, unsigned long size)
enum return_reason reason
static int derive_stack_segment(bfd_vma *bottom, bfd_vma *top)