On Mon, Apr 19, 2021 at 7:31 PM Jose E. Marchesi via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This patch introduces a dwarf2int.h header, to be used by code that
> needs access to the internal DIE structures and their attributes.
>
> The following functions which were previously defined as static in
> dwarf2out.c are now non-static, and extern prototypes for them have
> been added to dwarf2int.h:
>
> - get_AT
> - AT_int
> - get_AT_ref
> - get_AT_string
> - get_AT_class
> - AT_unsigned
> - get_AT_unsigned
> - get_AT_flag
> - add_name_attribute
> - new_die_raw
> - base_type_die
> - lookup_decl_die
> - get_AT_file
>
> Note how this patch doens't change the names of these functions to
> avoid a massive renaming in dwarf2out.c, but n the future we probably
> want these functions to sport a dw_* prefix.

Or maybe namespaces to the rescue?  We can do use dw; in dwarf2out
to avoid the renaming.

OK unless others disagree.

Richard.

> Also, some type definitions have been moved from dwarf2out.c to
> dwarf2int.h:
>
> - dw_attr_node
> - struct dwarf_file_data
>
> Finally, three new accessor functions have been added to dwarf2out.c
> with prototypes in dwarf2int.h:
>
> - dw_get_die_child
> - dw_get_die_sib
> - dw_get_die_tag
>
> 2021-04-14  Jose E. Marchesi  <jose.march...@oracle.com>
>
>         * dwarf2int.h: New file.
>         * dwarf2out.c (get_AT): Function is no longer static.
>         (get_AT_string): Likewise.
>         (get_AT_flag): Likewise.
>         (get_AT_unsigned): Likewise.
>         (get_AT_ref): Likewise.
>         (new_die_raw): Likewise.
>         (lookup_decl_die): Likewise.
>         (base_type_die): Likewise.
>         (add_name_attribute): Likewise.
>         (dw_get_die_tag): New function.
>         (dw_get_die_child): Likewise.
>         (dw_get_die_sib): Likewise.
>         Include dwarf2int.h.
>         * gengtype.c: add dwarf2int.h to open_base_files.
>         * Makefile.in (GTFILES): Add dwarf2int.h.
> ---
>  gcc/Makefile.in |  1 +
>  gcc/dwarf2int.h | 67 +++++++++++++++++++++++++++++++++++++++++
>  gcc/dwarf2out.c | 79 ++++++++++++++++++++++++-------------------------
>  gcc/gengtype.c  |  6 ++--
>  4 files changed, 109 insertions(+), 44 deletions(-)
>  create mode 100644 gcc/dwarf2int.h
>
> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
> index 8a5fb3fd99c..e464e8c65c5 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -2653,6 +2653,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
> $(srcdir)/coretypes.h \
>    $(srcdir)/ipa-modref.h $(srcdir)/ipa-modref.c \
>    $(srcdir)/ipa-modref-tree.h \
>    $(srcdir)/signop.h \
> +  $(srcdir)/dwarf2int.h \
>    $(srcdir)/dwarf2out.h \
>    $(srcdir)/dwarf2asm.c \
>    $(srcdir)/dwarf2cfi.c \
> diff --git a/gcc/dwarf2int.h b/gcc/dwarf2int.h
> new file mode 100644
> index 00000000000..f49f51d957b
> --- /dev/null
> +++ b/gcc/dwarf2int.h
> @@ -0,0 +1,67 @@
> +/* Prototypes for functions manipulating DWARF2 DIEs.
> +   Copyright (C) 2021 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify it under
> +the terms of the GNU General Public License as published by the Free
> +Software Foundation; either version 3, or (at your option) any later
> +version.
> +
> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* This file contains prototypes for functions defined in dwarf2out.c.  It is
> +   intended to be included in source files that need some internal knowledge 
> of
> +   the GCC dwarf structures.  */
> +
> +#ifndef GCC_DWARF2INT_H
> +#define GCC_DWARF2INT_H 1
> +
> +/* Each DIE attribute has a field specifying the attribute kind,
> +   a link to the next attribute in the chain, and an attribute value.
> +   Attributes are typically linked below the DIE they modify.  */
> +
> +typedef struct GTY(()) dw_attr_struct {
> +  enum dwarf_attribute dw_attr;
> +  dw_val_node dw_attr_val;
> +}
> +dw_attr_node;
> +
> +extern dw_attr_node *get_AT (dw_die_ref, enum dwarf_attribute);
> +extern HOST_WIDE_INT AT_int (dw_attr_node *);
> +extern unsigned HOST_WIDE_INT AT_unsigned (dw_attr_node *a);
> +extern dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
> +extern const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
> +extern enum dw_val_class AT_class (dw_attr_node *);
> +extern unsigned HOST_WIDE_INT AT_unsigned (dw_attr_node *);
> +extern unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
> +extern int get_AT_flag (dw_die_ref, enum dwarf_attribute);
> +
> +extern void add_name_attribute (dw_die_ref, const char *);
> +
> +extern dw_die_ref new_die_raw (enum dwarf_tag);
> +extern dw_die_ref base_type_die (tree, bool);
> +
> +extern dw_die_ref lookup_decl_die (tree);
> +
> +extern dw_die_ref dw_get_die_child (dw_die_ref);
> +extern dw_die_ref dw_get_die_sib (dw_die_ref);
> +extern enum dwarf_tag dw_get_die_tag (dw_die_ref);
> +
> +/* Data about a single source file.  */
> +struct GTY((for_user)) dwarf_file_data {
> +  const char * filename;
> +  int emitted_number;
> +};
> +
> +extern struct dwarf_file_data *get_AT_file (dw_die_ref,
> +                                           enum dwarf_attribute);
> +
> +#endif /* !GCC_DWARF2INT_H */
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 7a15debcb48..f9ff66c81cd 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -80,6 +80,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "expr.h"
>  #include "dwarf2out.h"
>  #include "dwarf2asm.h"
> +#include "dwarf2int.h"
>  #include "toplev.h"
>  #include "md5.h"
>  #include "tree-pretty-print.h"
> @@ -1281,12 +1282,6 @@ dwarf2out_switch_text_section (void)
>  /* And now, the subset of the debugging information support code necessary
>     for emitting location expressions.  */
>
> -/* Data about a single source file.  */
> -struct GTY((for_user)) dwarf_file_data {
> -  const char * filename;
> -  int emitted_number;
> -};
> -
>  /* Describe an entry into the .debug_addr section.  */
>
>  enum ate_kind {
> @@ -3069,17 +3064,6 @@ maybe_reset_location_view (rtx_insn *insn, 
> dw_line_info_table *table)
>      RESET_NEXT_VIEW (table->view);
>  }
>
> -/* Each DIE attribute has a field specifying the attribute kind,
> -   a link to the next attribute in the chain, and an attribute value.
> -   Attributes are typically linked below the DIE they modify.  */
> -
> -typedef struct GTY(()) dw_attr_struct {
> -  enum dwarf_attribute dw_attr;
> -  dw_val_node dw_attr_val;
> -}
> -dw_attr_node;
> -
> -
>  /* The Debugging Information Entry (DIE) structure.  DIEs form a tree.
>     The children of each node form a circular list linked by
>     die_sib.  die_child points to the node *before* the "first" child node.  
> */
> @@ -3657,14 +3641,11 @@ static const char *dwarf_form_name (unsigned);
>  static tree decl_ultimate_origin (const_tree);
>  static tree decl_class_context (tree);
>  static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
> -static inline enum dw_val_class AT_class (dw_attr_node *);
>  static inline unsigned int AT_index (dw_attr_node *);
>  static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
>  static inline unsigned AT_flag (dw_attr_node *);
>  static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
> -static inline HOST_WIDE_INT AT_int (dw_attr_node *);
>  static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned 
> HOST_WIDE_INT);
> -static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_node *);
>  static void add_AT_double (dw_die_ref, enum dwarf_attribute,
>                            HOST_WIDE_INT, unsigned HOST_WIDE_INT);
>  static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned 
> int,
> @@ -3696,12 +3677,7 @@ static void add_AT_macptr (dw_die_ref, enum 
> dwarf_attribute, const char *);
>  static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
>                                 unsigned long, bool);
>  static inline const char *AT_lbl (dw_attr_node *);
> -static dw_attr_node *get_AT (dw_die_ref, enum dwarf_attribute);
>  static const char *get_AT_low_pc (dw_die_ref);
> -static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
> -static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
> -static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
> -static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
>  static bool is_c (void);
>  static bool is_cxx (void);
>  static bool is_cxx (const_tree);
> @@ -3715,7 +3691,6 @@ static dw_die_ref lookup_type_die (tree);
>  static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
>  static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
>  static void equate_type_number_to_die (tree, dw_die_ref);
> -static dw_die_ref lookup_decl_die (tree);
>  static var_loc_list *lookup_decl_loc (const_tree);
>  static void equate_decl_number_to_die (tree, dw_die_ref);
>  static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *, 
> var_loc_view);
> @@ -3788,7 +3763,6 @@ static void output_ranges (void);
>  static dw_line_info_table *new_line_info_table (void);
>  static void output_line_info (bool);
>  static void output_file_names (void);
> -static dw_die_ref base_type_die (tree, bool);
>  static int is_base_type (tree);
>  static dw_die_ref subrange_type_die (tree, tree, tree, tree, dw_die_ref);
>  static int decl_quals (const_tree);
> @@ -3836,7 +3810,6 @@ static rtx rtl_for_decl_location (tree);
>  static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
>  static bool tree_add_const_value_attribute (dw_die_ref, tree);
>  static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
> -static void add_name_attribute (dw_die_ref, const char *);
>  static void add_desc_attribute (dw_die_ref, tree);
>  static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, 
> dw_die_ref);
>  static void add_comp_dir_attribute (dw_die_ref);
> @@ -4441,7 +4414,7 @@ add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
>    vec_safe_push (die->die_attr, *attr);
>  }
>
> -static inline enum dw_val_class
> +enum dw_val_class
>  AT_class (dw_attr_node *a)
>  {
>    return a->dw_attr_val.val_class;
> @@ -4497,7 +4470,7 @@ add_AT_int (dw_die_ref die, enum dwarf_attribute 
> attr_kind, HOST_WIDE_INT int_va
>    add_dwarf_attr (die, &attr);
>  }
>
> -static inline HOST_WIDE_INT
> +HOST_WIDE_INT
>  AT_int (dw_attr_node *a)
>  {
>    gcc_assert (a && (AT_class (a) == dw_val_class_const
> @@ -4520,7 +4493,7 @@ add_AT_unsigned (dw_die_ref die, enum dwarf_attribute 
> attr_kind,
>    add_dwarf_attr (die, &attr);
>  }
>
> -static inline unsigned HOST_WIDE_INT
> +unsigned HOST_WIDE_INT
>  AT_unsigned (dw_attr_node *a)
>  {
>    gcc_assert (a && (AT_class (a) == dw_val_class_unsigned_const
> @@ -5145,6 +5118,30 @@ index_addr_table_entry (addr_table_entry **h, unsigned 
> int *index)
>    return 1;
>  }
>
> +/* Return the tag of a given DIE.  */
> +
> +enum dwarf_tag
> +dw_get_die_tag (dw_die_ref die)
> +{
> +  return die->die_tag;
> +}
> +
> +/* Return a reference to the children list of a given DIE.  */
> +
> +dw_die_ref
> +dw_get_die_child (dw_die_ref die)
> +{
> +  return die->die_child;
> +}
> +
> +/* Return a reference to the sibling of a given DIE.  */
> +
> +dw_die_ref
> +dw_get_die_sib (dw_die_ref die)
> +{
> +  return die->die_sib;
> +}
> +
>  /* Add an address constant attribute value to a DIE.  When using
>     dwarf_split_debug_info, address attributes in dies destined for the
>     final executable should be direct references--setting the parameter
> @@ -5340,7 +5337,7 @@ AT_lbl (dw_attr_node *a)
>
>  /* Get the attribute of type attr_kind.  */
>
> -static dw_attr_node *
> +dw_attr_node *
>  get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
>  {
>    dw_attr_node *a;
> @@ -5395,7 +5392,7 @@ get_AT_low_pc (dw_die_ref die)
>  /* Return the value of the string attribute designated by ATTR_KIND, or
>     NULL if it is not present.  */
>
> -static inline const char *
> +const char *
>  get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
>  {
>    dw_attr_node *a = get_AT (die, attr_kind);
> @@ -5406,7 +5403,7 @@ get_AT_string (dw_die_ref die, enum dwarf_attribute 
> attr_kind)
>  /* Return the value of the flag attribute designated by ATTR_KIND, or -1
>     if it is not present.  */
>
> -static inline int
> +int
>  get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
>  {
>    dw_attr_node *a = get_AT (die, attr_kind);
> @@ -5417,7 +5414,7 @@ get_AT_flag (dw_die_ref die, enum dwarf_attribute 
> attr_kind)
>  /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
>     if it is not present.  */
>
> -static inline unsigned
> +unsigned
>  get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
>  {
>    dw_attr_node *a = get_AT (die, attr_kind);
> @@ -5425,7 +5422,7 @@ get_AT_unsigned (dw_die_ref die, enum dwarf_attribute 
> attr_kind)
>    return a ? AT_unsigned (a) : 0;
>  }
>
> -static inline dw_die_ref
> +dw_die_ref
>  get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
>  {
>    dw_attr_node *a = get_AT (die, attr_kind);
> @@ -5433,7 +5430,7 @@ get_AT_ref (dw_die_ref die, enum dwarf_attribute 
> attr_kind)
>    return a ? AT_ref (a) : NULL;
>  }
>
> -static inline struct dwarf_file_data *
> +struct dwarf_file_data *
>  get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
>  {
>    dw_attr_node *a = get_AT (die, attr_kind);
> @@ -5718,7 +5715,7 @@ splice_child_die (dw_die_ref parent, dw_die_ref child)
>
>  /* Create and return a new die with TAG_VALUE as tag.  */
>
> -static inline dw_die_ref
> +dw_die_ref
>  new_die_raw (enum dwarf_tag tag_value)
>  {
>    dw_die_ref die = ggc_cleared_alloc<die_node> ();
> @@ -5863,7 +5860,7 @@ decl_die_hasher::equal (die_node *x, tree y)
>
>  /* Return the DIE associated with a given declaration.  */
>
> -static inline dw_die_ref
> +dw_die_ref
>  lookup_decl_die (tree decl)
>  {
>    dw_die_ref *die = decl_die_table->find_slot_with_hash (decl, DECL_UID 
> (decl),
> @@ -13056,7 +13053,7 @@ need_endianity_attribute_p (bool reverse)
>     This routine must only be called for GCC type nodes that correspond to
>     Dwarf base (fundamental) types.  */
>
> -static dw_die_ref
> +dw_die_ref
>  base_type_die (tree type, bool reverse)
>  {
>    dw_die_ref base_type_result;
> @@ -20792,7 +20789,7 @@ compute_frame_pointer_to_fb_displacement (poly_int64 
> offset)
>  /* Generate a DW_AT_name attribute given some string value to be included as
>     the value of the attribute.  */
>
> -static void
> +void
>  add_name_attribute (dw_die_ref die, const char *name_string)
>  {
>    if (name_string != NULL && *name_string != 0)
> diff --git a/gcc/gengtype.c b/gcc/gengtype.c
> index 98d4626f87e..16c9a39145e 100644
> --- a/gcc/gengtype.c
> +++ b/gcc/gengtype.c
> @@ -1725,9 +1725,9 @@ open_base_files (void)
>        "tree-dfa.h", "tree-ssa.h", "reload.h", "cpplib.h", "tree-chrec.h",
>        "except.h", "output.h",  "cfgloop.h", "target.h", "lto-streamer.h",
>        "target-globals.h", "ipa-ref.h", "cgraph.h", "symbol-summary.h",
> -      "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "omp-general.h",
> -      "omp-offload.h", "ipa-modref-tree.h", "ipa-modref.h", 
> "symtab-thunks.h",
> -      "symtab-clones.h",
> +      "ipa-prop.h", "ipa-fnsummary.h", "dwarf2out.h", "dwarf2int.h",
> +      "omp-general.h", "omp-offload.h", "ipa-modref-tree.h", "ipa-modref.h",
> +      "symtab-thunks.h", "symtab-clones.h",
>        NULL
>      };
>      const char *const *ifp;
> --
> 2.25.0.2.g232378479e
>

Reply via email to