All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Douglas RAILLARD <douglas.raillard@arm.com>
Cc: acme@redhat.com, dwarves@vger.kernel.org
Subject: Re: [PATCH v2 4/6] pahole.c: Add prefix to expanded type names
Date: Tue, 14 Dec 2021 11:55:56 -0300	[thread overview]
Message-ID: <YbiwfOPqiuZE7SUX@kernel.org> (raw)
In-Reply-To: <20211207173151.2283946-5-douglas.raillard@arm.com>

Em Tue, Dec 07, 2021 at 05:31:49PM +0000, Douglas RAILLARD escreveu:
> From: Douglas Raillard <douglas.raillard@arm.com>
> 
> Add the prefix specified by --expanded_prefix to type names that have
> not been specificaly requested using -C. This allows manual namespacing
> so that these inner types will not conflict with existing headers.
> 
> Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
> ---
>  dwarves.h |  1 +
>  pahole.c  | 29 +++++++++++++++++++++++++++--
>  2 files changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/dwarves.h b/dwarves.h
> index fc5b3fa..0967e5c 100644
> --- a/dwarves.h
> +++ b/dwarves.h
> @@ -90,6 +90,7 @@ struct conf_load {
>   */
>  struct conf_fprintf {
>  	const char *prefix;
> +	const char *name_prefix;
>  	const char *suffix;
>  	int32_t	   type_spacing;
>  	int32_t	   name_spacing;
> diff --git a/pahole.c b/pahole.c
> index 42ba110..e0a1438 100644
> --- a/pahole.c
> +++ b/pahole.c
> @@ -2882,6 +2882,33 @@ out_btf:
>  
>  	bool include_decls = find_pointers_in_structs != 0 || stats_formatter == nr_methods_formatter;
>  	struct prototype *prototype, *n;
> +	static type_id_t class_id;
> +
> +	uint32_t id;
> +	struct tag *pos;
> +	bool skip;
> +	const char *prefix = conf_load->conf_fprintf->name_prefix;
> +	const size_t prefix_len = prefix ? strlen(prefix) : 0;
> +	cu__for_each_type(cu, id, pos) {
> +		if (tag__is_type(pos)) {
> +			const char *name = type__name(tag__type(pos));
> +			if (name && prefix) {
> +				skip = false;
> +				list_for_each_entry_safe(prototype, n, &class_names, node) {
> +					if (!strcmp(prototype->name, name)) {
> +						skip = true;
> +						break;
> +					}
> +				}
> +				if (!skip) {
> +					const size_t len = 1024 + prefix_len;
> +					char *bf = malloc(len);
> +					snprintf(bf, len, "%s%s", prefix, name);
> +					tag__namespace(pos)->name = bf;
> +				}
> +			}
> +		}
> +	}

I don't like this change in place mode, but I understand it is easier to
do it here instead of in all types fprintf routines, but perhaps its
better that way, I'll check how big it would be.

>  
>  	list_for_each_entry_safe(prototype, n, &class_names, node) {
>  
> @@ -2891,8 +2918,6 @@ out_btf:
>  				prototype->type_enum_resolved = type__find_type_enum(tag__type(prototype->class), cu, prototype->type_enum) == 0;
>  			continue;
>  		}
> -
> -		static type_id_t class_id;
>  		struct tag *class = cu__find_type_by_name(cu, prototype->name, include_decls, &class_id);
>  
>  		// couldn't find that class name in this CU, continue to the next one.
> -- 
> 2.25.1

-- 

- Arnaldo

  reply	other threads:[~2021-12-14 14:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07 17:31 [PATCH v2 0/6] improve expanded header Douglas RAILLARD
2021-12-07 17:31 ` [PATCH v2 1/6] Revert "fprintf: Allow making struct/enum/union anonymous" Douglas RAILLARD
2021-12-07 17:31 ` [PATCH v2 2/6] Revert "pahole.c: Add --inner_anonymous option" Douglas RAILLARD
2021-12-07 17:31 ` [PATCH v2 3/6] fprintf: Print types only once Douglas RAILLARD
2021-12-14 14:02   ` Arnaldo Carvalho de Melo
2021-12-14 17:54     ` Douglas Raillard
2021-12-14 14:06   ` Arnaldo Carvalho de Melo
2021-12-14 18:23     ` Douglas Raillard
2021-12-17 18:40       ` Arnaldo Carvalho de Melo
2021-12-07 17:31 ` [PATCH v2 4/6] pahole.c: Add prefix to expanded type names Douglas RAILLARD
2021-12-14 14:55   ` Arnaldo Carvalho de Melo [this message]
2021-12-14 17:50     ` Douglas Raillard
2021-12-14 19:13       ` Arnaldo Carvalho de Melo
2021-12-14 19:18       ` Arnaldo Carvalho de Melo
2021-12-07 17:31 ` [PATCH v2 5/6] pahole.c: Add --expanded_prefix option Douglas RAILLARD
2021-12-07 17:31 ` [PATCH v2 6/6] pahole.c: Add --forward_decl option Douglas RAILLARD
2021-12-08 11:55 ` [PATCH v2 0/6] improve expanded header Arnaldo Carvalho de Melo

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=YbiwfOPqiuZE7SUX@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=douglas.raillard@arm.com \
    --cc=dwarves@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.