#include "ctf-api.h"
static const struct objfile_key<htab, htab_deleter> ctf_tid_key;
-static const struct objfile_data *ctf_file_key;
+
+struct ctf_fp_info
+{
+ explicit ctf_fp_info (ctf_file_t *cfp) : fp (cfp) {}
+ ~ctf_fp_info ();
+ ctf_file_t *fp;
+};
+
+/* Cleanup function for the ctf_file_key data. */
+ctf_fp_info::~ctf_fp_info ()
+{
+ if (!fp)
+ return;
+
+ ctf_archive_t *arc = ctf_get_arc (fp);
+ ctf_file_close (fp);
+ ctf_close (arc);
+}
+
+static const objfile_key<ctf_fp_info> ctf_file_key;
/* A CTF context consists of a file pointer and an objfile pointer. */
-typedef struct ctf_context
+struct ctf_context
{
ctf_file_t *fp;
struct objfile *of;
struct buildsym_compunit *builder;
-} ctf_context_t;
+};
/* The routines that read and process fields/members of a C struct, union,
or enumeration, pass lists of data member fields in an instance of a
std::vector<struct ctf_nextfield> fields;
/* Context. */
- ctf_context_t *cur_context;
+ struct ctf_context *cur_context;
/* Parent type. */
struct type *ptype;
static int ctf_add_type_cb (ctf_id_t tid, void *arg);
-static struct type *read_array_type (ctf_context_t *ccp, ctf_id_t tid);
+static struct type *read_array_type (struct ctf_context *cp, ctf_id_t tid);
-static struct type *read_pointer_type (ctf_context_t *ccp, ctf_id_t tid,
+static struct type *read_pointer_type (struct ctf_context *cp, ctf_id_t tid,
ctf_id_t btid);
-static struct type *read_structure_type (ctf_context_t *ccp, ctf_id_t tid);
+static struct type *read_structure_type (struct ctf_context *cp, ctf_id_t tid);
-static struct type *read_enum_type (ctf_context_t *ccp, ctf_id_t tid);
+static struct type *read_enum_type (struct ctf_context *cp, ctf_id_t tid);
-static struct type *read_typedef_type (ctf_context_t *ccp, ctf_id_t tid,
+static struct type *read_typedef_type (struct ctf_context *cp, ctf_id_t tid,
ctf_id_t btid, const char *name);
-static struct type *read_type_record (ctf_context_t *ccp, ctf_id_t tid);
+static struct type *read_type_record (struct ctf_context *cp, ctf_id_t tid);
-static void process_structure_type (ctf_context_t *ccp, ctf_id_t tid);
+static void process_structure_type (struct ctf_context *cp, ctf_id_t tid);
-static void process_struct_members (ctf_context_t *ccp, ctf_id_t tid,
+static void process_struct_members (struct ctf_context *cp, ctf_id_t tid,
struct type *type);
-static struct symbol *new_symbol (ctf_context_t *ccp, struct type *type,
+static struct symbol *new_symbol (struct ctf_context *cp, struct type *type,
ctf_id_t tid);
struct ctf_tid_and_type
void *arg)
{
struct ctf_field_info *fip = (struct ctf_field_info *) arg;
- ctf_context_t *ccp = fip->cur_context;
+ struct ctf_context *ccp = fip->cur_context;
struct ctf_nextfield new_field;
struct field *fp;
struct type *t;
struct ctf_field_info *fip = (struct ctf_field_info *) arg;
struct ctf_nextfield new_field;
struct field *fp;
- ctf_context_t *ccp = fip->cur_context;
+ struct ctf_context *ccp = fip->cur_context;
fp = &new_field.field;
FIELD_NAME (*fp) = name;
domain from TID's kind, and its type from TYPE. */
static struct symbol *
-new_symbol (ctf_context_t *ccp, struct type *type, ctf_id_t tid)
+new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
{
struct objfile *objfile = ccp->of;
ctf_file_t *fp = ccp->fp;
and create the symbol for it. */
static struct type *
-read_base_type (ctf_context_t *ccp, ctf_id_t tid)
+read_base_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct objfile *of = ccp->of;
ctf_file_t *fp = ccp->fp;
}
static void
-process_base_type (ctf_context_t *ccp, ctf_id_t tid)
+process_base_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct type *type;
(assuming the type has a name). */
static struct type *
-read_structure_type (ctf_context_t *ccp, ctf_id_t tid)
+read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct objfile *of = ccp->of;
ctf_file_t *fp = ccp->fp;
and create the symbol for it. */
static void
-process_struct_members (ctf_context_t *ccp,
+process_struct_members (struct ctf_context *ccp,
ctf_id_t tid,
struct type *type)
{
}
static void
-process_structure_type (ctf_context_t *ccp, ctf_id_t tid)
+process_structure_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct type *type;
/* Create a function type for TID and set its return type. */
static struct type *
-read_func_kind_type (ctf_context_t *ccp, ctf_id_t tid)
+read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct objfile *of = ccp->of;
ctf_file_t *fp = ccp->fp;
enumeration, and create the symbol for the enumeration type. */
static struct type *
-read_enum_type (ctf_context_t *ccp, ctf_id_t tid)
+read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct objfile *of = ccp->of;
ctf_file_t *fp = ccp->fp;
}
static void
-process_enum_type (ctf_context_t *ccp, ctf_id_t tid)
+process_enum_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct type *type;
struct ctf_field_info fi;
/* Add given cv-qualifiers CNST+VOLTL to the BASE_TYPE of array TID. */
static struct type *
-add_array_cv_type (ctf_context_t *ccp,
+add_array_cv_type (struct ctf_context *ccp,
ctf_id_t tid,
struct type *base_type,
int cnst,
/* Read all information from a TID of CTF_K_ARRAY. */
static struct type *
-read_array_type (ctf_context_t *ccp, ctf_id_t tid)
+read_array_type (struct ctf_context *ccp, ctf_id_t tid)
{
struct objfile *objfile = ccp->of;
ctf_file_t *fp = ccp->fp;
/* Read TID of kind CTF_K_CONST with base type BTID. */
static struct type *
-read_const_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid)
+read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
{
struct objfile *objfile = ccp->of;
struct type *base_type, *cv_type;
/* Read TID of kind CTF_K_VOLATILE with base type BTID. */
static struct type *
-read_volatile_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid)
+read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
{
struct objfile *objfile = ccp->of;
ctf_file_t *fp = ccp->fp;
/* Read TID of kind CTF_K_RESTRICT with base type BTID. */
static struct type *
-read_restrict_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid)
+read_restrict_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
{
struct objfile *objfile = ccp->of;
struct type *base_type, *cv_type;
/* Read TID of kind CTF_K_TYPEDEF with its NAME and base type BTID. */
static struct type *
-read_typedef_type (ctf_context_t *ccp, ctf_id_t tid,
+read_typedef_type (struct ctf_context *ccp, ctf_id_t tid,
ctf_id_t btid, const char *name)
{
struct objfile *objfile = ccp->of;
/* Read TID of kind CTF_K_POINTER with base type BTID. */
static struct type *
-read_pointer_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid)
+read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
{
struct objfile *of = ccp->of;
struct type *target_type, *type;
/* Read information associated with type TID. */
static struct type *
-read_type_record (ctf_context_t *ccp, ctf_id_t tid)
+read_type_record (struct ctf_context *ccp, ctf_id_t tid)
{
ctf_file_t *fp = ccp->fp;
uint32_t kind;
static int
ctf_add_type_cb (ctf_id_t tid, void *arg)
{
- ctf_context_t *ccp = (ctf_context_t *) arg;
+ struct ctf_context *ccp = (struct ctf_context *) arg;
struct type *type;
uint32_t kind;
static int
ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
{
- ctf_context_t *ccp = (ctf_context_t *) arg;
+ struct ctf_context *ccp = (struct ctf_context *) arg;
struct symbol *sym = NULL;
struct type *type;
uint32_t kind;
/* Add an ELF STT_OBJ symbol with index IDX to the symbol table. */
static struct symbol *
-add_stt_obj (ctf_context_t *ccp, unsigned long idx)
+add_stt_obj (struct ctf_context *ccp, unsigned long idx)
{
struct symbol *sym;
struct type *type;
/* Add an ELF STT_FUNC symbol with index IDX to the symbol table. */
static struct symbol *
-add_stt_func (ctf_context_t *ccp, unsigned long idx)
+add_stt_func (struct ctf_context *ccp, unsigned long idx)
{
struct type *ftype, *atyp, *rettyp;
struct symbol *sym;
static CORE_ADDR
get_objfile_text_range (struct objfile *of, int *tsize)
{
- CORE_ADDR text_base;
bfd *abfd = of->obfd;
const asection *codes;
codes = bfd_get_section_by_name (abfd, ".text");
- if (codes == NULL)
- {
- text_base = 0;
- *tsize = 0;
- }
- else
- {
- text_base = bfd_section_vma (codes);
- *tsize = codes->size;
- }
-
- return text_base;
+ *tsize = codes ? bfd_section_size (codes) : 0;
+ return ANOFFSET (of->section_offsets, SECT_OFF_TEXT (of));
}
/* Start a symtab for OBJFILE in CTF format. */
ctf_start_symtab (struct partial_symtab *pst,
struct objfile *of, CORE_ADDR text_offset)
{
- ctf_context_t *ccp;
+ struct ctf_context *ccp;
- ccp = (ctf_context_t *) pst->read_symtab_private;
+ ccp = (struct ctf_context *) pst->read_symtab_private;
ccp->builder = new buildsym_compunit
(of, of->original_name, NULL,
language_c, text_offset);
ctf_end_symtab (struct partial_symtab *pst,
CORE_ADDR end_addr, int section)
{
- ctf_context_t *ccp;
+ struct ctf_context *ccp;
- ccp = (ctf_context_t *) pst->read_symtab_private;
+ ccp = (struct ctf_context *) pst->read_symtab_private;
struct compunit_symtab *result
= ccp->builder->end_symtab (end_addr, section);
delete ccp->builder;
psymtab_to_symtab (struct partial_symtab *pst)
{
struct symbol *sym;
- ctf_context_t *ccp;
+ struct ctf_context *ccp;
gdb_assert (!pst->readin);
- ccp = (ctf_context_t *) pst->read_symtab_private;
+ ccp = (struct ctf_context *) pst->read_symtab_private;
/* Iterate over entries in data types section. */
if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR)
}
}
-/* Cleanup function for the ctf_file_key data. */
-
-static void
-ctf_close_objfile (struct objfile *of, void *datum)
-{
- ctf_file_t *fp = static_cast<ctf_file_t *> (datum);
- ctf_archive_t *arc = ctf_get_arc (fp);
- ctf_file_close (fp);
- ctf_close (arc);
-}
-
/* Allocate a new partial_symtab NAME.
Each source file that has not been fully read in is represented by
struct objfile *objfile)
{
struct partial_symtab *pst;
- ctf_context_t *ccx;
+ struct ctf_context *ccx;
pst = start_psymtab_common (objfile, name, 0);
- ccx = XOBNEW (&objfile->objfile_obstack, ctf_context_t);
+ ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context);
ccx->fp = cfp;
ccx->of = objfile;
pst->read_symtab_private = (void *) ccx;
static int
ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
{
- ctf_context_t *ccp;
+ struct ctf_context *ccp;
uint32_t kind;
short section = -1;
- ccp = (ctf_context_t *) arg;
+ ccp = (struct ctf_context *) arg;
gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (ccp->fp, tid));
if (name == NULL || strlen (name.get ()) == 0)
return 0;
static int
ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
{
- ctf_context_t *ccp = (ctf_context_t *) arg;
+ struct ctf_context *ccp = (struct ctf_context *) arg;
add_psymbol_to_list (name, true,
VAR_DOMAIN, LOC_STATIC, -1,
static void
scan_partial_symbols (ctf_file_t *cfp, struct objfile *of)
{
- ctf_context_t ccx;
+ struct ctf_context ccx;
bfd *abfd = of->obfd;
const char *name = bfd_get_filename (abfd);
struct partial_symtab *pst = create_partial_symtab (name, cfp, of);
if (fp == NULL)
error (_("ctf_arc_open_by_name failed on %s - %s"),
bfd_get_filename (abfd), ctf_errmsg (err));
- set_objfile_data (of, ctf_file_key, fp);
+ ctf_file_key.emplace (of, fp);
scan_partial_symbols (fp, of);
}
void
_initialize_ctfread (void)
{
- ctf_file_key
- = register_objfile_data_with_cleanup (NULL, ctf_close_objfile);
}