| 152 | } |
| 153 | |
| 154 | async logStackTrace(threadId: number, withScopes = 0) { |
| 155 | const initial = await this._dap.stackTrace({ threadId }); |
| 156 | const stack = initial.stackFrames; |
| 157 | let totalFrames = initial.totalFrames || stack.length; |
| 158 | while (stack.length < totalFrames) { |
| 159 | const response = await this._dap.stackTrace({ |
| 160 | threadId, |
| 161 | startFrame: stack.length, |
| 162 | levels: Math.min(20, totalFrames - stack.length), |
| 163 | }); |
| 164 | stack.push(...response.stackFrames); |
| 165 | if (response.totalFrames) totalFrames = Math.min(totalFrames, response.totalFrames); |
| 166 | } |
| 167 | let emptyLine = withScopes > 0; |
| 168 | for (const frame of stack) { |
| 169 | if (emptyLine) this._log(''); |
| 170 | if (frame.presentationHint === 'label') { |
| 171 | this._log(`----${frame.name}----`); |
| 172 | emptyLine = false; |
| 173 | continue; |
| 174 | } |
| 175 | const origin = frame.source && frame.source.presentationHint === 'deemphasize' |
| 176 | ? ` <hidden: ${frame.source.origin || ''}>` |
| 177 | : ''; |
| 178 | this._log( |
| 179 | `${frame.name} @ ${ |
| 180 | frame.source ? frame.source.path! : 'unknown' |
| 181 | }:${frame.line}:${frame.column}${origin}`, |
| 182 | ); |
| 183 | if (withScopes-- <= 0) continue; |
| 184 | const scopes = await this._dap.scopes({ frameId: frame.id }); |
| 185 | if (typeof scopes === 'string') { |
| 186 | this._log(` scope error: ${scopes}`); |
| 187 | } else { |
| 188 | for (let i = 0; i < scopes.scopes.length; i++) { |
| 189 | const scope = scopes.scopes[i]; |
| 190 | if (scope.expensive) { |
| 191 | this._log(` scope #${i}: ${scope.name} [expensive]`); |
| 192 | continue; |
| 193 | } |
| 194 | await this.logVariable( |
| 195 | { |
| 196 | name: 'scope #' + i, |
| 197 | value: scope.name, |
| 198 | variablesReference: scope.variablesReference, |
| 199 | namedVariables: scope.namedVariables, |
| 200 | indexedVariables: scope.indexedVariables, |
| 201 | }, |
| 202 | {}, |
| 203 | ' ', |
| 204 | ); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return stack; |
| 210 | } |
| 211 | |