1*0a6a1f1dSLionel Sambuc.\" $NetBSD: dwarf_init.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2009 Joseph Koshy. All rights reserved. 4*0a6a1f1dSLionel Sambuc.\" 5*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 6*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 7*0a6a1f1dSLionel Sambuc.\" are met: 8*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 9*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 10*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 11*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 12*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 13*0a6a1f1dSLionel Sambuc.\" 14*0a6a1f1dSLionel Sambuc.\" This software is provided by Joseph Koshy ``as is'' and 15*0a6a1f1dSLionel Sambuc.\" any express or implied warranties, including, but not limited to, the 16*0a6a1f1dSLionel Sambuc.\" implied warranties of merchantability and fitness for a particular purpose 17*0a6a1f1dSLionel Sambuc.\" are disclaimed. in no event shall Joseph Koshy be liable 18*0a6a1f1dSLionel Sambuc.\" for any direct, indirect, incidental, special, exemplary, or consequential 19*0a6a1f1dSLionel Sambuc.\" damages (including, but not limited to, procurement of substitute goods 20*0a6a1f1dSLionel Sambuc.\" or services; loss of use, data, or profits; or business interruption) 21*0a6a1f1dSLionel Sambuc.\" however caused and on any theory of liability, whether in contract, strict 22*0a6a1f1dSLionel Sambuc.\" liability, or tort (including negligence or otherwise) arising in any way 23*0a6a1f1dSLionel Sambuc.\" out of the use of this software, even if advised of the possibility of 24*0a6a1f1dSLionel Sambuc.\" such damage. 25*0a6a1f1dSLionel Sambuc.\" 26*0a6a1f1dSLionel Sambuc.\" Id: dwarf_init.3 2122 2011-11-09 15:35:14Z jkoshy 27*0a6a1f1dSLionel Sambuc.\" 28*0a6a1f1dSLionel Sambuc.Dd November 9, 2011 29*0a6a1f1dSLionel Sambuc.Os 30*0a6a1f1dSLionel Sambuc.Dt DWARF_INIT 3 31*0a6a1f1dSLionel Sambuc.Sh NAME 32*0a6a1f1dSLionel Sambuc.Nm dwarf_init , 33*0a6a1f1dSLionel Sambuc.Nm dwarf_elf_init 34*0a6a1f1dSLionel Sambuc.Nd allocate a DWARF debug descriptor 35*0a6a1f1dSLionel Sambuc.Sh LIBRARY 36*0a6a1f1dSLionel Sambuc.Lb libdwarf 37*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 38*0a6a1f1dSLionel Sambuc.In libdwarf.h 39*0a6a1f1dSLionel Sambuc.Ft int 40*0a6a1f1dSLionel Sambuc.Fo dwarf_init 41*0a6a1f1dSLionel Sambuc.Fa "int fd" 42*0a6a1f1dSLionel Sambuc.Fa "int mode" 43*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Handler errhand" 44*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ptr errarg" 45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug *ret" 46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err" 47*0a6a1f1dSLionel Sambuc.Fc 48*0a6a1f1dSLionel Sambuc.Ft in 49*0a6a1f1dSLionel Sambuc.Fo dwarf_elf_init 50*0a6a1f1dSLionel Sambuc.Fa "Elf *elf" 51*0a6a1f1dSLionel Sambuc.Fa "int mode" 52*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Handler errhand" 53*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ptr errarg" 54*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug *ret" 55*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err" 56*0a6a1f1dSLionel Sambuc.Fc 57*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 58*0a6a1f1dSLionel SambucThese functions allocate and return a 59*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 60*0a6a1f1dSLionel Sambucinstance for the object denoted by argument 61*0a6a1f1dSLionel Sambuc.Ar fd 62*0a6a1f1dSLionel Sambucor 63*0a6a1f1dSLionel Sambuc.Ar elf . 64*0a6a1f1dSLionel SambucThis instance would be used for subsequent access to debugging information in the object by other functions in the DWARF(3) library. 65*0a6a1f1dSLionel Sambuc.Pp 66*0a6a1f1dSLionel SambucFor function 67*0a6a1f1dSLionel Sambuc.Fn dwarf_init , 68*0a6a1f1dSLionel Sambucargument 69*0a6a1f1dSLionel Sambuc.Ar fd 70*0a6a1f1dSLionel Sambucdenotes an open file descriptor referencing a compilation object. 71*0a6a1f1dSLionel SambucFunction 72*0a6a1f1dSLionel Sambuc.Fn dwarf_init 73*0a6a1f1dSLionel Sambucimplicitly allocates an 74*0a6a1f1dSLionel Sambuc.Vt Elf 75*0a6a1f1dSLionel Sambucdescriptor for argument 76*0a6a1f1dSLionel Sambuc.Ar fd . 77*0a6a1f1dSLionel Sambuc.Pp 78*0a6a1f1dSLionel SambucFor function 79*0a6a1f1dSLionel Sambuc.Fn dwarf_elf_init , 80*0a6a1f1dSLionel Sambucargument 81*0a6a1f1dSLionel Sambuc.Ar elf 82*0a6a1f1dSLionel Sambucdenotes a descriptor returned by 83*0a6a1f1dSLionel Sambuc.Xr elf_begin 3 84*0a6a1f1dSLionel Sambucor 85*0a6a1f1dSLionel Sambuc.Xr elf_memory 3 . 86*0a6a1f1dSLionel Sambuc.Pp 87*0a6a1f1dSLionel SambucArgument 88*0a6a1f1dSLionel Sambuc.Ar mode 89*0a6a1f1dSLionel Sambucspecifies the access mode desired. 90*0a6a1f1dSLionel SambucIt should be at least as permissive as the mode with which 91*0a6a1f1dSLionel Sambucthe file descriptor 92*0a6a1f1dSLionel Sambuc.Ar fd 93*0a6a1f1dSLionel Sambucor the ELF descriptor 94*0a6a1f1dSLionel Sambuc.Ar elf 95*0a6a1f1dSLionel Sambucwas created with. 96*0a6a1f1dSLionel SambucLegal values for argument 97*0a6a1f1dSLionel Sambuc.Ar mode 98*0a6a1f1dSLionel Sambucare: 99*0a6a1f1dSLionel Sambuc.Pp 100*0a6a1f1dSLionel Sambuc.Bl -tag -width "DW_DLC_WRITE" -compact 101*0a6a1f1dSLionel Sambuc.It DW_DLC_RDWR 102*0a6a1f1dSLionel SambucPermit reading and writing of DWARF information. 103*0a6a1f1dSLionel Sambuc.It DW_DLC_READ 104*0a6a1f1dSLionel SambucOperate in read-only mode. 105*0a6a1f1dSLionel Sambuc.It DW_DLC_WRITE 106*0a6a1f1dSLionel SambucPermit writing of DWARF information. 107*0a6a1f1dSLionel Sambuc.El 108*0a6a1f1dSLionel Sambuc.Pp 109*0a6a1f1dSLionel SambucArgument 110*0a6a1f1dSLionel Sambuc.Ar errhand 111*0a6a1f1dSLionel Sambucdenotes a function to be called in case of an error. 112*0a6a1f1dSLionel SambucIf this argument is 113*0a6a1f1dSLionel Sambuc.Dv NULL 114*0a6a1f1dSLionel Sambucthen a default error handling scheme is used. 115*0a6a1f1dSLionel SambucSee 116*0a6a1f1dSLionel Sambuc.Xr dwarf 3 117*0a6a1f1dSLionel Sambucfor a description of the error handling scheme used by the 118*0a6a1f1dSLionel SambucDWARF(3) library. 119*0a6a1f1dSLionel Sambuc.Pp 120*0a6a1f1dSLionel SambucArgument 121*0a6a1f1dSLionel Sambuc.Ar errarg 122*0a6a1f1dSLionel Sambucis passed to the error handler function denoted by argument 123*0a6a1f1dSLionel Sambuc.Ar errhand 124*0a6a1f1dSLionel Sambucwhen it is invoked. 125*0a6a1f1dSLionel Sambuc.Pp 126*0a6a1f1dSLionel SambucArgument 127*0a6a1f1dSLionel Sambuc.Ar ret 128*0a6a1f1dSLionel Sambucpoints to the memory location that will hold a 129*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 130*0a6a1f1dSLionel Sambucreference on a successful call these functions. 131*0a6a1f1dSLionel Sambuc.Pp 132*0a6a1f1dSLionel SambucArgument 133*0a6a1f1dSLionel Sambuc.Ar err 134*0a6a1f1dSLionel Sambucreferences a memory location that would hold a 135*0a6a1f1dSLionel Sambuc.Vt Dwarf_Error 136*0a6a1f1dSLionel Sambucdescriptor in case of an error. 137*0a6a1f1dSLionel Sambuc.Ss Memory Management 138*0a6a1f1dSLionel SambucThe 139*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 140*0a6a1f1dSLionel Sambucinstance returned by these functions should be freed using 141*0a6a1f1dSLionel Sambuc.Fn dwarf_finish . 142*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 143*0a6a1f1dSLionel SambucThese functions return the following values: 144*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY" 145*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLV_OK 146*0a6a1f1dSLionel SambucThis return value indicates a successful return. 147*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLV_ERROR 148*0a6a1f1dSLionel SambucThe operation failed. 149*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLV_NO_ENTRY 150*0a6a1f1dSLionel SambucThe object specified by arguments 151*0a6a1f1dSLionel Sambuc.Ar "fd" 152*0a6a1f1dSLionel Sambucor 153*0a6a1f1dSLionel Sambuc.Ar "elf" 154*0a6a1f1dSLionel Sambucdid not contain debug information. 155*0a6a1f1dSLionel Sambuc.El 156*0a6a1f1dSLionel Sambuc.Sh IMPLEMENTATION NOTES 157*0a6a1f1dSLionel SambucThe current implementation does not support access modes 158*0a6a1f1dSLionel Sambuc.Dv DW_DLC_RDWR 159*0a6a1f1dSLionel Sambucand 160*0a6a1f1dSLionel Sambuc.Dv DW_DLC_WRITE . 161*0a6a1f1dSLionel Sambuc.Sh EXAMPLES 162*0a6a1f1dSLionel SambucTo initialize a 163*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 164*0a6a1f1dSLionel Sambucinstance from a open file descriptor referencing an ELF object, and 165*0a6a1f1dSLionel Sambucwith the default error handler, use: 166*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 167*0a6a1f1dSLionel SambucDwarf_Error err; 168*0a6a1f1dSLionel SambucDwarf_Debug dbg; 169*0a6a1f1dSLionel Sambuc 170*0a6a1f1dSLionel Sambucif (dwarf_init(fd, DW_DLC_READ, NULL, NULL, &dbg, &err) != 171*0a6a1f1dSLionel Sambuc DW_DLV_OK) 172*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, "dwarf_init: %s", dwarf_errmsg(err)); 173*0a6a1f1dSLionel Sambuc.Ed 174*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 175*0a6a1f1dSLionel Sambuc.Xr dwarf 3 , 176*0a6a1f1dSLionel Sambuc.Xr dwarf_errmsg 3 , 177*0a6a1f1dSLionel Sambuc.Xr dwarf_finish 3 , 178*0a6a1f1dSLionel Sambuc.Xr dwarf_get_elf 3 , 179*0a6a1f1dSLionel Sambuc.Xr elf_begin 3 , 180*0a6a1f1dSLionel Sambuc.Xr elf_memory 3 181