@@ -24,6 +24,50 @@ function couldBeOutput(line: string) {
24
24
25
25
const trace = false ;
26
26
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
+
27
71
export class MI2 extends EventEmitter implements IBackend {
28
72
constructor ( public application : string , public preargs : string [ ] , public extraargs : string [ ] , procEnv : any , public extraCommands : string [ ] = [ ] ) {
29
73
super ( ) ;
@@ -47,6 +91,7 @@ export class MI2 extends EventEmitter implements IBackend {
47
91
this . procEnv = env ;
48
92
}
49
93
}
94
+ protected logMessage :LogMessage = new LogMessage ;
50
95
51
96
load ( cwd : string , target : string , procArgs : string , separateConsole : string , autorun : string [ ] ) : Thenable < any > {
52
97
if ( ! path . isAbsolute ( target ) )
@@ -354,6 +399,10 @@ export class MI2 extends EventEmitter implements IBackend {
354
399
parsed . outOfBandRecord . forEach ( record => {
355
400
if ( record . isStream ) {
356
401
this . log ( record . type , record . content ) ;
402
+ const logOutput = this . logMessage . logMsgOutput ( record ) ;
403
+ if ( logOutput ) {
404
+ this . log ( "console" , logOutput ) ;
405
+ }
357
406
} else {
358
407
if ( record . type == "exec" ) {
359
408
this . emit ( "exec-async-output" , parsed ) ;
@@ -373,6 +422,7 @@ export class MI2 extends EventEmitter implements IBackend {
373
422
switch ( reason ) {
374
423
case "breakpoint-hit" :
375
424
this . emit ( "breakpoint" , parsed ) ;
425
+ this . logMessage . logMsgProcess ( parsed ) ;
376
426
break ;
377
427
case "watchpoint-trigger" :
378
428
case "read-watchpoint-trigger" :
@@ -576,6 +626,23 @@ export class MI2 extends EventEmitter implements IBackend {
576
626
return this . sendCommand ( "break-condition " + bkptNum + " " + condition ) ;
577
627
}
578
628
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
+
579
646
setEntryBreakPoint ( entryPoint : string ) : Thenable < any > {
580
647
return this . sendCommand ( "break-insert -t -f " + entryPoint ) ;
581
648
}
@@ -607,15 +674,29 @@ export class MI2 extends EventEmitter implements IBackend {
607
674
if ( result . resultRecords . resultClass == "done" ) {
608
675
const bkptNum = parseInt ( result . result ( "bkpt.number" ) ) ;
609
676
const newBrk = {
677
+ id : bkptNum ,
610
678
file : breakpoint . file ? breakpoint . file : result . result ( "bkpt.file" ) ,
611
679
raw : breakpoint . raw ,
612
680
line : parseInt ( result . result ( "bkpt.line" ) ) ,
613
- condition : breakpoint . condition
681
+ condition : breakpoint . condition ,
682
+ logMessage : breakpoint ?. logMessage ,
614
683
} ;
615
684
if ( breakpoint . condition ) {
616
685
this . setBreakPointCondition ( bkptNum , breakpoint . condition ) . then ( ( result ) => {
617
686
if ( result . resultRecords . resultClass == "done" ) {
618
687
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
+
619
700
resolve ( [ true , newBrk ] ) ;
620
701
} else {
621
702
resolve ( [ false , undefined ] ) ;
0 commit comments