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