36 #include "readline/tilde.h"
41 #define MAX_COPY_BYTES (1024 * 1024)
57 error (
_(
"Failed to open '%s' for output."), filename);
58 bfd_set_format (obfd, bfd_core);
69 void *note_data = NULL;
71 asection *note_sec = NULL;
84 if (note_data == NULL || note_size == 0)
85 error (
_(
"Target does not support core file generation."));
88 note_sec = bfd_make_section_anyway_with_flags (obfd,
"note0",
93 error (
_(
"Failed to create 'note' section for corefile: %s"),
94 bfd_errmsg (bfd_get_error ()));
96 bfd_set_section_vma (obfd, note_sec, 0);
97 bfd_set_section_alignment (obfd, note_sec, 0);
98 bfd_set_section_size (obfd, note_sec, note_size);
102 error (
_(
"gcore: failed to get corefile memory sections from target."));
105 if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size))
106 warning (
_(
"writing note section (%s)"), bfd_errmsg (bfd_get_error ()));
141 const char *filename = obfd->filename;
153 struct cleanup *filename_chain;
163 corefilename = tilde_expand (args);
173 "Opening corefile '%s' for output.\n", corefilename);
202 return bfdarch->mach;
204 error (
_(
"Can't find default bfd machine type (need execfile)."));
210 static enum bfd_architecture
216 return bfdarch->arch;
218 error (
_(
"Can't find bfd architecture for corefile (need execfile)."));
295 struct value *target_sbrk_arg;
296 struct value *sbrk_fn, *ret;
337 bfd_vma top_of_data_memory = 0;
338 bfd_vma top_of_heap = 0;
339 bfd_size_type sec_size;
362 for (sec = abfd->sections; sec; sec = sec->next)
364 if (bfd_get_section_flags (abfd, sec) & SEC_DATA
365 || strcmp (
".bss", bfd_section_name (abfd, sec)) == 0)
367 sec_vaddr = bfd_get_section_vma (abfd, sec);
368 sec_size = bfd_get_section_size (sec);
369 if (sec_vaddr + sec_size > top_of_data_memory)
370 top_of_data_memory = sec_vaddr + sec_size;
375 if (top_of_heap == (bfd_vma) 0)
379 if (top_of_heap > top_of_data_memory)
381 *bottom = top_of_data_memory;
397 if (
startswith (bfd_section_name (obfd, osec),
"load"))
399 else if (
startswith (bfd_section_name (obfd, osec),
"note"))
405 if (!(bfd_get_section_flags (obfd, osec) & SEC_READONLY))
407 if (bfd_get_section_flags (obfd, osec) & SEC_CODE)
410 bfd_record_phdr (obfd, p_type, 1, p_flags, 0, 0, 0, 0, 1, &osec);
418 int write,
int exec,
int modified,
void *data)
422 flagword
flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD;
427 if (read == 0 && write == 0 && exec == 0 && modified == 0)
447 bfd *abfd = objfile->
obfd;
449 bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
462 && ((vaddr >= start && vaddr + size <= end)
463 || (start >= vaddr && end <= vaddr + size))
464 && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
466 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
475 flags |= SEC_READONLY;
482 osec = bfd_make_section_anyway_with_flags (obfd,
"load", flags);
485 warning (
_(
"Couldn't make gcore segment: %s"),
486 bfd_errmsg (bfd_get_error ()));
496 bfd_set_section_size (obfd, osec, size);
497 bfd_set_section_vma (obfd, osec, vaddr);
498 bfd_section_lma (obfd, osec) = 0;
509 bfd_vma temp_bottom, temp_top;
514 bfd *ibfd = objfile->
obfd;
516 flagword
flags = bfd_get_section_flags (ibfd, isec);
522 if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
524 int size = bfd_section_size (ibfd, isec);
529 (flags & SEC_READONLY) == 0,
530 (flags & SEC_CODE) != 0,
540 (*func) (temp_bottom, temp_top - temp_bottom,
549 (*func) (temp_bottom, temp_top - temp_bottom,
562 bfd_size_type
size, total_size = bfd_section_size (obfd, osec);
564 struct cleanup *old_chain = NULL;
568 if ((bfd_get_section_flags (obfd, osec) & SEC_LOAD) == 0)
572 if (!
startswith (bfd_section_name (obfd, osec),
"load"))
579 while (total_size > 0)
581 if (size > total_size)
587 warning (
_(
"Memory read failed for corefile "
588 "section, %s bytes at %s."),
593 if (!bfd_set_section_contents (obfd, osec, memhunk, offset, size))
595 warning (
_(
"Failed to write corefile contents (%s)."),
596 bfd_errmsg (bfd_get_error ()));
635 Save a core file with the current state of the debugged process.\n\
636 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
struct value * call_function_by_hand(struct value *function, int nargs, struct value **args)
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)
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)
struct ui_file * gdb_stdout
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)
static void do_bfd_delete_cleanup(void *arg)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static unsigned long default_gcore_mach(void)
initialize_file_ftype _initialize_gcore
#define obj_section_addr(s)
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)
void gdb_bfd_unref(struct bfd *abfd)
void initialize_file_ftype(void)
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 cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
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)
int ptid_get_pid(ptid_t ptid)
bfd * gdb_bfd_openw(const char *filename, const char *target)
void throw_exception(struct gdb_exception exception)
void discard_cleanups(struct cleanup *old_chain)
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)
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)
bfd * create_gcore_bfd(const char *filename)
static void gcore_command(char *args, int from_tty)
static int gcore_create_callback(CORE_ADDR vaddr, unsigned long size, int read, int write, int exec, int modified, void *data)
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
int gdbarch_gcore_bfd_target_p(struct gdbarch *gdbarch)
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 cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
int solib_keep_data_in_core(CORE_ADDR vaddr, unsigned long size)
void do_cleanups(struct cleanup *old_chain)
enum return_reason reason
static int derive_stack_segment(bfd_vma *bottom, bfd_vma *top)