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_dtdef_ref 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 char * ctf_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_dtdef_ref gen_ctf_void_type (ctf_container_ref ctfc)
 
static ctf_dtdef_ref gen_ctf_unknown_type (ctf_container_ref ctfc)
 
static uint32_t ctf_die_bitsize (dw_die_ref die)
 
static ctf_dtdef_ref gen_ctf_base_type (ctf_container_ref ctfc, dw_die_ref type)
 
static ctf_dtdef_ref gen_ctf_pointer_type (ctf_container_ref ctfc, dw_die_ref ptr_type)
 
static ctf_dtdef_ref gen_ctf_subrange_type (ctf_container_ref ctfc, ctf_dtdef_ref array_elems_type, dw_die_ref c, dw_die_ref last)
 
static ctf_dtdef_ref gen_ctf_array_type (ctf_container_ref ctfc, dw_die_ref array_type)
 
static ctf_dtdef_ref gen_ctf_typedef (ctf_container_ref ctfc, dw_die_ref tdef)
 
static ctf_dtdef_ref gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier)
 
static ctf_dtdef_ref gen_ctf_sou_type (ctf_container_ref ctfc, dw_die_ref sou, uint32_t kind)
 
static ctf_dtdef_ref gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, bool from_global_func)
 
static ctf_dtdef_ref 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)
 
bool ctf_do_die (dw_die_ref die)
 
void ctf_debug_init (void)
 
void ctf_debug_early_finish (const char *filename)
 
void ctf_debug_finish ()
 

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_finish()

void ctf_debug_finish ( void )
Finish CTF/BTF debug info emission.   

References btf_debuginfo_p(), and btf_finish().

◆ 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, integer_type_node, and new_die_raw().

◆ 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(), and get_AT().

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_loc_descr_node::dw_loc_oprnd1, dw_loc_descr_node::dw_loc_oprnd2, dw_val_class_const, dw_val_class_loc, dw_val_class_unsigned_const, gcc_assert, get_AT(), get_AT_unsigned(), dw_val_node::v, dw_val_node::val_class, and dw_val_node::dw_val_struct_union::val_unsigned.

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, and get_AT_ref().

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(), 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_dtdef_ref gen_ctf_array_type ( ctf_container_ref ctfc,
dw_die_ref array_type )
static

◆ gen_ctf_base_type()

static ctf_dtdef_ref 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(), double_type_node, float_type_node, gcc_assert, get_AT_string(), get_AT_unsigned(), long_double_type_node, NULL, tree_to_uhwi(), 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(), ctf_container::ctfc_num_global_funcs, and gen_ctf_function_type().

Referenced by ctf_do_die().

◆ gen_ctf_function_type()

◆ gen_ctf_modifier_type()

static ctf_dtdef_ref 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.

If the modifier is supported by CTF, then this function constructs and
returns an appropate CTF type representing the modifier.

For all other cases, this function returns NULL.   

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

Referenced by gen_ctf_type().

◆ gen_ctf_pointer_type()

static ctf_dtdef_ref gen_ctf_pointer_type ( ctf_container_ref ctfc,
dw_die_ref ptr_type )
static
Generate CTF for a pointer type.   

References ctf_add_pointer(), CTF_ADD_ROOT, ctf_get_AT_type(), ctf_type_exists(), and gen_ctf_type().

Referenced by gen_ctf_type().

◆ gen_ctf_sou_type()

◆ gen_ctf_subrange_type()

static ctf_dtdef_ref gen_ctf_subrange_type ( ctf_container_ref ctfc,
ctf_dtdef_ref array_elems_type,
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 is the CTF type object for the type of the
array elements.   

References AT_class(), ctf_add_array(), CTF_ADD_ROOT, ctf_get_AT_type(), ctf_type_exists(), ctf_arinfo::ctr_contents, ctf_arinfo::ctr_index, ctf_arinfo::ctr_nelems, 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(), and last.

Referenced by gen_ctf_array_type(), and gen_ctf_subrange_type().

◆ gen_ctf_type()

static ctf_dtdef_ref gen_ctf_type ( ctf_container_ref ctfc,
dw_die_ref die )
static
Generate CTF types and objects from the GCC DWARF.
   Copyright (C) 2021-2025 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 NULL.   

References 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(), and NULL.

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_dtdef_ref gen_ctf_typedef ( ctf_container_ref ctfc,
dw_die_ref tdef )
static
Generate CTF for a typedef.   

References CTF_ADD_ROOT, ctf_add_typedef(), ctf_get_AT_type(), ctf_type_exists(), gen_ctf_type(), and get_AT_string().

Referenced by gen_ctf_type().

◆ gen_ctf_unknown_type()

static ctf_dtdef_ref 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, 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(), and get_AT_string().

Referenced by ctf_do_die().

◆ gen_ctf_void_type()

static ctf_dtdef_ref gen_ctf_void_type ( ctf_container_ref ctfc)
static
Generate CTF for the void type.   

References ctf_encoding::cte_bits, ctf_encoding::cte_format, ctf_add_integer(), CTF_ADD_ROOT, ctf_void_die, gcc_assert, and NULL.

Referenced by gen_ctf_type().

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().