diff mbox series

[[PATCH,V9] 1/7] dwarf: add a dwarf2int.h internal interface

Message ID 20210531165802.5686-2-jose.marchesi@oracle.com
State New
Headers show
Series [[PATCH,V9] 1/7] dwarf: add a dwarf2int.h internal interface | expand

Commit Message

Jose E. Marchesi May 31, 2021, 4:57 p.m. UTC
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.

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-05-14  Jose E. Marchesi  <jose.marchesi@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

Comments

Jason Merrill June 22, 2021, 8:05 p.m. UTC | #1
On 5/31/21 12:57 PM, Jose E. Marchesi via Gcc-patches wrote:
> This patch introduces a dwarf2int.h header, to be used by code that
> needs access to the internal DIE structures and their attributes.

Why not put these bits in dwarf2out.h?

> 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.
> 
> 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-05-14  Jose E. Marchesi  <jose.marchesi@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 4cb2966157e..95d5e18ad9d 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -2648,6 +2648,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 b99598eb9f8..ea192cd02ff 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"
> @@ -1332,12 +1333,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 {
> @@ -3123,17 +3118,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.  */
> @@ -3711,14 +3695,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,
> @@ -3750,12 +3731,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);
> @@ -3769,7 +3745,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);
> @@ -3842,7 +3817,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);
> @@ -3890,7 +3864,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);
> @@ -4497,7 +4470,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;
> @@ -4553,7 +4526,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
> @@ -4576,7 +4549,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
> @@ -5201,6 +5174,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
> @@ -5398,7 +5395,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;
> @@ -5453,7 +5450,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);
> @@ -5464,7 +5461,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);
> @@ -5475,7 +5472,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);
> @@ -5483,7 +5480,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);
> @@ -5491,7 +5488,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);
> @@ -5776,7 +5773,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> ();
> @@ -5921,7 +5918,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),
> @@ -13150,7 +13147,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;
> @@ -20898,7 +20895,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 b94e2f126ec..c347694fa6a 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;
>
Jose E. Marchesi June 24, 2021, 1:52 p.m. UTC | #2
Hi Jason.

> On 5/31/21 12:57 PM, Jose E. Marchesi via Gcc-patches wrote:
>> This patch introduces a dwarf2int.h header, to be used by code that
>> needs access to the internal DIE structures and their attributes.
>
> Why not put these bits in dwarf2out.h?

We think that it makes sense to have a separated interface file for the
implementation of DWARF-based debug formats.  It is called `internal'
because it provides access to internal data structures as well as the
basic accessor functions to the internals of the DWARF DIEs.

That said, if you think this is a blocker, we can put these definitions
in dwarf2out.h.  But we think dwarf2out.c is in much need of some
refactoring, and this could be a first step in that direction :)
Jason Merrill June 24, 2021, 2:41 p.m. UTC | #3
On 6/24/21 9:52 AM, Jose E. Marchesi wrote:

>> On 5/31/21 12:57 PM, Jose E. Marchesi via Gcc-patches wrote:
>>> This patch introduces a dwarf2int.h header, to be used by code that
>>> needs access to the internal DIE structures and their attributes.
>>
>> Why not put these bits in dwarf2out.h?
> 
> We think that it makes sense to have a separated interface file for the
> implementation of DWARF-based debug formats.  It is called `internal'
> because it provides access to internal data structures as well as the
> basic accessor functions to the internals of the DWARF DIEs.

Yes, but "internal data structures" also describes most of the current 
dwarf2out.h.  I'm not opposed to refactoring the header, but splitting 
off a dwarf2cfi.h (for print-rtl.c and final.c) seems like a better 
dividing line.

