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

Add read and write features #343

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
sudo: false

language: rust
cache: cargo
cache:
directories:
- /home/travis/.cargo

os:
- linux
Expand All @@ -17,11 +19,7 @@ rust:
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- binutils-dev
- libiberty-dev # same
- libssl-dev

before_script:
- if [[ -e ~/.local/bin ]]; then export PATH=~/.local/bin:$PATH; fi
Expand All @@ -33,9 +31,8 @@ script: ./ci/script.sh
env:
matrix:
- GIMLI_JOB="test" GIMLI_PROFILE=
- GIMLI_JOB="test" GIMLI_PROFILE="--release"
- GIMLI_JOB="examples" GIMLI_PROFILE=
- GIMLI_JOB="examples" GIMLI_PROFILE="--release"
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features --features read,std"
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features --features write"

matrix:
fast_finish: true
Expand All @@ -49,14 +46,12 @@ matrix:
- rust: stable
os: linux
env: GIMLI_JOB="doc" GIMLI_PROFILE=
# Benching should only happen on nightly with --release.
# Benching should only happen on nightly.
- rust: nightly
env: GIMLI_JOB="bench" GIMLI_PROFILE="--release"
env: GIMLI_JOB="bench" GIMLI_PROFILE=
# The no-std/alloc build should only happen on nightly.
- rust: nightly
env: GIMLI_JOB="alloc" GIMLI_PROFILE=
- rust: nightly
env: GIMLI_JOB="alloc" GIMLI_PROFILE="--release"
# Build a 32 bit target.
- rust: stable
sudo: required
Expand All @@ -75,4 +70,3 @@ matrix:
- GIMLI_PROFILE=
allow_failures:
- env: GIMLI_JOB="alloc" GIMLI_PROFILE=
- env: GIMLI_JOB="alloc" GIMLI_PROFILE="--release"
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ test-assembler = "0.1.3"
typed-arena = "1"

[features]
std = ["fallible-iterator/std", "stable_deref_trait/std", "indexmap"]
read = []
write = ["std", "indexmap"]
std = ["fallible-iterator/std", "stable_deref_trait/std"]
alloc = ["fallible-iterator/alloc", "stable_deref_trait/alloc"]
default = ["std"]
default = ["read", "write", "std"]
15 changes: 10 additions & 5 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
set -ex

case "$GIMLI_JOB" in
"test")
"build")
cargo build $GIMLI_PROFILE
cargo test $GIMLI_PROFILE
cargo build --release $GIMLI_PROFILE
;;

"examples")
"test")
cargo build $GIMLI_PROFILE
cargo test $GIMLI_PROFILE
cargo build --release $GIMLI_PROFILE
cargo test --release $GIMLI_PROFILE
case "$TRAVIS_OS_NAME" in
"osx")
with_debug_info=$(find ./target/debug -type f | grep DWARF | grep gimli | head -n 1)
Expand All @@ -21,7 +24,8 @@ case "$GIMLI_JOB" in
echo "Error! Unknown \$TRAVIS_OS_NAME: $TRAVIS_OS_NAME"
exit 1
esac
cargo run --example dwarfdump -- "$with_debug_info" > /dev/null
cargo run --example dwarfdump -- "$with_debug_info" > /dev/null
cargo run --release --example dwarfdump -- "$with_debug_info" > /dev/null
;;

"doc")
Expand All @@ -30,7 +34,8 @@ case "$GIMLI_JOB" in

"alloc")
test "$TRAVIS_RUST_VERSION" == "nightly"
cargo build --no-default-features --features alloc $GIMLI_PROFILE
cargo build --no-default-features --features read,alloc $GIMLI_PROFILE
cargo build --release --no-default-features --features read,alloc $GIMLI_PROFILE
;;

