Skip to content

Commit

Permalink
Add support for DW_OP_push_object_address in dwarf expressions
Browse files Browse the repository at this point in the history
Additionally fix the type of some dwarf expression where we had a
confusion between scalar and load address types after a dereference.

Differential revision: http://reviews.llvm.org/D17604

llvm-svn: 262014
  • Loading branch information
Tamas Berghammer committed Feb 26, 2016
1 parent 38f912e commit 5b42c7a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 22 deletions.
3 changes: 3 additions & 0 deletions lldb/include/lldb/Expression/DWARFExpression.h
Expand Up @@ -282,6 +282,7 @@ class DWARFExpression
ClangExpressionDeclMap *decl_map,
lldb::addr_t loclist_base_load_addr,
const Value* initial_value_ptr,
const Value* object_address_ptr,
Value& result,
Error *error_ptr) const;

Expand All @@ -296,6 +297,7 @@ class DWARFExpression
RegisterContext *reg_ctx,
lldb::addr_t loclist_base_load_addr,
const Value* initial_value_ptr,
const Value* object_address_ptr,
Value& result,
Error *error_ptr) const;

Expand Down Expand Up @@ -370,6 +372,7 @@ class DWARFExpression
const lldb::offset_t length,
const lldb::RegisterKind reg_set,
const Value* initial_value_ptr,
const Value* object_address_ptr,
Value& result,
Error *error_ptr);

Expand Down
10 changes: 9 additions & 1 deletion lldb/source/Core/ValueObjectVariable.cpp
Expand Up @@ -164,7 +164,15 @@ ValueObjectVariable::UpdateValue ()
loclist_base_load_addr = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (target);
}
Value old_value(m_value);
if (expr.Evaluate (&exe_ctx, NULL, NULL, NULL, loclist_base_load_addr, NULL, m_value, &m_error))
if (expr.Evaluate (&exe_ctx,
nullptr,
nullptr,
nullptr,
loclist_base_load_addr,
nullptr,
nullptr,
m_value,
&m_error))
{
m_resolved_value = m_value;
m_value.SetContext(Value::eContextTypeVariable, variable);
Expand Down
31 changes: 27 additions & 4 deletions lldb/source/Expression/DWARFExpression.cpp
Expand Up @@ -1108,12 +1108,21 @@ DWARFExpression::Evaluate
ClangExpressionDeclMap *decl_map,
lldb::addr_t loclist_base_load_addr,
const Value* initial_value_ptr,
const Value* object_address_ptr,
Value& result,
Error *error_ptr
) const
{
ExecutionContext exe_ctx (exe_scope);
return Evaluate(&exe_ctx, expr_locals, decl_map, NULL, loclist_base_load_addr, initial_value_ptr, result, error_ptr);
return Evaluate(&exe_ctx,
expr_locals,
decl_map,
nullptr,
loclist_base_load_addr,
initial_value_ptr,
object_address_ptr,
result,
error_ptr);
}

bool
Expand All @@ -1125,6 +1134,7 @@ DWARFExpression::Evaluate
RegisterContext *reg_ctx,
lldb::addr_t loclist_base_load_addr,
const Value* initial_value_ptr,
const Value* object_address_ptr,
Value& result,
Error *error_ptr
) const
Expand Down Expand Up @@ -1189,6 +1199,7 @@ DWARFExpression::Evaluate
length,
m_reg_kind,
initial_value_ptr,
object_address_ptr,
result,
error_ptr);
}
Expand All @@ -1212,6 +1223,7 @@ DWARFExpression::Evaluate
m_data.GetByteSize(),
m_reg_kind,
initial_value_ptr,
object_address_ptr,
result,
error_ptr);
}
Expand All @@ -1232,6 +1244,7 @@ DWARFExpression::Evaluate
const lldb::offset_t opcodes_length,
const lldb::RegisterKind reg_kind,
const Value* initial_value_ptr,
const Value* object_address_ptr,
Value& result,
Error *error_ptr
)
Expand Down Expand Up @@ -1367,6 +1380,7 @@ DWARFExpression::Evaluate
intptr_t ptr;
::memcpy (&ptr, src, sizeof(void *));
stack.back().GetScalar() = ptr;
stack.back().SetValueType(Value::eValueTypeScalar);
stack.back().ClearContext();
}
break;
Expand All @@ -1381,6 +1395,7 @@ DWARFExpression::Evaluate
if (pointer_value != LLDB_INVALID_ADDRESS)
{
stack.back().GetScalar() = pointer_value;
stack.back().SetValueType(Value::eValueTypeScalar);
stack.back().ClearContext();
}
else
Expand Down Expand Up @@ -1462,6 +1477,7 @@ DWARFExpression::Evaluate
default: break;
}
stack.back().GetScalar() = ptr;
stack.back().SetValueType(Value::eValueTypeScalar);
stack.back().ClearContext();
}
break;
Expand All @@ -1485,6 +1501,7 @@ DWARFExpression::Evaluate
case 8: stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); break;
default: stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
}
stack.back().SetValueType(Value::eValueTypeScalar);
stack.back().ClearContext();
}
else
Expand Down Expand Up @@ -2689,9 +2706,15 @@ DWARFExpression::Evaluate
// during user expression evaluation.
//----------------------------------------------------------------------
case DW_OP_push_object_address:
if (error_ptr)
error_ptr->SetErrorString ("Unimplemented opcode DW_OP_push_object_address.");
return false;
if (object_address_ptr)
stack.push_back(*object_address_ptr);
else
{
if (error_ptr)
error_ptr->SetErrorString ("DW_OP_push_object_address used without specifying an object address");
return false;
}
break;

//----------------------------------------------------------------------
// OPCODE: DW_OP_call2
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
Expand Up @@ -1536,7 +1536,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
dwarfexpr.SetRegisterKind (unwindplan_registerkind);
Value result;
Error error;
if (dwarfexpr.Evaluate (&exe_ctx, NULL, NULL, this, 0, NULL, result, &error))
if (dwarfexpr.Evaluate (&exe_ctx, nullptr, nullptr, this, 0, nullptr, nullptr, result, &error))
{
addr_t val;
val = result.GetScalar().ULongLong();
Expand Down Expand Up @@ -1836,7 +1836,7 @@ RegisterContextLLDB::ReadCFAValueForRow (lldb::RegisterKind row_register_kind,
dwarfexpr.SetRegisterKind (row_register_kind);
Value result;
Error error;
if (dwarfexpr.Evaluate (&exe_ctx, NULL, NULL, this, 0, NULL, result, &error))
if (dwarfexpr.Evaluate (&exe_ctx, nullptr, nullptr, this, 0, nullptr, nullptr, result, &error))
{
cfa_value = result.GetScalar().ULongLong();

Expand Down
22 changes: 12 additions & 10 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Expand Up @@ -2703,19 +2703,20 @@ DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc,
const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data();
uint32_t block_length = form_value.Unsigned();
uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
NULL, // ClangExpressionVariableList *
NULL, // ClangExpressionDeclMap *
NULL, // RegisterContext *
if (DWARFExpression::Evaluate(nullptr, // ExecutionContext *
nullptr, // ClangExpressionVariableList *
nullptr, // ClangExpressionDeclMap *
nullptr, // RegisterContext *
module_sp,
debug_info_data,
die.GetCU(),
block_offset,
block_length,
eRegisterKindDWARF,
&initialValue,
nullptr,
memberOffset,
NULL))
nullptr))
{
member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
}
Expand Down Expand Up @@ -3129,19 +3130,20 @@ DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc,
const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data();
uint32_t block_length = form_value.Unsigned();
uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
if (DWARFExpression::Evaluate (NULL,
NULL,
NULL,
NULL,
if (DWARFExpression::Evaluate (nullptr,
nullptr,
nullptr,
nullptr,
module_sp,
debug_info_data,
die.GetCU(),
block_offset,
block_length,
eRegisterKindDWARF,
&initialValue,
nullptr,
memberOffset,
NULL))
nullptr))
{
member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
Expand Up @@ -715,7 +715,7 @@ DWARFASTParserGo::ParseChildMembers(const SymbolContext &sc, const DWARFDIE &par
NULL, // RegisterContext *
module_sp, debug_info_data, die.GetCU(),
block_offset, block_length, eRegisterKindDWARF,
&initialValue, memberOffset, NULL))
&initialValue, NULL, memberOffset, NULL))
{
member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
}
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Expand Up @@ -1063,7 +1063,6 @@ SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpec
if (cu_die)
{
const char * cu_comp_dir = resolveCompDir(cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr));

const dw_offset_t stmt_list = cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET);
if (stmt_list != DW_INVALID_OFFSET)
{
Expand Down Expand Up @@ -1832,7 +1831,7 @@ SymbolFileDWARF::GetGlobalAranges()
const DWARFExpression &location = var_sp->LocationExpression();
Value location_result;
Error error;
if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
if (location.Evaluate(nullptr, nullptr, nullptr, LLDB_INVALID_ADDRESS, nullptr, nullptr, location_result, &error))
{
if (location_result.GetValueType() == Value::eValueTypeFileAddress)
{
Expand Down
11 changes: 9 additions & 2 deletions lldb/source/Target/StackFrame.cpp
Expand Up @@ -1221,8 +1221,15 @@ StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
if (m_sc.function->GetFrameBaseExpression().IsLocationList())
loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());

if (!m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, nullptr, nullptr, nullptr, loclist_base_addr,
nullptr, expr_value, &m_frame_base_error))
if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx,
nullptr,
nullptr,
nullptr,
loclist_base_addr,
nullptr,
nullptr,
expr_value,
&m_frame_base_error) == false)
{
// We should really have an error if evaluate returns, but in case
// we don't, lets set the error to something at least.
Expand Down

0 comments on commit 5b42c7a

Please sign in to comment.