@@ -20,6 +20,7 @@ use util::logv;
20
20
#[ cfg( stage0, target_os = "win32" ) ] // NOTE: Remove after snapshot
21
21
use util;
22
22
23
+ use std:: from_str:: FromStr ;
23
24
use std:: io:: File ;
24
25
use std:: io:: fs;
25
26
use std:: io:: net:: tcp;
@@ -317,6 +318,7 @@ actual:\n\
317
318
}
318
319
319
320
fn run_debuginfo_gdb_test ( config : & Config , props : & TestProps , testfile : & Path ) {
321
+
320
322
let mut config = Config {
321
323
target_rustcflags : cleanup_debug_info_options ( & config. target_rustcflags ) ,
322
324
host_rustcflags : cleanup_debug_info_options ( & config. host_rustcflags ) ,
@@ -467,11 +469,38 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
467
469
. unwrap ( )
468
470
. to_string ( ) ;
469
471
// 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
+
475
504
debug ! ( "script_str = {}" , script_str) ;
476
505
dump_output_file ( config,
477
506
testfile,
@@ -501,15 +530,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
501
530
vec ! ( "-quiet" . to_string( ) ,
502
531
"-batch" . to_string( ) ,
503
532
"-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( ) ) ) ;
513
534
514
535
let proc_args = ProcArgs {
515
536
prog : debugger ( ) ,
@@ -546,6 +567,23 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
546
567
547
568
File :: create ( & script_path) . write ( script_content) . unwrap ( ) ;
548
569
}
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
+ }
549
587
}
550
588
551
589
fn find_rust_src_root ( config : & Config ) -> Option < Path > {
0 commit comments