DWARF_FORMREF(3)

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

πŸ’… DWARF_FORMREF(3) β€” ok so bestie, it's a libdwarf manpage from the Library Functions Manual 🌸

No cap, this one's a little niche but it slaps once you get it. We're talking about dwarf_formref and dwarf_global_formref β€” the two functions that pull offsets out of REFERENCE class attributes. Pull up a chair, we're doing this. πŸͺ‘


✨ NAME ✨

dwarf_formref, dwarf_global_formref β€” retrieve offsets for REFERENCE class attributes 🎯


πŸ“š LIBRARY πŸ“š

DWARF Access Library β€” that's libdwarf, and you link it with -ldwarf. Iconic. πŸ’œ


🧚 SYNOPSIS 🧚

Like, just copy it exactly, don't come for me:

#include <libdwarf.h>

int
dwarf_formref(Dwarf_Attribute attr, Dwarf_Off *retoffset,
    Dwarf_Error *err);

int
dwarf_global_formref(Dwarf_Attribute attr, Dwarf_Off *retoffset,
    Dwarf_Error *err);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so both of these functions return the offsets associated with a DWARF attribute descriptor. Same energy, different scope β€” and the scope thing is the whole plot twist, so listen up. πŸ‘€

πŸ’– dwarf_formref()

This one returns the compilation unit relative offset of the descriptor referenced by argument attr, and it puts it in the location pointed to by argument retoffset. 🫢

Heads up: argument attr must be a reference that is local to a compilation unit. That's not a suggestion, bestie, that's the requirement.

The permitted forms for argument attr are:

  • DW_FORM_ref1
  • DW_FORM_ref2
  • DW_FORM_ref4
  • DW_FORM_ref8
  • DW_FORM_ref_udata

🌈 dwarf_global_formref()

This one returns the section-relative offset of the descriptor referenced by argument attr, dropped into the location pointed to by argument retoffset. ✨

Argument attr should be a legal REFERENCE class form. The permitted forms for argument attr are:

  • DW_FORM_ref_addr
  • DW_FORM_ref_udata
  • DW_FORM_ref1
  • DW_FORM_ref2
  • DW_FORM_ref4
  • DW_FORM_ref8
  • DW_FORM_sec_offset

And the returned offset is relative to the start of the .debug_info ELF section. That's the whole vibe β€” .debug_info, always. πŸ’€

πŸŽ€ the err situation

If argument err is not NULL, it will be used to return an error descriptor in case of an error. If it is NULL, well β€” you do you, but don't say nobody warned you. πŸ™ˆ


πŸ‘‘ RETURN VALUES πŸ‘‘

These functions return DW_DLV_OK on success. Slay. πŸŽ‰

In case of an error, these functions return DW_DLV_ERROR and sets argument err. So yeah, check that err, bestie. 😭


πŸ’€ ERRORS πŸ’€

These functions may fail with the following errors:

  • [DW_DLE_ARGUMENT] β€” Either of arguments attr or retoffset was NULL. Classic.
  • [DW_DLE_ATTR_FORM_BAD] β€” The attribute referenced by argument attr was not of a permitted kind. You gave it the wrong form and it's giving "not today". 🚫

πŸ”₯ SEE ALSO πŸ”₯

Go read these next, iykyk β€” the whole friend group:


okay that's the whole page, mwah πŸ’‹ This one's from Debian, dated June 21, 2010 β€” vintage, honestly, but still serving. Go be a main character with your offsets, bestie πŸŽ€πŸ¦‹β­

πŸ“¦ where this page comes from