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 #![no_std] support #271

Merged
merged 2 commits into from
Dec 28, 2017
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ script:
with_debug_info=$(find ./target/debug -type f -perm -100 | grep gimli | head -n 1) &&
travis-cargo run -- --example dwarfdump "$with_debug_info" > /dev/null
)) &&
travis-cargo --only nightly build -- --no-default-features --features nightly &&
travis-cargo --only stable doc

after_success:
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ travis-ci = { repository = "gimli-rs/gimli" }
coveralls = { repository = "gimli-rs/gimli" }

[dependencies]
arrayvec = "0.4.6"
byteorder = "1"
fallible-iterator = "0.1.2"
arrayvec = { version = "0.4.6", default-features = false }
byteorder = { version = "1.0", default-features = false }
fallible-iterator = { version = "0.1.4", default-features = false }

[dev-dependencies]
getopts = "0.2"
Expand All @@ -26,4 +26,6 @@ object = "0.6"
test-assembler = "0.1.3"

[features]
nightly = []
std = ["fallible-iterator/std"]
nightly = ["fallible-iterator/alloc"]
default = ["std"]
11 changes: 6 additions & 5 deletions src/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use endianity::{EndianBuf, Endianity};
use parser::{Error, Format, Result};
use reader::Reader;
use unit::UnitHeader;
use std::collections::hash_map;
use vec::Vec;
use btree_map;
use Section;

/// An offset into the `.debug_abbrev` section.
Expand Down Expand Up @@ -80,15 +81,15 @@ impl<R: Reader> From<R> for DebugAbbrev<R> {
#[derive(Debug, Default, Clone)]
pub struct Abbreviations {
vec: Vec<Abbreviation>,
map: hash_map::HashMap<u64, Abbreviation>,
map: btree_map::BTreeMap<u64, Abbreviation>,
}

impl Abbreviations {
/// Construct a new, empty set of abbreviations.
fn empty() -> Abbreviations {
Abbreviations {
vec: Vec::new(),
map: hash_map::HashMap::new(),
map: btree_map::BTreeMap::new(),
}
}

Expand Down Expand Up @@ -116,8 +117,8 @@ impl Abbreviations {
}
}
match self.map.entry(abbrev.code) {
hash_map::Entry::Occupied(_) => Err(()),
hash_map::Entry::Vacant(entry) => {
btree_map::Entry::Occupied(_) => Err(()),
btree_map::Entry::Vacant(entry) => {
entry.insert(abbrev);
Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::marker::PhantomData;
use std::cmp::{Ord, Ordering};
use std::mem;
use std::str;
use boxed::Box;
use Section;

/// An offset into the `.debug_frame` section.
Expand Down Expand Up @@ -3105,6 +3106,7 @@ mod tests {
use std::marker::PhantomData;
use std::mem;
use std::u64;
use vec::Vec;
use test_util::GimliSectionMethods;

type DebugFrameCie<R, O = usize> = CommonInformationEntry<DebugFrame<R>, R, O>;
Expand Down
3 changes: 2 additions & 1 deletion src/endianity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use byteorder;
use byteorder::ByteOrder;
use std::borrow::Cow;
use std::fmt::Debug;
use std::mem;
use std::ops::{Deref, Index, Range, RangeFrom, RangeTo};
use std::str;
use string::String;
use borrow::Cow;
use parser::{Error, Result};
use reader::Reader;

Expand Down
2 changes: 2 additions & 0 deletions src/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn low_bits_of_byte(byte: u8) -> u8 {
}

#[inline]
#[allow(dead_code)]
fn low_bits_of_u64(val: u64) -> u8 {
let byte = val & (std::u8::MAX as u64);
low_bits_of_byte(byte as u8)
Expand Down Expand Up @@ -119,6 +120,7 @@ pub mod read {
}

/// A module for writing integers encoded as LEB128.
#[cfg(feature = "std")]
pub mod write {
use super::{low_bits_of_u64, CONTINUATION_BIT};
use std::io;
Expand Down
34 changes: 34 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,44 @@
// False positives when block expressions are used inside an assertion.
#![allow(panic_params)]

#![no_std]
#![cfg_attr(feature = "nightly", feature(alloc))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason for this to use a nightly feature, instead of not(feature = "std") like we do elsewhere? It'd be nice if cargo build --no-default-features could work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. See Cargo.toml:

nightly = ["fallible-iterator/alloc"]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, this is probably nitpicky, but I just want to make sure I understand if you don't mind:

  • do we need to use fallible-iterator/alloc in gimli?
  • why don't the uses of the alloc crate depend on the nightly feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we need to use fallible-iterator/alloc in gimli?

Yes. Otherwise, it cannot be tested without the std feature, I believe.


#[cfg(feature = "std")]
#[macro_use]
extern crate std;

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate core as std;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;

extern crate arrayvec;
extern crate byteorder;
extern crate fallible_iterator;

#[cfg(feature = "std")]
mod imports {
pub use std::boxed;
pub use std::vec;
pub use std::string;
pub use std::borrow;
pub use std::collections::btree_map;
}

#[cfg(not(feature = "std"))]
mod imports {
pub use alloc::boxed;
pub use alloc::vec;
pub use alloc::string;
pub use alloc::borrow;
pub use alloc::btree_map;
}

use imports::*;

mod cfi;
pub use cfi::*;

Expand Down
1 change: 1 addition & 0 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use endianity::{EndianBuf, Endianity};
use parser;
use reader::{Reader, ReaderOffset};
use std::fmt;
use vec::Vec;
use Section;

/// An offset into the `.debug_line` section.
Expand Down
1 change: 1 addition & 0 deletions src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use parser::{Error, Format};
use reader::{Reader, ReaderOffset};
use unit::{DebugInfoOffset, UnitOffset};
use std::mem;
use vec::Vec;

/// A reference to a DIE, either relative to the current CU or
/// relative to the section.
Expand Down
17 changes: 13 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Functions for parsing DWARF debugging information.

use std::error;
use std::fmt::{self, Debug};
use std::io;
use std::result;
#[cfg(feature = "std")]
use std::{io, error};
use cfi::BaseAddresses;
use constants;
use reader::{Reader, ReaderOffset};
Expand Down Expand Up @@ -143,8 +143,9 @@ impl fmt::Display for Error {
}
}

impl error::Error for Error {
fn description(&self) -> &str {
impl Error {
/// A short description of the error.
pub fn description(&self) -> &str {
match *self {
Error::Io => "An I/O error occurred while reading.",
Error::CfiRelativePointerButCfiBaseIsUndefined => {
Expand Down Expand Up @@ -259,6 +260,14 @@ impl error::Error for Error {
}
}

#[cfg(feature = "std")]
impl error::Error for Error {
fn description(&self) -> &str {
Error::description(self)
}
}

#[cfg(feature = "std")]
impl From<io::Error> for Error {
fn from(_: io::Error) -> Self {
Error::Io
Expand Down
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::fmt::Debug;
use std::ops::{Add, AddAssign, Sub};
use borrow::Cow;

use endianity::Endianity;
use leb128;
Expand Down
2 changes: 2 additions & 0 deletions src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

extern crate test_assembler;

use vec::Vec;

use leb128;
use self::test_assembler::{Endian, Section, ToLabelOrNum};

Expand Down
1 change: 1 addition & 0 deletions src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,7 @@ mod tests {
use str::DebugStrOffset;
use std;
use std::cell::Cell;
use vec::Vec;
use test_util::GimliSectionMethods;

// Mixin methods for `Section` to help define binary test data.
Expand Down