@@ -19,6 +19,7 @@ use util::logv;
19
19
#[ cfg( target_os = "win32" ) ]
20
20
use util;
21
21
22
+ use std:: from_str:: FromStr ;
22
23
use std:: io:: File ;
23
24
use std:: io:: fs;
24
25
use std:: io:: net:: tcp;
@@ -315,6 +316,7 @@ actual:\n\
315
316
}
316
317
317
318
fn run_debuginfo_gdb_test ( config : & Config , props : & TestProps , testfile : & Path ) {
319
+
318
320
let mut config = Config {
319
321
target_rustcflags : cleanup_debug_info_options ( & config. target_rustcflags ) ,
320
322
host_rustcflags : cleanup_debug_info_options ( & config. host_rustcflags ) ,
@@ -465,11 +467,38 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
465
467
. unwrap ( )
466
468
. to_string ( ) ;
467
469
// write debugger script
468
- let script_str = [
469
- "set charset UTF-8" . to_string ( ) ,
470
- cmds,
471
- "quit\n " . to_string ( )
472
- ] . connect ( "\n " ) ;
470
+ let mut script_str = String :: with_capacity ( 2048 ) ;
471
+
472
+ script_str. push_str ( "set charset UTF-8\n " ) ;
473
+ script_str. push_str ( "show version\n " ) ;
474
+
475
+ match config. gdb_version {
476
+ Some ( ref version) => {
477
+ if gdb_version_to_int ( version. as_slice ( ) ) > gdb_version_to_int ( "7.3" ) {
478
+ // Add the directory containing the pretty printers to
479
+ // GDB's script auto loading safe path ...
480
+ script_str. push_str (
481
+ format ! ( "add-auto-load-safe-path {}\n " ,
482
+ rust_pp_module_abs_path. as_slice( ) )
483
+ . as_slice ( ) ) ;
484
+ // ... and also the test directory
485
+ script_str. push_str (
486
+ format ! ( "add-auto-load-safe-path {}\n " ,
487
+ config. build_base. as_str( ) . unwrap( ) )
488
+ . as_slice ( ) ) ;
489
+ }
490
+ }
491
+ _ => { /* nothing to do */ }
492
+ }
493
+
494
+ // Load the target executable
495
+ script_str. push_str ( format ! ( "file {}\n " ,
496
+ exe_file. as_str( ) . unwrap( ) )
497
+ . as_slice ( ) ) ;
498
+
499
+ script_str. push_str ( cmds. as_slice ( ) ) ;
500
+ script_str. push_str ( "quit\n " ) ;
501
+
473
502
debug ! ( "script_str = {}" , script_str) ;
474
503
dump_output_file ( config,
475
504
testfile,
@@ -499,15 +528,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
499
528
vec ! ( "-quiet" . to_string( ) ,
500
529
"-batch" . to_string( ) ,
501
530
"-nx" . to_string( ) ,
502
- // Add the directory containing the pretty printers to
503
- // GDB's script auto loading safe path ...
504
- format!( "-iex=add-auto-load-safe-path {}" ,
505
- rust_pp_module_abs_path. as_slice( ) ) ,
506
- // ... and also the test directory
507
- format!( "-iex=add-auto-load-safe-path {}" ,
508
- config. build_base. as_str( ) . unwrap( ) ) ,
509
- format!( "-command={}" , debugger_script. as_str( ) . unwrap( ) ) ,
510
- exe_file. as_str( ) . unwrap( ) . to_string( ) ) ;
531
+ format!( "-command={}" , debugger_script. as_str( ) . unwrap( ) ) ) ;
511
532
512
533
let proc_args = ProcArgs {
513
534
prog : debugger ( ) ,
@@ -544,6 +565,23 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
544
565
545
566
File :: create ( & script_path) . write ( script_content) . unwrap ( ) ;
546
567
}
568
+
569
+ fn gdb_version_to_int ( version_string : & str ) -> int {
570
+ let error_string = format ! (
571
+ "Encountered GDB version string with unexpected format: {}" ,
572
+ version_string) ;
573
+
574
+ let components: Vec < & str > = version_string. trim ( ) . split ( '.' ) . collect ( ) ;
575
+
576
+ if components. len ( ) != 2 {
577
+ fatal ( error_string. as_slice ( ) ) ;
578
+ }
579
+
580
+ let major: int = FromStr :: from_str ( components[ 0 ] ) . expect ( error_string. as_slice ( ) ) ;
581
+ let minor: int = FromStr :: from_str ( components[ 1 ] ) . expect ( error_string. as_slice ( ) ) ;
582
+
583
+ return major * 1000 + minor;
584
+ }
547
585
}
548
586
549
587
fn find_rust_src_root ( config : & Config ) -> Option < Path > {
0 commit comments