opcodes/csky: return the default disassembler when there is no bfd

The disassembler function should return a valid disassembler function
even when there is no BFD present.  This is implied (I believe) by the
comment in dis-asm.h which says the BFD may be NULL.  Further, it
makes sense when considering that the disassembler is used in GDB, and
GDB may connect to a target and perform debugging even without a BFD
being supplied.

This commit makes the csky_get_disassembler function return the
default disassembler configuration when no bfd is supplied, this is
the same default configuration as is used when a BFD is supplied, but
the BFD has no attributes section.

Before the change configuring GDB with --enable-targets=all and
running the tests gdb.base/all-architectures-2.exp results in many
errors, but after this change there are no failures.

opcodes/ChangeLog:

	* csky-dis.c (csky_get_disassembler): Don't return NULL when there
	is no BFD.
This commit is contained in:
Andrew Burgess
2020-09-16 10:12:39 +01:00
committed by Lifang Xia
parent c2f876e11e
commit c568ac5ff7
2 changed files with 23 additions and 16 deletions

View File

@@ -1,3 +1,8 @@
2020-09-16 Andrew Burgess <andrew.burgess@embecosm.com>
* csky-dis.c (csky_get_disassembler): Don't return NULL when there
is no BFD.
2020-09-16 Alan Modra <amodra@gmail.com>
* ppc-dis.c (ppc_symbol_is_valid): Adjust elf_symbol_from invocation.

View File

@@ -239,23 +239,25 @@ csky_get_disassembler (bfd *abfd)
obj_attribute *attr;
const char *sec_name = NULL;
if (!abfd)
return NULL;
mach_flag = elf_elfheader (abfd)->e_flags;
sec_name = get_elf_backend_data (abfd)->obj_attrs_section;
/* Skip any input that hasn't attribute section.
This enables to link object files without attribute section with
any others. */
if (bfd_get_section_by_name (abfd, sec_name) != NULL)
{
attr = elf_known_obj_attributes_proc (abfd);
dis_info.isa = attr[Tag_CSKY_ISA_EXT_FLAGS].i;
dis_info.isa <<= 32;
dis_info.isa |= attr[Tag_CSKY_ISA_FLAGS].i;
}
else
dis_info.isa = CSKY_DEFAULT_ISA;
else
{
mach_flag = elf_elfheader (abfd)->e_flags;
sec_name = get_elf_backend_data (abfd)->obj_attrs_section;
/* Skip any input that hasn't attribute section.
This enables to link object files without attribute section with
any others. */
if (bfd_get_section_by_name (abfd, sec_name) != NULL)
{
attr = elf_known_obj_attributes_proc (abfd);
dis_info.isa = attr[Tag_CSKY_ISA_EXT_FLAGS].i;
dis_info.isa <<= 32;
dis_info.isa |= attr[Tag_CSKY_ISA_FLAGS].i;
}
else
dis_info.isa = CSKY_DEFAULT_ISA;
}
return print_insn_csky;
}