public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: arnaldo.melo@gmail.com
To: Namhyung Kim <namhyung@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>,
	Jiri Olsa <jolsa@kernel.org>,
	dwarves@vger.kernel.org
Subject: [PATCH 1/1] pfunct: Print DW_AT_external=1 functions once
Date: Mon, 26 Aug 2024 20:31:33 -0300	[thread overview]
Message-ID: <Zs0QVVZZfN9H7wQC@x1> (raw)

Namhyung mentioned that 'set_task_cpu' wasn't being printed with pfunct,
that was because those functions (with DW_AT_external=1) were not being
printed at all, out of some wrong expectations, this was added to avoid
printing it multiple times to allow for things like --compile to work,
but that was too much of a big hammer.

So add fn_stats->printed and use it to determine if functions were
already printed.

Also don't print definitions for functions marked as declarations, as it
clashes with the ones in system headers, like __builtin_memcpy, etc.

This all needs a more thorough love and care, but at least for now
--compile works with 'fullcircle tcp.o' (generating the functions and
the types it uses and then compiling it to get the original types and
functions and prints the external functions:

  $ pfunct -F dwarf -f set_task_cpu vmlinux
  void set_task_cpu(struct task_struct * p, unsigned int new_cpu);
  $ pfunct -F btf -f set_task_cpu vmlinux
  void set_task_cpu(struct task_struct * p, unsigned int new_cpu);
  $

Reported-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 pfunct.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/pfunct.c b/pfunct.c
index 938dd724e44a9416..bc3026b384284cb4 100644
--- a/pfunct.c
+++ b/pfunct.c
@@ -49,6 +49,7 @@ struct fn_stats {
 	uint32_t	 nr_expansions;
 	uint32_t	 size_expansions;
 	uint32_t	 nr_files;
+	bool		 printed;
 };
 
 static struct fn_stats *fn_stats__new(struct tag *tag, const struct cu *cu)
@@ -95,11 +96,13 @@ static void fn_stats__delete_list(void)
 	}
 }
 
-static void fn_stats__add(struct tag *tag, const struct cu *cu)
+static struct fn_stats *fn_stats__add(struct tag *tag, const struct cu *cu)
 {
 	struct fn_stats *fns = fn_stats__new(tag, cu);
 	if (fns != NULL)
 		list_add(&fns->node, &fn_stats__list);
+
+	return fns;
 }
 
 static void fn_stats_inline_exps_fmtr(const struct fn_stats *stats)
@@ -366,7 +369,12 @@ static void function__show(struct function *func, struct cu *cu)
 {
 	struct tag *tag = function__tag(func);
 
-	if (func->abstract_origin || func->external)
+	if (func->abstract_origin || func->declaration)
+		return;
+
+	struct fn_stats *fstats = fn_stats__find(func->name);
+
+	if (fstats && fstats->printed)
 		return;
 
 	if (expand_types)
@@ -393,6 +401,11 @@ static void function__show(struct function *func, struct cu *cu)
 	putchar('\n');
 	if (show_variables || show_inline_expansions)
 		function__fprintf_stats(tag, cu, &conf, stdout);
+
+	if (!fstats)
+		fstats = fn_stats__add(tag, cu);
+	if (fstats)
+		fstats->printed = true;
 }
 
 static int cu_function_iterator(struct cu *cu, void *cookie)
-- 
2.46.0


             reply	other threads:[~2024-08-26 23:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-26 23:31 arnaldo.melo [this message]
2024-08-26 23:57 ` [PATCH 1/1] pfunct: Print DW_AT_external=1 functions once Namhyung Kim

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=Zs0QVVZZfN9H7wQC@x1 \
    --to=arnaldo.melo@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=dwarves@vger.kernel.org \
    --cc=jolsa@kernel.org \
    --cc=namhyung@kernel.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