1*5ac3bc71Schristos.\" $NetBSD: dwarf_object_init.3,v 1.6 2024/03/03 17:37:32 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2011 Joseph Koshy 49dd9d0cfSchristos.\" All rights reserved. 59dd9d0cfSchristos.\" 69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 89dd9d0cfSchristos.\" are met: 99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 109dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 129dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 139dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 149dd9d0cfSchristos.\" 159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 189dd9d0cfSchristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 259dd9d0cfSchristos.\" SUCH DAMAGE. 269dd9d0cfSchristos.\" 27cdbf1fe1Sjkoshy.\" Id: dwarf_object_init.3 3963 2022-03-12 16:07:32Z jkoshy 289dd9d0cfSchristos.\" 299dd9d0cfSchristos.Dd September 29, 2011 309dd9d0cfSchristos.Dt DWARF_OBJECT_INIT 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_object_init 349dd9d0cfSchristos.Nd allocate a DWARF debug descriptor with application-specific file \ 359dd9d0cfSchristosaccess methods 369dd9d0cfSchristos.Sh LIBRARY 379dd9d0cfSchristos.Lb libdwarf 389dd9d0cfSchristos.Sh SYNOPSIS 399dd9d0cfSchristos.In libdwarf.h 409dd9d0cfSchristos.Ft int 419dd9d0cfSchristos.Fo dwarf_object_init 429dd9d0cfSchristos.Fa "Dwarf_Obj_Access_Interface *iface" 439dd9d0cfSchristos.Fa "Dwarf_Handler errhand" 449dd9d0cfSchristos.Fa "Dwarf_Ptr errarg" 459dd9d0cfSchristos.Fa "Dwarf_Debug *dbg" 469dd9d0cfSchristos.Fa "Dwarf_Error *err" 479dd9d0cfSchristos.Fc 489dd9d0cfSchristos.Sh DESCRIPTION 499dd9d0cfSchristosThe 509dd9d0cfSchristos.Fn dwarf_object_init 519dd9d0cfSchristosfunction allocates and returns a 529dd9d0cfSchristos.Vt Dwarf_Debug 539dd9d0cfSchristosinstance that uses application-supplied access methods to read file 549dd9d0cfSchristoscontent. 559dd9d0cfSchristos.Pp 569dd9d0cfSchristosThe argument 57cdbf1fe1Sjkoshy.Fa iface 589dd9d0cfSchristosshould point to a populated 599dd9d0cfSchristos.Vt Dwarf_Obj_Access_Interface 609dd9d0cfSchristosstructure. 619dd9d0cfSchristosThe contents of the 629dd9d0cfSchristos.Vt Dwarf_Obj_Access_Interface 639dd9d0cfSchristosstructure are described in the section 649dd9d0cfSchristos.Sx "Object Access Functions" 659dd9d0cfSchristosbelow. 669dd9d0cfSchristos.Pp 679dd9d0cfSchristosThe argument 68cdbf1fe1Sjkoshy.Fa errhand 699dd9d0cfSchristosshould point to a function to be called in case of an error. 709dd9d0cfSchristosIf this argument is 719dd9d0cfSchristos.Dv NULL 729dd9d0cfSchristosthen a default error handling scheme is used. 739dd9d0cfSchristosSee 749dd9d0cfSchristos.Xr dwarf 3 759dd9d0cfSchristosfor a description of the error handling schemes available. 769dd9d0cfSchristos.Pp 779dd9d0cfSchristosThe argument 78cdbf1fe1Sjkoshy.Fa errarg 799dd9d0cfSchristoswill be passed to the error handler function pointed to by argument 80cdbf1fe1Sjkoshy.Fa errhand . 819dd9d0cfSchristos.Pp 829dd9d0cfSchristosThe argument 83cdbf1fe1Sjkoshy.Fa dbg 849dd9d0cfSchristosshould point to a memory location that will be set to a reference to 859dd9d0cfSchristosthe returned 869dd9d0cfSchristos.Vt Dwarf_Debug 879dd9d0cfSchristosdescriptor. 889dd9d0cfSchristos.Pp 899dd9d0cfSchristosThe argument 90cdbf1fe1Sjkoshy.Fa err 919dd9d0cfSchristoswill be used to return a 929dd9d0cfSchristos.Vt Dwarf_Error 939dd9d0cfSchristosdescriptor in case of an error. 949dd9d0cfSchristos.Ss Object Access Functions 959dd9d0cfSchristosThe data structures used to specify object access methods are defined 969dd9d0cfSchristosin 979dd9d0cfSchristos.In libdwarf.h . 989dd9d0cfSchristos.Bl -tag -width indent 999dd9d0cfSchristos.It Vt "Dwarf_Obj_Access_Interface" 1009dd9d0cfSchristosThis structure bundles together a set of file access methods along 1019dd9d0cfSchristoswith a pointer to application-private state. 1029dd9d0cfSchristos.Bd -literal -offset indent 1039dd9d0cfSchristostypedef struct { 1049dd9d0cfSchristos void *object; 1059dd9d0cfSchristos const Dwarf_Obj_Access_Methods *methods; 1069dd9d0cfSchristos} Dwarf_Obj_Access_Interface; 1079dd9d0cfSchristos.Ed 1089dd9d0cfSchristos.Pp 1099dd9d0cfSchristos.Bl -tag -width ".Ar methods" -compact 1109dd9d0cfSchristos.It Ar object 1119dd9d0cfSchristosThis field points to application-specific state that will be passed as 1129dd9d0cfSchristosthe first parameter to the actual access object methods. 1139dd9d0cfSchristos.It Ar methods 1149dd9d0cfSchristosThis structure contains pointers to the functions implementing the 1159dd9d0cfSchristosaccess methods, as described below. 1169dd9d0cfSchristos.El 1179dd9d0cfSchristos.It Vt Dwarf_Obj_Access_Methods 1189dd9d0cfSchristosThis structure specifies the functions implementing low-level access. 1199dd9d0cfSchristos.Bd -literal -offset indent 1209dd9d0cfSchristostypedef struct { 1219dd9d0cfSchristos int (*get_section_info)(void *obj, Dwarf_Half index, 1229dd9d0cfSchristos Dwarf_Obj_Access_Section *ret, int *error); 1239dd9d0cfSchristos Dwarf_Endianness (*get_byte_order)(void *obj); 1249dd9d0cfSchristos Dwarf_Small (*get_length_size)(void *obj); 1259dd9d0cfSchristos Dwarf_Small (*get_pointer_size)(void *obj); 1269dd9d0cfSchristos Dwarf_Unsigned (*get_section_count)(void *obj); 1279dd9d0cfSchristos int (*load_section)(void *obj, Dwarf_Half ndx, 1289dd9d0cfSchristos Dwarf_Small **ret_data, int *error); 1299dd9d0cfSchristos} Dwarf_Obj_Access_Methods; 1309dd9d0cfSchristos.Ed 1319dd9d0cfSchristos.Pp 1329dd9d0cfSchristos.Bl -tag -width ".Ar get_section_count" -compact 1339dd9d0cfSchristos.It Ar get_byte_order 1349dd9d0cfSchristosThis function should return the endianness of the DWARF object by 1359dd9d0cfSchristosreturning one of the constants 1369dd9d0cfSchristos.Dv DW_OBJECT_MSB 1379dd9d0cfSchristosor 1389dd9d0cfSchristos.Dv DW_OBJECT_LSB . 1399dd9d0cfSchristos.It Ar get_length_size 1409dd9d0cfSchristosThis function should return the number of bytes needed to represent a 1419dd9d0cfSchristosDWARF offset in the object being debugged. 1429dd9d0cfSchristos.It Ar get_pointer_size 1439dd9d0cfSchristosThis function should return the size in bytes, in the object being 1449dd9d0cfSchristosdebugged, of a memory address. 1459dd9d0cfSchristos.It Ar get_section_count 1469dd9d0cfSchristosThis function should return the number of sections in the object being 1479dd9d0cfSchristosdebugged. 1489dd9d0cfSchristos.It Ar get_section_info 1499dd9d0cfSchristosThis function should return information about the section at the 1509dd9d0cfSchristosindex 151cdbf1fe1Sjkoshy.Fa ndx 1529dd9d0cfSchristosby filling in the structure of type 1539dd9d0cfSchristos.Vt Dwarf_Obj_Access_Section 1549dd9d0cfSchristospointed to by argument 155cdbf1fe1Sjkoshy.Fa ret . 1569dd9d0cfSchristosThe 1579dd9d0cfSchristos.Vt Dwarf_Obj_Access_Section 1589dd9d0cfSchristosstructure is described below. 1599dd9d0cfSchristos.It Ar load_section 1609dd9d0cfSchristosThis function should load the section specified by argument 161cdbf1fe1Sjkoshy.Fa ndx 1629dd9d0cfSchristosinto memory and place a pointer to the section's data into 1639dd9d0cfSchristosthe location pointed to by argument 164cdbf1fe1Sjkoshy.Fa ret_data . 1659dd9d0cfSchristos.El 1669dd9d0cfSchristos.Pp 1679dd9d0cfSchristosThe argument 168cdbf1fe1Sjkoshy.Fa obj 1699dd9d0cfSchristospassed to these functions will be set to the pointer value in the 170cdbf1fe1Sjkoshy.Fa object 1719dd9d0cfSchristosfield of the associated 1729dd9d0cfSchristos.Vt Dwarf_Obj_Access_Interface 1739dd9d0cfSchristosstructure. 1749dd9d0cfSchristos.Pp 1759dd9d0cfSchristosThe argument 176cdbf1fe1Sjkoshy.Fa error 1779dd9d0cfSchristosis used to return an error code in case of an error. 1789dd9d0cfSchristos.It Vt Dwarf_Obj_Access_Section 1799dd9d0cfSchristosThis structure describes the layout of a section in the DWARF object. 1809dd9d0cfSchristos.Bd -literal -offset indent 1819dd9d0cfSchristostypedef struct { 1829dd9d0cfSchristos Dwarf_Addr addr; 1839dd9d0cfSchristos Dwarf_Unsigned size; 1849dd9d0cfSchristos const char *name; 1859dd9d0cfSchristos} Dwarf_Obj_Access_Section; 1869dd9d0cfSchristos.Ed 1879dd9d0cfSchristos.Pp 1889dd9d0cfSchristos.Bl -tag -width ".Ar name" -compact 1899dd9d0cfSchristos.It Ar addr 1909dd9d0cfSchristosA pointer to the start of the section's data. 1919dd9d0cfSchristos.It Ar size 1929dd9d0cfSchristosThe size of the section in bytes. 1939dd9d0cfSchristos.It Ar name 1949dd9d0cfSchristosA pointer to a NUL-terminated string containing the name of the 1959dd9d0cfSchristossection. 1969dd9d0cfSchristos.El 1979dd9d0cfSchristos.El 1989dd9d0cfSchristos.Sh RETURN VALUES 1999dd9d0cfSchristosOn success, the 2009dd9d0cfSchristos.Fn dwarf_object_init 2019dd9d0cfSchristosfunction returns 2029dd9d0cfSchristos.Dv DW_DLV_OK . 2039dd9d0cfSchristosIn case of an error, the function returns 2049dd9d0cfSchristos.Dv DW_DLV_ERROR 2059dd9d0cfSchristosand sets the argument 206cdbf1fe1Sjkoshy.Fa err . 2079dd9d0cfSchristos.Sh ERRORS 2089dd9d0cfSchristosThe 2099dd9d0cfSchristos.Fn dwarf_object_init 2109dd9d0cfSchristosfunction may fail with the following errors: 2119dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLE_DEBUG_INFO_NULL" 2129dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT 2139dd9d0cfSchristosOne of the arguments 214cdbf1fe1Sjkoshy.Fa iface 2159dd9d0cfSchristosor 216cdbf1fe1Sjkoshy.Fa dbg 217cdbf1fe1Sjkoshywas 218cdbf1fe1Sjkoshy.Dv NULL . 2199dd9d0cfSchristos.It Bq Er DW_DLE_DEBUG_INFO_NULL 2209dd9d0cfSchristosThe underlying object did not contain debugging information. 2219dd9d0cfSchristos.It Bq Er DW_DLE_MEMORY 2229dd9d0cfSchristosAn out of memory condition was encountered during the execution of the 2239dd9d0cfSchristosfunction. 2249dd9d0cfSchristos.El 2259dd9d0cfSchristos.Sh SEE ALSO 2269dd9d0cfSchristos.Xr dwarf 3 , 2279dd9d0cfSchristos.Xr dwarf_init 3 , 2289dd9d0cfSchristos.Xr dwarf_init_elf 3 , 2299dd9d0cfSchristos.Xr dwarf_object_finish 3 230