From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10119 invoked by alias); 12 Jan 2016 14:10:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 10058 invoked by uid 89); 12 Jan 2016 14:10:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Reading, lucky, $10 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 12 Jan 2016 14:10:29 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 87A891304; Tue, 12 Jan 2016 14:10:28 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0CEAQ5h016372; Tue, 12 Jan 2016 09:10:27 -0500 Message-ID: <56950952.2030504@redhat.com> Date: Tue, 12 Jan 2016 14:10:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Luis Machado , "Maciej W. Rozycki" CC: gdb-patches@sourceware.org, jan.kratochvil@redhat.com Subject: Re: [PATCH] Handle loading improper core files gracefully in the mips backend. References: <1452277948-25292-1-git-send-email-lgustavo@codesourcery.com> <5693CE90.1060709@codesourcery.com> <5694F5BC.3050904@redhat.com> <5694FEB8.10406@codesourcery.com> In-Reply-To: <5694FEB8.10406@codesourcery.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-01/txt/msg00222.txt.bz2 On 01/12/2016 01:25 PM, Luis Machado wrote: > On 01/12/2016 10:46 AM, Pedro Alves wrote: >> On 01/11/2016 03:47 PM, Luis Machado wrote: >>> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c >>> index ca17864..cdfd80e 100644 >>> --- a/gdb/mips-tdep.c >>> +++ b/gdb/mips-tdep.c >>> @@ -8208,6 +8208,12 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) >>> int dspacc; >>> int dspctl; >>> >>> + /* Sanity check the e_machine field. */ >>> + if (info.abfd >>> + && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour >>> + && elf_elfheader (info.abfd)->e_machine != EM_MIPS) >>> + return NULL; >> >> This callback is registered for bfd_arch_mips: >> >> gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); >> >> Does bfd think this a bfd_arch_mips binary? How so? > > In the second time we call gdbarch_info_fill, when opening the core file > alone, we have this: > > p *info > $8 = {bfd_arch_info = 0x0, byte_order = BFD_ENDIAN_UNKNOWN, > byte_order_for_code = BFD_ENDIAN_UNKNOWN, abfd = 0xe1ce80, tdep_info = > 0x0, osabi = GDB_OSABI_UNINITIALIZED, target_desc = 0x0} > > p *info->abfd->arch_info > $10 = {bits_per_word = 32, bits_per_address = 32, bits_per_byte = 8, > arch = bfd_arch_unknown, mach = 0, arch_name = 0x9b799f "unknown", > printable_name = 0x9b799f "unknown", section_align_power = 2, > the_default = 1, compatible = 0x78a592 , > scan = 0x78a60a , fill = 0x78acc6 > , next = 0x0} > > p *default_bfd_arch > $12 = {bits_per_word = 32, bits_per_address = 32, bits_per_byte = 8, > arch = bfd_arch_mips, mach = 0, arch_name = 0x9d98e0 "mips", > printable_name = 0x9d98e0 "mips", section_align_power = 3, the_default = > 1, compatible = 0x832b40 , > scan = 0x78a60a , fill = 0x78acc6 > , next = 0x9d9b00 } > > The data above leads gdbarch_info_fill to assign default_bfd_arch to > info->bfd_arch_info here: > > /* From the default. */ > if (info->bfd_arch_info == NULL) > info->bfd_arch_info = default_bfd_arch; > > So the core file essentially turns into a mips-compatible core file. Hmmm. I see. I think we can't really change this, given that there are formats that don't have an architecture. Like, e.g., srec: (gdb) file testsuite/gdb.base/intstr2.srec Reading symbols from testsuite/gdb.base/intstr2.srec...(no debugging symbols found)...done. I take it that a --enable-targets=all wouldn't fail like this? Also, sounds like you should be able to trigger these incompatibilities and assertion by loading a 32-bit MIPS binary and playing with "set mips abi n64/o64", etc? All in all, maybe your original patch that flagged incompatible abi/isa combination is the way to go? I also wonder whether the bfd arch detection couldn't be always compiled in, at least for elf. Why does bfd fail to detect that this is an bfd_arch_i386 file in the first place? > This also happens with a powerpc-targeted gdb and likely any other > architecture. > > For powerpc we get lucky and end up "passing" this test because it has > no fatal failing conditions. It ends up displaying frame -1 for me, like so: > > PC not available^M > #-1 in ?? () Which is obviously bogus. Thanks, Pedro Alves