@@ -27,7 +27,7 @@ use std::fs::{self, File, create_dir_all};
27
27
use std:: io:: prelude:: * ;
28
28
use std:: io:: { self , BufReader } ;
29
29
use std:: path:: { Path , PathBuf } ;
30
- use std:: process:: { Command , Output , ExitStatus } ;
30
+ use std:: process:: { Command , Output , ExitStatus , Stdio } ;
31
31
use std:: str;
32
32
use std:: collections:: HashMap ;
33
33
@@ -500,32 +500,19 @@ actual:\n\
500
500
debug ! ( "script_str = {}" , script_str) ;
501
501
self . dump_output_file ( & script_str, "debugger.script" ) ;
502
502
503
+ let adb_path = & self . config . adb_path ;
503
504
504
- procsrv:: run ( "" ,
505
- & self . config . adb_path ,
506
- None ,
507
- & [
508
- "push" . to_owned ( ) ,
509
- exe_file. to_str ( ) . unwrap ( ) . to_owned ( ) ,
510
- self . config . adb_test_dir . clone ( )
511
- ] ,
512
- Vec :: new ( ) ,
513
- None ,
514
- None )
515
- . expect ( & format ! ( "failed to exec `{:?}`" , self . config. adb_path) ) ;
516
-
517
- procsrv:: run ( "" ,
518
- & self . config . adb_path ,
519
- None ,
520
- & [
521
- "forward" . to_owned ( ) ,
522
- "tcp:5039" . to_owned ( ) ,
523
- "tcp:5039" . to_owned ( )
524
- ] ,
525
- Vec :: new ( ) ,
526
- None ,
527
- None )
528
- . expect ( & format ! ( "failed to exec `{:?}`" , self . config. adb_path) ) ;
505
+ Command :: new ( adb_path)
506
+ . arg ( "push" )
507
+ . arg ( & exe_file)
508
+ . arg ( & self . config . adb_test_dir )
509
+ . status ( )
510
+ . expect ( & format ! ( "failed to exec `{:?}`" , adb_path) ) ;
511
+
512
+ Command :: new ( adb_path)
513
+ . args ( & [ "forward" , "tcp:5039" , "tcp:5039" ] )
514
+ . status ( )
515
+ . expect ( & format ! ( "failed to exec `{:?}`" , adb_path) ) ;
529
516
530
517
let adb_arg = format ! ( "export LD_LIBRARY_PATH={}; \
531
518
gdbserver{} :5039 {}/{}",
@@ -537,23 +524,15 @@ actual:\n\
537
524
. unwrap( ) ) ;
538
525
539
526
debug ! ( "adb arg: {}" , adb_arg) ;
540
- let mut process = procsrv:: run_background ( "" ,
541
- & self . config . adb_path
542
- ,
543
- None ,
544
- & [
545
- "shell" . to_owned ( ) ,
546
- adb_arg. clone ( )
547
- ] ,
548
- Vec :: new ( ) ,
549
- None ,
550
- None )
551
- . expect ( & format ! ( "failed to exec `{:?}`" , self . config. adb_path) ) ;
527
+ let mut adb = Command :: new ( adb_path)
528
+ . args ( & [ "shell" , & adb_arg] )
529
+ . spawn ( )
530
+ . expect ( & format ! ( "failed to exec `{:?}`" , adb_path) ) ;
552
531
553
532
// Wait for the gdbserver to print out "Listening on port ..."
554
533
// at which point we know that it's started and then we can
555
534
// execute the debugger below.
556
- let mut stdout = BufReader :: new ( process . stdout . take ( ) . unwrap ( ) ) ;
535
+ let mut stdout = BufReader :: new ( adb . stdout . take ( ) . unwrap ( ) ) ;
557
536
let mut line = String :: new ( ) ;
558
537
loop {
559
538
line. truncate ( 0 ) ;
@@ -574,17 +553,13 @@ actual:\n\
574
553
575
554
let mut gdb_path = tool_path;
576
555
gdb_path. push_str ( "/bin/gdb" ) ;
577
- let procsrv:: Result {
578
- out,
579
- err,
580
- status
581
- } = procsrv:: run ( "" ,
582
- & gdb_path,
583
- None ,
584
- & debugger_opts,
585
- Vec :: new ( ) ,
586
- None ,
587
- None )
556
+ let Output {
557
+ status,
558
+ stdout,
559
+ stderr
560
+ } = Command :: new ( & gdb_path)
561
+ . args ( & debugger_opts)
562
+ . output ( )
588
563
. expect ( & format ! ( "failed to exec `{:?}`" , gdb_path) ) ;
589
564
let cmdline = {
590
565
let cmdline = self . make_cmdline ( "" ,
@@ -596,11 +571,11 @@ actual:\n\
596
571
597
572
debugger_run_result = ProcRes {
598
573
status,
599
- stdout : out ,
600
- stderr : err ,
574
+ stdout : String :: from_utf8 ( stdout ) . unwrap ( ) ,
575
+ stderr : String :: from_utf8 ( stderr ) . unwrap ( ) ,
601
576
cmdline,
602
577
} ;
603
- if process . kill ( ) . is_err ( ) {
578
+ if adb . kill ( ) . is_err ( ) {
604
579
println ! ( "Adb process is already finished." ) ;
605
580
}
606
581
}
@@ -1367,7 +1342,46 @@ actual:\n\
1367
1342
aux_path : Option < & str > ,
1368
1343
input : Option < String > ,
1369
1344
working_dir : Option < String > ) -> ProcRes {
1370
- self . program_output ( lib_path, prog, aux_path, args, procenv, input, working_dir)
1345
+ let cmdline =
1346
+ {
1347
+ let cmdline = self . make_cmdline ( lib_path,
1348
+ & prog,
1349
+ & args) ;
1350
+ logv ( self . config , format ! ( "executing {}" , cmdline) ) ;
1351
+ cmdline
1352
+ } ;
1353
+
1354
+ let mut process = Command :: new ( & prog) ;
1355
+ process
1356
+ . args ( & args)
1357
+ . stdout ( Stdio :: piped ( ) )
1358
+ . stderr ( Stdio :: piped ( ) )
1359
+ . stdin ( Stdio :: piped ( ) ) ;
1360
+
1361
+ procsrv:: add_target_env ( & mut process, lib_path, aux_path) ;
1362
+ for ( key, val) in procenv {
1363
+ process. env ( & key, & val) ;
1364
+ }
1365
+ if let Some ( cwd) = working_dir {
1366
+ process. current_dir ( cwd) ;
1367
+ }
1368
+
1369
+ let mut child = process. spawn ( ) . expect ( & format ! ( "failed to exec `{}`" , prog) ) ;
1370
+ if let Some ( input) = input {
1371
+ child. stdin . as_mut ( ) . unwrap ( ) . write_all ( input. as_bytes ( ) ) . unwrap ( ) ;
1372
+ }
1373
+ let Output { status, stdout, stderr } = child. wait_with_output ( ) . unwrap ( ) ;
1374
+
1375
+ let result = ProcRes {
1376
+ status,
1377
+ stdout : String :: from_utf8 ( stdout) . unwrap ( ) ,
1378
+ stderr : String :: from_utf8 ( stderr) . unwrap ( ) ,
1379
+ cmdline,
1380
+ } ;
1381
+
1382
+ self . dump_output ( & result. stdout , & result. stderr ) ;
1383
+
1384
+ result
1371
1385
}
1372
1386
1373
1387
fn make_compile_args ( & self ,
@@ -1554,44 +1568,6 @@ actual:\n\
1554
1568
}
1555
1569
}
1556
1570
1557
- fn program_output ( & self ,
1558
- lib_path : & str ,
1559
- prog : String ,
1560
- aux_path : Option < & str > ,
1561
- args : Vec < String > ,
1562
- env : Vec < ( String , String ) > ,
1563
- input : Option < String > ,
1564
- working_dir : Option < String > )
1565
- -> ProcRes {
1566
- let cmdline =
1567
- {
1568
- let cmdline = self . make_cmdline ( lib_path,
1569
- & prog,
1570
- & args) ;
1571
- logv ( self . config , format ! ( "executing {}" , cmdline) ) ;
1572
- cmdline
1573
- } ;
1574
-
1575
- let procsrv:: Result {
1576
- out,
1577
- err,
1578
- status
1579
- } = procsrv:: run ( lib_path,
1580
- & prog,
1581
- aux_path,
1582
- & args,
1583
- env,
1584
- input,
1585
- working_dir) . expect ( & format ! ( "failed to exec `{}`" , prog) ) ;
1586
- self . dump_output ( & out, & err) ;
1587
- ProcRes {
1588
- status,
1589
- stdout : out,
1590
- stderr : err,
1591
- cmdline,
1592
- }
1593
- }
1594
-
1595
1571
fn make_cmdline ( & self , libpath : & str , prog : & str , args : & [ String ] ) -> String {
1596
1572
use util;
1597
1573
0 commit comments