[Lldb-commits] [lldb] [LLDB] Add array subscription and integer parsing to DIL (PR #138551)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Thu May 15 10:39:57 PDT 2025
================
@@ -272,4 +272,67 @@ Interpreter::Visit(const UnaryOpNode *node) {
m_expr, "invalid ast: unexpected binary operator", node->GetLocation());
}
+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;
+ const llvm::APInt *index = node->GetIndex();
+
+ Status error;
+ if (base->GetCompilerType().IsReferenceType()) {
+ base = base->Dereference(error);
+ if (error.Fail())
+ return error.ToError();
+ }
+
+ // Check to see if 'base' has a synthetic value; if so, try using that.
+ uint64_t child_idx = index->getZExtValue();
+ if (base->HasSyntheticValue()) {
+ lldb::ValueObjectSP synthetic = base->GetSyntheticValue();
+ if (synthetic && synthetic != base) {
+ uint32_t num_children = synthetic->GetNumChildrenIgnoringErrors();
+ // Verify that the 'index' is not out-of-range for the declared type.
+ if (child_idx >= num_children) {
+ auto 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,
+ node->GetLocation());
+ }
+
+ if (static_cast<uint32_t>(child_idx) <
+ synthetic->GetNumChildrenIgnoringErrors()) {
+ lldb::ValueObjectSP child_valobj_sp =
+ synthetic->GetChildAtIndex(child_idx);
+ if (child_valobj_sp) {
+ return child_valobj_sp;
+ }
+ }
+ }
+ }
+
+ auto base_type = base->GetCompilerType();
+ if (!base_type.IsPointerType() && !base_type.IsArrayType())
----------------
kuilpd wrote:
I tried that, but because I need to return `base->GetSyntheticArrayMember` in any case other than array, it didn't end up looking better.
https://github.com/llvm/llvm-project/pull/138551
More information about the lldb-commits
mailing list