libdwarf
Reading a location expression

Example getting details of a location expression.

See also
Location/expression access
*/
int example_locexprc(Dwarf_Debug dbg,Dwarf_Ptr expr_bytes,
Dwarf_Unsigned expr_len,
Dwarf_Half addr_size,
Dwarf_Half offset_size,
Dwarf_Half version,
Dwarf_Error*error)
{
Dwarf_Loc_Head_c head = 0;
Dwarf_Locdesc_c locentry = 0;
int res2 = 0;
Dwarf_Unsigned rawlopc = 0;
Dwarf_Unsigned rawhipc = 0;
Dwarf_Bool debug_addr_unavail = FALSE;
Dwarf_Unsigned lopc = 0;
Dwarf_Unsigned hipc = 0;
Dwarf_Unsigned ulistlen = 0;
Dwarf_Unsigned ulocentry_count = 0;
Dwarf_Unsigned section_offset = 0;
Dwarf_Unsigned locdesc_offset = 0;
Dwarf_Small lle_value = 0;
Dwarf_Small loclist_source = 0;
expr_bytes,expr_len,
addr_size,
offset_size,
version,
&head,
&ulistlen,
error);
if (res2 != DW_DLV_OK) {
return res2;
}
/* These are a location expression, not loclist.
So we just need the 0th entry. */
0, /* Data from 0th because it is a loc expr,
there is no list */
&lle_value,
&rawlopc, &rawhipc, &debug_addr_unavail, &lopc, &hipc,
&ulocentry_count, &locentry,
&loclist_source, &section_offset, &locdesc_offset,
error);
if (res2 == DW_DLV_ERROR) {
return res2;
} else if (res2 == DW_DLV_NO_ENTRY) {
return res2;
}
/* ASSERT: ulistlen == 1 */
for (i = 0; i < ulocentry_count;++i) {
Dwarf_Small op = 0;
Dwarf_Unsigned opd1 = 0;
Dwarf_Unsigned opd2 = 0;
Dwarf_Unsigned opd3 = 0;
Dwarf_Unsigned offsetforbranch = 0;
i, &op,&opd1,&opd2,&opd3,
&offsetforbranch,
error);
/* Do something with the expression operator and operands */
if (res2 != DW_DLV_OK) {
return res2;
}
}
return DW_DLV_OK;
}
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:586
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:580
struct Dwarf_Locdesc_c_s * Dwarf_Locdesc_c
Definition: libdwarf.h:331
struct Dwarf_Loc_Head_c_s * Dwarf_Loc_Head_c
Definition: libdwarf.h:337
unsigned char Dwarf_Small
Definition: libdwarf.h:204
unsigned short Dwarf_Half
Definition: libdwarf.h:203
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
void * Dwarf_Ptr
Definition: libdwarf.h:208
int Dwarf_Bool
Definition: libdwarf.h:202
int dwarf_get_location_op_value_c(Dwarf_Locdesc_c dw_locdesc, Dwarf_Unsigned dw_index, Dwarf_Small *dw_operator_out, Dwarf_Unsigned *dw_operand1, Dwarf_Unsigned *dw_operand2, Dwarf_Unsigned *dw_operand3, Dwarf_Unsigned *dw_offset_for_branch, Dwarf_Error *dw_error)
Get the raw values from a single location operation.
int dwarf_loclist_from_expr_c(Dwarf_Debug dw_dbg, Dwarf_Ptr dw_expression_in, Dwarf_Unsigned dw_expression_length, Dwarf_Half dw_address_size, Dwarf_Half dw_offset_size, Dwarf_Half dw_dwarf_version, Dwarf_Loc_Head_c *dw_loc_head, Dwarf_Unsigned *dw_listlen, Dwarf_Error *dw_error)
Generate a Dwarf_Loc_Head_c from an expression block.
int dwarf_get_locdesc_entry_d(Dwarf_Loc_Head_c dw_loclist_head, Dwarf_Unsigned dw_index, Dwarf_Small *dw_lle_value_out, Dwarf_Unsigned *dw_rawlowpc, Dwarf_Unsigned *dw_rawhipc, Dwarf_Bool *dw_debug_addr_unavailable, Dwarf_Addr *dw_lowpc_cooked, Dwarf_Addr *dw_hipc_cooked, Dwarf_Unsigned *dw_locexpr_op_count_out, Dwarf_Locdesc_c *dw_locentry_out, Dwarf_Small *dw_loclist_source_out, Dwarf_Unsigned *dw_expression_offset_out, Dwarf_Unsigned *dw_locdesc_offset_out, Dwarf_Error *dw_error)
Retrieve the details of a location expression.
void dwarf_dealloc_loc_head_c(Dwarf_Loc_Head_c dw_head)
Dealloc (free) all memory allocated for Dwarf_Loc_Head_c.