VDBSimpleDebuggerConsoleApplication.st
changeset 143 df7f89efd39d
parent 139 c619cc458fb1
child 144 315d72d8dc4e
equal deleted inserted replaced
142:dae35d5b3d72 143:df7f89efd39d
     9 "{ Package: 'jv:vdb' }"
     9 "{ Package: 'jv:vdb' }"
    10 
    10 
    11 "{ NameSpace: Smalltalk }"
    11 "{ NameSpace: Smalltalk }"
    12 
    12 
    13 VDBAbstractConsoleApplication subclass:#VDBSimpleDebuggerConsoleApplication
    13 VDBAbstractConsoleApplication subclass:#VDBSimpleDebuggerConsoleApplication
    14 	instanceVariableNames:'consoleInput consoleOutput consoleOutputLock consoleProcess
    14 	instanceVariableNames:'prompt promptPrinted running'
    15 		consolePrompt consolePromptPrinted outstandingCommand
       
    16 		outstandingCommandToken outstandingCommandBlocker
       
    17 		ignoreNextLogStreamEvent running'
       
    18 	classVariableNames:''
    15 	classVariableNames:''
    19 	poolDictionaries:'GDBCommandStatus'
    16 	poolDictionaries:'GDBCommandStatus'
    20 	category:'VDB-UI-Console'
    17 	category:'VDB-UI-Console'
    21 !
    18 !
    22 
    19 
    58     "this is only required for web-applications"
    55     "this is only required for web-applications"
    59 
    56 
    60     ^ self shouldImplement
    57     ^ self shouldImplement
    61 ! !
    58 ! !
    62 
    59 
    63 !VDBSimpleDebuggerConsoleApplication methodsFor:'accessing'!
       
    64 
       
    65 consoleInput
       
    66     ^ consoleInput
       
    67 
       
    68     "Created: / 21-01-2019 / 14:18:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    69 !
       
    70 
       
    71 consoleOutput
       
    72     ^ consoleOutput
       
    73 
       
    74     "Created: / 21-01-2019 / 14:18:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    75 ! !
       
    76 
       
    77 !VDBSimpleDebuggerConsoleApplication methodsFor:'actions'!
    60 !VDBSimpleDebuggerConsoleApplication methodsFor:'actions'!
    78 
    61 
    79 doComplete: line
    62 doComplete: line
    80     "Called when a user triggers a command completion (usually by pressing
    63     "Called when a user triggers a command completion (usually by pressing
    81      tab)"
    64      tab)"
    82 
    65 
    83     | command |
    66     | command |
    84 
    67 
    85     command := GDBMI_complete arguments: (Array with: line).
    68     command := GDBMI_complete arguments: (Array with: line).
    86     debugger send: command andWithResultDo: [ :result |
    69     debugger send: command andWithResultDo: [ :result |
    87         consoleView sensor pushUserEvent: #doComplete:with: for: self withArguments: (Array with: line with: result)
    70         result isDone ifTrue:[ 
       
    71             consoleView completions: (result propertyAt: #completions)
       
    72         ].
    88     ].
    73     ].
    89 
    74 
    90     "Created: / 30-12-2018 / 22:01:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    75     "Created: / 30-12-2018 / 22:01:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    91     "Modified (comment): / 31-12-2018 / 11:35:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    76     "Modified: / 25-01-2019 / 22:03:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    92 !
    77 !
    93 
    78 
    94 doComplete: line with: result
    79 doFire: aString
    95     "Called asynchronously from #doComplete: when possible completions
    80     "Executes entered command"
    96      are computed.
    81 
    97 
    82     | cmd |
    98      Private, this is for private use by #doComplete: 
    83 
    99     "
    84     promptPrinted := false.
   100     self consoleView completeCommandWith: (result propertyAt: #completions).
    85 
   101 
    86     aString isEmptyOrNil ifTrue:[ 
   102     "Created: / 30-12-2018 / 22:04:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    87         self showPrompt.
   103     "Modified: / 16-01-2019 / 14:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    88         ^ self.
       
    89     ].
       
    90 
       
    91     cmd := GDBCommand parse: aString.
       
    92     cmd isCLICommand ifTrue:[ 
       
    93         cmd runOnBackground: true.  
       
    94     ].
       
    95     consoleView readOnly:true.  
       
    96     debugger send:cmd andWithResultDo:[:result| 
       
    97         result isError ifTrue:[ 
       
    98             consoleView showCR: (result propertyAt: #msg)
       
    99         ].
       
   100         consoleView readOnly:false.
       
   101         self showPrompt.
       
   102     ].
       
   103 
       
   104     "Created: / 25-01-2019 / 12:12:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   104 ! !
   105 ! !
   105 
   106 
   106 !VDBSimpleDebuggerConsoleApplication methodsFor:'aspects'!
   107 !VDBSimpleDebuggerConsoleApplication methodsFor:'aspects'!
   107 
   108 
   108 consoleViewClass
   109 consoleViewClass
   109     ^ VDBSimpleDebuggerConsoleView
   110     ^ VDBSimpleConsoleView
   110 
   111 
   111     "Modified: / 21-01-2019 / 14:22:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   112     "Modified: / 21-01-2019 / 14:22:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   112 ! !
   113 ! !
   113 
   114 
   114 !VDBSimpleDebuggerConsoleApplication methodsFor:'event handling'!
   115 !VDBSimpleDebuggerConsoleApplication methodsFor:'event handling'!
   115 
   116 
   116 onCmdParamChanged: event
   117 onCmdParamChanged: event
   117     event name = 'prompt' ifTrue:[
   118     event name = 'prompt' ifTrue:[
   118         consolePrompt := event value
   119         prompt := event value
   119     ].
   120     ].
   120 
   121 
   121     "Created: / 19-01-2019 / 22:13:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   122     "Created: / 19-01-2019 / 22:13:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   122 !
       
   123 
       
   124 onCommandEvent: event
       
   125     event command == outstandingCommand ifTrue:[ 
       
   126         outstandingCommandToken := event token.
       
   127         ignoreNextLogStreamEvent := true.
       
   128     ].
       
   129 
       
   130     "Created: / 06-06-2014 / 22:43:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   131     "Modified: / 11-06-2014 / 12:35:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   132 !
       
   133 
       
   134 onCommandResultEvent: event
       
   135     outstandingCommandToken notNil ifTrue:[ 
       
   136         event token == outstandingCommandToken ifTrue:[ 
       
   137             "/ Check if command ended up with an error. If so,
       
   138             "/ print the error message.
       
   139             event result status == CommandStatusError ifTrue:[ 
       
   140                 self showCR: ('Error: %1 ' bindWith: (event result propertyAt: #msg)).
       
   141             ] ifFalse:[
       
   142                 "/ Check if the command issues is actually a MI command,
       
   143                 "/ if so, print "Done" to the console since MI command don't
       
   144                 "/ provide user feedback.
       
   145                 outstandingCommand isMICommand ifTrue:[ 
       
   146                     self showCR: ('Done ( %1 , see even log for result value)' bindWith: outstandingCommand value)
       
   147                 ].
       
   148             ].
       
   149             outstandingCommand := outstandingCommandToken := nil. 
       
   150             outstandingCommandBlocker signalForAll.     
       
   151         ].
       
   152     ].
       
   153 
       
   154     "Created: / 06-06-2014 / 22:44:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   155     "Modified: / 27-02-2015 / 13:01:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   156 !
       
   157 
       
   158 onEventSetProcessingFinished: event
       
   159     self showPrompt.
       
   160 
       
   161     "Created: / 18-09-2014 / 23:11:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   162 !
       
   163 
       
   164 onLogOutputEvent: event
       
   165     ignoreNextLogStreamEvent ifTrue:[ 
       
   166         ignoreNextLogStreamEvent := false.
       
   167     ] ifFalse:[
       
   168         self onStreamOutputEvent: event  
       
   169     ]
       
   170 
       
   171     "Created: / 11-06-2014 / 12:37:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   172     "Modified: / 04-04-2018 / 22:50:14 / jv"
       
   173     "Modified: / 30-12-2018 / 22:03:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   174 !
   123 !
   175 
   124 
   176 onRunningEvent: event
   125 onRunningEvent: event
   177     running := true.
   126     running := true.
   178     consoleView readOnly: true.
   127     consoleView readOnly: true.
   187 
   136 
   188     "Created: / 19-01-2019 / 23:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   137     "Created: / 19-01-2019 / 23:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   189 !
   138 !
   190 
   139 
   191 onStreamOutputEvent: event
   140 onStreamOutputEvent: event
   192     consolePromptPrinted ifTrue:[ self showCR:'' ].
   141     promptPrinted ifTrue:[ consoleView cr ].
   193     consolePromptPrinted := false.
   142     promptPrinted := false.
   194     event value asStringCollection do:[:line |  
   143     consoleView show: event value
   195         line notEmptyOrNil ifTrue:[ 
       
   196             self showCR: line.  
       
   197         ].
       
   198     ].
       
   199 
   144 
   200     "Created: / 11-06-2014 / 12:00:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   145     "Created: / 11-06-2014 / 12:00:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   201     "Modified: / 30-12-2018 / 22:02:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   146     "Modified: / 25-01-2019 / 13:36:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   202 ! !
   147 ! !
   203 
   148 
   204 !VDBSimpleDebuggerConsoleApplication methodsFor:'hooks'!
   149 !VDBSimpleDebuggerConsoleApplication methodsFor:'hooks'!
   205 
       
   206 commonPostOpen
       
   207     consoleProcess isNil ifTrue:[
       
   208         consoleProcess := 
       
   209             [
       
   210                 [ self consoleProcess1Command ] loop. 
       
   211             ] newProcess.
       
   212         consoleProcess name: 'VDB Debugger Console REPL loop'.
       
   213         consoleProcess resume.
       
   214     ].
       
   215 
       
   216     "Created: / 10-06-2014 / 01:25:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   217     "Modified: / 19-01-2019 / 23:48:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   218 !
       
   219 
   150 
   220 postBuildConsoleView: aTextCollector
   151 postBuildConsoleView: aTextCollector
   221     consoleView := aTextCollector scrolledView.
   152     consoleView := aTextCollector scrolledView.
   222     consoleView readOnly: true;       
   153     consoleView readOnly: true;       
   223                 font: CodeView defaultFont;
   154                 font: CodeView defaultFont;
   231 
   162 
   232 !VDBSimpleDebuggerConsoleApplication methodsFor:'initialization & release'!
   163 !VDBSimpleDebuggerConsoleApplication methodsFor:'initialization & release'!
   233 
   164 
   234 initialize
   165 initialize
   235     super initialize.
   166     super initialize.
   236 
   167     prompt := '(gdb) '.
   237     consoleInput := GDBInternalPipeStream new.
   168     promptPrinted := false.
   238     consoleOutput := GDBInternalPipeStream new.
       
   239     consoleOutputLock := RecursionLock new.
       
   240     consolePrompt := '(gdb) '.
       
   241     consolePromptPrinted := false.
       
   242     running := false.
   169     running := false.
   243     outstandingCommandBlocker := Semaphore new.
       
   244     ignoreNextLogStreamEvent := false.
       
   245 
   170 
   246     "Created: / 10-06-2014 / 01:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   171     "Created: / 10-06-2014 / 01:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   247     "Modified: / 07-04-2018 / 23:13:27 / jv"
   172     "Modified: / 07-04-2018 / 23:13:27 / jv"
   248     "Modified: / 21-01-2019 / 15:37:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   173     "Modified: / 25-01-2019 / 22:01:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   249 !
   174 !
   250 
   175 
   251 initializeConsoleView: aTerminalView
   176 initializeConsoleView: view
   252     super initializeConsoleView: aTerminalView.
   177     super initializeConsoleView: view.
   253     aTerminalView localEcho:true.
   178     consoleView acceptAction: [ :command | self doFire: command ].
   254     aTerminalView inputTranslateCRToNL:true.
   179 
   255     aTerminalView lineEditMode:true.
   180     "Created: / 25-01-2019 / 12:13:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   256 
   181     "Modified: / 25-01-2019 / 22:34:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   257     "Created: / 21-01-2019 / 14:13:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   258     "Modified: / 21-01-2019 / 15:33:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   259 !
   182 !
   260 
   183 
   261 initializeConsoleView: aTerminalView forDebugger: aGDBDebugger
   184 initializeConsoleView: aTerminalView forDebugger: aGDBDebugger
   262     super initializeConsoleView: aTerminalView forDebugger: aGDBDebugger.
   185     super initializeConsoleView: aTerminalView forDebugger: aGDBDebugger.
   263     (aGDBDebugger notNil and:[aGDBDebugger hasCommand:'-complete']) ifTrue:[ 
   186     consoleView clear.       
   264         consoleView completionBlock: [ :prefix | self doComplete: prefix ].
   187     consoleView completeAction: nil.  
   265         consolePrompt := debugger getParameter: 'prompt'.
   188     (aGDBDebugger notNil) ifTrue:[ 
       
   189         prompt := debugger getParameter: 'prompt'.
       
   190         self showPrompt.
       
   191         (aGDBDebugger hasCommand:'-complete') ifTrue:[ 
       
   192             consoleView completeAction: [ :command | self doComplete: command ]
       
   193         ].
   266     ] ifFalse:[ 
   194     ] ifFalse:[ 
   267         consoleView completionBlock: nil.
   195         prompt := '(gdb) '
   268         consolePrompt := '(gdb) '
       
   269     ].
   196     ].
   270 
   197 
   271     "Created: / 21-01-2019 / 15:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   198     "Created: / 21-01-2019 / 15:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   272     "Modified: / 21-01-2019 / 17:49:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   199     "Modified: / 25-01-2019 / 22:35:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   273 !
       
   274 
       
   275 release
       
   276     super release.
       
   277     consoleProcess terminate.
       
   278 
       
   279     "Created: / 10-06-2014 / 01:34:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   280 !
   200 !
   281 
   201 
   282 subscribe   
   202 subscribe   
   283     "Register for debugger events. To be overrided by subclasses"
   203     "Register for debugger events. To be overrided by subclasses"
   284 
   204 
   285     super subscribe.
   205     super subscribe.
   286     debugger announcer 
   206     debugger announcer 
   287         when: GDBCommandEvent           send: #onCommandEvent:          to: self;
   207 "/        when: GDBCommandEvent           send: #onCommandEvent:          to: self;
   288         when: GDBCommandResultEvent     send: #onCommandResultEvent:    to: self;
   208 "/        when: GDBCommandResultEvent     send: #onCommandResultEvent:    to: self;
   289 
   209 
   290         when: GDBRunningEvent           send: #onRunningEvent:          to: self;
   210         when: GDBRunningEvent           send: #onRunningEvent:          to: self;
   291         when: GDBStoppedEvent           send: #onStoppedEvent:          to: self;
   211         when: GDBStoppedEvent           send: #onStoppedEvent:          to: self;
   292 
   212 
   293         when: GDBConsoleOutputEvent      send: #onStreamOutputEvent:     to: self;
   213         when: GDBConsoleOutputEvent     send: #onStreamOutputEvent:     to: self;
   294         when: GDBTargetOutputEvent       send: #onStreamOutputEvent:     to: self;
   214         when: GDBTargetOutputEvent      send: #onStreamOutputEvent:     to: self;
   295         when: GDBLogOutputEvent          send: #onLogOutputEvent:        to: self;
   215 
   296 
   216         when: GDBCmdParamChangedEvent   send: #onCmdParamChanged:       to: self.
   297         when: GDBEventSetProcessingFinished send: #onEventSetProcessingFinished: to: self;
   217 
   298 
   218     running := debugger inferiors anySatisfy:[ :tg | tg isRunning and:[ tg isStopped not ] ].
   299         when: GDBCmdParamChangedEvent send: #onCmdParamChanged: to: self.
       
   300 
       
   301     running := debugger inferiors anySatisfy:[ :tg | tg isRunning ].
       
   302 
   219 
   303     "Created: / 06-06-2014 / 21:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   220     "Created: / 06-06-2014 / 21:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   304     "Modified: / 21-01-2019 / 15:37:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   221     "Modified: / 25-01-2019 / 12:33:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   305 ! !
   222 ! !
   306 
   223 
   307 !VDBSimpleDebuggerConsoleApplication methodsFor:'private - console process'!
   224 !VDBSimpleDebuggerConsoleApplication methodsFor:'private'!
   308 
       
   309 consoleProcess1Command
       
   310     | cmdLine cmd |
       
   311 
       
   312     self showPrompt.
       
   313     cmdLine := consoleInput nextLine asString.
       
   314     self showCR.
       
   315     consolePromptPrinted := false.
       
   316     cmdLine notEmptyOrNil ifTrue:[
       
   317         cmd := GDBCommand parse: cmdLine.
       
   318         cmd isCLICommand ifTrue:[ 
       
   319             cmd runOnBackground: true.  
       
   320         ].
       
   321         outstandingCommand := cmd.
       
   322         consoleView readOnly:true.  
       
   323         debugger send:cmd andWait:false. 
       
   324         outstandingCommandBlocker wait.
       
   325         consoleView readOnly:false.
       
   326     ].
       
   327 
       
   328     "Created: / 19-01-2019 / 23:49:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   329     "Modified: / 21-01-2019 / 12:25:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   330 ! !
       
   331 
       
   332 !VDBSimpleDebuggerConsoleApplication methodsFor:'private - writing'!
       
   333 
       
   334 show: aString
       
   335     consoleOutputLock critical:[ 
       
   336         consoleOutput nextPutAll: aString.
       
   337     ].
       
   338 
       
   339     "Created: / 11-06-2014 / 08:02:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   340     "Modified: / 11-06-2014 / 11:53:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   341 !
       
   342 
       
   343 showCR
       
   344     consoleOutputLock critical:[ 
       
   345         consoleOutput crlf.
       
   346     ].
       
   347 
       
   348     "Created: / 21-01-2019 / 12:25:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   349 !
       
   350 
       
   351 showCR: aString
       
   352     consoleOutputLock critical:[ 
       
   353         consoleOutput nextPutAll: aString; crlf.
       
   354     ].
       
   355 
       
   356     "Created: / 11-06-2014 / 08:02:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   357     "Modified: / 16-01-2019 / 10:52:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   358 !
       
   359 
   225 
   360 showPrompt
   226 showPrompt
   361     (running not and: [consolePromptPrinted not]) ifTrue:[
   227     (running not and: [promptPrinted not]) ifTrue:[
   362         self show: consolePrompt.
   228         consoleView show: prompt.
   363         consolePromptPrinted := true.
   229         promptPrinted := true.
   364     ].
   230     ].
   365 
   231 
   366     "Created: / 18-09-2014 / 23:18:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   232     "Created: / 18-09-2014 / 23:18:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   367     "Modified: / 04-04-2018 / 23:01:24 / jv"
   233     "Modified: / 04-04-2018 / 23:01:24 / jv"
   368     "Modified: / 19-01-2019 / 23:58:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   234     "Modified: / 25-01-2019 / 12:02:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   369 ! !
   235 ! !
   370 
   236 
   371 !VDBSimpleDebuggerConsoleApplication class methodsFor:'documentation'!
   237 !VDBSimpleDebuggerConsoleApplication class methodsFor:'documentation'!
   372 
   238 
   373 version_HG
   239 version_HG