1 1.1 christos /* Compact ANSI-C Type Format (CTF) support in GDB. 2 1.1 christos 3 1.1.1.3 christos Copyright (C) 2019-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1 christos /* This file format can be used to compactly represent the information needed 21 1.1 christos by a debugger to interpret the ANSI-C types used by a given program. 22 1.1 christos Traditionally, this kind of information is generated by the compiler when 23 1.1 christos invoked with the -g flag and is stored in "stabs" strings or in the more 24 1.1 christos modern DWARF format. A new -gtLEVEL option has been added in gcc to generate 25 1.1 christos such information. CTF provides a representation of only the information 26 1.1 christos that is relevant to debugging a complex, optimized C program such as the 27 1.1 christos operating system kernel in a form that is significantly more compact than 28 1.1 christos the equivalent stabs or DWARF representation. The format is data-model 29 1.1 christos independent, so consumers do not need different code depending on whether 30 1.1 christos they are 32-bit or 64-bit programs. CTF assumes that a standard ELF symbol 31 1.1 christos table is available for use in the debugger, and uses the structure and data 32 1.1 christos of the symbol table to avoid storing redundant information. The CTF data 33 1.1 christos may be compressed on disk or in memory, indicated by a bit in the header. 34 1.1 christos CTF may be interpreted in a raw disk file, or it may be stored in an ELF 35 1.1 christos section, typically named .ctf. Data structures are aligned so that a raw 36 1.1 christos CTF file or CTF ELF section may be manipulated using mmap(2). 37 1.1 christos 38 1.1 christos The CTF file or section itself has the following structure: 39 1.1 christos 40 1.1 christos +--------+--------+---------+----------+----------+-------+--------+ 41 1.1 christos | file | type | data | function | variable | data | string | 42 1.1 christos | header | labels | objects | info | info | types | table | 43 1.1 christos +--------+--------+---------+----------+----------+-------+--------+ 44 1.1 christos 45 1.1 christos The file header stores a magic number and version information, encoding 46 1.1 christos flags, and the byte offset of each of the sections relative to the end of the 47 1.1 christos header itself. If the CTF data has been uniquified against another set of 48 1.1 christos CTF data, a reference to that data also appears in the header. This 49 1.1 christos reference is the name of the label corresponding to the types uniquified 50 1.1 christos against. 51 1.1 christos 52 1.1 christos Following the header is a list of labels, used to group the types included in 53 1.1 christos the data types section. Each label is accompanied by a type ID i. A given 54 1.1 christos label refers to the group of types whose IDs are in the range [0, i]. 55 1.1 christos 56 1.1 christos Data object and function records are stored in the same order as they appear 57 1.1 christos in the corresponding symbol table, except that symbols marked SHN_UNDEF are 58 1.1 christos not stored and symbols that have no type data are padded out with zeroes. 59 1.1 christos For each data object, the type ID (a small integer) is recorded. For each 60 1.1 christos function, the type ID of the return type and argument types is recorded. 61 1.1 christos 62 1.1 christos Variable records (as distinct from data objects) provide a modicum of support 63 1.1 christos for non-ELF systems, mapping a variable name to a CTF type ID. The variable 64 1.1 christos names are sorted into ASCIIbetical order, permitting binary searching. 65 1.1 christos 66 1.1 christos The data types section is a list of variable size records that represent each 67 1.1 christos type, in order by their ID. The types themselves form a directed graph, 68 1.1 christos where each node may contain one or more outgoing edges to other type nodes, 69 1.1 christos denoted by their ID. 70 1.1 christos 71 1.1 christos Strings are recorded as a string table ID (0 or 1) and a byte offset into the 72 1.1 christos string table. String table 0 is the internal CTF string table. String table 73 1.1 christos 1 is the external string table, which is the string table associated with the 74 1.1 christos ELF symbol table for this object. CTF does not record any strings that are 75 1.1 christos already in the symbol table, and the CTF string table does not contain any 76 1.1 christos duplicated strings. */ 77 1.1 christos 78 1.1 christos #include "buildsym.h" 79 1.1 christos #include "complaints.h" 80 1.1 christos #include "block.h" 81 1.1 christos #include "ctfread.h" 82 1.1.1.3 christos #include "psymtab.h" 83 1.1 christos 84 1.1 christos #if ENABLE_LIBCTF 85 1.1 christos 86 1.1 christos #include "ctf.h" 87 1.1 christos #include "ctf-api.h" 88 1.1 christos 89 1.1.1.2 christos static const registry<objfile>::key<htab, htab_deleter> ctf_tid_key; 90 1.1 christos 91 1.1 christos struct ctf_fp_info 92 1.1 christos { 93 1.1.1.2 christos explicit ctf_fp_info (ctf_dict_t *cfp) : fp (cfp) {} 94 1.1 christos ~ctf_fp_info (); 95 1.1.1.2 christos ctf_dict_t *fp; 96 1.1 christos }; 97 1.1 christos 98 1.1.1.2 christos /* Cleanup function for the ctf_dict_key data. */ 99 1.1 christos ctf_fp_info::~ctf_fp_info () 100 1.1 christos { 101 1.1.1.2 christos if (fp == nullptr) 102 1.1 christos return; 103 1.1 christos 104 1.1 christos ctf_archive_t *arc = ctf_get_arc (fp); 105 1.1.1.2 christos ctf_dict_close (fp); 106 1.1 christos ctf_close (arc); 107 1.1 christos } 108 1.1 christos 109 1.1.1.2 christos static const registry<objfile>::key<ctf_fp_info> ctf_dict_key; 110 1.1 christos 111 1.1 christos /* A CTF context consists of a file pointer and an objfile pointer. */ 112 1.1 christos 113 1.1 christos struct ctf_context 114 1.1 christos { 115 1.1.1.2 christos ctf_dict_t *fp; 116 1.1 christos struct objfile *of; 117 1.1.1.2 christos psymtab_storage *partial_symtabs; 118 1.1.1.2 christos partial_symtab *pst; 119 1.1.1.2 christos ctf_archive_t *arc; 120 1.1 christos struct buildsym_compunit *builder; 121 1.1 christos }; 122 1.1 christos 123 1.1 christos /* A partial symtab, specialized for this module. */ 124 1.1 christos struct ctf_psymtab : public standard_psymtab 125 1.1 christos { 126 1.1.1.2 christos ctf_psymtab (const char *filename, 127 1.1.1.2 christos psymtab_storage *partial_symtabs, 128 1.1.1.2 christos objfile_per_bfd_storage *objfile_per_bfd, 129 1.1.1.3 christos unrelocated_addr addr) 130 1.1.1.2 christos : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr) 131 1.1 christos { 132 1.1 christos } 133 1.1 christos 134 1.1 christos void read_symtab (struct objfile *) override; 135 1.1 christos void expand_psymtab (struct objfile *) override; 136 1.1 christos 137 1.1.1.2 christos struct ctf_context context; 138 1.1 christos }; 139 1.1 christos 140 1.1 christos /* The routines that read and process fields/members of a C struct, union, 141 1.1 christos or enumeration, pass lists of data member fields in an instance of a 142 1.1 christos ctf_field_info structure. It is derived from dwarf2read.c. */ 143 1.1 christos 144 1.1 christos struct ctf_nextfield 145 1.1 christos { 146 1.1 christos struct field field {}; 147 1.1 christos }; 148 1.1 christos 149 1.1 christos struct ctf_field_info 150 1.1 christos { 151 1.1 christos /* List of data member fields. */ 152 1.1 christos std::vector<struct ctf_nextfield> fields; 153 1.1 christos 154 1.1 christos /* Context. */ 155 1.1 christos struct ctf_context *cur_context; 156 1.1 christos 157 1.1 christos /* Parent type. */ 158 1.1 christos struct type *ptype; 159 1.1 christos 160 1.1 christos /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head 161 1.1 christos of a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ 162 1.1 christos std::vector<struct decl_field> typedef_field_list; 163 1.1 christos 164 1.1 christos /* Nested types defined by this struct and the number of elements in 165 1.1 christos this list. */ 166 1.1 christos std::vector<struct decl_field> nested_types_list; 167 1.1 christos }; 168 1.1 christos 169 1.1.1.2 christos /* Data held for a translation unit. */ 170 1.1.1.2 christos 171 1.1.1.2 christos struct ctf_per_tu_data 172 1.1.1.2 christos { 173 1.1.1.2 christos ctf_dict_t *fp; 174 1.1.1.2 christos struct objfile *of; 175 1.1.1.2 christos ctf_archive_t *arc; 176 1.1.1.2 christos psymtab_storage *pss; 177 1.1.1.2 christos psymbol_functions *psf; 178 1.1.1.2 christos }; 179 1.1 christos 180 1.1 christos /* Local function prototypes */ 181 1.1 christos 182 1.1 christos static int ctf_add_type_cb (ctf_id_t tid, void *arg); 183 1.1 christos 184 1.1 christos static struct type *read_array_type (struct ctf_context *cp, ctf_id_t tid); 185 1.1 christos 186 1.1 christos static struct type *read_pointer_type (struct ctf_context *cp, ctf_id_t tid, 187 1.1 christos ctf_id_t btid); 188 1.1 christos 189 1.1 christos static struct type *read_structure_type (struct ctf_context *cp, ctf_id_t tid); 190 1.1 christos 191 1.1 christos static struct type *read_enum_type (struct ctf_context *cp, ctf_id_t tid); 192 1.1 christos 193 1.1 christos static struct type *read_typedef_type (struct ctf_context *cp, ctf_id_t tid, 194 1.1 christos ctf_id_t btid, const char *name); 195 1.1 christos 196 1.1 christos static struct type *read_type_record (struct ctf_context *cp, ctf_id_t tid); 197 1.1 christos 198 1.1 christos static void process_structure_type (struct ctf_context *cp, ctf_id_t tid); 199 1.1 christos 200 1.1 christos static void process_struct_members (struct ctf_context *cp, ctf_id_t tid, 201 1.1 christos struct type *type); 202 1.1 christos 203 1.1.1.2 christos static struct type *read_forward_type (struct ctf_context *cp, ctf_id_t tid); 204 1.1.1.2 christos 205 1.1 christos static struct symbol *new_symbol (struct ctf_context *cp, struct type *type, 206 1.1 christos ctf_id_t tid); 207 1.1 christos 208 1.1 christos struct ctf_tid_and_type 209 1.1 christos { 210 1.1 christos ctf_id_t tid; 211 1.1 christos struct type *type; 212 1.1 christos }; 213 1.1 christos 214 1.1 christos /* Hash function for a ctf_tid_and_type. */ 215 1.1 christos 216 1.1 christos static hashval_t 217 1.1 christos tid_and_type_hash (const void *item) 218 1.1 christos { 219 1.1 christos const struct ctf_tid_and_type *ids 220 1.1 christos = (const struct ctf_tid_and_type *) item; 221 1.1 christos 222 1.1 christos return ids->tid; 223 1.1 christos } 224 1.1 christos 225 1.1 christos /* Equality function for a ctf_tid_and_type. */ 226 1.1 christos 227 1.1 christos static int 228 1.1 christos tid_and_type_eq (const void *item_lhs, const void *item_rhs) 229 1.1 christos { 230 1.1 christos const struct ctf_tid_and_type *ids_lhs 231 1.1 christos = (const struct ctf_tid_and_type *) item_lhs; 232 1.1 christos const struct ctf_tid_and_type *ids_rhs 233 1.1 christos = (const struct ctf_tid_and_type *) item_rhs; 234 1.1 christos 235 1.1 christos return ids_lhs->tid == ids_rhs->tid; 236 1.1 christos } 237 1.1 christos 238 1.1 christos /* Set the type associated with TID to TYP. */ 239 1.1 christos 240 1.1 christos static struct type * 241 1.1 christos set_tid_type (struct objfile *of, ctf_id_t tid, struct type *typ) 242 1.1 christos { 243 1.1 christos htab_t htab; 244 1.1 christos 245 1.1.1.2 christos htab = ctf_tid_key.get (of); 246 1.1 christos if (htab == NULL) 247 1.1 christos { 248 1.1 christos htab = htab_create_alloc (1, tid_and_type_hash, 249 1.1 christos tid_and_type_eq, 250 1.1 christos NULL, xcalloc, xfree); 251 1.1 christos ctf_tid_key.set (of, htab); 252 1.1 christos } 253 1.1 christos 254 1.1 christos struct ctf_tid_and_type **slot, ids; 255 1.1 christos ids.tid = tid; 256 1.1 christos ids.type = typ; 257 1.1 christos slot = (struct ctf_tid_and_type **) htab_find_slot (htab, &ids, INSERT); 258 1.1.1.2 christos if (*slot == nullptr) 259 1.1.1.2 christos *slot = XOBNEW (&of->objfile_obstack, struct ctf_tid_and_type); 260 1.1 christos **slot = ids; 261 1.1 christos return typ; 262 1.1 christos } 263 1.1 christos 264 1.1 christos /* Look up the type for TID in tid_and_type hash, return NULL if hash is 265 1.1 christos empty or TID does not have a saved type. */ 266 1.1 christos 267 1.1 christos static struct type * 268 1.1 christos get_tid_type (struct objfile *of, ctf_id_t tid) 269 1.1 christos { 270 1.1 christos struct ctf_tid_and_type *slot, ids; 271 1.1 christos htab_t htab; 272 1.1 christos 273 1.1.1.2 christos htab = ctf_tid_key.get (of); 274 1.1 christos if (htab == NULL) 275 1.1.1.2 christos return nullptr; 276 1.1 christos 277 1.1 christos ids.tid = tid; 278 1.1.1.2 christos ids.type = nullptr; 279 1.1 christos slot = (struct ctf_tid_and_type *) htab_find (htab, &ids); 280 1.1 christos if (slot) 281 1.1 christos return slot->type; 282 1.1 christos else 283 1.1.1.2 christos return nullptr; 284 1.1.1.2 christos } 285 1.1.1.2 christos 286 1.1.1.2 christos /* Fetch the type for TID in CCP OF's tid_and_type hash, add the type to 287 1.1.1.2 christos * context CCP if hash is empty or TID does not have a saved type. */ 288 1.1.1.2 christos 289 1.1.1.2 christos static struct type * 290 1.1.1.2 christos fetch_tid_type (struct ctf_context *ccp, ctf_id_t tid) 291 1.1.1.2 christos { 292 1.1.1.2 christos struct objfile *of = ccp->of; 293 1.1.1.2 christos struct type *typ; 294 1.1.1.2 christos 295 1.1.1.2 christos typ = get_tid_type (of, tid); 296 1.1.1.2 christos if (typ == nullptr) 297 1.1.1.2 christos { 298 1.1.1.2 christos ctf_add_type_cb (tid, ccp); 299 1.1.1.2 christos typ = get_tid_type (of, tid); 300 1.1.1.2 christos } 301 1.1.1.2 christos 302 1.1.1.2 christos return typ; 303 1.1 christos } 304 1.1 christos 305 1.1 christos /* Return the size of storage in bits for INTEGER, FLOAT, or ENUM. */ 306 1.1 christos 307 1.1 christos static int 308 1.1.1.2 christos get_bitsize (ctf_dict_t *fp, ctf_id_t tid, uint32_t kind) 309 1.1 christos { 310 1.1 christos ctf_encoding_t cet; 311 1.1 christos 312 1.1 christos if ((kind == CTF_K_INTEGER || kind == CTF_K_ENUM 313 1.1 christos || kind == CTF_K_FLOAT) 314 1.1 christos && ctf_type_reference (fp, tid) != CTF_ERR 315 1.1 christos && ctf_type_encoding (fp, tid, &cet) != CTF_ERR) 316 1.1 christos return cet.cte_bits; 317 1.1 christos 318 1.1 christos return 0; 319 1.1 christos } 320 1.1 christos 321 1.1 christos /* Set SYM's address, with NAME, from its minimal symbol entry. */ 322 1.1 christos 323 1.1 christos static void 324 1.1 christos set_symbol_address (struct objfile *of, struct symbol *sym, const char *name) 325 1.1 christos { 326 1.1.1.4 christos bound_minimal_symbol msym 327 1.1.1.4 christos = lookup_minimal_symbol (current_program_space, name, of); 328 1.1 christos if (msym.minsym != NULL) 329 1.1 christos { 330 1.1.1.2 christos sym->set_value_address (msym.value_address ()); 331 1.1.1.2 christos sym->set_aclass_index (LOC_STATIC); 332 1.1.1.2 christos sym->set_section_index (msym.minsym->section_index ()); 333 1.1 christos } 334 1.1 christos } 335 1.1 christos 336 1.1 christos /* Create the vector of fields, and attach it to TYPE. */ 337 1.1 christos 338 1.1 christos static void 339 1.1 christos attach_fields_to_type (struct ctf_field_info *fip, struct type *type) 340 1.1 christos { 341 1.1 christos int nfields = fip->fields.size (); 342 1.1 christos 343 1.1 christos if (nfields == 0) 344 1.1 christos return; 345 1.1 christos 346 1.1 christos /* Record the field count, allocate space for the array of fields. */ 347 1.1.1.3 christos type->alloc_fields (nfields); 348 1.1 christos 349 1.1 christos /* Copy the saved-up fields into the field vector. */ 350 1.1 christos for (int i = 0; i < nfields; ++i) 351 1.1 christos { 352 1.1 christos struct ctf_nextfield &field = fip->fields[i]; 353 1.1 christos type->field (i) = field.field; 354 1.1 christos } 355 1.1 christos } 356 1.1 christos 357 1.1 christos /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT 358 1.1 christos (which may be different from NAME) to the architecture back-end to allow 359 1.1 christos it to guess the correct format if necessary. */ 360 1.1 christos 361 1.1 christos static struct type * 362 1.1 christos ctf_init_float_type (struct objfile *objfile, 363 1.1 christos int bits, 364 1.1 christos const char *name, 365 1.1 christos const char *name_hint) 366 1.1 christos { 367 1.1 christos struct gdbarch *gdbarch = objfile->arch (); 368 1.1 christos const struct floatformat **format; 369 1.1 christos struct type *type; 370 1.1 christos 371 1.1.1.3 christos type_allocator alloc (objfile, language_c); 372 1.1 christos format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits); 373 1.1.1.2 christos if (format != nullptr) 374 1.1.1.3 christos type = init_float_type (alloc, bits, name, format); 375 1.1 christos else 376 1.1.1.3 christos type = alloc.new_type (TYPE_CODE_ERROR, bits, name); 377 1.1 christos 378 1.1 christos return type; 379 1.1 christos } 380 1.1 christos 381 1.1 christos /* Callback to add member NAME to a struct/union type. TID is the type 382 1.1 christos of struct/union member, OFFSET is the offset of member in bits, 383 1.1 christos and ARG contains the ctf_field_info. */ 384 1.1 christos 385 1.1 christos static int 386 1.1 christos ctf_add_member_cb (const char *name, 387 1.1 christos ctf_id_t tid, 388 1.1 christos unsigned long offset, 389 1.1 christos void *arg) 390 1.1 christos { 391 1.1 christos struct ctf_field_info *fip = (struct ctf_field_info *) arg; 392 1.1 christos struct ctf_context *ccp = fip->cur_context; 393 1.1 christos struct ctf_nextfield new_field; 394 1.1 christos struct field *fp; 395 1.1 christos struct type *t; 396 1.1 christos uint32_t kind; 397 1.1 christos 398 1.1 christos fp = &new_field.field; 399 1.1.1.2 christos fp->set_name (name); 400 1.1 christos 401 1.1 christos kind = ctf_type_kind (ccp->fp, tid); 402 1.1.1.2 christos t = fetch_tid_type (ccp, tid); 403 1.1.1.2 christos if (t == nullptr) 404 1.1 christos { 405 1.1 christos t = read_type_record (ccp, tid); 406 1.1.1.2 christos if (t == nullptr) 407 1.1 christos { 408 1.1 christos complaint (_("ctf_add_member_cb: %s has NO type (%ld)"), name, tid); 409 1.1.1.3 christos t = builtin_type (ccp->of)->builtin_error; 410 1.1 christos set_tid_type (ccp->of, tid, t); 411 1.1 christos } 412 1.1 christos } 413 1.1 christos 414 1.1 christos if (kind == CTF_K_STRUCT || kind == CTF_K_UNION) 415 1.1 christos process_struct_members (ccp, tid, t); 416 1.1 christos 417 1.1 christos fp->set_type (t); 418 1.1.1.2 christos fp->set_loc_bitpos (offset / TARGET_CHAR_BIT); 419 1.1.1.3 christos fp->set_bitsize (get_bitsize (ccp->fp, tid, kind)); 420 1.1 christos 421 1.1 christos fip->fields.emplace_back (new_field); 422 1.1 christos 423 1.1 christos return 0; 424 1.1 christos } 425 1.1 christos 426 1.1 christos /* Callback to add member NAME of EVAL to an enumeration type. 427 1.1 christos ARG contains the ctf_field_info. */ 428 1.1 christos 429 1.1 christos static int 430 1.1 christos ctf_add_enum_member_cb (const char *name, int enum_value, void *arg) 431 1.1 christos { 432 1.1 christos struct ctf_field_info *fip = (struct ctf_field_info *) arg; 433 1.1 christos struct ctf_nextfield new_field; 434 1.1 christos struct field *fp; 435 1.1 christos struct ctf_context *ccp = fip->cur_context; 436 1.1 christos 437 1.1 christos fp = &new_field.field; 438 1.1.1.2 christos fp->set_name (name); 439 1.1.1.2 christos fp->set_type (nullptr); 440 1.1.1.2 christos fp->set_loc_enumval (enum_value); 441 1.1.1.3 christos fp->set_bitsize (0); 442 1.1 christos 443 1.1.1.2 christos if (name != nullptr) 444 1.1 christos { 445 1.1 christos struct symbol *sym = new (&ccp->of->objfile_obstack) symbol; 446 1.1 christos OBJSTAT (ccp->of, n_syms++); 447 1.1 christos 448 1.1 christos sym->set_language (language_c, &ccp->of->objfile_obstack); 449 1.1 christos sym->compute_and_set_names (name, false, ccp->of->per_bfd); 450 1.1.1.2 christos sym->set_aclass_index (LOC_CONST); 451 1.1.1.2 christos sym->set_domain (VAR_DOMAIN); 452 1.1.1.2 christos sym->set_type (fip->ptype); 453 1.1 christos add_symbol_to_list (sym, ccp->builder->get_global_symbols ()); 454 1.1 christos } 455 1.1 christos 456 1.1 christos fip->fields.emplace_back (new_field); 457 1.1 christos 458 1.1 christos return 0; 459 1.1 christos } 460 1.1 christos 461 1.1 christos /* Add a new symbol entry, with its name from TID, its access index and 462 1.1 christos domain from TID's kind, and its type from TYPE. */ 463 1.1 christos 464 1.1 christos static struct symbol * 465 1.1 christos new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid) 466 1.1 christos { 467 1.1 christos struct objfile *objfile = ccp->of; 468 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 469 1.1.1.2 christos struct symbol *sym = nullptr; 470 1.1 christos 471 1.1.1.2 christos const char *name = ctf_type_name_raw (fp, tid); 472 1.1.1.2 christos if (name != nullptr) 473 1.1 christos { 474 1.1 christos sym = new (&objfile->objfile_obstack) symbol; 475 1.1 christos OBJSTAT (objfile, n_syms++); 476 1.1 christos 477 1.1 christos sym->set_language (language_c, &objfile->objfile_obstack); 478 1.1.1.2 christos sym->compute_and_set_names (name, false, objfile->per_bfd); 479 1.1.1.2 christos sym->set_domain (VAR_DOMAIN); 480 1.1.1.2 christos sym->set_aclass_index (LOC_OPTIMIZED_OUT); 481 1.1 christos 482 1.1.1.2 christos if (type != nullptr) 483 1.1.1.2 christos sym->set_type (type); 484 1.1 christos 485 1.1 christos uint32_t kind = ctf_type_kind (fp, tid); 486 1.1 christos switch (kind) 487 1.1 christos { 488 1.1 christos case CTF_K_STRUCT: 489 1.1 christos case CTF_K_UNION: 490 1.1 christos case CTF_K_ENUM: 491 1.1.1.2 christos sym->set_aclass_index (LOC_TYPEDEF); 492 1.1.1.2 christos sym->set_domain (STRUCT_DOMAIN); 493 1.1 christos break; 494 1.1 christos case CTF_K_FUNCTION: 495 1.1.1.2 christos sym->set_aclass_index (LOC_STATIC); 496 1.1.1.2 christos set_symbol_address (objfile, sym, sym->linkage_name ()); 497 1.1 christos break; 498 1.1 christos case CTF_K_CONST: 499 1.1.1.2 christos if (sym->type ()->code () == TYPE_CODE_VOID) 500 1.1.1.3 christos sym->set_type (builtin_type (objfile)->builtin_int); 501 1.1 christos break; 502 1.1 christos case CTF_K_TYPEDEF: 503 1.1 christos case CTF_K_INTEGER: 504 1.1 christos case CTF_K_FLOAT: 505 1.1.1.2 christos sym->set_aclass_index (LOC_TYPEDEF); 506 1.1.1.3 christos sym->set_domain (TYPE_DOMAIN); 507 1.1 christos break; 508 1.1 christos case CTF_K_POINTER: 509 1.1 christos break; 510 1.1 christos case CTF_K_VOLATILE: 511 1.1 christos case CTF_K_RESTRICT: 512 1.1 christos break; 513 1.1 christos case CTF_K_SLICE: 514 1.1 christos case CTF_K_ARRAY: 515 1.1 christos case CTF_K_UNKNOWN: 516 1.1 christos break; 517 1.1 christos } 518 1.1 christos 519 1.1.1.2 christos add_symbol_to_list (sym, ccp->builder->get_file_symbols ()); 520 1.1 christos } 521 1.1 christos 522 1.1 christos return sym; 523 1.1 christos } 524 1.1 christos 525 1.1 christos /* Given a TID of kind CTF_K_INTEGER or CTF_K_FLOAT, find a representation 526 1.1 christos and create the symbol for it. */ 527 1.1 christos 528 1.1 christos static struct type * 529 1.1 christos read_base_type (struct ctf_context *ccp, ctf_id_t tid) 530 1.1 christos { 531 1.1 christos struct objfile *of = ccp->of; 532 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 533 1.1 christos ctf_encoding_t cet; 534 1.1.1.2 christos struct type *type = nullptr; 535 1.1.1.2 christos const char *name; 536 1.1 christos uint32_t kind; 537 1.1 christos 538 1.1 christos if (ctf_type_encoding (fp, tid, &cet)) 539 1.1 christos { 540 1.1 christos complaint (_("ctf_type_encoding read_base_type failed - %s"), 541 1.1 christos ctf_errmsg (ctf_errno (fp))); 542 1.1.1.2 christos return nullptr; 543 1.1 christos } 544 1.1 christos 545 1.1.1.2 christos name = ctf_type_name_raw (fp, tid); 546 1.1.1.2 christos if (name == nullptr || strlen (name) == 0) 547 1.1 christos { 548 1.1 christos name = ctf_type_aname (fp, tid); 549 1.1.1.2 christos if (name == nullptr) 550 1.1 christos complaint (_("ctf_type_aname read_base_type failed - %s"), 551 1.1 christos ctf_errmsg (ctf_errno (fp))); 552 1.1 christos } 553 1.1 christos 554 1.1.1.3 christos type_allocator alloc (of, language_c); 555 1.1 christos kind = ctf_type_kind (fp, tid); 556 1.1 christos if (kind == CTF_K_INTEGER) 557 1.1 christos { 558 1.1 christos uint32_t issigned, ischar, isbool; 559 1.1 christos struct gdbarch *gdbarch = of->arch (); 560 1.1 christos 561 1.1 christos issigned = cet.cte_format & CTF_INT_SIGNED; 562 1.1 christos ischar = cet.cte_format & CTF_INT_CHAR; 563 1.1 christos isbool = cet.cte_format & CTF_INT_BOOL; 564 1.1 christos if (ischar) 565 1.1.1.3 christos type = init_character_type (alloc, TARGET_CHAR_BIT, !issigned, name); 566 1.1 christos else if (isbool) 567 1.1.1.3 christos type = init_boolean_type (alloc, gdbarch_int_bit (gdbarch), 568 1.1 christos !issigned, name); 569 1.1 christos else 570 1.1 christos { 571 1.1 christos int bits; 572 1.1 christos if (cet.cte_bits && ((cet.cte_bits % TARGET_CHAR_BIT) == 0)) 573 1.1 christos bits = cet.cte_bits; 574 1.1 christos else 575 1.1 christos bits = gdbarch_int_bit (gdbarch); 576 1.1.1.3 christos type = init_integer_type (alloc, bits, !issigned, name); 577 1.1 christos } 578 1.1 christos } 579 1.1 christos else if (kind == CTF_K_FLOAT) 580 1.1 christos { 581 1.1 christos uint32_t isflt; 582 1.1 christos isflt = !((cet.cte_format & CTF_FP_IMAGRY) == CTF_FP_IMAGRY 583 1.1 christos || (cet.cte_format & CTF_FP_DIMAGRY) == CTF_FP_DIMAGRY 584 1.1 christos || (cet.cte_format & CTF_FP_LDIMAGRY) == CTF_FP_LDIMAGRY); 585 1.1 christos if (isflt) 586 1.1 christos type = ctf_init_float_type (of, cet.cte_bits, name, name); 587 1.1 christos else 588 1.1 christos { 589 1.1 christos struct type *t 590 1.1 christos = ctf_init_float_type (of, cet.cte_bits / 2, NULL, name); 591 1.1 christos type = init_complex_type (name, t); 592 1.1 christos } 593 1.1 christos } 594 1.1 christos else 595 1.1 christos { 596 1.1 christos complaint (_("read_base_type: unsupported base kind (%d)"), kind); 597 1.1.1.3 christos type = alloc.new_type (TYPE_CODE_ERROR, cet.cte_bits, name); 598 1.1 christos } 599 1.1 christos 600 1.1.1.2 christos if (name != nullptr && strcmp (name, "char") == 0) 601 1.1.1.2 christos type->set_has_no_signedness (true); 602 1.1 christos 603 1.1 christos return set_tid_type (of, tid, type); 604 1.1 christos } 605 1.1 christos 606 1.1 christos static void 607 1.1 christos process_base_type (struct ctf_context *ccp, ctf_id_t tid) 608 1.1 christos { 609 1.1 christos struct type *type; 610 1.1 christos 611 1.1 christos type = read_base_type (ccp, tid); 612 1.1 christos new_symbol (ccp, type, tid); 613 1.1 christos } 614 1.1 christos 615 1.1 christos /* Start a structure or union scope (definition) with TID to create a type 616 1.1 christos for the structure or union. 617 1.1 christos 618 1.1 christos Fill in the type's name and general properties. The members will not be 619 1.1 christos processed, nor a symbol table entry be done until process_structure_type 620 1.1 christos (assuming the type has a name). */ 621 1.1 christos 622 1.1 christos static struct type * 623 1.1 christos read_structure_type (struct ctf_context *ccp, ctf_id_t tid) 624 1.1 christos { 625 1.1 christos struct objfile *of = ccp->of; 626 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 627 1.1 christos struct type *type; 628 1.1 christos uint32_t kind; 629 1.1 christos 630 1.1.1.3 christos type = type_allocator (of, language_c).new_type (); 631 1.1 christos 632 1.1.1.2 christos const char *name = ctf_type_name_raw (fp, tid); 633 1.1.1.2 christos if (name != nullptr && strlen (name) != 0) 634 1.1.1.2 christos type->set_name (name); 635 1.1 christos 636 1.1 christos kind = ctf_type_kind (fp, tid); 637 1.1 christos if (kind == CTF_K_UNION) 638 1.1 christos type->set_code (TYPE_CODE_UNION); 639 1.1 christos else 640 1.1 christos type->set_code (TYPE_CODE_STRUCT); 641 1.1 christos 642 1.1.1.2 christos type->set_length (ctf_type_size (fp, tid)); 643 1.1 christos set_type_align (type, ctf_type_align (fp, tid)); 644 1.1 christos 645 1.1 christos return set_tid_type (ccp->of, tid, type); 646 1.1 christos } 647 1.1 christos 648 1.1 christos /* Given a tid of CTF_K_STRUCT or CTF_K_UNION, process all its members 649 1.1 christos and create the symbol for it. */ 650 1.1 christos 651 1.1 christos static void 652 1.1 christos process_struct_members (struct ctf_context *ccp, 653 1.1 christos ctf_id_t tid, 654 1.1 christos struct type *type) 655 1.1 christos { 656 1.1 christos struct ctf_field_info fi; 657 1.1 christos 658 1.1 christos fi.cur_context = ccp; 659 1.1 christos if (ctf_member_iter (ccp->fp, tid, ctf_add_member_cb, &fi) == CTF_ERR) 660 1.1 christos complaint (_("ctf_member_iter process_struct_members failed - %s"), 661 1.1 christos ctf_errmsg (ctf_errno (ccp->fp))); 662 1.1 christos 663 1.1 christos /* Attach fields to the type. */ 664 1.1 christos attach_fields_to_type (&fi, type); 665 1.1 christos 666 1.1 christos new_symbol (ccp, type, tid); 667 1.1 christos } 668 1.1 christos 669 1.1 christos static void 670 1.1 christos process_structure_type (struct ctf_context *ccp, ctf_id_t tid) 671 1.1 christos { 672 1.1 christos struct type *type; 673 1.1 christos 674 1.1 christos type = read_structure_type (ccp, tid); 675 1.1 christos process_struct_members (ccp, tid, type); 676 1.1 christos } 677 1.1 christos 678 1.1 christos /* Create a function type for TID and set its return type. */ 679 1.1 christos 680 1.1 christos static struct type * 681 1.1 christos read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid) 682 1.1 christos { 683 1.1 christos struct objfile *of = ccp->of; 684 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 685 1.1.1.2 christos struct type *type, *rettype, *atype; 686 1.1 christos ctf_funcinfo_t cfi; 687 1.1.1.2 christos uint32_t argc; 688 1.1 christos 689 1.1.1.3 christos type = type_allocator (of, language_c).new_type (); 690 1.1 christos 691 1.1 christos type->set_code (TYPE_CODE_FUNC); 692 1.1.1.2 christos if (ctf_func_type_info (fp, tid, &cfi) < 0) 693 1.1.1.2 christos { 694 1.1.1.2 christos const char *fname = ctf_type_name_raw (fp, tid); 695 1.1.1.2 christos error (_("Error getting function type info: %s"), 696 1.1.1.2 christos fname == nullptr ? "noname" : fname); 697 1.1.1.2 christos } 698 1.1.1.2 christos rettype = fetch_tid_type (ccp, cfi.ctc_return); 699 1.1.1.2 christos type->set_target_type (rettype); 700 1.1 christos set_type_align (type, ctf_type_align (fp, tid)); 701 1.1 christos 702 1.1.1.2 christos /* Set up function's arguments. */ 703 1.1.1.2 christos argc = cfi.ctc_argc; 704 1.1.1.2 christos type->set_num_fields (argc); 705 1.1.1.2 christos if ((cfi.ctc_flags & CTF_FUNC_VARARG) != 0) 706 1.1.1.2 christos type->set_has_varargs (true); 707 1.1.1.2 christos 708 1.1.1.2 christos if (argc != 0) 709 1.1.1.2 christos { 710 1.1.1.2 christos std::vector<ctf_id_t> argv (argc); 711 1.1.1.2 christos if (ctf_func_type_args (fp, tid, argc, argv.data ()) == CTF_ERR) 712 1.1.1.2 christos return nullptr; 713 1.1.1.2 christos 714 1.1.1.3 christos type->alloc_fields (argc); 715 1.1.1.3 christos struct type *void_type = builtin_type (of)->builtin_void; 716 1.1.1.2 christos /* If failed to find the argument type, fill it with void_type. */ 717 1.1.1.2 christos for (int iparam = 0; iparam < argc; iparam++) 718 1.1.1.2 christos { 719 1.1.1.2 christos atype = fetch_tid_type (ccp, argv[iparam]); 720 1.1.1.2 christos if (atype != nullptr) 721 1.1.1.2 christos type->field (iparam).set_type (atype); 722 1.1.1.2 christos else 723 1.1.1.2 christos type->field (iparam).set_type (void_type); 724 1.1.1.2 christos } 725 1.1.1.2 christos } 726 1.1.1.2 christos 727 1.1 christos return set_tid_type (of, tid, type); 728 1.1 christos } 729 1.1 christos 730 1.1 christos /* Given a TID of CTF_K_ENUM, process all the members of the 731 1.1 christos enumeration, and create the symbol for the enumeration type. */ 732 1.1 christos 733 1.1 christos static struct type * 734 1.1 christos read_enum_type (struct ctf_context *ccp, ctf_id_t tid) 735 1.1 christos { 736 1.1 christos struct objfile *of = ccp->of; 737 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 738 1.1.1.2 christos struct type *type; 739 1.1 christos 740 1.1.1.3 christos type = type_allocator (of, language_c).new_type (); 741 1.1 christos 742 1.1.1.2 christos const char *name = ctf_type_name_raw (fp, tid); 743 1.1.1.2 christos if (name != nullptr && strlen (name) != 0) 744 1.1.1.2 christos type->set_name (name); 745 1.1 christos 746 1.1 christos type->set_code (TYPE_CODE_ENUM); 747 1.1.1.2 christos type->set_length (ctf_type_size (fp, tid)); 748 1.1.1.2 christos /* Set the underlying type based on its ctf_type_size bits. */ 749 1.1.1.2 christos type->set_target_type (objfile_int_type (of, type->length (), false)); 750 1.1 christos set_type_align (type, ctf_type_align (fp, tid)); 751 1.1 christos 752 1.1 christos return set_tid_type (of, tid, type); 753 1.1 christos } 754 1.1 christos 755 1.1 christos static void 756 1.1 christos process_enum_type (struct ctf_context *ccp, ctf_id_t tid) 757 1.1 christos { 758 1.1 christos struct type *type; 759 1.1 christos struct ctf_field_info fi; 760 1.1 christos 761 1.1 christos type = read_enum_type (ccp, tid); 762 1.1 christos 763 1.1 christos fi.cur_context = ccp; 764 1.1 christos fi.ptype = type; 765 1.1 christos if (ctf_enum_iter (ccp->fp, tid, ctf_add_enum_member_cb, &fi) == CTF_ERR) 766 1.1 christos complaint (_("ctf_enum_iter process_enum_type failed - %s"), 767 1.1 christos ctf_errmsg (ctf_errno (ccp->fp))); 768 1.1 christos 769 1.1 christos /* Attach fields to the type. */ 770 1.1 christos attach_fields_to_type (&fi, type); 771 1.1 christos 772 1.1 christos new_symbol (ccp, type, tid); 773 1.1 christos } 774 1.1 christos 775 1.1 christos /* Add given cv-qualifiers CNST+VOLTL to the BASE_TYPE of array TID. */ 776 1.1 christos 777 1.1 christos static struct type * 778 1.1 christos add_array_cv_type (struct ctf_context *ccp, 779 1.1 christos ctf_id_t tid, 780 1.1 christos struct type *base_type, 781 1.1 christos int cnst, 782 1.1 christos int voltl) 783 1.1 christos { 784 1.1 christos struct type *el_type, *inner_array; 785 1.1 christos 786 1.1 christos base_type = copy_type (base_type); 787 1.1 christos inner_array = base_type; 788 1.1 christos 789 1.1.1.2 christos while (inner_array->target_type ()->code () == TYPE_CODE_ARRAY) 790 1.1 christos { 791 1.1.1.2 christos inner_array->set_target_type (copy_type (inner_array->target_type ())); 792 1.1.1.2 christos inner_array = inner_array->target_type (); 793 1.1 christos } 794 1.1 christos 795 1.1.1.2 christos el_type = inner_array->target_type (); 796 1.1 christos cnst |= TYPE_CONST (el_type); 797 1.1 christos voltl |= TYPE_VOLATILE (el_type); 798 1.1.1.2 christos inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, nullptr)); 799 1.1 christos 800 1.1 christos return set_tid_type (ccp->of, tid, base_type); 801 1.1 christos } 802 1.1 christos 803 1.1 christos /* Read all information from a TID of CTF_K_ARRAY. */ 804 1.1 christos 805 1.1 christos static struct type * 806 1.1 christos read_array_type (struct ctf_context *ccp, ctf_id_t tid) 807 1.1 christos { 808 1.1 christos struct objfile *objfile = ccp->of; 809 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 810 1.1 christos struct type *element_type, *range_type, *idx_type; 811 1.1 christos struct type *type; 812 1.1 christos ctf_arinfo_t ar; 813 1.1 christos 814 1.1 christos if (ctf_array_info (fp, tid, &ar) == CTF_ERR) 815 1.1 christos { 816 1.1 christos complaint (_("ctf_array_info read_array_type failed - %s"), 817 1.1 christos ctf_errmsg (ctf_errno (fp))); 818 1.1.1.2 christos return nullptr; 819 1.1 christos } 820 1.1 christos 821 1.1.1.2 christos element_type = fetch_tid_type (ccp, ar.ctr_contents); 822 1.1.1.2 christos if (element_type == nullptr) 823 1.1.1.2 christos return nullptr; 824 1.1 christos 825 1.1.1.2 christos idx_type = fetch_tid_type (ccp, ar.ctr_index); 826 1.1.1.2 christos if (idx_type == nullptr) 827 1.1.1.3 christos idx_type = builtin_type (objfile)->builtin_int; 828 1.1 christos 829 1.1.1.3 christos type_allocator alloc (objfile, language_c); 830 1.1.1.3 christos range_type = create_static_range_type (alloc, idx_type, 0, ar.ctr_nelems - 1); 831 1.1.1.3 christos type = create_array_type (alloc, element_type, range_type); 832 1.1 christos if (ar.ctr_nelems <= 1) /* Check if undefined upper bound. */ 833 1.1 christos { 834 1.1 christos range_type->bounds ()->high.set_undefined (); 835 1.1.1.2 christos type->set_length (0); 836 1.1.1.2 christos type->set_target_is_stub (true); 837 1.1 christos } 838 1.1 christos else 839 1.1.1.2 christos type->set_length (ctf_type_size (fp, tid)); 840 1.1 christos 841 1.1 christos set_type_align (type, ctf_type_align (fp, tid)); 842 1.1 christos 843 1.1 christos return set_tid_type (objfile, tid, type); 844 1.1 christos } 845 1.1 christos 846 1.1 christos /* Read TID of kind CTF_K_CONST with base type BTID. */ 847 1.1 christos 848 1.1 christos static struct type * 849 1.1 christos read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) 850 1.1 christos { 851 1.1 christos struct objfile *objfile = ccp->of; 852 1.1 christos struct type *base_type, *cv_type; 853 1.1 christos 854 1.1.1.2 christos base_type = fetch_tid_type (ccp, btid); 855 1.1.1.2 christos if (base_type == nullptr) 856 1.1 christos { 857 1.1 christos base_type = read_type_record (ccp, btid); 858 1.1.1.2 christos if (base_type == nullptr) 859 1.1 christos { 860 1.1 christos complaint (_("read_const_type: NULL base type (%ld)"), btid); 861 1.1.1.3 christos base_type = builtin_type (objfile)->builtin_error; 862 1.1 christos } 863 1.1 christos } 864 1.1 christos cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); 865 1.1 christos 866 1.1 christos return set_tid_type (objfile, tid, cv_type); 867 1.1 christos } 868 1.1 christos 869 1.1 christos /* Read TID of kind CTF_K_VOLATILE with base type BTID. */ 870 1.1 christos 871 1.1 christos static struct type * 872 1.1 christos read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) 873 1.1 christos { 874 1.1 christos struct objfile *objfile = ccp->of; 875 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 876 1.1 christos struct type *base_type, *cv_type; 877 1.1 christos 878 1.1.1.2 christos base_type = fetch_tid_type (ccp, btid); 879 1.1.1.2 christos if (base_type == nullptr) 880 1.1 christos { 881 1.1 christos base_type = read_type_record (ccp, btid); 882 1.1.1.2 christos if (base_type == nullptr) 883 1.1 christos { 884 1.1 christos complaint (_("read_volatile_type: NULL base type (%ld)"), btid); 885 1.1.1.3 christos base_type = builtin_type (objfile)->builtin_error; 886 1.1 christos } 887 1.1 christos } 888 1.1 christos 889 1.1 christos if (ctf_type_kind (fp, btid) == CTF_K_ARRAY) 890 1.1 christos return add_array_cv_type (ccp, tid, base_type, 0, 1); 891 1.1 christos cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); 892 1.1 christos 893 1.1 christos return set_tid_type (objfile, tid, cv_type); 894 1.1 christos } 895 1.1 christos 896 1.1 christos /* Read TID of kind CTF_K_RESTRICT with base type BTID. */ 897 1.1 christos 898 1.1 christos static struct type * 899 1.1 christos read_restrict_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) 900 1.1 christos { 901 1.1 christos struct objfile *objfile = ccp->of; 902 1.1 christos struct type *base_type, *cv_type; 903 1.1 christos 904 1.1.1.2 christos base_type = fetch_tid_type (ccp, btid); 905 1.1.1.2 christos if (base_type == nullptr) 906 1.1 christos { 907 1.1 christos base_type = read_type_record (ccp, btid); 908 1.1.1.2 christos if (base_type == nullptr) 909 1.1 christos { 910 1.1 christos complaint (_("read_restrict_type: NULL base type (%ld)"), btid); 911 1.1.1.3 christos base_type = builtin_type (objfile)->builtin_error; 912 1.1 christos } 913 1.1 christos } 914 1.1 christos cv_type = make_restrict_type (base_type); 915 1.1 christos 916 1.1 christos return set_tid_type (objfile, tid, cv_type); 917 1.1 christos } 918 1.1 christos 919 1.1 christos /* Read TID of kind CTF_K_TYPEDEF with its NAME and base type BTID. */ 920 1.1 christos 921 1.1 christos static struct type * 922 1.1 christos read_typedef_type (struct ctf_context *ccp, ctf_id_t tid, 923 1.1 christos ctf_id_t btid, const char *name) 924 1.1 christos { 925 1.1 christos struct objfile *objfile = ccp->of; 926 1.1 christos struct type *this_type, *target_type; 927 1.1 christos 928 1.1 christos char *aname = obstack_strdup (&objfile->objfile_obstack, name); 929 1.1.1.3 christos this_type = type_allocator (objfile, language_c).new_type (TYPE_CODE_TYPEDEF, 930 1.1.1.3 christos 0, aname); 931 1.1 christos set_tid_type (objfile, tid, this_type); 932 1.1.1.2 christos target_type = fetch_tid_type (ccp, btid); 933 1.1 christos if (target_type != this_type) 934 1.1.1.2 christos this_type->set_target_type (target_type); 935 1.1 christos else 936 1.1.1.2 christos this_type->set_target_type (nullptr); 937 1.1.1.2 christos 938 1.1.1.2 christos this_type->set_target_is_stub (this_type->target_type () != nullptr); 939 1.1 christos 940 1.1 christos return set_tid_type (objfile, tid, this_type); 941 1.1 christos } 942 1.1 christos 943 1.1 christos /* Read TID of kind CTF_K_POINTER with base type BTID. */ 944 1.1 christos 945 1.1 christos static struct type * 946 1.1 christos read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) 947 1.1 christos { 948 1.1 christos struct objfile *of = ccp->of; 949 1.1 christos struct type *target_type, *type; 950 1.1 christos 951 1.1.1.2 christos target_type = fetch_tid_type (ccp, btid); 952 1.1.1.2 christos if (target_type == nullptr) 953 1.1 christos { 954 1.1 christos target_type = read_type_record (ccp, btid); 955 1.1.1.2 christos if (target_type == nullptr) 956 1.1 christos { 957 1.1 christos complaint (_("read_pointer_type: NULL target type (%ld)"), btid); 958 1.1.1.3 christos target_type = builtin_type (ccp->of)->builtin_error; 959 1.1 christos } 960 1.1 christos } 961 1.1 christos 962 1.1 christos type = lookup_pointer_type (target_type); 963 1.1 christos set_type_align (type, ctf_type_align (ccp->fp, tid)); 964 1.1 christos 965 1.1 christos return set_tid_type (of, tid, type); 966 1.1 christos } 967 1.1 christos 968 1.1.1.2 christos /* Read information from a TID of CTF_K_FORWARD. */ 969 1.1.1.2 christos 970 1.1.1.2 christos static struct type * 971 1.1.1.2 christos read_forward_type (struct ctf_context *ccp, ctf_id_t tid) 972 1.1.1.2 christos { 973 1.1.1.2 christos struct objfile *of = ccp->of; 974 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 975 1.1.1.2 christos struct type *type; 976 1.1.1.2 christos uint32_t kind; 977 1.1.1.2 christos 978 1.1.1.3 christos type = type_allocator (of, language_c).new_type (); 979 1.1.1.2 christos 980 1.1.1.2 christos const char *name = ctf_type_name_raw (fp, tid); 981 1.1.1.2 christos if (name != nullptr && strlen (name) != 0) 982 1.1.1.2 christos type->set_name (name); 983 1.1.1.2 christos 984 1.1.1.2 christos kind = ctf_type_kind_forwarded (fp, tid); 985 1.1.1.2 christos if (kind == CTF_K_UNION) 986 1.1.1.2 christos type->set_code (TYPE_CODE_UNION); 987 1.1.1.2 christos else 988 1.1.1.2 christos type->set_code (TYPE_CODE_STRUCT); 989 1.1.1.2 christos 990 1.1.1.2 christos type->set_length (0); 991 1.1.1.2 christos type->set_is_stub (true); 992 1.1.1.2 christos 993 1.1.1.2 christos return set_tid_type (of, tid, type); 994 1.1.1.2 christos } 995 1.1.1.2 christos 996 1.1 christos /* Read information associated with type TID. */ 997 1.1 christos 998 1.1 christos static struct type * 999 1.1 christos read_type_record (struct ctf_context *ccp, ctf_id_t tid) 1000 1.1 christos { 1001 1.1.1.2 christos ctf_dict_t *fp = ccp->fp; 1002 1.1 christos uint32_t kind; 1003 1.1.1.2 christos struct type *type = nullptr; 1004 1.1 christos ctf_id_t btid; 1005 1.1 christos 1006 1.1 christos kind = ctf_type_kind (fp, tid); 1007 1.1 christos switch (kind) 1008 1.1 christos { 1009 1.1 christos case CTF_K_STRUCT: 1010 1.1 christos case CTF_K_UNION: 1011 1.1 christos type = read_structure_type (ccp, tid); 1012 1.1 christos break; 1013 1.1 christos case CTF_K_ENUM: 1014 1.1 christos type = read_enum_type (ccp, tid); 1015 1.1 christos break; 1016 1.1 christos case CTF_K_FUNCTION: 1017 1.1 christos type = read_func_kind_type (ccp, tid); 1018 1.1 christos break; 1019 1.1 christos case CTF_K_CONST: 1020 1.1 christos btid = ctf_type_reference (fp, tid); 1021 1.1 christos type = read_const_type (ccp, tid, btid); 1022 1.1 christos break; 1023 1.1 christos case CTF_K_TYPEDEF: 1024 1.1 christos { 1025 1.1.1.2 christos const char *name = ctf_type_name_raw (fp, tid); 1026 1.1 christos btid = ctf_type_reference (fp, tid); 1027 1.1.1.2 christos type = read_typedef_type (ccp, tid, btid, name); 1028 1.1 christos } 1029 1.1 christos break; 1030 1.1 christos case CTF_K_VOLATILE: 1031 1.1 christos btid = ctf_type_reference (fp, tid); 1032 1.1 christos type = read_volatile_type (ccp, tid, btid); 1033 1.1 christos break; 1034 1.1 christos case CTF_K_RESTRICT: 1035 1.1 christos btid = ctf_type_reference (fp, tid); 1036 1.1 christos type = read_restrict_type (ccp, tid, btid); 1037 1.1 christos break; 1038 1.1 christos case CTF_K_POINTER: 1039 1.1 christos btid = ctf_type_reference (fp, tid); 1040 1.1 christos type = read_pointer_type (ccp, tid, btid); 1041 1.1 christos break; 1042 1.1 christos case CTF_K_INTEGER: 1043 1.1 christos case CTF_K_FLOAT: 1044 1.1 christos type = read_base_type (ccp, tid); 1045 1.1 christos break; 1046 1.1 christos case CTF_K_ARRAY: 1047 1.1 christos type = read_array_type (ccp, tid); 1048 1.1 christos break; 1049 1.1.1.2 christos case CTF_K_FORWARD: 1050 1.1.1.2 christos type = read_forward_type (ccp, tid); 1051 1.1.1.2 christos break; 1052 1.1 christos case CTF_K_UNKNOWN: 1053 1.1 christos break; 1054 1.1 christos default: 1055 1.1 christos break; 1056 1.1 christos } 1057 1.1 christos 1058 1.1 christos return type; 1059 1.1 christos } 1060 1.1 christos 1061 1.1 christos /* Callback to add type TID to the symbol table. */ 1062 1.1 christos 1063 1.1 christos static int 1064 1.1 christos ctf_add_type_cb (ctf_id_t tid, void *arg) 1065 1.1 christos { 1066 1.1 christos struct ctf_context *ccp = (struct ctf_context *) arg; 1067 1.1 christos struct type *type; 1068 1.1 christos uint32_t kind; 1069 1.1 christos 1070 1.1 christos /* Check if tid's type has already been defined. */ 1071 1.1 christos type = get_tid_type (ccp->of, tid); 1072 1.1.1.2 christos if (type != nullptr) 1073 1.1 christos return 0; 1074 1.1 christos 1075 1.1 christos ctf_id_t btid = ctf_type_reference (ccp->fp, tid); 1076 1.1 christos kind = ctf_type_kind (ccp->fp, tid); 1077 1.1 christos switch (kind) 1078 1.1 christos { 1079 1.1 christos case CTF_K_STRUCT: 1080 1.1 christos case CTF_K_UNION: 1081 1.1 christos process_structure_type (ccp, tid); 1082 1.1 christos break; 1083 1.1 christos case CTF_K_ENUM: 1084 1.1 christos process_enum_type (ccp, tid); 1085 1.1 christos break; 1086 1.1 christos case CTF_K_FUNCTION: 1087 1.1 christos type = read_func_kind_type (ccp, tid); 1088 1.1 christos new_symbol (ccp, type, tid); 1089 1.1 christos break; 1090 1.1 christos case CTF_K_INTEGER: 1091 1.1 christos case CTF_K_FLOAT: 1092 1.1 christos process_base_type (ccp, tid); 1093 1.1 christos break; 1094 1.1 christos case CTF_K_TYPEDEF: 1095 1.1 christos new_symbol (ccp, read_type_record (ccp, tid), tid); 1096 1.1 christos break; 1097 1.1 christos case CTF_K_CONST: 1098 1.1 christos type = read_const_type (ccp, tid, btid); 1099 1.1 christos new_symbol (ccp, type, tid); 1100 1.1 christos break; 1101 1.1 christos case CTF_K_VOLATILE: 1102 1.1 christos type = read_volatile_type (ccp, tid, btid); 1103 1.1 christos new_symbol (ccp, type, tid); 1104 1.1 christos break; 1105 1.1 christos case CTF_K_RESTRICT: 1106 1.1 christos type = read_restrict_type (ccp, tid, btid); 1107 1.1 christos new_symbol (ccp, type, tid); 1108 1.1 christos break; 1109 1.1 christos case CTF_K_POINTER: 1110 1.1 christos type = read_pointer_type (ccp, tid, btid); 1111 1.1 christos new_symbol (ccp, type, tid); 1112 1.1 christos break; 1113 1.1 christos case CTF_K_ARRAY: 1114 1.1 christos type = read_array_type (ccp, tid); 1115 1.1 christos new_symbol (ccp, type, tid); 1116 1.1 christos break; 1117 1.1 christos case CTF_K_UNKNOWN: 1118 1.1 christos break; 1119 1.1 christos default: 1120 1.1 christos break; 1121 1.1 christos } 1122 1.1 christos 1123 1.1 christos return 0; 1124 1.1 christos } 1125 1.1 christos 1126 1.1 christos /* Callback to add variable NAME with TID to the symbol table. */ 1127 1.1 christos 1128 1.1 christos static int 1129 1.1 christos ctf_add_var_cb (const char *name, ctf_id_t id, void *arg) 1130 1.1 christos { 1131 1.1 christos struct ctf_context *ccp = (struct ctf_context *) arg; 1132 1.1.1.2 christos struct symbol *sym = nullptr; 1133 1.1 christos struct type *type; 1134 1.1 christos uint32_t kind; 1135 1.1 christos 1136 1.1 christos type = get_tid_type (ccp->of, id); 1137 1.1 christos 1138 1.1 christos kind = ctf_type_kind (ccp->fp, id); 1139 1.1 christos switch (kind) 1140 1.1 christos { 1141 1.1 christos case CTF_K_FUNCTION: 1142 1.1.1.2 christos if (name != nullptr && strcmp (name, "main") == 0) 1143 1.1 christos set_objfile_main_name (ccp->of, name, language_c); 1144 1.1 christos break; 1145 1.1 christos case CTF_K_INTEGER: 1146 1.1 christos case CTF_K_FLOAT: 1147 1.1 christos case CTF_K_VOLATILE: 1148 1.1 christos case CTF_K_RESTRICT: 1149 1.1 christos case CTF_K_TYPEDEF: 1150 1.1 christos case CTF_K_CONST: 1151 1.1 christos case CTF_K_POINTER: 1152 1.1 christos case CTF_K_ARRAY: 1153 1.1.1.2 christos if (type != nullptr) 1154 1.1 christos { 1155 1.1 christos sym = new_symbol (ccp, type, id); 1156 1.1.1.2 christos if (sym != nullptr) 1157 1.1.1.2 christos sym->compute_and_set_names (name, false, ccp->of->per_bfd); 1158 1.1 christos } 1159 1.1 christos break; 1160 1.1 christos case CTF_K_STRUCT: 1161 1.1 christos case CTF_K_UNION: 1162 1.1 christos case CTF_K_ENUM: 1163 1.1.1.2 christos if (type == nullptr) 1164 1.1.1.2 christos { 1165 1.1.1.2 christos complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id); 1166 1.1.1.3 christos type = builtin_type (ccp->of)->builtin_error; 1167 1.1.1.2 christos } 1168 1.1 christos sym = new (&ccp->of->objfile_obstack) symbol; 1169 1.1 christos OBJSTAT (ccp->of, n_syms++); 1170 1.1.1.2 christos sym->set_type (type); 1171 1.1.1.2 christos sym->set_domain (VAR_DOMAIN); 1172 1.1.1.2 christos sym->set_aclass_index (LOC_OPTIMIZED_OUT); 1173 1.1 christos sym->compute_and_set_names (name, false, ccp->of->per_bfd); 1174 1.1.1.2 christos add_symbol_to_list (sym, ccp->builder->get_file_symbols ()); 1175 1.1 christos break; 1176 1.1 christos default: 1177 1.1 christos complaint (_("ctf_add_var_cb: kind unsupported (%d)"), kind); 1178 1.1 christos break; 1179 1.1 christos } 1180 1.1 christos 1181 1.1.1.2 christos if (sym != nullptr) 1182 1.1 christos set_symbol_address (ccp->of, sym, name); 1183 1.1 christos 1184 1.1 christos return 0; 1185 1.1 christos } 1186 1.1 christos 1187 1.1.1.2 christos /* Add entries in either data objects or function info section, controlled 1188 1.1.1.2 christos by FUNCTIONS. */ 1189 1.1 christos 1190 1.1.1.2 christos static void 1191 1.1.1.2 christos add_stt_entries (struct ctf_context *ccp, int functions) 1192 1.1 christos { 1193 1.1.1.2 christos ctf_next_t *i = nullptr; 1194 1.1.1.2 christos const char *tname; 1195 1.1 christos ctf_id_t tid; 1196 1.1.1.2 christos struct symbol *sym = nullptr; 1197 1.1.1.2 christos struct type *type; 1198 1.1 christos 1199 1.1.1.2 christos while ((tid = ctf_symbol_next (ccp->fp, &i, &tname, functions)) != CTF_ERR) 1200 1.1.1.2 christos { 1201 1.1.1.2 christos type = get_tid_type (ccp->of, tid); 1202 1.1.1.2 christos if (type == nullptr) 1203 1.1.1.2 christos continue; 1204 1.1.1.2 christos sym = new (&ccp->of->objfile_obstack) symbol; 1205 1.1.1.2 christos OBJSTAT (ccp->of, n_syms++); 1206 1.1.1.2 christos sym->set_type (type); 1207 1.1.1.2 christos sym->set_domain (VAR_DOMAIN); 1208 1.1.1.2 christos sym->set_aclass_index (LOC_STATIC); 1209 1.1.1.2 christos sym->compute_and_set_names (tname, false, ccp->of->per_bfd); 1210 1.1.1.2 christos add_symbol_to_list (sym, ccp->builder->get_global_symbols ()); 1211 1.1.1.2 christos set_symbol_address (ccp->of, sym, tname); 1212 1.1.1.2 christos } 1213 1.1 christos } 1214 1.1 christos 1215 1.1.1.2 christos /* Add entries in data objects section. */ 1216 1.1 christos 1217 1.1.1.2 christos static void 1218 1.1.1.2 christos add_stt_obj (struct ctf_context *ccp) 1219 1.1 christos { 1220 1.1.1.2 christos add_stt_entries (ccp, 0); 1221 1.1.1.2 christos } 1222 1.1 christos 1223 1.1.1.2 christos /* Add entries in function info section. */ 1224 1.1 christos 1225 1.1.1.2 christos static void 1226 1.1.1.2 christos add_stt_func (struct ctf_context *ccp) 1227 1.1.1.2 christos { 1228 1.1.1.2 christos add_stt_entries (ccp, 1); 1229 1.1 christos } 1230 1.1 christos 1231 1.1.1.3 christos /* Get text section base for OBJFILE, TSIZE contains the size. */ 1232 1.1 christos 1233 1.1 christos static CORE_ADDR 1234 1.1.1.3 christos get_objfile_text_range (struct objfile *of, size_t *tsize) 1235 1.1 christos { 1236 1.1.1.2 christos bfd *abfd = of->obfd.get (); 1237 1.1 christos const asection *codes; 1238 1.1 christos 1239 1.1 christos codes = bfd_get_section_by_name (abfd, ".text"); 1240 1.1 christos *tsize = codes ? bfd_section_size (codes) : 0; 1241 1.1 christos return of->text_section_offset (); 1242 1.1 christos } 1243 1.1 christos 1244 1.1 christos /* Start a symtab for OBJFILE in CTF format. */ 1245 1.1 christos 1246 1.1 christos static void 1247 1.1.1.2 christos ctf_start_compunit_symtab (ctf_psymtab *pst, 1248 1.1.1.2 christos struct objfile *of, CORE_ADDR text_offset) 1249 1.1 christos { 1250 1.1 christos struct ctf_context *ccp; 1251 1.1 christos 1252 1.1.1.2 christos ccp = &pst->context; 1253 1.1 christos ccp->builder = new buildsym_compunit 1254 1.1.1.2 christos (of, pst->filename, nullptr, 1255 1.1 christos language_c, text_offset); 1256 1.1 christos ccp->builder->record_debugformat ("ctf"); 1257 1.1 christos } 1258 1.1 christos 1259 1.1 christos /* Finish reading symbol/type definitions in CTF format. 1260 1.1.1.3 christos END_ADDR is the end address of the file's text. */ 1261 1.1 christos 1262 1.1 christos static struct compunit_symtab * 1263 1.1.1.2 christos ctf_end_compunit_symtab (ctf_psymtab *pst, 1264 1.1.1.3 christos CORE_ADDR end_addr) 1265 1.1 christos { 1266 1.1 christos struct ctf_context *ccp; 1267 1.1 christos 1268 1.1.1.2 christos ccp = &pst->context; 1269 1.1 christos struct compunit_symtab *result 1270 1.1.1.3 christos = ccp->builder->end_compunit_symtab (end_addr); 1271 1.1 christos delete ccp->builder; 1272 1.1.1.2 christos ccp->builder = nullptr; 1273 1.1 christos return result; 1274 1.1 christos } 1275 1.1 christos 1276 1.1.1.2 christos /* Add all members of an enum with type TID to partial symbol table. */ 1277 1.1.1.2 christos 1278 1.1.1.2 christos static void 1279 1.1.1.2 christos ctf_psymtab_add_enums (struct ctf_context *ccp, ctf_id_t tid) 1280 1.1.1.2 christos { 1281 1.1.1.2 christos int val; 1282 1.1.1.2 christos const char *ename; 1283 1.1.1.2 christos ctf_next_t *i = nullptr; 1284 1.1.1.2 christos 1285 1.1.1.2 christos while ((ename = ctf_enum_next (ccp->fp, tid, &i, &val)) != nullptr) 1286 1.1.1.2 christos { 1287 1.1.1.2 christos ccp->pst->add_psymbol (ename, true, 1288 1.1.1.2 christos VAR_DOMAIN, LOC_CONST, -1, 1289 1.1.1.2 christos psymbol_placement::GLOBAL, 1290 1.1.1.3 christos unrelocated_addr (0), 1291 1.1.1.3 christos language_c, ccp->partial_symtabs, ccp->of); 1292 1.1.1.2 christos } 1293 1.1.1.2 christos if (ctf_errno (ccp->fp) != ECTF_NEXT_END) 1294 1.1.1.2 christos complaint (_("ctf_enum_next ctf_psymtab_add_enums failed - %s"), 1295 1.1.1.2 christos ctf_errmsg (ctf_errno (ccp->fp))); 1296 1.1.1.2 christos } 1297 1.1.1.2 christos 1298 1.1.1.2 christos /* Add entries in either data objects or function info section, controlled 1299 1.1.1.2 christos by FUNCTIONS, to psymtab. */ 1300 1.1.1.2 christos 1301 1.1.1.2 christos static void 1302 1.1.1.2 christos ctf_psymtab_add_stt_entries (ctf_dict_t *cfp, ctf_psymtab *pst, 1303 1.1.1.2 christos struct objfile *of, int functions) 1304 1.1.1.2 christos { 1305 1.1.1.2 christos ctf_next_t *i = nullptr; 1306 1.1.1.2 christos ctf_id_t tid; 1307 1.1.1.2 christos const char *tname; 1308 1.1.1.2 christos 1309 1.1.1.2 christos while ((tid = ctf_symbol_next (cfp, &i, &tname, functions)) != CTF_ERR) 1310 1.1.1.2 christos { 1311 1.1.1.2 christos uint32_t kind = ctf_type_kind (cfp, tid); 1312 1.1.1.2 christos address_class aclass; 1313 1.1.1.2 christos domain_enum tdomain; 1314 1.1.1.2 christos switch (kind) 1315 1.1.1.2 christos { 1316 1.1.1.2 christos case CTF_K_STRUCT: 1317 1.1.1.2 christos case CTF_K_UNION: 1318 1.1.1.2 christos case CTF_K_ENUM: 1319 1.1.1.2 christos tdomain = STRUCT_DOMAIN; 1320 1.1.1.2 christos break; 1321 1.1.1.2 christos default: 1322 1.1.1.2 christos tdomain = VAR_DOMAIN; 1323 1.1.1.2 christos break; 1324 1.1.1.2 christos } 1325 1.1.1.2 christos 1326 1.1.1.2 christos if (kind == CTF_K_FUNCTION) 1327 1.1.1.2 christos aclass = LOC_STATIC; 1328 1.1.1.2 christos else if (kind == CTF_K_CONST) 1329 1.1.1.2 christos aclass = LOC_CONST; 1330 1.1.1.2 christos else 1331 1.1.1.2 christos aclass = LOC_TYPEDEF; 1332 1.1.1.2 christos 1333 1.1.1.2 christos pst->add_psymbol (tname, true, 1334 1.1.1.2 christos tdomain, aclass, -1, 1335 1.1.1.2 christos psymbol_placement::GLOBAL, 1336 1.1.1.3 christos unrelocated_addr (0), 1337 1.1.1.3 christos language_c, pst->context.partial_symtabs, of); 1338 1.1.1.2 christos } 1339 1.1.1.2 christos } 1340 1.1.1.2 christos 1341 1.1.1.2 christos /* Add entries in data objects section to psymtab. */ 1342 1.1.1.2 christos 1343 1.1.1.2 christos static void 1344 1.1.1.2 christos ctf_psymtab_add_stt_obj (ctf_dict_t *cfp, ctf_psymtab *pst, 1345 1.1.1.2 christos struct objfile *of) 1346 1.1.1.2 christos { 1347 1.1.1.2 christos ctf_psymtab_add_stt_entries (cfp, pst, of, 0); 1348 1.1.1.2 christos } 1349 1.1.1.2 christos 1350 1.1.1.2 christos /* Add entries in function info section to psymtab. */ 1351 1.1.1.2 christos 1352 1.1.1.2 christos static void 1353 1.1.1.2 christos ctf_psymtab_add_stt_func (ctf_dict_t *cfp, ctf_psymtab *pst, 1354 1.1.1.2 christos struct objfile *of) 1355 1.1.1.2 christos { 1356 1.1.1.2 christos ctf_psymtab_add_stt_entries (cfp, pst, of, 1); 1357 1.1.1.2 christos } 1358 1.1.1.2 christos 1359 1.1 christos /* Read in full symbols for PST, and anything it depends on. */ 1360 1.1 christos 1361 1.1 christos void 1362 1.1 christos ctf_psymtab::expand_psymtab (struct objfile *objfile) 1363 1.1 christos { 1364 1.1 christos struct ctf_context *ccp; 1365 1.1 christos 1366 1.1 christos gdb_assert (!readin); 1367 1.1 christos 1368 1.1.1.2 christos ccp = &context; 1369 1.1 christos 1370 1.1 christos /* Iterate over entries in data types section. */ 1371 1.1 christos if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR) 1372 1.1 christos complaint (_("ctf_type_iter psymtab_to_symtab failed - %s"), 1373 1.1 christos ctf_errmsg (ctf_errno (ccp->fp))); 1374 1.1 christos 1375 1.1 christos 1376 1.1 christos /* Iterate over entries in variable info section. */ 1377 1.1 christos if (ctf_variable_iter (ccp->fp, ctf_add_var_cb, ccp) == CTF_ERR) 1378 1.1 christos complaint (_("ctf_variable_iter psymtab_to_symtab failed - %s"), 1379 1.1 christos ctf_errmsg (ctf_errno (ccp->fp))); 1380 1.1 christos 1381 1.1 christos /* Add entries in data objects and function info sections. */ 1382 1.1.1.2 christos add_stt_obj (ccp); 1383 1.1.1.2 christos add_stt_func (ccp); 1384 1.1 christos 1385 1.1 christos readin = true; 1386 1.1 christos } 1387 1.1 christos 1388 1.1 christos /* Expand partial symbol table PST into a full symbol table. 1389 1.1 christos PST is not NULL. */ 1390 1.1 christos 1391 1.1 christos void 1392 1.1 christos ctf_psymtab::read_symtab (struct objfile *objfile) 1393 1.1 christos { 1394 1.1 christos if (readin) 1395 1.1 christos warning (_("bug: psymtab for %s is already read in."), filename); 1396 1.1 christos else 1397 1.1 christos { 1398 1.1 christos if (info_verbose) 1399 1.1 christos { 1400 1.1.1.2 christos gdb_printf (_("Reading in CTF data for %s..."), filename); 1401 1.1 christos gdb_flush (gdb_stdout); 1402 1.1 christos } 1403 1.1 christos 1404 1.1 christos /* Start a symtab. */ 1405 1.1 christos CORE_ADDR offset; /* Start of text segment. */ 1406 1.1.1.3 christos size_t tsize; 1407 1.1 christos 1408 1.1 christos offset = get_objfile_text_range (objfile, &tsize); 1409 1.1.1.2 christos ctf_start_compunit_symtab (this, objfile, offset); 1410 1.1 christos expand_psymtab (objfile); 1411 1.1 christos 1412 1.1.1.3 christos set_text_low (unrelocated_addr (0)); 1413 1.1.1.3 christos set_text_high (unrelocated_addr (tsize)); 1414 1.1.1.3 christos compunit_symtab = ctf_end_compunit_symtab (this, offset + tsize); 1415 1.1 christos 1416 1.1 christos /* Finish up the debug error message. */ 1417 1.1 christos if (info_verbose) 1418 1.1.1.2 christos gdb_printf (_("done.\n")); 1419 1.1 christos } 1420 1.1 christos } 1421 1.1 christos 1422 1.1 christos /* Allocate a new partial_symtab NAME. 1423 1.1 christos 1424 1.1 christos Each source file that has not been fully read in is represented by 1425 1.1 christos a partial_symtab. This contains the information on where in the 1426 1.1 christos executable the debugging symbols for a specific file are, and a 1427 1.1 christos list of names of global symbols which are located in this file. 1428 1.1 christos They are all chained on partial symtab lists. 1429 1.1 christos 1430 1.1 christos Even after the source file has been read into a symtab, the 1431 1.1 christos partial_symtab remains around. They are allocated on an obstack, 1432 1.1 christos objfile_obstack. */ 1433 1.1 christos 1434 1.1 christos static ctf_psymtab * 1435 1.1 christos create_partial_symtab (const char *name, 1436 1.1.1.2 christos ctf_archive_t *arc, 1437 1.1.1.2 christos ctf_dict_t *cfp, 1438 1.1.1.2 christos psymtab_storage *partial_symtabs, 1439 1.1 christos struct objfile *objfile) 1440 1.1 christos { 1441 1.1 christos ctf_psymtab *pst; 1442 1.1 christos 1443 1.1.1.3 christos pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd, 1444 1.1.1.3 christos unrelocated_addr (0)); 1445 1.1 christos 1446 1.1.1.2 christos pst->context.arc = arc; 1447 1.1.1.2 christos pst->context.fp = cfp; 1448 1.1.1.2 christos pst->context.of = objfile; 1449 1.1.1.2 christos pst->context.partial_symtabs = partial_symtabs; 1450 1.1.1.2 christos pst->context.pst = pst; 1451 1.1.1.2 christos pst->context.builder = nullptr; 1452 1.1 christos 1453 1.1 christos return pst; 1454 1.1 christos } 1455 1.1 christos 1456 1.1 christos /* Callback to add type TID to partial symbol table. */ 1457 1.1 christos 1458 1.1 christos static int 1459 1.1 christos ctf_psymtab_type_cb (ctf_id_t tid, void *arg) 1460 1.1 christos { 1461 1.1 christos struct ctf_context *ccp; 1462 1.1 christos uint32_t kind; 1463 1.1.1.4 christos int section = -1; 1464 1.1 christos 1465 1.1 christos ccp = (struct ctf_context *) arg; 1466 1.1 christos 1467 1.1 christos domain_enum domain = UNDEF_DOMAIN; 1468 1.1 christos enum address_class aclass = LOC_UNDEF; 1469 1.1 christos kind = ctf_type_kind (ccp->fp, tid); 1470 1.1 christos switch (kind) 1471 1.1 christos { 1472 1.1.1.2 christos case CTF_K_ENUM: 1473 1.1.1.2 christos ctf_psymtab_add_enums (ccp, tid); 1474 1.1.1.3 christos [[fallthrough]]; 1475 1.1 christos case CTF_K_STRUCT: 1476 1.1 christos case CTF_K_UNION: 1477 1.1 christos domain = STRUCT_DOMAIN; 1478 1.1 christos aclass = LOC_TYPEDEF; 1479 1.1 christos break; 1480 1.1 christos case CTF_K_FUNCTION: 1481 1.1 christos case CTF_K_FORWARD: 1482 1.1 christos domain = VAR_DOMAIN; 1483 1.1 christos aclass = LOC_STATIC; 1484 1.1 christos section = SECT_OFF_TEXT (ccp->of); 1485 1.1 christos break; 1486 1.1 christos case CTF_K_CONST: 1487 1.1 christos domain = VAR_DOMAIN; 1488 1.1 christos aclass = LOC_STATIC; 1489 1.1 christos break; 1490 1.1 christos case CTF_K_TYPEDEF: 1491 1.1 christos case CTF_K_POINTER: 1492 1.1 christos case CTF_K_VOLATILE: 1493 1.1 christos case CTF_K_RESTRICT: 1494 1.1 christos domain = VAR_DOMAIN; 1495 1.1 christos aclass = LOC_TYPEDEF; 1496 1.1 christos break; 1497 1.1 christos case CTF_K_INTEGER: 1498 1.1 christos case CTF_K_FLOAT: 1499 1.1 christos domain = VAR_DOMAIN; 1500 1.1 christos aclass = LOC_TYPEDEF; 1501 1.1 christos break; 1502 1.1 christos case CTF_K_ARRAY: 1503 1.1 christos case CTF_K_UNKNOWN: 1504 1.1 christos return 0; 1505 1.1 christos } 1506 1.1 christos 1507 1.1.1.2 christos const char *name = ctf_type_name_raw (ccp->fp, tid); 1508 1.1.1.2 christos if (name == nullptr || strlen (name) == 0) 1509 1.1.1.2 christos return 0; 1510 1.1.1.2 christos 1511 1.1.1.2 christos ccp->pst->add_psymbol (name, false, 1512 1.1 christos domain, aclass, section, 1513 1.1.1.2 christos psymbol_placement::STATIC, 1514 1.1.1.3 christos unrelocated_addr (0), 1515 1.1.1.3 christos language_c, ccp->partial_symtabs, ccp->of); 1516 1.1 christos 1517 1.1 christos return 0; 1518 1.1 christos } 1519 1.1 christos 1520 1.1 christos /* Callback to add variable NAME with ID to partial symbol table. */ 1521 1.1 christos 1522 1.1 christos static int 1523 1.1 christos ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg) 1524 1.1 christos { 1525 1.1 christos struct ctf_context *ccp = (struct ctf_context *) arg; 1526 1.1 christos 1527 1.1.1.2 christos ccp->pst->add_psymbol (name, true, 1528 1.1.1.2 christos VAR_DOMAIN, LOC_STATIC, -1, 1529 1.1.1.2 christos psymbol_placement::GLOBAL, 1530 1.1.1.3 christos unrelocated_addr (0), 1531 1.1.1.3 christos language_c, ccp->partial_symtabs, ccp->of); 1532 1.1 christos return 0; 1533 1.1 christos } 1534 1.1 christos 1535 1.1 christos /* Setup partial_symtab's describing each source file for which 1536 1.1 christos debugging information is available. */ 1537 1.1 christos 1538 1.1 christos static void 1539 1.1.1.2 christos scan_partial_symbols (ctf_dict_t *cfp, psymtab_storage *partial_symtabs, 1540 1.1.1.2 christos struct ctf_per_tu_data *tup, const char *fname) 1541 1.1 christos { 1542 1.1.1.2 christos struct objfile *of = tup->of; 1543 1.1.1.2 christos bool isparent = false; 1544 1.1.1.2 christos 1545 1.1.1.2 christos if (strcmp (fname, ".ctf") == 0) 1546 1.1.1.2 christos { 1547 1.1.1.2 christos fname = bfd_get_filename (of->obfd.get ()); 1548 1.1.1.2 christos isparent = true; 1549 1.1.1.2 christos } 1550 1.1 christos 1551 1.1.1.2 christos ctf_psymtab *pst = create_partial_symtab (fname, tup->arc, cfp, 1552 1.1.1.2 christos partial_symtabs, of); 1553 1.1 christos 1554 1.1.1.2 christos struct ctf_context *ccx = &pst->context; 1555 1.1.1.2 christos if (isparent == false) 1556 1.1.1.2 christos ccx->pst = pst; 1557 1.1.1.2 christos 1558 1.1.1.2 christos if (ctf_type_iter (cfp, ctf_psymtab_type_cb, ccx) == CTF_ERR) 1559 1.1 christos complaint (_("ctf_type_iter scan_partial_symbols failed - %s"), 1560 1.1 christos ctf_errmsg (ctf_errno (cfp))); 1561 1.1 christos 1562 1.1.1.2 christos if (ctf_variable_iter (cfp, ctf_psymtab_var_cb, ccx) == CTF_ERR) 1563 1.1 christos complaint (_("ctf_variable_iter scan_partial_symbols failed - %s"), 1564 1.1 christos ctf_errmsg (ctf_errno (cfp))); 1565 1.1 christos 1566 1.1 christos /* Scan CTF object and function sections which correspond to each 1567 1.1 christos STT_FUNC or STT_OBJECT entry in the symbol table, 1568 1.1 christos pick up what init_symtab has done. */ 1569 1.1.1.2 christos ctf_psymtab_add_stt_obj (cfp, pst, of); 1570 1.1.1.2 christos ctf_psymtab_add_stt_func (cfp, pst, of); 1571 1.1 christos 1572 1.1.1.2 christos pst->end (); 1573 1.1.1.2 christos } 1574 1.1.1.2 christos 1575 1.1.1.2 christos /* Callback to build the psymtab for archive member NAME. */ 1576 1.1.1.2 christos 1577 1.1.1.2 christos static int 1578 1.1.1.2 christos build_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg) 1579 1.1.1.2 christos { 1580 1.1.1.2 christos struct ctf_per_tu_data *tup = (struct ctf_per_tu_data *) arg; 1581 1.1.1.2 christos ctf_dict_t *parent = tup->fp; 1582 1.1.1.2 christos 1583 1.1.1.2 christos if (strcmp (name, ".ctf") != 0) 1584 1.1.1.2 christos ctf_import (ctf, parent); 1585 1.1 christos 1586 1.1.1.2 christos if (info_verbose) 1587 1.1.1.2 christos { 1588 1.1.1.2 christos gdb_printf (_("Scanning archive member %s..."), name); 1589 1.1.1.2 christos gdb_flush (gdb_stdout); 1590 1.1 christos } 1591 1.1 christos 1592 1.1.1.2 christos psymtab_storage *pss = tup->psf->get_partial_symtabs ().get (); 1593 1.1.1.2 christos scan_partial_symbols (ctf, pss, tup, name); 1594 1.1.1.2 christos 1595 1.1.1.2 christos return 0; 1596 1.1 christos } 1597 1.1 christos 1598 1.1 christos /* Read CTF debugging information from a BFD section. This is 1599 1.1 christos called from elfread.c. It does a quick pass through the 1600 1.1 christos .ctf section to set up the partial symbol table. */ 1601 1.1 christos 1602 1.1 christos void 1603 1.1 christos elfctf_build_psymtabs (struct objfile *of) 1604 1.1 christos { 1605 1.1.1.2 christos struct ctf_per_tu_data pcu; 1606 1.1.1.2 christos bfd *abfd = of->obfd.get (); 1607 1.1 christos int err; 1608 1.1 christos 1609 1.1 christos ctf_archive_t *arc = ctf_bfdopen (abfd, &err); 1610 1.1.1.2 christos if (arc == nullptr) 1611 1.1 christos error (_("ctf_bfdopen failed on %s - %s"), 1612 1.1 christos bfd_get_filename (abfd), ctf_errmsg (err)); 1613 1.1 christos 1614 1.1.1.2 christos ctf_dict_t *fp = ctf_dict_open (arc, NULL, &err); 1615 1.1.1.2 christos if (fp == nullptr) 1616 1.1.1.2 christos error (_("ctf_dict_open failed on %s - %s"), 1617 1.1 christos bfd_get_filename (abfd), ctf_errmsg (err)); 1618 1.1.1.2 christos ctf_dict_key.emplace (of, fp); 1619 1.1 christos 1620 1.1.1.2 christos pcu.fp = fp; 1621 1.1.1.2 christos pcu.of = of; 1622 1.1.1.2 christos pcu.arc = arc; 1623 1.1.1.2 christos 1624 1.1.1.2 christos psymbol_functions *psf = new psymbol_functions (); 1625 1.1.1.2 christos of->qf.emplace_front (psf); 1626 1.1.1.2 christos pcu.psf = psf; 1627 1.1.1.2 christos 1628 1.1.1.2 christos if (ctf_archive_iter (arc, build_ctf_archive_member, &pcu) < 0) 1629 1.1.1.2 christos error (_("ctf_archive_iter failed in input file %s: - %s"), 1630 1.1.1.2 christos bfd_get_filename (abfd), ctf_errmsg (err)); 1631 1.1 christos } 1632 1.1 christos 1633 1.1 christos #else 1634 1.1 christos 1635 1.1 christos void 1636 1.1 christos elfctf_build_psymtabs (struct objfile *of) 1637 1.1 christos { 1638 1.1 christos /* Nothing to do if CTF is disabled. */ 1639 1.1 christos } 1640 1.1 christos 1641 1.1 christos #endif /* ENABLE_LIBCTF */ 1642