@@ -20,6 +20,7 @@ use util::logv;
2020#[ cfg( stage0, target_os = "win32" ) ] // NOTE: Remove after snapshot
2121use util;
2222
23+ use std:: from_str:: FromStr ;
2324use std:: io:: File ;
2425use std:: io:: fs;
2526use std:: io:: net:: tcp;
@@ -317,6 +318,7 @@ actual:\n\
317318}
318319
319320fn run_debuginfo_gdb_test ( config : & Config , props : & TestProps , testfile : & Path ) {
321+
320322 let mut config = Config {
321323 target_rustcflags : cleanup_debug_info_options ( & config. target_rustcflags ) ,
322324 host_rustcflags : cleanup_debug_info_options ( & config. host_rustcflags ) ,
@@ -467,11 +469,38 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
467469 . unwrap ( )
468470 . to_string ( ) ;
469471 // write debugger script
470- let script_str = [
471- "set charset UTF-8" . to_string ( ) ,
472- cmds,
473- "quit\n " . to_string ( )
474- ] . connect ( "\n " ) ;
472+ let mut script_str = String :: with_capacity ( 2048 ) ;
473+
474+ script_str. push_str ( "set charset UTF-8\n " ) ;
475+ script_str. push_str ( "show version\n " ) ;
476+
477+ match config. gdb_version {
478+ Some ( ref version) => {
479+ if gdb_version_to_int ( version. as_slice ( ) ) > gdb_version_to_int ( "7.3" ) {
480+ // Add the directory containing the pretty printers to
481+ // GDB's script auto loading safe path ...
482+ script_str. push_str (
483+ format ! ( "add-auto-load-safe-path {}\n " ,
484+ rust_pp_module_abs_path. as_slice( ) )
485+ . as_slice ( ) ) ;
486+ // ... and also the test directory
487+ script_str. push_str (
488+ format ! ( "add-auto-load-safe-path {}\n " ,
489+ config. build_base. as_str( ) . unwrap( ) )
490+ . as_slice ( ) ) ;
491+ }
492+ }
493+ _ => { /* nothing to do */ }
494+ }
495+
496+ // Load the target executable
497+ script_str. push_str ( format ! ( "file {}\n " ,
498+ exe_file. as_str( ) . unwrap( ) )
499+ . as_slice ( ) ) ;
500+
501+ script_str. push_str ( cmds. as_slice ( ) ) ;
502+ script_str. push_str ( "quit\n " ) ;
503+
475504 debug ! ( "script_str = {}" , script_str) ;
476505 dump_output_file ( config,
477506 testfile,
@@ -501,15 +530,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
501530 vec ! ( "-quiet" . to_string( ) ,
502531 "-batch" . to_string( ) ,
503532 "-nx" . to_string( ) ,
504- // Add the directory containing the pretty printers to
505- // GDB's script auto loading safe path ...
506- format!( "-iex=add-auto-load-safe-path {}" ,
507- rust_pp_module_abs_path. as_slice( ) ) ,
508- // ... and also the test directory
509- format!( "-iex=add-auto-load-safe-path {}" ,
510- config. build_base. as_str( ) . unwrap( ) ) ,
511- format!( "-command={}" , debugger_script. as_str( ) . unwrap( ) ) ,
512- exe_file. as_str( ) . unwrap( ) . to_string( ) ) ;
533+ format!( "-command={}" , debugger_script. as_str( ) . unwrap( ) ) ) ;
513534
514535 let proc_args = ProcArgs {
515536 prog : debugger ( ) ,
@@ -546,6 +567,23 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
546567
547568 File :: create ( & script_path) . write ( script_content) . unwrap ( ) ;
548569 }
570+
571+ fn gdb_version_to_int ( version_string : & str ) -> int {
572+ let error_string = format ! (
573+ "Encountered GDB version string with unexpected format: {}" ,
574+ version_string) ;
575+
576+ let components: Vec < & str > = version_string. trim ( ) . split ( '.' ) . collect ( ) ;
577+
578+ if components. len ( ) != 2 {
579+ fatal ( error_string. as_slice ( ) ) ;
580+ }
581+
582+ let major: int = FromStr :: from_str ( components[ 0 ] ) . expect ( error_string. as_slice ( ) ) ;
583+ let minor: int = FromStr :: from_str ( components[ 1 ] ) . expect ( error_string. as_slice ( ) ) ;
584+
585+ return major * 1000 + minor;
586+ }
549587}
550588
551589fn find_rust_src_root ( config : & Config ) -> Option < Path > {
0 commit comments