Skip to content

Add bundled pretty-printers for LLDB #2928

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 3 commits into from
Oct 31, 2018
Merged

Conversation

artemmukhin
Copy link
Member

@artemmukhin artemmukhin commented Oct 11, 2018

Current version of LLDB pretty-printer for Rust is very primitive. For example, it doesn't support children-based representation of data (synthetic children).

I started to develop a new LLDB pretty-printer for Rust. This PR adds:

  • Vec: size as summary and elements as synthetic children;
  • String and &str: value as summary, also supports UTF-8;
  • Regular structures, arrays, and slices: LLDB already supports it.

screen shot 2018-10-31 at 14 28 36

screen shot 2018-10-31 at 14 28 50

screen shot 2018-10-31 at 14 09 52

@artemmukhin artemmukhin changed the title WIP: Bundled pretty-printer for LLDB (std_vec support) WIP: Add bundled pretty-printer for LLDB (Vec support) Oct 11, 2018
Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Might be a good idea to upstream pretty printer changes?

@mchernyavsky
Copy link
Member

Flake8's output:

lldb_pretty_printer.py:18:80: E501 line too long (113 > 79 characters)
lldb_pretty_printer.py:19:80: E501 line too long (98 > 79 characters)
lldb_pretty_printer.py:30:80: E501 line too long (94 > 79 characters)
lldb_pretty_printer.py:38:80: E501 line too long (89 > 79 characters)
lldb_pretty_printer.py:49:9: E722 do not use bare except'
lldb_pretty_printer.py:58:80: E501 line too long (112 > 79 characters)

@Undin
Copy link
Member

Undin commented Oct 11, 2018

@matklad yep, we are going to do it

@Undin
Copy link
Member

Undin commented Oct 11, 2018

@mchernyavsky I think the warning about 80 symbols per line doesn't really make sense. Looks like we are not going to modify this code via console editors so we can easily use restriction in 120 symbols

@vlad20012
Copy link
Member

Let's move lldb_pretty_printer.py from src/main/kotiln to src/main/resources. Kotlin directory should contains only kotlin sources

@artemmukhin artemmukhin force-pushed the debugger branch 5 times, most recently from c8da71c to cbcab57 Compare October 12, 2018 11:19
@artemmukhin artemmukhin force-pushed the debugger branch 2 times, most recently from 37cf907 to 530667a Compare October 16, 2018 15:38
@artemmukhin artemmukhin changed the title WIP: Add bundled pretty-printer for LLDB (Vec support) Add bundled pretty-printer for LLDB (Vec support) Oct 16, 2018
Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

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

The current implementation doesn't work for me now. But I'm absolutely sure that some previous version worked pretty well on my mac.
Could you check it?


