Dwarves debugging tools
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	<dwarves@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH dwarves 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes
Date: Tue, 2 Nov 2021 16:21:03 -0700	[thread overview]
Message-ID: <b0eac86f-10ba-7fde-2fbf-3ba742dff858@fb.com> (raw)
In-Reply-To: <CAEf4BzaOuwJtLkEhLcnN4_GjG+qVBUF63ywPkAsZdC2FjxmJuQ@mail.gmail.com>



On 11/1/21 7:58 PM, Andrii Nakryiko wrote:
> On Wed, Oct 27, 2021 at 4:08 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> Emit BTF BTF_KIND_DECL_TAGs for btf_decl_tag attributes attached to
>> typedef declarations. The following is a simple example:
>>    $ cat t.c
>>      #define __tag1 __attribute__((btf_decl_tag("tag1")))
>>      #define __tag2 __attribute__((btf_decl_tag("tag2")))
>>      typedef struct { int a; int b; } __t __tag1 __tag2;
>>      __t g;
>>    $ clang -O2 -g -c t.c
>>    $ pahole -JV t.o
>>      btf_encoder__new: 't.o' doesn't have '.data..percpu' section
>>      Found 0 per-CPU variables!
>>      File t.o:
>>      [1] TYPEDEF __t type_id=2
>>      [2] STRUCT (anon) size=8
>>              a type_id=3 bits_offset=0
>>              b type_id=3 bits_offset=32
>>      [3] INT int size=4 nr_bits=32 encoding=SIGNED
>>      [4] DECL_TAG tag1 type_id=1 component_idx=-1
>>      [5] DECL_TAG tag2 type_id=1 component_idx=-1
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   btf_encoder.c | 12 +++++++++---
>>   1 file changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/btf_encoder.c b/btf_encoder.c
>> index 40f6aa3..2f1f4ae 100644
>> --- a/btf_encoder.c
>> +++ b/btf_encoder.c
>> @@ -1437,19 +1437,25 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
>>          }
>>
>>          cu__for_each_type(cu, core_id, pos) {
>> +               const char *tag_name = "typedef";
>>                  struct namespace *ns;
>>
>> -               if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type)
>> +               if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type &&
>> +                   pos->tag != DW_TAG_typedef)
>>                          continue;
>>
>> +               if (pos->tag == DW_TAG_structure_type)
>> +                       tag_name = "struct";
>> +               else if (pos->tag == DW_TAG_union_type)
>> +                       tag_name = "union";
> 
> nit: switch instead of these two related sets of if/else blocks would be cleaner

Sure. Will make the change in v2.

> 
> 
>> +
>>                  btf_type_id = type_id_off + core_id;
>>                  ns = tag__namespace(pos);
>>                  list_for_each_entry(annot, &ns->annots, node) {
>>                          tag_type_id = btf_encoder__add_decl_tag(encoder, annot->value, btf_type_id, annot->component_idx);
>>                          if (tag_type_id < 0) {
>>                                  fprintf(stderr, "error: failed to encode tag '%s' to %s '%s' with component_idx %d\n",
>> -                                       annot->value, pos->tag == DW_TAG_structure_type ? "struct" : "union",
>> -                                       namespace__name(ns), annot->component_idx);
>> +                                       annot->value, tag_name, namespace__name(ns), annot->component_idx);
>>                                  goto out;
>>                          }
>>                  }
>> --
>> 2.30.2
>>

      reply	other threads:[~2021-11-02 23:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 23:08 [PATCH dwarves 0/2] btf: support typedef DW_TAG_LLVM_annotation Yonghong Song
2021-10-27 23:08 ` [PATCH dwarves 1/2] dwarf_loader: " Yonghong Song
2021-10-27 23:08 ` [PATCH dwarves 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes Yonghong Song
2021-11-02  2:58   ` Andrii Nakryiko
2021-11-02 23:21     ` Yonghong Song [this message]

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=b0eac86f-10ba-7fde-2fbf-3ba742dff858@fb.com \
    --to=yhs@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dwarves@vger.kernel.org \
    --cc=kernel-team@fb.com \
    /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