public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: GCC's instrumentation and the target environment
@ 2019-11-20 15:22 David Taylor
  2019-11-21 12:43 ` Martin Liška
  0 siblings, 1 reply; 8+ messages in thread
From: David Taylor @ 2019-11-20 15:22 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc, dtaylor

Sorry for not responding sooner.

Thanks Martin.

Like Joel we have a third party solution to instrumentation.  Part of
my objection to the third party solution is freedom.  There are
customizations we would like, but not having source we're at the mercy
of the vendor both for whether it gets done and the timing.  Part of
the objection is the massive amount of changes I had to make to our
build system to integrate it and the resulting feeling of fragility.
They are reportedly addressing the latter in a future release.

By contrast, looking at GCC based instrumentation, the changes
required to our build system are very small and easy.

Part of my purpose in posting was the belief that this problem --
wanting to instrument embedded code -- is not uncommon and has likely
been solved already.  And the hope that one of the solvers would feel
that their existing solution was in a good enough shape to contribute
back.  Or that someone would point out that there is already an
existing {Free | Open} source solution that I am overlooking.

Since no one has mentioned an existing solution, here is a first draft
of a proposed solution to GCC instrumentation not playing well with
embedded...

NOTE: *NONE* of the following has been implemented as yet.  I would
ulimately like this to be something that once implemented would be
considered for becoming part of standard GCC.  So, if you see something
that would impede that goal or if changed would improve its chances,
please speak up.

Add a new configure options --{with|without}-libgcov-standalone-env

Default: without (i.e., hosted)

Question: should hosted libgcov be the default for all configuration
tuples?  Or should it only be the default when there are headers?
Or...?

When standalone, when building libgcov.a files, suppress
-Dinhibit_libc and add -DLIBGCOV_STANDALONE_ENV to the command line
switches.

Then in libgcov-driver.c, libgcov-driver-system.c, gcov-io.c, replace

all calls of fopen    with calls of __gcov_open_int
             fread                  __gcov_read_int
	     fwrite                 __gcov_write_int
	     fclose                 __gcov_close_int
	     fseek                  __gcov_seek_int
	     ftell                  __gcov_tell_int

	     setbuf                 __gcov_setbuf_int

	         Probably belongs inside __gcov_open_int instead of as
	         a separate routine.

	     getenv                 __gcov_getenv_int

	     abort                  __gcov_abort_int

                 When the application is 'the kernel' or 'the system',
                 abort isn't really an option.

	     fprintf                __gcov_fprintf_int

                 This is called in two places -- gcov_error and
                 gcov_exit_open_gcda_file.  The latter hard codes the
                 stream as stderr; the former calls get_gcov_error_file
                 to get the stream (which defaults to stderr but can be
                 overridded via an environment variable).

		 I think that get_gcov_error_file should be renamed to
		 __gcov_get_error_file, be made non-static, and be
		 called by gcov_exit_open_gcda_file instead of hard
		 coding stderr.

		 For that matter, I feel that gcov_exit_open_gcda_file
		 should just call __gcov_error instead of doing it's
		 own error reporting.  And __gcov_get_error_file and
		 __gcov_error should be a replacable routines as
		 embedded systems might well have a different way of
		 reporting errors.

	     vfprintf               __gcov_vfprintf_int

	     	 If gcov_open_gcda_file is altered to call
	     	 __gcov_error and __gcov_error becomes a replacable
	     	 routine, then fprintf and vfprintf do not need to be
	     	 wrapped.

	     malloc                 __gcov_malloc_int
	     free                   __gcov_free_int

	         Embedded applications often do memory allocation
	         differently.
	     
While I think that the above list is complete, I wouldn't be surprised
if I missed one or two.

Other than __gcov_open_int, there would be no conflict if the _int was
left off the end.  I put it on to emphasize that these routines were
not meant to be called by the user, but rather are provided by the
user.  Some other naming convention might be better.

There would be a new header file, included as appropriate.  If the
normal (hosted) build was in effect, then some new (potentially one
line static inline) functions would be defined for each of the above
functions that just call the expected standard libc function.  If the
embedded (standalone) build was in effect, then there would be extern
declarations for each of the above, but *NO* definition -- the
definition would be the reposibility of the application.

Comments?

David

^ permalink raw reply	[flat|nested] 8+ messages in thread
* GCC's instrumentation and the target environment
@ 2019-11-01 18:18 David Taylor
  2019-11-04  9:19 ` Martin Liška
  2020-11-14 13:04 ` Sebastian Huber
  0 siblings, 2 replies; 8+ messages in thread
From: David Taylor @ 2019-11-01 18:18 UTC (permalink / raw)
  To: gcc; +Cc: dtaylor

I wish to use GCC based instrumentation on an embedded target.  And I
am finding that GCC's libgcov.a is not well suited to my needs.

Ideally, all the application entry points and everthing that knows
about the internals of the implementation would be in separate files
from everything that does i/o or otherwise uses 'system services'.

Right now GCC has libgcov-driver.c which includes both gcov-io.c and
libgcov-driver-system.c.

What I'd like is a stable API between the routines that 'collect' the
data and the routines that do the i/o.  With the i/o routines being
non-static and in a separate file from the others that is not
#include'd.

I want them to be replaceable by the application.  Depending upon
circumstances I can imagine the routines doing network i/o, disk i/o,
or using a serial port.

I want one version of libgcov.a for all three with three different
sets of i/o routines that I can build into the application.  If the
internals of instrumentation changes, I want to not have to change the
i/o routines or anything in the application.

If you think of it in disk driver terms, some of the routines in
libgcov.a provide a DDI -- an interface of routines that the
application call call.  For applications that exit, one of the
routines is called at program exit.  For long running applications,
there are routines in the DDI to dump and flush the accumulated
information.

And the i/o routines can be thought of as providing a DKI -- what the
library libgcov.a expects of the environment -- for example, fopen and
fwrite.

There's also the inhibit_libc define.  While if you don't have headers
you might have a hard time including <stdio.h> or some of the other
header files, if the environment has a way of doing i/o or saving the
results, there is no real reason why it should not be possible to
provide instrumentation.

Comments?

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-11-14 13:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 15:22 GCC's instrumentation and the target environment David Taylor
2019-11-21 12:43 ` Martin Liška
  -- strict thread matches above, loose matches on Subject: below --
2019-11-01 18:18 David Taylor
2019-11-04  9:19 ` Martin Liška
2019-11-04 13:06   ` David.Taylor
2019-11-04 13:45     ` Joel Sherrill
2019-11-06  8:04     ` Martin Liška
2020-11-14 13:04 ` Sebastian Huber

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).