DWARF_FORMREF(3)
π
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_ref1DW_FORM_ref2DW_FORM_ref4DW_FORM_ref8DW_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_addrDW_FORM_ref_udataDW_FORM_ref1DW_FORM_ref2DW_FORM_ref4DW_FORM_ref8DW_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 argumentsattrorretoffsetwasNULL. Classic.[DW_DLE_ATTR_FORM_BAD]β The attribute referenced by argumentattrwas 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:
dwarf(3)dwarf_attr(3)dwarf_formblock(3)dwarf_formflag(3)dwarf_formsdata(3)dwarf_formsig8(3)dwarf_formstring(3)dwarf_formudata(3)dwarf_hasattr(3)
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
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: libdwarf 15.0.0
- Copyright (c) 2010 Joseph Koshy
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms