_libdwarf.h revision 303975
132145Spst/*-
232145Spst * Copyright (c) 2007 John Birrell (jb@freebsd.org)
332145Spst * Copyright (c) 2009-2014 Kai Wang
432145Spst * All rights reserved.
532145Spst *
632145Spst * Redistribution and use in source and binary forms, with or without
732145Spst * modification, are permitted provided that the following conditions
832145Spst * are met:
932145Spst * 1. Redistributions of source code must retain the above copyright
1032145Spst *    notice, this list of conditions and the following disclaimer.
1132145Spst * 2. Redistributions in binary form must reproduce the above copyright
1232145Spst *    notice, this list of conditions and the following disclaimer in the
1332145Spst *    documentation and/or other materials provided with the distribution.
1432145Spst *
1532145Spst * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1632145Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1732145Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1832145Spst * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1932145Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2066644Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2166644Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2232145Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2332145Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2432145Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25146778Ssam * SUCH DAMAGE.
26147904Ssam *
2732145Spst * $Id: _libdwarf.h 3298 2016-01-09 15:43:31Z jkoshy $
2832145Spst */
29146778Ssam
30146778Ssam#ifndef	__LIBDWARF_H_
3132145Spst#define	__LIBDWARF_H_
3232145Spst
33146778Ssam#include <sys/param.h>
3432145Spst#include <sys/queue.h>
35146778Ssam#include <assert.h>
36146778Ssam#include <limits.h>
3732145Spst#include <stdio.h>
3832145Spst#include <stdlib.h>
39146778Ssam#include <string.h>
40146778Ssam#include <gelf.h>
4132145Spst#include "dwarf.h"
42146778Ssam#include "libdwarf.h"
43146778Ssam#include "uthash.h"
44146778Ssam
4532145Spst#include "_elftc.h"
46146778Ssam
4732145Spst#define DWARF_DIE_HASH_SIZE		8191
48146778Ssam
49146778Ssamstruct _libdwarf_globals {
50146778Ssam	Dwarf_Handler	errhand;
51146778Ssam	Dwarf_Ptr	errarg;
52146778Ssam	int		applyreloc;
53146778Ssam};
54146778Ssam
55146778Ssamextern struct _libdwarf_globals _libdwarf;
56146778Ssam
57146778Ssam#define	_DWARF_SET_ERROR(_d, _e, _err, _elf_err)			\
58146778Ssam	_dwarf_set_error(_d, _e, _err, _elf_err, __func__, __LINE__)
59146778Ssam#define	DWARF_SET_ERROR(_d, _e, _err)					\
60146778Ssam	_DWARF_SET_ERROR(_d, _e, _err, 0)
61146778Ssam#define	DWARF_SET_ELF_ERROR(_d, _e)					\
62146778Ssam	_DWARF_SET_ERROR(_d, _e, DW_DLE_ELF, elf_errno())
63146778Ssam
64146778Ssam/*
65146778Ssam * Convenient macros for producer bytes stream generation.
66146778Ssam */
67146778Ssam#define	WRITE_VALUE(value, bytes)					\
6832145Spst	dbg->write_alloc(&ds->ds_data, &ds->ds_cap, &ds->ds_size,	\
69146778Ssam	    (value), (bytes), error)
7032145Spst#define	WRITE_ULEB128(value)						\
71146778Ssam	_dwarf_write_uleb128_alloc(&ds->ds_data, &ds->ds_cap,		\
72146778Ssam	    &ds->ds_size, (value), error)
73146778Ssam#define	WRITE_SLEB128(value)						\
74146778Ssam	_dwarf_write_sleb128_alloc(&ds->ds_data, &ds->ds_cap,		\
75146778Ssam	    &ds->ds_size, (value), error)
7632145Spst#define	WRITE_STRING(string)						\
77146778Ssam	_dwarf_write_string_alloc(&ds->ds_data, &ds->ds_cap,		\
78146778Ssam	    &ds->ds_size, (string), error)
79146778Ssam#define	WRITE_BLOCK(blk, size)						\
80146778Ssam	_dwarf_write_block_alloc(&ds->ds_data, &ds->ds_cap,		\
81146778Ssam	    &ds->ds_size, (blk), (size), error)
82146778Ssam#define	WRITE_PADDING(byte, cnt)					\
83146778Ssam	_dwarf_write_padding_alloc(&ds->ds_data, &ds->ds_cap,		\
84146778Ssam	    &ds->ds_size, (byte), (cnt), error)
8532145Spst#define	RCHECK(expr)							\
8632145Spst	do {								\
87146778Ssam		ret = expr;						\
88146778Ssam		if (ret != DW_DLE_NONE)					\
89146778Ssam			goto gen_fail;					\
90146778Ssam	} while(0)
91146778Ssam
92146778Ssamtypedef struct _Dwarf_CU *Dwarf_CU;
9332145Spst
94146778Ssamstruct _Dwarf_AttrDef {
95146778Ssam	Dwarf_Half	ad_attrib;		/* DW_AT_XXX */
9632145Spst	Dwarf_Half	ad_form;		/* DW_FORM_XXX */
97146778Ssam	uint64_t	ad_offset;		/* Offset in abbrev section. */
98146778Ssam	STAILQ_ENTRY(_Dwarf_AttrDef) ad_next;	/* Next attribute define. */
9932145Spst};
100146778Ssam
101146778Ssamstruct _Dwarf_Attribute {
10232145Spst	Dwarf_Die		at_die;		/* Ptr to containing DIE. */
103146778Ssam	Dwarf_Die		at_refdie;	/* Ptr to reference DIE. */
104146778Ssam	uint64_t		at_offset;	/* Offset in info section. */
10532145Spst	Dwarf_Half		at_attrib;	/* DW_AT_XXX */
106146778Ssam	Dwarf_Half		at_form;	/* DW_FORM_XXX */
107146778Ssam	int			at_indirect;	/* Has indirect form. */
108146778Ssam	union {
109146778Ssam		uint64_t	u64;		/* Unsigned value. */
110146778Ssam		int64_t		s64;		/* Signed value. */
111146778Ssam		char		*s;   		/* String. */
112146778Ssam		uint8_t		*u8p;		/* Block data. */
11332145Spst	} u[2];					/* Value. */
114146778Ssam	Dwarf_Block		at_block;	/* Block. */
115146778Ssam	Dwarf_Locdesc		*at_ld;		/* at value is locdesc. */
116146778Ssam	Dwarf_P_Expr		at_expr;	/* at value is expr. */
117146778Ssam	uint64_t		at_relsym;	/* Relocation symbol index. */
118146778Ssam	const char		*at_relsec;	/* Rel. to dwarf section. */
119146778Ssam	STAILQ_ENTRY(_Dwarf_Attribute) at_next;	/* Next attribute. */
120146778Ssam};
121146778Ssam
122146778Ssamstruct _Dwarf_Abbrev {
123146778Ssam	uint64_t	ab_entry;	/* Abbrev entry. */
124146778Ssam	uint64_t	ab_tag;		/* Tag: DW_TAG_ */
12532145Spst	uint8_t		ab_children;	/* DW_CHILDREN_no or DW_CHILDREN_yes */
12632145Spst	uint64_t	ab_offset;	/* Offset in abbrev section. */
127146778Ssam	uint64_t	ab_length;	/* Length of this abbrev entry. */
12832145Spst	uint64_t	ab_atnum;	/* Number of attribute defines. */
12932145Spst	UT_hash_handle	ab_hh;		/* Uthash handle. */
13032145Spst	STAILQ_HEAD(, _Dwarf_AttrDef) ab_attrdef; /* List of attribute defs. */
13132145Spst};
13232145Spst
13332145Spststruct _Dwarf_Die {
13432145Spst	Dwarf_Die	die_parent;	/* Parent DIE. */
13532145Spst	Dwarf_Die	die_child;	/* First child DIE. */
13632145Spst	Dwarf_Die	die_left;	/* Left sibling DIE. */
13732145Spst	Dwarf_Die	die_right;	/* Right sibling DIE. */
13832145Spst	uint64_t	die_offset;	/* DIE offset in section. */
13932145Spst	uint64_t	die_next_off;	/* Next DIE offset in section. */
14032145Spst	uint64_t	die_abnum;	/* Abbrev number. */
14132145Spst	Dwarf_Abbrev	die_ab;		/* Abbrev pointer. */
14232145Spst	Dwarf_Tag	die_tag;	/* DW_TAG_ */
14332145Spst	Dwarf_Debug	die_dbg;	/* Dwarf_Debug pointer. */
14432145Spst	Dwarf_CU	die_cu;		/* Compilation unit pointer. */
14532145Spst	char		*die_name;	/* Ptr to the name string. */
14632145Spst	Dwarf_Attribute	*die_attrarray;	/* Array of attributes. */
14732145Spst	STAILQ_HEAD(, _Dwarf_Attribute)	die_attr; /* List of attributes. */
14832145Spst	STAILQ_ENTRY(_Dwarf_Die) die_pro_next; /* Next die in pro-die list. */
14932145Spst};
15032145Spst
15132145Spststruct _Dwarf_P_Expr_Entry {
15232145Spst	Dwarf_Loc	ee_loc;		/* Location expression. */
153146778Ssam	Dwarf_Unsigned	ee_sym;		/* Optional related reloc sym index. */
154147904Ssam	STAILQ_ENTRY(_Dwarf_P_Expr_Entry) ee_next; /* Next entry in list. */
15532145Spst};
156147904Ssam
157146778Ssamstruct _Dwarf_P_Expr {
15832145Spst	Dwarf_Debug	pe_dbg;		/* Dwarf_Debug pointer. */
159146778Ssam	uint8_t		*pe_block;	/* Expression block data. */
16032145Spst	int		pe_invalid;	/* Block data is up-to-date or not. */
16132145Spst	Dwarf_Unsigned	pe_length;	/* Length of the block. */
162146778Ssam	STAILQ_HEAD(, _Dwarf_P_Expr_Entry) pe_eelist; /* List of entries. */
163146778Ssam	STAILQ_ENTRY(_Dwarf_P_Expr) pe_next; /* Next expr in list. */
16432145Spst};
165146778Ssam
166146778Ssamstruct _Dwarf_Line {
167146778Ssam	Dwarf_LineInfo	ln_li;		/* Ptr to line info. */
168146778Ssam	Dwarf_Addr	ln_addr;	/* Line address. */
169146778Ssam	Dwarf_Unsigned	ln_symndx;	/* Symbol index for relocation. */
170146778Ssam	Dwarf_Unsigned	ln_fileno;	/* File number. */
171146778Ssam	Dwarf_Unsigned	ln_lineno;	/* Line number. */
172146778Ssam	Dwarf_Signed	ln_column;	/* Column number. */
173146778Ssam	Dwarf_Bool	ln_bblock;	/* Basic block flag. */
174146778Ssam	Dwarf_Bool	ln_stmt;	/* Begin statement flag. */
175146778Ssam	Dwarf_Bool	ln_endseq;	/* End sequence flag. */
176146778Ssam	STAILQ_ENTRY(_Dwarf_Line) ln_next; /* Next line in list. */
177146778Ssam};
178146778Ssam
179146778Ssamstruct _Dwarf_LineFile {
180146778Ssam	char		*lf_fname;	/* Filename. */
181146778Ssam	char		*lf_fullpath;	/* Full pathname of the file. */
182146778Ssam	Dwarf_Unsigned	lf_dirndx;	/* Dir index. */
183146778Ssam	Dwarf_Unsigned	lf_mtime;	/* Modification time. */
184146778Ssam	Dwarf_Unsigned	lf_size;	/* File size. */
185146778Ssam	STAILQ_ENTRY(_Dwarf_LineFile) lf_next; /* Next file in list. */
186146778Ssam};
18732145Spst
18832145Spststruct _Dwarf_LineInfo {
189146778Ssam	Dwarf_Unsigned	li_length;	/* Length of line info data. */
190146778Ssam	Dwarf_Half	li_version;	/* Version of line info. */
19132145Spst	Dwarf_Unsigned	li_hdrlen;	/* Length of line info header. */
19232145Spst	Dwarf_Small	li_minlen;	/* Minimum instrutction length. */
19332145Spst	Dwarf_Small	li_maxop;	/* Maximum operations per inst. */
194147904Ssam	Dwarf_Small	li_defstmt;	/* Default value of is_stmt. */
195147904Ssam	int8_t		li_lbase;    	/* Line base for special opcode. */
196147904Ssam	Dwarf_Small	li_lrange;    	/* Line range for special opcode. */
197147904Ssam	Dwarf_Small	li_opbase;	/* Fisrt std opcode number. */
198147904Ssam	Dwarf_Small	*li_oplen;	/* Array of std opcode len. */
199147904Ssam	char		**li_incdirs;	/* Array of include dirs. */
200147904Ssam	Dwarf_Unsigned	li_inclen;	/* Length of inc dir array. */
201147904Ssam	char		**li_lfnarray;	/* Array of file names. */
202147904Ssam	Dwarf_Unsigned	li_lflen;	/* Length of filename array. */
203147904Ssam	STAILQ_HEAD(, _Dwarf_LineFile) li_lflist; /* List of files. */
204147904Ssam	Dwarf_Line	*li_lnarray;	/* Array of lines. */
205147904Ssam	Dwarf_Unsigned	li_lnlen;	/* Length of the line array. */
206147904Ssam	STAILQ_HEAD(, _Dwarf_Line) li_lnlist; /* List of lines. */
207147904Ssam};
208147904Ssam
209146778Ssamstruct _Dwarf_NamePair {
210146778Ssam	Dwarf_NameTbl	np_nt;		/* Ptr to containing name table. */
211146778Ssam	Dwarf_Die	np_die;		/* Ptr to Ref. Die. */
212146778Ssam	Dwarf_Unsigned	np_offset;	/* Offset in CU. */
213146778Ssam	char		*np_name;	/* Object/Type name. */
214146778Ssam	STAILQ_ENTRY(_Dwarf_NamePair) np_next; /* Next pair in the list. */
215146778Ssam};
21632145Spst
217146778Ssamstruct _Dwarf_NameTbl {
218146778Ssam	Dwarf_Unsigned	nt_length;	/* Name lookup table length. */
219147904Ssam	Dwarf_Half	nt_version;	/* Name lookup table version. */
220146778Ssam	Dwarf_CU	nt_cu;		/* Ptr to Ref. CU. */
22132145Spst	Dwarf_Off	nt_cu_offset;	/* Ref. CU offset in .debug_info */
222147904Ssam	Dwarf_Unsigned	nt_cu_length;	/* Ref. CU length. */
223147904Ssam	STAILQ_HEAD(, _Dwarf_NamePair) nt_nplist; /* List of offset+name pairs. */
224147904Ssam	STAILQ_ENTRY(_Dwarf_NameTbl) nt_next; /* Next name table in the list. */
225146778Ssam};
226146778Ssam
22732145Spststruct _Dwarf_NameSec {
228146778Ssam	STAILQ_HEAD(, _Dwarf_NameTbl) ns_ntlist; /* List of name tables. */
229146778Ssam	Dwarf_NamePair	*ns_array;	/* Array of pairs of all tables. */
230146778Ssam	Dwarf_Unsigned	ns_len;		/* Length of the pair array. */
231146778Ssam};
232146778Ssam
233146778Ssamstruct _Dwarf_Fde {
234146778Ssam	Dwarf_Debug	fde_dbg;	/* Ptr to containing dbg. */
235146778Ssam	Dwarf_Cie	fde_cie;	/* Ptr to associated CIE. */
236146778Ssam	Dwarf_FrameSec	fde_fs;		/* Ptr to containing .debug_frame. */
237147904Ssam	Dwarf_Ptr	fde_addr;	/* Ptr to start of the FDE. */
238146778Ssam	Dwarf_Unsigned	fde_offset;	/* Offset of the FDE. */
239146778Ssam	Dwarf_Unsigned	fde_length;	/* Length of the FDE. */
240146778Ssam	Dwarf_Unsigned	fde_cieoff;	/* Offset of associated CIE. */
241146778Ssam	Dwarf_Unsigned	fde_initloc;	/* Initial location. */
242146778Ssam	Dwarf_Unsigned	fde_adrange;	/* Address range. */
243146778Ssam	Dwarf_Unsigned	fde_auglen;	/* Augmentation length. */
244146778Ssam	uint8_t		*fde_augdata;	/* Augmentation data. */
245146778Ssam	uint8_t		*fde_inst;	/* Instructions. */
246146778Ssam	Dwarf_Unsigned	fde_instlen;	/* Length of instructions. */
247146778Ssam	Dwarf_Unsigned	fde_instcap;	/* Capacity of inst buffer. */
248146778Ssam	Dwarf_Unsigned	fde_symndx;	/* Symbol index for relocation. */
249146778Ssam	Dwarf_Unsigned	fde_esymndx;	/* End symbol index for relocation. */
250146778Ssam	Dwarf_Addr	fde_eoff;	/* Offset from the end symbol. */
251146778Ssam	STAILQ_ENTRY(_Dwarf_Fde) fde_next; /* Next FDE in list. */
252146778Ssam};
25332145Spst
254146778Ssamstruct _Dwarf_Cie {
25532145Spst	Dwarf_Debug	cie_dbg;	/* Ptr to containing dbg. */
256146778Ssam	Dwarf_Unsigned	cie_index;	/* Index of the CIE. */
257146778Ssam	Dwarf_Unsigned	cie_offset;	/* Offset of the CIE. */
25832145Spst	Dwarf_Unsigned	cie_length;	/* Length of the CIE. */
259146778Ssam	Dwarf_Half	cie_version;	/* CIE version. */
26032145Spst	uint8_t		*cie_augment;	/* CIE augmentation (UTF-8). */
261146778Ssam	Dwarf_Unsigned	cie_ehdata;	/* Optional EH Data. */
26232145Spst	uint8_t		cie_addrsize;	/* Address size. (DWARF4) */
263146778Ssam	uint8_t		cie_segmentsize; /* Segment size. (DWARF4) */
264146778Ssam	Dwarf_Unsigned	cie_caf;	/* Code alignment factor. */
265146778Ssam	Dwarf_Signed	cie_daf;	/* Data alignment factor. */
266146778Ssam	Dwarf_Unsigned	cie_ra;		/* Return address register. */
267146778Ssam	Dwarf_Unsigned	cie_auglen;	/* Augmentation length. */
268146778Ssam	uint8_t		*cie_augdata;	/* Augmentation data; */
26932145Spst	uint8_t		cie_fde_encode; /* FDE PC start/range encode. */
27032145Spst	Dwarf_Ptr	cie_initinst;	/* Initial instructions. */
27132145Spst	Dwarf_Unsigned	cie_instlen;	/* Length of init instructions. */
272147904Ssam	STAILQ_ENTRY(_Dwarf_Cie) cie_next;  /* Next CIE in list. */
27332145Spst};
274146778Ssam
275146778Ssamstruct _Dwarf_FrameSec {
276147904Ssam	STAILQ_HEAD(, _Dwarf_Cie) fs_cielist; /* List of CIE. */
277146778Ssam	STAILQ_HEAD(, _Dwarf_Fde) fs_fdelist; /* List of FDE. */
278146778Ssam	Dwarf_Cie	*fs_ciearray;	/* Array of CIE. */
279146778Ssam	Dwarf_Unsigned	fs_cielen;	/* Length of CIE array. */
280146778Ssam	Dwarf_Fde	*fs_fdearray;	/* Array of FDE.*/
281146778Ssam	Dwarf_Unsigned	fs_fdelen;	/* Length of FDE array. */
282147904Ssam};
283146778Ssam
28432145Spststruct _Dwarf_Arange {
285146778Ssam	Dwarf_ArangeSet	ar_as;		/* Ptr to the set it belongs to. */
286146778Ssam	Dwarf_Unsigned	ar_address;	/* Start PC. */
287146778Ssam	Dwarf_Unsigned	ar_range;	/* PC range. */
288146778Ssam	Dwarf_Unsigned	ar_symndx;	/* First symbol index for reloc. */
289146778Ssam	Dwarf_Unsigned	ar_esymndx;	/* Second symbol index for reloc. */
290146778Ssam	Dwarf_Addr	ar_eoff;	/* Offset from second symbol. */
291146778Ssam	STAILQ_ENTRY(_Dwarf_Arange) ar_next; /* Next arange in list. */
292146778Ssam};
293146778Ssam
29432145Spststruct _Dwarf_ArangeSet {
295146778Ssam	Dwarf_Unsigned	as_length;	/* Length of the arange set. */
296146778Ssam	Dwarf_Half	as_version;	/* Version of the arange set. */
297146778Ssam	Dwarf_Off	as_cu_offset;	/* Offset of associated CU. */
298146778Ssam	Dwarf_CU	as_cu;		/* Ptr to associated CU. */
299147904Ssam	Dwarf_Small	as_addrsz;	/* Target address size. */
30032145Spst	Dwarf_Small	as_segsz;	/* Target segment size. */
30132145Spst	STAILQ_HEAD (, _Dwarf_Arange) as_arlist; /* List of ae entries. */
302146778Ssam	STAILQ_ENTRY(_Dwarf_ArangeSet) as_next; /* Next set in list. */
303147904Ssam};
304147904Ssam
305147904Ssamstruct _Dwarf_MacroSet {
306147904Ssam	Dwarf_Macro_Details *ms_mdlist; /* Array of macinfo entries. */
307147904Ssam	Dwarf_Unsigned	ms_cnt;		/* Length of the array. */
30832145Spst	STAILQ_ENTRY(_Dwarf_MacroSet) ms_next; /* Next set in list. */
30932145Spst};
310146778Ssam
311146778Ssamstruct _Dwarf_Rangelist {
312146778Ssam	Dwarf_CU	rl_cu;		/* Ptr to associated CU. */
313146778Ssam	Dwarf_Unsigned	rl_offset;	/* Offset of the rangelist. */
314146778Ssam	Dwarf_Ranges	*rl_rgarray;	/* Array of ranges. */
315146778Ssam	Dwarf_Unsigned	rl_rglen;	/* Length of the ranges array. */
316146778Ssam	STAILQ_ENTRY(_Dwarf_Rangelist) rl_next; /* Next rangelist in list. */
317146778Ssam};
318146778Ssam
319146778Ssamstruct _Dwarf_CU {
320146778Ssam	Dwarf_Debug	cu_dbg;		/* Ptr to containing dbg. */
321146778Ssam	Dwarf_Off	cu_offset;	/* Offset to the this CU. */
322146778Ssam	uint32_t	cu_length;	/* Length of CU data. */
323146778Ssam	uint16_t	cu_length_size; /* Size in bytes of the length field. */
32432145Spst	uint16_t	cu_version;	/* DWARF version. */
325146778Ssam	uint64_t	cu_abbrev_offset; /* Offset into .debug_abbrev. */
326146778Ssam	uint64_t	cu_abbrev_offset_cur; /* Current abbrev offset. */
327146778Ssam	int		cu_abbrev_loaded; /* Abbrev table parsed. */
328146778Ssam	uint64_t	cu_abbrev_cnt;	/* Abbrev entry count. */
329146778Ssam	uint64_t	cu_lineno_offset; /* Offset into .debug_lineno. */
330146778Ssam	uint8_t		cu_pointer_size;/* Number of bytes in pointer. */
331146778Ssam	uint8_t		cu_dwarf_size;	/* CU section dwarf size. */
332146778Ssam	Dwarf_Sig8	cu_type_sig;	/* Type unit's signature. */
333146778Ssam	uint64_t	cu_type_offset; /* Type unit's type offset. */
334146778Ssam	Dwarf_Off	cu_next_offset; /* Offset to the next CU. */
335146778Ssam	uint64_t	cu_1st_offset;	/* First DIE offset. */
336146778Ssam	int		cu_pass2;	/* Two pass DIE traverse. */
337146778Ssam	Dwarf_LineInfo	cu_lineinfo;	/* Ptr to Dwarf_LineInfo. */
338146778Ssam	Dwarf_Abbrev	cu_abbrev_hash; /* Abbrev hash table. */
339146778Ssam	Dwarf_Bool	cu_is_info;	/* Compilation/type unit flag. */
340146778Ssam	STAILQ_ENTRY(_Dwarf_CU) cu_next; /* Next compilation unit. */
341146778Ssam};
342146778Ssam
343146778Ssamtypedef struct _Dwarf_Section {
344146778Ssam	const char	*ds_name;	/* Section name. */
345146778Ssam	Dwarf_Small	*ds_data;	/* Section data. */
346146778Ssam	Dwarf_Unsigned	ds_addr;	/* Section virtual addr. */
347146778Ssam	Dwarf_Unsigned	ds_size;	/* Section size. */
348146778Ssam} Dwarf_Section;
349146778Ssam
350146778Ssamtypedef struct _Dwarf_P_Section {
351146778Ssam	char		*ds_name;	/* Section name. */
352146778Ssam	Dwarf_Small	*ds_data;	/* Section data. */
353146778Ssam	Dwarf_Unsigned	ds_size;	/* Section size. */
354146778Ssam	Dwarf_Unsigned	ds_cap;		/* Section capacity. */
355146778Ssam	Dwarf_Unsigned	ds_ndx;		/* ELF section index. */
356146778Ssam	Dwarf_Unsigned	ds_symndx;	/* Section symbol index. (for reloc) */
35732145Spst	STAILQ_ENTRY(_Dwarf_P_Section) ds_next; /* Next section in the list. */
35832145Spst} *Dwarf_P_Section;
35932145Spst
36032145Spsttypedef struct _Dwarf_Rel_Entry {
36132145Spst	unsigned char	dre_type;	/* Reloc type. */
36232145Spst	unsigned char	dre_length;	/* Reloc storage unit length. */
36332145Spst	Dwarf_Unsigned	dre_offset;	/* Reloc storage unit offset. */
36432145Spst	Dwarf_Unsigned	dre_addend;	/* Reloc addend. */
36532145Spst	Dwarf_Unsigned	dre_symndx;	/* Reloc symbol index. */
36632145Spst	const char	*dre_secname;	/* Refer to some debug section. */
36732145Spst	STAILQ_ENTRY(_Dwarf_Rel_Entry) dre_next; /* Next reloc entry. */
36832145Spst} *Dwarf_Rel_Entry;
36932145Spst
37032145Spsttypedef struct _Dwarf_Rel_Section {
37132145Spst	struct _Dwarf_P_Section *drs_ds; /* Ptr to actual reloc ELF section. */
37232145Spst	struct _Dwarf_P_Section *drs_ref; /* Which debug section it refers. */
37332145Spst	struct Dwarf_Relocation_Data_s *drs_drd; /* Reloc data array. */
37432145Spst	STAILQ_HEAD(, _Dwarf_Rel_Entry) drs_dre; /* Reloc entry list. */
37532145Spst	Dwarf_Unsigned	drs_drecnt;	/* Count of entries. */
37632145Spst	Dwarf_Unsigned	drs_size;	/* Size of ELF section in bytes. */
37732145Spst	int		drs_addend;	/* Elf_Rel or Elf_Rela */
37832145Spst	STAILQ_ENTRY(_Dwarf_Rel_Section) drs_next; /* Next reloc section. */
37932145Spst} *Dwarf_Rel_Section;
38032145Spst
38132145Spsttypedef struct {
38232145Spst	Elf_Data *ed_data;
38332145Spst	void *ed_alloc;
38432145Spst} Dwarf_Elf_Data;
38532145Spst
38632145Spsttypedef struct {
38732145Spst	Elf		*eo_elf;
38832145Spst	GElf_Ehdr	eo_ehdr;
38932145Spst	GElf_Shdr	*eo_shdr;
39032145Spst	Dwarf_Elf_Data	*eo_data;
39132145Spst	Dwarf_Unsigned	eo_seccnt;
39232145Spst	size_t		eo_strndx;
39332145Spst	Dwarf_Obj_Access_Methods eo_methods;
39432145Spst} Dwarf_Elf_Object;
39532145Spst
39632145Spststruct _Dwarf_Debug {
39732145Spst	Dwarf_Obj_Access_Interface *dbg_iface;
39832145Spst	Dwarf_Section	*dbg_section;	/* Dwarf section list. */
39932145Spst	Dwarf_Section	*dbg_info_sec;	/* Pointer to info section. */
40032145Spst	Dwarf_Off	dbg_info_off;	/* Current info section offset. */
40132145Spst	Dwarf_Section	*dbg_types_sec; /* Pointer to type section. */
40232145Spst	Dwarf_Off	dbg_types_off;	/* Current types section offset. */
40332145Spst	Dwarf_Unsigned	dbg_seccnt;	/* Total number of dwarf sections. */
40432145Spst	int		dbg_mode;	/* Access mode. */
40532145Spst	int		dbg_pointer_size; /* Object address size. */
406146778Ssam	int		dbg_offset_size;  /* DWARF offset size. */
407146778Ssam	int		dbg_info_loaded; /* Flag indicating all CU loaded. */
408146778Ssam	int		dbg_types_loaded; /* Flag indicating all TU loaded. */
409146778Ssam	Dwarf_Half	dbg_machine;	/* ELF machine architecture. */
410146778Ssam	Dwarf_Handler	dbg_errhand;	/* Error handler. */
411146778Ssam	Dwarf_Ptr	dbg_errarg;	/* Argument to the error handler. */
412146778Ssam	STAILQ_HEAD(, _Dwarf_CU) dbg_cu;/* List of compilation units. */
413146778Ssam	STAILQ_HEAD(, _Dwarf_CU) dbg_tu;/* List of type units. */
414146778Ssam	Dwarf_CU	dbg_cu_current; /* Ptr to the current CU. */
415146778Ssam	Dwarf_CU	dbg_tu_current; /* Ptr to the current TU. */
416146778Ssam	Dwarf_NameSec	dbg_globals;	/* Ptr to pubnames lookup section. */
417146778Ssam	Dwarf_NameSec	dbg_pubtypes;	/* Ptr to pubtypes lookup section. */
418146778Ssam	Dwarf_NameSec	dbg_weaks;	/* Ptr to weaknames lookup section. */
419146778Ssam	Dwarf_NameSec	dbg_funcs;	/* Ptr to static funcs lookup sect. */
420146778Ssam	Dwarf_NameSec	dbg_vars;	/* Ptr to static vars lookup sect. */
421146778Ssam	Dwarf_NameSec	dbg_types;	/* Ptr to types lookup section. */
422146778Ssam	Dwarf_FrameSec	dbg_frame;	/* Ptr to .debug_frame section. */
42332145Spst	Dwarf_FrameSec	dbg_eh_frame;	/* Ptr to .eh_frame section. */
424146778Ssam	STAILQ_HEAD(, _Dwarf_ArangeSet) dbg_aslist; /* List of arange set. */
425146778Ssam	Dwarf_Arange	*dbg_arange_array; /* Array of arange. */
426146778Ssam	Dwarf_Unsigned	dbg_arange_cnt;	/* Length of the arange array. */
427146778Ssam	char		*dbg_strtab;	/* Dwarf string table. */
428146778Ssam	Dwarf_Unsigned	dbg_strtab_cap; /* Dwarf string table capacity. */
429146778Ssam	Dwarf_Unsigned	dbg_strtab_size; /* Dwarf string table size. */
430146778Ssam	STAILQ_HEAD(, _Dwarf_MacroSet) dbg_mslist; /* List of macro set. */
431146778Ssam	STAILQ_HEAD(, _Dwarf_Rangelist) dbg_rllist; /* List of rangelist. */
432146778Ssam	uint64_t	(*read)(uint8_t *, uint64_t *, int);
433146778Ssam	void		(*write)(uint8_t *, uint64_t *, uint64_t, int);
434146778Ssam	int		(*write_alloc)(uint8_t **, uint64_t *, uint64_t *,
435146778Ssam			    uint64_t, int, Dwarf_Error *);
436146778Ssam	uint64_t	(*decode)(uint8_t **, int);
437146778Ssam
438146778Ssam	Dwarf_Half	dbg_frame_rule_table_size;
439146778Ssam	Dwarf_Half	dbg_frame_rule_initial_value;
440146778Ssam	Dwarf_Half	dbg_frame_cfa_value;
441146778Ssam	Dwarf_Half	dbg_frame_same_value;
442146778Ssam	Dwarf_Half	dbg_frame_undefined_value;
443146778Ssam
44432145Spst	Dwarf_Regtable3	*dbg_internal_reg_table;
44532145Spst
446146778Ssam	/*
447146778Ssam	 * Fields used by libdwarf producer.
448146778Ssam	 */
44932145Spst
450146778Ssam	Dwarf_Unsigned	dbgp_flags;
451146778Ssam	Dwarf_Unsigned	dbgp_isa;
452146778Ssam	Dwarf_Callback_Func dbgp_func;
453146778Ssam	Dwarf_Callback_Func_b dbgp_func_b;
454146778Ssam	Dwarf_Die	dbgp_root_die;
455146778Ssam	STAILQ_HEAD(, _Dwarf_Die) dbgp_dielist;
45632145Spst	STAILQ_HEAD(, _Dwarf_P_Expr) dbgp_pelist;
457146778Ssam	Dwarf_LineInfo	dbgp_lineinfo;
458146778Ssam	Dwarf_ArangeSet dbgp_as;
459146778Ssam	Dwarf_Macro_Details *dbgp_mdlist;
460146778Ssam	Dwarf_Unsigned	dbgp_mdcnt;
461146778Ssam	STAILQ_HEAD(, _Dwarf_Cie) dbgp_cielist;
462146778Ssam	STAILQ_HEAD(, _Dwarf_Fde) dbgp_fdelist;
463146778Ssam	Dwarf_Unsigned	dbgp_cielen;
464146778Ssam	Dwarf_Unsigned	dbgp_fdelen;
465146778Ssam	Dwarf_NameTbl	dbgp_pubs;
466146778Ssam	Dwarf_NameTbl	dbgp_weaks;
467146778Ssam	Dwarf_NameTbl	dbgp_funcs;
468146778Ssam	Dwarf_NameTbl	dbgp_types;
469146778Ssam	Dwarf_NameTbl	dbgp_vars;
470146778Ssam	STAILQ_HEAD(, _Dwarf_P_Section) dbgp_seclist;
471146778Ssam	Dwarf_Unsigned	dbgp_seccnt;
472146778Ssam	Dwarf_P_Section	dbgp_secpos;
473146778Ssam	Dwarf_P_Section	dbgp_info;
474146778Ssam	STAILQ_HEAD(, _Dwarf_Rel_Section) dbgp_drslist;
47532145Spst	Dwarf_Unsigned	dbgp_drscnt;
47632145Spst	Dwarf_Rel_Section dbgp_drspos;
47732145Spst};
478146778Ssam
479146778Ssam/*
480146778Ssam * Internal function prototypes.
481146778Ssam */
48232145Spst
483147904Ssamint		_dwarf_abbrev_add(Dwarf_CU, uint64_t, uint64_t, uint8_t,
484147904Ssam		    uint64_t, Dwarf_Abbrev *, Dwarf_Error *);
485147904Ssamvoid		_dwarf_abbrev_cleanup(Dwarf_CU);
486147904Ssamint		_dwarf_abbrev_find(Dwarf_CU, uint64_t, Dwarf_Abbrev *,
487147904Ssam		    Dwarf_Error *);
488147904Ssamint		_dwarf_abbrev_gen(Dwarf_P_Debug, Dwarf_Error *);
489147904Ssamint		_dwarf_abbrev_parse(Dwarf_Debug, Dwarf_CU, Dwarf_Unsigned *,
490147904Ssam		    Dwarf_Abbrev *, Dwarf_Error *);
491147904Ssamint		_dwarf_add_AT_dataref(Dwarf_P_Debug, Dwarf_P_Die, Dwarf_Half,
492147904Ssam		    Dwarf_Unsigned, Dwarf_Unsigned, const char *,
493147904Ssam		    Dwarf_P_Attribute *, Dwarf_Error *);
494147904Ssamint		_dwarf_add_string_attr(Dwarf_P_Die, Dwarf_P_Attribute *,
495147904Ssam		    Dwarf_Half, char *, Dwarf_Error *);
496147904Ssamint		_dwarf_alloc(Dwarf_Debug *, int, Dwarf_Error *);
497147904Ssamvoid		_dwarf_arange_cleanup(Dwarf_Debug);
498147904Ssamint		_dwarf_arange_gen(Dwarf_P_Debug, Dwarf_Error *);
499147904Ssamint		_dwarf_arange_init(Dwarf_Debug, Dwarf_Error *);
500147904Ssamvoid		_dwarf_arange_pro_cleanup(Dwarf_P_Debug);
501147904Ssamint		_dwarf_attr_alloc(Dwarf_Die, Dwarf_Attribute *, Dwarf_Error *);
502147904SsamDwarf_Attribute	_dwarf_attr_find(Dwarf_Die, Dwarf_Half);
503147904Ssamint		_dwarf_attr_gen(Dwarf_P_Debug, Dwarf_P_Section, Dwarf_Rel_Section,
504147904Ssam		    Dwarf_CU, Dwarf_Die, int, Dwarf_Error *);
505147904Ssamint		_dwarf_attr_init(Dwarf_Debug, Dwarf_Section *, uint64_t *, int,
506147904Ssam		    Dwarf_CU, Dwarf_Die, Dwarf_AttrDef, uint64_t, int,
507147904Ssam		    Dwarf_Error *);
508147904Ssamint		_dwarf_attrdef_add(Dwarf_Debug, Dwarf_Abbrev, uint64_t,
50932145Spst		    uint64_t, uint64_t, Dwarf_AttrDef *, Dwarf_Error *);
510146778Ssamuint64_t	_dwarf_decode_lsb(uint8_t **, int);
51132145Spstuint64_t	_dwarf_decode_msb(uint8_t **, int);
51232145Spstint64_t		_dwarf_decode_sleb128(uint8_t **);
51332145Spstuint64_t	_dwarf_decode_uleb128(uint8_t **);
514146778Ssamvoid		_dwarf_deinit(Dwarf_Debug);
515146778Ssamint		_dwarf_die_alloc(Dwarf_Debug, Dwarf_Die *, Dwarf_Error *);
516147904Ssamint		_dwarf_die_count_links(Dwarf_P_Die, Dwarf_P_Die,
517146778Ssam		    Dwarf_P_Die, Dwarf_P_Die);
518146778SsamDwarf_Die	_dwarf_die_find(Dwarf_Die, Dwarf_Unsigned);
519146778Ssamint		_dwarf_die_gen(Dwarf_P_Debug, Dwarf_CU, Dwarf_Rel_Section,
520146778Ssam		    Dwarf_Error *);
521146778Ssamvoid		_dwarf_die_link(Dwarf_P_Die, Dwarf_P_Die, Dwarf_P_Die,
522146778Ssam		    Dwarf_P_Die, Dwarf_P_Die);
523146778Ssamint		_dwarf_die_parse(Dwarf_Debug, Dwarf_Section *, Dwarf_CU, int,
524146778Ssam		    uint64_t, uint64_t, Dwarf_Die *, int, Dwarf_Error *);
525146778Ssamvoid		_dwarf_die_pro_cleanup(Dwarf_P_Debug);
526146778Ssamvoid		_dwarf_elf_deinit(Dwarf_Debug);
52732145Spstint		_dwarf_elf_init(Dwarf_Debug, Elf *, Dwarf_Error *);
528146778Ssamint		_dwarf_elf_load_section(void *, Dwarf_Half, Dwarf_Small **,
52932145Spst		    int *);
53032145SpstDwarf_Endianness _dwarf_elf_get_byte_order(void *);
531147904SsamDwarf_Small	_dwarf_elf_get_length_size(void *);
532146778SsamDwarf_Small	_dwarf_elf_get_pointer_size(void *);
533146778SsamDwarf_Unsigned	_dwarf_elf_get_section_count(void *);
534146778Ssamint		_dwarf_elf_get_section_info(void *, Dwarf_Half,
535146778Ssam		    Dwarf_Obj_Access_Section *, int *);
536146778Ssamvoid		_dwarf_expr_cleanup(Dwarf_P_Debug);
537146778Ssamint		_dwarf_expr_into_block(Dwarf_P_Expr, Dwarf_Error *);
538146778SsamDwarf_Section	*_dwarf_find_next_types_section(Dwarf_Debug, Dwarf_Section *);
539146778SsamDwarf_Section	*_dwarf_find_section(Dwarf_Debug, const char *);
540146778Ssamvoid		_dwarf_frame_cleanup(Dwarf_Debug);
541146778Ssamint		_dwarf_frame_fde_add_inst(Dwarf_P_Fde, Dwarf_Small,
542146778Ssam		    Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Error *);
543146778Ssamint		_dwarf_frame_gen(Dwarf_P_Debug, Dwarf_Error *);
544146778Ssamint		_dwarf_frame_get_fop(Dwarf_Debug, uint8_t, uint8_t *,
545146778Ssam		    Dwarf_Unsigned, Dwarf_Frame_Op **, Dwarf_Signed *,
546146778Ssam		    Dwarf_Error *);
547146778Ssamint		_dwarf_frame_get_internal_table(Dwarf_Fde, Dwarf_Addr,
548146778Ssam		    Dwarf_Regtable3 **, Dwarf_Addr *, Dwarf_Error *);
549146778Ssamint		_dwarf_frame_interal_table_init(Dwarf_Debug, Dwarf_Error *);
55032145Spstvoid		_dwarf_frame_params_init(Dwarf_Debug);
551146778Ssamvoid		_dwarf_frame_pro_cleanup(Dwarf_P_Debug);
552146778Ssamint		_dwarf_frame_regtable_copy(Dwarf_Debug, Dwarf_Regtable3 **,
55332145Spst		    Dwarf_Regtable3 *, Dwarf_Error *);
55432145Spstint		_dwarf_frame_section_load(Dwarf_Debug, Dwarf_Error *);
555146778Ssamint		_dwarf_frame_section_load_eh(Dwarf_Debug, Dwarf_Error *);
55632145Spstint		_dwarf_generate_sections(Dwarf_P_Debug, Dwarf_Error *);
557146778SsamDwarf_Unsigned	_dwarf_get_reloc_type(Dwarf_P_Debug, int);
558146778Ssamint		_dwarf_get_reloc_size(Dwarf_Debug, Dwarf_Unsigned);
559146778Ssamvoid		_dwarf_info_cleanup(Dwarf_Debug);
560146778Ssamint		_dwarf_info_first_cu(Dwarf_Debug, Dwarf_Error *);
561146778Ssamint		_dwarf_info_first_tu(Dwarf_Debug, Dwarf_Error *);
562146778Ssamint		_dwarf_info_gen(Dwarf_P_Debug, Dwarf_Error *);
563146778Ssamint		_dwarf_info_load(Dwarf_Debug, Dwarf_Bool, Dwarf_Bool,
56432145Spst		    Dwarf_Error *);
56532145Spstint		_dwarf_info_next_cu(Dwarf_Debug, Dwarf_Error *);
566146778Ssamint		_dwarf_info_next_tu(Dwarf_Debug, Dwarf_Error *);
567146778Ssamvoid		_dwarf_info_pro_cleanup(Dwarf_P_Debug);
568146778Ssamint		_dwarf_init(Dwarf_Debug, Dwarf_Unsigned, Dwarf_Handler,
569146778Ssam		    Dwarf_Ptr, Dwarf_Error *);
570146778Ssamint		_dwarf_lineno_gen(Dwarf_P_Debug, Dwarf_Error *);
571146778Ssamint		_dwarf_lineno_init(Dwarf_Die, uint64_t, Dwarf_Error *);
572146778Ssamvoid		_dwarf_lineno_cleanup(Dwarf_LineInfo);
573146778Ssamvoid		_dwarf_lineno_pro_cleanup(Dwarf_P_Debug);
574146778Ssamint		_dwarf_loc_fill_locdesc(Dwarf_Debug, Dwarf_Locdesc *,
575147904Ssam		    uint8_t *, uint64_t, uint8_t, uint8_t, uint8_t,
576147904Ssam		    Dwarf_Error *);
577146778Ssamint		_dwarf_loc_fill_locexpr(Dwarf_Debug, Dwarf_Locdesc **,
578146778Ssam		    uint8_t *, uint64_t, uint8_t, uint8_t, uint8_t,
579146778Ssam		    Dwarf_Error *);
58032145Spstint		_dwarf_loc_add(Dwarf_Die, Dwarf_Attribute, Dwarf_Error *);
581146778Ssamint		_dwarf_loc_expr_add_atom(Dwarf_Debug, uint8_t *, uint8_t *,
582146778Ssam		    Dwarf_Small, Dwarf_Unsigned, Dwarf_Unsigned, int *,
583146778Ssam		    Dwarf_Error *);
58432145Spstint		_dwarf_loclist_find(Dwarf_Debug, Dwarf_CU, uint64_t,
585146778Ssam		    Dwarf_Locdesc ***, Dwarf_Signed *, Dwarf_Unsigned *,
586146778Ssam		    Dwarf_Error *);
587146778Ssamvoid		_dwarf_macinfo_cleanup(Dwarf_Debug);
588146778Ssamint		_dwarf_macinfo_gen(Dwarf_P_Debug, Dwarf_Error *);
589146778Ssamint		_dwarf_macinfo_init(Dwarf_Debug, Dwarf_Error *);
590146778Ssamvoid		_dwarf_macinfo_pro_cleanup(Dwarf_P_Debug);
591147904Ssamint		_dwarf_nametbl_init(Dwarf_Debug, Dwarf_NameSec *,
592147904Ssam		    Dwarf_Section *, Dwarf_Error *);
593147904Ssamvoid		_dwarf_nametbl_cleanup(Dwarf_NameSec *);
594147904Ssamint		_dwarf_nametbl_gen(Dwarf_P_Debug, const char *, Dwarf_NameTbl,
595147904Ssam		    Dwarf_Error *);
596147904Ssamvoid		_dwarf_nametbl_pro_cleanup(Dwarf_NameTbl *);
597147904Ssamint		_dwarf_pro_callback(Dwarf_P_Debug, char *, int, Dwarf_Unsigned,
598147904Ssam		    Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned,
599147904Ssam		    Dwarf_Unsigned *, int *);
600147904SsamDwarf_P_Section	_dwarf_pro_find_section(Dwarf_P_Debug, const char *);
601147904Ssamint		_dwarf_ranges_add(Dwarf_Debug, Dwarf_CU, uint64_t,
602147904Ssam		    Dwarf_Rangelist *, Dwarf_Error *);
603147904Ssamvoid		_dwarf_ranges_cleanup(Dwarf_Debug);
604147904Ssamint		_dwarf_ranges_find(Dwarf_Debug, uint64_t, Dwarf_Rangelist *);
605147904Ssamuint64_t	_dwarf_read_lsb(uint8_t *, uint64_t *, int);
606147904Ssamuint64_t	_dwarf_read_msb(uint8_t *, uint64_t *, int);
607147904Ssamint64_t		_dwarf_read_sleb128(uint8_t *, uint64_t *);
608147904Ssamuint64_t	_dwarf_read_uleb128(uint8_t *, uint64_t *);
609147904Ssamchar		*_dwarf_read_string(void *, Dwarf_Unsigned, uint64_t *);
610147904Ssamuint8_t		*_dwarf_read_block(void *, uint64_t *, uint64_t);
611147904Ssamint		_dwarf_reloc_section_finalize(Dwarf_P_Debug, Dwarf_Rel_Section,
612147904Ssam		    Dwarf_Error *);
613147904Ssamint		_dwarf_reloc_entry_add(Dwarf_P_Debug, Dwarf_Rel_Section,
614147904Ssam		    Dwarf_P_Section, unsigned char, unsigned char,
615147904Ssam		    Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned,
616147904Ssam		    const char *, Dwarf_Error *);
617147904Ssamint		_dwarf_reloc_entry_add_pair(Dwarf_P_Debug, Dwarf_Rel_Section,
618147904Ssam		    Dwarf_P_Section, unsigned char, Dwarf_Unsigned,
619147904Ssam		    Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned,
620147904Ssam		    Dwarf_Unsigned, Dwarf_Error *);
621147904Ssamvoid		_dwarf_reloc_cleanup(Dwarf_P_Debug);
622147904Ssamint		_dwarf_reloc_gen(Dwarf_P_Debug, Dwarf_Error *);
623147904Ssamint		_dwarf_reloc_section_gen(Dwarf_P_Debug, Dwarf_Rel_Section,
624147904Ssam		    Dwarf_Error *);
625147904Ssamint		_dwarf_reloc_section_init(Dwarf_P_Debug, Dwarf_Rel_Section *,
626147904Ssam		    Dwarf_P_Section, Dwarf_Error *);
627147904Ssamvoid		_dwarf_reloc_section_free(Dwarf_P_Debug, Dwarf_Rel_Section *);
628147904Ssamvoid		_dwarf_section_cleanup(Dwarf_P_Debug);
629147904Ssamint		_dwarf_section_callback(Dwarf_P_Debug, Dwarf_P_Section,
630147904Ssam		    Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned,
631147904Ssam		    Dwarf_Unsigned, Dwarf_Error *);
632147904Ssamvoid		_dwarf_section_free(Dwarf_P_Debug, Dwarf_P_Section *);
633147904Ssamint		_dwarf_section_init(Dwarf_P_Debug, Dwarf_P_Section *,
634147904Ssam		    const char *, int, Dwarf_Error *);
635147904Ssamvoid		_dwarf_set_error(Dwarf_Debug, Dwarf_Error *, int, int,
636147904Ssam		    const char *, int);
637147904Ssamint		_dwarf_strtab_add(Dwarf_Debug, char *, uint64_t *,
638147904Ssam		    Dwarf_Error *);
639147904Ssamvoid		_dwarf_strtab_cleanup(Dwarf_Debug);
640147904Ssamint		_dwarf_strtab_gen(Dwarf_P_Debug, Dwarf_Error *);
641147904Ssamchar		*_dwarf_strtab_get_table(Dwarf_Debug);
642147904Ssamint		_dwarf_strtab_init(Dwarf_Debug, Dwarf_Error *);
643147904Ssamvoid		_dwarf_type_unit_cleanup(Dwarf_Debug);
644void		_dwarf_write_block(void *, uint64_t *, uint8_t *, uint64_t);
645int		_dwarf_write_block_alloc(uint8_t **, uint64_t *, uint64_t *,
646		    uint8_t *, uint64_t, Dwarf_Error *);
647void		_dwarf_write_lsb(uint8_t *, uint64_t *, uint64_t, int);
648int		_dwarf_write_lsb_alloc(uint8_t **, uint64_t *, uint64_t *,
649		    uint64_t, int, Dwarf_Error *);
650void		_dwarf_write_msb(uint8_t *, uint64_t *, uint64_t, int);
651int		_dwarf_write_msb_alloc(uint8_t **, uint64_t *, uint64_t *,
652		    uint64_t, int, Dwarf_Error *);
653void		_dwarf_write_padding(void *, uint64_t *, uint8_t, uint64_t);
654int		_dwarf_write_padding_alloc(uint8_t **, uint64_t *, uint64_t *,
655		    uint8_t, uint64_t, Dwarf_Error *);
656void		_dwarf_write_string(void *, uint64_t *, char *);
657int		_dwarf_write_string_alloc(uint8_t **, uint64_t *, uint64_t *,
658		    char *, Dwarf_Error *);
659int		_dwarf_write_sleb128(uint8_t *, uint8_t *, int64_t);
660int		_dwarf_write_sleb128_alloc(uint8_t **, uint64_t *, uint64_t *,
661		    int64_t, Dwarf_Error *);
662int		_dwarf_write_uleb128(uint8_t *, uint8_t *, uint64_t);
663int		_dwarf_write_uleb128_alloc(uint8_t **, uint64_t *, uint64_t *,
664		    uint64_t, Dwarf_Error *);
665
666#endif /* !__LIBDWARF_H_ */
667