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