DWARF_PRODUCER_INIT(3)
DWARF_PRODUCER_INIT(3) π
okay bestie, this page is from the Library Functions Manual and it's all about allocating a DWARF producer descriptor. It's giving big libdwarf energy, and we're gonna keep every single detail while making it make sense π
π NAME π
dwarf_producer_init, dwarf_producer_init_b β allocate a DWARF producer descriptor
π LIBRARY π
DWARF Access Library (libdwarf, -ldwarf) β literally the library and linker flag, bestie β¨
πͺ SYNOPSIS πͺ
#include <libdwarf.h>
Dwarf_P_Debug
dwarf_producer_init(Dwarf_Unsigned flags, Dwarf_Callback_Func func,
Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *err);
Dwarf_P_Debug
dwarf_producer_init_b(Dwarf_Unsigned flags, Dwarf_Callback_Func_b func,
Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *error);
πΈ DESCRIPTION πΈ
These functions allocate and return a Dwarf_P_Debug descriptor representing a DWARF producer instance. Slay.
The argument errhand should contain the address of a function to be called in case of an error. If this argument is NULL, the default error handling scheme is used, see dwarf(3).
The argument errarg will be passed to the error handler function when it is invoked.
The argument err references a memory location that would hold a Dwarf_Error descriptor in case of an error.
The argument flags specifies additional characteristics of the DWARF producer instance. The following flags are recognized:
DW_DLC_ISA_IA64β (Deprecated) the target instruction set architecture is IA64. This flag is deprecated. Application code should use thedwarf_producer_set_isa(3)function to specify target instruction set architecture. π«DW_DLC_ISA_MIPSβ (Deprecated) the target instruction set architecture is MIPS. This flag is deprecated. Application code should use thedwarf_producer_set_isa(3)function to specify target instruction set architecture. π«DW_DLC_SIZE_32β (Default) the target address size is 32-bit.DW_DLC_SIZE_64β the target address size is 64-bit.DW_DLC_STREAM_RELOCATIONSβ (Default) generate stream relocations.DW_DLC_SYMBOLIC_RELOCATIONSβ generate symbolic relocations.DW_DLC_TARGET_BIGENDIANβ the target is big endian.DW_DLC_TARGET_LITTLEENDIANβ the target is little endian.DW_DLC_WRITEβ (Required) permit writing of DWARF information. Don't skip this one, bestie, it's literally required π
The following flags are mutually exclusive. Pick one from each pair, no chaotic combos:
- Flags
DW_DLC_ISA_IA64andDW_DLC_ISA_MIPS. - Flags
DW_DLC_SIZE_32andDW_DLC_SIZE_64. - Flags
DW_DLC_STREAM_RELOCATIONSandDW_DLC_SYMBOLIC_RELOCATIONS. - Flags
DW_DLC_TARGET_BIGENDIANandDW_DLC_TARGET_LITTLEENDIAN.
If neither of the flags DW_DLC_TARGET_BIGENDIAN and DW_DLC_TARGET_LITTLEENDIAN is set, the target's endianness is assumed to be the same as the host's endianness.
Argument func should point to an application-provided callback function of type Dwarf_Callback_Func_b. The type Dwarf_Callback_Func_b is defined in the header file <libdwarf.h> as:
typedef int (*Dwarf_Callback_Func_b)(char *name, int size,
Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link,
Dwarf_Unsigned info, Dwarf_Unsigned *index, int *error);
This function is called by the DWARF Access Library (libdwarf, -ldwarf) once for each section in the object file that the library needs to create. The arguments to this callback function specify the values in the ELF section header for the section being created:
nameβ the name of the section being created.sizeβ thesh_sizevalue in the section header.typeβ thesh_typevalue in the section header.flagsβ thesh_flagsvalue in the section header.linkβ thesh_linkvalue in the section header.infoβ thesh_infovalue in the section header.
On success, the callback function should return the section index value of the created section, and set the location pointed to by argument index to the symbol table index of the symbol that associated with the newly created section. This symbol table index will be used in relocation entries referring to the created section. Iconic behavior β¨
In case of failure, the callback function should return -1 and set the location pointed to by argument error to an application-defined error code. This application returned error code is currently ignored by the library.
β οΈ Deprecated alert, bestie: functiondwarf_producer_init()is deprecated. Functiondwarf_producer_init()is identical to functiondwarf_producer_init_b()except that the callback function it expects can not properly handle arbitrary section symbol index values. That's the tea β
π§Ή Memory Management π§Ή
The Dwarf_P_Debug instance returned by these functions should be freed using the function dwarf_producer_finish(). Clean up after yourself, periodt π
π RETURN VALUES π
On success, these functions return the created DWARF producer descriptor. In case of an error, they return DW_DLV_BADADDR and set the argument err.
π§ͺ EXAMPLES π§ͺ
To initialize a Dwarf_P_Debug instance for a MIPS32 big endian object, use:
Dwarf_P_Debug dbg;
Dwarf_Unsigned flags;
Dwarf_Error de;
/* ... assume cb_func points to the callback function ... */
flags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS |
DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN;
if ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) ==
DW_DLV_BADADDR)
warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1));
π ERRORS π
These functions can fail with:
[DW_DLE_ARGUMENT]β argumentfuncwasNULL. π[DW_DLE_ARGUMENT]β the flagDW_DLC_WRITEwas not set in argumentflags.[DW_DLE_ARGUMENT]β the flagsDW_DLC_SIZE_32andDW_DLC_SIZE_64were both set in argumentflags.[DW_DLE_ARGUMENT]β the flagsDW_DLC_ISA_IA64andDW_DLC_ISA_MIPSwere both set in argumentflags.[DW_DLE_ARGUMENT]β the flagsDW_DLC_TARGET_BIGENDIANandDW_DLC_TARGET_LITTLEENDIANwere both set in argumentflags.[DW_DLE_ARGUMENT]β the flagsDW_DLC_STREAM_RELOCATIONSandDW_DLC_SYMBOLIC_RELOCATIONSwere both set in argumentflags.[DW_DLE_MEMORY]β an out of memory condition was encountered.
π SEE ALSO π
dwarf(3), dwarf_errmsg(3), dwarf_producer_finish(3), dwarf_producer_set_isa(3), dwarf_transform_to_disk_form(3)
xoxo, from Debian π β August 20, 2011 π«Ά
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: libdwarf 15.0.0
- Copyright (c) 2011 Kai Wang
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms