@@ -324,7 +324,12 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
324
324
} ;
325
325
326
326
let config = & mut config;
327
- let DebuggerCommands { commands, check_lines, .. } = parse_debugger_commands ( testfile, "gdb" ) ;
327
+ let DebuggerCommands {
328
+ commands,
329
+ check_lines,
330
+ use_gdb_pretty_printer,
331
+ ..
332
+ } = parse_debugger_commands ( testfile, "gdb" ) ;
328
333
let mut cmds = commands. connect ( "\n " ) ;
329
334
330
335
// compile test file (it should have 'compile-flags:-g' in the header)
@@ -335,7 +340,6 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
335
340
336
341
let exe_file = make_exe_name ( config, testfile) ;
337
342
338
- let mut proc_args;
339
343
let debugger_run_result;
340
344
match config. target . as_slice ( ) {
341
345
"arm-linux-androideabi" => {
@@ -455,6 +459,12 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
455
459
}
456
460
457
461
_=> {
462
+ let rust_src_root = find_rust_src_root ( config) . expect ( "Could not find Rust source root" ) ;
463
+ let rust_pp_module_rel_path = Path :: new ( "./src/etc" ) ;
464
+ let rust_pp_module_abs_path = rust_src_root. join ( rust_pp_module_rel_path)
465
+ . as_str ( )
466
+ . unwrap ( )
467
+ . to_string ( ) ;
458
468
// write debugger script
459
469
let script_str = [
460
470
"set charset UTF-8" . to_string ( ) ,
@@ -467,6 +477,12 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
467
477
script_str. as_slice ( ) ,
468
478
"debugger.script" ) ;
469
479
480
+ if use_gdb_pretty_printer {
481
+ // Only emit the gdb auto-loading script if pretty printers
482
+ // should actually be loaded
483
+ dump_gdb_autoload_script ( config, testfile) ;
484
+ }
485
+
470
486
// run debugger script with gdb
471
487
#[ cfg( windows) ]
472
488
fn debugger ( ) -> String {
@@ -484,16 +500,27 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
484
500
vec ! ( "-quiet" . to_string( ) ,
485
501
"-batch" . to_string( ) ,
486
502
"-nx" . to_string( ) ,
503
+ // Add the directory containing the pretty printers to
504
+ // GDB's script auto loading safe path ...
505
+ format!( "-iex=add-auto-load-safe-path {}" ,
506
+ rust_pp_module_abs_path. as_slice( ) ) ,
507
+ // ... and also the test directory
508
+ format!( "-iex=add-auto-load-safe-path {}" ,
509
+ config. build_base. as_str( ) . unwrap( ) ) ,
487
510
format!( "-command={}" , debugger_script. as_str( ) . unwrap( ) ) ,
488
511
exe_file. as_str( ) . unwrap( ) . to_string( ) ) ;
489
- proc_args = ProcArgs {
512
+
513
+ let proc_args = ProcArgs {
490
514
prog : debugger ( ) ,
491
515
args : debugger_opts,
492
516
} ;
517
+
518
+ let environment = vec ! [ ( "PYTHONPATH" . to_string( ) , rust_pp_module_abs_path) ] ;
519
+
493
520
debugger_run_result = compose_and_run ( config,
494
521
testfile,
495
522
proc_args,
496
- Vec :: new ( ) ,
523
+ environment ,
497
524
config. run_lib_path . as_slice ( ) ,
498
525
None ,
499
526
None ) ;
@@ -505,6 +532,32 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
505
532
}
506
533
507
534
check_debugger_output ( & debugger_run_result, check_lines. as_slice ( ) ) ;
535
+
536
+ fn dump_gdb_autoload_script ( config : & Config , testfile : & Path ) {
537
+ let mut script_path = output_base_name ( config, testfile) ;
538
+ let mut script_file_name = script_path. filename ( ) . unwrap ( ) . to_vec ( ) ;
539
+ script_file_name. push_all ( "-gdb.py" . as_bytes ( ) ) ;
540
+ script_path. set_filename ( script_file_name. as_slice ( ) ) ;
541
+
542
+ let script_content = "import gdb_rust_pretty_printing\n \
543
+ gdb_rust_pretty_printing.register_printers(gdb.current_objfile())\n "
544
+ . as_bytes ( ) ;
545
+
546
+ File :: create ( & script_path) . write ( script_content) . unwrap ( ) ;
547
+ }
548
+ }
549
+
550
+ fn find_rust_src_root ( config : & Config ) -> Option < Path > {
551
+ let mut path = config. src_base . clone ( ) ;
552
+ let path_postfix = Path :: new ( "src/etc/lldb_batchmode.py" ) ;
553
+
554
+ while path. pop ( ) {
555
+ if path. join ( path_postfix. clone ( ) ) . is_file ( ) {
556
+ return Some ( path) ;
557
+ }
558
+ }
559
+
560
+ return None ;
508
561
}
509
562
510
563
fn run_debuginfo_lldb_test ( config : & Config , props : & TestProps , testfile : & Path ) {
@@ -534,7 +587,8 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
534
587
let DebuggerCommands {
535
588
commands,
536
589
check_lines,
537
- breakpoint_lines
590
+ breakpoint_lines,
591
+ ..
538
592
} = parse_debugger_commands ( testfile, "lldb" ) ;
539
593
540
594
// Write debugger script:
@@ -620,6 +674,7 @@ struct DebuggerCommands {
620
674
commands : Vec < String > ,
621
675
check_lines : Vec < String > ,
622
676
breakpoint_lines : Vec < uint > ,
677
+ use_gdb_pretty_printer : bool
623
678
}
624
679
625
680
fn parse_debugger_commands ( file_path : & Path , debugger_prefix : & str )
@@ -632,6 +687,7 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
632
687
let mut breakpoint_lines = vec ! ( ) ;
633
688
let mut commands = vec ! ( ) ;
634
689
let mut check_lines = vec ! ( ) ;
690
+ let mut use_gdb_pretty_printer = false ;
635
691
let mut counter = 1 ;
636
692
let mut reader = BufferedReader :: new ( File :: open ( file_path) . unwrap ( ) ) ;
637
693
for line in reader. lines ( ) {
@@ -641,6 +697,10 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
641
697
breakpoint_lines. push ( counter) ;
642
698
}
643
699
700
+ if line. as_slice ( ) . contains ( "gdb-use-pretty-printer" ) {
701
+ use_gdb_pretty_printer = true ;
702
+ }
703
+
644
704
header:: parse_name_value_directive (
645
705
line. as_slice ( ) ,
646
706
command_directive. as_slice ( ) ) . map ( |cmd| {
@@ -664,7 +724,8 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
664
724
DebuggerCommands {
665
725
commands : commands,
666
726
check_lines : check_lines,
667
- breakpoint_lines : breakpoint_lines
727
+ breakpoint_lines : breakpoint_lines,
728
+ use_gdb_pretty_printer : use_gdb_pretty_printer,
668
729
}
669
730
}
670
731
0 commit comments