diff --git a/lldb/include/lldb/Expression/DWARFExpression.h b/lldb/include/lldb/Expression/DWARFExpression.h --- a/lldb/include/lldb/Expression/DWARFExpression.h +++ b/lldb/include/lldb/Expression/DWARFExpression.h @@ -50,15 +50,8 @@ /// \param[in] data /// A data extractor configured to read the DWARF location expression's /// bytecode. - /// - /// \param[in] data_offset - /// The offset of the location expression in the extractor. - /// - /// \param[in] data_length - /// The byte length of the location expression. DWARFExpression(lldb::ModuleSP module, const DataExtractor &data, - const DWARFUnit *dwarf_cu, lldb::offset_t data_offset, - lldb::offset_t data_length); + const DWARFUnit *dwarf_cu); /// Destructor virtual ~DWARFExpression(); @@ -211,12 +204,6 @@ /// in the case where an expression needs to be evaluated while building /// the stack frame list, this short-cut is available. /// - /// \param[in] offset - /// The offset of the location expression in the data extractor. - /// - /// \param[in] length - /// The length in bytes of the location expression. - /// /// \param[in] reg_set /// The call-frame-info style register kind. /// @@ -236,8 +223,7 @@ /// details of the failure are provided through it. static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP opcode_ctx, const DataExtractor &opcodes, - const DWARFUnit *dwarf_cu, const lldb::offset_t offset, - const lldb::offset_t length, + const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -59,12 +59,9 @@ DWARFExpression::DWARFExpression(lldb::ModuleSP module_sp, const DataExtractor &data, - const DWARFUnit *dwarf_cu, - lldb::offset_t data_offset, - lldb::offset_t data_length) - : m_module_wp(), m_data(data, data_offset, data_length), - m_dwarf_cu(dwarf_cu), m_reg_kind(eRegisterKindDWARF), - m_loclist_slide(LLDB_INVALID_ADDRESS) { + const DWARFUnit *dwarf_cu) + : m_module_wp(), m_data(data), m_dwarf_cu(dwarf_cu), + m_reg_kind(eRegisterKindDWARF), m_loclist_slide(LLDB_INVALID_ADDRESS) { if (module_sp) m_module_wp = module_sp; } @@ -1135,9 +1132,9 @@ if (length > 0 && lo_pc <= pc && pc < hi_pc) { return DWARFExpression::Evaluate( - exe_ctx, reg_ctx, module_sp, m_data, m_dwarf_cu, offset, length, - m_reg_kind, initial_value_ptr, object_address_ptr, result, - error_ptr); + exe_ctx, reg_ctx, module_sp, + DataExtractor(m_data, offset, length), m_dwarf_cu, m_reg_kind, + initial_value_ptr, object_address_ptr, result, error_ptr); } offset += length; } @@ -1148,20 +1145,19 @@ } // Not a location list, just a single expression. - return DWARFExpression::Evaluate( - exe_ctx, reg_ctx, module_sp, m_data, m_dwarf_cu, 0, m_data.GetByteSize(), - m_reg_kind, initial_value_ptr, object_address_ptr, result, error_ptr); + return DWARFExpression::Evaluate(exe_ctx, reg_ctx, module_sp, m_data, + m_dwarf_cu, m_reg_kind, initial_value_ptr, + object_address_ptr, result, error_ptr); } bool DWARFExpression::Evaluate( ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, - const DWARFUnit *dwarf_cu, const lldb::offset_t opcodes_offset, - const lldb::offset_t opcodes_length, const lldb::RegisterKind reg_kind, + const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_kind, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) { - if (opcodes_length == 0) { + if (opcodes.GetByteSize() == 0) { if (error_ptr) error_ptr->SetErrorString( "no location, value may have been optimized out"); @@ -1182,8 +1178,7 @@ if (initial_value_ptr) stack.push_back(*initial_value_ptr); - lldb::offset_t offset = opcodes_offset; - const lldb::offset_t end_offset = opcodes_offset + opcodes_length; + lldb::offset_t offset = 0; Value tmp; uint32_t reg_num; @@ -1191,16 +1186,9 @@ uint64_t op_piece_offset = 0; Value pieces; // Used for DW_OP_piece - // Make sure all of the data is available in opcodes. - if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length)) { - if (error_ptr) - error_ptr->SetErrorString( - "invalid offset and/or length for opcodes buffer."); - return false; - } Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - while (opcodes.ValidOffset(offset) && offset < end_offset) { + while (opcodes.ValidOffset(offset)) { const lldb::offset_t op_offset = offset; const uint8_t op = opcodes.GetU8(&offset); @@ -1946,7 +1934,7 @@ case DW_OP_skip: { int16_t skip_offset = (int16_t)opcodes.GetU16(&offset); lldb::offset_t new_offset = offset + skip_offset; - if (new_offset >= opcodes_offset && new_offset < end_offset) + if (opcodes.ValidOffset(new_offset)) offset = new_offset; else { if (error_ptr) @@ -1975,7 +1963,7 @@ Scalar zero(0); if (tmp.ResolveValue(exe_ctx) != zero) { lldb::offset_t new_offset = offset + bra_offset; - if (new_offset >= opcodes_offset && new_offset < end_offset) + if (opcodes.ValidOffset(new_offset)) offset = new_offset; else { if (error_ptr) diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp --- a/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp @@ -1483,8 +1483,7 @@ process->GetByteOrder(), process->GetAddressByteSize()); ModuleSP opcode_ctx; - DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr, 0, - unwindplan_regloc.GetDWARFExpressionLength()); + DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr); dwarfexpr.SetRegisterKind(unwindplan_registerkind); Value cfa_val = Scalar(m_cfa); cfa_val.SetValueType(Value::eValueTypeLoadAddress); @@ -1837,8 +1836,7 @@ process->GetByteOrder(), process->GetAddressByteSize()); ModuleSP opcode_ctx; - DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr, 0, - fa.GetDWARFExpressionLength()); + DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr); dwarfexpr.SetRegisterKind(row_register_kind); Value result; Status error; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -2532,9 +2532,11 @@ if (DWARFExpression::Evaluate( nullptr, // ExecutionContext * nullptr, // RegisterContext * - module_sp, debug_info_data, die.GetCU(), block_offset, - block_length, eRegisterKindDWARF, &initialValue, - nullptr, memberOffset, nullptr)) { + module_sp, + DataExtractor(debug_info_data, block_offset, + block_length), + die.GetCU(), eRegisterKindDWARF, &initialValue, nullptr, + memberOffset, nullptr)) { member_byte_offset = memberOffset.ResolveValue(nullptr).UInt(); } @@ -2967,11 +2969,12 @@ uint32_t block_length = form_value.Unsigned(); uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); - if (DWARFExpression::Evaluate(nullptr, nullptr, module_sp, - debug_info_data, die.GetCU(), - block_offset, block_length, - eRegisterKindDWARF, &initialValue, - nullptr, memberOffset, nullptr)) { + if (DWARFExpression::Evaluate( + nullptr, nullptr, module_sp, + DataExtractor(debug_info_data, block_offset, + block_length), + die.GetCU(), eRegisterKindDWARF, &initialValue, nullptr, + memberOffset, nullptr)) { member_byte_offset = memberOffset.ResolveValue(nullptr).UInt(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -340,8 +340,8 @@ uint32_t block_offset = form_value.BlockData() - data.GetDataStart(); uint32_t block_length = form_value.Unsigned(); - *frame_base = DWARFExpression(module, data, cu, - block_offset, block_length); + *frame_base = DWARFExpression( + module, DataExtractor(data, block_offset, block_length), cu); } else { const DWARFDataExtractor &debug_loc_data = dwarf.DebugLocData(); const dw_offset_t debug_loc_offset = form_value.Unsigned(); @@ -349,9 +349,11 @@ size_t loc_list_length = DWARFExpression::LocationListSize( cu, debug_loc_data, debug_loc_offset); if (loc_list_length > 0) { - *frame_base = - DWARFExpression(module, debug_loc_data, cu, - debug_loc_offset, loc_list_length); + *frame_base = DWARFExpression(module, + DataExtractor(debug_loc_data, + debug_loc_offset, + loc_list_length), + cu); if (lo_pc != LLDB_INVALID_ADDRESS) { assert(lo_pc >= cu->GetBaseAddress()); frame_base->SetLocationListSlide(lo_pc - diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3243,15 +3243,18 @@ uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); uint32_t block_length = form_value.Unsigned(); - location = DWARFExpression(module, debug_info_data, die.GetCU(), - block_offset, block_length); + location = DWARFExpression( + module, + DataExtractor(debug_info_data, block_offset, block_length), + die.GetCU()); } else if (DWARFFormValue::IsDataForm(form_value.Form())) { // Retrieve the value as a data expression. uint32_t data_offset = attributes.DIEOffsetAtIndex(i); if (auto data_length = form_value.GetFixedSize()) - location = - DWARFExpression(module, debug_info_data, die.GetCU(), - data_offset, *data_length); + location = DWARFExpression( + module, + DataExtractor(debug_info_data, data_offset, *data_length), + die.GetCU()); else { const uint8_t *data_pointer = form_value.BlockData(); if (data_pointer) { @@ -3267,17 +3270,21 @@ if (form_value.Form() == DW_FORM_strp) { uint32_t data_offset = attributes.DIEOffsetAtIndex(i); if (auto data_length = form_value.GetFixedSize()) - location = - DWARFExpression(module, debug_info_data, die.GetCU(), - data_offset, *data_length); + location = DWARFExpression(module, + DataExtractor(debug_info_data, + data_offset, + *data_length), + die.GetCU()); } else { const char *str = form_value.AsCString(); uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); uint32_t string_length = strlen(str) + 1; - location = - DWARFExpression(module, debug_info_data, die.GetCU(), - string_offset, string_length); + location = DWARFExpression(module, + DataExtractor(debug_info_data, + string_offset, + string_length), + die.GetCU()); } } } @@ -3291,8 +3298,9 @@ uint32_t block_offset = form_value.BlockData() - data.GetDataStart(); uint32_t block_length = form_value.Unsigned(); - location = DWARFExpression(module, data, die.GetCU(), - block_offset, block_length); + location = DWARFExpression( + module, DataExtractor(data, block_offset, block_length), + die.GetCU()); } else { const DWARFDataExtractor &debug_loc_data = DebugLocData(); const dw_offset_t debug_loc_offset = form_value.Unsigned(); @@ -3300,8 +3308,11 @@ size_t loc_list_length = DWARFExpression::LocationListSize( die.GetCU(), debug_loc_data, debug_loc_offset); if (loc_list_length > 0) { - location = DWARFExpression(module, debug_loc_data, die.GetCU(), - debug_loc_offset, loc_list_length); + location = DWARFExpression(module, + DataExtractor(debug_loc_data, + debug_loc_offset, + loc_list_length), + die.GetCU()); assert(func_low_pc != LLDB_INVALID_ADDRESS); location.SetLocationListSlide( func_low_pc - diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp @@ -122,7 +122,7 @@ DataBufferSP buffer = std::make_shared(stream.GetData(), stream.GetSize()); DataExtractor extractor(buffer, byte_order, address_size, byte_size); - DWARFExpression result(module, extractor, nullptr, 0, buffer->GetByteSize()); + DWARFExpression result(module, extractor, nullptr); result.SetRegisterKind(register_kind); return result; @@ -247,6 +247,6 @@ .take_front(size); buffer->CopyData(bytes.data(), size); DataExtractor extractor(buffer, lldb::eByteOrderLittle, address_size); - DWARFExpression result(nullptr, extractor, nullptr, 0, size); + DWARFExpression result(nullptr, extractor, nullptr); return result; } diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp --- a/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp @@ -174,7 +174,7 @@ DataBufferSP buffer = std::make_shared(stream.GetData(), stream.GetSize()); DataExtractor extractor(buffer, byte_order, address_size, byte_size); - DWARFExpression result(module, extractor, nullptr, 0, buffer->GetByteSize()); + DWARFExpression result(module, extractor, nullptr); result.SetRegisterKind(register_kind); return result; diff --git a/lldb/source/Target/RegisterContext.cpp b/lldb/source/Target/RegisterContext.cpp --- a/lldb/source/Target/RegisterContext.cpp +++ b/lldb/source/Target/RegisterContext.cpp @@ -82,14 +82,12 @@ DataExtractor dwarf_data(dwarf_opcode_ptr, dwarf_opcode_len, arch.GetByteOrder(), addr_size); ModuleSP opcode_ctx; - DWARFExpression dwarf_expr(opcode_ctx, dwarf_data, nullptr, 0, - dwarf_opcode_len); + DWARFExpression dwarf_expr(opcode_ctx, dwarf_data, nullptr); Value result; Status error; - const lldb::offset_t offset = 0; if (dwarf_expr.Evaluate(&exe_ctx, this, opcode_ctx, dwarf_data, nullptr, - offset, dwarf_opcode_len, eRegisterKindDWARF, nullptr, - nullptr, result, &error)) { + eRegisterKindDWARF, nullptr, nullptr, result, + &error)) { expr_result = result.GetScalar().SInt(-1); switch (expr_result) { case 0: diff --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp b/lldb/unittests/Expression/DWARFExpressionTest.cpp --- a/lldb/unittests/Expression/DWARFExpressionTest.cpp +++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp @@ -24,8 +24,8 @@ Status status; if (!DWARFExpression::Evaluate( /*exe_ctx*/ nullptr, /*reg_ctx*/ nullptr, /*opcode_ctx*/ nullptr, - extractor, /*dwarf_cu*/ nullptr, /*offset*/ 0, expr.size(), - lldb::eRegisterKindLLDB, /*initial_value_ptr*/ nullptr, + extractor, /*dwarf_cu*/ nullptr, lldb::eRegisterKindLLDB, + /*initial_value_ptr*/ nullptr, /*object_address_ptr*/ nullptr, result, &status)) return status.ToError();