Skip to content

Commit 310351d

Browse files
authored
[LLDB] Add framework for Data Inspection Language (DIL) work. (#115666)
Add the framework code for hooking up and calling the Data Inspection Language (DIL) implementation, as an alternate implementation for the 'frame variable' command. For now, this is an opt-in option, via a target setting 'target.experimental.use-DIL'. See https://discourse.llvm.org/t/rfc-data-inspection-language/69893 for more information about this project. This PR does not actually call any of the DIL code; instead the piece that will eventually call the DIL code (StackFrame::DILEvaluateVariableExpression) calls back into the original 'frame variable' implementation.
1 parent 8ed3b05 commit 310351d

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@ class StackFrame : public ExecutionContextScope,
519519
bool HasCachedData() const;
520520

521521
private:
522+
/// Private methods, called from GetValueForVariableExpressionPath.
523+
/// See that method for documentation of parameters and return value.
524+
lldb::ValueObjectSP LegacyGetValueForVariableExpressionPath(
525+
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
526+
uint32_t options, lldb::VariableSP &var_sp, Status &error);
527+
528+
lldb::ValueObjectSP DILGetValueForVariableExpressionPath(
529+
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
530+
uint32_t options, lldb::VariableSP &var_sp, Status &error);
531+
522532
/// For StackFrame only.
523533
/// \{
524534
lldb::ThreadWP m_thread_wp;

lldb/include/lldb/Target/Target.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ class TargetProperties : public Properties {
256256

257257
bool GetInjectLocalVariables(ExecutionContext *exe_ctx) const;
258258

259+
bool GetUseDIL(ExecutionContext *exe_ctx) const;
260+
261+
void SetUseDIL(ExecutionContext *exe_ctx, bool b);
262+
259263
void SetRequireHardwareBreakpoints(bool b);
260264

261265
bool GetRequireHardwareBreakpoints() const;

lldb/source/Target/StackFrame.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,29 @@ StackFrame::GetInScopeVariableList(bool get_file_globals,
508508
ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
509509
llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
510510
VariableSP &var_sp, Status &error) {
511+
ExecutionContext exe_ctx;
512+
CalculateExecutionContext(exe_ctx);
513+
bool use_DIL = exe_ctx.GetTargetRef().GetUseDIL(&exe_ctx);
514+
if (use_DIL)
515+
return DILGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
516+
var_sp, error);
517+
518+
return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
519+
var_sp, error);
520+
}
521+
522+
ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
523+
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
524+
uint32_t options, lldb::VariableSP &var_sp, Status &error) {
525+
// This is a place-holder for the calls into the DIL parser and
526+
// evaluator. For now, just call the "real" frame variable implementation.
527+
return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
528+
var_sp, error);
529+
}
530+
531+
ValueObjectSP StackFrame::LegacyGetValueForVariableExpressionPath(
532+
llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
533+
VariableSP &var_sp, Status &error) {
511534
llvm::StringRef original_var_expr = var_expr;
512535
// We can't fetch variable information for a history stack frame.
513536
if (IsHistorical())

lldb/source/Target/Target.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,27 @@ bool TargetProperties::GetInjectLocalVariables(
43854385
.value_or(true);
43864386
}
43874387

4388+
bool TargetProperties::GetUseDIL(ExecutionContext *exe_ctx) const {
4389+
const Property *exp_property =
4390+
m_collection_sp->GetPropertyAtIndex(ePropertyExperimental, exe_ctx);
4391+
OptionValueProperties *exp_values =
4392+
exp_property->GetValue()->GetAsProperties();
4393+
if (exp_values)
4394+
return exp_values->GetPropertyAtIndexAs<bool>(ePropertyUseDIL, exe_ctx)
4395+
.value_or(false);
4396+
else
4397+
return true;
4398+
}
4399+
4400+
void TargetProperties::SetUseDIL(ExecutionContext *exe_ctx, bool b) {
4401+
const Property *exp_property =
4402+
m_collection_sp->GetPropertyAtIndex(ePropertyExperimental, exe_ctx);
4403+
OptionValueProperties *exp_values =
4404+
exp_property->GetValue()->GetAsProperties();
4405+
if (exp_values)
4406+
exp_values->SetPropertyAtIndex(ePropertyUseDIL, true, exe_ctx);
4407+
}
4408+
43884409
ArchSpec TargetProperties::GetDefaultArchitecture() const {
43894410
const uint32_t idx = ePropertyDefaultArch;
43904411
return GetPropertyAtIndexAs<ArchSpec>(idx, {});

lldb/source/Target/TargetProperties.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ let Definition = "target_experimental" in {
44
def InjectLocalVars : Property<"inject-local-vars", "Boolean">,
55
Global, DefaultTrue,
66
Desc<"If true, inject local variables explicitly into the expression text. This will fix symbol resolution when there are name collisions between ivars and local variables. But it can make expressions run much more slowly.">;
7+
def UseDIL : Property<"use-DIL", "Boolean">,
8+
Global, DefaultFalse,
9+
Desc<"If true, use the alternative DIL implementation for frame variable evaluation.">;
710
}
811

912
let Definition = "target" in {

0 commit comments

Comments
 (0)