From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 36D253857807 for ; Fri, 20 Nov 2020 09:25:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 36D253857807 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sebastian.huber@embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1kg2fE-0006Eq-W8; Fri, 20 Nov 2020 10:25:09 +0100 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1kg2fE-000WDe-Ss; Fri, 20 Nov 2020 10:25:08 +0100 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id D0B7C2A1610; Fri, 20 Nov 2020 10:21:49 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id w2mPbMrGJxj8; Fri, 20 Nov 2020 10:21:49 +0100 (CET) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 623BB2A165B; Fri, 20 Nov 2020 10:21:49 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 8HxERdQaYC91; Fri, 20 Nov 2020 10:21:49 +0100 (CET) Received: from shuber-nb-linux.eb.localhost (unknown [10.10.171.18]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 391892A1610; Fri, 20 Nov 2020 10:21:49 +0100 (CET) Subject: Re: [PATCH] gcov: Add __gcov_info_to_gdca() To: =?UTF-8?Q?Martin_Li=c5=a1ka?= , gcc-patches@gcc.gnu.org References: <20201117095741.3143-1-sebastian.huber@embedded-brains.de> <5d8b78e4-5c8b-3dde-e551-560e077bde5c@suse.cz> From: Sebastian Huber Message-ID: <1209b985-8be3-3dc4-9dc5-533d5d410f0e@embedded-brains.de> Date: Fri, 20 Nov 2020 10:25:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <5d8b78e4-5c8b-3dde-e551-560e077bde5c@suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.102.4/25993/Thu Nov 19 14:11:24 2020) X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Nov 2020 09:25:13 -0000 On 20/11/2020 09:37, Martin Li=C5=A1ka wrote: > On 11/17/20 10:57 AM, Sebastian Huber wrote: >> This is a proposal to get the gcda data for a gcda info in a=20 >> free-standing >> environment.=C2=A0 It is intended to be used with the=20 >> -fprofile-info-section option. >> A crude test program which doesn't use a linker script is: > > Hello. > > I'm not pretty sure how this set up is going to work. Can you please=20 > explain me that? > > I was thinking about your needs and I can imagine various techniques=20 > how to generate > gcda files format: > > 1) embedded system can override fopen, fwrite, fseek to a functions=20 > that do a remote > write-related functions Yes, this is one option, however, the inhibit_libc disables quite a lot=20 of libgcov functionality if Newlib is used for example. > > 2) - use -fprofile-info-section > =C2=A0=C2=A0 - run an app on an embedded system and do a memory dump to= a=20 > terminal/console > =C2=A0=C2=A0 - take the memory dump to a host system (with IO), run=20 > __gcov_init_from_memory_dump (...) > =C2=A0=C2=A0=C2=A0=C2=A0 and then do a normal __gcov_dump I am not sure if a plain memory dump really simplifies things. You have=20 to get the filename separately since it is only referenced in gcov_info=20 and not included in the structure: struct gcov_info { [...] =C2=A0 const char *filename;=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 /* out= put file name */ [...] #ifndef IN_GCOV_TOOL =C2=A0 const struct gcov_fn_info *const *functions; /* pointer to pointe= rs =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = to function=20 information=C2=A0 */ [...] #endif /* !IN_GCOV_TOOL */ }; Also the gcov_fn_info is not embedded in the gcov_info structure. If you=20 do a plain memory dump, then you dump also pointers and how do you deal=20 with these pointers on the host? You would need some extra information=20 to describe the memory dump. So, why not use the gcda format for this?=20 It is also more compact since zero value counters are skipped. Serial=20 lines are slow, so less data to transfer is good. /* Convert the gcov information to a gcda data stream.=C2=A0 The first=20 callback is =C2=A0=C2=A0 called exactly once with the filename associated with the g= cov=20 information. =C2=A0=C2=A0 The filename may be NULL.=C2=A0 Afterwards, the second call= back is=20 subsequently =C2=A0=C2=A0 called with chunks (the begin and length of the chunk are p= assed as the =C2=A0=C2=A0 first two arguments) of the gcda data stream.=C2=A0 The fou= rth parameter is a =C2=A0=C2=A0 user-provided argument passed as the last argument to the c= allback =C2=A0=C2=A0 functions.=C2=A0 */ extern void __gcov_info_to_gcda (const struct gcov_info *gi_ptr, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0void (*filename) (const char *name, void *arg), =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0void (*dump) (const void *begin, unsigned size, void=20 *arg), =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0void *arg); If __gcov_info_to_gcda() is correctly implemented, then this should give=20 you directly gcda files if you use something like this: #include #include extern const struct gcov_info *__gcov_info_start[]; extern const struct gcov_info *__gcov_info_end[]; static void filename (const char *f, void *arg) { =C2=A0 FILE **file =3D arg; =C2=A0 *file =3D fopen(f, "rb"); } static void dump (const void *d, unsigned n, void *arg) { =C2=A0 FILE **file =3D arg; =C2=A0 fwrite(d, n, 1, *file); } static void dump_gcov_info (void) { =C2=A0 const struct gcov_info **info =3D __gcov_info_start; =C2=A0 const struct gcov_info **end =3D __gcov_info_end; =C2=A0 /* Obfuscate variable to prevent compiler optimizations.=C2=A0 */ =C2=A0 __asm__ ("" : "+r" (end)); =C2=A0 while (info !=3D end) =C2=A0 { =C2=A0=C2=A0=C2=A0 FILE *file =3D NULL; =C2=A0=C2=A0=C2=A0 __gcov_info_to_gcda (*info, filename, dump, &file); =C2=A0=C2=A0=C2=A0 fclose(file); =C2=A0=C2=A0=C2=A0 ++info; =C2=A0 } } int main() { =C2=A0 dump_gcov_info(); =C2=A0 return 0; } The callback functions give the user the full control how the data of=20 the gcda file is encoded for the transfer to a host. No gcov internals=20 are exposed. --=20 embedded brains GmbH Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de Phone: +49-89-18 94 741 - 16 Fax: +49-89-18 94 741 - 08 PGP: Public key available on request. embedded brains GmbH Registergericht: Amtsgericht M=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains= .de/datenschutzerklaerung/