---
name: "dwarf_add_expr_gen"
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_expr_gen"
---

# dwarf\_add\_expr\_gen(3)

add an operator to a location expression descriptor

## NAME

**dwarf\_add\_expr\_gen** – add an operator to a location expression descriptor

## LIBRARY

library “libdwarf”

## SYNOPSIS

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

*Dwarf\_Unsigned*\

**dwarf\_add\_expr\_gen**(*Dwarf\_P\_Expr expr*, *Dwarf\_Small opcode*, *Dwarf\_Unsigned val1*, *Dwarf\_Unsigned val2*, *Dwarf\_Error \*err*);

## DESCRIPTION

Function **dwarf\_add\_expr\_gen**() adds a location expression operator to the location expression descriptor referenced by argument *expr*.

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

Argument *opcode* specifies the operation code of the location expression operator. Valid values for this argument are those denoted by the DW\_OP\_\* constants defined in ⟨libdwarf.h⟩.

To generate a DW\_OP\_addr operation, application code should instead use [dwarf\_add\_expr\_addr\_b(3)](/dwarf_add_expr_addr_b/3.md).

Argument *val1* specifies the first operand of the location expression operator.

Argument *val2* specifies the second operand of the location expression operator.

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\_expr\_gen**() returns the size in bytes of the location expression byte stream generated. In case of an error, function **dwarf\_add\_expr\_gen**() returns DW\_DLV\_NOCOUNT and sets the argument *err*.

## ERRORS

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

- \[DW\_DLE\_ARGUMENT\]

  Argument *expr* was NULL.

- \[DW\_DLE\_LOC\_EXPR\_BAD\]

  The operation code specified in argument *opcode* was invalid.

- \[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\_location\_expr(3)](/dwarf_add_AT_location_expr/3.md), [dwarf\_add\_expr\_addr(3)](/dwarf_add_expr_addr/3.md), [dwarf\_add\_expr\_addr\_b(3)](/dwarf_add_expr_addr_b/3.md), [dwarf\_expr\_current\_offset(3)](/dwarf_expr_current_offset/3.md), [dwarf\_expr\_into\_block(3)](/dwarf_expr_into_block/3.md), [dwarf\_new\_expr(3)](/dwarf_new_expr/3.md)
