[Lldb-commits] [lldb] r370027 - DWARFExpression: Simplify class interface
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 27 00:49:41 PDT 2019
Author: labath
Date: Tue Aug 27 00:49:41 2019
New Revision: 370027
URL: http://llvm.org/viewvc/llvm-project?rev=370027&view=rev
Log:
DWARFExpression: Simplify class interface
Summary:
The DWARFExpression methods have a lot of arguments. This removes two of
them by removing the ability to slice the expression via two offset+size
parameters. This is a functionality that it is not always needed, and
when it is, we already have a different handy way of slicing a data
extractor which we can use instead.
Reviewers: JDevlieghere, clayborg
Subscribers: aprantl, lldb-commits
Differential Revision: https://reviews.llvm.org/D66745
Modified:
lldb/trunk/include/lldb/Expression/DWARFExpression.h
lldb/trunk/source/Expression/DWARFExpression.cpp
lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp
lldb/trunk/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp
lldb/trunk/source/Target/RegisterContext.cpp
lldb/trunk/unittests/Expression/DWARFExpressionTest.cpp
Modified: lldb/trunk/include/lldb/Expression/DWARFExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/DWARFExpression.h?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/DWARFExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/DWARFExpression.h Tue Aug 27 00:49:41 2019
@@ -50,15 +50,8 @@ public:
/// \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 @@ public:
/// 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 @@ public:
/// 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,
Modified: lldb/trunk/source/Expression/DWARFExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/DWARFExpression.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Expression/DWARFExpression.cpp (original)
+++ lldb/trunk/source/Expression/DWARFExpression.cpp Tue Aug 27 00:49:41 2019
@@ -59,12 +59,9 @@ DWARFExpression::DWARFExpression()
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 @@ bool DWARFExpression::Evaluate(Execution
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 @@ bool DWARFExpression::Evaluate(Execution
}
// 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 @@ bool DWARFExpression::Evaluate(
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 @@ bool DWARFExpression::Evaluate(
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 @@ bool DWARFExpression::Evaluate(
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 @@ bool DWARFExpression::Evaluate(
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)
Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Tue Aug 27 00:49:41 2019
@@ -1483,8 +1483,7 @@ RegisterContextLLDB::SavedLocationForReg
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 @@ bool RegisterContextLLDB::ReadFrameAddre
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;
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Tue Aug 27 00:49:41 2019
@@ -2532,9 +2532,11 @@ bool DWARFASTParserClang::ParseChildMemb
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 @@ bool DWARFASTParserClang::ParseChildMemb
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();
}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Tue Aug 27 00:49:41 2019
@@ -340,8 +340,8 @@ bool DWARFDebugInfoEntry::GetDIENamesAnd
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 @@ bool DWARFDebugInfoEntry::GetDIENamesAnd
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 -
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Aug 27 00:49:41 2019
@@ -3243,15 +3243,18 @@ VariableSP SymbolFileDWARF::ParseVariabl
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 @@ VariableSP SymbolFileDWARF::ParseVariabl
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 @@ VariableSP SymbolFileDWARF::ParseVariabl
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 @@ VariableSP SymbolFileDWARF::ParseVariabl
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 -
Modified: lldb/trunk/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp Tue Aug 27 00:49:41 2019
@@ -122,7 +122,7 @@ static DWARFExpression MakeLocationExpre
DataBufferSP buffer =
std::make_shared<DataBufferHeap>(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 @@ DWARFExpression lldb_private::npdb::Make
.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;
}
Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp Tue Aug 27 00:49:41 2019
@@ -174,7 +174,7 @@ DWARFExpression ConvertPDBLocationToDWAR
DataBufferSP buffer =
std::make_shared<DataBufferHeap>(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;
Modified: lldb/trunk/source/Target/RegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/RegisterContext.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/source/Target/RegisterContext.cpp (original)
+++ lldb/trunk/source/Target/RegisterContext.cpp Tue Aug 27 00:49:41 2019
@@ -82,14 +82,12 @@ RegisterContext::UpdateDynamicRegisterSi
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:
Modified: lldb/trunk/unittests/Expression/DWARFExpressionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Expression/DWARFExpressionTest.cpp?rev=370027&r1=370026&r2=370027&view=diff
==============================================================================
--- lldb/trunk/unittests/Expression/DWARFExpressionTest.cpp (original)
+++ lldb/trunk/unittests/Expression/DWARFExpressionTest.cpp Tue Aug 27 00:49:41 2019
@@ -24,8 +24,8 @@ static llvm::Expected<Scalar> Evaluate(l
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();
More information about the lldb-commits
mailing list