From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hZGMC0mRCGCuZAAAWB0awg (envelope-from ) for ; Wed, 20 Jan 2021 15:23:37 -0500 Received: by simark.ca (Postfix, from userid 112) id 067DE1EF80; Wed, 20 Jan 2021 15:23:36 -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 E8D331EF7C for ; Wed, 20 Jan 2021 15:23:34 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38EC3397180B; Wed, 20 Jan 2021 20:23:29 +0000 (GMT) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 3D6EA3857830 for ; Wed, 20 Jan 2021 20:23:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3D6EA3857830 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-x431.google.com with SMTP id a9so20867120wrt.5 for ; Wed, 20 Jan 2021 12:23:25 -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=M3nmLwiRsl8Ncj7A3ENLuVUNMj0mRd1sTzyJ70vF5l4=; b=b++WJ0y5lcLwBq6WlMm081jVxr5KTCChMspEz9UhPDrM0qjGYqfqNI+U9KO0Mklm8+ 3vqkU+1SZQu6rqUJooTNK/1CnQwjy0uoo3lnsix1xzkvSFQ/qee1esg/Mb8xhHVpVfMU qYMfdqvWLfEXzZR/DuHaZn3C5t9nLx8nBVc0LyAuxCJw7gM6rIWb5xYrOjy/Wdfxiel8 t4wH0FTlrsBGNWrLn2qxuF2jO1/R83RBLgocCY3eAOnEhC7P2QzUEOBDi8TCzeIMf22a e3dDZxMEQzXyoHw2p3UKxNAQNhcmz5YTeqCL/z9I+gh7fwk4/8Jvl9J5RGIFsq8HBKqo jpjA== 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=M3nmLwiRsl8Ncj7A3ENLuVUNMj0mRd1sTzyJ70vF5l4=; b=pGOALtyxWhMqmGQnyCCZh+F0bhAf+apqhw4UyONtCnSEv3b+fk87xOkJrvZCgLfvy/ snCbmP7yu4bxYFeQNRclwO7aBdPcTXD8anDWwVbndQoNeEKDbw8z8SlGTWh8CzVkQtgq UxRQRnDwOAO0nXkawtI9Na7YBf9Gczme/UPo73MO9c+4gQ732xqSKNTkyngsJcmaI8Bv Fv778/igVL4BPQfd2xqZqQ/0J/f8HI6ypeaje5fhT/LsmG+W1eRukNeVXR7ODmIjXEiS yLtFeMTczQt5wUnK9X6qUR4MX4vHI6XkUcVq0c79O6x90bR+QWAPbLFJHzgfBnxsZIf6 ewTg== X-Gm-Message-State: AOAM531cU6KEy1kruGg+8GnNZQUtD83pRTK4SkFYrLGKZ/RD3BodHfWa p3/yOJNmfiU47khV+BJvaOpVyU8+kHHB4A== X-Google-Smtp-Source: ABdhPJw2R8cbKpblSAClTG/DC2aGqGBLjswYFmz12o0Hk3HwBcagiAdtWE6e5btDG6oTjp3jjfotiw== X-Received: by 2002:a5d:640c:: with SMTP id z12mr3641725wru.342.1611174204111; Wed, 20 Jan 2021 12:23:24 -0800 (PST) Received: from localhost (host86-180-62-229.range86-180.btcentralplus.com. [86.180.62.229]) by smtp.gmail.com with ESMTPSA id z8sm5792436wrh.65.2021.01.20.12.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 12:23:23 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCHv2 3/9] gdb: write target description into core file Date: Wed, 20 Jan 2021 20:23:09 +0000 Message-Id: <80730d605b35e6e8291a11e7cecbbf5a5da5de2f.1611172468.git.andrew.burgess@embecosm.com> 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: , Cc: Fredrik Hederstierna 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 | 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; + } + } + 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.")); -- 2.25.4