1*5ac3bc71Schristos.\" $NetBSD: dwarf_init.3,v 1.6 2024/03/03 17:37:31 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2009 Joseph Koshy. All rights reserved. 49dd9d0cfSchristos.\" 59dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 69dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 79dd9d0cfSchristos.\" are met: 89dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 99dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 109dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 119dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 129dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 139dd9d0cfSchristos.\" 149dd9d0cfSchristos.\" This software is provided by Joseph Koshy ``as is'' and 159dd9d0cfSchristos.\" any express or implied warranties, including, but not limited to, the 169dd9d0cfSchristos.\" implied warranties of merchantability and fitness for a particular purpose 179dd9d0cfSchristos.\" are disclaimed. in no event shall Joseph Koshy be liable 189dd9d0cfSchristos.\" for any direct, indirect, incidental, special, exemplary, or consequential 199dd9d0cfSchristos.\" damages (including, but not limited to, procurement of substitute goods 209dd9d0cfSchristos.\" or services; loss of use, data, or profits; or business interruption) 219dd9d0cfSchristos.\" however caused and on any theory of liability, whether in contract, strict 229dd9d0cfSchristos.\" liability, or tort (including negligence or otherwise) arising in any way 239dd9d0cfSchristos.\" out of the use of this software, even if advised of the possibility of 249dd9d0cfSchristos.\" such damage. 259dd9d0cfSchristos.\" 26cdbf1fe1Sjkoshy.\" Id: dwarf_init.3 3964 2022-03-13 21:41:26Z jkoshy 279dd9d0cfSchristos.\" 28cdbf1fe1Sjkoshy.Dd March 13, 2022 299dd9d0cfSchristos.Dt DWARF_INIT 3 30604b0842Sjkoshy.Os 319dd9d0cfSchristos.Sh NAME 329dd9d0cfSchristos.Nm dwarf_init , 339dd9d0cfSchristos.Nm dwarf_elf_init 349dd9d0cfSchristos.Nd allocate a DWARF debug descriptor 359dd9d0cfSchristos.Sh LIBRARY 369dd9d0cfSchristos.Lb libdwarf 379dd9d0cfSchristos.Sh SYNOPSIS 389dd9d0cfSchristos.In libdwarf.h 399dd9d0cfSchristos.Ft int 409dd9d0cfSchristos.Fo dwarf_init 419dd9d0cfSchristos.Fa "int fd" 429dd9d0cfSchristos.Fa "int mode" 439dd9d0cfSchristos.Fa "Dwarf_Handler errhand" 449dd9d0cfSchristos.Fa "Dwarf_Ptr errarg" 459dd9d0cfSchristos.Fa "Dwarf_Debug *ret" 469dd9d0cfSchristos.Fa "Dwarf_Error *err" 479dd9d0cfSchristos.Fc 48cdbf1fe1Sjkoshy.Ft int 499dd9d0cfSchristos.Fo dwarf_elf_init 509dd9d0cfSchristos.Fa "Elf *elf" 519dd9d0cfSchristos.Fa "int mode" 529dd9d0cfSchristos.Fa "Dwarf_Handler errhand" 539dd9d0cfSchristos.Fa "Dwarf_Ptr errarg" 549dd9d0cfSchristos.Fa "Dwarf_Debug *ret" 559dd9d0cfSchristos.Fa "Dwarf_Error *err" 569dd9d0cfSchristos.Fc 579dd9d0cfSchristos.Sh DESCRIPTION 589dd9d0cfSchristosThese functions allocate and return a 599dd9d0cfSchristos.Vt Dwarf_Debug 609dd9d0cfSchristosinstance for the object denoted by argument 61cdbf1fe1Sjkoshy.Fa fd 629dd9d0cfSchristosor 63cdbf1fe1Sjkoshy.Fa elf . 649dd9d0cfSchristosThis instance would be used for subsequent access to debugging information in the object by other functions in the DWARF(3) library. 659dd9d0cfSchristos.Pp 669dd9d0cfSchristosFor function 679dd9d0cfSchristos.Fn dwarf_init , 689dd9d0cfSchristosargument 69cdbf1fe1Sjkoshy.Fa fd 709dd9d0cfSchristosdenotes an open file descriptor referencing a compilation object. 719dd9d0cfSchristosFunction 729dd9d0cfSchristos.Fn dwarf_init 739dd9d0cfSchristosimplicitly allocates an 749dd9d0cfSchristos.Vt Elf 759dd9d0cfSchristosdescriptor for argument 76cdbf1fe1Sjkoshy.Fa fd . 779dd9d0cfSchristos.Pp 789dd9d0cfSchristosFor function 799dd9d0cfSchristos.Fn dwarf_elf_init , 809dd9d0cfSchristosargument 81cdbf1fe1Sjkoshy.Fa elf 829dd9d0cfSchristosdenotes a descriptor returned by 839dd9d0cfSchristos.Xr elf_begin 3 849dd9d0cfSchristosor 859dd9d0cfSchristos.Xr elf_memory 3 . 869dd9d0cfSchristos.Pp 879dd9d0cfSchristosArgument 88cdbf1fe1Sjkoshy.Fa mode 899dd9d0cfSchristosspecifies the access mode desired. 909dd9d0cfSchristosIt should be at least as permissive as the mode with which 919dd9d0cfSchristosthe file descriptor 92cdbf1fe1Sjkoshy.Fa fd 939dd9d0cfSchristosor the ELF descriptor 94cdbf1fe1Sjkoshy.Fa elf 959dd9d0cfSchristoswas created with. 969dd9d0cfSchristosLegal values for argument 97cdbf1fe1Sjkoshy.Fa mode 989dd9d0cfSchristosare: 999dd9d0cfSchristos.Pp 1009dd9d0cfSchristos.Bl -tag -width "DW_DLC_WRITE" -compact 1019dd9d0cfSchristos.It DW_DLC_RDWR 1029dd9d0cfSchristosPermit reading and writing of DWARF information. 1039dd9d0cfSchristos.It DW_DLC_READ 1049dd9d0cfSchristosOperate in read-only mode. 1059dd9d0cfSchristos.It DW_DLC_WRITE 1069dd9d0cfSchristosPermit writing of DWARF information. 1079dd9d0cfSchristos.El 1089dd9d0cfSchristos.Pp 1099dd9d0cfSchristosArgument 110cdbf1fe1Sjkoshy.Fa errhand 1119dd9d0cfSchristosdenotes a function to be called in case of an error. 1129dd9d0cfSchristosIf this argument is 1139dd9d0cfSchristos.Dv NULL 1149dd9d0cfSchristosthen a default error handling scheme is used. 1159dd9d0cfSchristosSee 1169dd9d0cfSchristos.Xr dwarf 3 1179dd9d0cfSchristosfor a description of the error handling scheme used by the 1189dd9d0cfSchristosDWARF(3) library. 1199dd9d0cfSchristos.Pp 1209dd9d0cfSchristosArgument 121cdbf1fe1Sjkoshy.Fa errarg 1229dd9d0cfSchristosis passed to the error handler function denoted by argument 123cdbf1fe1Sjkoshy.Fa errhand 1249dd9d0cfSchristoswhen it is invoked. 1259dd9d0cfSchristos.Pp 1269dd9d0cfSchristosArgument 127cdbf1fe1Sjkoshy.Fa ret 1289dd9d0cfSchristospoints to the memory location that will hold a 1299dd9d0cfSchristos.Vt Dwarf_Debug 1309dd9d0cfSchristosreference on a successful call these functions. 1319dd9d0cfSchristos.Pp 1329dd9d0cfSchristosArgument 133cdbf1fe1Sjkoshy.Fa err 1349dd9d0cfSchristosreferences a memory location that would hold a 1359dd9d0cfSchristos.Vt Dwarf_Error 1369dd9d0cfSchristosdescriptor in case of an error. 1379dd9d0cfSchristos.Ss Memory Management 1389dd9d0cfSchristosThe 1399dd9d0cfSchristos.Vt Dwarf_Debug 1409dd9d0cfSchristosinstance returned by these functions should be freed using 1419dd9d0cfSchristos.Fn dwarf_finish . 142604b0842Sjkoshy.Sh IMPLEMENTATION NOTES 143604b0842SjkoshyThe current implementation does not support access modes 144604b0842Sjkoshy.Dv DW_DLC_RDWR 145604b0842Sjkoshyand 146604b0842Sjkoshy.Dv DW_DLC_WRITE . 1479dd9d0cfSchristos.Sh RETURN VALUES 1489dd9d0cfSchristosThese functions return the following values: 1499dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY" 1509dd9d0cfSchristos.It Bq Er DW_DLV_OK 1519dd9d0cfSchristosThis return value indicates a successful return. 1529dd9d0cfSchristos.It Bq Er DW_DLV_ERROR 1539dd9d0cfSchristosThe operation failed. 1549dd9d0cfSchristos.It Bq Er DW_DLV_NO_ENTRY 1559dd9d0cfSchristosThe object specified by arguments 156cdbf1fe1Sjkoshy.Fa "fd" 1579dd9d0cfSchristosor 158cdbf1fe1Sjkoshy.Fa "elf" 1599dd9d0cfSchristosdid not contain debug information. 1609dd9d0cfSchristos.El 1619dd9d0cfSchristos.Sh EXAMPLES 1629dd9d0cfSchristosTo initialize a 1639dd9d0cfSchristos.Vt Dwarf_Debug 1649dd9d0cfSchristosinstance from a open file descriptor referencing an ELF object, and 1659dd9d0cfSchristoswith the default error handler, use: 1669dd9d0cfSchristos.Bd -literal -offset indent 1679dd9d0cfSchristosDwarf_Error err; 1689dd9d0cfSchristosDwarf_Debug dbg; 1699dd9d0cfSchristos 1709dd9d0cfSchristosif (dwarf_init(fd, DW_DLC_READ, NULL, NULL, &dbg, &err) != 1719dd9d0cfSchristos DW_DLV_OK) 1729dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_init: %s", dwarf_errmsg(err)); 1739dd9d0cfSchristos.Ed 1749dd9d0cfSchristos.Sh SEE ALSO 1759dd9d0cfSchristos.Xr dwarf 3 , 1769dd9d0cfSchristos.Xr dwarf_errmsg 3 , 1779dd9d0cfSchristos.Xr dwarf_finish 3 , 1789dd9d0cfSchristos.Xr dwarf_get_elf 3 , 1799dd9d0cfSchristos.Xr elf_begin 3 , 1809dd9d0cfSchristos.Xr elf_memory 3 181