1179187Sjb/*- 2179187Sjb * Copyright (c) 2007 John Birrell (jb@freebsd.org) 3179187Sjb * All rights reserved. 4179187Sjb * 5179187Sjb * Redistribution and use in source and binary forms, with or without 6179187Sjb * modification, are permitted provided that the following conditions 7179187Sjb * are met: 8179187Sjb * 1. Redistributions of source code must retain the above copyright 9179187Sjb * notice, this list of conditions and the following disclaimer. 10179187Sjb * 2. Redistributions in binary form must reproduce the above copyright 11179187Sjb * notice, this list of conditions and the following disclaimer in the 12179187Sjb * documentation and/or other materials provided with the distribution. 13179187Sjb * 14179187Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15179187Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16179187Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17179187Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18179187Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19179187Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20179187Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21179187Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22179187Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23179187Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24179187Sjb * SUCH DAMAGE. 25179187Sjb * 26179187Sjb * $FreeBSD$ 27179187Sjb */ 28179187Sjb 29179187Sjb#ifndef _LIBDWARF_H_ 30179187Sjb#define _LIBDWARF_H_ 31179187Sjb 32179187Sjb#include <libelf.h> 33179187Sjb 34179187Sjbtypedef int Dwarf_Bool; 35179187Sjbtypedef off_t Dwarf_Off; 36179187Sjbtypedef uint64_t Dwarf_Unsigned; 37179187Sjbtypedef uint16_t Dwarf_Half; 38179187Sjbtypedef uint8_t Dwarf_Small; 39179187Sjbtypedef int64_t Dwarf_Signed; 40179187Sjbtypedef uint64_t Dwarf_Addr; 41179187Sjbtypedef void *Dwarf_Ptr; 42179187Sjb 43179187Sjb/* Forward definitions. */ 44179187Sjbtypedef struct _Dwarf_Abbrev *Dwarf_Abbrev; 45179187Sjbtypedef struct _Dwarf_Arange *Dwarf_Arange; 46179187Sjbtypedef struct _Dwarf_Attribute *Dwarf_Attribute; 47179187Sjbtypedef struct _Dwarf_AttrValue *Dwarf_AttrValue; 48179187Sjbtypedef struct _Dwarf_CU *Dwarf_CU; 49179187Sjbtypedef struct _Dwarf_Cie *Dwarf_Cie; 50179187Sjbtypedef struct _Dwarf_Debug *Dwarf_Debug; 51179187Sjbtypedef struct _Dwarf_Die *Dwarf_Die; 52179187Sjbtypedef struct _Dwarf_Fde *Dwarf_Fde; 53179187Sjbtypedef struct _Dwarf_Func *Dwarf_Func; 54221569Sobrientypedef struct _Dwarf_Inlined_Func *Dwarf_Inlined_Func; 55179187Sjbtypedef struct _Dwarf_Global *Dwarf_Global; 56179187Sjbtypedef struct _Dwarf_Line *Dwarf_Line; 57179187Sjbtypedef struct _Dwarf_Type *Dwarf_Type; 58179187Sjbtypedef struct _Dwarf_Var *Dwarf_Var; 59179187Sjbtypedef struct _Dwarf_Weak *Dwarf_Weak; 60179187Sjb 61179187Sjbtypedef struct { 62179187Sjb Dwarf_Small lr_atom; 63179187Sjb Dwarf_Unsigned lr_number; 64179187Sjb Dwarf_Unsigned lr_number2; 65179187Sjb Dwarf_Unsigned lr_offset; 66179187Sjb} Dwarf_Loc; 67179187Sjb 68179187Sjbtypedef struct { 69179187Sjb Dwarf_Addr ld_lopc; 70179187Sjb Dwarf_Addr ld_hipc; 71179187Sjb Dwarf_Half ld_cents; 72179187Sjb Dwarf_Loc *ld_s; 73179187Sjb} Dwarf_Locdesc; 74179187Sjb 75221569Sobrien/* receiver function for dwarf_function_iterate_inlined_instance() API */ 76221569Sobrientypedef void (*Dwarf_Inlined_Callback)(Dwarf_Inlined_Func, void *); 77221569Sobrien 78179187Sjb/* 79179187Sjb * Error numbers which are specific to this implementation. 80179187Sjb */ 81179187Sjbenum { 82179187Sjb DWARF_E_NONE, /* No error. */ 83179187Sjb DWARF_E_ERROR, /* An error! */ 84179187Sjb DWARF_E_NO_ENTRY, /* No entry. */ 85179187Sjb DWARF_E_ARGUMENT, /* Invalid argument. */ 86179187Sjb DWARF_E_DEBUG_INFO, /* Debug info NULL. */ 87179187Sjb DWARF_E_MEMORY, /* Insufficient memory. */ 88179187Sjb DWARF_E_ELF, /* ELF error. */ 89179187Sjb DWARF_E_INVALID_CU, /* Invalid compilation unit data. */ 90179187Sjb DWARF_E_CU_VERSION, /* Wrong CU version. */ 91179187Sjb DWARF_E_MISSING_ABBREV, /* Abbrev not found. */ 92179187Sjb DWARF_E_NOT_IMPLEMENTED, /* Not implemented. */ 93179187Sjb DWARF_E_CU_CURRENT, /* No current compilation unit. */ 94179187Sjb DWARF_E_BAD_FORM, /* Wrong form type for attribute value. */ 95179187Sjb DWARF_E_INVALID_EXPR, /* Invalid DWARF expression. */ 96179187Sjb DWARF_E_NUM /* Max error number. */ 97179187Sjb}; 98179187Sjb 99179187Sjbtypedef struct _Dwarf_Error { 100179187Sjb int err_error; /* DWARF error. */ 101179187Sjb int elf_error; /* ELF error. */ 102179187Sjb const char *err_func; /* Function name where error occurred. */ 103179187Sjb int err_line; /* Line number where error occurred. */ 104179187Sjb char err_msg[1024]; /* Formatted error message. */ 105179187Sjb} Dwarf_Error; 106179187Sjb 107179187Sjb/* 108179187Sjb * Return values which have to be compatible with other 109179187Sjb * implementations of libdwarf. 110179187Sjb */ 111179187Sjb#define DW_DLV_NO_ENTRY DWARF_E_NO_ENTRY 112179187Sjb#define DW_DLV_OK DWARF_E_NONE 113179187Sjb#define DW_DLE_DEBUG_INFO_NULL DWARF_E_DEBUG_INFO 114179187Sjb 115179187Sjb#define DW_DLC_READ 0 /* read only access */ 116179187Sjb 117179187Sjb/* Function prototype definitions. */ 118179187Sjb__BEGIN_DECLS 119179187SjbDwarf_Abbrev dwarf_abbrev_find(Dwarf_CU, uint64_t); 120179187SjbDwarf_AttrValue dwarf_attrval_find(Dwarf_Die, Dwarf_Half); 121179187SjbDwarf_Die dwarf_die_find(Dwarf_Die, Dwarf_Unsigned); 122179187Sjbconst char *dwarf_errmsg(Dwarf_Error *); 123179187Sjbconst char *get_sht_desc(uint32_t); 124179187Sjbconst char *get_attr_desc(uint32_t); 125179187Sjbconst char *get_form_desc(uint32_t); 126179187Sjbconst char *get_tag_desc(uint32_t); 127179187Sjbint dwarf_abbrev_add(Dwarf_CU, uint64_t, uint64_t, uint8_t, Dwarf_Abbrev *, Dwarf_Error *); 128179187Sjbint dwarf_attr(Dwarf_Die, Dwarf_Half, Dwarf_Attribute *, Dwarf_Error *); 129179187Sjbint dwarf_attr_add(Dwarf_Abbrev, uint64_t, uint64_t, Dwarf_Attribute *, Dwarf_Error *); 130179187Sjbint dwarf_attrval(Dwarf_Die, Dwarf_Half, Dwarf_AttrValue *, Dwarf_Error *); 131179187Sjbint dwarf_attrval_add(Dwarf_Die, Dwarf_AttrValue, Dwarf_AttrValue *, Dwarf_Error *); 132179187Sjbint dwarf_attrval_flag(Dwarf_Die, uint64_t, Dwarf_Bool *, Dwarf_Error *); 133179187Sjbint dwarf_attrval_signed(Dwarf_Die, uint64_t, Dwarf_Signed *, Dwarf_Error *); 134179187Sjbint dwarf_attrval_string(Dwarf_Die, uint64_t, const char **, Dwarf_Error *); 135179187Sjbint dwarf_attrval_unsigned(Dwarf_Die, uint64_t, Dwarf_Unsigned *, Dwarf_Error *); 136179187Sjbint dwarf_child(Dwarf_Die, Dwarf_Die *, Dwarf_Error *); 137179187Sjbint dwarf_die_add(Dwarf_CU, int, uint64_t, uint64_t, Dwarf_Abbrev, Dwarf_Die *, Dwarf_Error *); 138179187Sjbint dwarf_dieoffset(Dwarf_Die, Dwarf_Off *, Dwarf_Error *); 139179187Sjbint dwarf_elf_init(Elf *, int, Dwarf_Debug *, Dwarf_Error *); 140179187Sjbint dwarf_errno(Dwarf_Error *); 141179187Sjbint dwarf_finish(Dwarf_Debug *, Dwarf_Error *); 142179187Sjbint dwarf_locdesc(Dwarf_Die, uint64_t, Dwarf_Locdesc **, Dwarf_Signed *, Dwarf_Error *); 143179187Sjbint dwarf_locdesc_free(Dwarf_Locdesc *, Dwarf_Error *); 144179187Sjbint dwarf_init(int, int, Dwarf_Debug *, Dwarf_Error *); 145179187Sjbint dwarf_next_cu_header(Dwarf_Debug, Dwarf_Unsigned *, Dwarf_Half *, 146179187Sjb Dwarf_Unsigned *, Dwarf_Half *, Dwarf_Unsigned *, Dwarf_Error *); 147179187Sjbint dwarf_op_num(uint8_t, uint8_t *, int); 148179187Sjbint dwarf_siblingof(Dwarf_Debug, Dwarf_Die, Dwarf_Die *, Dwarf_Error *); 149179187Sjbint dwarf_tag(Dwarf_Die, Dwarf_Half *, Dwarf_Error *); 150179187Sjbint dwarf_whatform(Dwarf_Attribute, Dwarf_Half *, Dwarf_Error *); 151179187Sjbvoid dwarf_dealloc(Dwarf_Debug, Dwarf_Ptr, Dwarf_Unsigned); 152179187Sjbvoid dwarf_dump(Dwarf_Debug); 153179187Sjbvoid dwarf_dump_abbrev(Dwarf_Debug); 154179187Sjbvoid dwarf_dump_av(Dwarf_Die, Dwarf_AttrValue); 155179187Sjbvoid dwarf_dump_dbgstr(Dwarf_Debug); 156179187Sjbvoid dwarf_dump_die(Dwarf_Die); 157179187Sjbvoid dwarf_dump_die_at_offset(Dwarf_Debug, Dwarf_Off); 158179187Sjbvoid dwarf_dump_info(Dwarf_Debug); 159179187Sjbvoid dwarf_dump_shstrtab(Dwarf_Debug); 160179187Sjbvoid dwarf_dump_strtab(Dwarf_Debug); 161179187Sjbvoid dwarf_dump_symtab(Dwarf_Debug); 162179187Sjbvoid dwarf_dump_raw(Dwarf_Debug); 163179187Sjbvoid dwarf_dump_tree(Dwarf_Debug); 164221569SobrienDwarf_Func dwarf_find_function_by_offset(Dwarf_Debug dbg, Dwarf_Off off); 165221569SobrienDwarf_Func dwarf_find_function_by_name(Dwarf_Debug dbg, const char *name); 166221569Sobrienint dwarf_function_get_addr_range(Dwarf_Func f, 167221569Sobrien Dwarf_Addr *low_pc, Dwarf_Addr *high_pc); 168221569Sobrienint dwarf_function_is_inlined(Dwarf_Func f); 169221569Sobrienvoid dwarf_function_iterate_inlined_instance(Dwarf_Func func, 170221569Sobrien Dwarf_Inlined_Callback f, void *data); 171221569Sobrienint dwarf_inlined_function_get_addr_range(Dwarf_Inlined_Func f, 172221569Sobrien Dwarf_Addr *low_pc, Dwarf_Addr *high_pc); 173221569Sobrien 174179187Sjb__END_DECLS 175179187Sjb 176179187Sjb#endif /* !_LIBDWARF_H_ */ 177