ctfread.c revision 1.1 1 1.1 christos /* Compact ANSI-C Type Format (CTF) support in GDB.
2 1.1 christos
3 1.1 christos Copyright (C) 2019-2020 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 "defs.h"
79 1.1 christos #include "buildsym.h"
80 1.1 christos #include "complaints.h"
81 1.1 christos #include "block.h"
82 1.1 christos #include "ctfread.h"
83 1.1 christos #include "psympriv.h"
84 1.1 christos
85 1.1 christos #if ENABLE_LIBCTF
86 1.1 christos
87 1.1 christos #include "ctf.h"
88 1.1 christos #include "ctf-api.h"
89 1.1 christos
90 1.1 christos static const struct objfile_key<htab, htab_deleter> ctf_tid_key;
91 1.1 christos
92 1.1 christos struct ctf_fp_info
93 1.1 christos {
94 1.1 christos explicit ctf_fp_info (ctf_file_t *cfp) : fp (cfp) {}
95 1.1 christos ~ctf_fp_info ();
96 1.1 christos ctf_file_t *fp;
97 1.1 christos };
98 1.1 christos
99 1.1 christos /* Cleanup function for the ctf_file_key data. */
100 1.1 christos ctf_fp_info::~ctf_fp_info ()
101 1.1 christos {
102 1.1 christos if (!fp)
103 1.1 christos return;
104 1.1 christos
105 1.1 christos ctf_archive_t *arc = ctf_get_arc (fp);
106 1.1 christos ctf_file_close (fp);
107 1.1 christos ctf_close (arc);
108 1.1 christos }
109 1.1 christos
110 1.1 christos static const objfile_key<ctf_fp_info> ctf_file_key;
111 1.1 christos
112 1.1 christos /* A CTF context consists of a file pointer and an objfile pointer. */
113 1.1 christos
114 1.1 christos struct ctf_context
115 1.1 christos {
116 1.1 christos ctf_file_t *fp;
117 1.1 christos struct objfile *of;
118 1.1 christos struct buildsym_compunit *builder;
119 1.1 christos };
120 1.1 christos
121 1.1 christos /* A partial symtab, specialized for this module. */
122 1.1 christos struct ctf_psymtab : public standard_psymtab
123 1.1 christos {
124 1.1 christos ctf_psymtab (const char *filename, struct objfile *objfile, CORE_ADDR addr)
125 1.1 christos : standard_psymtab (filename, objfile, addr)
126 1.1 christos {
127 1.1 christos }
128 1.1 christos
129 1.1 christos void read_symtab (struct objfile *) override;
130 1.1 christos void expand_psymtab (struct objfile *) override;
131 1.1 christos
132 1.1 christos struct ctf_context *context;
133 1.1 christos };
134 1.1 christos
135 1.1 christos /* The routines that read and process fields/members of a C struct, union,
136 1.1 christos or enumeration, pass lists of data member fields in an instance of a
137 1.1 christos ctf_field_info structure. It is derived from dwarf2read.c. */
138 1.1 christos
139 1.1 christos struct ctf_nextfield
140 1.1 christos {
141 1.1 christos struct field field {};
142 1.1 christos };
143 1.1 christos
144 1.1 christos struct ctf_field_info
145 1.1 christos {
146 1.1 christos /* List of data member fields. */
147 1.1 christos std::vector<struct ctf_nextfield> fields;
148 1.1 christos
149 1.1 christos /* Context. */
150 1.1 christos struct ctf_context *cur_context;
151 1.1 christos
152 1.1 christos /* Parent type. */
153 1.1 christos struct type *ptype;
154 1.1 christos
155 1.1 christos /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head
156 1.1 christos of a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
157 1.1 christos std::vector<struct decl_field> typedef_field_list;
158 1.1 christos
159 1.1 christos /* Nested types defined by this struct and the number of elements in
160 1.1 christos this list. */
161 1.1 christos std::vector<struct decl_field> nested_types_list;
162 1.1 christos };
163 1.1 christos
164 1.1 christos
165 1.1 christos /* Local function prototypes */
166 1.1 christos
167 1.1 christos static int ctf_add_type_cb (ctf_id_t tid, void *arg);
168 1.1 christos
169 1.1 christos static struct type *read_array_type (struct ctf_context *cp, ctf_id_t tid);
170 1.1 christos
171 1.1 christos static struct type *read_pointer_type (struct ctf_context *cp, ctf_id_t tid,
172 1.1 christos ctf_id_t btid);
173 1.1 christos
174 1.1 christos static struct type *read_structure_type (struct ctf_context *cp, ctf_id_t tid);
175 1.1 christos
176 1.1 christos static struct type *read_enum_type (struct ctf_context *cp, ctf_id_t tid);
177 1.1 christos
178 1.1 christos static struct type *read_typedef_type (struct ctf_context *cp, ctf_id_t tid,
179 1.1 christos ctf_id_t btid, const char *name);
180 1.1 christos
181 1.1 christos static struct type *read_type_record (struct ctf_context *cp, ctf_id_t tid);
182 1.1 christos
183 1.1 christos static void process_structure_type (struct ctf_context *cp, ctf_id_t tid);
184 1.1 christos
185 1.1 christos static void process_struct_members (struct ctf_context *cp, ctf_id_t tid,
186 1.1 christos struct type *type);
187 1.1 christos
188 1.1 christos static struct symbol *new_symbol (struct ctf_context *cp, struct type *type,
189 1.1 christos ctf_id_t tid);
190 1.1 christos
191 1.1 christos struct ctf_tid_and_type
192 1.1 christos {
193 1.1 christos ctf_id_t tid;
194 1.1 christos struct type *type;
195 1.1 christos };
196 1.1 christos
197 1.1 christos /* Hash function for a ctf_tid_and_type. */
198 1.1 christos
199 1.1 christos static hashval_t
200 1.1 christos tid_and_type_hash (const void *item)
201 1.1 christos {
202 1.1 christos const struct ctf_tid_and_type *ids
203 1.1 christos = (const struct ctf_tid_and_type *) item;
204 1.1 christos
205 1.1 christos return ids->tid;
206 1.1 christos }
207 1.1 christos
208 1.1 christos /* Equality function for a ctf_tid_and_type. */
209 1.1 christos
210 1.1 christos static int
211 1.1 christos tid_and_type_eq (const void *item_lhs, const void *item_rhs)
212 1.1 christos {
213 1.1 christos const struct ctf_tid_and_type *ids_lhs
214 1.1 christos = (const struct ctf_tid_and_type *) item_lhs;
215 1.1 christos const struct ctf_tid_and_type *ids_rhs
216 1.1 christos = (const struct ctf_tid_and_type *) item_rhs;
217 1.1 christos
218 1.1 christos return ids_lhs->tid == ids_rhs->tid;
219 1.1 christos }
220 1.1 christos
221 1.1 christos /* Set the type associated with TID to TYP. */
222 1.1 christos
223 1.1 christos static struct type *
224 1.1 christos set_tid_type (struct objfile *of, ctf_id_t tid, struct type *typ)
225 1.1 christos {
226 1.1 christos htab_t htab;
227 1.1 christos
228 1.1 christos htab = (htab_t) ctf_tid_key.get (of);
229 1.1 christos if (htab == NULL)
230 1.1 christos {
231 1.1 christos htab = htab_create_alloc (1, tid_and_type_hash,
232 1.1 christos tid_and_type_eq,
233 1.1 christos NULL, xcalloc, xfree);
234 1.1 christos ctf_tid_key.set (of, htab);
235 1.1 christos }
236 1.1 christos
237 1.1 christos struct ctf_tid_and_type **slot, ids;
238 1.1 christos ids.tid = tid;
239 1.1 christos ids.type = typ;
240 1.1 christos slot = (struct ctf_tid_and_type **) htab_find_slot (htab, &ids, INSERT);
241 1.1 christos if (*slot)
242 1.1 christos complaint (_("An internal GDB problem: ctf_ id_t %ld type already set"),
243 1.1 christos (tid));
244 1.1 christos *slot = XOBNEW (&of->objfile_obstack, struct ctf_tid_and_type);
245 1.1 christos **slot = ids;
246 1.1 christos return typ;
247 1.1 christos }
248 1.1 christos
249 1.1 christos /* Look up the type for TID in tid_and_type hash, return NULL if hash is
250 1.1 christos empty or TID does not have a saved type. */
251 1.1 christos
252 1.1 christos static struct type *
253 1.1 christos get_tid_type (struct objfile *of, ctf_id_t tid)
254 1.1 christos {
255 1.1 christos struct ctf_tid_and_type *slot, ids;
256 1.1 christos htab_t htab;
257 1.1 christos
258 1.1 christos htab = (htab_t) ctf_tid_key.get (of);
259 1.1 christos if (htab == NULL)
260 1.1 christos return NULL;
261 1.1 christos
262 1.1 christos ids.tid = tid;
263 1.1 christos ids.type = NULL;
264 1.1 christos slot = (struct ctf_tid_and_type *) htab_find (htab, &ids);
265 1.1 christos if (slot)
266 1.1 christos return slot->type;
267 1.1 christos else
268 1.1 christos return NULL;
269 1.1 christos }
270 1.1 christos
271 1.1 christos /* Return the size of storage in bits for INTEGER, FLOAT, or ENUM. */
272 1.1 christos
273 1.1 christos static int
274 1.1 christos get_bitsize (ctf_file_t *fp, ctf_id_t tid, uint32_t kind)
275 1.1 christos {
276 1.1 christos ctf_encoding_t cet;
277 1.1 christos
278 1.1 christos if ((kind == CTF_K_INTEGER || kind == CTF_K_ENUM
279 1.1 christos || kind == CTF_K_FLOAT)
280 1.1 christos && ctf_type_reference (fp, tid) != CTF_ERR
281 1.1 christos && ctf_type_encoding (fp, tid, &cet) != CTF_ERR)
282 1.1 christos return cet.cte_bits;
283 1.1 christos
284 1.1 christos return 0;
285 1.1 christos }
286 1.1 christos
287 1.1 christos /* Set SYM's address, with NAME, from its minimal symbol entry. */
288 1.1 christos
289 1.1 christos static void
290 1.1 christos set_symbol_address (struct objfile *of, struct symbol *sym, const char *name)
291 1.1 christos {
292 1.1 christos struct bound_minimal_symbol msym;
293 1.1 christos
294 1.1 christos msym = lookup_minimal_symbol (name, NULL, of);
295 1.1 christos if (msym.minsym != NULL)
296 1.1 christos {
297 1.1 christos SET_SYMBOL_VALUE_ADDRESS (sym, BMSYMBOL_VALUE_ADDRESS (msym));
298 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
299 1.1 christos SYMBOL_SECTION (sym) = MSYMBOL_SECTION (msym.minsym);
300 1.1 christos }
301 1.1 christos }
302 1.1 christos
303 1.1 christos /* Create the vector of fields, and attach it to TYPE. */
304 1.1 christos
305 1.1 christos static void
306 1.1 christos attach_fields_to_type (struct ctf_field_info *fip, struct type *type)
307 1.1 christos {
308 1.1 christos int nfields = fip->fields.size ();
309 1.1 christos
310 1.1 christos if (nfields == 0)
311 1.1 christos return;
312 1.1 christos
313 1.1 christos /* Record the field count, allocate space for the array of fields. */
314 1.1 christos type->set_num_fields (nfields);
315 1.1 christos type->set_fields
316 1.1 christos ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
317 1.1 christos
318 1.1 christos /* Copy the saved-up fields into the field vector. */
319 1.1 christos for (int i = 0; i < nfields; ++i)
320 1.1 christos {
321 1.1 christos struct ctf_nextfield &field = fip->fields[i];
322 1.1 christos type->field (i) = field.field;
323 1.1 christos }
324 1.1 christos }
325 1.1 christos
326 1.1 christos /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
327 1.1 christos (which may be different from NAME) to the architecture back-end to allow
328 1.1 christos it to guess the correct format if necessary. */
329 1.1 christos
330 1.1 christos static struct type *
331 1.1 christos ctf_init_float_type (struct objfile *objfile,
332 1.1 christos int bits,
333 1.1 christos const char *name,
334 1.1 christos const char *name_hint)
335 1.1 christos {
336 1.1 christos struct gdbarch *gdbarch = objfile->arch ();
337 1.1 christos const struct floatformat **format;
338 1.1 christos struct type *type;
339 1.1 christos
340 1.1 christos format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
341 1.1 christos if (format != NULL)
342 1.1 christos type = init_float_type (objfile, bits, name, format);
343 1.1 christos else
344 1.1 christos type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
345 1.1 christos
346 1.1 christos return type;
347 1.1 christos }
348 1.1 christos
349 1.1 christos /* Callback to add member NAME to a struct/union type. TID is the type
350 1.1 christos of struct/union member, OFFSET is the offset of member in bits,
351 1.1 christos and ARG contains the ctf_field_info. */
352 1.1 christos
353 1.1 christos static int
354 1.1 christos ctf_add_member_cb (const char *name,
355 1.1 christos ctf_id_t tid,
356 1.1 christos unsigned long offset,
357 1.1 christos void *arg)
358 1.1 christos {
359 1.1 christos struct ctf_field_info *fip = (struct ctf_field_info *) arg;
360 1.1 christos struct ctf_context *ccp = fip->cur_context;
361 1.1 christos struct ctf_nextfield new_field;
362 1.1 christos struct field *fp;
363 1.1 christos struct type *t;
364 1.1 christos uint32_t kind;
365 1.1 christos
366 1.1 christos fp = &new_field.field;
367 1.1 christos FIELD_NAME (*fp) = name;
368 1.1 christos
369 1.1 christos kind = ctf_type_kind (ccp->fp, tid);
370 1.1 christos t = get_tid_type (ccp->of, tid);
371 1.1 christos if (t == NULL)
372 1.1 christos {
373 1.1 christos t = read_type_record (ccp, tid);
374 1.1 christos if (t == NULL)
375 1.1 christos {
376 1.1 christos complaint (_("ctf_add_member_cb: %s has NO type (%ld)"), name, tid);
377 1.1 christos t = objfile_type (ccp->of)->builtin_error;
378 1.1 christos set_tid_type (ccp->of, tid, t);
379 1.1 christos }
380 1.1 christos }
381 1.1 christos
382 1.1 christos if (kind == CTF_K_STRUCT || kind == CTF_K_UNION)
383 1.1 christos process_struct_members (ccp, tid, t);
384 1.1 christos
385 1.1 christos fp->set_type (t);
386 1.1 christos SET_FIELD_BITPOS (*fp, offset / TARGET_CHAR_BIT);
387 1.1 christos FIELD_BITSIZE (*fp) = get_bitsize (ccp->fp, tid, kind);
388 1.1 christos
389 1.1 christos fip->fields.emplace_back (new_field);
390 1.1 christos
391 1.1 christos return 0;
392 1.1 christos }
393 1.1 christos
394 1.1 christos /* Callback to add member NAME of EVAL to an enumeration type.
395 1.1 christos ARG contains the ctf_field_info. */
396 1.1 christos
397 1.1 christos static int
398 1.1 christos ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
399 1.1 christos {
400 1.1 christos struct ctf_field_info *fip = (struct ctf_field_info *) arg;
401 1.1 christos struct ctf_nextfield new_field;
402 1.1 christos struct field *fp;
403 1.1 christos struct ctf_context *ccp = fip->cur_context;
404 1.1 christos
405 1.1 christos fp = &new_field.field;
406 1.1 christos FIELD_NAME (*fp) = name;
407 1.1 christos fp->set_type (NULL);
408 1.1 christos SET_FIELD_ENUMVAL (*fp, enum_value);
409 1.1 christos FIELD_BITSIZE (*fp) = 0;
410 1.1 christos
411 1.1 christos if (name != NULL)
412 1.1 christos {
413 1.1 christos struct symbol *sym = new (&ccp->of->objfile_obstack) symbol;
414 1.1 christos OBJSTAT (ccp->of, n_syms++);
415 1.1 christos
416 1.1 christos sym->set_language (language_c, &ccp->of->objfile_obstack);
417 1.1 christos sym->compute_and_set_names (name, false, ccp->of->per_bfd);
418 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
419 1.1 christos SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
420 1.1 christos SYMBOL_TYPE (sym) = fip->ptype;
421 1.1 christos add_symbol_to_list (sym, ccp->builder->get_global_symbols ());
422 1.1 christos }
423 1.1 christos
424 1.1 christos fip->fields.emplace_back (new_field);
425 1.1 christos
426 1.1 christos return 0;
427 1.1 christos }
428 1.1 christos
429 1.1 christos /* Add a new symbol entry, with its name from TID, its access index and
430 1.1 christos domain from TID's kind, and its type from TYPE. */
431 1.1 christos
432 1.1 christos static struct symbol *
433 1.1 christos new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
434 1.1 christos {
435 1.1 christos struct objfile *objfile = ccp->of;
436 1.1 christos ctf_file_t *fp = ccp->fp;
437 1.1 christos struct symbol *sym = NULL;
438 1.1 christos
439 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
440 1.1 christos if (name != NULL)
441 1.1 christos {
442 1.1 christos sym = new (&objfile->objfile_obstack) symbol;
443 1.1 christos OBJSTAT (objfile, n_syms++);
444 1.1 christos
445 1.1 christos sym->set_language (language_c, &objfile->objfile_obstack);
446 1.1 christos sym->compute_and_set_names (name.get (), true, objfile->per_bfd);
447 1.1 christos SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
448 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
449 1.1 christos
450 1.1 christos if (type != NULL)
451 1.1 christos SYMBOL_TYPE (sym) = type;
452 1.1 christos
453 1.1 christos uint32_t kind = ctf_type_kind (fp, tid);
454 1.1 christos switch (kind)
455 1.1 christos {
456 1.1 christos case CTF_K_STRUCT:
457 1.1 christos case CTF_K_UNION:
458 1.1 christos case CTF_K_ENUM:
459 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
460 1.1 christos SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
461 1.1 christos break;
462 1.1 christos case CTF_K_FUNCTION:
463 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
464 1.1 christos break;
465 1.1 christos case CTF_K_CONST:
466 1.1 christos if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_VOID)
467 1.1 christos SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_int;
468 1.1 christos break;
469 1.1 christos case CTF_K_TYPEDEF:
470 1.1 christos case CTF_K_INTEGER:
471 1.1 christos case CTF_K_FLOAT:
472 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
473 1.1 christos SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
474 1.1 christos break;
475 1.1 christos case CTF_K_POINTER:
476 1.1 christos break;
477 1.1 christos case CTF_K_VOLATILE:
478 1.1 christos case CTF_K_RESTRICT:
479 1.1 christos break;
480 1.1 christos case CTF_K_SLICE:
481 1.1 christos case CTF_K_ARRAY:
482 1.1 christos case CTF_K_UNKNOWN:
483 1.1 christos break;
484 1.1 christos }
485 1.1 christos
486 1.1 christos add_symbol_to_list (sym, ccp->builder->get_global_symbols ());
487 1.1 christos }
488 1.1 christos
489 1.1 christos return sym;
490 1.1 christos }
491 1.1 christos
492 1.1 christos /* Given a TID of kind CTF_K_INTEGER or CTF_K_FLOAT, find a representation
493 1.1 christos and create the symbol for it. */
494 1.1 christos
495 1.1 christos static struct type *
496 1.1 christos read_base_type (struct ctf_context *ccp, ctf_id_t tid)
497 1.1 christos {
498 1.1 christos struct objfile *of = ccp->of;
499 1.1 christos ctf_file_t *fp = ccp->fp;
500 1.1 christos ctf_encoding_t cet;
501 1.1 christos struct type *type = NULL;
502 1.1 christos char *name;
503 1.1 christos uint32_t kind;
504 1.1 christos
505 1.1 christos if (ctf_type_encoding (fp, tid, &cet))
506 1.1 christos {
507 1.1 christos complaint (_("ctf_type_encoding read_base_type failed - %s"),
508 1.1 christos ctf_errmsg (ctf_errno (fp)));
509 1.1 christos return NULL;
510 1.1 christos }
511 1.1 christos
512 1.1 christos gdb::unique_xmalloc_ptr<char> copied_name (ctf_type_aname_raw (fp, tid));
513 1.1 christos if (copied_name == NULL || strlen (copied_name.get ()) == 0)
514 1.1 christos {
515 1.1 christos name = ctf_type_aname (fp, tid);
516 1.1 christos if (name == NULL)
517 1.1 christos complaint (_("ctf_type_aname read_base_type failed - %s"),
518 1.1 christos ctf_errmsg (ctf_errno (fp)));
519 1.1 christos }
520 1.1 christos else
521 1.1 christos name = obstack_strdup (&of->objfile_obstack, copied_name.get ());
522 1.1 christos
523 1.1 christos kind = ctf_type_kind (fp, tid);
524 1.1 christos if (kind == CTF_K_INTEGER)
525 1.1 christos {
526 1.1 christos uint32_t issigned, ischar, isbool;
527 1.1 christos struct gdbarch *gdbarch = of->arch ();
528 1.1 christos
529 1.1 christos issigned = cet.cte_format & CTF_INT_SIGNED;
530 1.1 christos ischar = cet.cte_format & CTF_INT_CHAR;
531 1.1 christos isbool = cet.cte_format & CTF_INT_BOOL;
532 1.1 christos if (ischar)
533 1.1 christos type = init_character_type (of, TARGET_CHAR_BIT, !issigned, name);
534 1.1 christos else if (isbool)
535 1.1 christos type = init_boolean_type (of, gdbarch_int_bit (gdbarch),
536 1.1 christos !issigned, name);
537 1.1 christos else
538 1.1 christos {
539 1.1 christos int bits;
540 1.1 christos if (cet.cte_bits && ((cet.cte_bits % TARGET_CHAR_BIT) == 0))
541 1.1 christos bits = cet.cte_bits;
542 1.1 christos else
543 1.1 christos bits = gdbarch_int_bit (gdbarch);
544 1.1 christos type = init_integer_type (of, bits, !issigned, name);
545 1.1 christos }
546 1.1 christos }
547 1.1 christos else if (kind == CTF_K_FLOAT)
548 1.1 christos {
549 1.1 christos uint32_t isflt;
550 1.1 christos isflt = !((cet.cte_format & CTF_FP_IMAGRY) == CTF_FP_IMAGRY
551 1.1 christos || (cet.cte_format & CTF_FP_DIMAGRY) == CTF_FP_DIMAGRY
552 1.1 christos || (cet.cte_format & CTF_FP_LDIMAGRY) == CTF_FP_LDIMAGRY);
553 1.1 christos if (isflt)
554 1.1 christos type = ctf_init_float_type (of, cet.cte_bits, name, name);
555 1.1 christos else
556 1.1 christos {
557 1.1 christos struct type *t
558 1.1 christos = ctf_init_float_type (of, cet.cte_bits / 2, NULL, name);
559 1.1 christos type = init_complex_type (name, t);
560 1.1 christos }
561 1.1 christos }
562 1.1 christos else
563 1.1 christos {
564 1.1 christos complaint (_("read_base_type: unsupported base kind (%d)"), kind);
565 1.1 christos type = init_type (of, TYPE_CODE_ERROR, cet.cte_bits, name);
566 1.1 christos }
567 1.1 christos
568 1.1 christos if (name != NULL && strcmp (name, "char") == 0)
569 1.1 christos TYPE_NOSIGN (type) = 1;
570 1.1 christos
571 1.1 christos return set_tid_type (of, tid, type);
572 1.1 christos }
573 1.1 christos
574 1.1 christos static void
575 1.1 christos process_base_type (struct ctf_context *ccp, ctf_id_t tid)
576 1.1 christos {
577 1.1 christos struct type *type;
578 1.1 christos
579 1.1 christos type = read_base_type (ccp, tid);
580 1.1 christos new_symbol (ccp, type, tid);
581 1.1 christos }
582 1.1 christos
583 1.1 christos /* Start a structure or union scope (definition) with TID to create a type
584 1.1 christos for the structure or union.
585 1.1 christos
586 1.1 christos Fill in the type's name and general properties. The members will not be
587 1.1 christos processed, nor a symbol table entry be done until process_structure_type
588 1.1 christos (assuming the type has a name). */
589 1.1 christos
590 1.1 christos static struct type *
591 1.1 christos read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
592 1.1 christos {
593 1.1 christos struct objfile *of = ccp->of;
594 1.1 christos ctf_file_t *fp = ccp->fp;
595 1.1 christos struct type *type;
596 1.1 christos uint32_t kind;
597 1.1 christos
598 1.1 christos type = alloc_type (of);
599 1.1 christos
600 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
601 1.1 christos if (name != NULL && strlen (name.get() ) != 0)
602 1.1 christos type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
603 1.1 christos
604 1.1 christos kind = ctf_type_kind (fp, tid);
605 1.1 christos if (kind == CTF_K_UNION)
606 1.1 christos type->set_code (TYPE_CODE_UNION);
607 1.1 christos else
608 1.1 christos type->set_code (TYPE_CODE_STRUCT);
609 1.1 christos
610 1.1 christos TYPE_LENGTH (type) = ctf_type_size (fp, tid);
611 1.1 christos set_type_align (type, ctf_type_align (fp, tid));
612 1.1 christos
613 1.1 christos return set_tid_type (ccp->of, tid, type);
614 1.1 christos }
615 1.1 christos
616 1.1 christos /* Given a tid of CTF_K_STRUCT or CTF_K_UNION, process all its members
617 1.1 christos and create the symbol for it. */
618 1.1 christos
619 1.1 christos static void
620 1.1 christos process_struct_members (struct ctf_context *ccp,
621 1.1 christos ctf_id_t tid,
622 1.1 christos struct type *type)
623 1.1 christos {
624 1.1 christos struct ctf_field_info fi;
625 1.1 christos
626 1.1 christos fi.cur_context = ccp;
627 1.1 christos if (ctf_member_iter (ccp->fp, tid, ctf_add_member_cb, &fi) == CTF_ERR)
628 1.1 christos complaint (_("ctf_member_iter process_struct_members failed - %s"),
629 1.1 christos ctf_errmsg (ctf_errno (ccp->fp)));
630 1.1 christos
631 1.1 christos /* Attach fields to the type. */
632 1.1 christos attach_fields_to_type (&fi, type);
633 1.1 christos
634 1.1 christos new_symbol (ccp, type, tid);
635 1.1 christos }
636 1.1 christos
637 1.1 christos static void
638 1.1 christos process_structure_type (struct ctf_context *ccp, ctf_id_t tid)
639 1.1 christos {
640 1.1 christos struct type *type;
641 1.1 christos
642 1.1 christos type = read_structure_type (ccp, tid);
643 1.1 christos process_struct_members (ccp, tid, type);
644 1.1 christos }
645 1.1 christos
646 1.1 christos /* Create a function type for TID and set its return type. */
647 1.1 christos
648 1.1 christos static struct type *
649 1.1 christos read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
650 1.1 christos {
651 1.1 christos struct objfile *of = ccp->of;
652 1.1 christos ctf_file_t *fp = ccp->fp;
653 1.1 christos struct type *type, *rettype;
654 1.1 christos ctf_funcinfo_t cfi;
655 1.1 christos
656 1.1 christos type = alloc_type (of);
657 1.1 christos
658 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
659 1.1 christos if (name != NULL && strlen (name.get ()) != 0)
660 1.1 christos type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
661 1.1 christos
662 1.1 christos type->set_code (TYPE_CODE_FUNC);
663 1.1 christos ctf_func_type_info (fp, tid, &cfi);
664 1.1 christos rettype = get_tid_type (of, cfi.ctc_return);
665 1.1 christos TYPE_TARGET_TYPE (type) = rettype;
666 1.1 christos set_type_align (type, ctf_type_align (fp, tid));
667 1.1 christos
668 1.1 christos return set_tid_type (of, tid, type);
669 1.1 christos }
670 1.1 christos
671 1.1 christos /* Given a TID of CTF_K_ENUM, process all the members of the
672 1.1 christos enumeration, and create the symbol for the enumeration type. */
673 1.1 christos
674 1.1 christos static struct type *
675 1.1 christos read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
676 1.1 christos {
677 1.1 christos struct objfile *of = ccp->of;
678 1.1 christos ctf_file_t *fp = ccp->fp;
679 1.1 christos struct type *type, *target_type;
680 1.1 christos ctf_funcinfo_t fi;
681 1.1 christos
682 1.1 christos type = alloc_type (of);
683 1.1 christos
684 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
685 1.1 christos if (name != NULL && strlen (name.get ()) != 0)
686 1.1 christos type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
687 1.1 christos
688 1.1 christos type->set_code (TYPE_CODE_ENUM);
689 1.1 christos TYPE_LENGTH (type) = ctf_type_size (fp, tid);
690 1.1 christos ctf_func_type_info (fp, tid, &fi);
691 1.1 christos target_type = get_tid_type (of, fi.ctc_return);
692 1.1 christos TYPE_TARGET_TYPE (type) = target_type;
693 1.1 christos set_type_align (type, ctf_type_align (fp, tid));
694 1.1 christos
695 1.1 christos return set_tid_type (of, tid, type);
696 1.1 christos }
697 1.1 christos
698 1.1 christos static void
699 1.1 christos process_enum_type (struct ctf_context *ccp, ctf_id_t tid)
700 1.1 christos {
701 1.1 christos struct type *type;
702 1.1 christos struct ctf_field_info fi;
703 1.1 christos
704 1.1 christos type = read_enum_type (ccp, tid);
705 1.1 christos
706 1.1 christos fi.cur_context = ccp;
707 1.1 christos fi.ptype = type;
708 1.1 christos if (ctf_enum_iter (ccp->fp, tid, ctf_add_enum_member_cb, &fi) == CTF_ERR)
709 1.1 christos complaint (_("ctf_enum_iter process_enum_type failed - %s"),
710 1.1 christos ctf_errmsg (ctf_errno (ccp->fp)));
711 1.1 christos
712 1.1 christos /* Attach fields to the type. */
713 1.1 christos attach_fields_to_type (&fi, type);
714 1.1 christos
715 1.1 christos new_symbol (ccp, type, tid);
716 1.1 christos }
717 1.1 christos
718 1.1 christos /* Add given cv-qualifiers CNST+VOLTL to the BASE_TYPE of array TID. */
719 1.1 christos
720 1.1 christos static struct type *
721 1.1 christos add_array_cv_type (struct ctf_context *ccp,
722 1.1 christos ctf_id_t tid,
723 1.1 christos struct type *base_type,
724 1.1 christos int cnst,
725 1.1 christos int voltl)
726 1.1 christos {
727 1.1 christos struct type *el_type, *inner_array;
728 1.1 christos
729 1.1 christos base_type = copy_type (base_type);
730 1.1 christos inner_array = base_type;
731 1.1 christos
732 1.1 christos while (TYPE_TARGET_TYPE (inner_array)->code () == TYPE_CODE_ARRAY)
733 1.1 christos {
734 1.1 christos TYPE_TARGET_TYPE (inner_array)
735 1.1 christos = copy_type (TYPE_TARGET_TYPE (inner_array));
736 1.1 christos inner_array = TYPE_TARGET_TYPE (inner_array);
737 1.1 christos }
738 1.1 christos
739 1.1 christos el_type = TYPE_TARGET_TYPE (inner_array);
740 1.1 christos cnst |= TYPE_CONST (el_type);
741 1.1 christos voltl |= TYPE_VOLATILE (el_type);
742 1.1 christos TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL);
743 1.1 christos
744 1.1 christos return set_tid_type (ccp->of, tid, base_type);
745 1.1 christos }
746 1.1 christos
747 1.1 christos /* Read all information from a TID of CTF_K_ARRAY. */
748 1.1 christos
749 1.1 christos static struct type *
750 1.1 christos read_array_type (struct ctf_context *ccp, ctf_id_t tid)
751 1.1 christos {
752 1.1 christos struct objfile *objfile = ccp->of;
753 1.1 christos ctf_file_t *fp = ccp->fp;
754 1.1 christos struct type *element_type, *range_type, *idx_type;
755 1.1 christos struct type *type;
756 1.1 christos ctf_arinfo_t ar;
757 1.1 christos
758 1.1 christos if (ctf_array_info (fp, tid, &ar) == CTF_ERR)
759 1.1 christos {
760 1.1 christos complaint (_("ctf_array_info read_array_type failed - %s"),
761 1.1 christos ctf_errmsg (ctf_errno (fp)));
762 1.1 christos return NULL;
763 1.1 christos }
764 1.1 christos
765 1.1 christos element_type = get_tid_type (objfile, ar.ctr_contents);
766 1.1 christos if (element_type == NULL)
767 1.1 christos return NULL;
768 1.1 christos
769 1.1 christos idx_type = get_tid_type (objfile, ar.ctr_index);
770 1.1 christos if (idx_type == NULL)
771 1.1 christos idx_type = objfile_type (objfile)->builtin_int;
772 1.1 christos
773 1.1 christos range_type = create_static_range_type (NULL, idx_type, 0, ar.ctr_nelems - 1);
774 1.1 christos type = create_array_type (NULL, element_type, range_type);
775 1.1 christos if (ar.ctr_nelems <= 1) /* Check if undefined upper bound. */
776 1.1 christos {
777 1.1 christos range_type->bounds ()->high.set_undefined ();
778 1.1 christos TYPE_LENGTH (type) = 0;
779 1.1 christos TYPE_TARGET_STUB (type) = 1;
780 1.1 christos }
781 1.1 christos else
782 1.1 christos TYPE_LENGTH (type) = ctf_type_size (fp, tid);
783 1.1 christos
784 1.1 christos set_type_align (type, ctf_type_align (fp, tid));
785 1.1 christos
786 1.1 christos return set_tid_type (objfile, tid, type);
787 1.1 christos }
788 1.1 christos
789 1.1 christos /* Read TID of kind CTF_K_CONST with base type BTID. */
790 1.1 christos
791 1.1 christos static struct type *
792 1.1 christos read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
793 1.1 christos {
794 1.1 christos struct objfile *objfile = ccp->of;
795 1.1 christos struct type *base_type, *cv_type;
796 1.1 christos
797 1.1 christos base_type = get_tid_type (objfile, btid);
798 1.1 christos if (base_type == NULL)
799 1.1 christos {
800 1.1 christos base_type = read_type_record (ccp, btid);
801 1.1 christos if (base_type == NULL)
802 1.1 christos {
803 1.1 christos complaint (_("read_const_type: NULL base type (%ld)"), btid);
804 1.1 christos base_type = objfile_type (objfile)->builtin_error;
805 1.1 christos }
806 1.1 christos }
807 1.1 christos cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
808 1.1 christos
809 1.1 christos return set_tid_type (objfile, tid, cv_type);
810 1.1 christos }
811 1.1 christos
812 1.1 christos /* Read TID of kind CTF_K_VOLATILE with base type BTID. */
813 1.1 christos
814 1.1 christos static struct type *
815 1.1 christos read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
816 1.1 christos {
817 1.1 christos struct objfile *objfile = ccp->of;
818 1.1 christos ctf_file_t *fp = ccp->fp;
819 1.1 christos struct type *base_type, *cv_type;
820 1.1 christos
821 1.1 christos base_type = get_tid_type (objfile, btid);
822 1.1 christos if (base_type == NULL)
823 1.1 christos {
824 1.1 christos base_type = read_type_record (ccp, btid);
825 1.1 christos if (base_type == NULL)
826 1.1 christos {
827 1.1 christos complaint (_("read_volatile_type: NULL base type (%ld)"), btid);
828 1.1 christos base_type = objfile_type (objfile)->builtin_error;
829 1.1 christos }
830 1.1 christos }
831 1.1 christos
832 1.1 christos if (ctf_type_kind (fp, btid) == CTF_K_ARRAY)
833 1.1 christos return add_array_cv_type (ccp, tid, base_type, 0, 1);
834 1.1 christos cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
835 1.1 christos
836 1.1 christos return set_tid_type (objfile, tid, cv_type);
837 1.1 christos }
838 1.1 christos
839 1.1 christos /* Read TID of kind CTF_K_RESTRICT with base type BTID. */
840 1.1 christos
841 1.1 christos static struct type *
842 1.1 christos read_restrict_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
843 1.1 christos {
844 1.1 christos struct objfile *objfile = ccp->of;
845 1.1 christos struct type *base_type, *cv_type;
846 1.1 christos
847 1.1 christos base_type = get_tid_type (objfile, btid);
848 1.1 christos if (base_type == NULL)
849 1.1 christos {
850 1.1 christos base_type = read_type_record (ccp, btid);
851 1.1 christos if (base_type == NULL)
852 1.1 christos {
853 1.1 christos complaint (_("read_restrict_type: NULL base type (%ld)"), btid);
854 1.1 christos base_type = objfile_type (objfile)->builtin_error;
855 1.1 christos }
856 1.1 christos }
857 1.1 christos cv_type = make_restrict_type (base_type);
858 1.1 christos
859 1.1 christos return set_tid_type (objfile, tid, cv_type);
860 1.1 christos }
861 1.1 christos
862 1.1 christos /* Read TID of kind CTF_K_TYPEDEF with its NAME and base type BTID. */
863 1.1 christos
864 1.1 christos static struct type *
865 1.1 christos read_typedef_type (struct ctf_context *ccp, ctf_id_t tid,
866 1.1 christos ctf_id_t btid, const char *name)
867 1.1 christos {
868 1.1 christos struct objfile *objfile = ccp->of;
869 1.1 christos struct type *this_type, *target_type;
870 1.1 christos
871 1.1 christos char *aname = obstack_strdup (&objfile->objfile_obstack, name);
872 1.1 christos this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, aname);
873 1.1 christos set_tid_type (objfile, tid, this_type);
874 1.1 christos target_type = get_tid_type (objfile, btid);
875 1.1 christos if (target_type != this_type)
876 1.1 christos TYPE_TARGET_TYPE (this_type) = target_type;
877 1.1 christos else
878 1.1 christos TYPE_TARGET_TYPE (this_type) = NULL;
879 1.1 christos TYPE_TARGET_STUB (this_type) = TYPE_TARGET_TYPE (this_type) ? 1 : 0;
880 1.1 christos
881 1.1 christos return set_tid_type (objfile, tid, this_type);
882 1.1 christos }
883 1.1 christos
884 1.1 christos /* Read TID of kind CTF_K_POINTER with base type BTID. */
885 1.1 christos
886 1.1 christos static struct type *
887 1.1 christos read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
888 1.1 christos {
889 1.1 christos struct objfile *of = ccp->of;
890 1.1 christos struct type *target_type, *type;
891 1.1 christos
892 1.1 christos target_type = get_tid_type (of, btid);
893 1.1 christos if (target_type == NULL)
894 1.1 christos {
895 1.1 christos target_type = read_type_record (ccp, btid);
896 1.1 christos if (target_type == NULL)
897 1.1 christos {
898 1.1 christos complaint (_("read_pointer_type: NULL target type (%ld)"), btid);
899 1.1 christos target_type = objfile_type (ccp->of)->builtin_error;
900 1.1 christos }
901 1.1 christos }
902 1.1 christos
903 1.1 christos type = lookup_pointer_type (target_type);
904 1.1 christos set_type_align (type, ctf_type_align (ccp->fp, tid));
905 1.1 christos
906 1.1 christos return set_tid_type (of, tid, type);
907 1.1 christos }
908 1.1 christos
909 1.1 christos /* Read information associated with type TID. */
910 1.1 christos
911 1.1 christos static struct type *
912 1.1 christos read_type_record (struct ctf_context *ccp, ctf_id_t tid)
913 1.1 christos {
914 1.1 christos ctf_file_t *fp = ccp->fp;
915 1.1 christos uint32_t kind;
916 1.1 christos struct type *type = NULL;
917 1.1 christos ctf_id_t btid;
918 1.1 christos
919 1.1 christos kind = ctf_type_kind (fp, tid);
920 1.1 christos switch (kind)
921 1.1 christos {
922 1.1 christos case CTF_K_STRUCT:
923 1.1 christos case CTF_K_UNION:
924 1.1 christos type = read_structure_type (ccp, tid);
925 1.1 christos break;
926 1.1 christos case CTF_K_ENUM:
927 1.1 christos type = read_enum_type (ccp, tid);
928 1.1 christos break;
929 1.1 christos case CTF_K_FUNCTION:
930 1.1 christos type = read_func_kind_type (ccp, tid);
931 1.1 christos break;
932 1.1 christos case CTF_K_CONST:
933 1.1 christos btid = ctf_type_reference (fp, tid);
934 1.1 christos type = read_const_type (ccp, tid, btid);
935 1.1 christos break;
936 1.1 christos case CTF_K_TYPEDEF:
937 1.1 christos {
938 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
939 1.1 christos btid = ctf_type_reference (fp, tid);
940 1.1 christos type = read_typedef_type (ccp, tid, btid, name.get ());
941 1.1 christos }
942 1.1 christos break;
943 1.1 christos case CTF_K_VOLATILE:
944 1.1 christos btid = ctf_type_reference (fp, tid);
945 1.1 christos type = read_volatile_type (ccp, tid, btid);
946 1.1 christos break;
947 1.1 christos case CTF_K_RESTRICT:
948 1.1 christos btid = ctf_type_reference (fp, tid);
949 1.1 christos type = read_restrict_type (ccp, tid, btid);
950 1.1 christos break;
951 1.1 christos case CTF_K_POINTER:
952 1.1 christos btid = ctf_type_reference (fp, tid);
953 1.1 christos type = read_pointer_type (ccp, tid, btid);
954 1.1 christos break;
955 1.1 christos case CTF_K_INTEGER:
956 1.1 christos case CTF_K_FLOAT:
957 1.1 christos type = read_base_type (ccp, tid);
958 1.1 christos break;
959 1.1 christos case CTF_K_ARRAY:
960 1.1 christos type = read_array_type (ccp, tid);
961 1.1 christos break;
962 1.1 christos case CTF_K_UNKNOWN:
963 1.1 christos break;
964 1.1 christos default:
965 1.1 christos break;
966 1.1 christos }
967 1.1 christos
968 1.1 christos return type;
969 1.1 christos }
970 1.1 christos
971 1.1 christos /* Callback to add type TID to the symbol table. */
972 1.1 christos
973 1.1 christos static int
974 1.1 christos ctf_add_type_cb (ctf_id_t tid, void *arg)
975 1.1 christos {
976 1.1 christos struct ctf_context *ccp = (struct ctf_context *) arg;
977 1.1 christos struct type *type;
978 1.1 christos uint32_t kind;
979 1.1 christos
980 1.1 christos /* Check if tid's type has already been defined. */
981 1.1 christos type = get_tid_type (ccp->of, tid);
982 1.1 christos if (type != NULL)
983 1.1 christos return 0;
984 1.1 christos
985 1.1 christos ctf_id_t btid = ctf_type_reference (ccp->fp, tid);
986 1.1 christos kind = ctf_type_kind (ccp->fp, tid);
987 1.1 christos switch (kind)
988 1.1 christos {
989 1.1 christos case CTF_K_STRUCT:
990 1.1 christos case CTF_K_UNION:
991 1.1 christos process_structure_type (ccp, tid);
992 1.1 christos break;
993 1.1 christos case CTF_K_ENUM:
994 1.1 christos process_enum_type (ccp, tid);
995 1.1 christos break;
996 1.1 christos case CTF_K_FUNCTION:
997 1.1 christos type = read_func_kind_type (ccp, tid);
998 1.1 christos new_symbol (ccp, type, tid);
999 1.1 christos break;
1000 1.1 christos case CTF_K_INTEGER:
1001 1.1 christos case CTF_K_FLOAT:
1002 1.1 christos process_base_type (ccp, tid);
1003 1.1 christos break;
1004 1.1 christos case CTF_K_TYPEDEF:
1005 1.1 christos new_symbol (ccp, read_type_record (ccp, tid), tid);
1006 1.1 christos break;
1007 1.1 christos case CTF_K_CONST:
1008 1.1 christos type = read_const_type (ccp, tid, btid);
1009 1.1 christos new_symbol (ccp, type, tid);
1010 1.1 christos break;
1011 1.1 christos case CTF_K_VOLATILE:
1012 1.1 christos type = read_volatile_type (ccp, tid, btid);
1013 1.1 christos new_symbol (ccp, type, tid);
1014 1.1 christos break;
1015 1.1 christos case CTF_K_RESTRICT:
1016 1.1 christos type = read_restrict_type (ccp, tid, btid);
1017 1.1 christos new_symbol (ccp, type, tid);
1018 1.1 christos break;
1019 1.1 christos case CTF_K_POINTER:
1020 1.1 christos type = read_pointer_type (ccp, tid, btid);
1021 1.1 christos new_symbol (ccp, type, tid);
1022 1.1 christos break;
1023 1.1 christos case CTF_K_ARRAY:
1024 1.1 christos type = read_array_type (ccp, tid);
1025 1.1 christos new_symbol (ccp, type, tid);
1026 1.1 christos break;
1027 1.1 christos case CTF_K_UNKNOWN:
1028 1.1 christos break;
1029 1.1 christos default:
1030 1.1 christos break;
1031 1.1 christos }
1032 1.1 christos
1033 1.1 christos return 0;
1034 1.1 christos }
1035 1.1 christos
1036 1.1 christos /* Callback to add variable NAME with TID to the symbol table. */
1037 1.1 christos
1038 1.1 christos static int
1039 1.1 christos ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
1040 1.1 christos {
1041 1.1 christos struct ctf_context *ccp = (struct ctf_context *) arg;
1042 1.1 christos struct symbol *sym = NULL;
1043 1.1 christos struct type *type;
1044 1.1 christos uint32_t kind;
1045 1.1 christos
1046 1.1 christos type = get_tid_type (ccp->of, id);
1047 1.1 christos
1048 1.1 christos kind = ctf_type_kind (ccp->fp, id);
1049 1.1 christos switch (kind)
1050 1.1 christos {
1051 1.1 christos case CTF_K_FUNCTION:
1052 1.1 christos if (name && !strcmp(name, "main"))
1053 1.1 christos set_objfile_main_name (ccp->of, name, language_c);
1054 1.1 christos break;
1055 1.1 christos case CTF_K_INTEGER:
1056 1.1 christos case CTF_K_FLOAT:
1057 1.1 christos case CTF_K_VOLATILE:
1058 1.1 christos case CTF_K_RESTRICT:
1059 1.1 christos case CTF_K_TYPEDEF:
1060 1.1 christos case CTF_K_CONST:
1061 1.1 christos case CTF_K_POINTER:
1062 1.1 christos case CTF_K_ARRAY:
1063 1.1 christos if (type)
1064 1.1 christos {
1065 1.1 christos sym = new_symbol (ccp, type, id);
1066 1.1 christos sym->compute_and_set_names (name, false, ccp->of->per_bfd);
1067 1.1 christos }
1068 1.1 christos break;
1069 1.1 christos case CTF_K_STRUCT:
1070 1.1 christos case CTF_K_UNION:
1071 1.1 christos case CTF_K_ENUM:
1072 1.1 christos if (type == NULL)
1073 1.1 christos {
1074 1.1 christos complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id);
1075 1.1 christos type = objfile_type (ccp->of)->builtin_error;
1076 1.1 christos }
1077 1.1 christos sym = new (&ccp->of->objfile_obstack) symbol;
1078 1.1 christos OBJSTAT (ccp->of, n_syms++);
1079 1.1 christos SYMBOL_TYPE (sym) = type;
1080 1.1 christos SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1081 1.1 christos SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
1082 1.1 christos sym->compute_and_set_names (name, false, ccp->of->per_bfd);
1083 1.1 christos add_symbol_to_list (sym, ccp->builder->get_global_symbols ());
1084 1.1 christos break;
1085 1.1 christos default:
1086 1.1 christos complaint (_("ctf_add_var_cb: kind unsupported (%d)"), kind);
1087 1.1 christos break;
1088 1.1 christos }
1089 1.1 christos
1090 1.1 christos if (sym)
1091 1.1 christos set_symbol_address (ccp->of, sym, name);
1092 1.1 christos
1093 1.1 christos return 0;
1094 1.1 christos }
1095 1.1 christos
1096 1.1 christos /* Add an ELF STT_OBJ symbol with index IDX to the symbol table. */
1097 1.1 christos
1098 1.1 christos static struct symbol *
1099 1.1 christos add_stt_obj (struct ctf_context *ccp, unsigned long idx)
1100 1.1 christos {
1101 1.1 christos struct symbol *sym;
1102 1.1 christos struct type *type;
1103 1.1 christos ctf_id_t tid;
1104 1.1 christos
1105 1.1 christos if ((tid = ctf_lookup_by_symbol (ccp->fp, idx)) == CTF_ERR)
1106 1.1 christos return NULL;
1107 1.1 christos
1108 1.1 christos type = get_tid_type (ccp->of, tid);
1109 1.1 christos if (type == NULL)
1110 1.1 christos return NULL;
1111 1.1 christos
1112 1.1 christos sym = new_symbol (ccp, type, tid);
1113 1.1 christos
1114 1.1 christos return sym;
1115 1.1 christos }
1116 1.1 christos
1117 1.1 christos /* Add an ELF STT_FUNC symbol with index IDX to the symbol table. */
1118 1.1 christos
1119 1.1 christos static struct symbol *
1120 1.1 christos add_stt_func (struct ctf_context *ccp, unsigned long idx)
1121 1.1 christos {
1122 1.1 christos struct type *ftype, *atyp, *rettyp;
1123 1.1 christos struct symbol *sym;
1124 1.1 christos ctf_funcinfo_t finfo;
1125 1.1 christos ctf_id_t argv[32];
1126 1.1 christos uint32_t argc;
1127 1.1 christos ctf_id_t tid;
1128 1.1 christos struct type *void_type = objfile_type (ccp->of)->builtin_void;
1129 1.1 christos
1130 1.1 christos if (ctf_func_info (ccp->fp, idx, &finfo) == CTF_ERR)
1131 1.1 christos return NULL;
1132 1.1 christos
1133 1.1 christos argc = finfo.ctc_argc;
1134 1.1 christos if (ctf_func_args (ccp->fp, idx, argc, argv) == CTF_ERR)
1135 1.1 christos return NULL;
1136 1.1 christos
1137 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (ccp->fp, idx));
1138 1.1 christos if (name == NULL)
1139 1.1 christos return NULL;
1140 1.1 christos
1141 1.1 christos tid = ctf_lookup_by_symbol (ccp->fp, idx);
1142 1.1 christos ftype = get_tid_type (ccp->of, tid);
1143 1.1 christos if (finfo.ctc_flags & CTF_FUNC_VARARG)
1144 1.1 christos TYPE_VARARGS (ftype) = 1;
1145 1.1 christos ftype->set_num_fields (argc);
1146 1.1 christos
1147 1.1 christos /* If argc is 0, it has a "void" type. */
1148 1.1 christos if (argc != 0)
1149 1.1 christos ftype->set_fields
1150 1.1 christos ((struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field)));
1151 1.1 christos
1152 1.1 christos /* TYPE_FIELD_TYPE must never be NULL. Fill it with void_type, if failed
1153 1.1 christos to find the argument type. */
1154 1.1 christos for (int iparam = 0; iparam < argc; iparam++)
1155 1.1 christos {
1156 1.1 christos atyp = get_tid_type (ccp->of, argv[iparam]);
1157 1.1 christos if (atyp)
1158 1.1 christos ftype->field (iparam).set_type (atyp);
1159 1.1 christos else
1160 1.1 christos ftype->field (iparam).set_type (void_type);
1161 1.1 christos }
1162 1.1 christos
1163 1.1 christos sym = new_symbol (ccp, ftype, tid);
1164 1.1 christos rettyp = get_tid_type (ccp->of, finfo.ctc_return);
1165 1.1 christos if (rettyp != NULL)
1166 1.1 christos SYMBOL_TYPE (sym) = rettyp;
1167 1.1 christos else
1168 1.1 christos SYMBOL_TYPE (sym) = void_type;
1169 1.1 christos
1170 1.1 christos return sym;
1171 1.1 christos }
1172 1.1 christos
1173 1.1 christos /* Get text segment base for OBJFILE, TSIZE contains the segment size. */
1174 1.1 christos
1175 1.1 christos static CORE_ADDR
1176 1.1 christos get_objfile_text_range (struct objfile *of, int *tsize)
1177 1.1 christos {
1178 1.1 christos bfd *abfd = of->obfd;
1179 1.1 christos const asection *codes;
1180 1.1 christos
1181 1.1 christos codes = bfd_get_section_by_name (abfd, ".text");
1182 1.1 christos *tsize = codes ? bfd_section_size (codes) : 0;
1183 1.1 christos return of->text_section_offset ();
1184 1.1 christos }
1185 1.1 christos
1186 1.1 christos /* Start a symtab for OBJFILE in CTF format. */
1187 1.1 christos
1188 1.1 christos static void
1189 1.1 christos ctf_start_symtab (ctf_psymtab *pst,
1190 1.1 christos struct objfile *of, CORE_ADDR text_offset)
1191 1.1 christos {
1192 1.1 christos struct ctf_context *ccp;
1193 1.1 christos
1194 1.1 christos ccp = pst->context;
1195 1.1 christos ccp->builder = new buildsym_compunit
1196 1.1 christos (of, of->original_name, NULL,
1197 1.1 christos language_c, text_offset);
1198 1.1 christos ccp->builder->record_debugformat ("ctf");
1199 1.1 christos }
1200 1.1 christos
1201 1.1 christos /* Finish reading symbol/type definitions in CTF format.
1202 1.1 christos END_ADDR is the end address of the file's text. SECTION is
1203 1.1 christos the .text section number. */
1204 1.1 christos
1205 1.1 christos static struct compunit_symtab *
1206 1.1 christos ctf_end_symtab (ctf_psymtab *pst,
1207 1.1 christos CORE_ADDR end_addr, int section)
1208 1.1 christos {
1209 1.1 christos struct ctf_context *ccp;
1210 1.1 christos
1211 1.1 christos ccp = pst->context;
1212 1.1 christos struct compunit_symtab *result
1213 1.1 christos = ccp->builder->end_symtab (end_addr, section);
1214 1.1 christos delete ccp->builder;
1215 1.1 christos ccp->builder = NULL;
1216 1.1 christos return result;
1217 1.1 christos }
1218 1.1 christos
1219 1.1 christos /* Read in full symbols for PST, and anything it depends on. */
1220 1.1 christos
1221 1.1 christos void
1222 1.1 christos ctf_psymtab::expand_psymtab (struct objfile *objfile)
1223 1.1 christos {
1224 1.1 christos struct symbol *sym;
1225 1.1 christos struct ctf_context *ccp;
1226 1.1 christos
1227 1.1 christos gdb_assert (!readin);
1228 1.1 christos
1229 1.1 christos ccp = context;
1230 1.1 christos
1231 1.1 christos /* Iterate over entries in data types section. */
1232 1.1 christos if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR)
1233 1.1 christos complaint (_("ctf_type_iter psymtab_to_symtab failed - %s"),
1234 1.1 christos ctf_errmsg (ctf_errno (ccp->fp)));
1235 1.1 christos
1236 1.1 christos
1237 1.1 christos /* Iterate over entries in variable info section. */
1238 1.1 christos if (ctf_variable_iter (ccp->fp, ctf_add_var_cb, ccp) == CTF_ERR)
1239 1.1 christos complaint (_("ctf_variable_iter psymtab_to_symtab failed - %s"),
1240 1.1 christos ctf_errmsg (ctf_errno (ccp->fp)));
1241 1.1 christos
1242 1.1 christos /* Add entries in data objects and function info sections. */
1243 1.1 christos for (unsigned long i = 0; ; i++)
1244 1.1 christos {
1245 1.1 christos sym = add_stt_obj (ccp, i);
1246 1.1 christos if (sym == NULL)
1247 1.1 christos {
1248 1.1 christos if (ctf_errno (ccp->fp) == EINVAL
1249 1.1 christos || ctf_errno (ccp->fp) == ECTF_NOSYMTAB)
1250 1.1 christos break;
1251 1.1 christos sym = add_stt_func (ccp, i);
1252 1.1 christos }
1253 1.1 christos if (sym == NULL)
1254 1.1 christos continue;
1255 1.1 christos
1256 1.1 christos set_symbol_address (ccp->of, sym, sym->linkage_name ());
1257 1.1 christos }
1258 1.1 christos
1259 1.1 christos readin = true;
1260 1.1 christos }
1261 1.1 christos
1262 1.1 christos /* Expand partial symbol table PST into a full symbol table.
1263 1.1 christos PST is not NULL. */
1264 1.1 christos
1265 1.1 christos void
1266 1.1 christos ctf_psymtab::read_symtab (struct objfile *objfile)
1267 1.1 christos {
1268 1.1 christos if (readin)
1269 1.1 christos warning (_("bug: psymtab for %s is already read in."), filename);
1270 1.1 christos else
1271 1.1 christos {
1272 1.1 christos if (info_verbose)
1273 1.1 christos {
1274 1.1 christos printf_filtered (_("Reading in CTF data for %s..."), filename);
1275 1.1 christos gdb_flush (gdb_stdout);
1276 1.1 christos }
1277 1.1 christos
1278 1.1 christos /* Start a symtab. */
1279 1.1 christos CORE_ADDR offset; /* Start of text segment. */
1280 1.1 christos int tsize;
1281 1.1 christos
1282 1.1 christos offset = get_objfile_text_range (objfile, &tsize);
1283 1.1 christos ctf_start_symtab (this, objfile, offset);
1284 1.1 christos expand_psymtab (objfile);
1285 1.1 christos
1286 1.1 christos set_text_low (offset);
1287 1.1 christos set_text_high (offset + tsize);
1288 1.1 christos compunit_symtab = ctf_end_symtab (this, offset + tsize,
1289 1.1 christos SECT_OFF_TEXT (objfile));
1290 1.1 christos
1291 1.1 christos /* Finish up the debug error message. */
1292 1.1 christos if (info_verbose)
1293 1.1 christos printf_filtered (_("done.\n"));
1294 1.1 christos }
1295 1.1 christos }
1296 1.1 christos
1297 1.1 christos /* Allocate a new partial_symtab NAME.
1298 1.1 christos
1299 1.1 christos Each source file that has not been fully read in is represented by
1300 1.1 christos a partial_symtab. This contains the information on where in the
1301 1.1 christos executable the debugging symbols for a specific file are, and a
1302 1.1 christos list of names of global symbols which are located in this file.
1303 1.1 christos They are all chained on partial symtab lists.
1304 1.1 christos
1305 1.1 christos Even after the source file has been read into a symtab, the
1306 1.1 christos partial_symtab remains around. They are allocated on an obstack,
1307 1.1 christos objfile_obstack. */
1308 1.1 christos
1309 1.1 christos static ctf_psymtab *
1310 1.1 christos create_partial_symtab (const char *name,
1311 1.1 christos ctf_file_t *cfp,
1312 1.1 christos struct objfile *objfile)
1313 1.1 christos {
1314 1.1 christos ctf_psymtab *pst;
1315 1.1 christos struct ctf_context *ccx;
1316 1.1 christos
1317 1.1 christos pst = new ctf_psymtab (name, objfile, 0);
1318 1.1 christos
1319 1.1 christos ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context);
1320 1.1 christos ccx->fp = cfp;
1321 1.1 christos ccx->of = objfile;
1322 1.1 christos pst->context = ccx;
1323 1.1 christos
1324 1.1 christos return pst;
1325 1.1 christos }
1326 1.1 christos
1327 1.1 christos /* Callback to add type TID to partial symbol table. */
1328 1.1 christos
1329 1.1 christos static int
1330 1.1 christos ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
1331 1.1 christos {
1332 1.1 christos struct ctf_context *ccp;
1333 1.1 christos uint32_t kind;
1334 1.1 christos short section = -1;
1335 1.1 christos
1336 1.1 christos ccp = (struct ctf_context *) arg;
1337 1.1 christos gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (ccp->fp, tid));
1338 1.1 christos if (name == NULL || strlen (name.get ()) == 0)
1339 1.1 christos return 0;
1340 1.1 christos
1341 1.1 christos domain_enum domain = UNDEF_DOMAIN;
1342 1.1 christos enum address_class aclass = LOC_UNDEF;
1343 1.1 christos kind = ctf_type_kind (ccp->fp, tid);
1344 1.1 christos switch (kind)
1345 1.1 christos {
1346 1.1 christos case CTF_K_STRUCT:
1347 1.1 christos case CTF_K_UNION:
1348 1.1 christos case CTF_K_ENUM:
1349 1.1 christos domain = STRUCT_DOMAIN;
1350 1.1 christos aclass = LOC_TYPEDEF;
1351 1.1 christos break;
1352 1.1 christos case CTF_K_FUNCTION:
1353 1.1 christos case CTF_K_FORWARD:
1354 1.1 christos domain = VAR_DOMAIN;
1355 1.1 christos aclass = LOC_STATIC;
1356 1.1 christos section = SECT_OFF_TEXT (ccp->of);
1357 1.1 christos break;
1358 1.1 christos case CTF_K_CONST:
1359 1.1 christos domain = VAR_DOMAIN;
1360 1.1 christos aclass = LOC_STATIC;
1361 1.1 christos break;
1362 1.1 christos case CTF_K_TYPEDEF:
1363 1.1 christos case CTF_K_POINTER:
1364 1.1 christos case CTF_K_VOLATILE:
1365 1.1 christos case CTF_K_RESTRICT:
1366 1.1 christos domain = VAR_DOMAIN;
1367 1.1 christos aclass = LOC_TYPEDEF;
1368 1.1 christos break;
1369 1.1 christos case CTF_K_INTEGER:
1370 1.1 christos case CTF_K_FLOAT:
1371 1.1 christos domain = VAR_DOMAIN;
1372 1.1 christos aclass = LOC_TYPEDEF;
1373 1.1 christos break;
1374 1.1 christos case CTF_K_ARRAY:
1375 1.1 christos case CTF_K_UNKNOWN:
1376 1.1 christos return 0;
1377 1.1 christos }
1378 1.1 christos
1379 1.1 christos add_psymbol_to_list (name.get (), true,
1380 1.1 christos domain, aclass, section,
1381 1.1 christos psymbol_placement::GLOBAL,
1382 1.1 christos 0, language_c, ccp->of);
1383 1.1 christos
1384 1.1 christos return 0;
1385 1.1 christos }
1386 1.1 christos
1387 1.1 christos /* Callback to add variable NAME with ID to partial symbol table. */
1388 1.1 christos
1389 1.1 christos static int
1390 1.1 christos ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
1391 1.1 christos {
1392 1.1 christos struct ctf_context *ccp = (struct ctf_context *) arg;
1393 1.1 christos
1394 1.1 christos add_psymbol_to_list (name, true,
1395 1.1 christos VAR_DOMAIN, LOC_STATIC, -1,
1396 1.1 christos psymbol_placement::GLOBAL,
1397 1.1 christos 0, language_c, ccp->of);
1398 1.1 christos return 0;
1399 1.1 christos }
1400 1.1 christos
1401 1.1 christos /* Setup partial_symtab's describing each source file for which
1402 1.1 christos debugging information is available. */
1403 1.1 christos
1404 1.1 christos static void
1405 1.1 christos scan_partial_symbols (ctf_file_t *cfp, struct objfile *of)
1406 1.1 christos {
1407 1.1 christos struct ctf_context ccx;
1408 1.1 christos bfd *abfd = of->obfd;
1409 1.1 christos const char *name = bfd_get_filename (abfd);
1410 1.1 christos ctf_psymtab *pst = create_partial_symtab (name, cfp, of);
1411 1.1 christos
1412 1.1 christos ccx.fp = cfp;
1413 1.1 christos ccx.of = of;
1414 1.1 christos
1415 1.1 christos if (ctf_type_iter (cfp, ctf_psymtab_type_cb, &ccx) == CTF_ERR)
1416 1.1 christos complaint (_("ctf_type_iter scan_partial_symbols failed - %s"),
1417 1.1 christos ctf_errmsg (ctf_errno (cfp)));
1418 1.1 christos
1419 1.1 christos if (ctf_variable_iter (cfp, ctf_psymtab_var_cb, &ccx) == CTF_ERR)
1420 1.1 christos complaint (_("ctf_variable_iter scan_partial_symbols failed - %s"),
1421 1.1 christos ctf_errmsg (ctf_errno (cfp)));
1422 1.1 christos
1423 1.1 christos /* Scan CTF object and function sections which correspond to each
1424 1.1 christos STT_FUNC or STT_OBJECT entry in the symbol table,
1425 1.1 christos pick up what init_symtab has done. */
1426 1.1 christos for (unsigned long idx = 0; ; idx++)
1427 1.1 christos {
1428 1.1 christos ctf_id_t tid;
1429 1.1 christos if ((tid = ctf_lookup_by_symbol (cfp, idx)) == CTF_ERR)
1430 1.1 christos {
1431 1.1 christos if (ctf_errno (cfp) == EINVAL || ctf_errno (cfp) == ECTF_NOSYMTAB)
1432 1.1 christos break; // Done, reach end of the section.
1433 1.1 christos else
1434 1.1 christos continue;
1435 1.1 christos }
1436 1.1 christos gdb::unique_xmalloc_ptr<char> tname (ctf_type_aname_raw (cfp, tid));
1437 1.1 christos uint32_t kind = ctf_type_kind (cfp, tid);
1438 1.1 christos address_class aclass;
1439 1.1 christos domain_enum tdomain;
1440 1.1 christos switch (kind)
1441 1.1 christos {
1442 1.1 christos case CTF_K_STRUCT:
1443 1.1 christos case CTF_K_UNION:
1444 1.1 christos case CTF_K_ENUM:
1445 1.1 christos tdomain = STRUCT_DOMAIN;
1446 1.1 christos break;
1447 1.1 christos default:
1448 1.1 christos tdomain = VAR_DOMAIN;
1449 1.1 christos break;
1450 1.1 christos }
1451 1.1 christos
1452 1.1 christos if (kind == CTF_K_FUNCTION)
1453 1.1 christos aclass = LOC_STATIC;
1454 1.1 christos else if (kind == CTF_K_CONST)
1455 1.1 christos aclass = LOC_CONST;
1456 1.1 christos else
1457 1.1 christos aclass = LOC_TYPEDEF;
1458 1.1 christos
1459 1.1 christos add_psymbol_to_list (tname.get (), true,
1460 1.1 christos tdomain, aclass, -1,
1461 1.1 christos psymbol_placement::STATIC,
1462 1.1 christos 0, language_c, of);
1463 1.1 christos }
1464 1.1 christos
1465 1.1 christos end_psymtab_common (of, pst);
1466 1.1 christos }
1467 1.1 christos
1468 1.1 christos /* Read CTF debugging information from a BFD section. This is
1469 1.1 christos called from elfread.c. It does a quick pass through the
1470 1.1 christos .ctf section to set up the partial symbol table. */
1471 1.1 christos
1472 1.1 christos void
1473 1.1 christos elfctf_build_psymtabs (struct objfile *of)
1474 1.1 christos {
1475 1.1 christos bfd *abfd = of->obfd;
1476 1.1 christos int err;
1477 1.1 christos
1478 1.1 christos ctf_archive_t *arc = ctf_bfdopen (abfd, &err);
1479 1.1 christos if (arc == NULL)
1480 1.1 christos error (_("ctf_bfdopen failed on %s - %s"),
1481 1.1 christos bfd_get_filename (abfd), ctf_errmsg (err));
1482 1.1 christos
1483 1.1 christos ctf_file_t *fp = ctf_arc_open_by_name (arc, NULL, &err);
1484 1.1 christos if (fp == NULL)
1485 1.1 christos error (_("ctf_arc_open_by_name failed on %s - %s"),
1486 1.1 christos bfd_get_filename (abfd), ctf_errmsg (err));
1487 1.1 christos ctf_file_key.emplace (of, fp);
1488 1.1 christos
1489 1.1 christos scan_partial_symbols (fp, of);
1490 1.1 christos }
1491 1.1 christos
1492 1.1 christos #else
1493 1.1 christos
1494 1.1 christos void
1495 1.1 christos elfctf_build_psymtabs (struct objfile *of)
1496 1.1 christos {
1497 1.1 christos /* Nothing to do if CTF is disabled. */
1498 1.1 christos }
1499 1.1 christos
1500 1.1 christos #endif /* ENABLE_LIBCTF */
1501