Skip to content

Commit ebf9cca

Browse files
committed
[lldb-dap] Add readOnly attribute for variables
1 parent c7500a2 commit ebf9cca

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def verify_values(self, verify_dict, actual, varref_dict=None, expression=None):
6565
self.assertNotIn(
6666
key, actual, 'key "%s" is not expected in %s' % (key, actual)
6767
)
68+
isReadOnly = verify_dict.get("readOnly", False)
69+
attributes = actual.get("presentationHint", {}).get("attributes", [])
70+
self.assertEqual(
71+
isReadOnly, "readOnly" in attributes, "%s %s" % (verify_dict, actual)
72+
)
6873
hasVariablesReference = "variablesReference" in actual
6974
varRef = None
7075
if hasVariablesReference:
@@ -179,8 +184,9 @@ def do_test_scopes_variables_setVariable_evaluate(
179184
"children": {
180185
"x": {"equals": {"type": "int", "value": "11"}},
181186
"y": {"equals": {"type": "int", "value": "22"}},
182-
"buffer": {"children": buffer_children},
187+
"buffer": {"children": buffer_children, "readOnly": True},
183188
},
189+
"readOnly": True,
184190
},
185191
"x": {"equals": {"type": "int"}},
186192
}
@@ -456,8 +462,10 @@ def do_test_scopes_and_evaluate_expansion(self, enableAutoVariableSummaries: boo
456462
"buffer": {
457463
"children": buffer_children,
458464
"equals": {"indexedVariables": 16},
465+
"readOnly": True,
459466
},
460467
},
468+
"readOnly": True,
461469
},
462470
"x": {
463471
"equals": {"type": "int"},
@@ -540,7 +548,7 @@ def do_test_scopes_and_evaluate_expansion(self, enableAutoVariableSummaries: boo
540548
"children": {
541549
"x": {"equals": {"type": "int", "value": "11"}},
542550
"y": {"equals": {"type": "int", "value": "22"}},
543-
"buffer": {"children": buffer_children},
551+
"buffer": {"children": buffer_children, "readOnly": True},
544552
},
545553
}
546554

@@ -634,11 +642,17 @@ def do_test_indexedVariables(self, enableSyntheticChildDebugging: bool):
634642
# "[raw]" child.
635643
raw_child_count = 1 if enableSyntheticChildDebugging else 0
636644
verify_locals = {
637-
"small_array": {"equals": {"indexedVariables": 5}},
638-
"large_array": {"equals": {"indexedVariables": 200}},
639-
"small_vector": {"equals": {"indexedVariables": 5 + raw_child_count}},
640-
"large_vector": {"equals": {"indexedVariables": 200 + raw_child_count}},
641-
"pt": {"missing": ["indexedVariables"]},
645+
"small_array": {"equals": {"indexedVariables": 5}, "readOnly": True},
646+
"large_array": {"equals": {"indexedVariables": 200}, "readOnly": True},
647+
"small_vector": {
648+
"equals": {"indexedVariables": 5 + raw_child_count},
649+
"readOnly": True,
650+
},
651+
"large_vector": {
652+
"equals": {"indexedVariables": 200 + raw_child_count},
653+
"readOnly": True,
654+
},
655+
"pt": {"missing": ["indexedVariables"], "readOnly": True},
642656
}
643657
self.verify_variables(verify_locals, locals)
644658

@@ -652,7 +666,10 @@ def do_test_indexedVariables(self, enableSyntheticChildDebugging: bool):
652666
"[4]": {"equals": {"type": "int", "value": "0"}},
653667
}
654668
if enableSyntheticChildDebugging:
655-
verify_children["[raw]"] = ({"contains": {"type": ["vector"]}},)
669+
verify_children["[raw]"] = {
670+
"contains": {"type": ["vector"]},
671+
"readOnly": True,
672+
}
656673

657674
children = self.dap_server.request_variables(locals[2]["variablesReference"])[
658675
"body"
@@ -672,7 +689,7 @@ def test_return_variables(self):
672689
return_name: {"equals": {"type": "int", "value": "300"}},
673690
"argc": {},
674691
"argv": {},
675-
"pt": {},
692+
"pt": {"readOnly": True},
676693
"x": {},
677694
"return_result": {"equals": {"type": "int"}},
678695
}

lldb/tools/lldb-dap/ProtocolUtils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ Variable CreateVariable(lldb::SBValue v, int64_t var_ref, bool format_hex,
301301
if (lldb::addr_t addr = v.GetLoadAddress(); addr != LLDB_INVALID_ADDRESS)
302302
var.memoryReference = addr;
303303

304+
bool is_readonly = v.GetType().IsAggregateType() ||
305+
v.GetValueType() == lldb::eValueTypeRegisterSet;
306+
if (is_readonly) {
307+
if (!var.presentationHint)
308+
var.presentationHint = {VariablePresentationHint()};
309+
var.presentationHint->attributes.push_back("readOnly");
310+
}
311+
304312
return var;
305313
}
306314

0 commit comments

Comments
 (0)