Skip to content

Commit cd0bf27

Browse files
Revert "[LLDB] Update DIL handling of array subscripting. (#151605)"
This reverts commit 6d3ad9d. This was reverted because it broke the LLDB greendragon bot.
1 parent 853094f commit cd0bf27

File tree

4 files changed

+34
-126
lines changed

4 files changed

+34
-126
lines changed

lldb/source/ValueObject/DILEval.cpp

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -330,83 +330,40 @@ Interpreter::Visit(const ArraySubscriptNode *node) {
330330
return lhs_or_err;
331331
lldb::ValueObjectSP base = *lhs_or_err;
332332

333-
StreamString var_expr_path_strm;
333+
// Check to see if 'base' has a synthetic value; if so, try using that.
334334
uint64_t child_idx = node->GetIndex();
335-
lldb::ValueObjectSP child_valobj_sp;
336-
bool is_incomplete_array = false;
337-
CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
338-
base->GetExpressionPath(var_expr_path_strm);
339-
if (base_type.IsPointerType()) {
340-
child_valobj_sp = base->GetSyntheticArrayMember(child_idx, true);
341-
if (!child_valobj_sp) {
342-
std::string err_msg = llvm::formatv(
343-
"failed to use pointer as array for index {0} for "
344-
"\"({1}) {2}\"",
345-
child_idx, base->GetTypeName().AsCString("<invalid type>"),
346-
var_expr_path_strm.GetData());
347-
if (base_type.IsPointerToVoid())
348-
err_msg = "subscript of pointer to incomplete type 'void'";
349-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
350-
node->GetLocation());
351-
}
352-
} else if (base_type.IsArrayType(nullptr, nullptr, &is_incomplete_array)) {
353-
child_valobj_sp = base->GetChildAtIndex(child_idx);
354-
if (!child_valobj_sp && (is_incomplete_array || m_use_synthetic))
355-
child_valobj_sp = base->GetSyntheticArrayMember(child_idx, true);
356-
if (!child_valobj_sp) {
357-
std::string err_msg = llvm::formatv(
335+
if (lldb::ValueObjectSP synthetic = base->GetSyntheticValue()) {
336+
llvm::Expected<uint32_t> num_children =
337+
synthetic->GetNumChildren(child_idx + 1);
338+
if (!num_children)
339+
return llvm::make_error<DILDiagnosticError>(
340+
m_expr, toString(num_children.takeError()), node->GetLocation());
341+
if (child_idx >= *num_children) {
342+
std::string message = llvm::formatv(
358343
"array index {0} is not valid for \"({1}) {2}\"", child_idx,
359344
base->GetTypeName().AsCString("<invalid type>"),
360-
var_expr_path_strm.GetData());
361-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
345+
base->GetName().AsCString());
346+
return llvm::make_error<DILDiagnosticError>(m_expr, message,
362347
node->GetLocation());
363348
}
364-
} else if (base_type.IsScalarType()) {
365-
child_valobj_sp =
366-
base->GetSyntheticBitFieldChild(child_idx, child_idx, true);
367-
if (!child_valobj_sp) {
368-
std::string err_msg = llvm::formatv(
369-
"bitfield range {0}-{1} is not valid for \"({2}) {3}\"", child_idx,
370-
child_idx, base->GetTypeName().AsCString("<invalid type>"),
371-
var_expr_path_strm.GetData());
372-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
373-
node->GetLocation(), 1);
374-
}
375-
} else {
376-
lldb::ValueObjectSP synthetic = base->GetSyntheticValue();
377-
if (!m_use_synthetic || !synthetic || synthetic == base) {
378-
std::string err_msg =
379-
llvm::formatv("\"{0}\" is not an array type",
380-
base->GetTypeName().AsCString("<invalid type>"));
381-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
382-
node->GetLocation(), 1);
383-
}
384-
if (static_cast<uint32_t>(child_idx) >=
385-
synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
386-
std::string err_msg = llvm::formatv(
387-
"array index {0} is not valid for \"({1}) {2}\"", child_idx,
388-
base->GetTypeName().AsCString("<invalid type>"),
389-
var_expr_path_strm.GetData());
390-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
391-
node->GetLocation(), 1);
392-
}
393-
child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
394-
if (!child_valobj_sp) {
395-
std::string err_msg = llvm::formatv(
396-
"array index {0} is not valid for \"({1}) {2}\"", child_idx,
397-
base->GetTypeName().AsCString("<invalid type>"),
398-
var_expr_path_strm.GetData());
399-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
400-
node->GetLocation(), 1);
401-
}
349+
if (lldb::ValueObjectSP child_valobj_sp =
350+
synthetic->GetChildAtIndex(child_idx))
351+
return child_valobj_sp;
402352
}
403353

