GCC Middle and Back End API Reference
dwarf2ctf.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "target.h"
#include "dwarf2out.h"
#include "dwarf2ctf.h"
#include "ctfc.h"
#include "gt-dwarf2ctf.h"
Include dependency graph for dwarf2ctf.cc:

Functions

static ctf_id_t gen_ctf_type (ctf_container_ref, dw_die_ref)
 
static dw_die_ref ctf_get_AT_type (dw_die_ref die)
 
static HOST_WIDE_INT ctf_get_AT_data_member_location (dw_die_ref die)
 
const charctf_get_die_loc_file (dw_die_ref die)
 
unsigned int ctf_get_die_loc_line (dw_die_ref die)
 
unsigned int ctf_get_die_loc_col (dw_die_ref die)
 
static ctf_id_t gen_ctf_void_type (ctf_container_ref ctfc)
 
static ctf_id_t gen_ctf_unknown_type (ctf_container_ref ctfc)
 
static uint32_t ctf_die_bitsize (dw_die_ref die)
 
static ctf_id_t gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type)
 
static ctf_id_t gen_ctf_pointer_type (ctf_container_ref ctfc, dw_die_ref ptr_type)
 
static ctf_id_t gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_id_t array_elems_type_id, dw_die_ref c, dw_die_ref last)
 
static ctf_id_t gen_ctf_array_type (ctf_container_ref ctfc, dw_die_ref array_type)
 
static ctf_id_t gen_ctf_typedef (ctf_container_ref ctfc, dw_die_ref tdef)
 
static ctf_id_t gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier)
 
static ctf_id_t gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind)
 
static ctf_id_t gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, bool from_global_func)
 
static ctf_id_t gen_ctf_enumeration_type (ctf_container_ref ctfc, dw_die_ref enumeration)
 
static void gen_ctf_variable (ctf_container_ref ctfc, dw_die_ref die)
 
static void gen_ctf_function (ctf_container_ref ctfc, dw_die_ref die)
 
static void ctf_debug_finalize (const char *filename, bool btf)
 
bool ctf_do_die (dw_die_ref die)
 
void ctf_debug_init (void)
 
void ctf_debug_init_postprocess (bool btf)
 
void ctf_debug_early_finish (const char *filename)
 
void ctf_debug_finish (const char *filename)
 

Variables

static dw_die_ref ctf_void_die
 
static dw_die_ref ctf_array_index_die
 
static dw_die_ref ctf_unknown_die
 

Function Documentation

◆ ctf_debug_early_finish()

void ctf_debug_early_finish ( const char * filename)

◆ ctf_debug_finalize()

static void ctf_debug_finalize ( const char * filename,
bool btf )
static

◆ ctf_debug_finish()

void ctf_debug_finish ( const char * filename)
Finish CTF/BTF debug info emission.   

References btf_debuginfo_p(), btf_with_core_debuginfo_p(), ctf_debug_finalize(), and dwarf_file_data::filename.

◆ ctf_debug_init()

void ctf_debug_init ( void )
Initialize CTF subsystem for CTF debug info generation.   

References add_name_attribute(), base_type_die(), ctf_array_index_die, ctf_init(), ctf_unknown_die, ctf_void_die, ggc_alloc(), integer_type_node, and new_die_raw().

◆ ctf_debug_init_postprocess()

void ctf_debug_init_postprocess ( bool btf)
Preprocess the CTF debug information after initialization.   

References btf_init_postprocess(), and ggc_alloc().

◆ ctf_die_bitsize()

static uint32_t ctf_die_bitsize ( dw_die_ref die)
static
Sizes of entities can be given in bytes or bits.  This function
abstracts this by returning the size in bits of the given entity.
If no DW_AT_byte_size nor DW_AT_bit_size are defined, this function
returns 0.   

References AT_unsigned(), get_AT(), and ggc_alloc().

Referenced by gen_ctf_base_type(), gen_ctf_enumeration_type(), and gen_ctf_sou_type().

◆ ctf_do_die()

◆ ctf_get_AT_data_member_location()

static HOST_WIDE_INT ctf_get_AT_data_member_location ( dw_die_ref die)
static
Some data member DIEs have location specified as a DWARF expression
(specifically in DWARF2).  Luckily, the expression is a simple
DW_OP_plus_uconst with one operand set to zero.

