From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mXFGCxwEGGDyBwAAWB0awg (envelope-from ) for ; Mon, 01 Feb 2021 08:37:32 -0500 Received: by simark.ca (Postfix, from userid 112) id 20DC71EF80; Mon, 1 Feb 2021 08:37:32 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C9F831E590 for ; Mon, 1 Feb 2021 08:37:30 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53CB63834437; Mon, 1 Feb 2021 13:37:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53CB63834437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1612186650; bh=NHcda18/raFtIWp3J8bGMOAk69ejquinrzMudU9Wvn8=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Oj+WGpihKOAmCZTDpsLhMu0MFe4pcI2J1ICD2YgGP8sBA5lgfcd7xvWJqmJ/yKhHI XgQ1aSTX1nvnOjvq5M4ZP9wkQZjLrhNgOUcHuUAO5Tm5VOHZux2VQTSlEhXCjyuLut EXJd6n6J9kCNjzh0F0ZdeI7elOzEqi6O7GjdBVVw= Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id 40110385783A for ; Mon, 1 Feb 2021 13:37:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 40110385783A Received: by mail-qt1-x82c.google.com with SMTP id z9so12173901qtv.6 for ; Mon, 01 Feb 2021 05:37:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NHcda18/raFtIWp3J8bGMOAk69ejquinrzMudU9Wvn8=; b=k30ZXmft4Va1/2EIbvhvs0BU9JP5Z6TtEqFR5pqRgg2i8Ol0qdGofxSjh3vKldkUl9 uj1un7QW9/J7M31cRC0brkuSTopJRDPpgaHH35dBgCkp9aPEA/mlTxyJYsBRNCfnu3ye 9wJi/WP59Rx4SSvZXt9SmiRnVWbc0dZgy7oeZkMaGD7KXHzHJgwHVq7wE+paWYI3FTzj w1ej6gABYrXzFoub6c4frUHxwgOzgrf2ghtB2VIe4ehmZniDA+g67J1H0Q2ywriyrqLc Z2mMycGep0UcL6VLl4hayfJHULKkwAwiC4AN8khemItzYft++kW/MynQ1jbqjhSVcbZC WvQw== X-Gm-Message-State: AOAM532cBsp7UJRKRaLWjj1QW/CArKlIccT4fPBYFi/pwZtNbGRqXY0b R3fUC2iNJ1BwQp5tPmeeGTcexA== X-Google-Smtp-Source: ABdhPJxcPn+R1XfJGSzQqzwkmV8fNil5HTsXPZhEfCgr0GEXupnAgs4bE/Z2tIYXW1CfuPEz44VNMw== X-Received: by 2002:ac8:5e12:: with SMTP id h18mr15149423qtx.335.1612186646767; Mon, 01 Feb 2021 05:37:26 -0800 (PST) Received: from ?IPv6:2804:7f0:8284:848d:c0e:b160:155c:b079? ([2804:7f0:8284:848d:c0e:b160:155c:b079]) by smtp.gmail.com with ESMTPSA id y68sm13844454qkb.132.2021.02.01.05.37.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Feb 2021 05:37:26 -0800 (PST) Subject: Re: [PATCHv2 3/9] gdb: write target description into core file To: Andrew Burgess , gdb-patches@sourceware.org, binutils@sourceware.org References: <80730d605b35e6e8291a11e7cecbbf5a5da5de2f.1611172468.git.andrew.burgess@embecosm.com> Message-ID: <9f77cfb3-e149-289d-29c4-d4d95698210f@linaro.org> Date: Mon, 1 Feb 2021 10:37:21 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <80730d605b35e6e8291a11e7cecbbf5a5da5de2f.1611172468.git.andrew.burgess@embecosm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: Fredrik Hederstierna Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 1/20/21 5:23 PM, Andrew Burgess wrote: > When a core file is created from within GDB add the target description > into a note within the core file. > > When loading a core file, if the target description note is present > then load the target description from the core file. > > The benefit of this is that we can be sure that, when analysing the > core file within GDB, that we are using the exact same target > description as was in use at the time the core file was created. > > In future commits I intend to add support for bare metal core dumps > for some targets. These core dumps will include auxiliary registers, > the availability of which can only be established by looking at the > target description. > > gdb/ChangeLog: > > * corelow.c: Add 'xml-tdesc.h' include. > (core_target::read_description): Load the target description from > the core file when possible. > * gcore.c: Add 'gdbsupport/tdesc.h' include. > (write_gcore_file_1): Write out the target description. > --- > gdb/ChangeLog | 9 +++++++++ > gdb/corelow.c | 24 ++++++++++++++++++++++++ > gdb/gcore.c | 21 +++++++++++++++++++++ > 3 files changed, 54 insertions(+) > > diff --git a/gdb/corelow.c b/gdb/corelow.c > index a63eab4852b..fd8a5c71e22 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -49,6 +49,7 @@ > #include > #include > #include "gdbcmd.h" > +#include "xml-tdesc.h" > > #ifndef O_LARGEFILE > #define O_LARGEFILE 0 > @@ -1000,6 +1001,29 @@ core_target::thread_alive (ptid_t ptid) > const struct target_desc * > core_target::read_description () > { > + /* If the core file contains a target description note then we will use > + that in preference to anything else. */ > + bfd_size_type tdesc_note_size = 0; > + struct bfd_section *tdesc_note_section > + = bfd_get_section_by_name (core_bfd, ".gdb-tdesc"); > + if (tdesc_note_section != nullptr) > + tdesc_note_size = bfd_section_size (tdesc_note_section); > + if (tdesc_note_size > 0) > + { > + gdb::char_vector contents (tdesc_note_size + 1); > + if (bfd_get_section_contents (core_bfd, tdesc_note_section, > + contents.data (), (file_ptr) 0, > + tdesc_note_size)) > + { > + /* Ensure we have a null terminator. */ > + contents [tdesc_note_size] = '\0'; > + const struct target_desc *result > + = string_read_description_xml (contents.data ()); > + if (result != NULL) > + return result; NULL -> nullptr > + } > + } > + > if (m_core_gdbarch && gdbarch_core_read_description_p (m_core_gdbarch)) > { > const struct target_desc *result; > diff --git a/gdb/gcore.c b/gdb/gcore.c > index d62aa3a7109..cecb9146994 100644 > --- a/gdb/gcore.c > +++ b/gdb/gcore.c > @@ -38,6 +38,7 @@ > #include "gdbsupport/gdb_unlinker.h" > #include "gdbsupport/byte-vector.h" > #include "gdbsupport/scope-exit.h" > +#include "gdbsupport/tdesc.h" > > /* The largest amount of memory to read from the target at once. We > must throttle it to limit the amount of memory used by GDB during > @@ -82,6 +83,26 @@ write_gcore_file_1 (bfd *obfd) > note_data = gdbarch_make_corefile_notes (target_gdbarch (), obfd, > ¬e_size); > > + /* Append the target description to the core file. */ > + const struct target_desc *tdesc = gdbarch_target_desc (target_gdbarch ()); > + const char *tdesc_xml > + = tdesc == nullptr ? nullptr : tdesc_get_features_xml (tdesc); > + if (tdesc_xml != nullptr && *tdesc_xml != '\0') > + { > + /* Skip the leading '@'. */ > + if (*tdesc_xml == '@') > + ++tdesc_xml; > + > + /* Include the null terminator in the length. */ > + size_t tdesc_len = strlen (tdesc_xml) + 1; > + > + /* Now add the target description into the core file. */ > + note_data.reset (elfcore_write_register_note (obfd, > + note_data.release (), > + ¬e_size, ".gdb-tdesc", > + tdesc_xml, tdesc_len)); > + } > + > if (note_data == NULL || note_size == 0) > error (_("Target does not support core file generation.")); > > Otherwise this is OK.