@@ -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) ,
0 commit comments