From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ACRRMHjRx19ncQAAWB0awg (envelope-from ) for ; Wed, 02 Dec 2020 12:40:08 -0500 Received: by simark.ca (Postfix, from userid 112) id C33991F0AB; Wed, 2 Dec 2020 12:40:08 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,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 0BDB11E58E for ; Wed, 2 Dec 2020 12:40:08 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40046396D804; Wed, 2 Dec 2020 17:39:43 +0000 (GMT) Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id 21D52395CC64 for ; Wed, 2 Dec 2020 17:39:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 21D52395CC64 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x441.google.com with SMTP id 23so4907630wrc.8 for ; Wed, 02 Dec 2020 09:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WpHh3wgbAEkxEEal2tNqWQml6HCdOFhTbRfHvPFDnMU=; b=ehzhHIBgiv9UMxF1V+2nyFp18zszeJ1CR1vCIr8XHftckNEyuZYpGOm7W3Dl7oyyGe WM4D983odiTcUYSBPJvWkg9YoL/QwqvXXM2kl1utnYq9pjT9cmpJYaEgchhCmVCL78XS RXc7Vj8seRn+Kc36JQRkqs9yF0V+Z7ROwr6xXhzefzg4E5W4585cSillft60NnMNir9o DCrRPTrBwmmEPg/fTIzwip3uPg5OEL1i5rXZt+fXWtWTRLlIbanNQS5tEivDCjIFFUaa M0OUwmEjfX1anzX+T1BfKw7nd5vuL8TMmDI1vs51Mx57nc9BoWLq1J/FS2T5lcbQCVUt NgFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WpHh3wgbAEkxEEal2tNqWQml6HCdOFhTbRfHvPFDnMU=; b=qyJlHae4coFRW7CCFGEBI0QkG+SlOecACJg3S6HmdAIEv9wO/4O8cFjCuWeZypEBn8 L9iw1BvnbuFul2vWoQ9yV+lWn3ZBRRO6zkCtypqY0hZFOL8EiopJ0bnxhkAB/AOD7CI0 BMjZ0YM8hSU/SGHB0TkiiLBpL5G39OkPudk6KORD2dbTseOD8quKjlCAmpN5GP/lbqRo +so/n7qFEezAKvhk/UZGhGf9xoqEL7bmJIKK+K9q6L7ZPY+tTceUO5W5/R8EY/MruNrk NrxMip6x53eMKccsHsuQeN7UOhBYthQ5TEEW9hPXA4hslFWqvZ7g5ootgXARZ7UCWfF+ rQXQ== X-Gm-Message-State: AOAM533npbINV89jvk24yD00VZOL1SVMI0GSPCbuazkn6BpbYmj/sMrT K5EHxows5zRFb3odcDVYupmMNg== X-Google-Smtp-Source: ABdhPJy2djW08GXNw5xdAukROe+j50iea9jiAleNcFKt96IoCfble9lbDDflNXEdDOUy6z829kmhFQ== X-Received: by 2002:a5d:44d1:: with SMTP id z17mr4651795wrr.423.1606930779284; Wed, 02 Dec 2020 09:39:39 -0800 (PST) Received: from localhost (host109-154-20-215.range109-154.btcentralplus.com. [109.154.20.215]) by smtp.gmail.com with ESMTPSA id 90sm2895522wra.95.2020.12.02.09.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 09:39:38 -0800 (PST) From: Andrew Burgess To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: [PATCH 3/8] gdb: write target description into core file Date: Wed, 2 Dec 2020 17:39:27 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 | 22 ++++++++++++++++++++++ gdb/gcore.c | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/gdb/corelow.c b/gdb/corelow.c index 4c1f068053d..a35c829c55b 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,27 @@ 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); + if (bfd_get_section_contents (core_bfd, tdesc_note_section, + contents.data(), (file_ptr) 0, + tdesc_note_size)) + { + const struct target_desc *result + = string_read_description_xml (contents.data ()); + if (result != NULL) + return result; + } + } + 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 9a22b1005f0..bf6f44213bb 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,25 @@ 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_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.")); -- 2.25.4