DWARF_NEW_EXPR(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

DWARF_NEW_EXPR(3) πŸ’…

okay so welcome to the Library Functions Manual page for DWARF_NEW_EXPR(3) β€” yes, this is your DWARF girlie era, and we're gonna make a location expression descriptor together, no cap. ✨

🌸 NAME 🌸

dwarf_new_expr β€” create a location expression descriptor. That's the whole assignment, bestie. πŸŽ€

πŸ¦‹ LIBRARY πŸ¦‹

DWARF Access Library (libdwarf, -ldwarf). Iconic. πŸ’–

✨ SYNOPSIS ✨

#include <libdwarf.h>

Dwarf_P_Expr
dwarf_new_expr(Dwarf_P_Debug dbg, Dwarf_Error *err);

🧚 DESCRIPTION 🧚

Function dwarf_new_expr() allocates a DWARF location expression descriptor used to build up a location expression stream. Literally the starting point for your expression stream era. 🫢

Your app can use dwarf_add_expr_gen(3) and dwarf_add_expr_addr_b(3) to add location expression operators to the created descriptor. When you're done, call dwarf_expr_into_block(3) to retrieve the generated byte stream for the location expression, or call dwarf_add_AT_location_expr(3) to create an attribute with the location expression stream as its value. Slay. πŸ’…

Argument dbg should reference a DWARF producer instance allocated using dwarf_producer_init(3) or dwarf_producer_init_b(3). Keep that in mind, bestie.

If argument err is not NULL, it will be used to store error information in case of an error. So pass it if you want the tea. β˜•

πŸ‘‘ RETURN VALUES πŸ‘‘

On success, function dwarf_new_expr() returns the created location expression descriptor. In case of an error, function dwarf_new_expr() returns DW_DLV_BADADDR and sets the argument err. No cap. πŸ’€

🌈 EXAMPLES 🌈

To create a location expression descriptor, add location expression operators to it and to retrieve the generated byte stream, use:

             Dwarf_P_Debug dbg;
             Dwarf_Error de;
             Dwarf_P_Expr pe;
             Dwarf_Addr buf;
             Dwarf_Unsigned len;

             /* ...Assume that `dbg' refers to a DWARF producer instance... */

             if ((pe = dwarf_new_expr(dbg, &de)) == DW_DLV_BADADDR) {
                     warnx("dwarf_new_expr failed: %s", dwarf_errmsg(-1));
                     return;
             }

             if (dwarf_add_expr_gen(pe, DW_OP_regx, 55, 0, &de) ==
                 DW_DLV_NOCOUNT) {
                     warnx("dwarf_add_expr_gen failed: %s", dwarf_errmsg(-1));
                     return;
             }

             if ((buf = dwarf_expr_into_block(pe, &len, &de)) ==
                 DW_DLV_BADADDR) {
                     warnx("dwarf_expr_into_block failed: %s",
                         dwarf_errmsg(-1));
                     return;
             }

🚨 ERRORS 🚨

Function dwarf_new_expr() can fail with:

  • [DW_DLE_ARGUMENT] β€” Argument dbg was NULL.
  • [DW_DLE_MEMORY] β€” An out of memory condition was encountered during the execution of the function.
The [DW_DLE_ARGUMENT] one is giving "you forgot the dbg, bestie" energy; the [DW_DLE_MEMORY] one is the classic out-of-memory jump scare. 😭

πŸ”— SEE ALSO πŸ”—

dwarf(3), dwarf_add_AT_location_expr(3), dwarf_add_expr_addr(3), dwarf_add_expr_addr_b(3), dwarf_add_expr_gen(3), dwarf_expr_current_offset(3), dwarf_expr_into_block(3), dwarf_producer_init(3), dwarf_producer_init_b(3).

Go read those too, bestie β€” the whole friend group is linked. 🫢


Debian, September 8, 2011 β€” DWARF_NEW_EXPR(3), signing off. Stay iconic, and may your location expressions always be stream-ready. πŸ’–βœ¨
πŸ“¦ where this page comes from