@@ -72,7 +72,7 @@ export class MI2 extends EventEmitter implements IBackend {
7272 } ) ;
7373 }
7474
75- ssh ( args : SSHArguments , cwd : string , target : string , procArgs : string , separateConsole : string ) : Thenable < any > {
75+ ssh ( args : SSHArguments , cwd : string , target : string , procArgs : string , separateConsole : string , attach : boolean ) : Thenable < any > {
7676 return new Promise ( ( resolve , reject ) => {
7777 this . isSSH = true ;
7878 this . sshReady = false ;
@@ -125,6 +125,8 @@ export class MI2 extends EventEmitter implements IBackend {
125125 }
126126 let sshCMD = this . application + " " + this . preargs . join ( " " ) ;
127127 if ( args . bootstrap ) sshCMD = args . bootstrap + " && " + sshCMD ;
128+ if ( attach )
129+ sshCMD += " -p " + target ;
128130 this . sshConn . exec ( sshCMD , execArgs , ( err , stream ) => {
129131 if ( err ) {
130132 this . log ( "stderr" , "Could not run " + this . application + " over ssh!" ) ;
@@ -141,9 +143,9 @@ export class MI2 extends EventEmitter implements IBackend {
141143 this . emit ( "quit" ) ;
142144 this . sshConn . end ( ) ;
143145 } ) . bind ( this ) ) ;
144- let promises = this . initCommands ( target , cwd , true ) ;
146+ let promises = this . initCommands ( target , cwd , true , attach ) ;
145147 promises . push ( this . sendCommand ( "environment-cd \"" + escape ( cwd ) + "\"" ) ) ;
146- if ( procArgs && procArgs . length )
148+ if ( procArgs && procArgs . length && ! attach )
147149 promises . push ( this . sendCommand ( "exec-arguments " + procArgs ) ) ;
148150 Promise . all ( promises ) . then ( ( ) => {
149151 this . emit ( "debug-ready" )
@@ -159,7 +161,7 @@ export class MI2 extends EventEmitter implements IBackend {
159161 } ) ;
160162 }
161163
162- protected initCommands ( target : string , cwd : string , ssh : boolean = false ) {
164+ protected initCommands ( target : string , cwd : string , ssh : boolean = false , attach : boolean = false ) {
163165 if ( ssh ) {
164166 if ( ! path . isAbsolute ( target ) )
165167 target = path . join ( cwd , target ) ;
@@ -168,11 +170,13 @@ export class MI2 extends EventEmitter implements IBackend {
168170 if ( ! nativePath . isAbsolute ( target ) )
169171 target = nativePath . join ( cwd , target ) ;
170172 }
171- return [
172- this . sendCommand ( "gdb-set target-async on" ) ,
173- this . sendCommand ( "environment-directory \"" + escape ( cwd ) + "\"" ) ,
174- this . sendCommand ( "file-exec-and-symbols \"" + escape ( target ) + "\"" )
173+ var cmds = [
174+ this . sendCommand ( "gdb-set target-async on" , true ) ,
175+ this . sendCommand ( "environment-directory \"" + escape ( cwd ) + "\"" , true )
175176 ] ;
177+ if ( ! attach )
178+ cmds . push ( this . sendCommand ( "file-exec-and-symbols \"" + escape ( target ) + "\"" ) ) ;
179+ return cmds ;
176180 }
177181
178182 attach ( cwd : string , executable : string , target : string ) : Thenable < any > {
@@ -651,12 +655,18 @@ export class MI2 extends EventEmitter implements IBackend {
651655 this . process . stdin . write ( raw + "\n" ) ;
652656 }
653657
654- sendCommand ( command : string ) : Thenable < MINode > {
658+ sendCommand ( command : string , suppressFailure : boolean = false ) : Thenable < MINode > {
655659 let sel = this . currentToken ++ ;
656660 return new Promise ( ( resolve , reject ) => {
657661 this . handlers [ sel ] = ( node : MINode ) => {
658- if ( node && node . resultRecords && node . resultRecords . resultClass === "error" )
659- reject ( node . result ( "msg" ) || "Internal error" ) ;
662+ if ( node && node . resultRecords && node . resultRecords . resultClass === "error" ) {
663+ if ( suppressFailure ) {
664+ this . log ( "stderr" , "WARNING: Error executing command '" + command + "'" ) ;
665+ resolve ( node ) ;
666+ }
667+ else
668+ reject ( ( node . result ( "msg" ) || "Internal error" ) + " (from " + command + ")" ) ;
669+ }
660670 else
661671 resolve ( node ) ;
662672 } ;
0 commit comments