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