forked from Imagelibrary/binutils-gdb
objdump read_section_stabs
This function is used to read sections other than stabs, and there is now another version of it that extracts different info from the bfd section. Rename it and return the bfd section instead of assorted fields of the bfd section. * objcopy.c (read_section): Renamed from read_section_stabs. Delete size_ptr and entsize_ptr params, add contents param. Return asection pointer. Don't unnecessarily free contents on failure from bfd_malloc_and_get_section. (find_stabs_section): Use read_section. (dump_ctf, dump_section_sframe): Likewise. (read_section_sframe): Delete.
This commit is contained in:
@@ -4443,39 +4443,32 @@ dump_dwarf (bfd *abfd, bool is_mainfile)
|
|||||||
bfd_map_over_sections (abfd, dump_dwarf_section, (void *) &is_mainfile);
|
bfd_map_over_sections (abfd, dump_dwarf_section, (void *) &is_mainfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
|
/* Read ABFD's section SECT_NAME into *CONTENTS, and return a pointer to
|
||||||
it. Return NULL on failure. */
|
the section. Return NULL on failure. */
|
||||||
|
|
||||||
static bfd_byte *
|
static asection *
|
||||||
read_section_stabs (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr,
|
read_section (bfd *abfd, const char *sect_name, bfd_byte **contents)
|
||||||
bfd_size_type *entsize_ptr)
|
|
||||||
{
|
{
|
||||||
asection *stabsect;
|
asection *sec;
|
||||||
bfd_byte *contents;
|
|
||||||
|
|
||||||
stabsect = bfd_get_section_by_name (abfd, sect_name);
|
*contents = NULL;
|
||||||
if (stabsect == NULL)
|
sec = bfd_get_section_by_name (abfd, sect_name);
|
||||||
|
if (sec == NULL)
|
||||||
{
|
{
|
||||||
printf (_("No %s section present\n\n"),
|
printf (_("No %s section present\n\n"), sanitize_string (sect_name));
|
||||||
sanitize_string (sect_name));
|
return NULL;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bfd_malloc_and_get_section (abfd, stabsect, &contents))
|
if (!bfd_malloc_and_get_section (abfd, sec, contents))
|
||||||
{
|
{
|
||||||
non_fatal (_("reading %s section of %s failed: %s"),
|
non_fatal (_("reading %s section of %s failed: %s"),
|
||||||
sect_name, bfd_get_filename (abfd),
|
sect_name, bfd_get_filename (abfd),
|
||||||
bfd_errmsg (bfd_get_error ()));
|
bfd_errmsg (bfd_get_error ()));
|
||||||
exit_status = 1;
|
exit_status = 1;
|
||||||
free (contents);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*size_ptr = bfd_section_size (stabsect);
|
return sec;
|
||||||
if (entsize_ptr)
|
|
||||||
*entsize_ptr = stabsect->entsize;
|
|
||||||
|
|
||||||
return contents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stabs entries use a 12 byte format:
|
/* Stabs entries use a 12 byte format:
|
||||||
@@ -4595,15 +4588,20 @@ find_stabs_section (bfd *abfd, asection *section, void *names)
|
|||||||
&& (section->name[len] == 0
|
&& (section->name[len] == 0
|
||||||
|| (section->name[len] == '.' && ISDIGIT (section->name[len + 1]))))
|
|| (section->name[len] == '.' && ISDIGIT (section->name[len + 1]))))
|
||||||
{
|
{
|
||||||
|
asection *s;
|
||||||
if (strtab == NULL)
|
if (strtab == NULL)
|
||||||
strtab = read_section_stabs (abfd, sought->string_section_name,
|
{
|
||||||
&stabstr_size, NULL);
|
s = read_section (abfd, sought->string_section_name, &strtab);
|
||||||
|
if (s != NULL)
|
||||||
|
stabstr_size = bfd_section_size (s);
|
||||||
|
}
|
||||||
|
|
||||||
if (strtab)
|
if (strtab)
|
||||||
{
|
{
|
||||||
stabs = read_section_stabs (abfd, section->name, &stab_size, NULL);
|
s = read_section (abfd, section->name, &stabs);
|
||||||
if (stabs)
|
if (s != NULL)
|
||||||
{
|
{
|
||||||
|
stab_size = bfd_section_size (s);
|
||||||
print_section_stabs (abfd, section->name, &sought->string_offset);
|
print_section_stabs (abfd, section->name, &sought->string_offset);
|
||||||
free (stabs);
|
free (stabs);
|
||||||
}
|
}
|
||||||
@@ -4776,9 +4774,9 @@ dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent,
|
|||||||
static void
|
static void
|
||||||
dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
|
dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
|
||||||
{
|
{
|
||||||
|
asection *sec;
|
||||||
ctf_archive_t *ctfa = NULL;
|
ctf_archive_t *ctfa = NULL;
|
||||||
bfd_byte *ctfdata = NULL;
|
bfd_byte *ctfdata;
|
||||||
bfd_size_type ctfsize;
|
|
||||||
ctf_sect_t ctfsect;
|
ctf_sect_t ctfsect;
|
||||||
ctf_dict_t *parent;
|
ctf_dict_t *parent;
|
||||||
ctf_dict_t *fp;
|
ctf_dict_t *fp;
|
||||||
@@ -4790,13 +4788,14 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
|
|||||||
if (sect_name == NULL)
|
if (sect_name == NULL)
|
||||||
sect_name = ".ctf";
|
sect_name = ".ctf";
|
||||||
|
|
||||||
if ((ctfdata = read_section_stabs (abfd, sect_name, &ctfsize, NULL)) == NULL)
|
sec = read_section (abfd, sect_name, &ctfdata);
|
||||||
bfd_fatal (bfd_get_filename (abfd));
|
if (sec == NULL)
|
||||||
|
bfd_fatal (bfd_get_filename (abfd));
|
||||||
|
|
||||||
/* Load the CTF file and dump it. Preload the parent dict, since it will
|
/* Load the CTF file and dump it. Preload the parent dict, since it will
|
||||||
need to be imported into every child in turn. */
|
need to be imported into every child in turn. */
|
||||||
|
|
||||||
ctfsect = make_ctfsect (sect_name, ctfdata, ctfsize);
|
ctfsect = make_ctfsect (sect_name, ctfdata, bfd_section_size (sec));
|
||||||
if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
|
if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL)
|
||||||
{
|
{
|
||||||
dump_ctf_errs (NULL);
|
dump_ctf_errs (NULL);
|
||||||
@@ -4831,54 +4830,25 @@ dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED,
|
|||||||
const char *parent_name ATTRIBUTE_UNUSED) {}
|
const char *parent_name ATTRIBUTE_UNUSED) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bfd_byte*
|
|
||||||
read_section_sframe (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr,
|
|
||||||
bfd_vma *sframe_vma)
|
|
||||||
{
|
|
||||||
asection *sframe_sect;
|
|
||||||
bfd_byte *contents;
|
|
||||||
|
|
||||||
sframe_sect = bfd_get_section_by_name (abfd, sect_name);
|
|
||||||
if (sframe_sect == NULL)
|
|
||||||
{
|
|
||||||
printf (_("No %s section present\n\n"),
|
|
||||||
sanitize_string (sect_name));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bfd_malloc_and_get_section (abfd, sframe_sect, &contents))
|
|
||||||
{
|
|
||||||
non_fatal (_("reading %s section of %s failed: %s"),
|
|
||||||
sect_name, bfd_get_filename (abfd),
|
|
||||||
bfd_errmsg (bfd_get_error ()));
|
|
||||||
exit_status = 1;
|
|
||||||
free (contents);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*size_ptr = bfd_section_size (sframe_sect);
|
|
||||||
*sframe_vma = bfd_section_vma (sframe_sect);
|
|
||||||
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED,
|
dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED,
|
||||||
const char * sect_name)
|
const char * sect_name)
|
||||||
{
|
{
|
||||||
|
asection *sec;
|
||||||
sframe_decoder_ctx *sfd_ctx = NULL;
|
sframe_decoder_ctx *sfd_ctx = NULL;
|
||||||
bfd_size_type sf_size;
|
bfd_size_type sf_size;
|
||||||
bfd_byte *sframe_data = NULL;
|
bfd_byte *sframe_data;
|
||||||
bfd_vma sf_vma;
|
bfd_vma sf_vma;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (sect_name == NULL)
|
if (sect_name == NULL)
|
||||||
sect_name = ".sframe";
|
sect_name = ".sframe";
|
||||||
|
|
||||||
sframe_data = read_section_sframe (abfd, sect_name, &sf_size, &sf_vma);
|
sec = read_section (abfd, sect_name, &sframe_data);
|
||||||
|
if (sec == NULL)
|
||||||
if (sframe_data == NULL)
|
|
||||||
bfd_fatal (bfd_get_filename (abfd));
|
bfd_fatal (bfd_get_filename (abfd));
|
||||||
|
sf_size = bfd_section_size (sec);
|
||||||
|
sf_vma = bfd_section_vma (sec);
|
||||||
|
|
||||||
/* Decode the contents of the section. */
|
/* Decode the contents of the section. */
|
||||||
sfd_ctx = sframe_decode ((const char*)sframe_data, sf_size, &err);
|
sfd_ctx = sframe_decode ((const char*)sframe_data, sf_size, &err);
|
||||||
|
|||||||
Reference in New Issue
Block a user