"bench")
Expand Down
3 changes: 2 additions & 1 deletion src/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn low_bits_of_u64(val: u64) -> u8 {

/// A module for reading signed and unsigned integers that have been LEB128
/// encoded.
#[cfg(feature = "read")]
pub mod read {
use super::{low_bits_of_byte, CONTINUATION_BIT, SIGN_BIT};
use read::{Error, Reader, Result};
Expand Down Expand Up @@ -119,7 +120,7 @@ pub mod read {
}

/// A module for writing integers encoded as LEB128.
#[cfg(feature = "std")]
#[cfg(feature = "write")]
pub mod write {
use super::{low_bits_of_u64, CONTINUATION_BIT};
use std::io;
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
//! * `alloc`: Nightly only. Enables usage of the unstable, nightly-only
//! `#![feature(alloc)]` Rust feature that allows `gimli` to use boxes and
//! collection types in a `#[no_std]` environment.
//!
//! * `read`: Enabled by default. Enables the `read` module. Requires
//! either `alloc` or `std` to also be enabled.
//!
//! * `write`: Enabled by default. Enables the `write` module. Automatically
//! enables `std` too.
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
// Allow clippy warnings when we aren't building with clippy.
Expand Down Expand Up @@ -194,7 +200,7 @@ extern crate core as std;
extern crate arrayvec;
extern crate byteorder;
extern crate fallible_iterator;
#[cfg(feature = "std")]
#[cfg(feature = "write")]
extern crate indexmap;
extern crate stable_deref_trait;

Expand Down Expand Up @@ -239,11 +245,13 @@ pub use endianity::{BigEndian, Endianity, LittleEndian, NativeEndian, RunTimeEnd

pub mod leb128;

#[cfg(feature = "read")]
pub mod read;
// For backwards compat.
#[cfg(feature = "read")]
pub use read::*;

#[cfg(feature = "std")]
#[cfg(feature = "write")]
pub mod write;

#[cfg(test)]
Expand Down
104 changes: 55 additions & 49 deletions src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::fmt;
use std::ops::DerefMut;
use std::result;

use read;

mod endian_vec;
pub use self::endian_vec::*;

Expand Down Expand Up @@ -70,53 +68,6 @@ impl error::Error for Error {}
/// The result of a write.
pub type Result<T> = result::Result<T, Error>;

/// An error that occurred when converting a read value into a write value.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConvertError {
/// An error occurred when reading.
Read(read::Error),
/// Writing of this attribute value is not implemented yet.
UnsupportedAttributeValue,
/// This attribute value is an invalid name/form combination.
InvalidAttributeValue,
/// A `.debug_info` reference does not refer to a valid entry.
InvalidDebugInfoOffset,
/// An address could not be converted.
InvalidAddress,
}

impl fmt::Display for ConvertError {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
use self::ConvertError::*;
match *self {
Read(ref e) => e.fmt(f),
UnsupportedAttributeValue => {
write!(f, "Writing of this attribute value is not implemented yet.")
}
InvalidAttributeValue => write!(
f,
"This attribute value is an invalid name/form combination."
),
InvalidDebugInfoOffset => write!(
f,
"A `.debug_info` reference does not refer to a valid entry."
),
InvalidAddress => write!(f, "An address could not be converted."),
}
}
}

impl error::Error for ConvertError {}

impl From<read::Error> for ConvertError {
fn from(e: read::Error) -> Self {
ConvertError::Read(e)
}
}

/// The result of a conversion.
pub type ConvertResult<T> = result::Result<T, ConvertError>;

/// An identifier for a DWARF section.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SectionId {
Expand Down Expand Up @@ -186,3 +137,58 @@ pub enum Address {
addend: i64,
},
}

#[cfg(feature = "read")]
mod convert {
use super::*;
use read;

/// An error that occurred when converting a read value into a write value.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConvertError {
/// An error occurred when reading.
Read(read::Error),
/// Writing of this attribute value is not implemented yet.
UnsupportedAttributeValue,
/// This attribute value is an invalid name/form combination.
InvalidAttributeValue,
/// A `.debug_info` reference does not refer to a valid entry.
InvalidDebugInfoOffset,
/// An address could not be converted.
InvalidAddress,
}

impl fmt::Display for ConvertError {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
use self::ConvertError::*;
match *self {
Read(ref e) => e.fmt(f),
UnsupportedAttributeValue => {
write!(f, "Writing of this attribute value is not implemented yet.")
}
InvalidAttributeValue => write!(
f,
"This attribute value is an invalid name/form combination."
),
InvalidDebugInfoOffset => write!(
f,
"A `.debug_info` reference does not refer to a valid entry."
),
InvalidAddress => write!(f, "An address could not be converted."),
}
}
}

impl error::Error for ConvertError {}

impl From<read::Error> for ConvertError {
fn from(e: read::Error) -> Self {
ConvertError::Read(e)
}
}

/// The result of a conversion.
pub type ConvertResult<T> = result::Result<T, ConvertError>;
}
#[cfg(feature = "read")]
pub use self::convert::*;
Loading