@@ -23,6 +23,7 @@ import {
23
23
import { DebugProtocol } from 'vscode-debugprotocol' ;
24
24
import * as Fs from 'fs' ;
25
25
import * as Path from 'path' ;
26
+ import * as Util from 'util' ;
26
27
import { IAttachRequestArguments , SourceSendingOptions , TemporaryBreakpoint } from './IotjsDebuggerInterfaces' ;
27
28
import { JerryDebuggerClient , JerryDebuggerOptions } from './JerryDebuggerClient' ;
28
29
import {
@@ -69,8 +70,6 @@ class IotjsDebugSession extends DebugSession {
69
70
protected initializeRequest (
70
71
response : DebugProtocol . InitializeResponse , args : DebugProtocol . InitializeRequestArguments
71
72
) : void {
72
- this . log ( 'initializeRequest' , LOG_LEVEL . SESSION ) ;
73
-
74
73
// This debug adapter implements the configurationDoneRequest.
75
74
response . body . supportsConfigurationDoneRequest = true ;
76
75
response . body . supportsFunctionBreakpoints = false ;
@@ -90,8 +89,6 @@ class IotjsDebugSession extends DebugSession {
90
89
protected configurationDoneRequest (
91
90
response : DebugProtocol . ConfigurationDoneResponse , args : DebugProtocol . ConfigurationDoneArguments
92
91
) : void {
93
- this . log ( 'configurationDoneRequest' , LOG_LEVEL . SESSION ) ;
94
-
95
92
super . configurationDoneRequest ( response , args ) ;
96
93
}
97
94
@@ -118,7 +115,6 @@ class IotjsDebugSession extends DebugSession {
118
115
} else {
119
116
this . sendErrorResponse ( response , new Error ( 'No log level given' ) ) ;
120
117
}
121
- this . log ( 'attachRequest' ) ;
122
118
123
119
const protocolDelegate = < JerryDebugProtocolDelegate > {
124
120
onBreakpointHit : ( ref : JerryMessageBreakpointHit , type : string ) => this . onBreakpointHit ( ref , type ) ,
@@ -128,7 +124,8 @@ class IotjsDebugSession extends DebugSession {
128
124
} ;
129
125
130
126
this . _protocolhandler = new JerryDebugProtocolHandler (
131
- protocolDelegate , message => this . log ( message , LOG_LEVEL . SESSION ) ) ;
127
+ protocolDelegate , ( message : any , level : number = LOG_LEVEL . VERBOSE ) => this . log ( message , level )
128
+ ) ;
132
129
this . _debuggerClient = new JerryDebuggerClient ( < JerryDebuggerOptions > {
133
130
delegate : {
134
131
onMessage : ( message : Uint8Array ) => this . _protocolhandler . onMessage ( message ) ,
@@ -154,16 +151,12 @@ class IotjsDebugSession extends DebugSession {
154
151
}
155
152
156
153
protected launchRequest ( response : DebugProtocol . LaunchResponse , args : DebugProtocol . LaunchRequestArguments ) : void {
157
- this . log ( 'launchRequest' , LOG_LEVEL . SESSION ) ;
158
-
159
154
this . sendErrorResponse ( response , new Error ( 'Launching is not supported. Use Attach.' ) ) ;
160
155
}
161
156
162
157
protected disconnectRequest (
163
158
response : DebugProtocol . DisconnectResponse , args : DebugProtocol . DisconnectArguments
164
159
) : void {
165
- this . log ( 'disconnectRequest' , LOG_LEVEL . SESSION ) ;
166
-
167
160
this . _debuggerClient . disconnect ( ) ;
168
161
169
162
this . sendEvent ( new TerminatedEvent ( ) ) ;
@@ -177,8 +170,6 @@ class IotjsDebugSession extends DebugSession {
177
170
}
178
171
179
172
protected continueRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
180
- this . log ( 'continueRequest' , LOG_LEVEL . SESSION ) ;
181
-
182
173
this . _protocolhandler . resume ( )
183
174
. then ( ( ) => {
184
175
this . sendResponse ( response ) ;
@@ -187,8 +178,6 @@ class IotjsDebugSession extends DebugSession {
187
178
}
188
179
189
180
protected nextRequest ( response : DebugProtocol . NextResponse , args : DebugProtocol . NextArguments ) : void {
190
- this . log ( 'nextRequest' , LOG_LEVEL . SESSION ) ;
191
-
192
181
this . _protocolhandler . stepOver ( )
193
182
. then ( ( ) => {
194
183
this . sendResponse ( response ) ;
@@ -197,8 +186,6 @@ class IotjsDebugSession extends DebugSession {
197
186
}
198
187
199
188
protected stepInRequest ( response : DebugProtocol . StepInResponse , args : DebugProtocol . StepInArguments ) : void {
200
- this . log ( 'stepInRequest' , LOG_LEVEL . SESSION ) ;
201
-
202
189
this . _protocolhandler . stepInto ( )
203
190
. then ( ( ) => {
204
191
this . sendResponse ( response ) ;
@@ -207,8 +194,6 @@ class IotjsDebugSession extends DebugSession {
207
194
}
208
195
209
196
protected stepOutRequest ( response : DebugProtocol . StepOutResponse , args : DebugProtocol . StepOutArguments ) : void {
210
- this . log ( 'stepOutRequest' , LOG_LEVEL . SESSION ) ;
211
-
212
197
this . _protocolhandler . stepOut ( )
213
198
. then ( ( ) => {
214
199
this . sendResponse ( response ) ;
@@ -217,8 +202,6 @@ class IotjsDebugSession extends DebugSession {
217
202
}
218
203
219
204
protected pauseRequest ( response : DebugProtocol . PauseResponse , args : DebugProtocol . PauseArguments ) : void {
220
- this . log ( 'pauseRequest' , LOG_LEVEL . SESSION ) ;
221
-
222
205
this . _protocolhandler . pause ( )
223
206
. then ( ( ) => {
224
207
this . sendResponse ( response ) ;
@@ -229,8 +212,6 @@ class IotjsDebugSession extends DebugSession {
229
212
protected async setBreakPointsRequest (
230
213
response : DebugProtocol . SetBreakpointsResponse , args : DebugProtocol . SetBreakpointsArguments
231
214
) : Promise < void > {
232
- this . log ( 'setBreakPointsRequest' , LOG_LEVEL . SESSION ) ;
233
-
234
215
const filename : string = args . source . name ;
235
216
const vscodeBreakpoints : DebugProtocol . Breakpoint [ ] = args . breakpoints ! . map ( b => ( { verified : false , line : b . line } ) ) ;
236
217
@@ -281,8 +262,6 @@ class IotjsDebugSession extends DebugSession {
281
262
protected async evaluateRequest (
282
263
response : DebugProtocol . EvaluateResponse , args : DebugProtocol . EvaluateArguments
283
264
) : Promise < void > {
284
- this . log ( 'evaluateRequest' , LOG_LEVEL . SESSION ) ;
285
-
286
265
try {
287
266
const result : JerryEvalResult = await this . _protocolhandler . evaluate ( args . expression ) ;
288
267
const value : string = result . subtype === EVAL_RESULT_SUBTYPE . JERRY_DEBUGGER_EVAL_OK
@@ -303,8 +282,7 @@ class IotjsDebugSession extends DebugSession {
303
282
protected async stackTraceRequest (
304
283
response : DebugProtocol . StackTraceResponse , args : DebugProtocol . StackTraceArguments
305
284
) : Promise < void > {
306
- this . log ( 'stackTraceRequest' , LOG_LEVEL . SESSION ) ;
307
-
285
+ this . log ( args , LOG_LEVEL . SESSION ) ;
308
286
try {
309
287
const backtrace = await this . _protocolhandler . requestBacktrace ( ) ;
310
288
const stk = backtrace . map ( ( f , i ) => new StackFrame (
@@ -328,8 +306,6 @@ class IotjsDebugSession extends DebugSession {
328
306
}
329
307
330
308
protected customRequest ( command : string , response : DebugProtocol . Response , args : any ) : void {
331
- this . log ( 'customRequest' , LOG_LEVEL . SESSION ) ;
332
-
333
309
switch ( command ) {
334
310
case 'sendSource' : {
335
311
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . IN_PROGRESS ;
@@ -352,6 +328,28 @@ class IotjsDebugSession extends DebugSession {
352
328
}
353
329
354
330
// Overrides.
331
+ protected dispatchRequest ( request : DebugProtocol . Request ) : void {
332
+ const log = `-> ${ request . command } Request\n${ Util . inspect ( request , { depth : Infinity } ) } \n` ;
333
+ this . log ( log , LOG_LEVEL . SESSION ) ;
334
+
335
+ super . dispatchRequest ( request ) ;
336
+ }
337
+
338
+ public sendResponse ( response : DebugProtocol . Response ) : void {
339
+ const log = `<- ${ response . command } Response\n${ Util . inspect ( response , { depth : Infinity } ) } \n` ;
340
+ this . log ( log , LOG_LEVEL . SESSION ) ;
341
+
342
+ super . sendResponse ( response ) ;
343
+ }
344
+
345
+ public sendEvent ( event : DebugProtocol . Event , bypassLog : boolean = false ) : void {
346
+ if ( ! bypassLog ) {
347
+ const log = `<- ${ event . event } Event\n${ Util . inspect ( event , { depth : Infinity } ) } \n` ;
348
+ this . log ( log , LOG_LEVEL . SESSION ) ;
349
+ }
350
+
351
+ super . sendEvent ( event ) ;
352
+ }
355
353
356
354
protected sendErrorResponse (
357
355
response : DebugProtocol . Response ,
@@ -391,25 +389,25 @@ class IotjsDebugSession extends DebugSession {
391
389
// Helper functions for event handling
392
390
393
391
private onBreakpointHit ( breakpointRef : JerryMessageBreakpointHit , stopType : string ) : void {
394
- this . log ( 'onBreakpointHit' ) ;
392
+ this . log ( 'onBreakpointHit' , LOG_LEVEL . SESSION ) ;
395
393
396
394
this . sendEvent ( new StoppedEvent ( stopType , IotjsDebugSession . THREAD_ID ) ) ;
397
395
}
398
396
399
397
private onExceptionHit ( data : JerryMessageExceptionHit ) : void {
400
- this . log ( 'onExceptionHit' ) ;
398
+ this . log ( 'onExceptionHit' , LOG_LEVEL . SESSION ) ;
401
399
402
400
this . sendEvent ( new StoppedEvent ( 'exception' , IotjsDebugSession . THREAD_ID , data . message ) ) ;
403
401
}
404
402
405
403
private onScriptParsed ( data : JerryMessageScriptParsed ) : void {
406
- this . log ( 'onScriptParsed' ) ;
404
+ this . log ( 'onScriptParsed' , LOG_LEVEL . SESSION ) ;
407
405
408
406
this . handleSource ( data ) ;
409
407
}
410
408
411
409
private async onWaitForSource ( ) : Promise < void > {
412
- this . log ( 'onWaitForSource' ) ;
410
+ this . log ( 'onWaitForSource' , LOG_LEVEL . SESSION ) ;
413
411
414
412
if ( this . _sourceSendingOptions . state === SOURCE_SENDING_STATES . NOP ) {
415
413
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . WAITING ;
@@ -423,7 +421,7 @@ class IotjsDebugSession extends DebugSession {
423
421
}
424
422
425
423
private onClose ( ) : void {
426
- this . log ( 'onClose' ) ;
424
+ this . log ( 'onClose' , LOG_LEVEL . SESSION ) ;
427
425
428
426
this . sendEvent ( new TerminatedEvent ( ) ) ;
429
427
}
@@ -463,14 +461,14 @@ class IotjsDebugSession extends DebugSession {
463
461
if ( level === this . _debugLog || this . _debugLog === LOG_LEVEL . VERBOSE ) {
464
462
switch ( typeof message ) {
465
463
case 'object' :
466
- message = JSON . stringify ( message , null , 2 ) ;
464
+ message = Util . inspect ( message , { depth : Infinity } ) ;
467
465
break ;
468
466
default :
469
467
message = message . toString ( ) ;
470
468
break ;
471
469
}
472
470
473
- this . sendEvent ( new OutputEvent ( `[DS] ${ message } \n` , 'console' ) ) ;
471
+ this . sendEvent ( new OutputEvent ( `[${ LOG_LEVEL [ level ] } ] ${ message } \n` , 'console' ) , true ) ;
474
472
}
475
473
}
476
474
}
0 commit comments