@@ -24,6 +24,50 @@ function couldBeOutput(line: string) {
2424
2525const trace = false ;
2626
27+ class LogMessage {
28+ protected logMsgVar = "" ;
29+ protected logMsgVarProcess = "" ;
30+ protected logMsgRplNum = 0 ;
31+ protected logMsgRplItem : string [ ] = [ ] ;
32+ protected logMsgMatch = / ( ^ \$ [ 0 - 9 ] * [ \ ] * = [ \ ] * ) ( .* ) / ;
33+ protected logReplaceTest = / { ( [ ^ } ] * ) } / g;
34+ public logMsgBrkList : Breakpoint [ ] = [ ] ;
35+
36+ logMsgOutput ( record ) {
37+ if ( ( record . type === 'console' ) ) {
38+ if ( record . content . startsWith ( "$" ) ) {
39+ const content = record . content ;
40+ const variableMatch = this . logMsgMatch . exec ( content ) ;
41+ if ( variableMatch ) {
42+ const value = content . substr ( variableMatch [ 1 ] . length ) . trim ( ) ;
43+ this . logMsgRplItem . push ( value ) ;
44+ this . logMsgRplNum -- ;
45+ if ( this . logMsgRplNum == 0 ) {
46+ for ( let i = 0 ; i < this . logMsgRplItem . length ; i ++ ) {
47+ this . logMsgVarProcess = this . logMsgVarProcess . replace ( "placeHolderForVariable" , this . logMsgRplItem [ i ] ) ;
48+ }
49+ return "Log Message:" + this . logMsgVarProcess ;
50+ }
51+ }
52+ }
53+ return null
54+ }
55+ }
56+
57+ logMsgProcess ( parsed ) {
58+ this . logMsgBrkList . forEach ( ( brk ) => {
59+ if ( parsed . outOfBandRecord [ 0 ] . output [ 0 ] [ 1 ] == "breakpoint-hit" && parsed . outOfBandRecord [ 0 ] . output [ 2 ] [ 1 ] == brk . id ) {
60+ this . logMsgVar = brk ?. logMessage ;
61+ const matches = this . logMsgVar . match ( this . logReplaceTest ) ;
62+ const count = matches ? matches . length : 0 ;
63+ this . logMsgRplNum = count ;
64+ this . logMsgVarProcess = this . logMsgVar . replace ( this . logReplaceTest , "placeHolderForVariable" ) ;
65+ this . logMsgRplItem = [ ] ;
66+ }
67+ } ) ;
68+ }
69+ }
70+
2771export class MI2 extends EventEmitter implements IBackend {
2872 constructor ( public application : string , public preargs : string [ ] , public extraargs : string [ ] , procEnv : any , public extraCommands : string [ ] = [ ] ) {
2973 super ( ) ;
@@ -47,6 +91,7 @@ export class MI2 extends EventEmitter implements IBackend {
4791 this . procEnv = env ;
4892 }
4993 }
94+ protected logMessage :LogMessage = new LogMessage ;
5095
5196 load ( cwd : string , target : string , procArgs : string , separateConsole : string , autorun : string [ ] ) : Thenable < any > {
5297 if ( ! path . isAbsolute ( target ) )
@@ -354,6 +399,10 @@ export class MI2 extends EventEmitter implements IBackend {
354399 parsed . outOfBandRecord . forEach ( record => {
355400 if ( record . isStream ) {
356401 this . log ( record . type , record . content ) ;
402+ const logOutput = this . logMessage . logMsgOutput ( record ) ;
403+ if ( logOutput ) {
404+ this . log ( "console" , logOutput ) ;
405+ }
357406 } else {
358407 if ( record . type == "exec" ) {
359408 this . emit ( "exec-async-output" , parsed ) ;
@@ -373,6 +422,7 @@ export class MI2 extends EventEmitter implements IBackend {
373422 switch ( reason ) {
374423 case "breakpoint-hit" :
375424 this . emit ( "breakpoint" , parsed ) ;
425+ this . logMessage . logMsgProcess ( parsed ) ;
376426 break ;
377427 case "watchpoint-trigger" :
378428 case "read-watchpoint-trigger" :
@@ -576,6 +626,23 @@ export class MI2 extends EventEmitter implements IBackend {
576626 return this . sendCommand ( "break-condition " + bkptNum + " " + condition ) ;
577627 }
578628
629+ setLogPoint ( bkptNum , command ) : Thenable < any > {
630+ const regex = / { ( [ a - z 0 - 9 A - Z -_ \. \> \& \* \[ \] ] * ) } / gm;
631+ let m :RegExpExecArray ;
632+ let commands :string = "" ;
633+
634+ while ( ( m = regex . exec ( command ) ) ) {
635+ if ( m . index === regex . lastIndex ) {
636+ regex . lastIndex ++ ;
637+ }
638+ if ( m [ 1 ] ) {
639+ commands += `\"print ${ m [ 1 ] } \" ` ;
640+ }
641+ }
642+ commands += "\"continue\"" ;
643+ return this . sendCommand ( "break-commands " + bkptNum + " " + commands ) ;
644+ }
645+
579646 setEntryBreakPoint ( entryPoint : string ) : Thenable < any > {
580647 return this . sendCommand ( "break-insert -t -f " + entryPoint ) ;
581648 }
@@ -607,15 +674,29 @@ export class MI2 extends EventEmitter implements IBackend {
607674 if ( result . resultRecords . resultClass == "done" ) {
608675 const bkptNum = parseInt ( result . result ( "bkpt.number" ) ) ;
609676 const newBrk = {
677+ id : bkptNum ,
610678 file : breakpoint . file ? breakpoint . file : result . result ( "bkpt.file" ) ,
611679 raw : breakpoint . raw ,
612680 line : parseInt ( result . result ( "bkpt.line" ) ) ,
613- condition : breakpoint . condition
681+ condition : breakpoint . condition ,
682+ logMessage : breakpoint ?. logMessage ,
614683 } ;
615684 if ( breakpoint . condition ) {
616685 this . setBreakPointCondition ( bkptNum , breakpoint . condition ) . then ( ( result ) => {
617686 if ( result . resultRecords . resultClass == "done" ) {
618687 this . breakpoints . set ( newBrk , bkptNum ) ;
688+ resolve ( [ true , newBrk ] ) ;
689+ } else {
690+ resolve ( [ false , undefined ] ) ;
691+ }
692+ } , reject ) ;
693+ } else if ( breakpoint . logMessage ) {
694+ this . setLogPoint ( bkptNum , breakpoint . logMessage ) . then ( ( result ) => {
695+ if ( result . resultRecords . resultClass == "done" ) {
696+ breakpoint . id = newBrk . id ;
697+ this . breakpoints . set ( newBrk , bkptNum ) ;
698+ this . logMessage . logMsgBrkList . push ( breakpoint ) ;
699+
619700 resolve ( [ true , newBrk ] ) ;
620701 } else {
621702 resolve ( [ false , undefined ] ) ;
0 commit comments