-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLDB] Re-land 'Update DIL handling of array subscripting' #154269
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
Merged
+178
−34
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,40 +330,135 @@ Interpreter::Visit(const ArraySubscriptNode *node) { | |
| 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( | ||
| 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->GetCompilerType().IsPointerType()) | ||
| is_objc_pointer = false; | ||
|
|
||
| if (!m_use_synthetic && is_objc_pointer) { | ||
| std::string err_msg = | ||
| llvm::formatv("\"(%s) %s\" is an Objective-C pointer, and cannot be " | ||
| "subscripted", | ||
| base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation()); | ||
| } else if (is_objc_pointer) { | ||
|
||
| lldb::ValueObjectSP synthetic = base->GetSyntheticValue(); | ||
| if (!synthetic || synthetic == base) { | ||
| std::string err_msg = | ||
| llvm::formatv("\"(%s) %s\" is not an array type", | ||
| base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation()); | ||
| } else if (static_cast<uint32_t>(child_idx) >= | ||
| synthetic->GetNumChildrenIgnoringErrors()) { | ||
| std::string err_msg = llvm::formatv( | ||
| "array index %ld is not valid for \"(%s) %s\"", child_idx, | ||
| base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation()); | ||
| } else { | ||
| child_valobj_sp = synthetic->GetChildAtIndex(child_idx); | ||
| if (!child_valobj_sp) { | ||
| std::string err_msg = llvm::formatv( | ||
| "array index %ld is not valid for \"(%s) %s\"", child_idx, | ||
| base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>( | ||
| m_expr, std::move(err_msg), node->GetLocation()); | ||
| } | ||
| if (m_use_dynamic != lldb::eNoDynamicValues) { | ||
| if (auto dynamic_sp = child_valobj_sp->GetDynamicValue(m_use_dynamic)) | ||
| child_valobj_sp = std::move(dynamic_sp); | ||
| } | ||
| return child_valobj_sp; | ||
| } | ||
| } | ||
|
|
||
| child_valobj_sp = base->GetSyntheticArrayMember(child_idx, true); | ||
| if (!child_valobj_sp) { | ||
| std::string err_msg = llvm::formatv( | ||
| "failed to use pointer as array for index {0} for " | ||
| "\"({1}) {2}\"", | ||
| child_idx, base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| if (base_type.IsPointerToVoid()) | ||
| err_msg = "subscript of pointer to incomplete type 'void'"; | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation()); | ||
| } | ||
| } else if (base_type.IsArrayType(nullptr, nullptr, &is_incomplete_array)) { | ||
| child_valobj_sp = base->GetChildAtIndex(child_idx); | ||
| if (!child_valobj_sp && (is_incomplete_array || m_use_synthetic)) | ||
| child_valobj_sp = base->GetSyntheticArrayMember(child_idx, true); | ||
| if (!child_valobj_sp) { | ||
| std::string err_msg = 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, | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation()); | ||
| } | ||
| if (lldb::ValueObjectSP child_valobj_sp = | ||
| synthetic->GetChildAtIndex(child_idx)) | ||
| return child_valobj_sp; | ||
| } else if (base_type.IsScalarType()) { | ||
| child_valobj_sp = | ||
| base->GetSyntheticBitFieldChild(child_idx, child_idx, true); | ||
| if (!child_valobj_sp) { | ||
| std::string err_msg = llvm::formatv( | ||
| "bitfield range {0}-{1} is not valid for \"({2}) {3}\"", child_idx, | ||
| child_idx, base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation(), 1); | ||
| } | ||
| } else { | ||
| lldb::ValueObjectSP synthetic = base->GetSyntheticValue(); | ||
| if (!m_use_synthetic || !synthetic || synthetic == base) { | ||
| std::string err_msg = | ||
| llvm::formatv("\"{0}\" is not an array type", | ||
| base->GetTypeName().AsCString("<invalid type>")); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation(), 1); | ||
| } | ||
| if (static_cast<uint32_t>(child_idx) >= | ||
| synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) { | ||
| std::string err_msg = llvm::formatv( | ||
| "array index {0} is not valid for \"({1}) {2}\"", child_idx, | ||
| base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation(), 1); | ||
| } | ||
| child_valobj_sp = synthetic->GetChildAtIndex(child_idx); | ||
| if (!child_valobj_sp) { | ||
| std::string err_msg = llvm::formatv( | ||
| "array index {0} is not valid for \"({1}) {2}\"", child_idx, | ||
| base->GetTypeName().AsCString("<invalid type>"), | ||
| var_expr_path_strm.GetData()); | ||
| return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg), | ||
| node->GetLocation(), 1); | ||
| } | ||
| } | ||
|
|
||
| auto base_type = base->GetCompilerType().GetNonReferenceType(); | ||
| if (!base_type.IsPointerType() && !base_type.IsArrayType()) | ||
| return llvm::make_error<DILDiagnosticError>( | ||
| m_expr, "subscripted value is not an array or pointer", | ||
| node->GetLocation()); | ||
| if (base_type.IsPointerToVoid()) | ||
| return llvm::make_error<DILDiagnosticError>( | ||
| m_expr, "subscript of pointer to incomplete type 'void'", | ||
| node->GetLocation()); | ||
|
|
||
| if (base_type.IsArrayType()) { | ||
| if (lldb::ValueObjectSP child_valobj_sp = base->GetChildAtIndex(child_idx)) | ||
| return child_valobj_sp; | ||
| if (child_valobj_sp) { | ||
| if (m_use_dynamic != lldb::eNoDynamicValues) { | ||
| if (auto dynamic_sp = child_valobj_sp->GetDynamicValue(m_use_dynamic)) | ||
| child_valobj_sp = std::move(dynamic_sp); | ||
| } | ||
| return child_valobj_sp; | ||
| } | ||
|
|
||
| int64_t signed_child_idx = node->GetIndex(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/myArraySynthProvider.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import lldb | ||
|
|
||
|
|
||
| class myArraySynthProvider: | ||
| def __init__(self, valobj, dict): | ||
| self.valobj = valobj | ||
|
|
||
| def num_children(self): | ||
| size_valobj = self.valobj.GetChildMemberWithName("m_arr_size") | ||
| if size_valobj: | ||
| return size_valobj.GetValueAsUnsigned(0) | ||
| return 0 | ||
|
|
||
| def get_child_at_index(self, index): | ||
| size_valobj = self.valobj.GetChildMemberWithName("m_arr_size") | ||
| arr = self.valobj.GetChildMemberWithName("m_array") | ||
| if not size_valobj or not arr: | ||
| return None | ||
| max_idx = size_valobj.GetValueAsUnsigned(0) | ||
| if index >= max_idx: | ||
| return None | ||
| return arr.GetChildAtIndex(index) | ||
|
|
||
| def get_child_index(self, name): | ||
| if name == "[0]": | ||
| return 0 | ||
| if name == "[1]": | ||
| return | ||
| if name == "[2]": | ||
| return 2 | ||
| if name == "[3]": | ||
| return 3 | ||
| return -1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the right
formatvsyntax (throughout the function).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