---
name: "dwarf_get_elf"
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_get_elf"
---

# dwarf\_get\_elf(3)

retrieve the Elf descriptor associated with a Dwarf\_Debug instance

## NAME

**dwarf\_get\_elf** – retrieve the *Elf* descriptor associated with a *Dwarf\_Debug* instance

## LIBRARY

library “libdwarf”

## SYNOPSIS

**#include \<libdwarf.h\>**

*int*\

**dwarf\_get\_elf**(*Dwarf\_Debug dbg*, *Elf \*\*elf*, *Dwarf\_Error \*err*);

## DESCRIPTION

Function **dwarf\_get\_elf**() returns the *Elf* descriptor associated with a *Dwarf\_Debug* instance.

Argument *dbg* should be a handle to a valid *Dwarf\_Debug* instance returned by a prior call to [dwarf\_init(3)](/dwarf_init/3.md) or [dwarf\_elf\_init(3)](/dwarf_elf_init/3.md).

Argument *elf* points a location into which a handle to an *Elf* descriptor will be written.

Argument *err* is used to record error information in case of failure.

## RETURN VALUES

On success, function **dwarf\_get\_elf**() returns DW\_DLV\_OK. In case of an error, it returns DW\_DLV\_ERROR and sets argument *err*.

## EXAMPLES

To retrieve the *Elf* instance associated with a *Dwarf\_Debug* instance use:

```
Dwarf_Debug dbg;
Dwarf_Error de;
Elf *elf;
... allocate dbg using dwarf_init() etc ...
if (dwarf_get_elf(dbg, &elf, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_get_elf: %s", dwarf_errmsg(de));
```

## SEE ALSO

[dwarf(3)](/dwarf/3.md), [dwarf\_errmsg(3)](/dwarf_errmsg/3.md), [dwarf\_finish(3)](/dwarf_finish/3.md), [dwarf\_init(3)](/dwarf_init/3.md), [elf(3)](/elf/3.md)
