@@ -44,7 +44,7 @@ export interface ParserStackFrame {
44
44
}
45
45
46
46
export interface JerryDebugProtocolDelegate {
47
- onBacktrace ?( backtrace : Array < Breakpoint > ) : void ;
47
+ onBacktrace ?( backtrace : JerryBacktraceResult ) : void ;
48
48
onBreakpointHit ?( message : JerryMessageBreakpointHit , stopType : string ) : void ;
49
49
onExceptionHit ?( message : JerryMessageExceptionHit ) : void ;
50
50
onEvalResult ?( subType : number , result : string ) : void ;
@@ -85,6 +85,11 @@ interface ProtocolFunctionMap {
85
85
[ type : number ] : ( data : Uint8Array ) => void ;
86
86
}
87
87
88
+ export interface JerryBacktraceResult {
89
+ totalFrames : number ;
90
+ backtrace : Array < Breakpoint > ;
91
+ }
92
+
88
93
interface FunctionMap {
89
94
[ cp : string ] : ParsedFunction ;
90
95
}
@@ -143,7 +148,7 @@ export class JerryDebugProtocolHandler {
143
148
private evalResultData ?: Uint8Array ;
144
149
private functions : FunctionMap = { } ;
145
150
private newFunctions : FunctionMap = { } ;
146
- private backtrace : Array < Breakpoint > = [ ] ;
151
+ private backtraceData : JerryBacktraceResult = { totalFrames : 0 , backtrace : [ ] } ;
147
152
148
153
private nextScriptID : number = 1 ;
149
154
private exceptionData ?: Uint8Array ;
@@ -187,6 +192,7 @@ export class JerryDebugProtocolHandler {
187
192
[ SP . SERVER . JERRY_DEBUGGER_EXCEPTION_HIT ] : this . onBreakpointHit ,
188
193
[ SP . SERVER . JERRY_DEBUGGER_EXCEPTION_STR ] : this . onExceptionStr ,
189
194
[ SP . SERVER . JERRY_DEBUGGER_EXCEPTION_STR_END ] : this . onExceptionStr ,
195
+ [ SP . SERVER . JERRY_DEBUGGER_BACKTRACE_TOTAL ] : this . onBacktrace ,
190
196
[ SP . SERVER . JERRY_DEBUGGER_BACKTRACE ] : this . onBacktrace ,
191
197
[ SP . SERVER . JERRY_DEBUGGER_BACKTRACE_END ] : this . onBacktrace ,
192
198
[ SP . SERVER . JERRY_DEBUGGER_EVAL_RESULT ] : this . onEvalResult ,
@@ -547,25 +553,26 @@ export class JerryDebugProtocolHandler {
547
553
this . lastStopType = null ;
548
554
}
549
555
550
- public onBacktrace ( data : Uint8Array ) : Breakpoint [ ] {
556
+ public onBacktrace ( data : Uint8Array ) : JerryBacktraceResult {
551
557
this . logPacket ( 'Backtrace' ) ;
552
- for ( let i = 1 ; i < data . byteLength ; i += this . byteConfig . cpointerSize + 4 ) {
553
- const breakpointData = this . decodeMessage ( 'CI' , data , i ) ;
554
- this . backtrace . push ( this . getBreakpoint ( breakpointData ) . breakpoint ) ;
558
+
559
+ if ( data [ 0 ] === SP . SERVER . JERRY_DEBUGGER_BACKTRACE_TOTAL ) {
560
+ this . backtraceData . totalFrames = this . decodeMessage ( 'I' , data , 1 ) ;
561
+ this . backtraceData . backtrace = [ ] ;
562
+ } else {
563
+ for ( let i = 1 ; i < data . byteLength ; i += this . byteConfig . cpointerSize + 4 ) {
564
+ const breakpointData = this . decodeMessage ( 'CI' , data , i ) ;
565
+ this . backtraceData . backtrace . push ( this . getBreakpoint ( breakpointData ) . breakpoint ) ;
566
+ }
555
567
}
556
568
557
569
if ( data [ 0 ] === SP . SERVER . JERRY_DEBUGGER_BACKTRACE_END ) {
558
570
if ( this . delegate . onBacktrace ) {
559
- this . delegate . onBacktrace ( this . backtrace ) ;
571
+ this . delegate . onBacktrace ( this . backtraceData ) ;
560
572
}
561
-
562
- const bt = this . backtrace ;
563
- this . backtrace = [ ] ;
564
-
565
- return bt ;
566
573
}
567
574
568
- return [ ] ;
575
+ return this . backtraceData ;
569
576
}
570
577
571
578
public onEvalResult ( data : Uint8Array ) : JerryEvalResult {
@@ -741,11 +748,21 @@ export class JerryDebugProtocolHandler {
741
748
] ) ) ;
742
749
}
743
750
744
- public requestBacktrace ( ) : Promise < any > {
751
+ public requestBacktrace ( start ?: number , levels ?: number ) : Promise < any > {
752
+ if ( start === undefined )
753
+ start = 0 ;
754
+ if ( levels === undefined )
755
+ levels = 0 ;
756
+
745
757
if ( ! this . lastBreakpointHit ) {
746
758
return Promise . reject ( new Error ( 'backtrace not allowed while app running' ) ) ;
747
759
}
748
- return this . sendRequest ( encodeMessage ( this . byteConfig , 'BI' , [ SP . CLIENT . JERRY_DEBUGGER_GET_BACKTRACE , 0 ] ) ) ;
760
+
761
+ return this . sendRequest ( encodeMessage ( this . byteConfig , 'BIIB' ,
762
+ [ SP . CLIENT . JERRY_DEBUGGER_GET_BACKTRACE ,
763
+ start ,
764
+ start + levels ,
765
+ 1 ] ) ) ;
749
766
}
750
767
751
768
logPacket ( description : string , ignorable : boolean = false ) {
0 commit comments