1/*- 2 * Copyright (c) 2007 John Birrell (jb@freebsd.org) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29#ifndef _LIBDWARF_H_ 30#define _LIBDWARF_H_ 31 32#include <libelf.h> 33 34typedef int Dwarf_Bool; 35typedef off_t Dwarf_Off; 36typedef uint64_t Dwarf_Unsigned; 37typedef uint16_t Dwarf_Half; 38typedef uint8_t Dwarf_Small; 39typedef int64_t Dwarf_Signed; 40typedef uint64_t Dwarf_Addr; 41typedef void *Dwarf_Ptr; 42 43/* Forward definitions. */ 44typedef struct _Dwarf_Abbrev *Dwarf_Abbrev; 45typedef struct _Dwarf_Arange *Dwarf_Arange; 46typedef struct _Dwarf_Attribute *Dwarf_Attribute; 47typedef struct _Dwarf_AttrValue *Dwarf_AttrValue; 48typedef struct _Dwarf_CU *Dwarf_CU; 49typedef struct _Dwarf_Cie *Dwarf_Cie; 50typedef struct _Dwarf_Debug *Dwarf_Debug; 51typedef struct _Dwarf_Die *Dwarf_Die; 52typedef struct _Dwarf_Fde *Dwarf_Fde; 53typedef struct _Dwarf_Func *Dwarf_Func; 54typedef struct _Dwarf_Inlined_Func *Dwarf_Inlined_Func; 55typedef struct _Dwarf_Global *Dwarf_Global; 56typedef struct _Dwarf_Line *Dwarf_Line; 57typedef struct _Dwarf_Type *Dwarf_Type; 58typedef struct _Dwarf_Var *Dwarf_Var; 59typedef struct _Dwarf_Weak *Dwarf_Weak; 60 61typedef struct { 62 Dwarf_Small lr_atom; 63 Dwarf_Unsigned lr_number; 64 Dwarf_Unsigned lr_number2; 65 Dwarf_Unsigned lr_offset; 66} Dwarf_Loc; 67 68typedef struct { 69 Dwarf_Addr ld_lopc; 70 Dwarf_Addr ld_hipc; 71 Dwarf_Half ld_cents; 72 Dwarf_Loc *ld_s; 73} Dwarf_Locdesc; 74 75/* receiver function for dwarf_function_iterate_inlined_instance() API */ 76typedef void (*Dwarf_Inlined_Callback)(Dwarf_Inlined_Func, void *); 77 78/* 79 * Error numbers which are specific to this implementation. 80 */ 81enum { 82 DWARF_E_NONE, /* No error. */ 83 DWARF_E_ERROR, /* An error! */ 84 DWARF_E_NO_ENTRY, /* No entry. */ 85 DWARF_E_ARGUMENT, /* Invalid argument. */ 86 DWARF_E_DEBUG_INFO, /* Debug info NULL. */ 87 DWARF_E_MEMORY, /* Insufficient memory. */ 88 DWARF_E_ELF, /* ELF error. */ 89 DWARF_E_INVALID_CU, /* Invalid compilation unit data. */ 90 DWARF_E_CU_VERSION, /* Wrong CU version. */ 91 DWARF_E_MISSING_ABBREV, /* Abbrev not found. */ 92 DWARF_E_NOT_IMPLEMENTED, /* Not implemented. */ 93 DWARF_E_CU_CURRENT, /* No current compilation unit. */ 94 DWARF_E_BAD_FORM, /* Wrong form type for attribute value. */ 95 DWARF_E_INVALID_EXPR, /* Invalid DWARF expression. */ 96 DWARF_E_NUM /* Max error number. */ 97}; 98 99typedef struct _Dwarf_Error { 100 int err_error; /* DWARF error. */ 101 int elf_error; /* ELF error. */ 102 const char *err_func; /* Function name where error occurred. */ 103 int err_line; /* Line number where error occurred. */ 104 char err_msg[1024]; /* Formatted error message. */ 105} Dwarf_Error; 106 107/* 108 * Return values which have to be compatible with other 109 * implementations of libdwarf. 110 */ 111#define DW_DLV_NO_ENTRY DWARF_E_NO_ENTRY 112#define DW_DLV_OK DWARF_E_NONE 113#define DW_DLE_DEBUG_INFO_NULL DWARF_E_DEBUG_INFO 114 115#define DW_DLC_READ 0 /* read only access */ 116 117/* Function prototype definitions. */ 118__BEGIN_DECLS 119Dwarf_Abbrev dwarf_abbrev_find(Dwarf_CU, uint64_t); 120Dwarf_AttrValue dwarf_attrval_find(Dwarf_Die, Dwarf_Half); 121Dwarf_Die dwarf_die_find(Dwarf_Die, Dwarf_Unsigned); 122const char *dwarf_errmsg(Dwarf_Error *); 123const char *get_sht_desc(uint32_t); 124const char *get_attr_desc(uint32_t); 125const char *get_form_desc(uint32_t); 126const char *get_tag_desc(uint32_t); 127int dwarf_abbrev_add(Dwarf_CU, uint64_t, uint64_t, uint8_t, Dwarf_Abbrev *, Dwarf_Error *); 128int dwarf_attr(Dwarf_Die, Dwarf_Half, Dwarf_Attribute *, Dwarf_Error *); 129int dwarf_attr_add(Dwarf_Abbrev, uint64_t, uint64_t, Dwarf_Attribute *, Dwarf_Error *); 130int dwarf_attrval(Dwarf_Die, Dwarf_Half, Dwarf_AttrValue *, Dwarf_Error *); 131int dwarf_attrval_add(Dwarf_Die, Dwarf_AttrValue, Dwarf_AttrValue *, Dwarf_Error *); 132int dwarf_attrval_flag(Dwarf_Die, uint64_t, Dwarf_Bool *, Dwarf_Error *); 133int dwarf_attrval_signed(Dwarf_Die, uint64_t, Dwarf_Signed *, Dwarf_Error *); 134int dwarf_attrval_string(Dwarf_Die, uint64_t, const char **, Dwarf_Error *); 135int dwarf_attrval_unsigned(Dwarf_Die, uint64_t, Dwarf_Unsigned *, Dwarf_Error *); 136int dwarf_child(Dwarf_Die, Dwarf_Die *, Dwarf_Error *); 137int dwarf_die_add(Dwarf_CU, int, uint64_t, uint64_t, Dwarf_Abbrev, Dwarf_Die *, Dwarf_Error *); 138int dwarf_dieoffset(Dwarf_Die, Dwarf_Off *, Dwarf_Error *); 139int dwarf_elf_init(Elf *, int, Dwarf_Debug *, Dwarf_Error *); 140int dwarf_errno(Dwarf_Error *); 141int dwarf_finish(Dwarf_Debug *, Dwarf_Error *); 142int dwarf_locdesc(Dwarf_Die, uint64_t, Dwarf_Locdesc **, Dwarf_Signed *, Dwarf_Error *); 143int dwarf_locdesc_free(Dwarf_Locdesc *, Dwarf_Error *); 144int dwarf_init(int, int, Dwarf_Debug *, Dwarf_Error *); 145int dwarf_next_cu_header(Dwarf_Debug, Dwarf_Unsigned *, Dwarf_Half *, 146 Dwarf_Unsigned *, Dwarf_Half *, Dwarf_Unsigned *, Dwarf_Error *); 147int dwarf_op_num(uint8_t, uint8_t *, int); 148int dwarf_siblingof(Dwarf_Debug, Dwarf_Die, Dwarf_Die *, Dwarf_Error *); 149int dwarf_tag(Dwarf_Die, Dwarf_Half *, Dwarf_Error *); 150int dwarf_whatform(Dwarf_Attribute, Dwarf_Half *, Dwarf_Error *); 151void dwarf_dealloc(Dwarf_Debug, Dwarf_Ptr, Dwarf_Unsigned); 152void dwarf_dump(Dwarf_Debug); 153void dwarf_dump_abbrev(Dwarf_Debug); 154void dwarf_dump_av(Dwarf_Die, Dwarf_AttrValue); 155void dwarf_dump_dbgstr(Dwarf_Debug); 156void dwarf_dump_die(Dwarf_Die); 157void dwarf_dump_die_at_offset(Dwarf_Debug, Dwarf_Off); 158void dwarf_dump_info(Dwarf_Debug); 159void dwarf_dump_shstrtab(Dwarf_Debug); 160void dwarf_dump_strtab(Dwarf_Debug); 161void dwarf_dump_symtab(Dwarf_Debug); 162void dwarf_dump_raw(Dwarf_Debug); 163void dwarf_dump_tree(Dwarf_Debug); 164Dwarf_Func dwarf_find_function_by_offset(Dwarf_Debug dbg, Dwarf_Off off); 165Dwarf_Func dwarf_find_function_by_name(Dwarf_Debug dbg, const char *name); 166int dwarf_function_get_addr_range(Dwarf_Func f, 167 Dwarf_Addr *low_pc, Dwarf_Addr *high_pc); 168int dwarf_function_is_inlined(Dwarf_Func f); 169void dwarf_function_iterate_inlined_instance(Dwarf_Func func, 170 Dwarf_Inlined_Callback f, void *data); 171int dwarf_inlined_function_get_addr_range(Dwarf_Inlined_Func f, 172 Dwarf_Addr *low_pc, Dwarf_Addr *high_pc); 173 174__END_DECLS 175 176#endif /* !_LIBDWARF_H_ */ 177