2 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 typedef int Dwarf_Bool;
35 typedef off_t Dwarf_Off;
36 typedef uint64_t Dwarf_Unsigned;
37 typedef uint16_t Dwarf_Half;
38 typedef uint8_t Dwarf_Small;
39 typedef int64_t Dwarf_Signed;
40 typedef uint64_t Dwarf_Addr;
41 typedef void *Dwarf_Ptr;
43 /* Forward definitions. */
44 typedef struct _Dwarf_Abbrev *Dwarf_Abbrev;
45 typedef struct _Dwarf_Arange *Dwarf_Arange;
46 typedef struct _Dwarf_Attribute *Dwarf_Attribute;
47 typedef struct _Dwarf_AttrValue *Dwarf_AttrValue;
48 typedef struct _Dwarf_CU *Dwarf_CU;
49 typedef struct _Dwarf_Cie *Dwarf_Cie;
50 typedef struct _Dwarf_Debug *Dwarf_Debug;
51 typedef struct _Dwarf_Die *Dwarf_Die;
52 typedef struct _Dwarf_Fde *Dwarf_Fde;
53 typedef struct _Dwarf_Func *Dwarf_Func;
54 typedef struct _Dwarf_Global *Dwarf_Global;
55 typedef struct _Dwarf_Line *Dwarf_Line;
56 typedef struct _Dwarf_Type *Dwarf_Type;
57 typedef struct _Dwarf_Var *Dwarf_Var;
58 typedef struct _Dwarf_Weak *Dwarf_Weak;
62 Dwarf_Unsigned lr_number;
63 Dwarf_Unsigned lr_number2;
64 Dwarf_Unsigned lr_offset;
75 * Error numbers which are specific to this implementation.
78 DWARF_E_NONE, /* No error. */
79 DWARF_E_ERROR, /* An error! */
80 DWARF_E_NO_ENTRY, /* No entry. */
81 DWARF_E_ARGUMENT, /* Invalid argument. */
82 DWARF_E_DEBUG_INFO, /* Debug info NULL. */
83 DWARF_E_MEMORY, /* Insufficient memory. */
84 DWARF_E_ELF, /* ELF error. */
85 DWARF_E_INVALID_CU, /* Invalid compilation unit data. */
86 DWARF_E_CU_VERSION, /* Wrong CU version. */
87 DWARF_E_MISSING_ABBREV, /* Abbrev not found. */
88 DWARF_E_NOT_IMPLEMENTED, /* Not implemented. */
89 DWARF_E_CU_CURRENT, /* No current compilation unit. */
90 DWARF_E_BAD_FORM, /* Wrong form type for attribute value. */
91 DWARF_E_INVALID_EXPR, /* Invalid DWARF expression. */
92 DWARF_E_NUM /* Max error number. */
95 typedef struct _Dwarf_Error {
96 int err_error; /* DWARF error. */
97 int elf_error; /* ELF error. */
98 const char *err_func; /* Function name where error occurred. */
99 int err_line; /* Line number where error occurred. */
100 char err_msg[1024]; /* Formatted error message. */
104 * Return values which have to be compatible with other
105 * implementations of libdwarf.
107 #define DW_DLV_NO_ENTRY DWARF_E_NO_ENTRY
108 #define DW_DLV_OK DWARF_E_NONE
109 #define DW_DLE_DEBUG_INFO_NULL DWARF_E_DEBUG_INFO
111 #define DW_DLC_READ 0 /* read only access */
113 /* Function prototype definitions. */
115 Dwarf_Abbrev dwarf_abbrev_find(Dwarf_CU, uint64_t);
116 Dwarf_AttrValue dwarf_attrval_find(Dwarf_Die, Dwarf_Half);
117 Dwarf_Die dwarf_die_find(Dwarf_Die, Dwarf_Unsigned);
118 const char *dwarf_errmsg(Dwarf_Error *);
119 const char *get_sht_desc(uint32_t);
120 const char *get_attr_desc(uint32_t);
121 const char *get_form_desc(uint32_t);
122 const char *get_tag_desc(uint32_t);
123 int dwarf_abbrev_add(Dwarf_CU, uint64_t, uint64_t, uint8_t, Dwarf_Abbrev *, Dwarf_Error *);
124 int dwarf_attr(Dwarf_Die, Dwarf_Half, Dwarf_Attribute *, Dwarf_Error *);
125 int dwarf_attr_add(Dwarf_Abbrev, uint64_t, uint64_t, Dwarf_Attribute *, Dwarf_Error *);
126 int dwarf_attrval(Dwarf_Die, Dwarf_Half, Dwarf_AttrValue *, Dwarf_Error *);
127 int dwarf_attrval_add(Dwarf_Die, Dwarf_AttrValue, Dwarf_AttrValue *, Dwarf_Error *);
128 int dwarf_attrval_flag(Dwarf_Die, uint64_t, Dwarf_Bool *, Dwarf_Error *);
129 int dwarf_attrval_signed(Dwarf_Die, uint64_t, Dwarf_Signed *, Dwarf_Error *);
130 int dwarf_attrval_string(Dwarf_Die, uint64_t, const char **, Dwarf_Error *);
131 int dwarf_attrval_unsigned(Dwarf_Die, uint64_t, Dwarf_Unsigned *, Dwarf_Error *);
132 int dwarf_child(Dwarf_Die, Dwarf_Die *, Dwarf_Error *);
133 int dwarf_die_add(Dwarf_CU, int, uint64_t, uint64_t, Dwarf_Abbrev, Dwarf_Die *, Dwarf_Error *);
134 int dwarf_dieoffset(Dwarf_Die, Dwarf_Off *, Dwarf_Error *);
135 int dwarf_elf_init(Elf *, int, Dwarf_Debug *, Dwarf_Error *);
136 int dwarf_errno(Dwarf_Error *);
137 int dwarf_finish(Dwarf_Debug *, Dwarf_Error *);
138 int dwarf_locdesc(Dwarf_Die, uint64_t, Dwarf_Locdesc **, Dwarf_Signed *, Dwarf_Error *);
139 int dwarf_locdesc_free(Dwarf_Locdesc *, Dwarf_Error *);
140 int dwarf_init(int, int, Dwarf_Debug *, Dwarf_Error *);
141 int dwarf_next_cu_header(Dwarf_Debug, Dwarf_Unsigned *, Dwarf_Half *,
142 Dwarf_Unsigned *, Dwarf_Half *, Dwarf_Unsigned *, Dwarf_Error *);
143 int dwarf_op_num(uint8_t, uint8_t *, int);
144 int dwarf_siblingof(Dwarf_Debug, Dwarf_Die, Dwarf_Die *, Dwarf_Error *);
145 int dwarf_tag(Dwarf_Die, Dwarf_Half *, Dwarf_Error *);
146 int dwarf_whatform(Dwarf_Attribute, Dwarf_Half *, Dwarf_Error *);
147 void dwarf_dealloc(Dwarf_Debug, Dwarf_Ptr, Dwarf_Unsigned);
148 void dwarf_dump(Dwarf_Debug);
149 void dwarf_dump_abbrev(Dwarf_Debug);
150 void dwarf_dump_av(Dwarf_Die, Dwarf_AttrValue);
151 void dwarf_dump_dbgstr(Dwarf_Debug);
152 void dwarf_dump_die(Dwarf_Die);
153 void dwarf_dump_die_at_offset(Dwarf_Debug, Dwarf_Off);
154 void dwarf_dump_info(Dwarf_Debug);
155 void dwarf_dump_shstrtab(Dwarf_Debug);
156 void dwarf_dump_strtab(Dwarf_Debug);
157 void dwarf_dump_symtab(Dwarf_Debug);
158 void dwarf_dump_raw(Dwarf_Debug);
159 void dwarf_dump_tree(Dwarf_Debug);
162 #endif /* !_LIBDWARF_H_ */