Skip to content

Commit f6b60d5

Browse files
authored
[lldb] Support non-pointer implicit this/self in GetValueForVariableExpressionPath (#5142)
The `frame variable` command supports an implicit `this`/`self`, allowing a user to run `v some_field` instead of `v this->some_field`. However, some languages have non-pointer `this`/`self` types (for example, Swift). This change adds support for non-pointer implicit `this`/`self`. This is done by consulting the type of the instance variable. If the type is known to be non-pointer, the dot operator is used instead of the arrow operator. The C language of families each have a pointer instance type, which makes testing of this difficult. Tests for this feature will be done in the Swift downstream fork, as Swift's `self` is a non-pointer (reference) type. rdar://82095148 Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D127605 (cherry picked from commit e30c493)
1 parent 5e60c0a commit f6b60d5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lldb/source/Target/StackFrame.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
552552

553553
if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) {
554554
// Check for direct ivars access which helps us with implicit access to
555-
// ivars with the "this->" or "self->"
555+
// ivars using "this" or "self".
556556
GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
557557
lldb::LanguageType method_language = eLanguageTypeUnknown;
558558
bool is_instance_method = false;
@@ -563,7 +563,13 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
563563
var_sp = variable_list->FindVariable(method_object_name);
564564
if (var_sp) {
565565
separator_idx = 0;
566-
var_expr_storage = "->";
566+
if (Type *var_type = var_sp->GetType())
567+
if (auto compiler_type = var_type->GetForwardCompilerType())
568+
if (!compiler_type.IsPointerType())
569+
var_expr_storage = ".";
570+
571+
if (var_expr_storage.empty())
572+
var_expr_storage = "->";
567573
var_expr_storage += var_expr;
568574
var_expr = var_expr_storage;
569575
synthetically_added_instance_object = true;

0 commit comments

Comments
 (0)