---
name: "dwarf_add_AT_location_expr"
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_location_expr"
---

# dwarf\_add\_AT\_location\_expr(3)

create an attribute descriptor for a location expression

## NAME

**dwarf\_add\_AT\_location\_expr** – create an attribute descriptor for a location expression

## LIBRARY

library “libdwarf”

## SYNOPSIS

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

*Dwarf\_P\_Attribute*\

**dwarf\_add\_AT\_location\_expr**(*Dwarf\_P\_Debug dbg*, *Dwarf\_P\_Die die*, *Dwarf\_Half attr*, *Dwarf\_P\_Expr loc\_expr*, *Dwarf\_Error \*err*);

## DESCRIPTION

Function **dwarf\_add\_AT\_location\_expr**() creates an attribute descriptor for a location expression and attaches it to the debugging information entry referenced by argument *die*.

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* specifies the attribute code of the created attribute descriptor.

Argument *loc\_expr* should reference a location expression descriptor allocated using [dwarf\_new\_expr(3)](/dwarf_new_expr/3.md).

The attribute created by function **dwarf\_add\_AT\_location\_expr**() will have one of the DWARF forms DW\_FORM\_block, DW\_FORM\_block1, DW\_FORM\_block2 or DW\_FORM\_block4, depending on the size of the byte stream generated by the location expression descriptor referenced by argument *loc\_expr*.

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

## RETURN VALUES

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

## ERRORS

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

- \[DW\_DLE\_ARGUMENT\]

  One of the arguments *dbg*, *die* or *loc\_expr* 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\_new\_die(3)](/dwarf_new_die/3.md), [dwarf\_new\_expr(3)](/dwarf_new_expr/3.md), [dwarf\_producer\_init(3)](/dwarf_producer_init/3.md), [dwarf\_producer\_init\_b(3)](/dwarf_producer_init_b/3.md)
