diff options
author | Mark Wielaard <mjw@redhat.com> | 2013-08-30 23:55:12 +0200 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2013-09-06 12:09:45 +0200 |
commit | b2535b6a6be7717cdd41834d76e5cb48cb446b83 (patch) | |
tree | 6f90ce8b4e754103beaf72cef9778fe744ddc65d /libdw/dwarf_getlocation.c | |
parent | 66eaae9bcc1608efad65e3aa0204afbb3cb1a83d (diff) | |
download | elfutils-b2535b6a6be7717cdd41834d76e5cb48cb446b83.tar.gz |
libdw: Add new functions dwarf_getlocation_attr and dwarf_getlocation_die.
Some location expression operations have a DIE associated with them.
Examples are some of the new GNU typed DWARF extensions, DW_OP_GNU_convert,
DW_OP_GNU_reinterpret, DW_OP_GNU_const_type, DW_OP_GNU_regval_type and
DW_OP_GNU_deref_type. Others have (block) values associated with them,
like DW_OP_GNU_entry_value and DW_OP_GNU_const_type.
It is not always easy to access these values. The DIE offset is given in
various formats either as global offset or CU relative offset. The (block)
value might be constant or a location description. And the block might be
encoded with a uleb128 or ubyte length. The new functions help to easily
get at the DIE or attribute value.
In theory dwarf_getlocation_attr could be used for all cases, since
besides returning DW_AT_const_value or DW_AT_location, it could also
return an attribute referencing a DIE. But at least one operation,
DW_OP_GNU_const_type, has both a (type) DIE and a constant (block)
value associated with it. And directly getting the DIE when needed
is easier than first having to retrieve a (synthesized) attribute
and then getting the actual (type) DIE.
Expression operations that reference an actual DIE for the
DW_AT_location or DW_AT_const_value, like DW_OP_call2, DW_OP_call4,
DW_OP_callref and DW_OP_GNU_implicit_pointer can be used with both
dwarf_getlocation_attr and dwarf_getlocation_die.
DW_OP_implicit_value and DW_OP_GNU_implicit_pointer already had
their own special accessors (dwarf_getlocation_implicit_value
and dwarf_getlocation_implicit_pointer), but it seemed consistent
to include them in the new more generic accessors too.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libdw/dwarf_getlocation.c')
-rw-r--r-- | libdw/dwarf_getlocation.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/libdw/dwarf_getlocation.c b/libdw/dwarf_getlocation.c index aab471c6..f7d64f41 100644 --- a/libdw/dwarf_getlocation.c +++ b/libdw/dwarf_getlocation.c @@ -95,13 +95,15 @@ loc_compare (const void *p1, const void *p2) /* For each DW_OP_implicit_value, we store a special entry in the cache. This points us directly to the block data for later fetching. */ static void -store_implicit_value (Dwarf *dbg, void **cache, Dwarf_Op *op, - unsigned char *data) +store_implicit_value (Dwarf *dbg, void **cache, Dwarf_Op *op) { struct loc_block_s *block = libdw_alloc (dbg, struct loc_block_s, sizeof (struct loc_block_s), 1); + const unsigned char *data = (const unsigned char *) op->number2; + Dwarf_Word blength; // Ignored, equal to op->number. + get_uleb128 (blength, data); block->addr = op; - block->data = data + op->number2; + block->data = (unsigned char *) data; block->length = op->number; (void) tsearch (block, cache, loc_compare); } @@ -412,11 +414,11 @@ __libdw_intern_expression (Dwarf *dbg, bool other_byte_order, if (unlikely (dbg == NULL)) goto invalid; + newloc->number2 = (Dwarf_Word) data; /* start of block inc. len. */ /* XXX Check size. */ get_uleb128 (newloc->number, data); /* Block length. */ if (unlikely ((Dwarf_Word) (end_data - data) < newloc->number)) goto invalid; - newloc->number2 = data - block->data; /* Relative block offset. */ data += newloc->number; /* Skip the block. */ break; @@ -437,17 +439,20 @@ __libdw_intern_expression (Dwarf *dbg, bool other_byte_order, break; case DW_OP_GNU_const_type: - /* XXX Check size. */ - get_uleb128 (newloc->number, data); - if (unlikely (data >= end_data)) - goto invalid; - newloc->number2 = *data++; /* Block length. */ - if (unlikely ((Dwarf_Word) (end_data - data) < newloc->number2)) - goto invalid; - /* The third operand is relative block offset: - newloc->number3 = data - block->data; - We don't support this at this point. */ - data += newloc->number2; /* Skip the block. */ + { + size_t size; + + /* XXX Check size. */ + get_uleb128 (newloc->number, data); + if (unlikely (data >= end_data)) + goto invalid; + + newloc->number2 = (Dwarf_Word) data; /* start of block inc. len. */ + size = *data++; + if (unlikely ((Dwarf_Word) (end_data - data) < size)) + goto invalid; + data += size; /* Skip the block. */ + } break; default: @@ -505,7 +510,7 @@ __libdw_intern_expression (Dwarf *dbg, bool other_byte_order, result[n].offset = loclist->offset; if (result[n].atom == DW_OP_implicit_value) - store_implicit_value (dbg, cache, &result[n], block->data); + store_implicit_value (dbg, cache, &result[n]); loclist = loclist->next; } |