public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Faust <david.faust@oracle.com>
To: gcc-patches@gcc.gnu.org
Cc: jose.marchesi@oracle.com, yhs@fb.com
Subject: [PATCH 4/9] dwarf: generate annotation DIEs
Date: Tue,  7 Jun 2022 14:43:37 -0700	[thread overview]
Message-ID: <20220607214342.19463-5-david.faust@oracle.com> (raw)
In-Reply-To: <20220607214342.19463-1-david.faust@oracle.com>

The "debug_annotate_decl" and "debug_annotate_type" attributes are
handled by constructing DW_TAG_GNU_annotation DIEs. These DIEs are
children of the declarations or types which they annotate, and convey
the information via a string constant.

gcc/

	* dwarf2out.cc (gen_decl_annotation_dies): New function.
	(gen_type_annotation_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 | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 9c61026bb34..aff9f72bd55 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -13611,6 +13611,78 @@ long_double_as_float128 (tree type)
   return NULL_TREE;
 }
 
+/* Given a tree T, which may be a decl or a type, process any
+   "debug_annotate_decl" 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_decl_annotation_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 ("debug_annotate_decl", TYPE_ATTRIBUTES (t));
+  else if (DECL_P (t))
+    attr = lookup_attribute ("debug_annotate_decl", 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 ("debug_annotate_decl", TYPE_ATTRIBUTES (t));
+  else if (DECL_P (t))
+    DECL_ATTRIBUTES (t) =
+      remove_attribute ("debug_annotate_decl", DECL_ATTRIBUTES (t));
+}
+
+/* Given a tree TYPE, process any "debug_annotate_type" attributes on
+   TYPE. Construct DW_TAG_GNU_annotation DIEs appropriately as children of
+   TARGET, usually the DIE for TYPE.  */
+
+static void
+gen_type_annotation_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 ("debug_annotate_type", 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 ("debug_annotate_type", 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
@@ -14009,6 +14081,9 @@ modified_type_die (tree type, int cv_quals, bool reverse,
   if (TYPE_ARTIFICIAL (type))
     add_AT_flag (mod_type_die, DW_AT_artificial, 1);
 
+  /* Generate any annotation DIEs on this type.  */
+  gen_type_annotation_dies (type, mod_type_die);
+
   return mod_type_die;
 }
 
@@ -23002,6 +23077,9 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
       gcc_unreachable ();
     }
 
+  /* Generate any annotation DIEs for this decl.  */
+  gen_decl_annotation_dies (node, parm_die);
+
   return parm_die;
 }
 
@@ -26076,6 +26154,9 @@ gen_typedef_die (tree decl, dw_die_ref context_die)
 
   if (get_AT (type_die, DW_AT_name))
     add_pubtype (decl, type_die);
+
+  /* Generate any annotation DIEs for the typedef.  */
+  gen_decl_annotation_dies (decl, type_die);
 }
 
 /* Generate a DIE for a struct, class, enum or union type.  */
@@ -26389,6 +26470,16 @@ gen_type_die (tree type, dw_die_ref context_die)
 	  if (die)
 	    check_die (die);
 	}
+
+      /* Generate any annotation DIEs on the type.  */
+      dw_die_ref die = lookup_type_die (type);
+      if (die)
+	{
+	  gen_type_annotation_dies (type, die);
+
+	  /* "decl" annotations may also be attached to a type.  */
+	  gen_decl_annotation_dies (type, die);
+	}
     }
 }
 
@@ -27145,6 +27236,9 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
       break;
     }
 
+  /* Generate any annotation DIEs for the decl.  */
+  gen_decl_annotation_dies (decl, lookup_decl_die (decl_or_origin));
+
   return NULL;
 }
 \f
-- 
2.36.1


  parent reply	other threads:[~2022-06-07 21:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 21:43 [PATCH 0/9] Add debug_annotate attributes David Faust
2022-06-07 21:43 ` [PATCH 1/9] dwarf: add dw_get_die_parent function David Faust
2022-06-13 10:13   ` Richard Biener
2022-06-07 21:43 ` [PATCH 2/9] include: Add new definitions David Faust
2022-06-07 21:43 ` [PATCH 3/9] c-family: Add debug_annotate attribute handlers David Faust
2022-06-07 21:43 ` David Faust [this message]
2022-06-07 21:43 ` [PATCH 5/9] ctfc: pass through debug annotations to BTF David Faust
2022-06-07 21:43 ` [PATCH 6/9] dwarf2ctf: convert annotation DIEs to CTF types David Faust
2022-06-07 21:43 ` [PATCH 7/9] btf: output decl_tag and type_tag records David Faust
2022-06-07 21:43 ` [PATCH 8/9] doc: document new attributes David Faust
2022-06-07 21:43 ` [PATCH 9/9] testsuite: add debug annotation tests David Faust
2022-06-15  5:53 ` [PATCH 0/9] Add debug_annotate attributes Yonghong Song
2022-06-15 20:57   ` David Faust
2022-06-15 22:56     ` Yonghong Song
2022-06-17 17:18       ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type,decl} WAS: " Jose E. Marchesi
2022-06-20 17:06         ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type, decl} " Yonghong Song
2022-06-21 16:12           ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type,decl} " Jose E. Marchesi
2022-06-24 18:01             ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type, decl} " Yonghong Song
2022-07-07 20:24               ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type,decl} " Jose E. Marchesi
2022-07-13  4:23                 ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type, decl} " Yonghong Song
2022-07-14 15:09                   ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type,decl} " Jose E. Marchesi
2022-07-15  1:20                     ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type, decl} " Yonghong Song
2022-07-15 14:17                       ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type,decl} " Jose E. Marchesi
2022-07-15 16:48                         ` kernel sparse annotations vs. compiler attributes and debug_annotate_{type, decl} " Yonghong Song
2022-11-01 22:29       ` Yonghong Song

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=20220607214342.19463-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).