1*ad9a875cSmpi /* $OpenBSD: itype.h,v 1.5 2019/11/11 19:10:35 mpi Exp $ */ 20687c322Sjasper 3192095f7Smpi /* 4192095f7Smpi * Copyright (c) 2016-2017 Martin Pieuchot 5192095f7Smpi * Copyright (c) 2016 Jasper Lievisse Adriaanse <jasper@openbsd.org> 6192095f7Smpi * 7192095f7Smpi * Permission to use, copy, modify, and distribute this software for any 8192095f7Smpi * purpose with or without fee is hereby granted, provided that the above 9192095f7Smpi * copyright notice and this permission notice appear in all copies. 10192095f7Smpi * 11192095f7Smpi * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12192095f7Smpi * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13192095f7Smpi * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14192095f7Smpi * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15192095f7Smpi * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16192095f7Smpi * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17192095f7Smpi * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18192095f7Smpi */ 19192095f7Smpi 20192095f7Smpi #ifndef _ITTYPE_H_ 21192095f7Smpi #define _ITTYPE_H_ 22192095f7Smpi 23192095f7Smpi #define ITNAME_MAX 128 24192095f7Smpi 25192095f7Smpi struct imember; 26192095f7Smpi struct itref; 27192095f7Smpi 28192095f7Smpi /* 29192095f7Smpi * Internal type representation. 30192095f7Smpi * 31192095f7Smpi * Some bits of DWARF that we want to keep around to resolve types and 32192095f7Smpi * variables to their intrinsics. 33192095f7Smpi */ 34192095f7Smpi struct itype { 35192095f7Smpi TAILQ_ENTRY(itype) it_next; /* itype: global queue of types */ 36192095f7Smpi TAILQ_ENTRY(itype) it_symb; /* itype: global queue of symbol */ 37192095f7Smpi RB_ENTRY(itype) it_node; /* itype: per-type tree of types */ 38192095f7Smpi 39*ad9a875cSmpi SIMPLEQ_HEAD(, itref) it_refs; /* itype: backpointing refs */ 40192095f7Smpi 41192095f7Smpi TAILQ_HEAD(, imember) it_members;/* itype: members of struct/union */ 42192095f7Smpi 43192095f7Smpi size_t it_off; /* DWARF: matching .abbrev offset */ 44192095f7Smpi uint64_t it_ref; /* DWARF: CU offset of ref. type */ 45192095f7Smpi 46192095f7Smpi struct itype *it_refp; /* itype: resolved type */ 47192095f7Smpi 48192095f7Smpi char it_name[ITNAME_MAX];/* CTF: type name */ 49192095f7Smpi uint32_t it_size; /* CTF: size in byte or bits */ 50192095f7Smpi uint32_t it_nelems; /* CTF: # of members or arguments */ 51192095f7Smpi uint16_t it_enc; /* CTF: base type encoding */ 52192095f7Smpi uint16_t it_idx; /* CTF: generated type ID */ 53192095f7Smpi uint16_t it_type; /* CTF: type */ 54192095f7Smpi uint8_t __pad[2]; 55192095f7Smpi 56192095f7Smpi unsigned int it_flags; /* itype: parser flags */ 57192095f7Smpi #define ITF_UNRES 0x01 /* needs to be resolved */ 58192095f7Smpi #define ITF_UNRES_MEMB 0x02 /* members need to be resolved */ 59192095f7Smpi #define ITF_FUNC 0x04 /* is a function */ 60192095f7Smpi #define ITF_OBJ 0x08 /* is an object */ 611657e891Smpi #define ITF_FORWARD 0x10 /* is a forward declaration */ 62192095f7Smpi #define ITF_INSERTED 0x20 /* already found/inserted */ 63192095f7Smpi #define ITF_USED 0x40 /* referenced in the current CU */ 64192095f7Smpi #define ITF_ANON 0x80 /* type without name */ 65192095f7Smpi #define ITF_MASK (ITF_INSERTED|ITF_USED) 66192095f7Smpi }; 67192095f7Smpi 68192095f7Smpi /* 69192095f7Smpi * Member for types with a variable length (struct, array, etc). 70192095f7Smpi */ 71192095f7Smpi struct imember { 72192095f7Smpi TAILQ_ENTRY(imember) im_next; 73192095f7Smpi char im_name[ITNAME_MAX]; /* struct field name */ 74192095f7Smpi size_t im_ref; /* CU offset of the field type */ 75192095f7Smpi size_t im_off; /* field offset in struct/union */ 76192095f7Smpi struct itype *im_refp; /* resolved CTF type */ 77192095f7Smpi unsigned int im_flags; /* parser flags */ 7872c906afSmpi #define IMF_ANON 0x01 /* member without name */ 79192095f7Smpi }; 80192095f7Smpi 81192095f7Smpi /* 82192095f7Smpi * Used to build a list of backpointing references to speed up 83192095f7Smpi * merging duplicated types. 84192095f7Smpi */ 85192095f7Smpi struct itref { 86192095f7Smpi SIMPLEQ_ENTRY(itref) ir_next; 87192095f7Smpi struct itype *ir_itp; 88192095f7Smpi }; 89192095f7Smpi 90192095f7Smpi TAILQ_HEAD(itype_queue, itype); 91192095f7Smpi RB_HEAD(isymb_tree, itype); 92192095f7Smpi 93192095f7Smpi /* lists of types, functions & data objects */ 94192095f7Smpi extern struct itype_queue itypeq, ifuncq, iobjq; 95192095f7Smpi extern struct isymb_tree isymbt; /* tree of symbols */ 96192095f7Smpi extern uint16_t tidx; /* type index */ 97192095f7Smpi extern uint16_t long_tidx; /* type ID for "long" */ 98192095f7Smpi 99192095f7Smpi RB_PROTOTYPE(isymb_tree, itype, it_node, it_name_cmp); 100192095f7Smpi 101192095f7Smpi struct itype *it_dup(struct itype *); 102192095f7Smpi const char *it_name(struct itype *); 10372c906afSmpi const char *im_name(struct imember *); 104192095f7Smpi 105192095f7Smpi #endif /*_ITTYPE_H_ */ 106