public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Simon Sobisch <simonsobisch@gnu.org>
To: gcc-help@gcc.gnu.org
Subject: Is it possible to insert own "function points" via define in code (similar to #line), especially for --coverage?
Date: Thu, 5 Jan 2023 16:05:31 +0100	[thread overview]
Message-ID: <df9bf2fe-df07-0bd0-15a5-f88057687e23@gnu.org> (raw)

We can do something like

gcc --coverage some.c

and then get the function information after running it with gcov.

This works fine with "plain C", but when executing generated code you're 
out of luck.

Most easy example: bison

it generates relevant #line directives to "switch" between parser.y and 
parser.c.

Inspecting parser.c shows many functions "commonly not interesting" 
(like bison generated state functions), so these generated files are 
often ignored / excluded.

Inspecting parser.y shows all the functions that are defined "directly" 
in the parser.y file (within the  %{} block), but it doesn't show any of 
the most interesting terminals.

The idea is to insert something like
  {
    #function push
    #function my-important-terminal
    code here
    #function pop
  }

and then have gcov consider this part "as if it has been a function".

For a similar case, related to profiling, I've only found the option to 
make the C code non-portable by inserting nested functions here (I 
haven't checked yet, but guess gcov and lcov would handle those similar 
to gdb/perf/...); but maybe there is something "general" that can be 
used instead.

Any insights / ideas?
Thanks a lot,
Simon

                 reply	other threads:[~2023-01-05 15:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=df9bf2fe-df07-0bd0-15a5-f88057687e23@gnu.org \
    --to=simonsobisch@gnu.org \
    --cc=gcc-help@gcc.gnu.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).