Skip to content

[lldb] Add Substring type summary #5559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 11, 2022

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Nov 3, 2022

Adds a type summary for Substring values.

With this change, a summary string shows the substring slice. The substring's children show the base string, and start/end indexes.

(lldb) v substring
(Substring) substring = "bcdefghijklmnopqrstuvwxy" {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}

Before this change, a literal substring was not shown, only the full base string:

(lldb) v substring
(Substring) substring = {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}

Implementation Notes

This supports Swift native (utf8) strings. NSString (utf16) are not yet supported, that will be a follow up change. Additionally, this change requires that the indexes be matching encoding.

rdar://91431816

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test

Copy link

@augusto2112 augusto2112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I just have a couple of questions.

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a nice improvement!

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione merged commit a514263 into stable/20220421 Nov 11, 2022
@kastiglione kastiglione deleted the dl/lldb-add-substring-type-summary branch November 11, 2022 23:16
uint64_t buffer[2] = {raw0, raw1};
uint64_t rawBuffer[2] = {raw0, raw1};
auto *buffer = (uint8_t *)&rawBuffer;
applySlice(buffer, count, slice);
Copy link

@Michael137 Michael137 Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong but AFAIU this is technically UB. I don't think any compiler will break this kind of type punning but the recommended way of reading a type through a uint8_t* is using memcpy.

The standard doesn't technically permit doing pointer arithmetic on something that isn't pointer-interconvertible. Chances are memcpy will get optimised away into exactly the same code that reinterpret_cast produces because memcpy is compiler magic.

kastiglione added a commit that referenced this pull request Nov 17, 2022
Replace hex literals with binary literals to improve bit masking readability. Follow up to #5559.
kastiglione added a commit that referenced this pull request Dec 3, 2022
Adds a type summary for `Substring` values.

With this change, a summary string shows the substring slice. The substring's children show the base string, and start/end indexes.

```
(lldb) v substring
(Substring) substring = "bcdefghijklmnopqrstuvwxy" {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}
```

Before this change, a literal substring was not shown, only the full base string:

```
(lldb) v substring
(Substring) substring = {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}
```

#### Implementation Notes

This supports Swift native (utf8) strings. NSString (utf16) are not yet supported, that will be a follow up change. Additionally, this change requires that the indexes be matching encoding.

rdar://91431816
(cherry picked from commit a514263)
kastiglione added a commit that referenced this pull request Dec 3, 2022
Replace hex literals with binary literals to improve bit masking readability. Follow up to #5559.

(cherry picked from commit c842163)
kastiglione added a commit that referenced this pull request Feb 9, 2023
Adds a type summary for `Substring` values.

With this change, a summary string shows the substring slice. The substring's children show the base string, and start/end indexes.

```
(lldb) v substring
(Substring) substring = "bcdefghijklmnopqrstuvwxy" {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}
```

Before this change, a literal substring was not shown, only the full base string:

```
(lldb) v substring
(Substring) substring = {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}
```

#### Implementation Notes

This supports Swift native (utf8) strings. NSString (utf16) are not yet supported, that will be a follow up change. Additionally, this change requires that the indexes be matching encoding.

rdar://91431816
(cherry picked from commit a514263)
kastiglione added a commit that referenced this pull request Feb 9, 2023
Adds a type summary for `Substring` values.

With this change, a summary string shows the substring slice. The substring's children show the base string, and start/end indexes.

```
(lldb) v substring
(Substring) substring = "bcdefghijklmnopqrstuvwxy" {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}
```

Before this change, a literal substring was not shown, only the full base string:

```
(lldb) v substring
(Substring) substring = {
  _slice = {
    _startIndex = 1[utf8]
    _endIndex = 25[utf8]
    _base = "abcdefghijklmnopqrstuvwxyz"
  }
}
```

#### Implementation Notes

This supports Swift native (utf8) strings. NSString (utf16) are not yet supported, that will be a follow up change. Additionally, this change requires that the indexes be matching encoding.

rdar://91431816
(cherry picked from commit a514263)
kastiglione added a commit that referenced this pull request Feb 9, 2023
Replace hex literals with binary literals to improve bit masking readability. Follow up to #5559.

(cherry picked from commit c842163)
kastiglione added a commit that referenced this pull request Feb 9, 2023
Replace hex literals with binary literals to improve bit masking readability. Follow up to #5559.

(cherry picked from commit c842163)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants