Browse Source

add mechanism for forcing frame pointer.

master
matt rice 5 years ago
committed by Alex Crichton
parent
commit
02ed9e6895
  1. 31
      src/lib.rs
  2. 32
      tests/test.rs

31
src/lib.rs

@ -105,6 +105,7 @@ pub struct Build {
out_dir: Option<PathBuf>, out_dir: Option<PathBuf>,
opt_level: Option<String>, opt_level: Option<String>,
debug: Option<bool>, debug: Option<bool>,
force_frame_pointer: Option<bool>,
env: Vec<(OsString, OsString)>, env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>, compiler: Option<PathBuf>,
archiver: Option<PathBuf>, archiver: Option<PathBuf>,
@ -209,8 +210,17 @@ impl ToolFamily {
} }
ToolFamily::Gnu | ToolFamily::Clang => { ToolFamily::Gnu | ToolFamily::Clang => {
cmd.push_cc_arg("-g".into()); cmd.push_cc_arg("-g".into());
}
}
}
/// What the flag to force frame pointers.
fn add_force_frame_pointer(&self, cmd: &mut Tool) {
match *self {
ToolFamily::Gnu | ToolFamily::Clang => {
cmd.push_cc_arg("-fno-omit-frame-pointer".into()); cmd.push_cc_arg("-fno-omit-frame-pointer".into());
} }
_ => (),
} }
} }
@ -286,6 +296,7 @@ impl Build {
out_dir: None, out_dir: None,
opt_level: None, opt_level: None,
debug: None, debug: None,
force_frame_pointer: None,
env: Vec::new(), env: Vec::new(),
compiler: None, compiler: None,
archiver: None, archiver: None,
@ -758,6 +769,17 @@ impl Build {
self self
} }
/// Configures whether the compiler will emit instructions to store
/// frame pointers during codegen.
///
/// This option is automatically enabled when debug information is emitted.
/// Otherwise the target platform compiler's default will be used.
/// You can use this option to force a specific setting.
pub fn force_frame_pointer(&mut self, force: bool) -> &mut Build {
self.force_frame_pointer = Some(force);
self
}
/// Configures the output directory where all object files and static /// Configures the output directory where all object files and static
/// libraries will be located. /// libraries will be located.
/// ///
@ -1348,6 +1370,11 @@ impl Build {
family.add_debug_flags(cmd); family.add_debug_flags(cmd);
} }
if self.get_force_frame_pointer() {
let family = cmd.family;
family.add_force_frame_pointer(cmd);
}
// Target flags // Target flags
match cmd.family { match cmd.family {
ToolFamily::Clang => { ToolFamily::Clang => {
@ -2227,6 +2254,10 @@ impl Build {
}) })
} }
fn get_force_frame_pointer(&self) -> bool {
self.force_frame_pointer.unwrap_or_else(|| self.get_debug())
}
fn get_out_dir(&self) -> Result<PathBuf, Error> { fn get_out_dir(&self) -> Result<PathBuf, Error> {
match self.out_dir.clone() { match self.out_dir.clone() {
Some(p) => Ok(p), Some(p) => Ok(p),

32
tests/test.rs

@ -39,10 +39,40 @@ fn gnu_opt_level_s() {
} }
#[test] #[test]
fn gnu_debug() { fn gnu_debug_fp_auto() {
let test = Test::gnu(); let test = Test::gnu();
test.gcc().debug(true).file("foo.c").compile("foo"); test.gcc().debug(true).file("foo.c").compile("foo");
test.cmd(0).must_have("-g"); test.cmd(0).must_have("-g");
test.cmd(0).must_have("-fno-omit-frame-pointer");
}
#[test]
fn gnu_debug_fp() {
let test = Test::gnu();
test.gcc().debug(true).file("foo.c").compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_have("-fno-omit-frame-pointer");
}
#[test]
fn gnu_debug_nofp() {
let test = Test::gnu();
test.gcc()
.debug(true)
.force_frame_pointer(false)
.file("foo.c")
.compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_not_have("-fno-omit-frame-pointer");
let test = Test::gnu();
test.gcc()
.force_frame_pointer(false)
.debug(true)
.file("foo.c")
.compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_not_have("-fno-omit-frame-pointer");
} }
#[test] #[test]

Loading…
Cancel
Save