Skip to content
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

gdb Pretty Print: generic encoded was failing on reference/pointer types #33612

Merged
merged 1 commit into from
May 15, 2016
Merged

gdb Pretty Print: generic encoded was failing on reference/pointer types #33612

merged 1 commit into from
May 15, 2016

Conversation

royalstream
Copy link
Contributor

If you debug this program using gdb

fn main() {
    let x = 10;
    let y = Some(&x);
    // additional code
}

And you try to print y's value from the debugger, you get the following:

(gdb) print y
Python Exception <class 'gdb.error'> Cannot convert value to int.: 
$1 = {RUST$ENCODED$ENUM$0$None = Some = {0x7fff5fbff97c}}

What happens is that inside debugger_pretty_printers_common.py the method is_null_variant doesn't have any special handling for pointer values so it ends up calling .as_integer() on discriminant_val (which holds a pointer) and fails.

Considering it needs to handle pointers and return true when the pointer is null, I modified the .as_integer() method in gdb_rust_pretty_printing.py to take pointers into consideration.

After this modification gdb prints y like this:

(gdb) print y
$1 = Some = {0x7fff5fbff97c}

Now, it would be nice to print something useful (instead of a pointer address) but the pretty printer doesn't currently handle references/pointers so that's a completely different subject.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@nikomatsakis
Copy link
Contributor

Hmm, do we have any unit testing for these pretty printers?

cc @michaelwoerister

@michaelwoerister
Copy link
Member

We had tests for this at some point:
3430532

I don't remember why they were removed.

@michaelwoerister
Copy link
Member

@bors: r+
Thanks for the PR!

@bors
Copy link
Contributor

bors commented May 13, 2016

📌 Commit 04baf25 has been approved by michaelwoerister

@bors
Copy link
Contributor

bors commented May 15, 2016

⌛ Testing commit 04baf25 with merge b358319...

bors added a commit that referenced this pull request May 15, 2016
…lwoerister

gdb Pretty Print: generic encoded was failing on reference/pointer types

If you debug this program using **gdb**
```rust
fn main() {
    let x = 10;
    let y = Some(&x);
    // additional code
}
```
And you try to print **y**'s value from the debugger, you get the following:
```
(gdb) print y
Python Exception <class 'gdb.error'> Cannot convert value to int.:
$1 = {RUST$ENCODED$ENUM$0$None = Some = {0x7fff5fbff97c}}
```
What happens is that inside **debugger_pretty_printers_common.py** the method `is_null_variant` doesn't have any special handling for pointer values so it ends up calling `.as_integer()` on `discriminant_val` (which holds a pointer) and fails.

Considering it needs to handle pointers and return _true_ when the pointer is _null_, I modified the `.as_integer()` method in **gdb_rust_pretty_printing.py** to take pointers into consideration.

After this modification **gdb** prints **y** like this:
```
(gdb) print y
$1 = Some = {0x7fff5fbff97c}
```
Now, it would be nice to print something useful (instead of a pointer address) but the pretty printer doesn't currently handle references/pointers so that's a completely different subject.
@bors bors merged commit 04baf25 into rust-lang:master May 15, 2016
bors added a commit that referenced this pull request May 16, 2016
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.

5 participants