18
18
19
19
import {
20
20
DebugSession , InitializedEvent , OutputEvent , Thread , Source ,
21
- StoppedEvent , ContinuedEvent , StackFrame , TerminatedEvent , Event , ErrorDestination
21
+ StoppedEvent , StackFrame , TerminatedEvent , Event , ErrorDestination
22
22
} from 'vscode-debugadapter' ;
23
23
import { DebugProtocol } from 'vscode-debugprotocol' ;
24
24
import * as Fs from 'fs' ;
@@ -27,7 +27,7 @@ import { IAttachRequestArguments, SourceSendingOptions, TemporaryBreakpoint } fr
27
27
import { JerryDebuggerClient , JerryDebuggerOptions } from './JerryDebuggerClient' ;
28
28
import {
29
29
JerryDebugProtocolDelegate , JerryDebugProtocolHandler , JerryMessageScriptParsed , JerryEvalResult ,
30
- JerryMessageExceptionHit
30
+ JerryMessageExceptionHit , JerryMessageBreakpointHit
31
31
} from './JerryProtocolHandler' ;
32
32
import { EVAL_RESULT_SUBTYPE , CLIENT as CLIENT_PACKAGE } from './JerryProtocolConstants' ;
33
33
import { Breakpoint } from './JerryBreakpoints' ;
@@ -56,7 +56,7 @@ class IotjsDebugSession extends DebugSession {
56
56
// Runtime supports now threads so just return a default thread.
57
57
response . body = {
58
58
threads : [
59
- new Thread ( IotjsDebugSession . THREAD_ID , 'thread 1 ' )
59
+ new Thread ( IotjsDebugSession . THREAD_ID , 'Main Thread ' )
60
60
]
61
61
} ;
62
62
this . sendResponse ( response ) ;
@@ -76,7 +76,8 @@ class IotjsDebugSession extends DebugSession {
76
76
response . body . supportsFunctionBreakpoints = false ;
77
77
response . body . supportsEvaluateForHovers = false ;
78
78
response . body . supportsStepBack = false ;
79
- response . body . supportsRestartRequest = true ;
79
+ response . body . supportsRestartRequest = false ;
80
+ response . body . supportsDelayedStackTraceLoading = false ;
80
81
81
82
this . _sourceSendingOptions = < SourceSendingOptions > {
82
83
contextReset : false ,
@@ -92,7 +93,6 @@ class IotjsDebugSession extends DebugSession {
92
93
this . log ( 'configurationDoneRequest' , LOG_LEVEL . SESSION ) ;
93
94
94
95
super . configurationDoneRequest ( response , args ) ;
95
- this . sendResponse ( response ) ;
96
96
}
97
97
98
98
protected attachRequest ( response : DebugProtocol . AttachResponse , args : IAttachRequestArguments ) : void {
@@ -113,66 +113,26 @@ class IotjsDebugSession extends DebugSession {
113
113
}
114
114
115
115
this . _args = args ;
116
- if ( args . debugLog in LOG_LEVEL ) {
116
+ if ( args . debugLog && args . debugLog in LOG_LEVEL ) {
117
117
this . _debugLog = args . debugLog ;
118
118
} else {
119
119
this . sendErrorResponse ( response , new Error ( 'No log level given' ) ) ;
120
120
}
121
121
this . log ( 'attachRequest' ) ;
122
122
123
- const onBreakpointHit = ( breakpointRef , stopType ) => {
124
- this . log ( 'onBreakpointHit' , LOG_LEVEL . SESSION ) ;
125
- this . sendEvent ( new StoppedEvent ( stopType , IotjsDebugSession . THREAD_ID ) ) ;
126
- } ;
127
-
128
- const onExceptionHit = ( data : JerryMessageExceptionHit ) => {
129
- this . log ( 'onExceptionHit' , LOG_LEVEL . SESSION ) ;
130
- this . sendEvent ( new StoppedEvent ( 'exception' , IotjsDebugSession . THREAD_ID , data . message ) ) ;
131
- } ;
132
-
133
- const onResume = ( ) => {
134
- this . log ( 'onResume' , LOG_LEVEL . SESSION ) ;
135
-
136
- this . sendEvent ( new ContinuedEvent ( IotjsDebugSession . THREAD_ID ) ) ;
137
- } ;
138
-
139
- const onScriptParsed = data => {
140
- this . log ( 'onScriptParsed' , LOG_LEVEL . SESSION ) ;
141
- this . handleSource ( data ) ;
142
- } ;
143
-
144
- const onClose = ( ) => {
145
- this . log ( 'onClose' , LOG_LEVEL . SESSION ) ;
146
- this . sendEvent ( new TerminatedEvent ( ) ) ;
147
- } ;
148
-
149
- const onWaitForSource = async ( ) => {
150
- this . log ( 'onWaitForSource' , LOG_LEVEL . SESSION ) ;
151
- if ( this . _sourceSendingOptions . state === SOURCE_SENDING_STATES . NOP ) {
152
- this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . WAITING ;
153
- this . sendEvent ( new Event ( 'waitForSource' ) ) ;
154
- } else if ( this . _sourceSendingOptions . state === SOURCE_SENDING_STATES . LAST_SENT ) {
155
- if ( ! this . _sourceSendingOptions . contextReset ) {
156
- this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . NOP ;
157
- this . _protocolhandler . sendClientSourceControl ( CLIENT_PACKAGE . JERRY_DEBUGGER_NO_MORE_SOURCES ) ;
158
- }
159
- }
160
- } ;
161
-
162
123
const protocolDelegate = < JerryDebugProtocolDelegate > {
163
- onBreakpointHit,
164
- onExceptionHit,
165
- onResume,
166
- onScriptParsed,
167
- onWaitForSource
124
+ onBreakpointHit : ( ref : JerryMessageBreakpointHit , type : string ) => this . onBreakpointHit ( ref , type ) ,
125
+ onExceptionHit : ( data : JerryMessageExceptionHit ) => this . onExceptionHit ( data ) ,
126
+ onScriptParsed : ( data : JerryMessageScriptParsed ) => this . onScriptParsed ( data ) ,
127
+ onWaitForSource : ( ) => this . onWaitForSource ( )
168
128
} ;
169
129
170
130
this . _protocolhandler = new JerryDebugProtocolHandler (
171
131
protocolDelegate , message => this . log ( message , LOG_LEVEL . SESSION ) ) ;
172
132
this . _debuggerClient = new JerryDebuggerClient ( < JerryDebuggerOptions > {
173
133
delegate : {
174
134
onMessage : ( message : Uint8Array ) => this . _protocolhandler . onMessage ( message ) ,
175
- onClose
135
+ onClose : ( ) => this . onClose ( )
176
136
} ,
177
137
host : args . address ,
178
138
port : args . port
@@ -318,47 +278,53 @@ class IotjsDebugSession extends DebugSession {
318
278
this . sendResponse ( response ) ;
319
279
}
320
280
321
- protected evaluateRequest ( response : DebugProtocol . EvaluateResponse , args : DebugProtocol . EvaluateArguments ) : void {
281
+ protected async evaluateRequest (
282
+ response : DebugProtocol . EvaluateResponse , args : DebugProtocol . EvaluateArguments
283
+ ) : Promise < void > {
322
284
this . log ( 'evaluateRequest' , LOG_LEVEL . SESSION ) ;
323
285
324
- this . _protocolhandler . evaluate ( args . expression )
325
- . then ( ( result : JerryEvalResult ) => {
326
- const value = result . subtype === EVAL_RESULT_SUBTYPE . JERRY_DEBUGGER_EVAL_OK ? result . value : 'Evaluate Error' ;
286
+ try {
287
+ const result : JerryEvalResult = await this . _protocolhandler . evaluate ( args . expression ) ;
288
+ const value : string = result . subtype === EVAL_RESULT_SUBTYPE . JERRY_DEBUGGER_EVAL_OK
289
+ ? result . value
290
+ : 'Evaluate Error' ;
327
291
328
- response . body = {
329
- result : value ,
330
- variablesReference : 0
331
- } ;
292
+ response . body = {
293
+ result : value ,
294
+ variablesReference : 0
295
+ } ;
332
296
333
- this . sendResponse ( response ) ;
334
- } )
335
- . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
297
+ this . sendResponse ( response ) ;
298
+ } catch ( error ) {
299
+ this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ;
300
+ }
336
301
}
337
302
338
- protected stackTraceRequest (
303
+ protected async stackTraceRequest (
339
304
response : DebugProtocol . StackTraceResponse , args : DebugProtocol . StackTraceArguments
340
- ) : void {
305
+ ) : Promise < void > {
341
306
this . log ( 'stackTraceRequest' , LOG_LEVEL . SESSION ) ;
342
307
343
- this . _protocolhandler . requestBacktrace ( )
344
- . then ( backtrace => {
345
- const stk = backtrace . map ( ( f , i ) => new StackFrame (
346
- i ,
347
- f . func . name || 'global' ,
348
- this . pathToSource ( `${ this . _args . localRoot } /${ this . pathToBasename ( f . func . sourceName ) } ` ) ,
349
- f . line ,
350
- f . func . column
351
- )
352
- ) ;
353
-
354
- response . body = {
355
- stackFrames : stk ,
356
- totalFrames : stk . length ,
357
- } ;
308
+ try {
309
+ const backtrace = await this . _protocolhandler . requestBacktrace ( ) ;
310
+ const stk = backtrace . map ( ( f , i ) => new StackFrame (
311
+ 1000 + i ,
312
+ f . func . name || 'global' ,
313
+ this . pathToSource ( `${ this . _args . localRoot } /${ this . pathToBasename ( f . func . sourceName ) } ` ) ,
314
+ f . line ,
315
+ f . func . column
316
+ )
317
+ ) ;
318
+
319
+ response . body = {
320
+ stackFrames : stk ,
321
+ } ;
358
322
359
- this . sendResponse ( response ) ;
360
- } )
361
- . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
323
+ this . sendResponse ( response ) ;
324
+ } catch ( error ) {
325
+ this . log ( error ) ;
326
+ this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ;
327
+ }
362
328
}
363
329
364
330
protected customRequest ( command : string , response : DebugProtocol . Response , args : any ) : void {
@@ -422,7 +388,47 @@ class IotjsDebugSession extends DebugSession {
422
388
}
423
389
}
424
390
425
- // Helper functions
391
+ // Helper functions for event handling
392
+
393
+ private onBreakpointHit ( breakpointRef : JerryMessageBreakpointHit , stopType : string ) : void {
394
+ this . log ( 'onBreakpointHit' ) ;
395
+
396
+ this . sendEvent ( new StoppedEvent ( stopType , IotjsDebugSession . THREAD_ID ) ) ;
397
+ }
398
+
399
+ private onExceptionHit ( data : JerryMessageExceptionHit ) : void {
400
+ this . log ( 'onExceptionHit' ) ;
401
+
402
+ this . sendEvent ( new StoppedEvent ( 'exception' , IotjsDebugSession . THREAD_ID , data . message ) ) ;
403
+ }
404
+
405
+ private onScriptParsed ( data : JerryMessageScriptParsed ) : void {
406
+ this . log ( 'onScriptParsed' ) ;
407
+
408
+ this . handleSource ( data ) ;
409
+ }
410
+
411
+ private async onWaitForSource ( ) : Promise < void > {
412
+ this . log ( 'onWaitForSource' ) ;
413
+
414
+ if ( this . _sourceSendingOptions . state === SOURCE_SENDING_STATES . NOP ) {
415
+ this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . WAITING ;
416
+ this . sendEvent ( new Event ( 'waitForSource' ) ) ;
417
+ } else if ( this . _sourceSendingOptions . state === SOURCE_SENDING_STATES . LAST_SENT ) {
418
+ if ( ! this . _sourceSendingOptions . contextReset ) {
419
+ this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . NOP ;
420
+ this . _protocolhandler . sendClientSourceControl ( CLIENT_PACKAGE . JERRY_DEBUGGER_NO_MORE_SOURCES ) ;
421
+ }
422
+ }
423
+ }
424
+
425
+ private onClose ( ) : void {
426
+ this . log ( 'onClose' ) ;
427
+
428
+ this . sendEvent ( new TerminatedEvent ( ) ) ;
429
+ }
430
+
431
+ // General helper functions
426
432
427
433
private handleSource ( data : JerryMessageScriptParsed ) : void {
428
434
const path = `${ this . _args . localRoot } /${ this . pathToBasename ( data . name ) } ` ;
@@ -451,7 +457,6 @@ class IotjsDebugSession extends DebugSession {
451
457
private pathToBasename ( path : string ) : string {
452
458
if ( path === '' || path === undefined ) path = 'debug_eval.js' ;
453
459
return Path . basename ( path ) ;
454
-
455
460
}
456
461
457
462
private log ( message : any , level : number = LOG_LEVEL . VERBOSE ) : void {
0 commit comments