Jason
Jose E. Marchesi June 24, 2021, 3:13 p.m. UTC | #4
>>>> This patch introduces a dwarf2int.h header, to be used by code that
>>>> needs access to the internal DIE structures and their attributes.
>>>
>>> Why not put these bits in dwarf2out.h?
>> We think that it makes sense to have a separated interface file for
>> the
>> implementation of DWARF-based debug formats.  It is called `internal'
>> because it provides access to internal data structures as well as the
>> basic accessor functions to the internals of the DWARF DIEs.
>
> Yes, but "internal data structures" also describes most of the current
> dwarf2out.h.

Yes right, dwarf2out.h contains a mixture of function prototypes and
several data structures, many of them "internal".

> I'm not opposed to refactoring the header, but splitting 
> off a dwarf2cfi.h (for print-rtl.c and final.c) seems like a better
> dividing line.

Ok, so what about this: at this point we remove dwarf2int.h from our
patch, put the definitions in dwarf2out.h instead, and then once the
stuff is upstream we can discuss on how better refactor the dwarf2out*
stuff.

Is that ok?
Jason Merrill June 24, 2021, 3:30 p.m. UTC | #5
On 6/24/21 11:13 AM, Jose E. Marchesi wrote:
> 
>>>>> This patch introduces a dwarf2int.h header, to be used by code that
>>>>> needs access to the internal DIE structures and their attributes.
>>>>
>>>> Why not put these bits in dwarf2out.h?
>>> We think that it makes sense to have a separated interface file for
>>> the
>>> implementation of DWARF-based debug formats.  It is called `internal'
>>> because it provides access to internal data structures as well as the
>>> basic accessor functions to the internals of the DWARF DIEs.
>>
>> Yes, but "internal data structures" also describes most of the current
>> dwarf2out.h.
> 
> Yes right, dwarf2out.h contains a mixture of function prototypes and
> several data structures, many of them "internal".
> 
>> I'm not opposed to refactoring the header, but splitting
>> off a dwarf2cfi.h (for print-rtl.c and final.c) seems like a better
>> dividing line.
> 
> Ok, so what about this: at this point we remove dwarf2int.h from our
> patch, put the definitions in dwarf2out.h instead, and then once the
> stuff is upstream we can discuss on how better refactor the dwarf2out*
> stuff.
> 
> Is that ok?

Sounds good.

Jason
Richard Biener June 25, 2021, 7:47 a.m. UTC | #6
On Thu, Jun 24, 2021 at 5:31 PM Jason Merrill via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On 6/24/21 11:13 AM, Jose E. Marchesi wrote:
> >
> >>>>> This patch introduces a dwarf2int.h header, to be used by code that
> >>>>> needs access to the internal DIE structures and their attributes.
> >>>>
> >>>> Why not put these bits in dwarf2out.h?
> >>> We think that it makes sense to have a separated interface file for
> >>> the
> >>> implementation of DWARF-based debug formats.  It is called `internal'
> >>> because it provides access to internal data structures as well as the
> >>> basic accessor functions to the internals of the DWARF DIEs.
> >>
> >> Yes, but "internal data structures" also describes most of the current
> >> dwarf2out.h.
> >
> > Yes right, dwarf2out.h contains a mixture of function prototypes and
> > several data structures, many of them "internal".
> >
> >> I'm not opposed to refactoring the header, but splitting
> >> off a dwarf2cfi.h (for print-rtl.c and final.c) seems like a better
> >> dividing line.
> >
> > Ok, so what about this: at this point we remove dwarf2int.h from our
> > patch, put the definitions in dwarf2out.h instead, and then once the
> > stuff is upstream we can discuss on how better refactor the dwarf2out*
> > stuff.
> >
> > Is that ok?
>
> Sounds good.

Fine with me as well.

Richard.

> Jason
>
diff mbox series

Patch

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 4cb2966157e..95d5e18ad9d 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2648,6 +2648,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 b99598eb9f8..ea192cd02ff 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"
@@ -1332,12 +1333,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 {
@@ -3123,17 +3118,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.  */
@@ -3711,14 +3695,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,
@@ -3750,12 +3731,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);
@@ -3769,7 +3745,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);
@@ -3842,7 +3817,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);
@@ -3890,7 +3864,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);
@@ -4497,7 +4470,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;
@@ -4553,7 +4526,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
@@ -4576,7 +4549,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
@@ -5201,6 +5174,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
@@ -5398,7 +5395,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;
@@ -5453,7 +5450,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);
@@ -5464,7 +5461,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);
@@ -5475,7 +5472,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);
@@ -5483,7 +5480,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);
@@ -5491,7 +5488,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);
@@ -5776,7 +5773,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> ();
@@ -5921,7 +5918,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),
@@ -13150,7 +13147,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;
@@ -20898,7 +20895,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 b94e2f126ec..c347694fa6a 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;