private fun getSourceCode(): String {
val resourceStream = LLDBJetbrainsPrettyPrinter::class.java.classLoader.getResourceAsStream("$PP_RESOURCE_DIR/$LLDB_PP")
return resourceStream.bufferedReader().use { it.readText() }
Copy link
Member

Choose a reason for hiding this comment

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

readText potentially throws IOException

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ApplicationComponent

class UpdatePrettyPrintersComponent : ApplicationComponent, Disposable {
Copy link
Member

Choose a reason for hiding this comment

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

UnpackPrettyPrintersComponent looks more suitable here

// NOP
}

override fun dispose() = disposeComponent()
Copy link
Member

Choose a reason for hiding this comment

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

Looks like that we don't need to implement Disposable and implement custom disposeComponent.

@@ -18,21 +18,28 @@ class RsDebuggerSettingsConfigurable(
private val isRendersEnabledCheckbox: JBCheckBox = JBCheckBox("Enable Rust library renders")
private var isRendersEnabled: Boolean by CheckboxDelegate(isRendersEnabledCheckbox)

private val isBundledPrintersEnabledCheckbox: JBCheckBox = JBCheckBox("Enable bundled IntelliJ Rust pretty-printers")
Copy link
Member

Choose a reason for hiding this comment

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

Let's shorten label to Enable bundled pretty-printers

@artemmukhin
Copy link
Member Author

@Undin thank you for the review! Now it should work fine again.

@artemmukhin artemmukhin force-pushed the debugger branch 2 times, most recently from a034e3e to a60eb7d Compare October 23, 2018 12:04
@artemmukhin artemmukhin changed the title Add bundled pretty-printer for LLDB (Vec support) Add bundled pretty-printers for LLDB Oct 25, 2018
@artemmukhin
Copy link
Member Author

Initially, I was going to use my pretty-printers along with the original ones by using regular expressions (non-trivial regexes for my printers and trivial .* for original). But unfortunately, LLDB doesn't preserve the order of regexes: sometimes Vec<i32> matches with .* (instead of Vec<.+>) and goes to the original printer instead of mine. Also, LLDB doesn't support lookahead regexes, so I can't just rewrite .* with a negation of the others. Therefore, I decided to get rid of regexes at all and use pretty-printers separately to avoid conflicts: either bundled or original.

Now, instead of regexes, I use two lookups (synthetic and summary) to determine which pretty-printer should be used for a given value.

@artemmukhin artemmukhin force-pushed the debugger branch 2 times, most recently from 88a9e37 to 6dfe25a Compare October 29, 2018 10:48
Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

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

In general, it already works better than default lldb pretty printers 😄

import javax.swing.JComponent

class RsDebuggerSettingsConfigurable(
private val settings: RsDebuggerSettings
) : SearchableConfigurable {

private val isRendersEnabledCheckbox: JBCheckBox = JBCheckBox("Enable Rust library renders")
private var isRendersEnabled: Boolean by CheckboxDelegate(isRendersEnabledCheckbox)
private val isLLDB = CPPToolchains.getInstance().defaultToolchain?.debuggerKind?.isLLDB() == true
Copy link
Member

@Undin Undin Oct 29, 2018

Choose a reason for hiding this comment

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

Unfortunately, we can't just read toolchain type here because

  • RsDebuggerSettingsConfigurable is not instantiated on each opening of the corresponding ui panel in settings
  • A user can change default toolchain and we should modify our ui on each change

Let's subscribe on CPPToolchainsConfigurable.TOPIC and do the corresponding changes in ui on toolchain change

Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to unsubscribe in disposeUIResources

Copy link
Contributor

Choose a reason for hiding this comment

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

Using CPPToolchainsConfigurable.TOPIC is a rather tricky business, because of the lifecycle of the configurables. I'd suggest not to go that way.
If you absolutely have to separate GDB/LLDB settings, it will be much easier to show both settings groups (for GDB and for LLDB)

Copy link
Member

Choose a reason for hiding this comment

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

@amakeev Oh, as you are much more aware of CLion related things, let's do it in this way!

If you absolutely have to separate GDB/LLDB settings

Maybe there is a better solution, but the current one allows us to release own pretty printers partially. Also, we still use formatters from rustup distribution as defaut variant for now.
We'll merge these settings and make bundled printers default when we implement all basic features available with formatters from rustup distribution

Copy link
Contributor

Choose a reason for hiding this comment

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

Just in case: you're comment about A user can change default toolchain is totally valid. I meant that making the correct listener between two configurables is not straightforward.


private val dataFormattersLabel = Label("Data formatters")

private val dataFormatters = ComboBox<DataFormatters>().apply {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like it's better to separate properties for gdb and lldb toolchains. At least, until we have bundled pretty printers for gdb

@artemmukhin artemmukhin force-pushed the debugger branch 2 times, most recently from de8cd52 to add99ce Compare October 30, 2018 11:51
@artemmukhin artemmukhin force-pushed the debugger branch 3 times, most recently from 376cfa4 to 23a9b43 Compare October 30, 2018 15:10
Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

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

The latest minor comments:)
Also, behaviour of bundled renders differs from default rust and C++ renders in case of scalar types:

Bundled:
screen shot 2018-10-30 at 23 20 30
Default:
screen shot 2018-10-30 at 23 18 06

But it's ok for now

@artemmukhin artemmukhin force-pushed the debugger branch 2 times, most recently from 830c251 to bb5d390 Compare October 31, 2018 11:11
@artemmukhin
Copy link
Member Author

@Undin thank you for attention! Now scalar types render correctly.

@artemmukhin artemmukhin added the subsystem::debugger Issues related to debugger label Oct 31, 2018
@Undin
Copy link
Member

Undin commented Oct 31, 2018

bors r+

bors bot added a commit that referenced this pull request Oct 31, 2018
2928: Add bundled pretty-printers for LLDB r=Undin a=ortem

Current version of [LLDB pretty-printer for Rust](https://github.com/rust-lang/rust/blob/master/src/etc/lldb_rust_formatters.py) is very primitive. For example, it doesn't support children-based representation of data (synthetic children).

I started to develop a new LLDB pretty-printer for Rust. This PR adds:
* `Vec`: size as summary and elements as synthetic children;
* `String` and `&str`: value as summary, also supports UTF-8;
* Regular structures, arrays, and slices: LLDB already supports it.

<img width="438" alt="screen shot 2018-10-31 at 14 28 36" src="https://user-images.githubusercontent.com/4854600/47785295-554f9580-dd19-11e8-94ae-dffe1f930e6e.png">
<img width="394" alt="screen shot 2018-10-31 at 14 28 50" src="https://user-images.githubusercontent.com/4854600/47785297-554f9580-dd19-11e8-8821-e941d004091a.png">

<img width="451" alt="screen shot 2018-10-31 at 14 09 52" src="https://user-images.githubusercontent.com/4854600/47784453-b75acb80-dd16-11e8-83db-7e2313fd1cf3.png">


Co-authored-by: ortem <[email protected]>
@bors
Copy link
Contributor

bors bot commented Oct 31, 2018

@bors bors bot merged commit 3496337 into intellij-rust:master Oct 31, 2018
@artemmukhin artemmukhin deleted the debugger branch November 1, 2018 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subsystem::debugger Issues related to debugger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants