summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2019-09-10 16:17:38 +0000
committerAdrian Prantl <aprantl@apple.com>2019-09-10 16:17:38 +0000
commit9b23df63ecd9f23bb8877783d30d1a49e895cf7c (patch)
treee1e9e41f9c70fd6c5ba7c34eb00757305d84649d /lldb/source
parent6b877f6aac3d8e569e74953f0310323c2882619c (diff)
downloadbcm5719-llvm-9b23df63ecd9f23bb8877783d30d1a49e895cf7c.tar.gz
bcm5719-llvm-9b23df63ecd9f23bb8877783d30d1a49e895cf7c.zip
Implement DW_OP_convert
This patch adds basic support for DW_OP_convert[1] for integer types. Recent versions of LLVM's optimizer may insert this opcode into DWARF expressions. DW_OP_convert is effectively a type cast operation that takes a reference to a base type DIE (or zero) and then casts the value at the top of the DWARF stack to that type. Internally this works by changing the bit size of the APInt that is used as backing storage for LLDB's DWARF stack. I managed to write a unit test for this by implementing a mock YAML object file / module that takes debug info sections in yaml2obj format. [1] Typed DWARF stack. http://www.dwarfstd.org/ShowIssue.php?issue=140425.1 <rdar://problem/48167864> Differential Revision: https://reviews.llvm.org/D67369 llvm-svn: 371532
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Core/Section.cpp4
-rw-r--r--lldb/source/Expression/DWARFExpression.cpp77
-rw-r--r--lldb/source/Utility/Scalar.cpp45
3 files changed, 122 insertions, 4 deletions
diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp
index de017ed3783..7615dc1d65c 100644
--- a/lldb/source/Core/Section.cpp
+++ b/lldb/source/Core/Section.cpp
@@ -417,10 +417,6 @@ lldb::offset_t Section::GetSectionData(DataExtractor &section_data) {
#pragma mark SectionList
-SectionList::SectionList() : m_sections() {}
-
-SectionList::~SectionList() {}
-
SectionList &SectionList::operator=(const SectionList &rhs) {
if (this != &rhs)
m_sections = rhs.m_sections;
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index 44aacfde43c..c11800dc4a0 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -2559,6 +2559,83 @@ bool DWARFExpression::Evaluate(
stack.back().SetValueType(Value::eValueTypeScalar);
break;
+ // OPCODE: DW_OP_convert
+ // OPERANDS: 1
+ // A ULEB128 that is either a DIE offset of a
+ // DW_TAG_base_type or 0 for the generic (pointer-sized) type.
+ //
+ // DESCRIPTION: Pop the top stack element, convert it to a
+ // different type, and push the result.
+ case DW_OP_convert: {
+ if (stack.size() < 1) {
+ if (error_ptr)
+ error_ptr->SetErrorString(
+ "Expression stack needs at least 1 item for DW_OP_convert.");
+ return false;
+ }
+ const uint64_t die_offset = opcodes.GetULEB128(&offset);
+ Scalar::Type type = Scalar::e_void;
+ uint64_t bit_size;
+ if (die_offset == 0) {
+ // The generic type has the size of an address on the target
+ // machine and an unspecified signedness. Scalar has no
+ // "unspecified signedness", so we use unsigned types.
+ if (!module_sp) {
+ if (error_ptr)
+ error_ptr->SetErrorString("No module");
+ return false;
+ }
+ bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
+ if (!bit_size) {
+ if (error_ptr)
+ error_ptr->SetErrorString("unspecified architecture");
+ return false;
+ }
+ type = Scalar::GetBestTypeForBitSize(bit_size, false);
+ } else {
+ // Retrieve the type DIE that the value is being converted to.
+ // FIXME: the constness has annoying ripple effects.
+ DWARFDIE die = const_cast<DWARFUnit *>(dwarf_cu)->GetDIE(die_offset);
+ if (!die) {
+ if (error_ptr)
+ error_ptr->SetErrorString("Cannot resolve DW_OP_convert type DIE");
+ return false;
+ }
+ uint64_t encoding =
+ die.GetAttributeValueAsUnsigned(DW_AT_encoding, DW_ATE_hi_user);
+ bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
+ if (!bit_size)
+ bit_size = die.GetAttributeValueAsUnsigned(DW_AT_bit_size, 0);
+ if (!bit_size) {
+ if (error_ptr)
+ error_ptr->SetErrorString("Unsupported type size in DW_OP_convert");
+ return false;
+ }
+ switch (encoding) {
+ case DW_ATE_signed:
+ case DW_ATE_signed_char:
+ type = Scalar::GetBestTypeForBitSize(bit_size, true);
+ break;
+ case DW_ATE_unsigned:
+ case DW_ATE_unsigned_char:
+ type = Scalar::GetBestTypeForBitSize(bit_size, false);
+ break;
+ default:
+ if (error_ptr)
+ error_ptr->SetErrorString("Unsupported encoding in DW_OP_convert");
+ return false;
+ }
+ }
+ if (type == Scalar::e_void) {
+ if (error_ptr)
+ error_ptr->SetErrorString("Unsupported pointer size");
+ return false;
+ }
+ Scalar &top = stack.back().ResolveValue(exe_ctx);
+ top.TruncOrExtendTo(type, bit_size);
+ break;
+ }
+
// OPCODE: DW_OP_call_frame_cfa
// OPERANDS: None
// DESCRIPTION: Specifies a DWARF expression that pushes the value of
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 23d50b9eaba..3393af921dd 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -416,6 +416,51 @@ Scalar &Scalar::operator=(llvm::APInt rhs) {
Scalar::~Scalar() = default;
+Scalar::Type Scalar::GetBestTypeForBitSize(size_t bit_size, bool sign) {
+ // Scalar types are always host types, hence the sizeof().
+ if (sign) {
+ if (bit_size <= sizeof(int)*8) return Scalar::e_sint;
+ if (bit_size <= sizeof(long)*8) return Scalar::e_slong;
+ if (bit_size <= sizeof(long long)*8) return Scalar::e_slonglong;
+ if (bit_size <= 128) return Scalar::e_sint128;
+ if (bit_size <= 256) return Scalar::e_sint256;
+ if (bit_size <= 512) return Scalar::e_sint512;
+ } else {
+ if (bit_size <= sizeof(unsigned int)*8) return Scalar::e_uint;
+ if (bit_size <= sizeof(unsigned long)*8) return Scalar::e_ulong;
+ if (bit_size <= sizeof(unsigned long long)*8) return Scalar::e_ulonglong;
+ if (bit_size <= 128) return Scalar::e_uint128;
+ if (bit_size <= 256) return Scalar::e_uint256;
+ if (bit_size <= 512) return Scalar::e_uint512;
+ }
+ return Scalar::e_void;
+};
+
+void Scalar::TruncOrExtendTo(Scalar::Type type, uint16_t bits) {
+ switch (type) {
+ case e_sint:
+ case e_slong:
+ case e_slonglong:
+ case e_sint128:
+ case e_sint256:
+ case e_sint512:
+ m_integer = m_integer.sextOrTrunc(bits);
+ break;
+ case e_uint:
+ case e_ulong:
+ case e_ulonglong:
+ case e_uint128:
+ case e_uint256:
+ case e_uint512:
+ m_integer = m_integer.zextOrTrunc(bits);
+ break;
+ default:
+ llvm_unreachable("Promoting a Scalar to a specific number of bits is only "
+ "supported for integer types.");
+ }
+ m_type = type;
+}
+
bool Scalar::Promote(Scalar::Type type) {
bool success = false;
switch (m_type) {
OpenPOWER on IntegriCloud