---
name: "dwarf_producer_init_b"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/dwarf_producer_init"
---

# dwarf\_producer\_init\_b(3)

allocate a DWARF producer descriptor

Part of [dwarf\_producer\_init(3)](/dwarf_producer_init/3.md).

## NAME

**dwarf\_producer\_init**, **dwarf\_producer\_init\_b** – allocate a DWARF producer descriptor

## LIBRARY

library “libdwarf”

## 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.

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)](/dwarf/3.md).

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 the [dwarf\_producer\_set\_isa(3)](/dwarf_producer_set_isa/3.md) 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 the [dwarf\_producer\_set\_isa(3)](/dwarf_producer_set_isa/3.md) 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.

The following flags are mutually exclusive.

- Flags DW\_DLC\_ISA\_IA64 and DW\_DLC\_ISA\_MIPS.

- Flags DW\_DLC\_SIZE\_32 and DW\_DLC\_SIZE\_64.

- Flags DW\_DLC\_STREAM\_RELOCATIONS and DW\_DLC\_SYMBOLIC\_RELOCATIONS.

- Flags DW\_DLC\_TARGET\_BIGENDIAN and DW\_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 library “libdwarf” 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*

  The *sh\_size* value in the section header.

- *type*

  The *sh\_type* value in the section header.

- *flags*

  The *sh\_flags* value in the section header.

- *link*

  The *sh\_link* value in the section header.

- *info*

  The *sh\_info* value 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.

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.

Function **dwarf\_producer\_init**() is deprecated. Function **dwarf\_producer\_init**() is identical to function **dwarf\_producer\_init\_b**() except that the callback function it expects can not properly handle arbitrary section symbol index values.

### Memory Management

The *Dwarf\_P\_Debug* instance returned by these functions should be freed using the function **dwarf\_producer\_finish**().

## 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\]

  Argument *func* was NULL.

- \[DW\_DLE\_ARGUMENT\]

  The flag DW\_DLC\_WRITE was not set in argument *flags*.

- \[DW\_DLE\_ARGUMENT\]

  The flags DW\_DLC\_SIZE\_32 and DW\_DLC\_SIZE\_64 were both set in argument *flags*.

- \[DW\_DLE\_ARGUMENT\]

  The flags DW\_DLC\_ISA\_IA64 and DW\_DLC\_ISA\_MIPS were both set in argument *flags*.

- \[DW\_DLE\_ARGUMENT\]

  The flags DW\_DLC\_TARGET\_BIGENDIAN and DW\_DLC\_TARGET\_LITTLEENDIAN were both set in argument *flags*.

- \[DW\_DLE\_ARGUMENT\]

  The flags DW\_DLC\_STREAM\_RELOCATIONS and DW\_DLC\_SYMBOLIC\_RELOCATIONS were both set in argument *flags*.

- \[DW\_DLE\_MEMORY\]

  An out of memory condition was encountered.

## SEE ALSO

[dwarf(3)](/dwarf/3.md), [dwarf\_errmsg(3)](/dwarf_errmsg/3.md), dwarf\_producer\_finish(3), [dwarf\_producer\_set\_isa(3)](/dwarf_producer_set_isa/3.md), [dwarf\_transform\_to\_disk\_form(3)](/dwarf_transform_to_disk_form/3.md)