Sometimes the data member location may also be negative.  In yet some other
cases (specifically union data members), the data member location is
non-existent.  Handle all these scenarios here to abstract this.   

References AT_class(), AT_int(), AT_loc(), dw_val_class_const, dw_val_class_loc, dw_val_class_unsigned_const, gcc_assert, get_AT(), get_AT_unsigned(), and ggc_alloc().

Referenced by gen_ctf_sou_type().

◆ ctf_get_AT_type()

static dw_die_ref ctf_get_AT_type ( dw_die_ref die)
static
Some DIEs have a type description attribute, stored in a DW_AT_type
attribute.  However, GCC generates no attribute to signify a `void'
type.

This can happen in many contexts (return type of a function,
pointed or qualified type, etc) so we use the `ctf_get_AT_type'
function below abstracts this.   

References ctf_void_die, get_AT_ref(), and ggc_alloc().

Referenced by gen_ctf_array_type(), gen_ctf_enumeration_type(), gen_ctf_function_type(), gen_ctf_modifier_type(), gen_ctf_pointer_type(), gen_ctf_sou_type(), gen_ctf_subrange_type(), gen_ctf_typedef(), and gen_ctf_variable().

◆ ctf_get_die_loc_col()

unsigned int ctf_get_die_loc_col ( dw_die_ref die)

◆ ctf_get_die_loc_file()

const char * ctf_get_die_loc_file ( dw_die_ref die)
CTF Types' and CTF Variables' Location Information.  CTF section does not
emit location information, this is provided for BTF CO-RE use-cases.  These
functions fetch information from DWARF Die directly, as such the location
information is not buffered in the CTF container.   

References dwarf_file_data::filename, get_AT_file(), ggc_alloc(), and NULL.

Referenced by ctfc_get_dtd_srcloc(), and ctfc_get_dvd_srcloc().

◆ ctf_get_die_loc_line()

unsigned int ctf_get_die_loc_line ( dw_die_ref die)

◆ gen_ctf_array_type()

static ctf_id_t gen_ctf_array_type ( ctf_container_ref ctfc,
dw_die_ref array_type )
static

◆ gen_ctf_base_type()

static ctf_id_t gen_ctf_base_type ( ctf_container_ref ctfc,
dw_die_ref type )
static
Generate CTF for base type (integer, boolean, real, fixed point and complex).
Important: the caller of this API must make sure that duplicate types are
not added.   

References ctf_encoding::cte_bits, ctf_encoding::cte_format, ctf_add_float(), ctf_add_integer(), CTF_ADD_ROOT, ctf_die_bitsize(), CTF_NULL_TYPEID, double_type_node, float_type_node, gcc_assert, get_AT_string(), get_AT_unsigned(), ggc_alloc(), long_double_type_node, tree_to_uhwi(), type_id, and TYPE_SIZE.

Referenced by gen_ctf_type().

◆ gen_ctf_enumeration_type()

◆ gen_ctf_function()

static void gen_ctf_function ( ctf_container_ref ctfc,
dw_die_ref die )
static
Add a CTF function record for the given input DWARF DIE.   

References ctf_type_exists(), gen_ctf_function_type(), and ggc_alloc().

Referenced by ctf_do_die().

◆ gen_ctf_function_type()

◆ gen_ctf_modifier_type()

static ctf_id_t gen_ctf_modifier_type ( ctf_container_ref ctfc,
dw_die_ref modifier )
static
Generate CTF for a type modifier.

  If the given DIE contains a valid C modifier (like _Atomic), which is not
  supported by CTF, then this function skips the modifier die and continues
  with the underlying type.

  For all other cases, this function returns a CTF_NULL_TYPEID;

References ctf_add_reftype(), CTF_ADD_ROOT, ctf_get_AT_type(), CTF_NULL_TYPEID, ctf_type_exists(), dw_get_die_tag(), gcc_assert, gen_ctf_type(), and ggc_alloc().

Referenced by gen_ctf_type().

◆ gen_ctf_pointer_type()

static ctf_id_t gen_ctf_pointer_type ( ctf_container_ref ctfc,
dw_die_ref ptr_type )
static

◆ gen_ctf_sou_type()

◆ gen_ctf_subrange_type()

