/* Compact ANSI-C Type Format (CTF) support in GDB.
- Copyright (C) 2019-2022 Free Software Foundation, Inc.
+ Copyright (C) 2019-2023 Free Software Foundation, Inc.
This file is part of GDB.
#include "complaints.h"
#include "block.h"
#include "ctfread.h"
-#include "psympriv.h"
+#include "psymtab.h"
#if ENABLE_LIBCTF
ctf_psymtab (const char *filename,
psymtab_storage *partial_symtabs,
objfile_per_bfd_storage *objfile_per_bfd,
- CORE_ADDR addr)
+ unrelocated_addr addr)
: standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
{
}
return;
/* Record the field count, allocate space for the array of fields. */
- type->set_num_fields (nfields);
- type->set_fields
- ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
+ type->alloc_fields (nfields);
/* Copy the saved-up fields into the field vector. */
for (int i = 0; i < nfields; ++i)
const struct floatformat **format;
struct type *type;
+ type_allocator alloc (objfile);
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format != nullptr)
- type = init_float_type (objfile, bits, name, format);
+ type = init_float_type (alloc, bits, name, format);
else
- type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
+ type = alloc.new_type (TYPE_CODE_ERROR, bits, name);
return type;
}
if (t == nullptr)
{
complaint (_("ctf_add_member_cb: %s has NO type (%ld)"), name, tid);
- t = objfile_type (ccp->of)->builtin_error;
+ t = builtin_type (ccp->of)->builtin_error;
set_tid_type (ccp->of, tid, t);
}
}
fp->set_type (t);
fp->set_loc_bitpos (offset / TARGET_CHAR_BIT);
- FIELD_BITSIZE (*fp) = get_bitsize (ccp->fp, tid, kind);
+ fp->set_bitsize (get_bitsize (ccp->fp, tid, kind));
fip->fields.emplace_back (new_field);
fp->set_name (name);
fp->set_type (nullptr);
fp->set_loc_enumval (enum_value);
- FIELD_BITSIZE (*fp) = 0;
+ fp->set_bitsize (0);
if (name != nullptr)
{
break;
case CTF_K_CONST:
if (sym->type ()->code () == TYPE_CODE_VOID)
- sym->set_type (objfile_type (objfile)->builtin_int);
+ sym->set_type (builtin_type (objfile)->builtin_int);
break;
case CTF_K_TYPEDEF:
case CTF_K_INTEGER:
ctf_errmsg (ctf_errno (fp)));
}
+ type_allocator alloc (of);
kind = ctf_type_kind (fp, tid);
if (kind == CTF_K_INTEGER)
{
ischar = cet.cte_format & CTF_INT_CHAR;
isbool = cet.cte_format & CTF_INT_BOOL;
if (ischar)
- type = init_character_type (of, TARGET_CHAR_BIT, !issigned, name);
+ type = init_character_type (alloc, TARGET_CHAR_BIT, !issigned, name);
else if (isbool)
- type = init_boolean_type (of, gdbarch_int_bit (gdbarch),
+ type = init_boolean_type (alloc, gdbarch_int_bit (gdbarch),
!issigned, name);
else
{
bits = cet.cte_bits;
else
bits = gdbarch_int_bit (gdbarch);
- type = init_integer_type (of, bits, !issigned, name);
+ type = init_integer_type (alloc, bits, !issigned, name);
}
}
else if (kind == CTF_K_FLOAT)
else
{
complaint (_("read_base_type: unsupported base kind (%d)"), kind);
- type = init_type (of, TYPE_CODE_ERROR, cet.cte_bits, name);
+ type = alloc.new_type (TYPE_CODE_ERROR, cet.cte_bits, name);
}
if (name != nullptr && strcmp (name, "char") == 0)
struct type *type;
uint32_t kind;
- type = alloc_type (of);
+ type = type_allocator (of).new_type ();
const char *name = ctf_type_name_raw (fp, tid);
if (name != nullptr && strlen (name) != 0)
else
type->set_code (TYPE_CODE_STRUCT);
- TYPE_LENGTH (type) = ctf_type_size (fp, tid);
+ type->set_length (ctf_type_size (fp, tid));
set_type_align (type, ctf_type_align (fp, tid));
return set_tid_type (ccp->of, tid, type);
ctf_funcinfo_t cfi;
uint32_t argc;
- type = alloc_type (of);
+ type = type_allocator (of).new_type ();
type->set_code (TYPE_CODE_FUNC);
if (ctf_func_type_info (fp, tid, &cfi) < 0)
fname == nullptr ? "noname" : fname);
}
rettype = fetch_tid_type (ccp, cfi.ctc_return);
- TYPE_TARGET_TYPE (type) = rettype;
+ type->set_target_type (rettype);
set_type_align (type, ctf_type_align (fp, tid));
/* Set up function's arguments. */
if (ctf_func_type_args (fp, tid, argc, argv.data ()) == CTF_ERR)
return nullptr;
- type->set_fields
- ((struct field *) TYPE_ZALLOC (type, argc * sizeof (struct field)));
- struct type *void_type = objfile_type (of)->builtin_void;
+ type->alloc_fields (argc);
+ struct type *void_type = builtin_type (of)->builtin_void;
/* If failed to find the argument type, fill it with void_type. */
for (int iparam = 0; iparam < argc; iparam++)
{
ctf_dict_t *fp = ccp->fp;
struct type *type;
- type = alloc_type (of);
+ type = type_allocator (of).new_type ();
const char *name = ctf_type_name_raw (fp, tid);
if (name != nullptr && strlen (name) != 0)
type->set_name (name);
type->set_code (TYPE_CODE_ENUM);
- TYPE_LENGTH (type) = ctf_type_size (fp, tid);
+ type->set_length (ctf_type_size (fp, tid));
/* Set the underlying type based on its ctf_type_size bits. */
- TYPE_TARGET_TYPE (type) = objfile_int_type (of, TYPE_LENGTH (type), false);
+ type->set_target_type (objfile_int_type (of, type->length (), false));
set_type_align (type, ctf_type_align (fp, tid));
return set_tid_type (of, tid, type);
base_type = copy_type (base_type);
inner_array = base_type;
- while (TYPE_TARGET_TYPE (inner_array)->code () == TYPE_CODE_ARRAY)
+ while (inner_array->target_type ()->code () == TYPE_CODE_ARRAY)
{
- TYPE_TARGET_TYPE (inner_array)
- = copy_type (TYPE_TARGET_TYPE (inner_array));
- inner_array = TYPE_TARGET_TYPE (inner_array);
+ inner_array->set_target_type (copy_type (inner_array->target_type ()));
+ inner_array = inner_array->target_type ();
}
- el_type = TYPE_TARGET_TYPE (inner_array);
+ el_type = inner_array->target_type ();
cnst |= TYPE_CONST (el_type);
voltl |= TYPE_VOLATILE (el_type);
- TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, nullptr);
+ inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, nullptr));
return set_tid_type (ccp->of, tid, base_type);
}
idx_type = fetch_tid_type (ccp, ar.ctr_index);
if (idx_type == nullptr)
- idx_type = objfile_type (objfile)->builtin_int;
+ idx_type = builtin_type (objfile)->builtin_int;
- range_type = create_static_range_type (NULL, idx_type, 0, ar.ctr_nelems - 1);
- type = create_array_type (NULL, element_type, range_type);
+ type_allocator alloc (objfile);
+ range_type = create_static_range_type (alloc, idx_type, 0, ar.ctr_nelems - 1);
+ type = create_array_type (alloc, element_type, range_type);
if (ar.ctr_nelems <= 1) /* Check if undefined upper bound. */
{
range_type->bounds ()->high.set_undefined ();
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_target_is_stub (true);
}
else
- TYPE_LENGTH (type) = ctf_type_size (fp, tid);
+ type->set_length (ctf_type_size (fp, tid));
set_type_align (type, ctf_type_align (fp, tid));
if (base_type == nullptr)
{
complaint (_("read_const_type: NULL base type (%ld)"), btid);
- base_type = objfile_type (objfile)->builtin_error;
+ base_type = builtin_type (objfile)->builtin_error;
}
}
cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
if (base_type == nullptr)
{
complaint (_("read_volatile_type: NULL base type (%ld)"), btid);
- base_type = objfile_type (objfile)->builtin_error;
+ base_type = builtin_type (objfile)->builtin_error;
}
}
if (base_type == nullptr)
{
complaint (_("read_restrict_type: NULL base type (%ld)"), btid);
- base_type = objfile_type (objfile)->builtin_error;
+ base_type = builtin_type (objfile)->builtin_error;
}
}
cv_type = make_restrict_type (base_type);
struct type *this_type, *target_type;
char *aname = obstack_strdup (&objfile->objfile_obstack, name);
- this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, aname);
+ this_type = type_allocator (objfile).new_type (TYPE_CODE_TYPEDEF, 0, aname);
set_tid_type (objfile, tid, this_type);
target_type = fetch_tid_type (ccp, btid);
if (target_type != this_type)
- TYPE_TARGET_TYPE (this_type) = target_type;
+ this_type->set_target_type (target_type);
else
- TYPE_TARGET_TYPE (this_type) = nullptr;
+ this_type->set_target_type (nullptr);
- this_type->set_target_is_stub (TYPE_TARGET_TYPE (this_type) != nullptr);
+ this_type->set_target_is_stub (this_type->target_type () != nullptr);
return set_tid_type (objfile, tid, this_type);
}
if (target_type == nullptr)
{
complaint (_("read_pointer_type: NULL target type (%ld)"), btid);
- target_type = objfile_type (ccp->of)->builtin_error;
+ target_type = builtin_type (ccp->of)->builtin_error;
}
}
struct type *type;
uint32_t kind;
- type = alloc_type (of);
+ type = type_allocator (of).new_type ();
const char *name = ctf_type_name_raw (fp, tid);
if (name != nullptr && strlen (name) != 0)
else
type->set_code (TYPE_CODE_STRUCT);
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_is_stub (true);
return set_tid_type (of, tid, type);
if (type == nullptr)
{
complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id);
- type = objfile_type (ccp->of)->builtin_error;
+ type = builtin_type (ccp->of)->builtin_error;
}
sym = new (&ccp->of->objfile_obstack) symbol;
OBJSTAT (ccp->of, n_syms++);
add_stt_entries (ccp, 1);
}
-/* Get text segment base for OBJFILE, TSIZE contains the segment size. */
+/* Get text section base for OBJFILE, TSIZE contains the size. */
static CORE_ADDR
-get_objfile_text_range (struct objfile *of, int *tsize)
+get_objfile_text_range (struct objfile *of, size_t *tsize)
{
bfd *abfd = of->obfd.get ();
const asection *codes;
}
/* Finish reading symbol/type definitions in CTF format.
- END_ADDR is the end address of the file's text. SECTION is
- the .text section number. */
+ END_ADDR is the end address of the file's text. */
static struct compunit_symtab *
ctf_end_compunit_symtab (ctf_psymtab *pst,
- CORE_ADDR end_addr, int section)
+ CORE_ADDR end_addr)
{
struct ctf_context *ccp;
ccp = &pst->context;
struct compunit_symtab *result
- = ccp->builder->end_compunit_symtab (end_addr, section);
+ = ccp->builder->end_compunit_symtab (end_addr);
delete ccp->builder;
ccp->builder = nullptr;
return result;
ccp->pst->add_psymbol (ename, true,
VAR_DOMAIN, LOC_CONST, -1,
psymbol_placement::GLOBAL,
- 0, language_c, ccp->partial_symtabs, ccp->of);
+ unrelocated_addr (0),
+ language_c, ccp->partial_symtabs, ccp->of);
}
if (ctf_errno (ccp->fp) != ECTF_NEXT_END)
complaint (_("ctf_enum_next ctf_psymtab_add_enums failed - %s"),
pst->add_psymbol (tname, true,
tdomain, aclass, -1,
psymbol_placement::GLOBAL,
- 0, language_c, pst->context.partial_symtabs, of);
+ unrelocated_addr (0),
+ language_c, pst->context.partial_symtabs, of);
}
}
/* Start a symtab. */
CORE_ADDR offset; /* Start of text segment. */
- int tsize;
+ size_t tsize;
offset = get_objfile_text_range (objfile, &tsize);
ctf_start_compunit_symtab (this, objfile, offset);
expand_psymtab (objfile);
- set_text_low (offset);
- set_text_high (offset + tsize);
- compunit_symtab = ctf_end_compunit_symtab (this, offset + tsize,
- SECT_OFF_TEXT (objfile));
+ set_text_low (unrelocated_addr (0));
+ set_text_high (unrelocated_addr (tsize));
+ compunit_symtab = ctf_end_compunit_symtab (this, offset + tsize);
/* Finish up the debug error message. */
if (info_verbose)
{
ctf_psymtab *pst;
- pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd, 0);
+ pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd,
+ unrelocated_addr (0));
pst->context.arc = arc;
pst->context.fp = cfp;
ccp->pst->add_psymbol (name, false,
domain, aclass, section,
psymbol_placement::STATIC,
- 0, language_c, ccp->partial_symtabs, ccp->of);
+ unrelocated_addr (0),
+ language_c, ccp->partial_symtabs, ccp->of);
return 0;
}
ccp->pst->add_psymbol (name, true,
VAR_DOMAIN, LOC_STATIC, -1,
psymbol_placement::GLOBAL,
- 0, language_c, ccp->partial_symtabs, ccp->of);
+ unrelocated_addr (0),
+ language_c, ccp->partial_symtabs, ccp->of);
return 0;
}