Skip to content

Commit 02ed9e6

Browse files
ratmicealexcrichton
authored andcommitted
add mechanism for forcing frame pointer.
1 parent 0ed1d0a commit 02ed9e6

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/lib.rs

+31
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub struct Build {
105105
out_dir: Option<PathBuf>,
106106
opt_level: Option<String>,
107107
debug: Option<bool>,
108+
force_frame_pointer: Option<bool>,
108109
env: Vec<(OsString, OsString)>,
109110
compiler: Option<PathBuf>,
110111
archiver: Option<PathBuf>,
@@ -209,8 +210,17 @@ impl ToolFamily {
209210
}
210211
ToolFamily::Gnu | ToolFamily::Clang => {
211212
cmd.push_cc_arg("-g".into());
213+
}
214+
}
215+
}
216+
217+
/// What the flag to force frame pointers.
218+
fn add_force_frame_pointer(&self, cmd: &mut Tool) {
219+
match *self {
220+
ToolFamily::Gnu | ToolFamily::Clang => {
212221
cmd.push_cc_arg("-fno-omit-frame-pointer".into());
213222
}
223+
_ => (),
214224
}
215225
}
216226

@@ -286,6 +296,7 @@ impl Build {
286296
out_dir: None,
287297
opt_level: None,
288298
debug: None,
299+
force_frame_pointer: None,
289300
env: Vec::new(),
290301
compiler: None,
291302
archiver: None,
@@ -758,6 +769,17 @@ impl Build {
758769
self
759770
}
760771

772+
/// Configures whether the compiler will emit instructions to store
773+
/// frame pointers during codegen.
774+
///
775+
/// This option is automatically enabled when debug information is emitted.
776+
/// Otherwise the target platform compiler's default will be used.
777+
/// You can use this option to force a specific setting.
778+
pub fn force_frame_pointer(&mut self, force: bool) -> &mut Build {
779+
self.force_frame_pointer = Some(force);
780+
self
781+
}
782+
761783
/// Configures the output directory where all object files and static
762784
/// libraries will be located.
763785
///
@@ -1348,6 +1370,11 @@ impl Build {
13481370
family.add_debug_flags(cmd);
13491371
}
13501372

1373+
if self.get_force_frame_pointer() {
1374+
let family = cmd.family;
1375+
family.add_force_frame_pointer(cmd);
1376+
}
1377+
13511378
// Target flags
13521379
match cmd.family {
13531380
ToolFamily::Clang => {
@@ -2227,6 +2254,10 @@ impl Build {
22272254
})
22282255
}
22292256

2257+
fn get_force_frame_pointer(&self) -> bool {
2258+
self.force_frame_pointer.unwrap_or_else(|| self.get_debug())
2259+
}
2260+
22302261
fn get_out_dir(&self) -> Result<PathBuf, Error> {
22312262
match self.out_dir.clone() {
22322263
Some(p) => Ok(p),

tests/test.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,40 @@ fn gnu_opt_level_s() {
3939
}
4040

4141
#[test]
42-
fn gnu_debug() {
42+
fn gnu_debug_fp_auto() {
4343
let test = Test::gnu();
4444
test.gcc().debug(true).file("foo.c").compile("foo");
4545
test.cmd(0).must_have("-g");
46+
test.cmd(0).must_have("-fno-omit-frame-pointer");
47+
}
48+
49+
#[test]
50+
fn gnu_debug_fp() {
51+
let test = Test::gnu();
52+
test.gcc().debug(true).file("foo.c").compile("foo");
53+
test.cmd(0).must_have("-g");
54+
test.cmd(0).must_have("-fno-omit-frame-pointer");
55+
}
56+
57+
#[test]
58+
fn gnu_debug_nofp() {
59+
let test = Test::gnu();
60+
test.gcc()
61+
.debug(true)
62+
.force_frame_pointer(false)
63+
.file("foo.c")
64+
.compile("foo");
65+
test.cmd(0).must_have("-g");
66+
test.cmd(0).must_not_have("-fno-omit-frame-pointer");
67+
68+
let test = Test::gnu();
69+
test.gcc()
70+
.force_frame_pointer(false)
71+
.debug(true)
72+
.file("foo.c")
73+
.compile("foo");
74+
test.cmd(0).must_have("-g");
75+
test.cmd(0).must_not_have("-fno-omit-frame-pointer");
4676
}
4777

4878
#[test]

0 commit comments

Comments
 (0)