From: David Faust <david.faust@oracle.com>
To: gcc-patches@gcc.gnu.org
Cc: yhs@fb.com, jose.marchesi@oracle.com
Subject: [PATCH 4/8] dwarf: create BTF decl and type tag DIEs
Date: Fri, 1 Apr 2022 12:42:12 -0700 [thread overview]
Message-ID: <20220401194216.16469-5-david.faust@oracle.com> (raw)
In-Reply-To: <20220401194216.16469-1-david.faust@oracle.com>
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.
---
gcc/dwarf2out.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 35322fb5f6e..8f59213f96e 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;
}
@@ -22986,6 +23062,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;
}
@@ -26060,6 +26140,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. */
@@ -26373,6 +26457,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);
+ }
+ }
}
}
@@ -27129,6 +27227,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;
}
\f
--
2.35.1
next prev parent reply other threads:[~2022-04-01 19:43 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-01 19:42 [PATCH 0/8][RFC] Support BTF decl_tag and type_tag annotations David Faust
2022-04-01 19:42 ` [PATCH 1/8] dwarf: Add dw_get_die_parent function David Faust
2022-04-01 19:42 ` [PATCH 2/8] include: Add BTF tag defines to dwarf2 and btf David Faust
2022-04-01 19:42 ` [PATCH 3/8] c-family: Add BTF tag attribute handlers David Faust
2022-04-01 19:42 ` David Faust [this message]
2022-04-01 19:42 ` [PATCH 5/8] ctfc: Add support to pass through BTF annotations David Faust
2022-04-01 19:42 ` [PATCH 6/8] dwarf2ctf: convert tag DIEs to CTF types David Faust
2022-04-01 19:42 ` [PATCH 7/8] Output BTF DECL_TAG and TYPE_TAG types David Faust
2022-04-01 19:42 ` [PATCH 8/8] testsuite: Add tests for BTF tags David Faust
2022-04-04 22:13 ` [PATCH 0/8][RFC] Support BTF decl_tag and type_tag annotations Yonghong Song
2022-04-05 16:26 ` David Faust
2022-04-18 19:36 ` [ping][PATCH " David Faust
2022-05-02 16:57 ` [ping2][PATCH " David Faust
2022-05-03 22:32 ` Joseph Myers
2022-05-04 17:03 ` David Faust
2022-05-05 23:00 ` Yonghong Song
2022-05-06 21:18 ` David Faust
2022-05-11 3:43 ` Yonghong Song
2022-05-11 5:05 ` Yonghong Song
2022-05-11 18:44 ` David Faust
2022-05-24 6:33 ` Yonghong Song
2022-05-24 11:07 ` Jose E. Marchesi
2022-05-24 15:52 ` Yonghong Song
2022-05-24 15:53 ` David Faust
2022-05-24 16:03 ` Yonghong Song
2022-05-24 17:04 ` David Faust
2022-05-26 7:29 ` Yonghong Song
2022-05-27 19:56 ` David Faust
2022-06-03 2:04 ` Yonghong Song
2022-06-07 21:42 ` David Faust
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=20220401194216.16469-5-david.faust@oracle.com \
--to=david.faust@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jose.marchesi@oracle.com \
--cc=yhs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).