From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 969DF3851C33 for ; Tue, 6 Oct 2020 14:29:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 969DF3851C33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 147BF1E4B5; Tue, 6 Oct 2020 10:29:04 -0400 (EDT) Subject: Re: [PATCH v2] gdb: add support for handling core dumps on arm-none-eabi To: Luis Machado , Paul Mathieu Cc: gdb-patches@sourceware.org References: <20201003181451.GA2211174@google.com> From: Simon Marchi Message-ID: <9d2c488d-8763-c17d-e93a-1dbad80bc293@simark.ca> Date: Tue, 6 Oct 2020 10:29:03 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Oct 2020 14:29:05 -0000 On 2020-10-06 8:45 a.m., Luis Machado wrote: > On 10/6/20 1:32 AM, Paul Mathieu via Gdb-patches wrote: >> Seems to me like current_inferior()->gdbarch is returning the >> arm-linux gdbarch. Maybe this is because the main .elf executable >> itself is recognized as arm-linux? I have virtually no control over >> the executable image, so I would not be able to insert the same kind >> of note section as I would for a core file to differentiate it from >> arm-linux executables. > > I think there may be enough hints here and there to be able to tell > those apart via an heuristic. Isn't there a particular note section or > flag that you can fetch and tell it is not a Linux executable but a > bare-metal one? Just so we are on the same page as to why this is happening, can you try to step into function "gdbarch_info_fill" while you're executable is loaded? What I think is happening is that gdbarch_lookup_osabi returns GDB_OSABI_UNKNOWN, because no sniffer identified it. So the default osabi of your build gets used instead: /* From the configured default. */ #ifdef GDB_OSABI_DEFAULT if (info->osabi == GDB_OSABI_UNKNOWN) info->osabi = GDB_OSABI_DEFAULT; #endif So indeed, if there was a sniffer identifying the binary as a "none" osabi, it would probably work. The problem is, how do you write such a sniffer? It's easy to check for a Linux binary, you check for the os abi ELF note. But how do you identify a "none" binary? You would have to check that's it's not a Linux binary, not FreeBSD binary, not a Windows binary, etc. I don't really like the idea of having a "default" osabi that we fall back on, because it can just silently get it wrong, like in this case. I think it would make more sense for the fall back to be "none". Because it's hard to detect a "none" binary, as explained above. In the mean time, for your testing, you can force the osabi to none by using "set osabi none" prior to loading anything. Simon