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