static ctf_id_t gen_ctf_subrange_type ( ctf_container_ref ctfc,
ctf_id_t array_elems_type_id,
dw_die_ref c,
dw_die_ref last )
static
Recursively generate CTF for array dimensions starting at DIE C (of type
DW_TAG_subrange_type) until DIE LAST (of type DW_TAG_subrange_type) is
reached.  ARRAY_ELEMS_TYPE_ID is base type for the array.   

References AT_class(), ctf_add_array(), CTF_ADD_ROOT, ctf_get_AT_type(), CTF_NULL_TYPEID, ctf_type_exists(), dw_get_die_sib(), dw_get_die_tag(), dw_val_class_unsigned_const, gcc_unreachable, gen_ctf_subrange_type(), gen_ctf_type(), get_AT(), get_AT_unsigned(), ggc_alloc(), and last.

Referenced by gen_ctf_array_type(), and gen_ctf_subrange_type().

◆ gen_ctf_type()

static ctf_id_t gen_ctf_type ( ctf_container_ref ctfc,
dw_die_ref die )
static
Generate CTF types and objects from the GCC DWARF.
   Copyright (C) 2021-2024 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/>.   
Forward declarations for some routines defined in this file.   
Add CTF type record(s) for the given input DWARF DIE and return its type id.

If there is already a CTF type corresponding to the given DIE, then
this function returns the type id of the existing type.

If the given DIE is not recognized as a type, then this function
returns CTF_NULL_TYPEID.   

References CTF_NULL_TYPEID, ctf_type_exists(), dw_get_die_tag(), gen_ctf_array_type(), gen_ctf_base_type(), gen_ctf_enumeration_type(), gen_ctf_function_type(), gen_ctf_modifier_type(), gen_ctf_pointer_type(), gen_ctf_sou_type(), gen_ctf_typedef(), gen_ctf_unknown_type(), gen_ctf_void_type(), get_AT_string(), ggc_alloc(), and type_id.

Referenced by ctf_do_die(), gen_ctf_array_type(), gen_ctf_function_type(), gen_ctf_modifier_type(), gen_ctf_pointer_type(), gen_ctf_sou_type(), gen_ctf_subrange_type(), gen_ctf_typedef(), and gen_ctf_variable().

◆ gen_ctf_typedef()

static ctf_id_t gen_ctf_typedef ( ctf_container_ref ctfc,
dw_die_ref tdef )
static

◆ gen_ctf_unknown_type()

static ctf_id_t gen_ctf_unknown_type ( ctf_container_ref ctfc)
static
Generate CTF type of unknown kind.   

References CTF_ADD_ROOT, ctf_add_unknown(), ctf_type_exists(), ctf_unknown_die, gcc_assert, ggc_alloc(), and NULL.

Referenced by gen_ctf_sou_type(), and gen_ctf_type().

◆ gen_ctf_variable()

static void gen_ctf_variable ( ctf_container_ref ctfc,
dw_die_ref die )
static
Add a CTF variable record for the given input DWARF DIE.   

References ctf_add_variable(), ctf_dvd_ignore_lookup(), ctf_dvd_lookup(), ctf_get_AT_type(), gen_ctf_type(), get_AT_flag(), get_AT_ref(), get_AT_string(), and ggc_alloc().

Referenced by ctf_do_die().

◆ gen_ctf_void_type()

static ctf_id_t gen_ctf_void_type ( ctf_container_ref ctfc)
static

Variable Documentation

◆ ctf_array_index_die

dw_die_ref ctf_array_index_die
static

Referenced by ctf_debug_init().

◆ ctf_unknown_die

dw_die_ref ctf_unknown_die
static

◆ ctf_void_die

dw_die_ref ctf_void_die
static
All the DIE structures we handle come from the DWARF information
generated by GCC.  However, there are three situations where we need
to create our own created DIE structures because GCC doesn't
provide them.

The DWARF spec suggests using a DIE with DW_TAG_unspecified_type
and name "void" in order to denote the void type.  But GCC doesn't
follow this advice.  Still we need a DIE to act as a key for void
types, we use ctf_void_die.

Also, if a subrange type corresponding to an array index does not
specify a type then we assume it is `int'.

Finally, for types unrepresentable in CTF, we need a DIE to anchor
them to a CTF type of kind unknown.

The variables below are initialized in ctf_debug_init and hold
references to the proper DIEs.   

Referenced by ctf_debug_init(), ctf_get_AT_type(), and gen_ctf_void_type().