Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for DW_OP_WASM_location #500

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions elftools/dwarf/dwarf_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from io import BytesIO

from ..common.utils import struct_parse, bytelist2string, read_blob
from ..common.exceptions import DWARFError


# DWARF expression opcodes. name -> opcode mapping
Expand Down Expand Up @@ -84,6 +85,7 @@
DW_OP_reinterpret=0xa9,
DW_OP_lo_user=0xe0,
DW_OP_GNU_push_tls_address=0xe0,
DW_OP_WASM_location=0xed,
DW_OP_GNU_implicit_pointer=0xf2,
DW_OP_GNU_entry_value=0xf3,
DW_OP_GNU_const_type=0xf4,
Expand Down Expand Up @@ -196,6 +198,19 @@ def parse_blob():
# ULEB128 with datatype DIE offset, then byte, then a blob of that size
def parse_typedblob():
return lambda stream: [struct_parse(structs.Dwarf_uleb128(''), stream), read_blob(stream, struct_parse(structs.Dwarf_uint8(''), stream))]

# https://yurydelendik.github.io/webassembly-dwarf/
# Byte, then variant: 0, 1, 2 => uleb128, 3 => uint32
def parse_wasmloc():
def parse(stream):
op = struct_parse(structs.Dwarf_uint8(''), stream)
if 0 <= op <= 2:
return [op, struct_parse(structs.Dwarf_uleb128(''), stream)]
elif op == 3:
return [op, struct_parse(structs.Dwarf_uint32(''), stream)]
else:
raise DWARFError("Unknown operation code in DW_OP_WASM_location: %d" % (op,))
return parse

add('DW_OP_addr', parse_op_addr())
add('DW_OP_addrx', parse_arg_struct(structs.Dwarf_uleb128('')))
Expand Down Expand Up @@ -263,5 +278,6 @@ def parse_typedblob():
structs.Dwarf_sleb128('')))
add('DW_OP_GNU_parameter_ref', parse_arg_struct(structs.Dwarf_offset('')))
add('DW_OP_GNU_convert', parse_arg_struct(structs.Dwarf_uleb128('')))
add('DW_OP_WASM_location', parse_wasmloc())

return table