From e6c2f47b45315ba13f25fb57e51389d0c5ed0701 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 7 Mar 2016 00:10:30 +0000 Subject: [PATCH] Fix "set architecture mips:10000" crash Fix this GDB crash: $ gdb -ex "set architecture mips:10000" Segmentation fault (core dumped) Backtrace: Program received signal SIGSEGV, Segmentation fault. 0x0000000000495b1b in mips_gdbarch_init (info=..., arches=0x0) at /home/pedro/gdb/mygit/cxx-convertion/src/gdb/mips-tdep.c:8436 8436 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour (top-gdb) bt #0 0x0000000000495b1b in mips_gdbarch_init (info=..., arches=0x0) at .../src/gdb/mips-tdep.c:8436 #1 0x00000000007348a6 in gdbarch_find_by_info (info=...) at .../src/gdb/gdbarch.c:5155 #2 0x000000000073563c in gdbarch_update_p (info=...) at .../src/gdb/arch-utils.c:522 #3 0x0000000000735585 in set_architecture (ignore_args=0x0, from_tty=1, c=0x26bc870) at .../src/gdb/arch-utils.c:496 #4 0x00000000005f29fd in do_sfunc (c=0x26bc870, args=0x0, from_tty=1) at .../src/gdb/cli/cli-decode.c:121 #5 0x00000000005fd3f3 in do_set_command (arg=0x7fffffffdcdd "mips:10000", from_tty=1, c=0x26bc870) at .../src/gdb/cli/cli-setshow.c:455 #6 0x0000000000836157 in execute_command (p=0x7fffffffdcdd "mips:10000", from_tty=1) at .../src/gdb/top.c:460 #7 0x000000000071abfb in catch_command_errors (command=0x835f6b , arg=0x7fffffffdccc "set architecture mips:10000", from_tty=1) at .../src/gdb/main.c:368 #8 0x000000000071bf4f in captured_main (data=0x7fffffffd750) at .../src/gdb/main.c:1132 #9 0x0000000000716737 in catch_errors (func=0x71af44 , func_args=0x7fffffffd750, errstring=0x106b9a1 "", mask=RETURN_MASK_ALL) at .../src/gdb/exceptions.c:240 #10 0x000000000071bfe6 in gdb_main (args=0x7fffffffd750) at .../src/gdb/main.c:1164 #11 0x000000000040a6ad in main (argc=4, argv=0x7fffffffd858) at .../src/gdb/gdb.c:32 (top-gdb) We already check whether info.abfd is NULL before all other bfd_get_flavour calls in the same function. Just this one case was missing. (This was exposed by a WIP test that tries all "set architecture ARCH" values.) gdb/ChangeLog: 2016-03-07 Pedro Alves * mips-tdep.c (mips_gdbarch_init): Check whether info.abfd is NULL before calling bfd_get_flavour. --- gdb/ChangeLog | 5 +++++ gdb/mips-tdep.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b84326c243d..3f020fffc6d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2016-03-07 Pedro Alves + + * mips-tdep.c (mips_gdbarch_init): Check whether info.abfd is NULL + before calling bfd_get_flavour. + 2016-03-05 Pitchumani Sivanupandi * avr-tdep.c (AVR_LAST_ARG_REGNUM): Define. diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 63c1560f568..178a163cae9 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -8433,7 +8433,8 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) /* On Irix, ELF64 executables use the N64 ABI. The pseudo-sections which describe the ABI aren't present on IRIX. (Even for executables created by gcc.) */ - if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour + if (info.abfd != NULL + && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) found_abi = MIPS_ABI_N64; else -- 2.30.2