-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLDB] Update DIL handling of array subscripting. #151605
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
Changes from 1 commit
0d51e89
0f706e8
a394c68
fe70937
0f8331c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -323,47 +323,144 @@ Interpreter::Visit(const MemberOfNode *node) { | |||||||||||||
| m_expr, errMsg, node->GetLocation(), node->GetFieldName().size()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| llvm::Expected<lldb::ValueObjectSP> | ||||||||||||||
| Interpreter::Visit(const ArraySubscriptNode *node) { | ||||||||||||||
| auto lhs_or_err = Evaluate(node->GetBase()); | ||||||||||||||
| if (!lhs_or_err) | ||||||||||||||
| return lhs_or_err; | ||||||||||||||
| lldb::ValueObjectSP base = *lhs_or_err; | ||||||||||||||
|
|
||||||||||||||
| // Check to see if 'base' has a synthetic value; if so, try using that. | ||||||||||||||
| StreamString var_expr_path_strm; | ||||||||||||||
| uint64_t child_idx = node->GetIndex(); | ||||||||||||||
| if (lldb::ValueObjectSP synthetic = base->GetSyntheticValue()) { | ||||||||||||||
| llvm::Expected<uint32_t> num_children = | ||||||||||||||
| synthetic->GetNumChildren(child_idx + 1); | ||||||||||||||
| if (!num_children) | ||||||||||||||
| return llvm::make_error<DILDiagnosticError>( | ||||||||||||||
| m_expr, toString(num_children.takeError()), node->GetLocation()); | ||||||||||||||
| if (child_idx >= *num_children) { | ||||||||||||||
| std::string message = llvm::formatv( | ||||||||||||||
| "array index {0} is not valid for \"({1}) {2}\"", child_idx, | ||||||||||||||
| base->GetTypeName().AsCString("<invalid type>"), | ||||||||||||||
| base->GetName().AsCString()); | ||||||||||||||
| return llvm::make_error<DILDiagnosticError>(m_expr, message, | ||||||||||||||
| lldb::ValueObjectSP child_valobj_sp; | ||||||||||||||
| bool is_incomplete_array = false; | ||||||||||||||
| CompilerType base_type = base->GetCompilerType().GetNonReferenceType(); | ||||||||||||||
| base->GetExpressionPath(var_expr_path_strm); | ||||||||||||||
| if (base_type.IsPointerType()) { | ||||||||||||||
| bool is_objc_pointer = true; | ||||||||||||||
| if (base->GetCompilerType().GetMinimumLanguage() != lldb::eLanguageTypeObjC) | ||||||||||||||
| is_objc_pointer = false; | ||||||||||||||
| else if (!base_type.IsPointerType()) | ||||||||||||||
| is_objc_pointer = false; | ||||||||||||||
|
|
||||||||||||||
| if (is_objc_pointer && !m_use_synthetic) { | ||||||||||||||
| std::string errMsg = | ||||||||||||||
| llvm::formatv("\"(({0}) {1}\" is an Objective-C pointer, and cannot " | ||||||||||||||
| "be subscripted", | ||||||||||||||
| base->GetTypeName().AsCString("<invalid type>"), | ||||||||||||||
| base->GetName()); | ||||||||||||||
| return llvm::make_error<DILDiagnosticError>(m_expr, errMsg, | ||||||||||||||
| node->GetLocation()); | ||||||||||||||
| } else if (is_objc_pointer) { | ||||||||||||||
|
||||||||||||||
| lldb::ValueObjectSP synthetic = base->GetSyntheticValue(); | ||||||||||||||
| if (!synthetic || synthetic == base) { | ||||||||||||||
| std::string errMsg = | ||||||||||||||
| llvm::formatv("\"({0}) {1}\" is not an array type", | ||||||||||||||
| base->GetTypeName().AsCString("<invalid type>"), | ||||||||||||||
| base->GetName()); | ||||||||||||||
| return llvm::make_error<DILDiagnosticError>(m_expr, errMsg, | ||||||||||||||
| node->GetLocation()); | ||||||||||||||
| } else if (static_cast<uint32_t>(child_idx) >= | ||||||||||||||
| synthetic->GetNumChildrenIgnoringErrors()) { | ||||||||||||||
|
||||||||||||||
| synthetic->GetNumChildrenIgnoringErrors()) { | |
| synthetic->GetNumChildrenIgnoringErrors(child_idx+1)) { |
.. potentially avoids materializing many children unnecessarily
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code in lines 356-383 is basically the same as in lines 426-453, could we reuse this somehow?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| lldb::ValueObjectSP dynamic_value_sp( | |
| child_valobj_sp->GetDynamicValue(m_use_dynamic)); | |
| if (dynamic_value_sp) | |
| child_valobj_sp = dynamic_value_sp; | |
| if (auto dynamic_sp = child_valobj_sp->GetDynamicValue(m_use_dynamic)) | |
| child_valobj_sp = std::move(dynamic_sp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -69,17 +69,19 @@ def test_subscript(self): | |||||
| substrs=["expected 'r_square', got: <'.'"], | ||||||
| ) | ||||||
|
|
||||||
| # Base should be a "pointer to T" and index should be of an integral type. | ||||||
| self.expect( | ||||||
| "frame var 'idx_1[0]'", | ||||||
| error=True, | ||||||
| substrs=["subscripted value is not an array or pointer"], | ||||||
| ) | ||||||
|
|
||||||
| # Test accessing bits in scalar types. | ||||||
| self.expect_var_path("idx_1[0]", value="1") | ||||||
| self.expect_var_path("idx_1[1]", value="0") | ||||||
|
|
||||||
| # Bit acess not valid for a reference. | ||||||
|
||||||
| # Bit acess not valid for a reference. | |
| # Bit access not valid for a reference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err_msg