---
name: "dwarf_add_AT_reference"
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_add_AT_reference"
---

# dwarf\_add\_AT\_reference(3)

create and attach an attribute that references another DIE

## NAME

**dwarf\_add\_AT\_reference** – create and attach an attribute that references another DIE

## LIBRARY

library “libdwarf”

## SYNOPSIS

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

*Dwarf\_P\_Attribute*\

**dwarf\_add\_AT\_reference**(*Dwarf\_P\_Debug dbg*, *Dwarf\_P\_Die die*, *Dwarf\_Half attr*, *Dwarf\_P\_Die ref\_die*, *Dwarf\_Error \*err*);

## DESCRIPTION

Function **dwarf\_add\_AT\_reference**() creates an attribute descriptor that references another debugging information entry in the same compilation unit. The attribute will be of DWARF form DW\_FORM\_ref4 or DW\_FORM\_ref8 depending on the target address size, and will contain the section-relative offset of the referenced debugging information entry as its value.

Argument *dbg* should reference a DWARF producer instance allocated using [dwarf\_producer\_init(3)](/dwarf_producer_init/3.md) or [dwarf\_producer\_init\_b(3)](/dwarf_producer_init_b/3.md).

Argument *die* should reference a debugging information entry allocated using [dwarf\_new\_die(3)](/dwarf_new_die/3.md).

Argument *attr* should specify the attribute code of the created attribute descriptor.

Argument *ref\_die* should hold the debugging information entry descriptor that the attribute should refer to.

If argument *err* is not NULL, it will be used to store error information in case of an error.

## RETURN VALUES

On success, function **dwarf\_add\_AT\_reference**() returns the created attribute descriptor. In case of an error, function **dwarf\_add\_AT\_reference**() returns DW\_DLV\_BADADDR and sets the argument *err*.

## ERRORS

Function **dwarf\_add\_AT\_reference**() can fail with:

- \[DW\_DLE\_ARGUMENT\]

  One of the arguments *dbg*, *die* or *ref\_die* was NULL.

- \[DW\_DLE\_MEMORY\]

  An out of memory condition was encountered during the execution of the function.

## SEE ALSO

[dwarf(3)](/dwarf/3.md), [dwarf\_add\_AT\_dataref(3)](/dwarf_add_AT_dataref/3.md), [dwarf\_add\_AT\_ref\_address(3)](/dwarf_add_AT_ref_address/3.md), [dwarf\_add\_AT\_signed\_const(3)](/dwarf_add_AT_signed_const/3.md), [dwarf\_add\_AT\_unsigned\_const(3)](/dwarf_add_AT_unsigned_const/3.md), [dwarf\_new\_die(3)](/dwarf_new_die/3.md), [dwarf\_producer\_init(3)](/dwarf_producer_init/3.md), [dwarf\_producer\_init\_b(3)](/dwarf_producer_init_b/3.md)
