/* Generate a core file for the inferior process.
- Copyright (C) 2001-2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "readline/tilde.h"
#include <algorithm>
#include "common/gdb_unlinker.h"
-#include "byte-vector.h"
+#include "common/byte-vector.h"
+#include "common/scope-exit.h"
/* The largest amount of memory to read from the target at once. We
must throttle it to limit the amount of memory used by GDB during
void
write_gcore_file (bfd *obfd)
{
- struct gdb_exception except = exception_none;
-
target_prepare_to_generate_core ();
-
- TRY
- {
- write_gcore_file_1 (obfd);
- }
- CATCH (e, RETURN_MASK_ALL)
- {
- except = e;
- }
- END_CATCH
-
- target_done_generating_core ();
-
- if (except.reason < 0)
- throw_exception (except);
+ SCOPE_EXIT { target_done_generating_core (); };
+ write_gcore_file_1 (obfd);
}
/* gcore_command -- implements the 'gcore' command.
else
{
/* Default corefile name is "core.PID". */
- corefilename.reset (xstrprintf ("core.%d", ptid_get_pid (inferior_ptid)));
+ corefilename.reset (xstrprintf ("core.%d", inferior_ptid.pid ()));
}
if (info_verbose)
target_sbrk_arg = value_from_longest (builtin_type (gdbarch)->builtin_int,
sbrk_arg);
gdb_assert (target_sbrk_arg);
- ret = call_function_by_hand (sbrk_fn, NULL, 1, &target_sbrk_arg);
+ ret = call_function_by_hand (sbrk_fn, NULL, target_sbrk_arg);
if (ret == NULL)
return (bfd_vma) 0;
{
/* See if this region of memory lies inside a known file on disk.
If so, we can avoid copying its contents by clearing SEC_LOAD. */
- struct objfile *objfile;
struct obj_section *objsec;
- ALL_OBJSECTIONS (objfile, objsec)
- {
- bfd *abfd = objfile->obfd;
- asection *asec = objsec->the_bfd_section;
- bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
- asec);
- bfd_vma start = obj_section_addr (objsec) & -align;
- bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
-
- /* Match if either the entire memory region lies inside the
- section (i.e. a mapping covering some pages of a large
- segment) or the entire section lies inside the memory region
- (i.e. a mapping covering multiple small sections).
-
- This BFD was synthesized from reading target memory,
- we don't want to omit that. */
- if (objfile->separate_debug_objfile_backlink == NULL
- && ((vaddr >= start && vaddr + size <= end)
- || (start >= vaddr && end <= vaddr + size))
- && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
- {
- flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
- goto keep; /* Break out of two nested for loops. */
- }
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, objsec)
+ {
+ bfd *abfd = objfile->obfd;
+ asection *asec = objsec->the_bfd_section;
+ bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
+ asec);
+ bfd_vma start = obj_section_addr (objsec) & -align;
+ bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
+
+ /* Match if either the entire memory region lies inside the
+ section (i.e. a mapping covering some pages of a large
+ segment) or the entire section lies inside the memory region
+ (i.e. a mapping covering multiple small sections).
+
+ This BFD was synthesized from reading target memory,
+ we don't want to omit that. */
+ if (objfile->separate_debug_objfile_backlink == NULL
+ && ((vaddr >= start && vaddr + size <= end)
+ || (start >= vaddr && end <= vaddr + size))
+ && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
+ {
+ flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
+ goto keep; /* Break out of two nested for loops. */
+ }
+ }
keep:;
}
find_memory_region_ftype func, void *obfd)
{
/* Use objfile data to create memory sections. */
- struct objfile *objfile;
struct obj_section *objsec;
bfd_vma temp_bottom, temp_top;
/* Call callback function for each objfile section. */
- ALL_OBJSECTIONS (objfile, objsec)
- {
- bfd *ibfd = objfile->obfd;
- asection *isec = objsec->the_bfd_section;
- flagword flags = bfd_get_section_flags (ibfd, isec);
-
- /* Separate debug info files are irrelevant for gcore. */
- if (objfile->separate_debug_objfile_backlink != NULL)
- continue;
-
- if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
- {
- int size = bfd_section_size (ibfd, isec);
- int ret;
-
- ret = (*func) (obj_section_addr (objsec), size,
- 1, /* All sections will be readable. */
- (flags & SEC_READONLY) == 0, /* Writable. */
- (flags & SEC_CODE) != 0, /* Executable. */
- 1, /* MODIFIED is unknown, pass it as true. */
- obfd);
- if (ret != 0)
- return ret;
- }
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, objsec)
+ {
+ bfd *ibfd = objfile->obfd;
+ asection *isec = objsec->the_bfd_section;
+ flagword flags = bfd_get_section_flags (ibfd, isec);
+
+ /* Separate debug info files are irrelevant for gcore. */
+ if (objfile->separate_debug_objfile_backlink != NULL)
+ continue;
+
+ if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
+ {
+ int size = bfd_section_size (ibfd, isec);
+ int ret;
+
+ ret = (*func) (obj_section_addr (objsec), size,
+ 1, /* All sections will be readable. */
+ (flags & SEC_READONLY) == 0, /* Writable. */
+ (flags & SEC_CODE) != 0, /* Executable. */
+ 1, /* MODIFIED is unknown, pass it as true. */
+ obfd);
+ if (ret != 0)
+ return ret;
+ }
+ }
/* Make a stack segment. */
if (derive_stack_segment (&temp_bottom, &temp_top))