1.\" $NetBSD: dwarf_producer_init.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2.\" 3.\" Copyright (c) 2011 Kai Wang 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_producer_init.3 2074 2011-10-27 03:34:33Z jkoshy 28.\" 29.Dd August 20, 2011 30.Os 31.Dt DWARF_PRODUCER_INIT 3 32.Sh NAME 33.Nm dwarf_producer_init 34.Nm dwarf_producer_init_b 35.Nd allocate a DWARF producer descriptor 36.Sh LIBRARY 37.Lb libdwarf 38.Sh SYNOPSIS 39.In libdwarf.h 40.Ft Dwarf_P_Debug 41.Fo dwarf_producer_init 42.Fa "Dwarf_Unsigned flags" 43.Fa "Dwarf_Callback_Func func" 44.Fa "Dwarf_Handler errhand" 45.Fa "Dwarf_Ptr errarg" 46.Fa "Dwarf_Error *err" 47.Fc 48.Ft Dwarf_P_Debug 49.Fo dwarf_producer_init_b 50.Fa "Dwarf_Unsigned flags" 51.Fa "Dwarf_Callback_Func_b func" 52.Fa "Dwarf_Handler errhand" 53.Fa "Dwarf_Ptr errarg" 54.Fa "Dwarf_Error *error" 55.Fc 56.Sh DESCRIPTION 57These functions allocate and return a 58.Vt Dwarf_P_Debug 59descriptor representing a DWARF producer instance. 60.Pp 61The argument 62.Ar errhand 63should contain the adddress of a function to be called in case of an 64error. 65If this argument is 66.Dv NULL , 67the default error handling scheme is used, see 68.Xr dwarf 3 . 69.Pp 70The argument 71.Ar errarg 72will be passed to the error handler function when it is invoked. 73.Pp 74The argument 75.Ar err 76references a memory location that would hold a 77.Vt Dwarf_Error 78descriptor in case of an error. 79.Pp 80The argument 81.Ar flags 82specifies additional characteristics of the DWARF producer instance. 83The following flags are recognized: 84.Pp 85.Bl -tag -width "Dv DW_DLC_ISA_MIPS" 86.It Dv DW_DLC_ISA_IA64 87.Pq Deprecated 88The target instruction set architecture is IA64. 89This flag is deprecated. 90Application code should use the 91.Xr dwarf_producer_set_isa 3 92function to specify target instruction set architecture. 93.It Dv DW_DLC_ISA_MIPS 94.Pq Deprecated 95The target instruction set architecture is MIPS. 96This flag is deprecated. 97Application code should use the 98.Xr dwarf_producer_set_isa 3 99function to specify target instruction set architecture. 100.It Dv DW_DLC_SIZE_32 101.Pq Default 102The target address size is 32-bit. 103.It Dv DW_DLC_SIZE_64 104The target address size is 64-bit. 105.It Dv DW_DLC_STREAM_RELOCATIONS 106.Pq Default 107Generate stream relocations. 108.It Dv DW_DLC_SYMBOLIC_RELOCATIONS 109Generate symbolic relocations. 110.It Dv DW_DLC_TARGET_BIGENDIAN 111The target is big endian. 112.It Dv DW_DLC_TARGET_LITTLEENDIAN 113The target is little endian. 114.It Dv DW_DLC_WRITE 115.Pq Required 116Permit writing of DWARF information. 117.El 118.Pp 119The following flags are mutually exclusive. 120.Bl -bullet -compact 121.It 122Flags 123.Dv DW_DLC_ISA_IA64 124and 125.Dv DW_DLC_ISA_MIPS . 126.It 127Flags 128.Dv DW_DLC_SIZE_32 129and 130.Dv DW_DLC_SIZE_64 . 131.It 132Flags 133.Dv DW_DLC_STREAM_RELOCATIONS 134and 135.Dv DW_DLC_SYMBOLIC_RELOCATIONS . 136.It 137Flags 138.Dv DW_DLC_TARGET_BIGENDIAN 139and 140.Dv DW_DLC_TARGET_LITTLEENDIAN . 141.El 142If neither of the flags 143.Dv DW_DLC_TARGET_BIGENDIAN 144and 145.Dv DW_DLC_TARGET_LITTLEENDIAN 146is set, the target's endianness is assumed to be the same as the host's 147endianness. 148.Pp 149Argument 150.Ar func 151should point to an application-provided callback function of type 152.Vt Dwarf_Callback_Func_b . 153The type 154.Vt Dwarf_Callback_Func_b 155is defined in the header file 156.In libdwarf.h 157as: 158.Bd -literal -offset indent 159typedef int (*Dwarf_Callback_Func_b)(char *name, int size, 160 Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link, 161 Dwarf_Unsigned info, Dwarf_Unsigned *index, int *error); 162.Ed 163.Pp 164This function is called by the 165.Lb libdwarf 166once for each section in the object file that the library needs to 167create. 168The arguments to this callback function specify the values in the ELF 169section header for the section being created: 170.Pp 171.Bl -tag -width indent -compact -offset indent 172.It Ar name 173The name of the section being created. 174.It Ar size 175The 176.Va sh_size 177value in the section header. 178.It Ar type 179The 180.Va sh_type 181value in the section header. 182.It Ar flags 183The 184.Va sh_flags 185value in the section header. 186.It Ar link 187The 188.Va sh_link 189value in the section header. 190.It Ar info 191The 192.Va sh_info 193value in the section header. 194.El 195.Pp 196On success, the callback function should return the section index 197value of the created section, and set the location pointed to by 198argument 199.Ar index 200to the symbol table index of the symbol that associated with the newly 201created section. 202This symbol table index will be used in relocation entries 203referring to the created section. 204.Pp 205In case of failure, the callback function should return -1 and set the 206location pointed to by argument 207.Ar error 208to an application-defined error code. 209This application returned error code is currently ignored by the 210library. 211.Pp 212Function 213.Fn dwarf_producer_init 214is deprecated. 215Function 216.Fn dwarf_producer_init 217is identical to function 218.Fn dwarf_producer_init_b 219except that the callback function it expects can not properly handle 220arbitrary section symbol index values. 221.Ss Memory Management 222The 223.Vt Dwarf_P_Debug 224instance returned by these functions should be freed using the 225function 226.Fn dwarf_producer_finish . 227.Sh RETURN VALUES 228On success, these functions return the created DWARF producer 229descriptor. 230In case of an error, they return 231.Dv DW_DLV_BADADDR 232and set the argument 233.Ar err . 234.Sh ERRORS 235These functions can fail with: 236.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 237.It Bq Er DW_DLE_ARGUMENT 238Argument 239.Ar func 240was NULL. 241.It Bq Er DW_DLE_ARGUMENT 242The flag 243.Dv DW_DLC_WRITE 244was not set in argument 245.Ar flags . 246.It Bq Er DW_DLE_ARGUMENT 247The flags 248.Dv DW_DLC_SIZE_32 249and 250.Dv DW_DLC_SIZE_64 251were both set in argument 252.Ar flags . 253.It Bq Er DW_DLE_ARGUMENT 254The flags 255.Dv DW_DLC_ISA_IA64 256and 257.Dv DW_DLC_ISA_MIPS 258were both set in argument 259.Ar flags . 260.It Bq Er DW_DLE_ARGUMENT 261The flags 262.Dv DW_DLC_TARGET_BIGENDIAN 263and 264.Dv DW_DLC_TARGET_LITTLEENDIAN 265were both set in argument 266.Ar flags . 267.It Bq Er DW_DLE_ARGUMENT 268The flags 269.Dv DW_DLC_STREAM_RELOCATIONS 270and 271.Dv DW_DLC_SYMBOLIC_RELOCATIONS 272were both set in argument 273.Ar flags . 274.It Bq Er DW_DLE_MEMORY 275An out of memory condition was encountered. 276.El 277.Sh EXAMPLES 278To initialize a 279.Vt Dwarf_P_Debug 280instance for a MIPS32 big endian object, use: 281.Bd -literal -offset indent 282Dwarf_P_Debug dbg; 283Dwarf_Unsigned flags; 284Dwarf_Error de; 285 286/* ... assume cb_func points to the callback function ... */ 287 288flags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS | 289 DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN; 290if ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) == 291 DW_DLV_BADADDR) 292 warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1)); 293.Ed 294.Sh SEE ALSO 295.Xr dwarf 3 , 296.Xr dwarf_errmsg 3 , 297.Xr dwarf_producer_finish 3 , 298.Xr dwarf_producer_set_isa 3 , 299.Xr dwarf_transform_to_disk_form 3 300