From: Luis Machado <luis.machado@linaro.org>
To: Andrew Burgess <andrew.burgess@embecosm.com>,
gdb-patches@sourceware.org, binutils@sourceware.org
Cc: Fredrik Hederstierna <fredrik@hederstierna.com>
Subject: Re: [PATCHv2 3/9] gdb: write target description into core file
Date: Mon, 1 Feb 2021 10:37:21 -0300 [thread overview]
Message-ID: <9f77cfb3-e149-289d-29c4-d4d95698210f@linaro.org> (raw)
In-Reply-To: <80730d605b35e6e8291a11e7cecbbf5a5da5de2f.1611172468.git.andrew.burgess@embecosm.com>
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 <unordered_map>
> #include <unordered_set>
> #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.
next prev parent reply other threads:[~2021-02-01 13:37 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-20 20:23 [PATCHv2 0/9] Bare-metal core dumps for RISC-V Andrew Burgess
2021-01-20 20:23 ` [PATCHv2 1/9] gdb: unify parts of the Linux and FreeBSD core dumping code Andrew Burgess
2021-01-22 12:01 ` Strasuns, Mihails
2021-01-22 18:50 ` Tom Tromey
2021-02-01 11:56 ` Andrew Burgess
2021-02-09 21:52 ` Andrew Burgess
2021-01-20 20:23 ` [PATCHv2 2/9] bfd/binutils: support for gdb target descriptions in the core file Andrew Burgess
2021-01-22 10:47 ` Strasuns, Mihails
2021-01-22 19:30 ` Andrew Burgess
2021-01-25 10:11 ` Strasuns, Mihails
2021-01-25 11:20 ` Andrew Burgess
2021-02-01 12:05 ` PING: " Andrew Burgess
2021-02-01 15:10 ` Strasuns, Mihails
2021-02-01 13:29 ` Luis Machado
2021-02-10 20:45 ` Jim Wilson
2021-01-20 20:23 ` [PATCHv2 3/9] gdb: write target description into " Andrew Burgess
2021-01-22 19:15 ` Tom Tromey
2021-02-01 13:37 ` Luis Machado [this message]
2021-01-20 20:23 ` [PATCHv2 4/9] bfd/riscv: prepare to handle bare metal core dump creation Andrew Burgess
2021-02-01 12:03 ` PING: " Andrew Burgess
2021-02-01 13:48 ` Luis Machado
2021-02-01 14:44 ` Andrew Burgess
2021-02-10 20:57 ` Jim Wilson
2021-01-20 20:23 ` [PATCHv2 5/9] gdb/riscv: introduce bare metal core dump support Andrew Burgess
2021-02-01 14:05 ` Luis Machado
2021-02-03 3:04 ` Palmer Dabbelt
2021-01-20 20:23 ` [PATCHv2 6/9] bfd/binutils: add support for RISC-V CSRs in core files Andrew Burgess
2021-02-01 12:00 ` Andrew Burgess
2021-02-01 14:08 ` Luis Machado
2021-02-10 21:00 ` Jim Wilson
2021-01-20 20:23 ` [PATCHv2 7/9] gdb/riscv: make riscv target description names global Andrew Burgess
2021-02-01 14:22 ` Luis Machado
2021-01-20 20:23 ` [PATCHv2 8/9] gdb/riscv: write CSRs into baremetal core dumps Andrew Burgess
2021-02-01 14:33 ` Luis Machado
2021-01-20 20:23 ` [PATCHv2 9/9] gdb/arm: add support for bare-metal " Andrew Burgess
2021-02-01 14:51 ` Luis Machado
2021-01-22 19:28 ` [PATCHv2 0/9] Bare-metal core dumps for RISC-V Tom Tromey
2021-02-15 17:29 ` [PATCHv3 " Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 1/9] gdb: unify parts of the Linux and FreeBSD core dumping code Andrew Burgess
2021-02-15 22:56 ` Lancelot SIX
2021-02-16 16:55 ` Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 2/9] bfd/binutils: support for gdb target descriptions in the core file Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 3/9] gdb: write target description into " Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 4/9] bfd/riscv: prepare to handle bare metal core dump creation Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 5/9] gdb/riscv: introduce bare metal core dump support Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 6/9] bfd/binutils: add support for RISC-V CSRs in core files Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 7/9] gdb/riscv: make riscv target description names global Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 8/9] gdb/riscv: write CSRs into baremetal core dumps Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 9/9] gdb/arm: add support for bare-metal " Andrew Burgess
2021-05-13 13:42 ` Andrew Burgess
2021-05-13 13:51 ` Luis Machado
2021-05-13 13:56 ` Andrew Burgess
2021-05-15 13:52 ` SV: " sarah@hederstierna.com
2021-06-01 9:00 ` Andrew Burgess
2021-03-01 10:32 ` [PATCHv3 0/9] Bare-metal core dumps for RISC-V Andrew Burgess
2021-03-01 14:45 ` Nick Clifton
2021-03-05 17:35 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f77cfb3-e149-289d-29c4-d4d95698210f@linaro.org \
--to=luis.machado@linaro.org \
--cc=andrew.burgess@embecosm.com \
--cc=binutils@sourceware.org \
--cc=fredrik@hederstierna.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).