public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: David Faust <dfaust@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/dfaust/heads/btf-type-tag-new-rebase)] dwarf: create BTF decl and type tag DIEs Date: Fri, 7 Oct 2022 18:34:36 +0000 (GMT) [thread overview] Message-ID: <20221007183436.46D35385802B@sourceware.org> (raw) https://gcc.gnu.org/g:c71525e7f0d10fcc20892e8986d9a43c1c8f4d64 commit c71525e7f0d10fcc20892e8986d9a43c1c8f4d64 Author: David Faust <david.faust@oracle.com> Date: Wed Mar 2 15:03:34 2022 -0800 dwarf: create BTF decl and type tag DIEs The "btf_decl_tag" and "btf_type_tag" attributes are handled by constructing DW_TAG_LLVM_annotation DIEs. The DIEs are children of the declarations or types which they annotate, and convey the annotation via a string constant. Currently, all generation of these DIEs is gated behind btf_debuginfo_p (). That is, they will not be generated nor output unless BTF debug information is generated. The DIEs will be output in DWARF if both -gbtf and -gdwarf are supplied by the user. gcc/ * dwarf2out.cc (gen_btf_decl_tag_dies): New function. (gen_btf_type_tag_dies): Likewise. (modified_type_die): Call them here, if appropriate. (gen_formal_parameter_die): Likewise. (gen_typedef_die): Likewise. (gen_type_die): Likewise. (gen_decl_die): Likewise. Diff: --- gcc/dwarf2out.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 9429e04cb06..daf9312f0a3 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -13612,6 +13612,78 @@ long_double_as_float128 (tree type) return NULL_TREE; } +/* BTF support. Given a tree T, which may be a decl or a type, process any + "btf_decl_tag" attributes on T, provided in ATTR. Construct + DW_TAG_GNU_annotation DIEs appropriately as children of TARGET, usually + the DIE for T. */ + +static void +gen_btf_decl_tag_dies (tree t, dw_die_ref target) +{ + dw_die_ref die; + tree attr; + + if (t == NULL_TREE || !target) + return; + + if (TYPE_P (t)) + attr = lookup_attribute ("btf_decl_tag", TYPE_ATTRIBUTES (t)); + else if (DECL_P (t)) + attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); + else + /* This is an error. */ + gcc_unreachable (); + + while (attr != NULL_TREE) + { + die = new_die (DW_TAG_GNU_annotation, target, t); + add_name_attribute (die, IDENTIFIER_POINTER (get_attribute_name (attr))); + add_AT_string (die, DW_AT_const_value, + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + attr = TREE_CHAIN (attr); + } + + /* Strip the decl tag attribute to avoid creating multiple copies if we hit + this tree node again in some recursive call. */ + if (TYPE_P (t)) + TYPE_ATTRIBUTES (t) = + remove_attribute ("btf_decl_tag", TYPE_ATTRIBUTES (t)); + else if (DECL_P (t)) + DECL_ATTRIBUTES (t) = + remove_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); +} + +/* BTF support. Given a tree TYPE, process any "btf_type_tag" attributes on + TYPE. Construct DW_TAG_GNU_annotation DIEs appropriately as children of + TARGET, usually the DIE for TYPE. */ + +static void +gen_btf_type_tag_dies (tree type, dw_die_ref target) +{ + dw_die_ref die; + tree attr; + + if (type == NULL_TREE || !target) + return; + + gcc_assert (TYPE_P (type)); + + attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); + while (attr != NULL_TREE) + { + die = new_die (DW_TAG_GNU_annotation, target, type); + add_name_attribute (die, IDENTIFIER_POINTER (get_attribute_name (attr))); + add_AT_string (die, DW_AT_const_value, + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + attr = TREE_CHAIN (attr); + } + + /* Strip the type tag attribute to avoid creating multiple copies if we hit + this type again in some recursive call. */ + TYPE_ATTRIBUTES (type) = + remove_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); +} + /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging entry that chains the modifiers specified by CV_QUALS in front of the given type. REVERSE is true if the type is to be interpreted in the @@ -14010,6 +14082,10 @@ modified_type_die (tree type, int cv_quals, bool reverse, if (TYPE_ARTIFICIAL (type)) add_AT_flag (mod_type_die, DW_AT_artificial, 1); + /* BTF support. Handle any "btf_type_tag" attributes on the type. */ + if (btf_debuginfo_p ()) + gen_btf_type_tag_dies (type, mod_type_die); + return mod_type_die; } @@ -23006,6 +23082,10 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p, gcc_unreachable (); } + /* BTF Support */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (node, parm_die); + return parm_die; } @@ -26084,6 +26164,10 @@ gen_typedef_die (tree decl, dw_die_ref context_die) if (get_AT (type_die, DW_AT_name)) add_pubtype (decl, type_die); + + /* BTF: handle attribute btf_decl_tag which may appear on the typedef. */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (decl, type_die); } /* Generate a DIE for a struct, class, enum or union type. */ @@ -26397,6 +26481,20 @@ gen_type_die (tree type, dw_die_ref context_die) if (die) check_die (die); } + + /* BTF support. Handle any "btf_type_tag" or "btf_decl_tag" attributes + on the type, constructing annotation DIEs as appropriate. */ + if (btf_debuginfo_p ()) + { + dw_die_ref die = lookup_type_die (type); + if (die) + { + gen_btf_type_tag_dies (type, die); + + /* decl tags may also be attached to a type. */ + gen_btf_decl_tag_dies (type, die); + } + } } } @@ -27153,6 +27251,10 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx, break; } + /* BTF: handle attribute btf_decl_tag. */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (decl, lookup_decl_die (decl)); + return NULL; }
reply other threads:[~2022-10-07 18:34 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=20221007183436.46D35385802B@sourceware.org \ --to=dfaust@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).