Skip to content

[🍒 swift/release/6.1] [lldb] Add missing operations to GetOpcodeDataSize (#120163) #9873

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

Merged
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
76 changes: 63 additions & 13 deletions lldb/source/Expression/DWARFExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,35 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
/// are made on the state of \p data after this call.
static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
const lldb::offset_t data_offset,
const uint8_t op,
const LocationAtom op,
const DWARFUnit *dwarf_cu) {
lldb::offset_t offset = data_offset;
switch (op) {
// Only used in LLVM metadata.
case DW_OP_LLVM_fragment:
case DW_OP_LLVM_convert:
case DW_OP_LLVM_tag_offset:
case DW_OP_LLVM_entry_value:
case DW_OP_LLVM_implicit_pointer:
case DW_OP_LLVM_arg:
case DW_OP_LLVM_extract_bits_sext:
case DW_OP_LLVM_extract_bits_zext:
break;
// Vendor extensions:
case DW_OP_HP_is_value:
case DW_OP_HP_fltconst4:
case DW_OP_HP_fltconst8:
case DW_OP_HP_mod_range:
case DW_OP_HP_unmod_range:
case DW_OP_HP_tls:
case DW_OP_INTEL_bit_piece:
case DW_OP_WASM_location:
case DW_OP_WASM_location_int:
case DW_OP_APPLE_uninit:
case DW_OP_PGI_omp_thread_num:
case DW_OP_hi_user:
break;

case DW_OP_addr:
case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
return data.GetAddressByteSize();
Expand Down Expand Up @@ -250,6 +275,7 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
case DW_OP_pick: // 0x15 1 1-byte stack index
case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
case DW_OP_deref_type: // 0xa6 1 1-byte constant
return 1;

// Opcodes with a single 2 byte arguments
Expand All @@ -272,7 +298,6 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
return 8;

// All opcodes that have a single ULEB (signed or unsigned) argument
case DW_OP_addrx: // 0xa1 1 ULEB128 index
case DW_OP_constu: // 0x10 1 ULEB128 constant
case DW_OP_consts: // 0x11 1 SLEB128 constant
case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
Expand Down Expand Up @@ -311,14 +336,20 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
case DW_OP_regx: // 0x90 1 ULEB128 register
case DW_OP_fbreg: // 0x91 1 SLEB128 offset
case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
case DW_OP_convert: // 0xa8 1 ULEB128 offset
case DW_OP_reinterpret: // 0xa9 1 ULEB128 offset
case DW_OP_addrx: // 0xa1 1 ULEB128 index
case DW_OP_constx: // 0xa2 1 ULEB128 index
case DW_OP_xderef_type: // 0xa7 1 ULEB128 index
case DW_OP_GNU_addr_index: // 0xfb 1 ULEB128 index
case DW_OP_GNU_const_index: // 0xfc 1 ULEB128 index
data.Skip_LEB128(&offset);
return offset - data_offset;

// All opcodes that have a 2 ULEB (signed or unsigned) arguments
case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
case DW_OP_regval_type: // 0xa5 ULEB128 + ULEB128
data.Skip_LEB128(&offset);
data.Skip_LEB128(&offset);
return offset - data_offset;
Expand All @@ -331,28 +362,47 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
return offset - data_offset;
}

case DW_OP_implicit_pointer: // 0xa0 4-byte (or 8-byte for DWARF 64) constant
// + LEB128
{
data.Skip_LEB128(&offset);
return DWARFUnit::GetAddressByteSize(dwarf_cu) + offset - data_offset;
}

case DW_OP_GNU_entry_value:
case DW_OP_entry_value: // 0xa3 ULEB128 size + variable-length block
{
uint64_t subexpr_len = data.GetULEB128(&offset);
return (offset - data_offset) + subexpr_len;
}

default:
if (!dwarf_cu) {
return LLDB_INVALID_OFFSET;
}
case DW_OP_const_type: // 0xa4 ULEB128 + size + variable-length block
{
data.Skip_LEB128(&offset);
uint8_t length = data.GetU8(&offset);
return (offset - data_offset) + length;
}

case DW_OP_LLVM_user: // 0xe9: ULEB128 + variable length constant
{
uint64_t constants = data.GetULEB128(&offset);
return (offset - data_offset) + constants;
}
}

if (dwarf_cu)
return dwarf_cu->GetSymbolFileDWARF().GetVendorDWARFOpcodeSize(
data, data_offset, op);
}

return LLDB_INVALID_OFFSET;
}

lldb::addr_t DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu,
bool &error) const {
error = false;
lldb::offset_t offset = 0;
while (m_data.ValidOffset(offset)) {
const uint8_t op = m_data.GetU8(&offset);
const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));

if (op == DW_OP_addr)
return m_data.GetAddress(&offset);
Expand All @@ -378,7 +428,7 @@ bool DWARFExpression::Update_DW_OP_addr(const DWARFUnit *dwarf_cu,
lldb::addr_t file_addr) {
lldb::offset_t offset = 0;
while (m_data.ValidOffset(offset)) {
const uint8_t op = m_data.GetU8(&offset);
const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));

if (op == DW_OP_addr) {
const uint32_t addr_byte_size = m_data.GetAddressByteSize();
Expand Down Expand Up @@ -436,7 +486,7 @@ bool DWARFExpression::ContainsThreadLocalStorage(
const DWARFUnit *dwarf_cu) const {
lldb::offset_t offset = 0;
while (m_data.ValidOffset(offset)) {
const uint8_t op = m_data.GetU8(&offset);
const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));

if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
return true;
Expand Down Expand Up @@ -467,7 +517,7 @@ bool DWARFExpression::LinkThreadLocalStorage(
lldb::addr_t const_value = 0;
size_t const_byte_size = 0;
while (m_data.ValidOffset(offset)) {
const uint8_t op = m_data.GetU8(&offset);
const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));

bool decoded_data = false;
switch (op) {
Expand Down