404-
if (child_valobj_sp) {
405-
if (m_use_dynamic != lldb::eNoDynamicValues) {
406-
if (auto dynamic_sp = child_valobj_sp->GetDynamicValue(m_use_dynamic))
407-
child_valobj_sp = std::move(dynamic_sp);
408-
}
409-
return child_valobj_sp;
354+
auto base_type = base->GetCompilerType().GetNonReferenceType();
355+
if (!base_type.IsPointerType() && !base_type.IsArrayType())
356+
return llvm::make_error<DILDiagnosticError>(
357+
m_expr, "subscripted value is not an array or pointer",
358+
node->GetLocation());
359+
if (base_type.IsPointerToVoid())
360+
return llvm::make_error<DILDiagnosticError>(
361+
m_expr, "subscript of pointer to incomplete type 'void'",
362+
node->GetLocation());
363+
364+
if (base_type.IsArrayType()) {
365+
if (lldb::ValueObjectSP child_valobj_sp = base->GetChildAtIndex(child_idx))
366+
return child_valobj_sp;
410367
}
411368

412369
int64_t signed_child_idx = node->GetIndex();

lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,17 @@ def test_subscript(self):
6969
substrs=["expected 'r_square', got: <'.'"],
7070
)
7171

72-
# Test accessing bits in scalar types.
73-
self.expect_var_path("idx_1[0]", value="1")
74-
self.expect_var_path("idx_1[1]", value="0")
75-
76-
# Bit adcess not valid for a reference.
72+
# Base should be a "pointer to T" and index should be of an integral type.
73+
self.expect(
74+
"frame var 'idx_1[0]'",
75+
error=True,
76+
substrs=["subscripted value is not an array or pointer"],
77+
)
7778
self.expect(
7879
"frame var 'idx_1_ref[0]'",
7980
error=True,
80-
substrs=["bitfield range 0-0 is not valid"],
81+
substrs=["subscripted value is not an array or pointer"],
8182
)
82-
83-
# Base should be a "pointer to T" and index should be of an integral type.
8483
self.expect(
8584
"frame var 'int_arr[int_ptr]'",
8685
error=True,
@@ -106,8 +105,6 @@ def test_subscript_synthetic(self):
106105
)
107106

108107
self.runCmd("settings set target.experimental.use-DIL true")
109-
self.runCmd("script from myArraySynthProvider import *")
110-
self.runCmd("type synth add -l myArraySynthProvider myArray")
111108

112109
# Test synthetic value subscription
113110
self.expect_var_path("vector[1]", value="2")
@@ -116,7 +113,3 @@ def test_subscript_synthetic(self):
116113
error=True,
117114
substrs=["array index 100 is not valid"],
118115
)
119-
self.expect(
120-
"frame var 'ma_ptr[0]'",
121-
substrs=["(myArray) ma_ptr[0] = ([0] = 7, [1] = 8, [2] = 9, [3] = 10)"],
122-
)

lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/main.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#include <vector>
22

3-
class myArray {
4-
public:
5-
int m_array[4] = {7, 8, 9, 10};
6-
int m_arr_size = 4;
7-
};
8-
93
int main(int argc, char **argv) {
104
int int_arr[] = {1, 2, 3};
115
int *int_ptr = int_arr;
@@ -35,8 +29,5 @@ int main(int argc, char **argv) {
3529

3630
std::vector<int> vector = {1, 2, 3};
3731

38-
myArray ma;
39-
myArray *ma_ptr = &ma;
40-
4132
return 0; // Set a breakpoint here
4233
}

lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/myArraySynthProvider.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)