1*0a6a1f1dSLionel Sambuc.\" $NetBSD: dwarf_object_init.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2011 Joseph Koshy 4*0a6a1f1dSLionel Sambuc.\" All rights reserved. 5*0a6a1f1dSLionel Sambuc.\" 6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc.\" are met: 9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 10*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 12*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 13*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 14*0a6a1f1dSLionel Sambuc.\" 15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE. 26*0a6a1f1dSLionel Sambuc.\" 27*0a6a1f1dSLionel Sambuc.\" Id: dwarf_object_init.3 2074 2011-10-27 03:34:33Z jkoshy 28*0a6a1f1dSLionel Sambuc.\" 29*0a6a1f1dSLionel Sambuc.Dd September 29, 2011 30*0a6a1f1dSLionel Sambuc.Os 31*0a6a1f1dSLionel Sambuc.Dt DWARF_OBJECT_INIT 3 32*0a6a1f1dSLionel Sambuc.Sh NAME 33*0a6a1f1dSLionel Sambuc.Nm dwarf_object_init 34*0a6a1f1dSLionel Sambuc.Nd allocate a DWARF debug descriptor with application-specific file \ 35*0a6a1f1dSLionel Sambucaccess methods 36*0a6a1f1dSLionel Sambuc.Sh LIBRARY 37*0a6a1f1dSLionel Sambuc.Lb libdwarf 38*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 39*0a6a1f1dSLionel Sambuc.In libdwarf.h 40*0a6a1f1dSLionel Sambuc.Ft int 41*0a6a1f1dSLionel Sambuc.Fo dwarf_object_init 42*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Obj_Access_Interface *iface" 43*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Handler errhand" 44*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ptr errarg" 45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug *dbg" 46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err" 47*0a6a1f1dSLionel Sambuc.Fc 48*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 49*0a6a1f1dSLionel Sambuc.Pp 50*0a6a1f1dSLionel SambucThe 51*0a6a1f1dSLionel Sambuc.Fn dwarf_object_init 52*0a6a1f1dSLionel Sambucfunction allocates and returns a 53*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 54*0a6a1f1dSLionel Sambucinstance that uses application-supplied access methods to read file 55*0a6a1f1dSLionel Sambuccontent. 56*0a6a1f1dSLionel Sambuc.Pp 57*0a6a1f1dSLionel SambucThe argument 58*0a6a1f1dSLionel Sambuc.Ar iface 59*0a6a1f1dSLionel Sambucshould point to a populated 60*0a6a1f1dSLionel Sambuc.Vt Dwarf_Obj_Access_Interface 61*0a6a1f1dSLionel Sambucstructure. 62*0a6a1f1dSLionel SambucThe contents of the 63*0a6a1f1dSLionel Sambuc.Vt Dwarf_Obj_Access_Interface 64*0a6a1f1dSLionel Sambucstructure are described in the section 65*0a6a1f1dSLionel Sambuc.Sx "Object Access Functions" 66*0a6a1f1dSLionel Sambucbelow. 67*0a6a1f1dSLionel Sambuc.Pp 68*0a6a1f1dSLionel SambucThe argument 69*0a6a1f1dSLionel Sambuc.Ar errhand 70*0a6a1f1dSLionel Sambucshould point to a function to be called in case of an error. 71*0a6a1f1dSLionel SambucIf this argument is 72*0a6a1f1dSLionel Sambuc.Dv NULL 73*0a6a1f1dSLionel Sambucthen a default error handling scheme is used. 74*0a6a1f1dSLionel SambucSee 75*0a6a1f1dSLionel Sambuc.Xr dwarf 3 76*0a6a1f1dSLionel Sambucfor a description of the error handling schemes available. 77*0a6a1f1dSLionel Sambuc.Pp 78*0a6a1f1dSLionel SambucThe argument 79*0a6a1f1dSLionel Sambuc.Ar errarg 80*0a6a1f1dSLionel Sambucwill be passed to the error handler function pointed to by argument 81*0a6a1f1dSLionel Sambuc.Ar errhand . 82*0a6a1f1dSLionel Sambuc.Pp 83*0a6a1f1dSLionel SambucThe argument 84*0a6a1f1dSLionel Sambuc.Ar dbg 85*0a6a1f1dSLionel Sambucshould point to a memory location that will be set to a reference to 86*0a6a1f1dSLionel Sambucthe returned 87*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 88*0a6a1f1dSLionel Sambucdescriptor. 89*0a6a1f1dSLionel Sambuc.Pp 90*0a6a1f1dSLionel SambucThe argument 91*0a6a1f1dSLionel Sambuc.Ar err 92*0a6a1f1dSLionel Sambucwill be used to return a 93*0a6a1f1dSLionel Sambuc.Vt Dwarf_Error 94*0a6a1f1dSLionel Sambucdescriptor in case of an error. 95*0a6a1f1dSLionel Sambuc.Ss Object Access Functions 96*0a6a1f1dSLionel SambucThe data structures used to specify object access methods are defined 97*0a6a1f1dSLionel Sambucin 98*0a6a1f1dSLionel Sambuc.In libdwarf.h . 99*0a6a1f1dSLionel Sambuc.Bl -tag -width indent 100*0a6a1f1dSLionel Sambuc.It Vt "Dwarf_Obj_Access_Interface" 101*0a6a1f1dSLionel SambucThis structure bundles together a set of file access methods along 102*0a6a1f1dSLionel Sambucwith a pointer to application-private state. 103*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 104*0a6a1f1dSLionel Sambuctypedef struct { 105*0a6a1f1dSLionel Sambuc void *object; 106*0a6a1f1dSLionel Sambuc const Dwarf_Obj_Access_Methods *methods; 107*0a6a1f1dSLionel Sambuc} Dwarf_Obj_Access_Interface; 108*0a6a1f1dSLionel Sambuc.Ed 109*0a6a1f1dSLionel Sambuc.Pp 110*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Ar methods" -compact 111*0a6a1f1dSLionel Sambuc.It Ar object 112*0a6a1f1dSLionel SambucThis field points to application-specific state that will be passed as 113*0a6a1f1dSLionel Sambucthe first parameter to the actual access object methods. 114*0a6a1f1dSLionel Sambuc.It Ar methods 115*0a6a1f1dSLionel SambucThis structure contains pointers to the functions implementing the 116*0a6a1f1dSLionel Sambucaccess methods, as described below. 117*0a6a1f1dSLionel Sambuc.El 118*0a6a1f1dSLionel Sambuc.It Vt Dwarf_Obj_Access_Methods 119*0a6a1f1dSLionel SambucThis structure specifies the functions implementing low-level access. 120*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 121*0a6a1f1dSLionel Sambuctypedef struct { 122*0a6a1f1dSLionel Sambuc int (*get_section_info)(void *obj, Dwarf_Half index, 123*0a6a1f1dSLionel Sambuc Dwarf_Obj_Access_Section *ret, int *error); 124*0a6a1f1dSLionel Sambuc Dwarf_Endianness (*get_byte_order)(void *obj); 125*0a6a1f1dSLionel Sambuc Dwarf_Small (*get_length_size)(void *obj); 126*0a6a1f1dSLionel Sambuc Dwarf_Small (*get_pointer_size)(void *obj); 127*0a6a1f1dSLionel Sambuc Dwarf_Unsigned (*get_section_count)(void *obj); 128*0a6a1f1dSLionel Sambuc int (*load_section)(void *obj, Dwarf_Half ndx, 129*0a6a1f1dSLionel Sambuc Dwarf_Small **ret_data, int *error); 130*0a6a1f1dSLionel Sambuc} Dwarf_Obj_Access_Methods; 131*0a6a1f1dSLionel Sambuc.Ed 132*0a6a1f1dSLionel Sambuc.Pp 133*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Ar get_section_count" -compact 134*0a6a1f1dSLionel Sambuc.It Ar get_byte_order 135*0a6a1f1dSLionel SambucThis function should return the endianness of the DWARF object by 136*0a6a1f1dSLionel Sambucreturning one of the constants 137*0a6a1f1dSLionel Sambuc.Dv DW_OBJECT_MSB 138*0a6a1f1dSLionel Sambucor 139*0a6a1f1dSLionel Sambuc.Dv DW_OBJECT_LSB . 140*0a6a1f1dSLionel Sambuc.It Ar get_length_size 141*0a6a1f1dSLionel SambucThis function should return the number of bytes needed to represent a 142*0a6a1f1dSLionel SambucDWARF offset in the object being debugged. 143*0a6a1f1dSLionel Sambuc.It Ar get_pointer_size 144*0a6a1f1dSLionel SambucThis function should return the size in bytes, in the object being 145*0a6a1f1dSLionel Sambucdebugged, of a memory address. 146*0a6a1f1dSLionel Sambuc.It Ar get_section_count 147*0a6a1f1dSLionel SambucThis function should return the number of sections in the object being 148*0a6a1f1dSLionel Sambucdebugged. 149*0a6a1f1dSLionel Sambuc.It Ar get_section_info 150*0a6a1f1dSLionel SambucThis function should return information about the section at the 151*0a6a1f1dSLionel Sambucindex 152*0a6a1f1dSLionel Sambuc.Ar ndx 153*0a6a1f1dSLionel Sambucby filling in the structure of type 154*0a6a1f1dSLionel Sambuc.Vt Dwarf_Obj_Access_Section 155*0a6a1f1dSLionel Sambucpointed to by argument 156*0a6a1f1dSLionel Sambuc.Ar ret . 157*0a6a1f1dSLionel SambucThe 158*0a6a1f1dSLionel Sambuc.Vt Dwarf_Obj_Access_Section 159*0a6a1f1dSLionel Sambucstructure is described below. 160*0a6a1f1dSLionel Sambuc.It Ar load_section 161*0a6a1f1dSLionel SambucThis function should load the section specified by argument 162*0a6a1f1dSLionel Sambuc.Ar ndx 163*0a6a1f1dSLionel Sambucinto memory and place a pointer to the section's data into 164*0a6a1f1dSLionel Sambucthe location pointed to by argument 165*0a6a1f1dSLionel Sambuc.Ar ret_data . 166*0a6a1f1dSLionel Sambuc.El 167*0a6a1f1dSLionel Sambuc.Pp 168*0a6a1f1dSLionel SambucThe argument 169*0a6a1f1dSLionel Sambuc.Ar obj 170*0a6a1f1dSLionel Sambucpassed to these functions will be set to the pointer value in the 171*0a6a1f1dSLionel Sambuc.Ar object 172*0a6a1f1dSLionel Sambucfield of the associated 173*0a6a1f1dSLionel Sambuc.Vt Dwarf_Obj_Access_Interface 174*0a6a1f1dSLionel Sambucstructure. 175*0a6a1f1dSLionel Sambuc.Pp 176*0a6a1f1dSLionel SambucThe argument 177*0a6a1f1dSLionel Sambuc.Ar error 178*0a6a1f1dSLionel Sambucis used to return an error code in case of an error. 179*0a6a1f1dSLionel Sambuc.It Vt Dwarf_Obj_Access_Section 180*0a6a1f1dSLionel SambucThis structure describes the layout of a section in the DWARF object. 181*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 182*0a6a1f1dSLionel Sambuctypedef struct { 183*0a6a1f1dSLionel Sambuc Dwarf_Addr addr; 184*0a6a1f1dSLionel Sambuc Dwarf_Unsigned size; 185*0a6a1f1dSLionel Sambuc const char *name; 186*0a6a1f1dSLionel Sambuc} Dwarf_Obj_Access_Section; 187*0a6a1f1dSLionel Sambuc.Ed 188*0a6a1f1dSLionel Sambuc.Pp 189*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Ar name" -compact 190*0a6a1f1dSLionel Sambuc.It Ar addr 191*0a6a1f1dSLionel SambucA pointer to the start of the section's data. 192*0a6a1f1dSLionel Sambuc.It Ar size 193*0a6a1f1dSLionel SambucThe size of the section in bytes. 194*0a6a1f1dSLionel Sambuc.It Ar name 195*0a6a1f1dSLionel SambucA pointer to a NUL-terminated string containing the name of the 196*0a6a1f1dSLionel Sambucsection. 197*0a6a1f1dSLionel Sambuc.El 198*0a6a1f1dSLionel Sambuc.El 199*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 200*0a6a1f1dSLionel SambucOn success, the 201*0a6a1f1dSLionel Sambuc.Fn dwarf_object_init 202*0a6a1f1dSLionel Sambucfunction returns 203*0a6a1f1dSLionel Sambuc.Dv DW_DLV_OK . 204*0a6a1f1dSLionel SambucIn case of an error, the function returns 205*0a6a1f1dSLionel Sambuc.Dv DW_DLV_ERROR 206*0a6a1f1dSLionel Sambucand sets the argument 207*0a6a1f1dSLionel Sambuc.Ar err. 208*0a6a1f1dSLionel Sambuc.Sh ERRORS 209*0a6a1f1dSLionel SambucThe 210*0a6a1f1dSLionel Sambuc.Fn dwarf_object_init 211*0a6a1f1dSLionel Sambucfunction may fail with the following errors: 212*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLE_DEBUG_INFO_NULL" 213*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT 214*0a6a1f1dSLionel SambucOne of the arguments 215*0a6a1f1dSLionel Sambuc.Ar iface 216*0a6a1f1dSLionel Sambucor 217*0a6a1f1dSLionel Sambuc.Ar dbg 218*0a6a1f1dSLionel Sambucwas NULL. 219*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_DEBUG_INFO_NULL 220*0a6a1f1dSLionel SambucThe underlying object did not contain debugging information. 221*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_MEMORY 222*0a6a1f1dSLionel SambucAn out of memory condition was encountered during the execution of the 223*0a6a1f1dSLionel Sambucfunction. 224*0a6a1f1dSLionel Sambuc.El 225*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 226*0a6a1f1dSLionel Sambuc.Xr dwarf 3 , 227*0a6a1f1dSLionel Sambuc.Xr dwarf_init 3 , 228*0a6a1f1dSLionel Sambuc.Xr dwarf_init_elf 3 , 229*0a6a1f1dSLionel Sambuc.Xr dwarf_object_finish 3 230