12de3b87aSKai Wang.\" Copyright (c) 2011 Kai Wang 22de3b87aSKai Wang.\" All rights reserved. 32de3b87aSKai Wang.\" 42de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 52de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 62de3b87aSKai Wang.\" are met: 72de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 82de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 92de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 102de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 112de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 122de3b87aSKai Wang.\" 132de3b87aSKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 142de3b87aSKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 152de3b87aSKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 162de3b87aSKai Wang.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 172de3b87aSKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 182de3b87aSKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 192de3b87aSKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 202de3b87aSKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 212de3b87aSKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 222de3b87aSKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 232de3b87aSKai Wang.\" SUCH DAMAGE. 242de3b87aSKai Wang.\" 25*ae500c1fSEd Maste.\" $Id: dwarf_producer_init.3 3644 2018-10-15 19:55:01Z jkoshy $ 262de3b87aSKai Wang.\" 272de3b87aSKai Wang.Dd August 20, 2011 282de3b87aSKai Wang.Dt DWARF_PRODUCER_INIT 3 29*ae500c1fSEd Maste.Os 302de3b87aSKai Wang.Sh NAME 31*ae500c1fSEd Maste.Nm dwarf_producer_init , 322de3b87aSKai Wang.Nm dwarf_producer_init_b 332de3b87aSKai Wang.Nd allocate a DWARF producer descriptor 342de3b87aSKai Wang.Sh LIBRARY 352de3b87aSKai Wang.Lb libdwarf 362de3b87aSKai Wang.Sh SYNOPSIS 372de3b87aSKai Wang.In libdwarf.h 382de3b87aSKai Wang.Ft Dwarf_P_Debug 392de3b87aSKai Wang.Fo dwarf_producer_init 402de3b87aSKai Wang.Fa "Dwarf_Unsigned flags" 412de3b87aSKai Wang.Fa "Dwarf_Callback_Func func" 422de3b87aSKai Wang.Fa "Dwarf_Handler errhand" 432de3b87aSKai Wang.Fa "Dwarf_Ptr errarg" 442de3b87aSKai Wang.Fa "Dwarf_Error *err" 452de3b87aSKai Wang.Fc 462de3b87aSKai Wang.Ft Dwarf_P_Debug 472de3b87aSKai Wang.Fo dwarf_producer_init_b 482de3b87aSKai Wang.Fa "Dwarf_Unsigned flags" 492de3b87aSKai Wang.Fa "Dwarf_Callback_Func_b func" 502de3b87aSKai Wang.Fa "Dwarf_Handler errhand" 512de3b87aSKai Wang.Fa "Dwarf_Ptr errarg" 522de3b87aSKai Wang.Fa "Dwarf_Error *error" 532de3b87aSKai Wang.Fc 542de3b87aSKai Wang.Sh DESCRIPTION 552de3b87aSKai WangThese functions allocate and return a 562de3b87aSKai Wang.Vt Dwarf_P_Debug 572de3b87aSKai Wangdescriptor representing a DWARF producer instance. 582de3b87aSKai Wang.Pp 592de3b87aSKai WangThe argument 602de3b87aSKai Wang.Ar errhand 61b00fe64fSEd Masteshould contain the address of a function to be called in case of an 622de3b87aSKai Wangerror. 632de3b87aSKai WangIf this argument is 642de3b87aSKai Wang.Dv NULL , 652de3b87aSKai Wangthe default error handling scheme is used, see 662de3b87aSKai Wang.Xr dwarf 3 . 672de3b87aSKai Wang.Pp 682de3b87aSKai WangThe argument 692de3b87aSKai Wang.Ar errarg 702de3b87aSKai Wangwill be passed to the error handler function when it is invoked. 712de3b87aSKai Wang.Pp 722de3b87aSKai WangThe argument 732de3b87aSKai Wang.Ar err 742de3b87aSKai Wangreferences a memory location that would hold a 752de3b87aSKai Wang.Vt Dwarf_Error 762de3b87aSKai Wangdescriptor in case of an error. 772de3b87aSKai Wang.Pp 782de3b87aSKai WangThe argument 792de3b87aSKai Wang.Ar flags 802de3b87aSKai Wangspecifies additional characteristics of the DWARF producer instance. 812de3b87aSKai WangThe following flags are recognized: 822de3b87aSKai Wang.Bl -tag -width "Dv DW_DLC_ISA_MIPS" 832de3b87aSKai Wang.It Dv DW_DLC_ISA_IA64 842de3b87aSKai Wang.Pq Deprecated 852de3b87aSKai WangThe target instruction set architecture is IA64. 862de3b87aSKai WangThis flag is deprecated. 872de3b87aSKai WangApplication code should use the 882de3b87aSKai Wang.Xr dwarf_producer_set_isa 3 892de3b87aSKai Wangfunction to specify target instruction set architecture. 902de3b87aSKai Wang.It Dv DW_DLC_ISA_MIPS 912de3b87aSKai Wang.Pq Deprecated 922de3b87aSKai WangThe target instruction set architecture is MIPS. 932de3b87aSKai WangThis flag is deprecated. 942de3b87aSKai WangApplication code should use the 952de3b87aSKai Wang.Xr dwarf_producer_set_isa 3 962de3b87aSKai Wangfunction to specify target instruction set architecture. 972de3b87aSKai Wang.It Dv DW_DLC_SIZE_32 982de3b87aSKai Wang.Pq Default 992de3b87aSKai WangThe target address size is 32-bit. 1002de3b87aSKai Wang.It Dv DW_DLC_SIZE_64 1012de3b87aSKai WangThe target address size is 64-bit. 1022de3b87aSKai Wang.It Dv DW_DLC_STREAM_RELOCATIONS 1032de3b87aSKai Wang.Pq Default 1042de3b87aSKai WangGenerate stream relocations. 1052de3b87aSKai Wang.It Dv DW_DLC_SYMBOLIC_RELOCATIONS 1062de3b87aSKai WangGenerate symbolic relocations. 1072de3b87aSKai Wang.It Dv DW_DLC_TARGET_BIGENDIAN 1082de3b87aSKai WangThe target is big endian. 1092de3b87aSKai Wang.It Dv DW_DLC_TARGET_LITTLEENDIAN 1102de3b87aSKai WangThe target is little endian. 1112de3b87aSKai Wang.It Dv DW_DLC_WRITE 1122de3b87aSKai Wang.Pq Required 1132de3b87aSKai WangPermit writing of DWARF information. 1142de3b87aSKai Wang.El 1152de3b87aSKai Wang.Pp 1162de3b87aSKai WangThe following flags are mutually exclusive. 1172de3b87aSKai Wang.Bl -bullet -compact 1182de3b87aSKai Wang.It 1192de3b87aSKai WangFlags 1202de3b87aSKai Wang.Dv DW_DLC_ISA_IA64 1212de3b87aSKai Wangand 1222de3b87aSKai Wang.Dv DW_DLC_ISA_MIPS . 1232de3b87aSKai Wang.It 1242de3b87aSKai WangFlags 1252de3b87aSKai Wang.Dv DW_DLC_SIZE_32 1262de3b87aSKai Wangand 1272de3b87aSKai Wang.Dv DW_DLC_SIZE_64 . 1282de3b87aSKai Wang.It 1292de3b87aSKai WangFlags 1302de3b87aSKai Wang.Dv DW_DLC_STREAM_RELOCATIONS 1312de3b87aSKai Wangand 1322de3b87aSKai Wang.Dv DW_DLC_SYMBOLIC_RELOCATIONS . 1332de3b87aSKai Wang.It 1342de3b87aSKai WangFlags 1352de3b87aSKai Wang.Dv DW_DLC_TARGET_BIGENDIAN 1362de3b87aSKai Wangand 1372de3b87aSKai Wang.Dv DW_DLC_TARGET_LITTLEENDIAN . 1382de3b87aSKai Wang.El 1392de3b87aSKai WangIf neither of the flags 1402de3b87aSKai Wang.Dv DW_DLC_TARGET_BIGENDIAN 1412de3b87aSKai Wangand 1422de3b87aSKai Wang.Dv DW_DLC_TARGET_LITTLEENDIAN 1432de3b87aSKai Wangis set, the target's endianness is assumed to be the same as the host's 1442de3b87aSKai Wangendianness. 1452de3b87aSKai Wang.Pp 1462de3b87aSKai WangArgument 1472de3b87aSKai Wang.Ar func 1482de3b87aSKai Wangshould point to an application-provided callback function of type 1492de3b87aSKai Wang.Vt Dwarf_Callback_Func_b . 1502de3b87aSKai WangThe type 1512de3b87aSKai Wang.Vt Dwarf_Callback_Func_b 1522de3b87aSKai Wangis defined in the header file 1532de3b87aSKai Wang.In libdwarf.h 1542de3b87aSKai Wangas: 1552de3b87aSKai Wang.Bd -literal -offset indent 1562de3b87aSKai Wangtypedef int (*Dwarf_Callback_Func_b)(char *name, int size, 1572de3b87aSKai Wang Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link, 1582de3b87aSKai Wang Dwarf_Unsigned info, Dwarf_Unsigned *index, int *error); 1592de3b87aSKai Wang.Ed 1602de3b87aSKai Wang.Pp 1612de3b87aSKai WangThis function is called by the 1622de3b87aSKai Wang.Lb libdwarf 1632de3b87aSKai Wangonce for each section in the object file that the library needs to 1642de3b87aSKai Wangcreate. 1652de3b87aSKai WangThe arguments to this callback function specify the values in the ELF 1662de3b87aSKai Wangsection header for the section being created: 1672de3b87aSKai Wang.Pp 1682de3b87aSKai Wang.Bl -tag -width indent -compact -offset indent 1692de3b87aSKai Wang.It Ar name 1702de3b87aSKai WangThe name of the section being created. 1712de3b87aSKai Wang.It Ar size 1722de3b87aSKai WangThe 1732de3b87aSKai Wang.Va sh_size 1742de3b87aSKai Wangvalue in the section header. 1752de3b87aSKai Wang.It Ar type 1762de3b87aSKai WangThe 1772de3b87aSKai Wang.Va sh_type 1782de3b87aSKai Wangvalue in the section header. 1792de3b87aSKai Wang.It Ar flags 1802de3b87aSKai WangThe 1812de3b87aSKai Wang.Va sh_flags 1822de3b87aSKai Wangvalue in the section header. 1832de3b87aSKai Wang.It Ar link 1842de3b87aSKai WangThe 1852de3b87aSKai Wang.Va sh_link 1862de3b87aSKai Wangvalue in the section header. 1872de3b87aSKai Wang.It Ar info 1882de3b87aSKai WangThe 1892de3b87aSKai Wang.Va sh_info 1902de3b87aSKai Wangvalue in the section header. 1912de3b87aSKai Wang.El 1922de3b87aSKai Wang.Pp 1932de3b87aSKai WangOn success, the callback function should return the section index 1942de3b87aSKai Wangvalue of the created section, and set the location pointed to by 1952de3b87aSKai Wangargument 1962de3b87aSKai Wang.Ar index 1972de3b87aSKai Wangto the symbol table index of the symbol that associated with the newly 1982de3b87aSKai Wangcreated section. 1992de3b87aSKai WangThis symbol table index will be used in relocation entries 2002de3b87aSKai Wangreferring to the created section. 2012de3b87aSKai Wang.Pp 2022de3b87aSKai WangIn case of failure, the callback function should return -1 and set the 2032de3b87aSKai Wanglocation pointed to by argument 2042de3b87aSKai Wang.Ar error 2052de3b87aSKai Wangto an application-defined error code. 2062de3b87aSKai WangThis application returned error code is currently ignored by the 2072de3b87aSKai Wanglibrary. 2082de3b87aSKai Wang.Pp 2092de3b87aSKai WangFunction 2102de3b87aSKai Wang.Fn dwarf_producer_init 2112de3b87aSKai Wangis deprecated. 2122de3b87aSKai WangFunction 2132de3b87aSKai Wang.Fn dwarf_producer_init 2142de3b87aSKai Wangis identical to function 2152de3b87aSKai Wang.Fn dwarf_producer_init_b 2162de3b87aSKai Wangexcept that the callback function it expects can not properly handle 2172de3b87aSKai Wangarbitrary section symbol index values. 2182de3b87aSKai Wang.Ss Memory Management 2192de3b87aSKai WangThe 2202de3b87aSKai Wang.Vt Dwarf_P_Debug 2212de3b87aSKai Wanginstance returned by these functions should be freed using the 2222de3b87aSKai Wangfunction 2232de3b87aSKai Wang.Fn dwarf_producer_finish . 2242de3b87aSKai Wang.Sh RETURN VALUES 2252de3b87aSKai WangOn success, these functions return the created DWARF producer 2262de3b87aSKai Wangdescriptor. 2272de3b87aSKai WangIn case of an error, they return 2282de3b87aSKai Wang.Dv DW_DLV_BADADDR 2292de3b87aSKai Wangand set the argument 2302de3b87aSKai Wang.Ar err . 231*ae500c1fSEd Maste.Sh EXAMPLES 232*ae500c1fSEd MasteTo initialize a 233*ae500c1fSEd Maste.Vt Dwarf_P_Debug 234*ae500c1fSEd Masteinstance for a MIPS32 big endian object, use: 235*ae500c1fSEd Maste.Bd -literal -offset indent 236*ae500c1fSEd MasteDwarf_P_Debug dbg; 237*ae500c1fSEd MasteDwarf_Unsigned flags; 238*ae500c1fSEd MasteDwarf_Error de; 239*ae500c1fSEd Maste 240*ae500c1fSEd Maste/* ... assume cb_func points to the callback function ... */ 241*ae500c1fSEd Maste 242*ae500c1fSEd Masteflags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS | 243*ae500c1fSEd Maste DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN; 244*ae500c1fSEd Masteif ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) == 245*ae500c1fSEd Maste DW_DLV_BADADDR) 246*ae500c1fSEd Maste warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1)); 247*ae500c1fSEd Maste.Ed 2482de3b87aSKai Wang.Sh ERRORS 2492de3b87aSKai WangThese functions can fail with: 2502de3b87aSKai Wang.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 2512de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 2522de3b87aSKai WangArgument 2532de3b87aSKai Wang.Ar func 2542de3b87aSKai Wangwas NULL. 2552de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 2562de3b87aSKai WangThe flag 2572de3b87aSKai Wang.Dv DW_DLC_WRITE 2582de3b87aSKai Wangwas not set in argument 2592de3b87aSKai Wang.Ar flags . 2602de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 2612de3b87aSKai WangThe flags 2622de3b87aSKai Wang.Dv DW_DLC_SIZE_32 2632de3b87aSKai Wangand 2642de3b87aSKai Wang.Dv DW_DLC_SIZE_64 2652de3b87aSKai Wangwere both set in argument 2662de3b87aSKai Wang.Ar flags . 2672de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 2682de3b87aSKai WangThe flags 2692de3b87aSKai Wang.Dv DW_DLC_ISA_IA64 2702de3b87aSKai Wangand 2712de3b87aSKai Wang.Dv DW_DLC_ISA_MIPS 2722de3b87aSKai Wangwere both set in argument 2732de3b87aSKai Wang.Ar flags . 2742de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 2752de3b87aSKai WangThe flags 2762de3b87aSKai Wang.Dv DW_DLC_TARGET_BIGENDIAN 2772de3b87aSKai Wangand 2782de3b87aSKai Wang.Dv DW_DLC_TARGET_LITTLEENDIAN 2792de3b87aSKai Wangwere both set in argument 2802de3b87aSKai Wang.Ar flags . 2812de3b87aSKai Wang.It Bq Er DW_DLE_ARGUMENT 2822de3b87aSKai WangThe flags 2832de3b87aSKai Wang.Dv DW_DLC_STREAM_RELOCATIONS 2842de3b87aSKai Wangand 2852de3b87aSKai Wang.Dv DW_DLC_SYMBOLIC_RELOCATIONS 2862de3b87aSKai Wangwere both set in argument 2872de3b87aSKai Wang.Ar flags . 2882de3b87aSKai Wang.It Bq Er DW_DLE_MEMORY 2892de3b87aSKai WangAn out of memory condition was encountered. 2902de3b87aSKai Wang.El 2912de3b87aSKai Wang.Sh SEE ALSO 2922de3b87aSKai Wang.Xr dwarf 3 , 2932de3b87aSKai Wang.Xr dwarf_errmsg 3 , 2942de3b87aSKai Wang.Xr dwarf_producer_finish 3 , 2952de3b87aSKai Wang.Xr dwarf_producer_set_isa 3 , 2962de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 297