1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _CTFTOOLS_H 28*7c478bd9Sstevel@tonic-gate #define _CTFTOOLS_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * Functions and data structures used in the manipulation of stabs and CTF data 34*7c478bd9Sstevel@tonic-gate */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <stdio.h> 37*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 38*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 39*7c478bd9Sstevel@tonic-gate #include <libelf.h> 40*7c478bd9Sstevel@tonic-gate #include <gelf.h> 41*7c478bd9Sstevel@tonic-gate #include <pthread.h> 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 44*7c478bd9Sstevel@tonic-gate extern "C" { 45*7c478bd9Sstevel@tonic-gate #endif 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #include "list.h" 48*7c478bd9Sstevel@tonic-gate #include "hash.h" 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #ifndef DEBUG_LEVEL 51*7c478bd9Sstevel@tonic-gate #define DEBUG_LEVEL 0 52*7c478bd9Sstevel@tonic-gate #endif 53*7c478bd9Sstevel@tonic-gate #ifndef DEBUG_PARSE 54*7c478bd9Sstevel@tonic-gate #define DEBUG_PARSE 0 55*7c478bd9Sstevel@tonic-gate #endif 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate #ifndef DEBUG_STREAM 58*7c478bd9Sstevel@tonic-gate #define DEBUG_STREAM stderr 59*7c478bd9Sstevel@tonic-gate #endif 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate #ifndef MAX 62*7c478bd9Sstevel@tonic-gate #define MAX(a, b) ((a) < (b) ? (b) : (a)) 63*7c478bd9Sstevel@tonic-gate #endif 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate #ifndef MIN 66*7c478bd9Sstevel@tonic-gate #define MIN(a, b) ((a) > (b) ? (b) : (a)) 67*7c478bd9Sstevel@tonic-gate #endif 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate #define TRUE 1 70*7c478bd9Sstevel@tonic-gate #define FALSE 0 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate #define CTF_ELF_SCN_NAME ".SUNW_ctf" 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #define CTF_LABEL_LASTIDX -1 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate #define CTF_DEFAULT_LABEL "*** No Label Provided ***" 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate /* 79*7c478bd9Sstevel@tonic-gate * Default hash sizes 80*7c478bd9Sstevel@tonic-gate */ 81*7c478bd9Sstevel@tonic-gate #define TDATA_LAYOUT_HASH_SIZE 8191 /* A tdesc hash based on layout */ 82*7c478bd9Sstevel@tonic-gate #define TDATA_ID_HASH_SIZE 997 /* A tdesc hash based on type id */ 83*7c478bd9Sstevel@tonic-gate #define IIDESC_HASH_SIZE 8191 /* Hash of iidesc's */ 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * The default function argument array size. We'll realloc the array larger 87*7c478bd9Sstevel@tonic-gate * if we need to, but we want a default value that will allow us to avoid 88*7c478bd9Sstevel@tonic-gate * reallocation in the common case. 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate #define FUNCARG_DEF 5 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate extern const char *progname; 93*7c478bd9Sstevel@tonic-gate extern int debug_level; 94*7c478bd9Sstevel@tonic-gate extern int debug_parse; 95*7c478bd9Sstevel@tonic-gate extern const char *curhdr; 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * This is a partial copy of the stab.h that DevPro includes with their 99*7c478bd9Sstevel@tonic-gate * compiler. 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate typedef struct stab { 102*7c478bd9Sstevel@tonic-gate uint32_t n_strx; 103*7c478bd9Sstevel@tonic-gate uint8_t n_type; 104*7c478bd9Sstevel@tonic-gate int8_t n_other; 105*7c478bd9Sstevel@tonic-gate int16_t n_desc; 106*7c478bd9Sstevel@tonic-gate uint32_t n_value; 107*7c478bd9Sstevel@tonic-gate } stab_t; 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate #define N_GSYM 0x20 /* global symbol: name,,0,type,0 */ 110*7c478bd9Sstevel@tonic-gate #define N_FUN 0x24 /* procedure: name,,0,linenumber,0 */ 111*7c478bd9Sstevel@tonic-gate #define N_STSYM 0x26 /* static symbol: name,,0,type,0 or section relative */ 112*7c478bd9Sstevel@tonic-gate #define N_LCSYM 0x28 /* .lcomm symbol: name,,0,type,0 or section relative */ 113*7c478bd9Sstevel@tonic-gate #define N_ROSYM 0x2c /* ro_data: name,,0,type,0 or section relative */ 114*7c478bd9Sstevel@tonic-gate #define N_OPT 0x3c /* compiler options */ 115*7c478bd9Sstevel@tonic-gate #define N_RSYM 0x40 /* register sym: name,,0,type,register */ 116*7c478bd9Sstevel@tonic-gate #define N_SO 0x64 /* source file name: name,,0,0,0 */ 117*7c478bd9Sstevel@tonic-gate #define N_LSYM 0x80 /* local sym: name,,0,type,offset */ 118*7c478bd9Sstevel@tonic-gate #define N_SOL 0x84 /* #included file name: name,,0,0,0 */ 119*7c478bd9Sstevel@tonic-gate #define N_PSYM 0xa0 /* parameter: name,,0,type,offset */ 120*7c478bd9Sstevel@tonic-gate #define N_LBRAC 0xc0 /* left bracket: 0,,0,nesting level,function relative */ 121*7c478bd9Sstevel@tonic-gate #define N_RBRAC 0xe0 /* right bracket: 0,,0,nesting level,func relative */ 122*7c478bd9Sstevel@tonic-gate #define N_BINCL 0x82 /* header file: name,,0,0,0 */ 123*7c478bd9Sstevel@tonic-gate #define N_EINCL 0xa2 /* end of include file */ 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate /* 126*7c478bd9Sstevel@tonic-gate * Nodes in the type tree 127*7c478bd9Sstevel@tonic-gate * 128*7c478bd9Sstevel@tonic-gate * Each node consists of a single tdesc_t, with one of several auxiliary 129*7c478bd9Sstevel@tonic-gate * structures linked in via the `data' union. 130*7c478bd9Sstevel@tonic-gate */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* The type of tdesc_t node */ 133*7c478bd9Sstevel@tonic-gate typedef enum stabtype { 134*7c478bd9Sstevel@tonic-gate STABTYPE_FIRST, /* do not use */ 135*7c478bd9Sstevel@tonic-gate INTRINSIC, 136*7c478bd9Sstevel@tonic-gate POINTER, 137*7c478bd9Sstevel@tonic-gate ARRAY, 138*7c478bd9Sstevel@tonic-gate FUNCTION, 139*7c478bd9Sstevel@tonic-gate STRUCT, 140*7c478bd9Sstevel@tonic-gate UNION, 141*7c478bd9Sstevel@tonic-gate ENUM, 142*7c478bd9Sstevel@tonic-gate FORWARD, 143*7c478bd9Sstevel@tonic-gate TYPEDEF, 144*7c478bd9Sstevel@tonic-gate TYPEDEF_UNRES, 145*7c478bd9Sstevel@tonic-gate VOLATILE, 146*7c478bd9Sstevel@tonic-gate CONST, 147*7c478bd9Sstevel@tonic-gate RESTRICT, 148*7c478bd9Sstevel@tonic-gate STABTYPE_LAST /* do not use */ 149*7c478bd9Sstevel@tonic-gate } stabtype_t; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate typedef struct tdesc tdesc_t; 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate /* Auxiliary structure for array tdesc_t */ 154*7c478bd9Sstevel@tonic-gate typedef struct ardef { 155*7c478bd9Sstevel@tonic-gate tdesc_t *ad_contents; 156*7c478bd9Sstevel@tonic-gate tdesc_t *ad_idxtype; 157*7c478bd9Sstevel@tonic-gate uint_t ad_nelems; 158*7c478bd9Sstevel@tonic-gate } ardef_t; 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate /* Auxiliary structure for structure/union tdesc_t */ 161*7c478bd9Sstevel@tonic-gate typedef struct mlist { 162*7c478bd9Sstevel@tonic-gate int ml_offset; /* Offset from start of structure (in bits) */ 163*7c478bd9Sstevel@tonic-gate int ml_size; /* Member size (in bits) */ 164*7c478bd9Sstevel@tonic-gate char *ml_name; /* Member name */ 165*7c478bd9Sstevel@tonic-gate struct tdesc *ml_type; /* Member type */ 166*7c478bd9Sstevel@tonic-gate struct mlist *ml_next; /* Next member */ 167*7c478bd9Sstevel@tonic-gate } mlist_t; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate /* Auxiliary structure for enum tdesc_t */ 170*7c478bd9Sstevel@tonic-gate typedef struct elist { 171*7c478bd9Sstevel@tonic-gate char *el_name; 172*7c478bd9Sstevel@tonic-gate int el_number; 173*7c478bd9Sstevel@tonic-gate struct elist *el_next; 174*7c478bd9Sstevel@tonic-gate } elist_t; 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate /* Auxiliary structure for intrinsics (integers and reals) */ 177*7c478bd9Sstevel@tonic-gate typedef enum { 178*7c478bd9Sstevel@tonic-gate INTR_INT, 179*7c478bd9Sstevel@tonic-gate INTR_REAL 180*7c478bd9Sstevel@tonic-gate } intrtype_t; 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate typedef struct intr { 183*7c478bd9Sstevel@tonic-gate intrtype_t intr_type; 184*7c478bd9Sstevel@tonic-gate int intr_signed; 185*7c478bd9Sstevel@tonic-gate union { 186*7c478bd9Sstevel@tonic-gate char _iformat; 187*7c478bd9Sstevel@tonic-gate int _fformat; 188*7c478bd9Sstevel@tonic-gate } _u; 189*7c478bd9Sstevel@tonic-gate int intr_offset; 190*7c478bd9Sstevel@tonic-gate int intr_nbits; 191*7c478bd9Sstevel@tonic-gate } intr_t; 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate #define intr_iformat _u._iformat 194*7c478bd9Sstevel@tonic-gate #define intr_fformat _u._fformat 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate typedef struct fnarg { 197*7c478bd9Sstevel@tonic-gate char *fna_name; 198*7c478bd9Sstevel@tonic-gate struct tdesc *fna_type; 199*7c478bd9Sstevel@tonic-gate } fnarg_t; 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate #define FN_F_GLOBAL 0x1 202*7c478bd9Sstevel@tonic-gate #define FN_F_VARARGS 0x2 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate typedef struct fndef { 205*7c478bd9Sstevel@tonic-gate struct tdesc *fn_ret; 206*7c478bd9Sstevel@tonic-gate uint_t fn_nargs; 207*7c478bd9Sstevel@tonic-gate tdesc_t **fn_args; 208*7c478bd9Sstevel@tonic-gate uint_t fn_vargs; 209*7c478bd9Sstevel@tonic-gate } fndef_t; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate typedef int32_t tid_t; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate /* 214*7c478bd9Sstevel@tonic-gate * The tdesc_t (Type DESCription) is the basic node type used in the stabs data 215*7c478bd9Sstevel@tonic-gate * structure. Each data node gets a tdesc structure. Each node is linked into 216*7c478bd9Sstevel@tonic-gate * a directed graph (think of it as a tree with multiple roots and multiple 217*7c478bd9Sstevel@tonic-gate * leaves), with the root nodes at the top, and intrinsics at the bottom. The 218*7c478bd9Sstevel@tonic-gate * root nodes, which are pointed to by iidesc nodes, correspond to the types, 219*7c478bd9Sstevel@tonic-gate * globals, and statics defined by the stabs. 220*7c478bd9Sstevel@tonic-gate */ 221*7c478bd9Sstevel@tonic-gate struct tdesc { 222*7c478bd9Sstevel@tonic-gate char *t_name; 223*7c478bd9Sstevel@tonic-gate tdesc_t *t_next; /* Name hash next pointer */ 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate tid_t t_id; 226*7c478bd9Sstevel@tonic-gate tdesc_t *t_hash; /* ID hash next pointer */ 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate stabtype_t t_type; 229*7c478bd9Sstevel@tonic-gate int t_size; /* Size in bytes of object represented by this node */ 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate union { 232*7c478bd9Sstevel@tonic-gate intr_t *intr; /* int, real */ 233*7c478bd9Sstevel@tonic-gate tdesc_t *tdesc; /* ptr, typedef, vol, const, restr */ 234*7c478bd9Sstevel@tonic-gate ardef_t *ardef; /* array */ 235*7c478bd9Sstevel@tonic-gate mlist_t *members; /* struct, union */ 236*7c478bd9Sstevel@tonic-gate elist_t *emem; /* enum */ 237*7c478bd9Sstevel@tonic-gate fndef_t *fndef; /* function - first is return type */ 238*7c478bd9Sstevel@tonic-gate } t_data; 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate int t_flags; 241*7c478bd9Sstevel@tonic-gate int t_vgen; /* Visitation generation (see traverse.c) */ 242*7c478bd9Sstevel@tonic-gate int t_emark; /* Equality mark (see equiv_cb() in merge.c) */ 243*7c478bd9Sstevel@tonic-gate }; 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate #define t_intr t_data.intr 246*7c478bd9Sstevel@tonic-gate #define t_tdesc t_data.tdesc 247*7c478bd9Sstevel@tonic-gate #define t_ardef t_data.ardef 248*7c478bd9Sstevel@tonic-gate #define t_members t_data.members 249*7c478bd9Sstevel@tonic-gate #define t_emem t_data.emem 250*7c478bd9Sstevel@tonic-gate #define t_fndef t_data.fndef 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate #define TDESC_F_ISROOT 0x1 /* Has an iidesc_t (see below) */ 253*7c478bd9Sstevel@tonic-gate #define TDESC_F_GLOBAL 0x2 254*7c478bd9Sstevel@tonic-gate #define TDESC_F_RESOLVED 0x4 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate /* 257*7c478bd9Sstevel@tonic-gate * iidesc_t (Interesting Item DESCription) nodes point to tdesc_t nodes that 258*7c478bd9Sstevel@tonic-gate * correspond to "interesting" stabs. A stab is interesting if it defines a 259*7c478bd9Sstevel@tonic-gate * global or static variable, a global or static function, or a data type. 260*7c478bd9Sstevel@tonic-gate */ 261*7c478bd9Sstevel@tonic-gate typedef enum iitype { 262*7c478bd9Sstevel@tonic-gate II_NOT = 0, 263*7c478bd9Sstevel@tonic-gate II_GFUN, /* Global function */ 264*7c478bd9Sstevel@tonic-gate II_SFUN, /* Static function */ 265*7c478bd9Sstevel@tonic-gate II_GVAR, /* Global variable */ 266*7c478bd9Sstevel@tonic-gate II_SVAR, /* Static variable */ 267*7c478bd9Sstevel@tonic-gate II_PSYM, /* Function argument */ 268*7c478bd9Sstevel@tonic-gate II_SOU, /* Struct or union */ 269*7c478bd9Sstevel@tonic-gate II_TYPE /* Type (typedef) */ 270*7c478bd9Sstevel@tonic-gate } iitype_t; 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate typedef struct iidesc { 273*7c478bd9Sstevel@tonic-gate iitype_t ii_type; 274*7c478bd9Sstevel@tonic-gate char *ii_name; 275*7c478bd9Sstevel@tonic-gate tdesc_t *ii_dtype; 276*7c478bd9Sstevel@tonic-gate char *ii_owner; /* File that defined this node */ 277*7c478bd9Sstevel@tonic-gate int ii_flags; 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate /* Function arguments (if any) */ 280*7c478bd9Sstevel@tonic-gate int ii_nargs; 281*7c478bd9Sstevel@tonic-gate tdesc_t **ii_args; 282*7c478bd9Sstevel@tonic-gate int ii_vargs; /* Function uses varargs */ 283*7c478bd9Sstevel@tonic-gate } iidesc_t; 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate #define IIDESC_F_USED 0x1 /* Write this iidesc out */ 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate /* 288*7c478bd9Sstevel@tonic-gate * labelent_t nodes identify labels and corresponding type ranges associated 289*7c478bd9Sstevel@tonic-gate * with them. The label in a given labelent_t is associated with types with 290*7c478bd9Sstevel@tonic-gate * ids <= le_idx. 291*7c478bd9Sstevel@tonic-gate */ 292*7c478bd9Sstevel@tonic-gate typedef struct labelent { 293*7c478bd9Sstevel@tonic-gate char *le_name; 294*7c478bd9Sstevel@tonic-gate int le_idx; 295*7c478bd9Sstevel@tonic-gate } labelent_t; 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate /* 298*7c478bd9Sstevel@tonic-gate * The tdata_t (Type DATA) structure contains or references all type data for 299*7c478bd9Sstevel@tonic-gate * a given file or, during merging, several files. 300*7c478bd9Sstevel@tonic-gate */ 301*7c478bd9Sstevel@tonic-gate typedef struct tdata { 302*7c478bd9Sstevel@tonic-gate int td_curemark; /* Equality mark (see merge.c) */ 303*7c478bd9Sstevel@tonic-gate int td_curvgen; /* Visitation generation (see traverse.c) */ 304*7c478bd9Sstevel@tonic-gate int td_nextid; /* The ID for the next tdesc_t created */ 305*7c478bd9Sstevel@tonic-gate hash_t *td_iihash; /* The iidesc_t nodes for this file */ 306*7c478bd9Sstevel@tonic-gate 307*7c478bd9Sstevel@tonic-gate hash_t *td_layouthash; /* The tdesc nodes, hashed by structure */ 308*7c478bd9Sstevel@tonic-gate hash_t *td_idhash; /* The tdesc nodes, hashed by type id */ 309*7c478bd9Sstevel@tonic-gate list_t *td_fwdlist; /* All forward declaration tdesc nodes */ 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate char *td_parlabel; /* Top label uniq'd against in parent */ 312*7c478bd9Sstevel@tonic-gate char *td_parname; /* Basename of parent */ 313*7c478bd9Sstevel@tonic-gate list_t *td_labels; /* Labels and their type ranges */ 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate pthread_mutex_t td_mergelock; 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate int td_ref; 318*7c478bd9Sstevel@tonic-gate } tdata_t; 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate /* 321*7c478bd9Sstevel@tonic-gate * By design, the iidesc hash is heterogeneous. The CTF emitter, on the 322*7c478bd9Sstevel@tonic-gate * other hand, needs to be able to access the elements of the list by type, 323*7c478bd9Sstevel@tonic-gate * and in a specific sorted order. An iiburst holds these elements in that 324*7c478bd9Sstevel@tonic-gate * order. (A burster is a machine that separates carbon-copy forms) 325*7c478bd9Sstevel@tonic-gate */ 326*7c478bd9Sstevel@tonic-gate typedef struct iiburst { 327*7c478bd9Sstevel@tonic-gate int iib_nfuncs; 328*7c478bd9Sstevel@tonic-gate int iib_curfunc; 329*7c478bd9Sstevel@tonic-gate iidesc_t **iib_funcs; 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate int iib_nobjts; 332*7c478bd9Sstevel@tonic-gate int iib_curobjt; 333*7c478bd9Sstevel@tonic-gate iidesc_t **iib_objts; 334*7c478bd9Sstevel@tonic-gate 335*7c478bd9Sstevel@tonic-gate list_t *iib_types; 336*7c478bd9Sstevel@tonic-gate int iib_maxtypeid; 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate tdata_t *iib_td; 339*7c478bd9Sstevel@tonic-gate struct tdtrav_data *iib_tdtd; /* tdtrav_data_t */ 340*7c478bd9Sstevel@tonic-gate } iiburst_t; 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate typedef struct ctf_buf ctf_buf_t; 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate typedef struct symit_data symit_data_t; 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* bugs.c */ 347*7c478bd9Sstevel@tonic-gate void cvt_fixbugs(tdata_t *td); 348*7c478bd9Sstevel@tonic-gate 349*7c478bd9Sstevel@tonic-gate /* ctf.c */ 350*7c478bd9Sstevel@tonic-gate caddr_t ctf_gen(iiburst_t *, size_t *, int); 351*7c478bd9Sstevel@tonic-gate tdata_t *ctf_load(char *, caddr_t, size_t, symit_data_t *, char *); 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate /* iidesc.c */ 354*7c478bd9Sstevel@tonic-gate iidesc_t *iidesc_new(char *); 355*7c478bd9Sstevel@tonic-gate int iidesc_hash(int, void *); 356*7c478bd9Sstevel@tonic-gate iidesc_t *iidesc_dup(iidesc_t *); 357*7c478bd9Sstevel@tonic-gate iidesc_t *iidesc_dup_rename(iidesc_t *, char const *, char const *); 358*7c478bd9Sstevel@tonic-gate void iidesc_add(hash_t *, iidesc_t *); 359*7c478bd9Sstevel@tonic-gate void iidesc_free(iidesc_t *, void *); 360*7c478bd9Sstevel@tonic-gate int iidesc_count_type(void *, void *); 361*7c478bd9Sstevel@tonic-gate void iidesc_stats(hash_t *); 362*7c478bd9Sstevel@tonic-gate int iidesc_dump(iidesc_t *); 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate /* input.c */ 365*7c478bd9Sstevel@tonic-gate typedef enum source_types { 366*7c478bd9Sstevel@tonic-gate SOURCE_NONE = 0, 367*7c478bd9Sstevel@tonic-gate SOURCE_UNKNOWN = 1, 368*7c478bd9Sstevel@tonic-gate SOURCE_C = 2, 369*7c478bd9Sstevel@tonic-gate SOURCE_S = 4 370*7c478bd9Sstevel@tonic-gate } source_types_t; 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate source_types_t built_source_types(Elf *, const char *); 373*7c478bd9Sstevel@tonic-gate int count_files(char **, int); 374*7c478bd9Sstevel@tonic-gate int read_ctf(char **, int, char *, int (*)(tdata_t *, char *, void *), 375*7c478bd9Sstevel@tonic-gate void *, int); 376*7c478bd9Sstevel@tonic-gate int read_ctf_save_cb(tdata_t *, char *, void *); 377*7c478bd9Sstevel@tonic-gate symit_data_t *symit_new(Elf *, const char *); 378*7c478bd9Sstevel@tonic-gate void symit_reset(symit_data_t *); 379*7c478bd9Sstevel@tonic-gate char *symit_curfile(symit_data_t *); 380*7c478bd9Sstevel@tonic-gate GElf_Sym *symit_next(symit_data_t *, int); 381*7c478bd9Sstevel@tonic-gate char *symit_name(symit_data_t *); 382*7c478bd9Sstevel@tonic-gate void symit_free(symit_data_t *); 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate /* merge.c */ 385*7c478bd9Sstevel@tonic-gate void merge_into_master(tdata_t *, tdata_t *, tdata_t *, int); 386*7c478bd9Sstevel@tonic-gate 387*7c478bd9Sstevel@tonic-gate /* output.c */ 388*7c478bd9Sstevel@tonic-gate #define CTF_FUZZY_MATCH 0x1 /* match local symbols to global CTF */ 389*7c478bd9Sstevel@tonic-gate #define CTF_USE_DYNSYM 0x2 /* use .dynsym not .symtab */ 390*7c478bd9Sstevel@tonic-gate #define CTF_COMPRESS 0x4 /* compress CTF output */ 391*7c478bd9Sstevel@tonic-gate #define CTF_KEEP_STABS 0x8 /* keep .stabs sections */ 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate void write_ctf(tdata_t *, const char *, const char *, int); 394*7c478bd9Sstevel@tonic-gate 395*7c478bd9Sstevel@tonic-gate /* parse.c */ 396*7c478bd9Sstevel@tonic-gate void parse_init(tdata_t *); 397*7c478bd9Sstevel@tonic-gate void parse_finish(tdata_t *); 398*7c478bd9Sstevel@tonic-gate int parse_stab(stab_t *, char *, iidesc_t **); 399*7c478bd9Sstevel@tonic-gate tdesc_t *lookup(int); 400*7c478bd9Sstevel@tonic-gate tdesc_t *lookupname(char *); 401*7c478bd9Sstevel@tonic-gate void check_hash(void); 402*7c478bd9Sstevel@tonic-gate void resolve_typed_bitfields(void); 403*7c478bd9Sstevel@tonic-gate 404*7c478bd9Sstevel@tonic-gate /* stabs.c */ 405*7c478bd9Sstevel@tonic-gate int stabs_read(tdata_t *, Elf *, const char *); 406*7c478bd9Sstevel@tonic-gate 407*7c478bd9Sstevel@tonic-gate /* dwarf.c */ 408*7c478bd9Sstevel@tonic-gate int dw_read(tdata_t *, Elf *, const char *); 409*7c478bd9Sstevel@tonic-gate const char *dw_tag2str(uint_t); 410*7c478bd9Sstevel@tonic-gate 411*7c478bd9Sstevel@tonic-gate /* tdata.c */ 412*7c478bd9Sstevel@tonic-gate tdata_t *tdata_new(void); 413*7c478bd9Sstevel@tonic-gate void tdata_free(tdata_t *); 414*7c478bd9Sstevel@tonic-gate void tdata_build_hashes(tdata_t *td); 415*7c478bd9Sstevel@tonic-gate int tdesc_idhash(int, void *); 416*7c478bd9Sstevel@tonic-gate int tdesc_idcmp(void *, void *); 417*7c478bd9Sstevel@tonic-gate int tdesc_namehash(int, void *); 418*7c478bd9Sstevel@tonic-gate int tdesc_namecmp(void *, void *); 419*7c478bd9Sstevel@tonic-gate int tdesc_layouthash(int, void *); 420*7c478bd9Sstevel@tonic-gate int tdesc_layoutcmp(void *, void *); 421*7c478bd9Sstevel@tonic-gate void tdesc_free(tdesc_t *); 422*7c478bd9Sstevel@tonic-gate void tdata_label_add(tdata_t *, char *, int); 423*7c478bd9Sstevel@tonic-gate labelent_t *tdata_label_top(tdata_t *); 424*7c478bd9Sstevel@tonic-gate int tdata_label_find(tdata_t *, char *); 425*7c478bd9Sstevel@tonic-gate void tdata_label_free(tdata_t *); 426*7c478bd9Sstevel@tonic-gate void tdata_merge(tdata_t *, tdata_t *); 427*7c478bd9Sstevel@tonic-gate void tdata_label_newmax(tdata_t *, int); 428*7c478bd9Sstevel@tonic-gate 429*7c478bd9Sstevel@tonic-gate /* util.c */ 430*7c478bd9Sstevel@tonic-gate int streq(char *, char *); 431*7c478bd9Sstevel@tonic-gate int findelfsecidx(Elf *, char *); 432*7c478bd9Sstevel@tonic-gate char *mktmpname(const char *, const char *); 433*7c478bd9Sstevel@tonic-gate void terminate(char *, ...); 434*7c478bd9Sstevel@tonic-gate void set_terminate_cleanup(void (*)()); 435*7c478bd9Sstevel@tonic-gate void vaterminate(char *, va_list); 436*7c478bd9Sstevel@tonic-gate void elfterminate(const char *, const char *, ...); 437*7c478bd9Sstevel@tonic-gate void warning(char *, ...); 438*7c478bd9Sstevel@tonic-gate void vadebug(int, char *, va_list); 439*7c478bd9Sstevel@tonic-gate void debug(int, char *, ...); 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 442*7c478bd9Sstevel@tonic-gate } 443*7c478bd9Sstevel@tonic-gate #endif 444*7c478bd9Sstevel@tonic-gate 445*7c478bd9Sstevel@tonic-gate #endif /* _CTFTOOLS_H */ 446