@@ -31,21 +31,15 @@ import {
31
31
} from './JerryProtocolHandler' ;
32
32
import { EVAL_RESULT_SUBTYPE , CLIENT as CLIENT_PACKAGE } from './JerryProtocolConstants' ;
33
33
import { Breakpoint } from './JerryBreakpoints' ;
34
-
35
- enum SOURCE_SENDING_STATES {
36
- NOP = 0 ,
37
- WAITING = 1 ,
38
- IN_PROGRESS = 2 ,
39
- LAST_SENT = 3
40
- }
34
+ import { SOURCE_SENDING_STATES , LOG_LEVEL } from './IotjsDebuggerConstants' ;
41
35
42
36
class IotjsDebugSession extends DebugSession {
43
37
44
38
// We don't support multiple threads, so we can use a hardcoded ID for the default thread
45
39
private static THREAD_ID = 1 ;
46
40
47
41
private _args : IAttachRequestArguments ;
48
- private _debugLog : boolean = false ;
42
+ private _debugLog : number = 0 ;
49
43
private _debuggerClient : JerryDebuggerClient ;
50
44
private _protocolhandler : JerryDebugProtocolHandler ;
51
45
private _sourceSendingOptions : SourceSendingOptions ;
@@ -75,7 +69,7 @@ class IotjsDebugSession extends DebugSession {
75
69
protected initializeRequest (
76
70
response : DebugProtocol . InitializeResponse , args : DebugProtocol . InitializeRequestArguments
77
71
) : void {
78
- this . log ( 'initializeRequest' ) ;
72
+ this . log ( 'initializeRequest' , LOG_LEVEL . SESSION ) ;
79
73
80
74
// This debug adapter implements the configurationDoneRequest.
81
75
response . body . supportsConfigurationDoneRequest = true ;
@@ -95,14 +89,13 @@ class IotjsDebugSession extends DebugSession {
95
89
protected configurationDoneRequest (
96
90
response : DebugProtocol . ConfigurationDoneResponse , args : DebugProtocol . ConfigurationDoneArguments
97
91
) : void {
98
- this . log ( 'configurationDoneRequest' ) ;
92
+ this . log ( 'configurationDoneRequest' , LOG_LEVEL . SESSION ) ;
99
93
100
94
super . configurationDoneRequest ( response , args ) ;
101
95
this . sendResponse ( response ) ;
102
96
}
103
97
104
98
protected attachRequest ( response : DebugProtocol . AttachResponse , args : IAttachRequestArguments ) : void {
105
- this . log ( 'attachRequest' ) ;
106
99
107
100
if ( ! args . address || args . address === '' ) {
108
101
this . sendErrorResponse ( response , new Error ( 'Must specify an address' ) ) ;
@@ -120,36 +113,41 @@ class IotjsDebugSession extends DebugSession {
120
113
}
121
114
122
115
this . _args = args ;
123
- this . _debugLog = args . debugLog || false ;
116
+ if ( args . debugLog in LOG_LEVEL ) {
117
+ this . _debugLog = args . debugLog ;
118
+ } else {
119
+ this . sendErrorResponse ( response , new Error ( 'No log level given' ) ) ;
120
+ }
121
+ this . log ( 'attachRequest' ) ;
124
122
125
123
const onBreakpointHit = ( breakpointRef , stopType ) => {
126
- this . log ( 'onBreakpointHit' ) ;
124
+ this . log ( 'onBreakpointHit' , LOG_LEVEL . SESSION ) ;
127
125
this . sendEvent ( new StoppedEvent ( stopType , IotjsDebugSession . THREAD_ID ) ) ;
128
126
} ;
129
127
130
128
const onExceptionHit = ( data : JerryMessageExceptionHit ) => {
131
- this . log ( 'onExceptionHit' ) ;
129
+ this . log ( 'onExceptionHit' , LOG_LEVEL . SESSION ) ;
132
130
this . sendEvent ( new StoppedEvent ( 'exception' , IotjsDebugSession . THREAD_ID , data . message ) ) ;
133
131
} ;
134
132
135
133
const onResume = ( ) => {
136
- this . log ( 'onResume' ) ;
134
+ this . log ( 'onResume' , LOG_LEVEL . SESSION ) ;
137
135
138
136
this . sendEvent ( new ContinuedEvent ( IotjsDebugSession . THREAD_ID ) ) ;
139
137
} ;
140
138
141
139
const onScriptParsed = data => {
142
- this . log ( 'onScriptParsed' ) ;
140
+ this . log ( 'onScriptParsed' , LOG_LEVEL . SESSION ) ;
143
141
this . handleSource ( data ) ;
144
142
} ;
145
143
146
144
const onClose = ( ) => {
147
- this . log ( 'onClose' ) ;
145
+ this . log ( 'onClose' , LOG_LEVEL . SESSION ) ;
148
146
this . sendEvent ( new TerminatedEvent ( ) ) ;
149
147
} ;
150
148
151
149
const onWaitForSource = async ( ) => {
152
- this . log ( 'onWaitForSource' ) ;
150
+ this . log ( 'onWaitForSource' , LOG_LEVEL . SESSION ) ;
153
151
if ( this . _sourceSendingOptions . state === SOURCE_SENDING_STATES . NOP ) {
154
152
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . WAITING ;
155
153
this . sendEvent ( new Event ( 'waitForSource' ) ) ;
@@ -169,7 +167,8 @@ class IotjsDebugSession extends DebugSession {
169
167
onWaitForSource
170
168
} ;
171
169
172
- this . _protocolhandler = new JerryDebugProtocolHandler ( protocolDelegate , message => this . log ( message ) ) ;
170
+ this . _protocolhandler = new JerryDebugProtocolHandler (
171
+ protocolDelegate , message => this . log ( message , LOG_LEVEL . SESSION ) ) ;
173
172
this . _debuggerClient = new JerryDebuggerClient ( < JerryDebuggerOptions > {
174
173
delegate : {
175
174
onMessage : ( message : Uint8Array ) => this . _protocolhandler . onMessage ( message ) ,
@@ -182,11 +181,11 @@ class IotjsDebugSession extends DebugSession {
182
181
183
182
this . _debuggerClient . connect ( )
184
183
. then ( ( ) => {
185
- this . log ( `Connected to: ${ args . address } :${ args . port } ` ) ;
184
+ this . log ( `Connected to: ${ args . address } :${ args . port } ` , LOG_LEVEL . SESSION ) ;
186
185
this . sendResponse ( response ) ;
187
186
} )
188
187
. catch ( error => {
189
- this . log ( error ) ;
188
+ this . log ( error , LOG_LEVEL . ERROR ) ;
190
189
this . sendErrorResponse ( response , error ) ;
191
190
} )
192
191
. then ( ( ) => {
@@ -195,15 +194,15 @@ class IotjsDebugSession extends DebugSession {
195
194
}
196
195
197
196
protected launchRequest ( response : DebugProtocol . LaunchResponse , args : DebugProtocol . LaunchRequestArguments ) : void {
198
- this . log ( 'launchRequest' ) ;
197
+ this . log ( 'launchRequest' , LOG_LEVEL . SESSION ) ;
199
198
200
199
this . sendErrorResponse ( response , new Error ( 'Launching is not supported. Use Attach.' ) ) ;
201
200
}
202
201
203
202
protected disconnectRequest (
204
203
response : DebugProtocol . DisconnectResponse , args : DebugProtocol . DisconnectArguments
205
204
) : void {
206
- this . log ( 'disconnectRequest' ) ;
205
+ this . log ( 'disconnectRequest' , LOG_LEVEL . SESSION ) ;
207
206
208
207
this . _debuggerClient . disconnect ( ) ;
209
208
@@ -212,13 +211,13 @@ class IotjsDebugSession extends DebugSession {
212
211
}
213
212
214
213
protected restartRequest ( response : DebugProtocol . RestartResponse , args : DebugProtocol . RestartArguments ) : void {
215
- this . log ( 'restartRequest: Not implemented yet' ) ;
214
+ this . log ( 'restartRequest: Not implemented yet' , LOG_LEVEL . SESSION ) ;
216
215
217
216
this . sendResponse ( response ) ;
218
217
}
219
218
220
219
protected continueRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
221
- this . log ( 'continueRequest' ) ;
220
+ this . log ( 'continueRequest' , LOG_LEVEL . SESSION ) ;
222
221
223
222
this . _protocolhandler . resume ( )
224
223
. then ( ( ) => {
@@ -228,7 +227,7 @@ class IotjsDebugSession extends DebugSession {
228
227
}
229
228
230
229
protected nextRequest ( response : DebugProtocol . NextResponse , args : DebugProtocol . NextArguments ) : void {
231
- this . log ( 'nextRequest' ) ;
230
+ this . log ( 'nextRequest' , LOG_LEVEL . SESSION ) ;
232
231
233
232
this . _protocolhandler . stepOver ( )
234
233
. then ( ( ) => {
@@ -238,7 +237,7 @@ class IotjsDebugSession extends DebugSession {
238
237
}
239
238
240
239
protected stepInRequest ( response : DebugProtocol . StepInResponse , args : DebugProtocol . StepInArguments ) : void {
241
- this . log ( 'stepInRequest' ) ;
240
+ this . log ( 'stepInRequest' , LOG_LEVEL . SESSION ) ;
242
241
243
242
this . _protocolhandler . stepInto ( )
244
243
. then ( ( ) => {
@@ -248,7 +247,7 @@ class IotjsDebugSession extends DebugSession {
248
247
}
249
248
250
249
protected stepOutRequest ( response : DebugProtocol . StepOutResponse , args : DebugProtocol . StepOutArguments ) : void {
251
- this . log ( 'stepOutRequest' ) ;
250
+ this . log ( 'stepOutRequest' , LOG_LEVEL . SESSION ) ;
252
251
253
252
this . _protocolhandler . stepOut ( )
254
253
. then ( ( ) => {
@@ -258,7 +257,7 @@ class IotjsDebugSession extends DebugSession {
258
257
}
259
258
260
259
protected pauseRequest ( response : DebugProtocol . PauseResponse , args : DebugProtocol . PauseArguments ) : void {
261
- this . log ( 'pauseRequest' ) ;
260
+ this . log ( 'pauseRequest' , LOG_LEVEL . SESSION ) ;
262
261
263
262
this . _protocolhandler . pause ( )
264
263
. then ( ( ) => {
@@ -270,7 +269,7 @@ class IotjsDebugSession extends DebugSession {
270
269
protected async setBreakPointsRequest (
271
270
response : DebugProtocol . SetBreakpointsResponse , args : DebugProtocol . SetBreakpointsArguments
272
271
) : Promise < void > {
273
- this . log ( 'setBreakPointsRequest' ) ;
272
+ this . log ( 'setBreakPointsRequest' , LOG_LEVEL . SESSION ) ;
274
273
275
274
const filename : string = args . source . name ;
276
275
const vscodeBreakpoints : DebugProtocol . Breakpoint [ ] = args . breakpoints ! . map ( b => ( { verified : false , line : b . line } ) ) ;
@@ -289,7 +288,7 @@ class IotjsDebugSession extends DebugSession {
289
288
await this . _protocolhandler . updateBreakpoint ( jerryBreakpoint , true ) ;
290
289
return < TemporaryBreakpoint > { verified : true , line : breakpoint . line } ;
291
290
} catch ( error ) {
292
- this . log ( error ) ;
291
+ this . log ( error , LOG_LEVEL . ERROR ) ;
293
292
return < TemporaryBreakpoint > { verified : false , line : breakpoint . line , message : ( < Error > error ) . message } ;
294
293
}
295
294
} ) ) ;
@@ -311,7 +310,7 @@ class IotjsDebugSession extends DebugSession {
311
310
312
311
response . body = { breakpoints : [ ...persistingBreakpoints , ...newBreakpoints ] } ;
313
312
} catch ( error ) {
314
- this . log ( error ) ;
313
+ this . log ( error , LOG_LEVEL . ERROR ) ;
315
314
this . sendErrorResponse ( response , < Error > error ) ;
316
315
return ;
317
316
}
@@ -320,7 +319,7 @@ class IotjsDebugSession extends DebugSession {
320
319
}
321
320
322
321
protected evaluateRequest ( response : DebugProtocol . EvaluateResponse , args : DebugProtocol . EvaluateArguments ) : void {
323
- this . log ( 'evaluateRequest' ) ;
322
+ this . log ( 'evaluateRequest' , LOG_LEVEL . SESSION ) ;
324
323
325
324
this . _protocolhandler . evaluate ( args . expression )
326
325
. then ( ( result : JerryEvalResult ) => {
@@ -339,7 +338,7 @@ class IotjsDebugSession extends DebugSession {
339
338
protected stackTraceRequest (
340
339
response : DebugProtocol . StackTraceResponse , args : DebugProtocol . StackTraceArguments
341
340
) : void {
342
- this . log ( 'stackTraceRequest' ) ;
341
+ this . log ( 'stackTraceRequest' , LOG_LEVEL . SESSION ) ;
343
342
344
343
this . _protocolhandler . requestBacktrace ( )
345
344
. then ( backtrace => {
@@ -363,19 +362,19 @@ class IotjsDebugSession extends DebugSession {
363
362
}
364
363
365
364
protected customRequest ( command : string , response : DebugProtocol . Response , args : any ) : void {
366
- this . log ( 'customRequest' ) ;
365
+ this . log ( 'customRequest' , LOG_LEVEL . SESSION ) ;
367
366
368
367
switch ( command ) {
369
368
case 'sendSource' : {
370
369
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . IN_PROGRESS ;
371
370
this . _protocolhandler . sendClientSource ( args . program . name , args . program . source )
372
371
. then ( ( ) => {
373
- this . log ( 'Source has been sent to the engine.' ) ;
372
+ this . log ( 'Source has been sent to the engine.' , LOG_LEVEL . SESSION ) ;
374
373
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . LAST_SENT ;
375
374
this . sendResponse ( response ) ;
376
375
} )
377
376
. catch ( error => {
378
- this . log ( error ) ;
377
+ this . log ( error , LOG_LEVEL . ERROR ) ;
379
378
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . NOP ;
380
379
this . sendErrorResponse ( response , < Error > error , ErrorDestination . User ) ;
381
380
} ) ;
@@ -455,8 +454,8 @@ class IotjsDebugSession extends DebugSession {
455
454
456
455
}
457
456
458
- private log ( message : any ) : void {
459
- if ( this . _debugLog ) {
457
+ private log ( message : any , level : number = LOG_LEVEL . VERBOSE ) : void {
458
+ if ( level === this . _debugLog || this . _debugLog === LOG_LEVEL . VERBOSE ) {
460
459
switch ( typeof message ) {
461
460
case 'object' :
462
461
message = JSON . stringify ( message , null , 2 ) ;
0 commit comments