@@ -18,8 +18,11 @@ class ExtendedVariable {
1818 }
1919}
2020
21+ const STACK_HANDLES_START = 1000 ;
22+ const VAR_HANDLES_START = 2000 ;
23+
2124export class MI2DebugSession extends DebugSession {
22- protected variableHandles = new Handles < any > ( ) ;
25+ protected variableHandles = new Handles < string | ExtendedVariable > ( VAR_HANDLES_START ) ;
2326 protected quit : boolean ;
2427 protected attached : boolean ;
2528 protected needContinue : boolean ;
@@ -253,7 +256,7 @@ export class MI2DebugSession extends DebugSession {
253256
254257 protected scopesRequest ( response : DebugProtocol . ScopesResponse , args : DebugProtocol . ScopesArguments ) : void {
255258 const scopes = new Array < Scope > ( ) ;
256- scopes . push ( new Scope ( "Local" , this . variableHandles . create ( "@frame:" + ( args . frameId || 0 ) ) , false ) ) ;
259+ scopes . push ( new Scope ( "Local" , STACK_HANDLES_START + ( parseInt ( args . frameId as any ) || 0 ) , false ) ) ;
257260
258261 response . body = {
259262 scopes : scopes
@@ -263,7 +266,13 @@ export class MI2DebugSession extends DebugSession {
263266
264267 protected async variablesRequest ( response : DebugProtocol . VariablesResponse , args : DebugProtocol . VariablesArguments ) : Promise < void > {
265268 const variables : DebugProtocol . Variable [ ] = [ ] ;
266- const id = this . variableHandles . get ( args . variablesReference ) ;
269+ let id : number | string | ExtendedVariable ;
270+ if ( args . variablesReference < VAR_HANDLES_START ) {
271+ id = args . variablesReference - STACK_HANDLES_START ;
272+ }
273+ else {
274+ id = this . variableHandles . get ( args . variablesReference ) ;
275+ }
267276
268277 let createVariable = ( arg , options ?) => {
269278 if ( options )
@@ -296,58 +305,56 @@ export class MI2DebugSession extends DebugSession {
296305 return res ;
297306 } ;
298307
299- if ( typeof id == "string" ) {
300- if ( id . startsWith ( "@frame:" ) ) {
301- let stack : Variable [ ] ;
302- try {
303- stack = await this . miDebugger . getStackVariables ( this . threadID , parseInt ( id . substr ( "@frame:" . length ) ) ) ;
304- for ( const variable of stack ) {
305- try {
306- const varObj = await this . miDebugger . varCreate ( variable . name ) ;
307- let v = miVarObjToVariable ( varObj . resultRecords . results ) ;
308- v . name = variable . name ;
309- variables . push ( v ) ;
310- }
311- catch ( err ) {
312- variables . push ( {
313- name : variable . name ,
314- value : err ,
315- variablesReference : 0
316- } ) ;
317- }
308+ if ( typeof id == "number" ) {
309+ let stack : Variable [ ] ;
310+ try {
311+ stack = await this . miDebugger . getStackVariables ( this . threadID , id ) ;
312+ for ( const variable of stack ) {
313+ try {
314+ const varObj = await this . miDebugger . varCreate ( variable . name ) ;
315+ let v = miVarObjToVariable ( varObj . resultRecords . results ) ;
316+ v . name = variable . name ;
317+ variables . push ( v ) ;
318+ }
319+ catch ( err ) {
320+ variables . push ( {
321+ name : variable . name ,
322+ value : `<${ err } >` ,
323+ variablesReference : 0
324+ } ) ;
318325 }
319- response . body = {
320- variables : variables
321- } ;
322- this . sendResponse ( response ) ;
323- }
324- catch ( err ) {
325- this . sendErrorResponse ( response , 1 , `Could not expand variable: ${ err } ` ) ;
326326 }
327+ response . body = {
328+ variables : variables
329+ } ;
330+ this . sendResponse ( response ) ;
327331 }
328- else {
329- // Variable members
330- let listChildren ;
331- try {
332- listChildren = await this . miDebugger . varListChildren ( id ) ;
333- const children : any [ ] = listChildren . result ( "children" ) ;
334- // TODO: use hasMore when it's > 0
335- // const hasMore = parseInt(listChildren.result("has_more"));
336- const vars = children . map ( child => miVarObjToVariable ( child [ 1 ] ) ) ;
332+ catch ( err ) {
333+ this . sendErrorResponse ( response , 1 , `Could not expand variable: ${ err } ` ) ;
334+ }
335+ }
336+ else if ( typeof id == "string" ) {
337+ // Variable members
338+ let listChildren ;
339+ try {
340+ listChildren = await this . miDebugger . varListChildren ( id ) ;
341+ const children : any [ ] = listChildren . result ( "children" ) ;
342+ // TODO: use hasMore when it's > 0
343+ // const hasMore = parseInt(listChildren.result("has_more"));
344+ const vars = children . map ( child => miVarObjToVariable ( child [ 1 ] ) ) ;
337345
338- response . body = {
339- variables : vars
340- }
341- this . sendResponse ( response ) ;
342- }
343- catch ( err ) {
344- this . sendErrorResponse ( response , 1 , `Could not expand variable: ${ err } ` ) ;
346+ response . body = {
347+ variables : vars
345348 }
349+ this . sendResponse ( response ) ;
350+ }
351+ catch ( err ) {
352+ this . sendErrorResponse ( response , 1 , `Could not expand variable: ${ err } ` ) ;
346353 }
347354 }
348355 else if ( typeof id == "object" ) {
349356 if ( id instanceof ExtendedVariable ) {
350- let varReq = < ExtendedVariable > id ;
357+ let varReq = id ;
351358 if ( varReq . options . arg ) {
352359 let strArr = [ ] ;
353360 let argsPart = true ;
0 commit comments