This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Support non-pointer implicit this/self in GetValueForVariableExpressionPath
ClosedPublic

Authored by kastiglione on Jun 12 2022, 12:08 PM.

Details

Summary

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

Diff Detail

Event Timeline

kastiglione created this revision.Jun 12 2022, 12:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2022, 12:08 PM
kastiglione requested review of this revision.Jun 12 2022, 12:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2022, 12:08 PM

use explicit type instead of auto

kastiglione edited the summary of this revision. (Show Details)Jun 12 2022, 12:12 PM
kastiglione edited the summary of this revision. (Show Details)Jun 12 2022, 12:14 PM

check valid compiler type

aprantl accepted this revision.Jun 13 2022, 4:24 PM

This is good, but it also illustrates how the strings "->" and ".'" should actually come from the typesystem and not be hardcoded. We're just lucky that all languages have a "." operator.

This revision is now accepted and ready to land.Jun 13 2022, 4:24 PM

More elegant would be to just add an API to TypeSystem to get the operator to access ivars.

kastiglione added a comment.EditedJun 13 2022, 4:52 PM

This is good, but it also illustrates how the strings "->" and ".'" should actually come from the typesystem and not be hardcoded. We're just lucky that all languages have a "." operator.

More elegant would be to just add an API to TypeSystem to get the operator to access ivars.

Initially I was thinking along these lines. But I became less sure. The "variable expression path" syntax is C-like but independent of the source language. For example, in Swift, there is no ->. So my rhetorical question is, should the Language or TypeSystem, etc, know about "variable expression path" syntax, as you suggest? Or should we rely on there being a shared subset between source language and variable expression path syntax, and allow the two subsystems to think they're speaking the same language even though we know they're each actually speaking a different but partially compatible language (source vs variable expression path).

I decided to keep the ->/. choice inside GetValueForVariableExpressionPath because I feel that kind of logic belongs closer to other variable expression path code.

This revision was automatically updated to reflect the committed changes.

This is good, but it also illustrates how the strings "->" and ".'" should actually come from the typesystem and not be hardcoded. We're just lucky that all languages have a "." operator.

More elegant would be to just add an API to TypeSystem to get the operator to access ivars.

Initially I was thinking along these lines. But I became less sure. The "variable expression path" syntax is C-like but independent of the source language. For example, in Swift, there is no ->. So my rhetorical question is, should the Language or TypeSystem, etc, know about "variable expression path" syntax, as you suggest? Or should we rely on there being a shared subset between source language and variable expression path syntax, and allow the two subsystems to think they're speaking the same language even though we know they're each actually speaking a different but partially compatible language (source vs variable expression path).

I decided to keep the ->/. choice inside GetValueForVariableExpressionPath because I feel that kind of logic belongs closer to other variable expression path code.

The original intention of the variable expression paths was that they were really about navigating the ValueObject hierarchy, and the syntax we use should be governed by how to do that most conveniently, without being bound by the variety of languages that might underly that ValueObject hierarchy. That's particularly convenient when you get to synthetic children, which aren't necessarily bound to the language in which the types are expressed.