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

Convert remaining modules to use Reader #214

Merged
merged 8 commits into from
Jul 4, 2017
Merged

Conversation

philipc
Copy link
Collaborator

@philipc philipc commented Jul 3, 2017

Also avoid Copy/Eq requirement by using offsets.

Next step after this is to convert dwarfdump to use Reader. Probably need to add to_vec and to_string methods to the Reader trait to allow this.

@philipc philipc requested a review from fitzgen July 3, 2017 03:38
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.531% when pulling 0db9a25 on philipc:reader into 32acbcc on gimli-rs:master.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Thanks for doing all this conversion work, @philipc :)

I have a concern about the first commit (see below) and a bunch of little nitpicks from copy-paste. Would like to hash it out before we merge this PR.

Thanks again!

src/cfi.rs Outdated
@@ -766,7 +766,7 @@ impl Default for Augmentation {
}

impl Augmentation {
fn parse<'aug, 'bases, 'input, Endian, Section>(augmentation_str: &'aug str,
fn parse<'aug, 'bases, 'input, Endian, Section>(augmentation_str: &'aug [u8],
Copy link
Member

Choose a reason for hiding this comment

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

Page 174, line 19 of the DWARF 5 standard (and earlier versions too) says that augmentation strings are encoded in UTF-8. Given that, why would we want to parse as &[u8]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So that we can trivially convert this to use the Reader trait. Since all of the characters that we understand currently are single-byte, it doesn't matter if we treat it as &[u8]. If we do need to handle multi-byte UTF-8 characters in future, we'll need to either potentially read the whole string into a Vec and then validate it as a UTF-8 string, or add a read_utf8_char method to the trait.

One thing we do lack from this approach is that we no longer validate that unknown augmentation strings are UTF-8. I don't see that as much of a problem though, since the user will handle this when they convert the Reader into a string.

src/cfi.rs Outdated
///
/// It is the caller's responsibility to read the section and present it as
/// a `&[u8]` slice. That means using some ELF loader on Linux, a Mach-O
/// loader on OSX, etc.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: not a &[u8] here, but a Reader

src/cfi.rs Outdated
///
/// It is the caller's responsibility to read the section and present it as
/// a `&[u8]` slice. That means using some ELF loader on Linux, a Mach-O
/// loader on OSX, etc.
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -11,8 +11,7 @@ use parser::{Error, Result, Format, u64_to_offset};
/// All read operations advance the section offset of the reader
/// unless specified otherwise.
///
// TODO: Don't require Copy, Eq
pub trait Reader: Debug + Clone + Copy + PartialEq + Eq + Read {
pub trait Reader: Debug + Clone + Read {
Copy link
Member

Choose a reason for hiding this comment

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

Nice :)

src/loc.rs Outdated
/// section.
///
/// It is the caller's responsibility to read the `.debug_loc` section and
/// present it as a `&[u8]` slice. That means using some ELF loader on
Copy link
Member

Choose a reason for hiding this comment

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

ditto

src/ranges.rs Outdated
/// section.
///
/// It is the caller's responsibility to read the `.debug_ranges` section and
/// present it as a `&[u8]` slice. That means using some ELF loader on
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@fitzgen
Copy link
Member

fitzgen commented Jul 3, 2017

I have a concern about the first commit

Ah, OK I see now that this was just a temporary thing until it became a &mut R in the next commit, which I guess I glazed over.

LGTM, r+ with the nitpicks on copy-paste

Thanks a third time! :)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.531% when pulling 85371f8 on philipc:reader into 32acbcc on gimli-rs:master.

@philipc philipc merged commit e042865 into gimli-rs:master Jul 4, 2017
@philipc philipc deleted the reader branch July 4, 2017 03:48
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.

3 participants