From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id TsM6OgHuF2CMBQAAWB0awg (envelope-from ) for ; Mon, 01 Feb 2021 07:03:13 -0500 Received: by simark.ca (Postfix, from userid 112) id E64D11EF80; Mon, 1 Feb 2021 07:03:13 -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 E91B81E590 for ; Mon, 1 Feb 2021 07:03:12 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 635DA3836C0E; Mon, 1 Feb 2021 12:03:12 +0000 (GMT) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id B89743836C7E for ; Mon, 1 Feb 2021 12:03:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B89743836C7E 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-x435.google.com with SMTP id 6so16277243wri.3 for ; Mon, 01 Feb 2021 04:03:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FVBeJ+PSkWnq2RIE7pL5Z2AU49e2e6Ur/FJce4Mixqc=; b=T5r0Yn+We6+RcoCwJ6l+qSwb/EWvpOy7PQA7v2azBNd86CpZa7HM+rWNS+j+4GrQT/ DcoP07b9PCuNJshQ+OlCl47cu7/y3Z3wUMKB9UuB/elVQmOTZxmNbQEGKfsp8k4piTin ZHhy02jygOap392nRVrPktD+4UPgiiflhBy6knkKTIKqA9cU5XX8JgDyGSUyDu9vlllv 4FtpfM/hZHqk7Fn/u6lNb266eD49xrp8CHxOhz6nJA+9pk/Zqck8MVTExIAW1TRDE0PK bGOfYR2Zi9bR+ZDvl6BU7/BZXGuXl+4rq5YfcpfuLc+mqjgIbPWD7+VlokOuwK39CyfM qChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FVBeJ+PSkWnq2RIE7pL5Z2AU49e2e6Ur/FJce4Mixqc=; b=VEEpSN539uPaFYT19N7ztW19/jvMy5a4s1VDGupfxUMHsRnmWCRWJME1cfeIVy1A7X aRO0WcJvjC6dP2EAhQPweDR+BPoTA2YjxMKe/pLQAZPXPPzi89yy69vxj5/V2xaE1GU4 TrmtXpEYSR6euHfaZsGVBzZcLQH9LTxUo7SK8KduoF2lmp/cMrXWqRwwzFPz1Hv6SPHu Qw8rZb4GjsfX+I36ANIcr39MYOpd7AFF9zcbaHFAotH3GTHEDGAg7bLNFUW1BIPa/1zT Fxe8pT4kcMHShFmReTS3sZD2Sk3s5OhkvlPXlHHkdANTF42ULkRZpTC5JuklLL3buc5Y 2ftw== X-Gm-Message-State: AOAM532J38sB4V6E8prkBWUhxckpLhWs9FXJcgYGS0AW4fFwA6hL5Hft tnO+NsA7gPMu3hiRxL5zeMt1Oe8u+kOG7w== X-Google-Smtp-Source: ABdhPJxcn+yYZ0m+M2m2nHDmpi+GP/TZPNcZmZV6NXre+5TGc8+UjmV/wsW59jvbNQc9vXXCM6iOBA== X-Received: by 2002:adf:d1c2:: with SMTP id b2mr18104274wrd.296.1612180985445; Mon, 01 Feb 2021 04:03:05 -0800 (PST) Received: from localhost (host86-191-239-31.range86-191.btcentralplus.com. [86.191.239.31]) by smtp.gmail.com with ESMTPSA id q6sm20388131wmj.32.2021.02.01.04.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 04:03:04 -0800 (PST) Date: Mon, 1 Feb 2021 12:03:04 +0000 From: Andrew Burgess To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: PING: Re: [PATCHv2 4/9] bfd/riscv: prepare to handle bare metal core dump creation Message-ID: <20210201120304.GU265215@embecosm.com> References: <9379a3e1af978103cfa47e869594f0df91d807ea.1611172468.git.andrew.burgess@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9379a3e1af978103cfa47e869594f0df91d807ea.1611172468.git.andrew.burgess@embecosm.com> X-Operating-System: Linux/5.8.13-100.fc31.x86_64 (x86_64) X-Uptime: 12:01:19 up 54 days, 16:45, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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" I believe that this patch was approved here: https://sourceware.org/pipermail/binutils/2020-December/114376.html But I just thought I'd ping in case anyone else on the binutils side wanted to comment. Thanks, Andrew --- * Andrew Burgess [2021-01-20 20:23:10 +0000]: > When creating a core file GDB will call the function > elfcore_write_prstatus to write out the general purpose registers > along with the pid/tid for the thread. > > However, for a bare metal RISC-V tool chain the prstatus*_t types are > not defined so the elfcore_write_prstatus function will return NULL, > preventing core file creation. > > This commit provides the `elf_backend_write_core_note' hook and uses > the provided function to write out the ptstatus information. > > In order to keep changes in the non bare metal tools to a minimum, the > provided backend function will itself return NULL when the prstatus*_t > types are available, the consequence of this is that the generic code > in elfcore_write_prstatus will be used just as before. But, when > prstatus*_t is not available, the new backend function will write out > the prstatus information using predefined offsets. > > This new functionality will be used by a later GDB commit that will > add bare metal core dumps for RISC-V. > > bfd/ChangeLog: > > * elfnn-riscv.c (riscv_write_core_note): New function. > (elf_backend_write_core_note): Define. > --- > bfd/ChangeLog | 6 ++++ > bfd/elfnn-riscv.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 78 insertions(+) > > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c > index b2ec6a29fbf..70a683b45a3 100644 > --- a/bfd/elfnn-riscv.c > +++ b/bfd/elfnn-riscv.c > @@ -4886,6 +4886,77 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec, > # define PRPSINFO_OFFSET_PR_PSARGS 56 > #endif > > +/* Write PRSTATUS and PRPSINFO note into core file. This will be called > + before the generic code in elf.c. By checking the compiler defines we > + only perform any action here if the generic code would otherwise not be > + able to help us. The intention is that bare metal core dumps (where the > + prstatus_t and/or prpsinfo_t might not be available) will use this code, > + while non bare metal tools will use the generic elf code. */ > + > +static char * > +riscv_write_core_note (bfd *abfd ATTRIBUTE_UNUSED, > + char *buf ATTRIBUTE_UNUSED, > + int *bufsiz ATTRIBUTE_UNUSED, > + int note_type ATTRIBUTE_UNUSED, ...) > +{ > + switch (note_type) > + { > + default: > + return NULL; > + > +#if !defined (HAVE_PRPSINFO_T) > + case NT_PRPSINFO: > + { > + char data[PRPSINFO_SIZE] ATTRIBUTE_NONSTRING; > + va_list ap; > + > + va_start (ap, note_type); > + memset (data, 0, sizeof (data)); > + strncpy (data + PRPSINFO_OFFSET_PR_FNAME, va_arg (ap, const char *), 16); > +#if GCC_VERSION == 8000 || GCC_VERSION == 8001 > + DIAGNOSTIC_PUSH; > + /* GCC 8.0 and 8.1 warn about 80 equals destination size with > + -Wstringop-truncation: > + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643 > + */ > + DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION; > +#endif > + strncpy (data + PRPSINFO_OFFSET_PR_PSARGS, va_arg (ap, const char *), 80); > +#if GCC_VERSION == 8000 || GCC_VERSION == 8001 > + DIAGNOSTIC_POP; > +#endif > + va_end (ap); > + return elfcore_write_note (abfd, buf, bufsiz, > + "CORE", note_type, data, sizeof (data)); > + } > +#endif /* !HAVE_PRPSINFO_T */ > + > +#if !defined (HAVE_PRSTATUS_T) > + case NT_PRSTATUS: > + { > + char data[PRSTATUS_SIZE]; > + va_list ap; > + long pid; > + int cursig; > + const void *greg; > + > + va_start (ap, note_type); > + memset (data, 0, sizeof(data)); > + pid = va_arg (ap, long); > + bfd_put_32 (abfd, pid, data + PRSTATUS_OFFSET_PR_PID); > + cursig = va_arg (ap, int); > + bfd_put_16 (abfd, cursig, data + PRSTATUS_OFFSET_PR_CURSIG); > + greg = va_arg (ap, const void *); > + memcpy (data + PRSTATUS_OFFSET_PR_REG, greg, > + PRSTATUS_SIZE - PRSTATUS_OFFSET_PR_REG - ARCH_SIZE / 8); > + va_end (ap); > + return elfcore_write_note (abfd, buf, bufsiz, > + "CORE", note_type, data, sizeof (data)); > + } > +#endif /* !HAVE_PRSTATUS_T */ > + } > +} > + > /* Support for core dump NOTE sections. */ > > static bfd_boolean > @@ -5000,6 +5071,7 @@ riscv_elf_obj_attrs_arg_type (int tag) > #define elf_backend_grok_prstatus riscv_elf_grok_prstatus > #define elf_backend_grok_psinfo riscv_elf_grok_psinfo > #define elf_backend_object_p riscv_elf_object_p > +#define elf_backend_write_core_note riscv_write_core_note > #define elf_info_to_howto_rel NULL > #define elf_info_to_howto riscv_info_to_howto_rela > #define bfd_elfNN_bfd_relax_section _bfd_riscv_relax_section > -- > 2.25.4 >