@theia/debug 1.45.0 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +62 -62
  2. package/lib/browser/breakpoint/breakpoint-manager.d.ts +70 -70
  3. package/lib/browser/breakpoint/breakpoint-manager.js +328 -328
  4. package/lib/browser/breakpoint/breakpoint-marker.d.ts +41 -41
  5. package/lib/browser/breakpoint/breakpoint-marker.js +87 -87
  6. package/lib/browser/console/debug-console-contribution.d.ts +40 -40
  7. package/lib/browser/console/debug-console-contribution.js +231 -231
  8. package/lib/browser/console/debug-console-items.d.ts +93 -93
  9. package/lib/browser/console/debug-console-items.js +319 -319
  10. package/lib/browser/console/debug-console-session.d.ts +31 -31
  11. package/lib/browser/console/debug-console-session.js +199 -199
  12. package/lib/browser/debug-call-stack-item-type-key.d.ts +3 -3
  13. package/lib/browser/debug-call-stack-item-type-key.js +19 -19
  14. package/lib/browser/debug-configuration-manager.d.ts +102 -102
  15. package/lib/browser/debug-configuration-manager.js +552 -552
  16. package/lib/browser/debug-configuration-model.d.ts +29 -29
  17. package/lib/browser/debug-configuration-model.js +79 -79
  18. package/lib/browser/debug-contribution.d.ts +22 -22
  19. package/lib/browser/debug-contribution.js +19 -19
  20. package/lib/browser/debug-frontend-application-contribution.d.ts +222 -222
  21. package/lib/browser/debug-frontend-application-contribution.js +1404 -1404
  22. package/lib/browser/debug-frontend-module.d.ts +4 -4
  23. package/lib/browser/debug-frontend-module.d.ts.map +1 -1
  24. package/lib/browser/debug-frontend-module.js +105 -104
  25. package/lib/browser/debug-frontend-module.js.map +1 -1
  26. package/lib/browser/debug-package.spec.js +18 -18
  27. package/lib/browser/debug-preferences.d.ts +17 -17
  28. package/lib/browser/debug-preferences.js +89 -89
  29. package/lib/browser/debug-prefix-configuration.d.ts +51 -51
  30. package/lib/browser/debug-prefix-configuration.js +208 -208
  31. package/lib/browser/debug-resource.d.ts +14 -14
  32. package/lib/browser/debug-resource.js +65 -65
  33. package/lib/browser/debug-schema-updater.d.ts +15 -15
  34. package/lib/browser/debug-schema-updater.js +168 -168
  35. package/lib/browser/debug-session-connection.d.ts +110 -110
  36. package/lib/browser/debug-session-connection.js +258 -258
  37. package/lib/browser/debug-session-contribution.d.ts +73 -73
  38. package/lib/browser/debug-session-contribution.js +145 -145
  39. package/lib/browser/debug-session-manager.d.ts +137 -137
  40. package/lib/browser/debug-session-manager.js +599 -599
  41. package/lib/browser/debug-session-manager.js.map +1 -1
  42. package/lib/browser/debug-session-options.d.ts +48 -48
  43. package/lib/browser/debug-session-options.js +85 -85
  44. package/lib/browser/debug-session.d.ts +178 -178
  45. package/lib/browser/debug-session.js +871 -871
  46. package/lib/browser/debug-tab-bar-decorator.d.ts +16 -16
  47. package/lib/browser/debug-tab-bar-decorator.js +70 -70
  48. package/lib/browser/debug-watch-manager.d.ts +21 -21
  49. package/lib/browser/debug-watch-manager.js +93 -93
  50. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.d.ts +6 -6
  51. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.js +38 -38
  52. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.d.ts +19 -19
  53. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.js +110 -110
  54. package/lib/browser/disassembly-view/disassembly-view-contribution.d.ts +24 -24
  55. package/lib/browser/disassembly-view/disassembly-view-contribution.js +131 -131
  56. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.d.ts +38 -38
  57. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.js +222 -222
  58. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.js.map +1 -1
  59. package/lib/browser/disassembly-view/disassembly-view-table-delegate.d.ts +15 -15
  60. package/lib/browser/disassembly-view/disassembly-view-table-delegate.js +38 -38
  61. package/lib/browser/disassembly-view/disassembly-view-utilities.d.ts +37 -37
  62. package/lib/browser/disassembly-view/disassembly-view-utilities.js +17 -17
  63. package/lib/browser/disassembly-view/disassembly-view-widget.d.ts +60 -60
  64. package/lib/browser/disassembly-view/disassembly-view-widget.js +453 -452
  65. package/lib/browser/disassembly-view/disassembly-view-widget.js.map +1 -1
  66. package/lib/browser/editor/debug-breakpoint-widget.d.ts +53 -53
  67. package/lib/browser/editor/debug-breakpoint-widget.js +261 -261
  68. package/lib/browser/editor/debug-editor-model.d.ts +91 -93
  69. package/lib/browser/editor/debug-editor-model.d.ts.map +1 -1
  70. package/lib/browser/editor/debug-editor-model.js +515 -516
  71. package/lib/browser/editor/debug-editor-model.js.map +1 -1
  72. package/lib/browser/editor/debug-editor-service.d.ts +35 -35
  73. package/lib/browser/editor/debug-editor-service.js +202 -202
  74. package/lib/browser/editor/debug-editor.d.ts +3 -3
  75. package/lib/browser/editor/debug-editor.js +19 -19
  76. package/lib/browser/editor/debug-exception-widget.d.ts +29 -29
  77. package/lib/browser/editor/debug-exception-widget.js +114 -114
  78. package/lib/browser/editor/debug-expression-provider.d.ts +11 -11
  79. package/lib/browser/editor/debug-expression-provider.js +81 -81
  80. package/lib/browser/editor/debug-hover-source.d.ts +18 -18
  81. package/lib/browser/editor/debug-hover-source.js +117 -117
  82. package/lib/browser/editor/debug-hover-widget.d.ts +47 -47
  83. package/lib/browser/editor/debug-hover-widget.js +276 -276
  84. package/lib/browser/editor/debug-inline-value-decorator.d.ts +19 -21
  85. package/lib/browser/editor/debug-inline-value-decorator.d.ts.map +1 -1
  86. package/lib/browser/editor/debug-inline-value-decorator.js +333 -337
  87. package/lib/browser/editor/debug-inline-value-decorator.js.map +1 -1
  88. package/lib/browser/model/debug-breakpoint.d.ts +47 -47
  89. package/lib/browser/model/debug-breakpoint.js +109 -109
  90. package/lib/browser/model/debug-function-breakpoint.d.ts +18 -18
  91. package/lib/browser/model/debug-function-breakpoint.js +92 -92
  92. package/lib/browser/model/debug-instruction-breakpoint.d.ts +14 -14
  93. package/lib/browser/model/debug-instruction-breakpoint.js +65 -65
  94. package/lib/browser/model/debug-source-breakpoint.d.ts +37 -37
  95. package/lib/browser/model/debug-source-breakpoint.js +217 -217
  96. package/lib/browser/model/debug-source.d.ts +24 -24
  97. package/lib/browser/model/debug-source.js +80 -80
  98. package/lib/browser/model/debug-stack-frame.d.ts +41 -41
  99. package/lib/browser/model/debug-stack-frame.js +150 -150
  100. package/lib/browser/model/debug-thread.d.ts +62 -62
  101. package/lib/browser/model/debug-thread.js +237 -237
  102. package/lib/browser/preferences/launch-preferences.d.ts +4 -4
  103. package/lib/browser/preferences/launch-preferences.js +38 -38
  104. package/lib/browser/view/debug-action.d.ts +16 -16
  105. package/lib/browser/view/debug-action.js +43 -43
  106. package/lib/browser/view/debug-breakpoints-source.d.ts +9 -9
  107. package/lib/browser/view/debug-breakpoints-source.js +70 -70
  108. package/lib/browser/view/debug-breakpoints-widget.d.ts +22 -22
  109. package/lib/browser/view/debug-breakpoints-widget.js +87 -87
  110. package/lib/browser/view/debug-configuration-select.d.ts +64 -64
  111. package/lib/browser/view/debug-configuration-select.js +216 -216
  112. package/lib/browser/view/debug-configuration-widget.d.ts +30 -30
  113. package/lib/browser/view/debug-configuration-widget.js +135 -135
  114. package/lib/browser/view/debug-exception-breakpoint.d.ts +14 -14
  115. package/lib/browser/view/debug-exception-breakpoint.js +61 -61
  116. package/lib/browser/view/debug-session-widget.d.ts +28 -28
  117. package/lib/browser/view/debug-session-widget.js +134 -134
  118. package/lib/browser/view/debug-stack-frames-source.d.ts +17 -17
  119. package/lib/browser/view/debug-stack-frames-source.js +89 -89
  120. package/lib/browser/view/debug-stack-frames-widget.d.ts +24 -24
  121. package/lib/browser/view/debug-stack-frames-widget.js +154 -154
  122. package/lib/browser/view/debug-threads-source.d.ts +8 -8
  123. package/lib/browser/view/debug-threads-source.js +63 -63
  124. package/lib/browser/view/debug-threads-widget.d.ts +26 -26
  125. package/lib/browser/view/debug-threads-widget.js +145 -145
  126. package/lib/browser/view/debug-toolbar-widget.d.ts +34 -34
  127. package/lib/browser/view/debug-toolbar-widget.js +156 -156
  128. package/lib/browser/view/debug-variables-source.d.ts +9 -9
  129. package/lib/browser/view/debug-variables-source.js +60 -60
  130. package/lib/browser/view/debug-variables-widget.d.ts +16 -16
  131. package/lib/browser/view/debug-variables-widget.js +78 -78
  132. package/lib/browser/view/debug-view-model.d.ts +51 -51
  133. package/lib/browser/view/debug-view-model.js +220 -220
  134. package/lib/browser/view/debug-watch-expression.d.ts +30 -30
  135. package/lib/browser/view/debug-watch-expression.js +73 -73
  136. package/lib/browser/view/debug-watch-source.d.ts +9 -9
  137. package/lib/browser/view/debug-watch-source.js +58 -58
  138. package/lib/browser/view/debug-watch-widget.d.ts +16 -16
  139. package/lib/browser/view/debug-watch-widget.js +78 -78
  140. package/lib/browser/view/debug-widget.d.ts +23 -23
  141. package/lib/browser/view/debug-widget.js +108 -108
  142. package/lib/common/debug-adapter-contribution-registry.d.ts +59 -59
  143. package/lib/common/debug-adapter-contribution-registry.js +212 -212
  144. package/lib/common/debug-adapter-session.d.ts +18 -18
  145. package/lib/common/debug-adapter-session.js +78 -78
  146. package/lib/common/debug-common.d.ts +1 -1
  147. package/lib/common/debug-common.js +29 -29
  148. package/lib/common/debug-compound.d.ts +14 -14
  149. package/lib/common/debug-compound.js +27 -27
  150. package/lib/common/debug-configuration.d.ts +70 -70
  151. package/lib/common/debug-configuration.js +31 -31
  152. package/lib/common/debug-model.d.ts +152 -152
  153. package/lib/common/debug-model.js +35 -35
  154. package/lib/common/debug-service.d.ts +123 -123
  155. package/lib/common/debug-service.js +66 -66
  156. package/lib/common/debug-uri-utils.d.ts +23 -23
  157. package/lib/common/debug-uri-utils.js +26 -26
  158. package/lib/common/inline-debug-adapter.d.ts +18 -18
  159. package/lib/common/inline-debug-adapter.js +44 -44
  160. package/lib/node/debug-adapter-factory.d.ts +19 -19
  161. package/lib/node/debug-adapter-factory.js +96 -96
  162. package/lib/node/debug-adapter-session-manager.d.ts +37 -37
  163. package/lib/node/debug-adapter-session-manager.js +111 -111
  164. package/lib/node/debug-backend-module.d.ts +3 -3
  165. package/lib/node/debug-backend-module.js +41 -41
  166. package/lib/node/debug-service-impl.d.ts +30 -30
  167. package/lib/node/debug-service-impl.js +124 -124
  168. package/lib/node/stream-debug-adapter.d.ts +36 -36
  169. package/lib/node/stream-debug-adapter.js +112 -112
  170. package/package.json +16 -16
  171. package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
  172. package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
  173. package/src/browser/console/debug-console-contribution.tsx +240 -240
  174. package/src/browser/console/debug-console-items.tsx +384 -384
  175. package/src/browser/console/debug-console-session.ts +205 -205
  176. package/src/browser/debug-call-stack-item-type-key.ts +20 -20
  177. package/src/browser/debug-configuration-manager.ts +591 -591
  178. package/src/browser/debug-configuration-model.ts +100 -100
  179. package/src/browser/debug-contribution.ts +43 -43
  180. package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
  181. package/src/browser/debug-frontend-module.ts +133 -132
  182. package/src/browser/debug-package.spec.ts +20 -20
  183. package/src/browser/debug-preferences.ts +98 -98
  184. package/src/browser/debug-prefix-configuration.ts +195 -195
  185. package/src/browser/debug-resource.ts +59 -59
  186. package/src/browser/debug-schema-updater.ts +149 -149
  187. package/src/browser/debug-session-connection.ts +357 -357
  188. package/src/browser/debug-session-contribution.ts +150 -150
  189. package/src/browser/debug-session-manager.ts +682 -682
  190. package/src/browser/debug-session-options.ts +114 -114
  191. package/src/browser/debug-session.tsx +947 -947
  192. package/src/browser/debug-tab-bar-decorator.ts +57 -57
  193. package/src/browser/debug-watch-manager.ts +93 -93
  194. package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
  195. package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
  196. package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
  197. package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
  198. package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
  199. package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
  200. package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
  201. package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
  202. package/src/browser/editor/debug-editor-model.ts +529 -528
  203. package/src/browser/editor/debug-editor-service.ts +192 -192
  204. package/src/browser/editor/debug-editor.ts +20 -20
  205. package/src/browser/editor/debug-exception-widget.tsx +122 -122
  206. package/src/browser/editor/debug-expression-provider.ts +78 -78
  207. package/src/browser/editor/debug-hover-source.tsx +105 -105
  208. package/src/browser/editor/debug-hover-widget.ts +298 -298
  209. package/src/browser/editor/debug-inline-value-decorator.ts +373 -377
  210. package/src/browser/model/debug-breakpoint.tsx +151 -151
  211. package/src/browser/model/debug-function-breakpoint.tsx +101 -101
  212. package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
  213. package/src/browser/model/debug-source-breakpoint.tsx +237 -237
  214. package/src/browser/model/debug-source.ts +93 -93
  215. package/src/browser/model/debug-stack-frame.tsx +170 -170
  216. package/src/browser/model/debug-thread.tsx +285 -285
  217. package/src/browser/preferences/launch-preferences.ts +38 -38
  218. package/src/browser/style/index.css +453 -453
  219. package/src/browser/view/debug-action.tsx +57 -57
  220. package/src/browser/view/debug-breakpoints-source.tsx +53 -53
  221. package/src/browser/view/debug-breakpoints-widget.ts +71 -71
  222. package/src/browser/view/debug-configuration-select.tsx +269 -269
  223. package/src/browser/view/debug-configuration-widget.tsx +121 -121
  224. package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
  225. package/src/browser/view/debug-session-widget.ts +124 -124
  226. package/src/browser/view/debug-stack-frames-source.tsx +75 -75
  227. package/src/browser/view/debug-stack-frames-widget.ts +135 -135
  228. package/src/browser/view/debug-threads-source.tsx +48 -48
  229. package/src/browser/view/debug-threads-widget.ts +125 -125
  230. package/src/browser/view/debug-toolbar-widget.tsx +145 -145
  231. package/src/browser/view/debug-variables-source.ts +43 -43
  232. package/src/browser/view/debug-variables-widget.ts +61 -61
  233. package/src/browser/view/debug-view-model.ts +230 -230
  234. package/src/browser/view/debug-watch-expression.tsx +88 -88
  235. package/src/browser/view/debug-watch-source.ts +41 -41
  236. package/src/browser/view/debug-watch-widget.ts +61 -61
  237. package/src/browser/view/debug-widget.ts +97 -97
  238. package/src/common/debug-adapter-contribution-registry.ts +206 -206
  239. package/src/common/debug-adapter-session.ts +102 -102
  240. package/src/common/debug-common.ts +19 -19
  241. package/src/common/debug-compound.ts +33 -33
  242. package/src/common/debug-configuration.ts +108 -108
  243. package/src/common/debug-model.ts +200 -200
  244. package/src/common/debug-service.ts +184 -184
  245. package/src/common/debug-uri-utils.ts +24 -24
  246. package/src/common/inline-debug-adapter.ts +47 -47
  247. package/src/node/debug-adapter-factory.ts +107 -107
  248. package/src/node/debug-adapter-session-manager.ts +106 -106
  249. package/src/node/debug-backend-module.ts +57 -57
  250. package/src/node/debug-service-impl.ts +119 -119
  251. package/src/node/stream-debug-adapter.ts +126 -126
@@ -1,947 +1,947 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Red Hat, Inc. and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* eslint-disable @typescript-eslint/no-explicit-any */
18
-
19
- import * as React from '@theia/core/shared/react';
20
- import { LabelProvider } from '@theia/core/lib/browser';
21
- import { DebugProtocol } from '@vscode/debugprotocol';
22
- import { Emitter, Event, DisposableCollection, Disposable, MessageClient, MessageType, Mutable, ContributionProvider } from '@theia/core/lib/common';
23
- import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
24
- import { EditorManager } from '@theia/editor/lib/browser';
25
- import { CompositeTreeElement } from '@theia/core/lib/browser/source-tree';
26
- import { DebugSessionConnection, DebugRequestTypes, DebugEventTypes } from './debug-session-connection';
27
- import { DebugThread, StoppedDetails, DebugThreadData } from './model/debug-thread';
28
- import { DebugScope } from './console/debug-console-items';
29
- import { DebugStackFrame } from './model/debug-stack-frame';
30
- import { DebugSource } from './model/debug-source';
31
- import { DebugBreakpoint, DebugBreakpointOptions } from './model/debug-breakpoint';
32
- import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
33
- import debounce = require('p-debounce');
34
- import URI from '@theia/core/lib/common/uri';
35
- import { BreakpointManager } from './breakpoint/breakpoint-manager';
36
- import { DebugConfigurationSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
37
- import { DebugConfiguration, DebugConsoleMode } from '../common/debug-common';
38
- import { SourceBreakpoint, ExceptionBreakpoint } from './breakpoint/breakpoint-marker';
39
- import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
40
- import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
41
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
42
- import { DebugContribution } from './debug-contribution';
43
- import { Deferred, waitForEvent } from '@theia/core/lib/common/promise-util';
44
- import { WorkspaceService } from '@theia/workspace/lib/browser';
45
- import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
46
- import { nls } from '@theia/core';
47
-
48
- export enum DebugState {
49
- Inactive,
50
- Initializing,
51
- Running,
52
- Stopped
53
- }
54
- /**
55
- * The mapped string values must not change as they are used for the `debugState` when context closure.
56
- * For more details see the `Debugger contexts` section of the [official doc](https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts).
57
- */
58
- export function debugStateContextValue(state: DebugState): string {
59
- switch (state) {
60
- case DebugState.Initializing: return 'initializing';
61
- case DebugState.Stopped: return 'stopped';
62
- case DebugState.Running: return 'running';
63
- default: return 'inactive';
64
- }
65
- }
66
-
67
- // FIXME: make injectable to allow easily inject services
68
- export class DebugSession implements CompositeTreeElement {
69
- protected readonly deferredOnDidConfigureCapabilities = new Deferred<void>();
70
-
71
- protected readonly onDidChangeEmitter = new Emitter<void>();
72
- readonly onDidChange: Event<void> = this.onDidChangeEmitter.event;
73
- protected fireDidChange(): void {
74
- this.onDidChangeEmitter.fire(undefined);
75
- }
76
- protected readonly onDidFocusStackFrameEmitter = new Emitter<DebugStackFrame | undefined>();
77
- get onDidFocusStackFrame(): Event<DebugStackFrame | undefined> {
78
- return this.onDidFocusStackFrameEmitter.event;
79
- }
80
-
81
- protected readonly onDidChangeBreakpointsEmitter = new Emitter<URI>();
82
- readonly onDidChangeBreakpoints: Event<URI> = this.onDidChangeBreakpointsEmitter.event;
83
- protected fireDidChangeBreakpoints(uri: URI): void {
84
- this.onDidChangeBreakpointsEmitter.fire(uri);
85
- }
86
-
87
- protected readonly childSessions = new Map<string, DebugSession>();
88
- protected readonly toDispose = new DisposableCollection();
89
-
90
- protected isStopping: boolean = false;
91
-
92
- constructor(
93
- readonly id: string,
94
- readonly options: DebugConfigurationSessionOptions,
95
- readonly parentSession: DebugSession | undefined,
96
- protected readonly connection: DebugSessionConnection,
97
- protected readonly terminalServer: TerminalService,
98
- protected readonly editorManager: EditorManager,
99
- protected readonly breakpoints: BreakpointManager,
100
- protected readonly labelProvider: LabelProvider,
101
- protected readonly messages: MessageClient,
102
- protected readonly fileService: FileService,
103
- protected readonly debugContributionProvider: ContributionProvider<DebugContribution>,
104
- protected readonly workspaceService: WorkspaceService,
105
- /**
106
- * Number of millis after a `stop` request times out. It's 5 seconds by default.
107
- */
108
- protected readonly stopTimeout = 5_000,
109
- ) {
110
- this.connection.onRequest('runInTerminal', (request: DebugProtocol.RunInTerminalRequest) => this.runInTerminal(request));
111
- this.connection.onDidClose(() => {
112
- this.toDispose.dispose();
113
- });
114
- this.registerDebugContributions(options.configuration.type, this.connection);
115
-
116
- if (parentSession) {
117
- parentSession.childSessions.set(id, this);
118
- this.toDispose.push(Disposable.create(() => {
119
- this.parentSession?.childSessions?.delete(id);
120
- }));
121
- }
122
- this.connection.onDidClose(() => this.toDispose.dispose());
123
- this.toDispose.pushAll([
124
- this.onDidChangeEmitter,
125
- this.onDidChangeBreakpointsEmitter,
126
- Disposable.create(() => {
127
- this.clearBreakpoints();
128
- this.doUpdateThreads([]);
129
- }),
130
- this.connection,
131
- this.connection.on('initialized', () => this.configure()),
132
- this.connection.on('breakpoint', ({ body }) => this.updateBreakpoint(body)),
133
- this.connection.on('continued', e => this.handleContinued(e)),
134
- this.connection.on('stopped', e => this.handleStopped(e)),
135
- this.connection.on('thread', e => this.handleThread(e)),
136
- this.connection.on('capabilities', event => this.updateCapabilities(event.body.capabilities)),
137
- this.breakpoints.onDidChangeMarkers(uri => this.updateBreakpoints({ uri, sourceModified: true }))
138
- ]);
139
- }
140
-
141
- get onDispose(): Event<void> {
142
- return this.toDispose.onDispose;
143
- }
144
-
145
- get configuration(): DebugConfiguration {
146
- return this.options.configuration;
147
- }
148
-
149
- protected _capabilities: DebugProtocol.Capabilities = {};
150
- get capabilities(): DebugProtocol.Capabilities {
151
- return this._capabilities;
152
- }
153
-
154
- protected readonly sources = new Map<string, DebugSource>();
155
- getSource(raw: DebugProtocol.Source): DebugSource {
156
- const uri = DebugSource.toUri(raw).toString();
157
- const source = this.sources.get(uri) || new DebugSource(this, this.editorManager, this.labelProvider);
158
- source.update({ raw });
159
- this.sources.set(uri, source);
160
- return source;
161
- }
162
-
163
- getSourceForUri(uri: URI): DebugSource | undefined {
164
- return this.sources.get(uri.toString());
165
- }
166
-
167
- async toSource(uri: URI): Promise<DebugSource> {
168
- const source = this.getSourceForUri(uri);
169
- if (source) {
170
- return source;
171
- }
172
-
173
- return this.getSource(await this.toDebugSource(uri));
174
- }
175
-
176
- async toDebugSource(uri: URI): Promise<DebugProtocol.Source> {
177
- if (uri.scheme === DebugSource.SCHEME) {
178
- return {
179
- name: uri.path.toString(),
180
- sourceReference: Number(uri.query)
181
- };
182
- }
183
- const name = uri.displayName;
184
- let path;
185
- const underlying = await this.fileService.toUnderlyingResource(uri);
186
- if (underlying.scheme === 'file') {
187
- path = await this.fileService.fsPath(underlying);
188
- } else {
189
- path = uri.toString();
190
- }
191
- return { name, path };
192
- }
193
-
194
- protected _threads = new Map<number, DebugThread>();
195
- get threads(): IterableIterator<DebugThread> {
196
- return this._threads.values();
197
- }
198
-
199
- get threadCount(): number {
200
- return this._threads.size;
201
- }
202
-
203
- *getThreads(filter: (thread: DebugThread) => boolean): IterableIterator<DebugThread> {
204
- for (const thread of this.threads) {
205
- if (filter(thread)) {
206
- yield thread;
207
- }
208
- }
209
- }
210
-
211
- get runningThreads(): IterableIterator<DebugThread> {
212
- return this.getThreads(thread => !thread.stopped);
213
- }
214
-
215
- get stoppedThreads(): IterableIterator<DebugThread> {
216
- return this.getThreads(thread => thread.stopped);
217
- }
218
-
219
- async pauseAll(): Promise<void> {
220
- const promises: Promise<void>[] = [];
221
- for (const thread of this.runningThreads) {
222
- promises.push((async () => {
223
- try {
224
- await thread.pause();
225
- } catch (e) {
226
- console.error('pauseAll failed:', e);
227
- }
228
- })());
229
- }
230
- await Promise.all(promises);
231
- }
232
-
233
- async continueAll(): Promise<void> {
234
- const promises: Promise<void>[] = [];
235
- for (const thread of this.stoppedThreads) {
236
- promises.push((async () => {
237
- try {
238
- await thread.continue();
239
- } catch (e) {
240
- console.error('continueAll failed:', e);
241
- }
242
- })());
243
- }
244
- await Promise.all(promises);
245
- }
246
-
247
- get currentFrame(): DebugStackFrame | undefined {
248
- return this.currentThread && this.currentThread.currentFrame;
249
- }
250
-
251
- protected _currentThread: DebugThread | undefined;
252
- protected readonly toDisposeOnCurrentThread = new DisposableCollection();
253
- get currentThread(): DebugThread | undefined {
254
- return this._currentThread;
255
- }
256
- set currentThread(thread: DebugThread | undefined) {
257
- this.toDisposeOnCurrentThread.dispose();
258
- this._currentThread = thread;
259
- this.fireDidChange();
260
- if (thread) {
261
- this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));
262
- this.toDisposeOnCurrentThread.push(thread.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
263
-
264
- // If this thread is missing stack frame information, then load that.
265
- this.updateFrames();
266
- }
267
- }
268
-
269
- get state(): DebugState {
270
- if (this.connection.disposed) {
271
- return DebugState.Inactive;
272
- }
273
- if (!this.initialized) {
274
- return DebugState.Initializing;
275
- }
276
- const thread = this.currentThread;
277
- if (thread) {
278
- return thread.stopped ? DebugState.Stopped : DebugState.Running;
279
- }
280
- return !!this.stoppedThreads.next().value ? DebugState.Stopped : DebugState.Running;
281
- }
282
-
283
- async getScopes(): Promise<DebugScope[]> {
284
- const { currentFrame } = this;
285
- return currentFrame ? currentFrame.getScopes() : [];
286
- }
287
-
288
- async start(): Promise<void> {
289
- await this.initialize();
290
- await this.launchOrAttach();
291
- }
292
-
293
- protected async initialize(): Promise<void> {
294
- try {
295
- const response = await this.connection.sendRequest('initialize', {
296
- clientID: 'Theia',
297
- clientName: 'Theia IDE',
298
- adapterID: this.configuration.type,
299
- locale: 'en-US',
300
- linesStartAt1: true,
301
- columnsStartAt1: true,
302
- pathFormat: 'path',
303
- supportsVariableType: false,
304
- supportsVariablePaging: false,
305
- supportsRunInTerminalRequest: true
306
- });
307
- this.updateCapabilities(response?.body || {});
308
- this.didReceiveCapabilities.resolve();
309
- } catch (err) {
310
- this.didReceiveCapabilities.reject(err);
311
- throw err;
312
- }
313
- }
314
-
315
- protected async launchOrAttach(): Promise<void> {
316
- try {
317
- await this.sendRequest((this.configuration.request as keyof DebugRequestTypes), this.configuration);
318
- } catch (reason) {
319
- this.messages.showMessage({
320
- type: MessageType.Error,
321
- text: reason.message || 'Debug session initialization failed. See console for details.',
322
- options: {
323
- timeout: 10000
324
- }
325
- });
326
- throw reason;
327
- }
328
- }
329
-
330
- /**
331
- * The `send('initialize')` request could resolve later than `on('initialized')` emits the event.
332
- * Hence, the `configure` would use the empty object `capabilities`.
333
- * Using the empty `capabilities` could result in missing exception breakpoint filters, as
334
- * always `capabilities.exceptionBreakpointFilters` is falsy. This deferred promise works
335
- * around this timing issue. https://github.com/eclipse-theia/theia/issues/11886
336
- */
337
- protected didReceiveCapabilities = new Deferred<void>();
338
- protected initialized = false;
339
- protected async configure(): Promise<void> {
340
- await this.didReceiveCapabilities.promise;
341
- if (this.capabilities.exceptionBreakpointFilters) {
342
- const exceptionBreakpoints = [];
343
- for (const filter of this.capabilities.exceptionBreakpointFilters) {
344
- const origin = this.breakpoints.getExceptionBreakpoint(filter.filter);
345
- exceptionBreakpoints.push(ExceptionBreakpoint.create(filter, origin));
346
- }
347
- this.breakpoints.setExceptionBreakpoints(exceptionBreakpoints);
348
- }
349
- await this.updateBreakpoints({ sourceModified: false });
350
- if (this.capabilities.supportsConfigurationDoneRequest) {
351
- await this.sendRequest('configurationDone', {});
352
- }
353
- this.initialized = true;
354
- await this.updateThreads(undefined);
355
- }
356
-
357
- canTerminate(): boolean {
358
- return !!this.capabilities.supportsTerminateRequest;
359
- }
360
-
361
- canRestart(): boolean {
362
- return !!this.capabilities.supportsRestartRequest;
363
- }
364
-
365
- async restart(): Promise<void> {
366
- if (this.canRestart()) {
367
- await this.sendRequest('restart', {});
368
- }
369
- }
370
-
371
- async stop(isRestart: boolean, callback: () => void): Promise<void> {
372
- if (!this.isStopping) {
373
- this.isStopping = true;
374
- if (this.canTerminate()) {
375
- const terminated = this.waitFor('terminated', this.stopTimeout);
376
- try {
377
- await this.connection.sendRequest('terminate', { restart: isRestart }, this.stopTimeout);
378
- await terminated;
379
- } catch (e) {
380
- this.handleTerminateError(e);
381
- }
382
- } else {
383
- const terminateDebuggee = this.initialized && this.capabilities.supportTerminateDebuggee;
384
- try {
385
- await this.sendRequest('disconnect', { restart: isRestart, terminateDebuggee }, this.stopTimeout);
386
- } catch (e) {
387
- this.handleDisconnectError(e);
388
- }
389
- }
390
- callback();
391
- }
392
- }
393
-
394
- /**
395
- * Invoked when sending the `terminate` request to the debugger is rejected or timed out.
396
- */
397
- protected handleTerminateError(err: unknown): void {
398
- console.error('Did not receive terminated event in time', err);
399
- }
400
-
401
- /**
402
- * Invoked when sending the `disconnect` request to the debugger is rejected or timed out.
403
- */
404
- protected handleDisconnectError(err: unknown): void {
405
- console.error('Error on disconnect', err);
406
- }
407
-
408
- async disconnect(isRestart: boolean, callback: () => void): Promise<void> {
409
- if (!this.isStopping) {
410
- this.isStopping = true;
411
- await this.sendRequest('disconnect', { restart: isRestart });
412
- callback();
413
- }
414
- }
415
-
416
- async completions(text: string, column: number, line: number): Promise<DebugProtocol.CompletionItem[]> {
417
- const frameId = this.currentFrame && this.currentFrame.raw.id;
418
- const response = await this.sendRequest('completions', { frameId, text, column, line });
419
- return response.body.targets;
420
- }
421
-
422
- async evaluate(expression: string, context?: string): Promise<DebugProtocol.EvaluateResponse['body']> {
423
- const frameId = this.currentFrame && this.currentFrame.raw.id;
424
- const response = await this.sendRequest('evaluate', { expression, frameId, context });
425
- return response.body;
426
- }
427
-
428
- sendRequest<K extends keyof DebugRequestTypes>(command: K, args: DebugRequestTypes[K][0], timeout?: number): Promise<DebugRequestTypes[K][1]> {
429
- return this.connection.sendRequest(command, args, timeout);
430
- }
431
-
432
- sendCustomRequest<T extends DebugProtocol.Response>(command: string, args?: any): Promise<T> {
433
- return this.connection.sendCustomRequest(command, args);
434
- }
435
-
436
- on<K extends keyof DebugEventTypes>(kind: K, listener: (e: DebugEventTypes[K]) => any): Disposable {
437
- return this.connection.on(kind, listener);
438
- }
439
-
440
- waitFor<K extends keyof DebugEventTypes>(kind: K, ms: number): Promise<void> {
441
- return waitForEvent(this.connection.onEvent(kind), ms).then();
442
- }
443
-
444
- get onDidCustomEvent(): Event<DebugProtocol.Event> {
445
- return this.connection.onDidCustomEvent;
446
- }
447
-
448
- protected async runInTerminal({ arguments: { title, cwd, args, env } }: DebugProtocol.RunInTerminalRequest): Promise<DebugProtocol.RunInTerminalResponse['body']> {
449
- const terminal = await this.doCreateTerminal({ title, cwd, env, useServerTitle: false });
450
- const { processId } = terminal;
451
- await terminal.executeCommand({ cwd, args, env });
452
- return { processId: await processId };
453
- }
454
-
455
- protected async doCreateTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
456
- let terminal = undefined;
457
- for (const t of this.terminalServer.all) {
458
- if ((t.title.label === options.title || t.title.caption === options.title) && (await t.hasChildProcesses()) === false) {
459
- terminal = t;
460
- break;
461
- }
462
- }
463
-
464
- if (!terminal) {
465
- terminal = await this.terminalServer.newTerminal(options);
466
- await terminal.start();
467
- }
468
- this.terminalServer.open(terminal);
469
- return terminal;
470
- }
471
-
472
- protected clearThreads(): void {
473
- for (const thread of this.threads) {
474
- thread.clear();
475
- }
476
- this.updateCurrentThread();
477
- }
478
-
479
- protected clearThread(threadId: number): void {
480
- const thread = this._threads.get(threadId);
481
- if (thread) {
482
- thread.clear();
483
- }
484
- this.updateCurrentThread();
485
- }
486
-
487
- protected readonly scheduleUpdateThreads = debounce(() => this.updateThreads(undefined), 100);
488
- protected pendingThreads = Promise.resolve();
489
-
490
- updateThreads(stoppedDetails: StoppedDetails | undefined): Promise<void> {
491
- return this.pendingThreads = this.pendingThreads.then(async () => {
492
- try {
493
- const response = await this.sendRequest('threads', {});
494
- // java debugger returns an empty body sometimes
495
- const threads = response && response.body && response.body.threads || [];
496
- this.doUpdateThreads(threads, stoppedDetails);
497
- } catch (e) {
498
- console.error('updateThreads failed:', e);
499
- }
500
- });
501
- }
502
-
503
- protected doUpdateThreads(threads: DebugProtocol.Thread[], stoppedDetails?: StoppedDetails): void {
504
- const existing = this._threads;
505
- this._threads = new Map();
506
- for (const raw of threads) {
507
- const id = raw.id;
508
- const thread = existing.get(id) || new DebugThread(this);
509
- this._threads.set(id, thread);
510
- const data: Partial<Mutable<DebugThreadData>> = { raw };
511
- if (stoppedDetails) {
512
- if (stoppedDetails.threadId === id) {
513
- data.stoppedDetails = stoppedDetails;
514
- } else if (stoppedDetails.allThreadsStopped) {
515
- data.stoppedDetails = {
516
- // When a debug adapter notifies us that all threads are stopped,
517
- // we do not know why the others are stopped, so we should default
518
- // to something generic.
519
- reason: '',
520
- };
521
- }
522
- }
523
- thread.update(data);
524
- }
525
- this.updateCurrentThread(stoppedDetails);
526
- }
527
-
528
- protected updateCurrentThread(stoppedDetails?: StoppedDetails): void {
529
- const { currentThread } = this;
530
- let threadId = currentThread && currentThread.raw.id;
531
- if (stoppedDetails && !stoppedDetails.preserveFocusHint && !!stoppedDetails.threadId) {
532
- threadId = stoppedDetails.threadId;
533
- }
534
- this.currentThread = typeof threadId === 'number' && this._threads.get(threadId)
535
- || this._threads.values().next().value;
536
- }
537
-
538
- protected async updateFrames(): Promise<void> {
539
- const thread = this._currentThread;
540
- if (!thread || thread.pendingFrameCount || thread.frameCount) {
541
- return;
542
- }
543
- if (this.capabilities.supportsDelayedStackTraceLoading) {
544
- await thread.fetchFrames(1);
545
- await thread.fetchFrames(19);
546
- } else {
547
- await thread.fetchFrames();
548
- }
549
- }
550
-
551
- protected updateCapabilities(capabilities: DebugProtocol.Capabilities): void {
552
- Object.assign(this._capabilities, capabilities);
553
- this.deferredOnDidConfigureCapabilities.resolve();
554
- }
555
-
556
- protected readonly _breakpoints = new Map<string, DebugBreakpoint[]>();
557
- get breakpointUris(): IterableIterator<string> {
558
- return this._breakpoints.keys();
559
- }
560
-
561
- getSourceBreakpoints(uri?: URI): DebugSourceBreakpoint[] {
562
- const breakpoints = [];
563
- for (const breakpoint of this.getBreakpoints(uri)) {
564
- if (breakpoint instanceof DebugSourceBreakpoint) {
565
- breakpoints.push(breakpoint);
566
- }
567
- }
568
- return breakpoints;
569
- }
570
-
571
- getFunctionBreakpoints(): DebugFunctionBreakpoint[] {
572
- return this.getBreakpoints(BreakpointManager.FUNCTION_URI).filter((breakpoint): breakpoint is DebugFunctionBreakpoint => breakpoint instanceof DebugFunctionBreakpoint);
573
- }
574
-
575
- getInstructionBreakpoints(): DebugInstructionBreakpoint[] {
576
- if (this.capabilities.supportsInstructionBreakpoints) {
577
- return this.getBreakpoints(BreakpointManager.INSTRUCTION_URI)
578
- .filter((breakpoint): breakpoint is DebugInstructionBreakpoint => breakpoint instanceof DebugInstructionBreakpoint);
579
- }
580
- return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, this.asDebugBreakpointOptions()));
581
- }
582
-
583
- getBreakpoints(uri?: URI): DebugBreakpoint[] {
584
- if (uri) {
585
- return this._breakpoints.get(uri.toString()) || [];
586
- }
587
- const result = [];
588
- for (const breakpoints of this._breakpoints.values()) {
589
- result.push(...breakpoints);
590
- }
591
- return result;
592
- }
593
-
594
- getBreakpoint(id: string): DebugBreakpoint | undefined {
595
- for (const breakpoints of this._breakpoints.values()) {
596
- const breakpoint = breakpoints.find(b => b.id === id);
597
- if (breakpoint) {
598
- return breakpoint;
599
- }
600
-
601
- }
602
- return undefined;
603
- }
604
-
605
- protected clearBreakpoints(): void {
606
- const uris = [...this._breakpoints.keys()];
607
- this._breakpoints.clear();
608
- for (const uri of uris) {
609
- this.fireDidChangeBreakpoints(new URI(uri));
610
- }
611
- }
612
-
613
- protected updatingBreakpoints = false;
614
-
615
- protected updateBreakpoint(body: DebugProtocol.BreakpointEvent['body']): void {
616
- this.updatingBreakpoints = true;
617
- try {
618
- const raw = body.breakpoint;
619
- if (body.reason === 'new') {
620
- if (raw.source && typeof raw.line === 'number') {
621
- const uri = DebugSource.toUri(raw.source);
622
- const origin = SourceBreakpoint.create(uri, { line: raw.line, column: raw.column });
623
- if (this.breakpoints.addBreakpoint(origin)) {
624
- const breakpoints = this.getSourceBreakpoints(uri);
625
- const breakpoint = new DebugSourceBreakpoint(origin, this.asDebugBreakpointOptions());
626
- breakpoint.update({ raw });
627
- breakpoints.push(breakpoint);
628
- this.setSourceBreakpoints(uri, breakpoints);
629
- }
630
- }
631
- }
632
- if (body.reason === 'removed' && raw.id) {
633
- const toRemove = this.findBreakpoint(b => b.idFromAdapter === raw.id);
634
- if (toRemove) {
635
- toRemove.remove();
636
- const breakpoints = this.getBreakpoints(toRemove.uri);
637
- const index = breakpoints.indexOf(toRemove);
638
- if (index !== -1) {
639
- breakpoints.splice(index, 1);
640
- this.setBreakpoints(toRemove.uri, breakpoints);
641
- }
642
- }
643
- }
644
- if (body.reason === 'changed' && raw.id) {
645
- const toUpdate = this.findBreakpoint(b => b.idFromAdapter === raw.id);
646
- if (toUpdate) {
647
- toUpdate.update({ raw });
648
- if (toUpdate instanceof DebugSourceBreakpoint) {
649
- const sourceBreakpoints = this.getSourceBreakpoints(toUpdate.uri);
650
- // in order to dedup again if a debugger converted line breakpoint to inline breakpoint
651
- // i.e. assigned a column to a line breakpoint
652
- this.setSourceBreakpoints(toUpdate.uri, sourceBreakpoints);
653
- } else {
654
- this.fireDidChangeBreakpoints(toUpdate.uri);
655
- }
656
- }
657
- }
658
- } finally {
659
- this.updatingBreakpoints = false;
660
- }
661
- }
662
- protected findBreakpoint(match: (breakpoint: DebugBreakpoint) => boolean): DebugBreakpoint | undefined {
663
- for (const [, breakpoints] of this._breakpoints) {
664
- for (const breakpoint of breakpoints) {
665
- if (match(breakpoint)) {
666
- return breakpoint;
667
- }
668
- }
669
- }
670
- return undefined;
671
- }
672
-
673
- protected async updateBreakpoints(options: {
674
- uri?: URI,
675
- sourceModified: boolean
676
- }): Promise<void> {
677
- if (this.updatingBreakpoints) {
678
- return;
679
- }
680
- const { uri, sourceModified } = options;
681
- await this.deferredOnDidConfigureCapabilities.promise;
682
- for (const affectedUri of this.getAffectedUris(uri)) {
683
- if (affectedUri.toString() === BreakpointManager.EXCEPTION_URI.toString()) {
684
- await this.sendExceptionBreakpoints();
685
- } else if (affectedUri.toString() === BreakpointManager.FUNCTION_URI.toString()) {
686
- await this.sendFunctionBreakpoints(affectedUri);
687
- } else if (affectedUri.toString() === BreakpointManager.INSTRUCTION_URI.toString()) {
688
- await this.sendInstructionBreakpoints();
689
- } else {
690
- await this.sendSourceBreakpoints(affectedUri, sourceModified);
691
- }
692
- }
693
- }
694
-
695
- protected async sendExceptionBreakpoints(): Promise<void> {
696
- const filters: string[] = [];
697
- const filterOptions: DebugProtocol.ExceptionFilterOptions[] | undefined = this.capabilities.supportsExceptionFilterOptions ? [] : undefined;
698
- for (const breakpoint of this.breakpoints.getExceptionBreakpoints()) {
699
- if (breakpoint.enabled) {
700
- if (filterOptions) {
701
- filterOptions.push({
702
- filterId: breakpoint.raw.filter,
703
- condition: breakpoint.condition
704
- });
705
- } else {
706
- filters.push(breakpoint.raw.filter);
707
- }
708
- }
709
- }
710
- await this.sendRequest('setExceptionBreakpoints', { filters, filterOptions });
711
- }
712
-
713
- protected async sendFunctionBreakpoints(affectedUri: URI): Promise<void> {
714
- const all = this.breakpoints.getFunctionBreakpoints().map(origin =>
715
- new DebugFunctionBreakpoint(origin, this.asDebugBreakpointOptions())
716
- );
717
- const enabled = all.filter(b => b.enabled);
718
- if (this.capabilities.supportsFunctionBreakpoints) {
719
- try {
720
- const response = await this.sendRequest('setFunctionBreakpoints', {
721
- breakpoints: enabled.map(b => b.origin.raw)
722
- });
723
- // Apparently, `body` and `breakpoints` can be missing.
724
- // https://github.com/eclipse-theia/theia/issues/11885
725
- // https://github.com/microsoft/vscode/blob/80004351ccf0884b58359f7c8c801c91bb827d83/src/vs/workbench/contrib/debug/browser/debugSession.ts#L448-L449
726
- if (response && response.body) {
727
- response.body.breakpoints.forEach((raw, index) => {
728
- // node debug adapter returns more breakpoints sometimes
729
- if (enabled[index]) {
730
- enabled[index].update({ raw });
731
- }
732
- });
733
- }
734
- } catch (error) {
735
- // could be error or promise rejection of DebugProtocol.SetFunctionBreakpoints
736
- if (error instanceof Error) {
737
- console.error(`Error setting breakpoints: ${error.message}`);
738
- } else {
739
- // handle adapters that send failed DebugProtocol.SetFunctionBreakpoints for invalid breakpoints
740
- const genericMessage: string = 'Function breakpoint not valid for current debug session';
741
- const message: string = error.message ? `${error.message}` : genericMessage;
742
- console.warn(`Could not handle function breakpoints: ${message}, disabling...`);
743
- enabled.forEach(b => b.update({
744
- raw: {
745
- verified: false,
746
- message
747
- }
748
- }));
749
- }
750
- }
751
- }
752
- this.setBreakpoints(affectedUri, all);
753
- }
754
-
755
- protected async sendSourceBreakpoints(affectedUri: URI, sourceModified?: boolean): Promise<void> {
756
- const source = await this.toSource(affectedUri);
757
- const all = this.breakpoints.findMarkers({ uri: affectedUri }).map(({ data }) =>
758
- new DebugSourceBreakpoint(data, this.asDebugBreakpointOptions())
759
- );
760
- const enabled = all.filter(b => b.enabled);
761
- try {
762
- const breakpoints = enabled.map(({ origin }) => origin.raw);
763
- const response = await this.sendRequest('setBreakpoints', {
764
- source: source.raw,
765
- sourceModified,
766
- breakpoints,
767
- lines: breakpoints.map(({ line }) => line)
768
- });
769
- response.body.breakpoints.forEach((raw, index) => {
770
- // node debug adapter returns more breakpoints sometimes
771
- if (enabled[index]) {
772
- enabled[index].update({ raw });
773
- }
774
- });
775
- } catch (error) {
776
- // could be error or promise rejection of DebugProtocol.SetBreakpointsResponse
777
- if (error instanceof Error) {
778
- console.error(`Error setting breakpoints: ${error.message}`);
779
- } else {
780
- // handle adapters that send failed DebugProtocol.SetBreakpointsResponse for invalid breakpoints
781
- const genericMessage: string = 'Breakpoint not valid for current debug session';
782
- const message: string = error.message ? `${error.message}` : genericMessage;
783
- console.warn(`Could not handle breakpoints for ${affectedUri}: ${message}, disabling...`);
784
- enabled.forEach(b => b.update({
785
- raw: {
786
- verified: false,
787
- message
788
- }
789
- }));
790
- }
791
- }
792
- this.setSourceBreakpoints(affectedUri, all);
793
- }
794
-
795
- protected async sendInstructionBreakpoints(): Promise<void> {
796
- if (!this.capabilities.supportsInstructionBreakpoints) {
797
- return;
798
- }
799
- const all = this.breakpoints.getInstructionBreakpoints().map(breakpoint => new DebugInstructionBreakpoint(breakpoint, this.asDebugBreakpointOptions()));
800
- const enabled = all.filter(breakpoint => breakpoint.enabled);
801
- try {
802
- const response = await this.sendRequest('setInstructionBreakpoints', {
803
- breakpoints: enabled.map(renderable => renderable.origin),
804
- });
805
- response.body.breakpoints.forEach((raw, index) => enabled[index]?.update({ raw }));
806
- } catch {
807
- enabled.forEach(breakpoint => breakpoint.update({ raw: { verified: false } }));
808
- }
809
- this.setBreakpoints(BreakpointManager.INSTRUCTION_URI, all);
810
- }
811
-
812
- protected setBreakpoints(uri: URI, breakpoints: DebugBreakpoint[]): void {
813
- this._breakpoints.set(uri.toString(), breakpoints);
814
- this.fireDidChangeBreakpoints(uri);
815
- }
816
-
817
- protected setSourceBreakpoints(uri: URI, breakpoints: DebugSourceBreakpoint[]): void {
818
- const distinct = this.dedupSourceBreakpoints(breakpoints);
819
- this.setBreakpoints(uri, distinct);
820
- }
821
-
822
- protected dedupSourceBreakpoints(all: DebugSourceBreakpoint[]): DebugSourceBreakpoint[] {
823
- const positions = new Map<string, DebugSourceBreakpoint>();
824
- for (const breakpoint of all) {
825
- let primary = positions.get(breakpoint.renderPosition()) || breakpoint;
826
- if (primary !== breakpoint) {
827
- let secondary = breakpoint;
828
- if (secondary.raw && secondary.raw.line === secondary.origin.raw.line && secondary.raw.column === secondary.origin.raw.column) {
829
- [primary, secondary] = [breakpoint, primary];
830
- }
831
- primary.origins.push(...secondary.origins);
832
- }
833
- positions.set(primary.renderPosition(), primary);
834
- }
835
- return [...positions.values()];
836
- }
837
-
838
- protected *getAffectedUris(uri?: URI): IterableIterator<URI> {
839
- if (uri) {
840
- yield uri;
841
- } else {
842
- for (const uriString of this.breakpoints.getUris()) {
843
- yield new URI(uriString);
844
- }
845
- yield BreakpointManager.FUNCTION_URI;
846
- yield BreakpointManager.EXCEPTION_URI;
847
- }
848
- }
849
-
850
- protected asDebugBreakpointOptions(): DebugBreakpointOptions {
851
- const { labelProvider, breakpoints, editorManager } = this;
852
- return { labelProvider, breakpoints, editorManager, session: this };
853
- }
854
-
855
- get label(): string {
856
- const suffixes = [];
857
- if (InternalDebugSessionOptions.is(this.options) && this.options.id) {
858
- suffixes.push(String(this.options.id + 1));
859
- }
860
- if (this.workspaceService.isMultiRootWorkspaceOpened && this.options.workspaceFolderUri) {
861
- suffixes.push(this.labelProvider.getName(new URI(this.options.workspaceFolderUri)));
862
- }
863
- return suffixes.length === 0 ? this.configuration.name : this.configuration.name + ` (${suffixes.join(' - ')})`;
864
- }
865
-
866
- get visible(): boolean {
867
- return this.state > DebugState.Inactive;
868
- }
869
-
870
- render(): React.ReactNode {
871
- let label = '';
872
- const state = this.state === DebugState.Stopped ? nls.localizeByDefault('Paused') : nls.localizeByDefault('Running');
873
- const child = this.getSingleChildSession();
874
- if (child && child.configuration.compact) {
875
- // Inlines the name of the child debug session
876
- label = `: ${child.label}`;
877
- }
878
- return <div className='theia-debug-session' title='Session'>
879
- <span className='label'>{this.label + label}</span>
880
- <span className='status'>{state}</span>
881
- </div>;
882
- }
883
-
884
- *getElements(): IterableIterator<DebugThread | DebugSession> {
885
- const child = this.getSingleChildSession();
886
- if (child && child.configuration.compact) {
887
- // Inlines the elements of the child debug session
888
- return yield* child.getElements();
889
- }
890
- yield* this.threads;
891
- yield* this.childSessions.values();
892
- }
893
-
894
- protected getSingleChildSession(): DebugSession | undefined {
895
- if (this._threads.size === 0 && this.childSessions.size === 1) {
896
- const child = this.childSessions.values().next().value as DebugSession;
897
- return child;
898
- }
899
- return undefined;
900
- }
901
-
902
- protected async handleContinued({ body: { allThreadsContinued, threadId } }: DebugProtocol.ContinuedEvent): Promise<void> {
903
- if (allThreadsContinued !== false) {
904
- this.clearThreads();
905
- } else {
906
- this.clearThread(threadId);
907
- }
908
- };
909
-
910
- protected async handleStopped({ body }: DebugProtocol.StoppedEvent): Promise<void> {
911
- // Update thread list
912
- await this.updateThreads(body);
913
-
914
- // Update current thread's frames immediately
915
- await this.updateFrames();
916
- };
917
-
918
- protected async handleThread({ body: { reason, threadId } }: DebugProtocol.ThreadEvent): Promise<void> {
919
- if (reason === 'started') {
920
- this.scheduleUpdateThreads();
921
- } else if (reason === 'exited') {
922
- this._threads.delete(threadId);
923
- this.updateCurrentThread();
924
- }
925
- };
926
-
927
- protected registerDebugContributions(configType: string, connection: DebugSessionConnection): void {
928
- for (const contrib of this.debugContributionProvider.getContributions()) {
929
- contrib.register(configType, connection);
930
- }
931
- };
932
-
933
- /**
934
- * Returns the top-most parent session that is responsible for the console. If this session uses a {@link DebugConsoleMode.Separate separate console}
935
- * or does not have any parent session, undefined is returned.
936
- */
937
- public findConsoleParent(): DebugSession | undefined {
938
- if (this.configuration.consoleMode !== DebugConsoleMode.MergeWithParent) {
939
- return undefined;
940
- }
941
- let debugSession: DebugSession | undefined = this;
942
- do {
943
- debugSession = debugSession.parentSession;
944
- } while (debugSession?.parentSession && debugSession.configuration.consoleMode === DebugConsoleMode.MergeWithParent);
945
- return debugSession;
946
- }
947
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Red Hat, Inc. and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+
19
+ import * as React from '@theia/core/shared/react';
20
+ import { LabelProvider } from '@theia/core/lib/browser';
21
+ import { DebugProtocol } from '@vscode/debugprotocol';
22
+ import { Emitter, Event, DisposableCollection, Disposable, MessageClient, MessageType, Mutable, ContributionProvider } from '@theia/core/lib/common';
23
+ import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
24
+ import { EditorManager } from '@theia/editor/lib/browser';
25
+ import { CompositeTreeElement } from '@theia/core/lib/browser/source-tree';
26
+ import { DebugSessionConnection, DebugRequestTypes, DebugEventTypes } from './debug-session-connection';
27
+ import { DebugThread, StoppedDetails, DebugThreadData } from './model/debug-thread';
28
+ import { DebugScope } from './console/debug-console-items';
29
+ import { DebugStackFrame } from './model/debug-stack-frame';
30
+ import { DebugSource } from './model/debug-source';
31
+ import { DebugBreakpoint, DebugBreakpointOptions } from './model/debug-breakpoint';
32
+ import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
33
+ import debounce = require('p-debounce');
34
+ import URI from '@theia/core/lib/common/uri';
35
+ import { BreakpointManager } from './breakpoint/breakpoint-manager';
36
+ import { DebugConfigurationSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
37
+ import { DebugConfiguration, DebugConsoleMode } from '../common/debug-common';
38
+ import { SourceBreakpoint, ExceptionBreakpoint } from './breakpoint/breakpoint-marker';
39
+ import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
40
+ import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
41
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
42
+ import { DebugContribution } from './debug-contribution';
43
+ import { Deferred, waitForEvent } from '@theia/core/lib/common/promise-util';
44
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
45
+ import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
46
+ import { nls } from '@theia/core';
47
+
48
+ export enum DebugState {
49
+ Inactive,
50
+ Initializing,
51
+ Running,
52
+ Stopped
53
+ }
54
+ /**
55
+ * The mapped string values must not change as they are used for the `debugState` when context closure.
56
+ * For more details see the `Debugger contexts` section of the [official doc](https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts).
57
+ */
58
+ export function debugStateContextValue(state: DebugState): string {
59
+ switch (state) {
60
+ case DebugState.Initializing: return 'initializing';
61
+ case DebugState.Stopped: return 'stopped';
62
+ case DebugState.Running: return 'running';
63
+ default: return 'inactive';
64
+ }
65
+ }
66
+
67
+ // FIXME: make injectable to allow easily inject services
68
+ export class DebugSession implements CompositeTreeElement {
69
+ protected readonly deferredOnDidConfigureCapabilities = new Deferred<void>();
70
+
71
+ protected readonly onDidChangeEmitter = new Emitter<void>();
72
+ readonly onDidChange: Event<void> = this.onDidChangeEmitter.event;
73
+ protected fireDidChange(): void {
74
+ this.onDidChangeEmitter.fire(undefined);
75
+ }
76
+ protected readonly onDidFocusStackFrameEmitter = new Emitter<DebugStackFrame | undefined>();
77
+ get onDidFocusStackFrame(): Event<DebugStackFrame | undefined> {
78
+ return this.onDidFocusStackFrameEmitter.event;
79
+ }
80
+
81
+ protected readonly onDidChangeBreakpointsEmitter = new Emitter<URI>();
82
+ readonly onDidChangeBreakpoints: Event<URI> = this.onDidChangeBreakpointsEmitter.event;
83
+ protected fireDidChangeBreakpoints(uri: URI): void {
84
+ this.onDidChangeBreakpointsEmitter.fire(uri);
85
+ }
86
+
87
+ protected readonly childSessions = new Map<string, DebugSession>();
88
+ protected readonly toDispose = new DisposableCollection();
89
+
90
+ protected isStopping: boolean = false;
91
+
92
+ constructor(
93
+ readonly id: string,
94
+ readonly options: DebugConfigurationSessionOptions,
95
+ readonly parentSession: DebugSession | undefined,
96
+ protected readonly connection: DebugSessionConnection,
97
+ protected readonly terminalServer: TerminalService,
98
+ protected readonly editorManager: EditorManager,
99
+ protected readonly breakpoints: BreakpointManager,
100
+ protected readonly labelProvider: LabelProvider,
101
+ protected readonly messages: MessageClient,
102
+ protected readonly fileService: FileService,
103
+ protected readonly debugContributionProvider: ContributionProvider<DebugContribution>,
104
+ protected readonly workspaceService: WorkspaceService,
105
+ /**
106
+ * Number of millis after a `stop` request times out. It's 5 seconds by default.
107
+ */
108
+ protected readonly stopTimeout = 5_000,
109
+ ) {
110
+ this.connection.onRequest('runInTerminal', (request: DebugProtocol.RunInTerminalRequest) => this.runInTerminal(request));
111
+ this.connection.onDidClose(() => {
112
+ this.toDispose.dispose();
113
+ });
114
+ this.registerDebugContributions(options.configuration.type, this.connection);
115
+
116
+ if (parentSession) {
117
+ parentSession.childSessions.set(id, this);
118
+ this.toDispose.push(Disposable.create(() => {
119
+ this.parentSession?.childSessions?.delete(id);
120
+ }));
121
+ }
122
+ this.connection.onDidClose(() => this.toDispose.dispose());
123
+ this.toDispose.pushAll([
124
+ this.onDidChangeEmitter,
125
+ this.onDidChangeBreakpointsEmitter,
126
+ Disposable.create(() => {
127
+ this.clearBreakpoints();
128
+ this.doUpdateThreads([]);
129
+ }),
130
+ this.connection,
131
+ this.connection.on('initialized', () => this.configure()),
132
+ this.connection.on('breakpoint', ({ body }) => this.updateBreakpoint(body)),
133
+ this.connection.on('continued', e => this.handleContinued(e)),
134
+ this.connection.on('stopped', e => this.handleStopped(e)),
135
+ this.connection.on('thread', e => this.handleThread(e)),
136
+ this.connection.on('capabilities', event => this.updateCapabilities(event.body.capabilities)),
137
+ this.breakpoints.onDidChangeMarkers(uri => this.updateBreakpoints({ uri, sourceModified: true }))
138
+ ]);
139
+ }
140
+
141
+ get onDispose(): Event<void> {
142
+ return this.toDispose.onDispose;
143
+ }
144
+
145
+ get configuration(): DebugConfiguration {
146
+ return this.options.configuration;
147
+ }
148
+
149
+ protected _capabilities: DebugProtocol.Capabilities = {};
150
+ get capabilities(): DebugProtocol.Capabilities {
151
+ return this._capabilities;
152
+ }
153
+
154
+ protected readonly sources = new Map<string, DebugSource>();
155
+ getSource(raw: DebugProtocol.Source): DebugSource {
156
+ const uri = DebugSource.toUri(raw).toString();
157
+ const source = this.sources.get(uri) || new DebugSource(this, this.editorManager, this.labelProvider);
158
+ source.update({ raw });
159
+ this.sources.set(uri, source);
160
+ return source;
161
+ }
162
+
163
+ getSourceForUri(uri: URI): DebugSource | undefined {
164
+ return this.sources.get(uri.toString());
165
+ }
166
+
167
+ async toSource(uri: URI): Promise<DebugSource> {
168
+ const source = this.getSourceForUri(uri);
169
+ if (source) {
170
+ return source;
171
+ }
172
+
173
+ return this.getSource(await this.toDebugSource(uri));
174
+ }
175
+
176
+ async toDebugSource(uri: URI): Promise<DebugProtocol.Source> {
177
+ if (uri.scheme === DebugSource.SCHEME) {
178
+ return {
179
+ name: uri.path.toString(),
180
+ sourceReference: Number(uri.query)
181
+ };
182
+ }
183
+ const name = uri.displayName;
184
+ let path;
185
+ const underlying = await this.fileService.toUnderlyingResource(uri);
186
+ if (underlying.scheme === 'file') {
187
+ path = await this.fileService.fsPath(underlying);
188
+ } else {
189
+ path = uri.toString();
190
+ }
191
+ return { name, path };
192
+ }
193
+
194
+ protected _threads = new Map<number, DebugThread>();
195
+ get threads(): IterableIterator<DebugThread> {
196
+ return this._threads.values();
197
+ }
198
+
199
+ get threadCount(): number {
200
+ return this._threads.size;
201
+ }
202
+
203
+ *getThreads(filter: (thread: DebugThread) => boolean): IterableIterator<DebugThread> {
204
+ for (const thread of this.threads) {
205
+ if (filter(thread)) {
206
+ yield thread;
207
+ }
208
+ }
209
+ }
210
+
211
+ get runningThreads(): IterableIterator<DebugThread> {
212
+ return this.getThreads(thread => !thread.stopped);
213
+ }
214
+
215
+ get stoppedThreads(): IterableIterator<DebugThread> {
216
+ return this.getThreads(thread => thread.stopped);
217
+ }
218
+
219
+ async pauseAll(): Promise<void> {
220
+ const promises: Promise<void>[] = [];
221
+ for (const thread of this.runningThreads) {
222
+ promises.push((async () => {
223
+ try {
224
+ await thread.pause();
225
+ } catch (e) {
226
+ console.error('pauseAll failed:', e);
227
+ }
228
+ })());
229
+ }
230
+ await Promise.all(promises);
231
+ }
232
+
233
+ async continueAll(): Promise<void> {
234
+ const promises: Promise<void>[] = [];
235
+ for (const thread of this.stoppedThreads) {
236
+ promises.push((async () => {
237
+ try {
238
+ await thread.continue();
239
+ } catch (e) {
240
+ console.error('continueAll failed:', e);
241
+ }
242
+ })());
243
+ }
244
+ await Promise.all(promises);
245
+ }
246
+
247
+ get currentFrame(): DebugStackFrame | undefined {
248
+ return this.currentThread && this.currentThread.currentFrame;
249
+ }
250
+
251
+ protected _currentThread: DebugThread | undefined;
252
+ protected readonly toDisposeOnCurrentThread = new DisposableCollection();
253
+ get currentThread(): DebugThread | undefined {
254
+ return this._currentThread;
255
+ }
256
+ set currentThread(thread: DebugThread | undefined) {
257
+ this.toDisposeOnCurrentThread.dispose();
258
+ this._currentThread = thread;
259
+ this.fireDidChange();
260
+ if (thread) {
261
+ this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));
262
+ this.toDisposeOnCurrentThread.push(thread.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
263
+
264
+ // If this thread is missing stack frame information, then load that.
265
+ this.updateFrames();
266
+ }
267
+ }
268
+
269
+ get state(): DebugState {
270
+ if (this.connection.disposed) {
271
+ return DebugState.Inactive;
272
+ }
273
+ if (!this.initialized) {
274
+ return DebugState.Initializing;
275
+ }
276
+ const thread = this.currentThread;
277
+ if (thread) {
278
+ return thread.stopped ? DebugState.Stopped : DebugState.Running;
279
+ }
280
+ return !!this.stoppedThreads.next().value ? DebugState.Stopped : DebugState.Running;
281
+ }
282
+
283
+ async getScopes(): Promise<DebugScope[]> {
284
+ const { currentFrame } = this;
285
+ return currentFrame ? currentFrame.getScopes() : [];
286
+ }
287
+
288
+ async start(): Promise<void> {
289
+ await this.initialize();
290
+ await this.launchOrAttach();
291
+ }
292
+
293
+ protected async initialize(): Promise<void> {
294
+ try {
295
+ const response = await this.connection.sendRequest('initialize', {
296
+ clientID: 'Theia',
297
+ clientName: 'Theia IDE',
298
+ adapterID: this.configuration.type,
299
+ locale: 'en-US',
300
+ linesStartAt1: true,
301
+ columnsStartAt1: true,
302
+ pathFormat: 'path',
303
+ supportsVariableType: false,
304
+ supportsVariablePaging: false,
305
+ supportsRunInTerminalRequest: true
306
+ });
307
+ this.updateCapabilities(response?.body || {});
308
+ this.didReceiveCapabilities.resolve();
309
+ } catch (err) {
310
+ this.didReceiveCapabilities.reject(err);
311
+ throw err;
312
+ }
313
+ }
314
+
315
+ protected async launchOrAttach(): Promise<void> {
316
+ try {
317
+ await this.sendRequest((this.configuration.request as keyof DebugRequestTypes), this.configuration);
318
+ } catch (reason) {
319
+ this.messages.showMessage({
320
+ type: MessageType.Error,
321
+ text: reason.message || 'Debug session initialization failed. See console for details.',
322
+ options: {
323
+ timeout: 10000
324
+ }
325
+ });
326
+ throw reason;
327
+ }
328
+ }
329
+
330
+ /**
331
+ * The `send('initialize')` request could resolve later than `on('initialized')` emits the event.
332
+ * Hence, the `configure` would use the empty object `capabilities`.
333
+ * Using the empty `capabilities` could result in missing exception breakpoint filters, as
334
+ * always `capabilities.exceptionBreakpointFilters` is falsy. This deferred promise works
335
+ * around this timing issue. https://github.com/eclipse-theia/theia/issues/11886
336
+ */
337
+ protected didReceiveCapabilities = new Deferred<void>();
338
+ protected initialized = false;
339
+ protected async configure(): Promise<void> {
340
+ await this.didReceiveCapabilities.promise;
341
+ if (this.capabilities.exceptionBreakpointFilters) {
342
+ const exceptionBreakpoints = [];
343
+ for (const filter of this.capabilities.exceptionBreakpointFilters) {
344
+ const origin = this.breakpoints.getExceptionBreakpoint(filter.filter);
345
+ exceptionBreakpoints.push(ExceptionBreakpoint.create(filter, origin));
346
+ }
347
+ this.breakpoints.setExceptionBreakpoints(exceptionBreakpoints);
348
+ }
349
+ await this.updateBreakpoints({ sourceModified: false });
350
+ if (this.capabilities.supportsConfigurationDoneRequest) {
351
+ await this.sendRequest('configurationDone', {});
352
+ }
353
+ this.initialized = true;
354
+ await this.updateThreads(undefined);
355
+ }
356
+
357
+ canTerminate(): boolean {
358
+ return !!this.capabilities.supportsTerminateRequest;
359
+ }
360
+
361
+ canRestart(): boolean {
362
+ return !!this.capabilities.supportsRestartRequest;
363
+ }
364
+
365
+ async restart(): Promise<void> {
366
+ if (this.canRestart()) {
367
+ await this.sendRequest('restart', {});
368
+ }
369
+ }
370
+
371
+ async stop(isRestart: boolean, callback: () => void): Promise<void> {
372
+ if (!this.isStopping) {
373
+ this.isStopping = true;
374
+ if (this.canTerminate()) {
375
+ const terminated = this.waitFor('terminated', this.stopTimeout);
376
+ try {
377
+ await this.connection.sendRequest('terminate', { restart: isRestart }, this.stopTimeout);
378
+ await terminated;
379
+ } catch (e) {
380
+ this.handleTerminateError(e);
381
+ }
382
+ } else {
383
+ const terminateDebuggee = this.initialized && this.capabilities.supportTerminateDebuggee;
384
+ try {
385
+ await this.sendRequest('disconnect', { restart: isRestart, terminateDebuggee }, this.stopTimeout);
386
+ } catch (e) {
387
+ this.handleDisconnectError(e);
388
+ }
389
+ }
390
+ callback();
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Invoked when sending the `terminate` request to the debugger is rejected or timed out.
396
+ */
397
+ protected handleTerminateError(err: unknown): void {
398
+ console.error('Did not receive terminated event in time', err);
399
+ }
400
+
401
+ /**
402
+ * Invoked when sending the `disconnect` request to the debugger is rejected or timed out.
403
+ */
404
+ protected handleDisconnectError(err: unknown): void {
405
+ console.error('Error on disconnect', err);
406
+ }
407
+
408
+ async disconnect(isRestart: boolean, callback: () => void): Promise<void> {
409
+ if (!this.isStopping) {
410
+ this.isStopping = true;
411
+ await this.sendRequest('disconnect', { restart: isRestart });
412
+ callback();
413
+ }
414
+ }
415
+
416
+ async completions(text: string, column: number, line: number): Promise<DebugProtocol.CompletionItem[]> {
417
+ const frameId = this.currentFrame && this.currentFrame.raw.id;
418
+ const response = await this.sendRequest('completions', { frameId, text, column, line });
419
+ return response.body.targets;
420
+ }
421
+
422
+ async evaluate(expression: string, context?: string): Promise<DebugProtocol.EvaluateResponse['body']> {
423
+ const frameId = this.currentFrame && this.currentFrame.raw.id;
424
+ const response = await this.sendRequest('evaluate', { expression, frameId, context });
425
+ return response.body;
426
+ }
427
+
428
+ sendRequest<K extends keyof DebugRequestTypes>(command: K, args: DebugRequestTypes[K][0], timeout?: number): Promise<DebugRequestTypes[K][1]> {
429
+ return this.connection.sendRequest(command, args, timeout);
430
+ }
431
+
432
+ sendCustomRequest<T extends DebugProtocol.Response>(command: string, args?: any): Promise<T> {
433
+ return this.connection.sendCustomRequest(command, args);
434
+ }
435
+
436
+ on<K extends keyof DebugEventTypes>(kind: K, listener: (e: DebugEventTypes[K]) => any): Disposable {
437
+ return this.connection.on(kind, listener);
438
+ }
439
+
440
+ waitFor<K extends keyof DebugEventTypes>(kind: K, ms: number): Promise<void> {
441
+ return waitForEvent(this.connection.onEvent(kind), ms).then();
442
+ }
443
+
444
+ get onDidCustomEvent(): Event<DebugProtocol.Event> {
445
+ return this.connection.onDidCustomEvent;
446
+ }
447
+
448
+ protected async runInTerminal({ arguments: { title, cwd, args, env } }: DebugProtocol.RunInTerminalRequest): Promise<DebugProtocol.RunInTerminalResponse['body']> {
449
+ const terminal = await this.doCreateTerminal({ title, cwd, env, useServerTitle: false });
450
+ const { processId } = terminal;
451
+ await terminal.executeCommand({ cwd, args, env });
452
+ return { processId: await processId };
453
+ }
454
+
455
+ protected async doCreateTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
456
+ let terminal = undefined;
457
+ for (const t of this.terminalServer.all) {
458
+ if ((t.title.label === options.title || t.title.caption === options.title) && (await t.hasChildProcesses()) === false) {
459
+ terminal = t;
460
+ break;
461
+ }
462
+ }
463
+
464
+ if (!terminal) {
465
+ terminal = await this.terminalServer.newTerminal(options);
466
+ await terminal.start();
467
+ }
468
+ this.terminalServer.open(terminal);
469
+ return terminal;
470
+ }
471
+
472
+ protected clearThreads(): void {
473
+ for (const thread of this.threads) {
474
+ thread.clear();
475
+ }
476
+ this.updateCurrentThread();
477
+ }
478
+
479
+ protected clearThread(threadId: number): void {
480
+ const thread = this._threads.get(threadId);
481
+ if (thread) {
482
+ thread.clear();
483
+ }
484
+ this.updateCurrentThread();
485
+ }
486
+
487
+ protected readonly scheduleUpdateThreads = debounce(() => this.updateThreads(undefined), 100);
488
+ protected pendingThreads = Promise.resolve();
489
+
490
+ updateThreads(stoppedDetails: StoppedDetails | undefined): Promise<void> {
491
+ return this.pendingThreads = this.pendingThreads.then(async () => {
492
+ try {
493
+ const response = await this.sendRequest('threads', {});
494
+ // java debugger returns an empty body sometimes
495
+ const threads = response && response.body && response.body.threads || [];
496
+ this.doUpdateThreads(threads, stoppedDetails);
497
+ } catch (e) {
498
+ console.error('updateThreads failed:', e);
499
+ }
500
+ });
501
+ }
502
+
503
+ protected doUpdateThreads(threads: DebugProtocol.Thread[], stoppedDetails?: StoppedDetails): void {
504
+ const existing = this._threads;
505
+ this._threads = new Map();
506
+ for (const raw of threads) {
507
+ const id = raw.id;
508
+ const thread = existing.get(id) || new DebugThread(this);
509
+ this._threads.set(id, thread);
510
+ const data: Partial<Mutable<DebugThreadData>> = { raw };
511
+ if (stoppedDetails) {
512
+ if (stoppedDetails.threadId === id) {
513
+ data.stoppedDetails = stoppedDetails;
514
+ } else if (stoppedDetails.allThreadsStopped) {
515
+ data.stoppedDetails = {
516
+ // When a debug adapter notifies us that all threads are stopped,
517
+ // we do not know why the others are stopped, so we should default
518
+ // to something generic.
519
+ reason: '',
520
+ };
521
+ }
522
+ }
523
+ thread.update(data);
524
+ }
525
+ this.updateCurrentThread(stoppedDetails);
526
+ }
527
+
528
+ protected updateCurrentThread(stoppedDetails?: StoppedDetails): void {
529
+ const { currentThread } = this;
530
+ let threadId = currentThread && currentThread.raw.id;
531
+ if (stoppedDetails && !stoppedDetails.preserveFocusHint && !!stoppedDetails.threadId) {
532
+ threadId = stoppedDetails.threadId;
533
+ }
534
+ this.currentThread = typeof threadId === 'number' && this._threads.get(threadId)
535
+ || this._threads.values().next().value;
536
+ }
537
+
538
+ protected async updateFrames(): Promise<void> {
539
+ const thread = this._currentThread;
540
+ if (!thread || thread.pendingFrameCount || thread.frameCount) {
541
+ return;
542
+ }
543
+ if (this.capabilities.supportsDelayedStackTraceLoading) {
544
+ await thread.fetchFrames(1);
545
+ await thread.fetchFrames(19);
546
+ } else {
547
+ await thread.fetchFrames();
548
+ }
549
+ }
550
+
551
+ protected updateCapabilities(capabilities: DebugProtocol.Capabilities): void {
552
+ Object.assign(this._capabilities, capabilities);
553
+ this.deferredOnDidConfigureCapabilities.resolve();
554
+ }
555
+
556
+ protected readonly _breakpoints = new Map<string, DebugBreakpoint[]>();
557
+ get breakpointUris(): IterableIterator<string> {
558
+ return this._breakpoints.keys();
559
+ }
560
+
561
+ getSourceBreakpoints(uri?: URI): DebugSourceBreakpoint[] {
562
+ const breakpoints = [];
563
+ for (const breakpoint of this.getBreakpoints(uri)) {
564
+ if (breakpoint instanceof DebugSourceBreakpoint) {
565
+ breakpoints.push(breakpoint);
566
+ }
567
+ }
568
+ return breakpoints;
569
+ }
570
+
571
+ getFunctionBreakpoints(): DebugFunctionBreakpoint[] {
572
+ return this.getBreakpoints(BreakpointManager.FUNCTION_URI).filter((breakpoint): breakpoint is DebugFunctionBreakpoint => breakpoint instanceof DebugFunctionBreakpoint);
573
+ }
574
+
575
+ getInstructionBreakpoints(): DebugInstructionBreakpoint[] {
576
+ if (this.capabilities.supportsInstructionBreakpoints) {
577
+ return this.getBreakpoints(BreakpointManager.INSTRUCTION_URI)
578
+ .filter((breakpoint): breakpoint is DebugInstructionBreakpoint => breakpoint instanceof DebugInstructionBreakpoint);
579
+ }
580
+ return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, this.asDebugBreakpointOptions()));
581
+ }
582
+
583
+ getBreakpoints(uri?: URI): DebugBreakpoint[] {
584
+ if (uri) {
585
+ return this._breakpoints.get(uri.toString()) || [];
586
+ }
587
+ const result = [];
588
+ for (const breakpoints of this._breakpoints.values()) {
589
+ result.push(...breakpoints);
590
+ }
591
+ return result;
592
+ }
593
+
594
+ getBreakpoint(id: string): DebugBreakpoint | undefined {
595
+ for (const breakpoints of this._breakpoints.values()) {
596
+ const breakpoint = breakpoints.find(b => b.id === id);
597
+ if (breakpoint) {
598
+ return breakpoint;
599
+ }
600
+
601
+ }
602
+ return undefined;
603
+ }
604
+
605
+ protected clearBreakpoints(): void {
606
+ const uris = [...this._breakpoints.keys()];
607
+ this._breakpoints.clear();
608
+ for (const uri of uris) {
609
+ this.fireDidChangeBreakpoints(new URI(uri));
610
+ }
611
+ }
612
+
613
+ protected updatingBreakpoints = false;
614
+
615
+ protected updateBreakpoint(body: DebugProtocol.BreakpointEvent['body']): void {
616
+ this.updatingBreakpoints = true;
617
+ try {
618
+ const raw = body.breakpoint;
619
+ if (body.reason === 'new') {
620
+ if (raw.source && typeof raw.line === 'number') {
621
+ const uri = DebugSource.toUri(raw.source);
622
+ const origin = SourceBreakpoint.create(uri, { line: raw.line, column: raw.column });
623
+ if (this.breakpoints.addBreakpoint(origin)) {
624
+ const breakpoints = this.getSourceBreakpoints(uri);
625
+ const breakpoint = new DebugSourceBreakpoint(origin, this.asDebugBreakpointOptions());
626
+ breakpoint.update({ raw });
627
+ breakpoints.push(breakpoint);
628
+ this.setSourceBreakpoints(uri, breakpoints);
629
+ }
630
+ }
631
+ }
632
+ if (body.reason === 'removed' && raw.id) {
633
+ const toRemove = this.findBreakpoint(b => b.idFromAdapter === raw.id);
634
+ if (toRemove) {
635
+ toRemove.remove();
636
+ const breakpoints = this.getBreakpoints(toRemove.uri);
637
+ const index = breakpoints.indexOf(toRemove);
638
+ if (index !== -1) {
639
+ breakpoints.splice(index, 1);
640
+ this.setBreakpoints(toRemove.uri, breakpoints);
641
+ }
642
+ }
643
+ }
644
+ if (body.reason === 'changed' && raw.id) {
645
+ const toUpdate = this.findBreakpoint(b => b.idFromAdapter === raw.id);
646
+ if (toUpdate) {
647
+ toUpdate.update({ raw });
648
+ if (toUpdate instanceof DebugSourceBreakpoint) {
649
+ const sourceBreakpoints = this.getSourceBreakpoints(toUpdate.uri);
650
+ // in order to dedup again if a debugger converted line breakpoint to inline breakpoint
651
+ // i.e. assigned a column to a line breakpoint
652
+ this.setSourceBreakpoints(toUpdate.uri, sourceBreakpoints);
653
+ } else {
654
+ this.fireDidChangeBreakpoints(toUpdate.uri);
655
+ }
656
+ }
657
+ }
658
+ } finally {
659
+ this.updatingBreakpoints = false;
660
+ }
661
+ }
662
+ protected findBreakpoint(match: (breakpoint: DebugBreakpoint) => boolean): DebugBreakpoint | undefined {
663
+ for (const [, breakpoints] of this._breakpoints) {
664
+ for (const breakpoint of breakpoints) {
665
+ if (match(breakpoint)) {
666
+ return breakpoint;
667
+ }
668
+ }
669
+ }
670
+ return undefined;
671
+ }
672
+
673
+ protected async updateBreakpoints(options: {
674
+ uri?: URI,
675
+ sourceModified: boolean
676
+ }): Promise<void> {
677
+ if (this.updatingBreakpoints) {
678
+ return;
679
+ }
680
+ const { uri, sourceModified } = options;
681
+ await this.deferredOnDidConfigureCapabilities.promise;
682
+ for (const affectedUri of this.getAffectedUris(uri)) {
683
+ if (affectedUri.toString() === BreakpointManager.EXCEPTION_URI.toString()) {
684
+ await this.sendExceptionBreakpoints();
685
+ } else if (affectedUri.toString() === BreakpointManager.FUNCTION_URI.toString()) {
686
+ await this.sendFunctionBreakpoints(affectedUri);
687
+ } else if (affectedUri.toString() === BreakpointManager.INSTRUCTION_URI.toString()) {
688
+ await this.sendInstructionBreakpoints();
689
+ } else {
690
+ await this.sendSourceBreakpoints(affectedUri, sourceModified);
691
+ }
692
+ }
693
+ }
694
+
695
+ protected async sendExceptionBreakpoints(): Promise<void> {
696
+ const filters: string[] = [];
697
+ const filterOptions: DebugProtocol.ExceptionFilterOptions[] | undefined = this.capabilities.supportsExceptionFilterOptions ? [] : undefined;
698
+ for (const breakpoint of this.breakpoints.getExceptionBreakpoints()) {
699
+ if (breakpoint.enabled) {
700
+ if (filterOptions) {
701
+ filterOptions.push({
702
+ filterId: breakpoint.raw.filter,
703
+ condition: breakpoint.condition
704
+ });
705
+ } else {
706
+ filters.push(breakpoint.raw.filter);
707
+ }
708
+ }
709
+ }
710
+ await this.sendRequest('setExceptionBreakpoints', { filters, filterOptions });
711
+ }
712
+
713
+ protected async sendFunctionBreakpoints(affectedUri: URI): Promise<void> {
714
+ const all = this.breakpoints.getFunctionBreakpoints().map(origin =>
715
+ new DebugFunctionBreakpoint(origin, this.asDebugBreakpointOptions())
716
+ );
717
+ const enabled = all.filter(b => b.enabled);
718
+ if (this.capabilities.supportsFunctionBreakpoints) {
719
+ try {
720
+ const response = await this.sendRequest('setFunctionBreakpoints', {
721
+ breakpoints: enabled.map(b => b.origin.raw)
722
+ });
723
+ // Apparently, `body` and `breakpoints` can be missing.
724
+ // https://github.com/eclipse-theia/theia/issues/11885
725
+ // https://github.com/microsoft/vscode/blob/80004351ccf0884b58359f7c8c801c91bb827d83/src/vs/workbench/contrib/debug/browser/debugSession.ts#L448-L449
726
+ if (response && response.body) {
727
+ response.body.breakpoints.forEach((raw, index) => {
728
+ // node debug adapter returns more breakpoints sometimes
729
+ if (enabled[index]) {
730
+ enabled[index].update({ raw });
731
+ }
732
+ });
733
+ }
734
+ } catch (error) {
735
+ // could be error or promise rejection of DebugProtocol.SetFunctionBreakpoints
736
+ if (error instanceof Error) {
737
+ console.error(`Error setting breakpoints: ${error.message}`);
738
+ } else {
739
+ // handle adapters that send failed DebugProtocol.SetFunctionBreakpoints for invalid breakpoints
740
+ const genericMessage: string = 'Function breakpoint not valid for current debug session';
741
+ const message: string = error.message ? `${error.message}` : genericMessage;
742
+ console.warn(`Could not handle function breakpoints: ${message}, disabling...`);
743
+ enabled.forEach(b => b.update({
744
+ raw: {
745
+ verified: false,
746
+ message
747
+ }
748
+ }));
749
+ }
750
+ }
751
+ }
752
+ this.setBreakpoints(affectedUri, all);
753
+ }
754
+
755
+ protected async sendSourceBreakpoints(affectedUri: URI, sourceModified?: boolean): Promise<void> {
756
+ const source = await this.toSource(affectedUri);
757
+ const all = this.breakpoints.findMarkers({ uri: affectedUri }).map(({ data }) =>
758
+ new DebugSourceBreakpoint(data, this.asDebugBreakpointOptions())
759
+ );
760
+ const enabled = all.filter(b => b.enabled);
761
+ try {
762
+ const breakpoints = enabled.map(({ origin }) => origin.raw);
763
+ const response = await this.sendRequest('setBreakpoints', {
764
+ source: source.raw,
765
+ sourceModified,
766
+ breakpoints,
767
+ lines: breakpoints.map(({ line }) => line)
768
+ });
769
+ response.body.breakpoints.forEach((raw, index) => {
770
+ // node debug adapter returns more breakpoints sometimes
771
+ if (enabled[index]) {
772
+ enabled[index].update({ raw });
773
+ }
774
+ });
775
+ } catch (error) {
776
+ // could be error or promise rejection of DebugProtocol.SetBreakpointsResponse
777
+ if (error instanceof Error) {
778
+ console.error(`Error setting breakpoints: ${error.message}`);
779
+ } else {
780
+ // handle adapters that send failed DebugProtocol.SetBreakpointsResponse for invalid breakpoints
781
+ const genericMessage: string = 'Breakpoint not valid for current debug session';
782
+ const message: string = error.message ? `${error.message}` : genericMessage;
783
+ console.warn(`Could not handle breakpoints for ${affectedUri}: ${message}, disabling...`);
784
+ enabled.forEach(b => b.update({
785
+ raw: {
786
+ verified: false,
787
+ message
788
+ }
789
+ }));
790
+ }
791
+ }
792
+ this.setSourceBreakpoints(affectedUri, all);
793
+ }
794
+
795
+ protected async sendInstructionBreakpoints(): Promise<void> {
796
+ if (!this.capabilities.supportsInstructionBreakpoints) {
797
+ return;
798
+ }
799
+ const all = this.breakpoints.getInstructionBreakpoints().map(breakpoint => new DebugInstructionBreakpoint(breakpoint, this.asDebugBreakpointOptions()));
800
+ const enabled = all.filter(breakpoint => breakpoint.enabled);
801
+ try {
802
+ const response = await this.sendRequest('setInstructionBreakpoints', {
803
+ breakpoints: enabled.map(renderable => renderable.origin),
804
+ });
805
+ response.body.breakpoints.forEach((raw, index) => enabled[index]?.update({ raw }));
806
+ } catch {
807
+ enabled.forEach(breakpoint => breakpoint.update({ raw: { verified: false } }));
808
+ }
809
+ this.setBreakpoints(BreakpointManager.INSTRUCTION_URI, all);
810
+ }
811
+
812
+ protected setBreakpoints(uri: URI, breakpoints: DebugBreakpoint[]): void {
813
+ this._breakpoints.set(uri.toString(), breakpoints);
814
+ this.fireDidChangeBreakpoints(uri);
815
+ }
816
+
817
+ protected setSourceBreakpoints(uri: URI, breakpoints: DebugSourceBreakpoint[]): void {
818
+ const distinct = this.dedupSourceBreakpoints(breakpoints);
819
+ this.setBreakpoints(uri, distinct);
820
+ }
821
+
822
+ protected dedupSourceBreakpoints(all: DebugSourceBreakpoint[]): DebugSourceBreakpoint[] {
823
+ const positions = new Map<string, DebugSourceBreakpoint>();
824
+ for (const breakpoint of all) {
825
+ let primary = positions.get(breakpoint.renderPosition()) || breakpoint;
826
+ if (primary !== breakpoint) {
827
+ let secondary = breakpoint;
828
+ if (secondary.raw && secondary.raw.line === secondary.origin.raw.line && secondary.raw.column === secondary.origin.raw.column) {
829
+ [primary, secondary] = [breakpoint, primary];
830
+ }
831
+ primary.origins.push(...secondary.origins);
832
+ }
833
+ positions.set(primary.renderPosition(), primary);
834
+ }
835
+ return [...positions.values()];
836
+ }
837
+
838
+ protected *getAffectedUris(uri?: URI): IterableIterator<URI> {
839
+ if (uri) {
840
+ yield uri;
841
+ } else {
842
+ for (const uriString of this.breakpoints.getUris()) {
843
+ yield new URI(uriString);
844
+ }
845
+ yield BreakpointManager.FUNCTION_URI;
846
+ yield BreakpointManager.EXCEPTION_URI;
847
+ }
848
+ }
849
+
850
+ protected asDebugBreakpointOptions(): DebugBreakpointOptions {
851
+ const { labelProvider, breakpoints, editorManager } = this;
852
+ return { labelProvider, breakpoints, editorManager, session: this };
853
+ }
854
+
855
+ get label(): string {
856
+ const suffixes = [];
857
+ if (InternalDebugSessionOptions.is(this.options) && this.options.id) {
858
+ suffixes.push(String(this.options.id + 1));
859
+ }
860
+ if (this.workspaceService.isMultiRootWorkspaceOpened && this.options.workspaceFolderUri) {
861
+ suffixes.push(this.labelProvider.getName(new URI(this.options.workspaceFolderUri)));
862
+ }
863
+ return suffixes.length === 0 ? this.configuration.name : this.configuration.name + ` (${suffixes.join(' - ')})`;
864
+ }
865
+
866
+ get visible(): boolean {
867
+ return this.state > DebugState.Inactive;
868
+ }
869
+
870
+ render(): React.ReactNode {
871
+ let label = '';
872
+ const state = this.state === DebugState.Stopped ? nls.localizeByDefault('Paused') : nls.localizeByDefault('Running');
873
+ const child = this.getSingleChildSession();
874
+ if (child && child.configuration.compact) {
875
+ // Inlines the name of the child debug session
876
+ label = `: ${child.label}`;
877
+ }
878
+ return <div className='theia-debug-session' title='Session'>
879
+ <span className='label'>{this.label + label}</span>
880
+ <span className='status'>{state}</span>
881
+ </div>;
882
+ }
883
+
884
+ *getElements(): IterableIterator<DebugThread | DebugSession> {
885
+ const child = this.getSingleChildSession();
886
+ if (child && child.configuration.compact) {
887
+ // Inlines the elements of the child debug session
888
+ return yield* child.getElements();
889
+ }
890
+ yield* this.threads;
891
+ yield* this.childSessions.values();
892
+ }
893
+
894
+ protected getSingleChildSession(): DebugSession | undefined {
895
+ if (this._threads.size === 0 && this.childSessions.size === 1) {
896
+ const child = this.childSessions.values().next().value as DebugSession;
897
+ return child;
898
+ }
899
+ return undefined;
900
+ }
901
+
902
+ protected async handleContinued({ body: { allThreadsContinued, threadId } }: DebugProtocol.ContinuedEvent): Promise<void> {
903
+ if (allThreadsContinued !== false) {
904
+ this.clearThreads();
905
+ } else {
906
+ this.clearThread(threadId);
907
+ }
908
+ };
909
+
910
+ protected async handleStopped({ body }: DebugProtocol.StoppedEvent): Promise<void> {
911
+ // Update thread list
912
+ await this.updateThreads(body);
913
+
914
+ // Update current thread's frames immediately
915
+ await this.updateFrames();
916
+ };
917
+
918
+ protected async handleThread({ body: { reason, threadId } }: DebugProtocol.ThreadEvent): Promise<void> {
919
+ if (reason === 'started') {
920
+ this.scheduleUpdateThreads();
921
+ } else if (reason === 'exited') {
922
+ this._threads.delete(threadId);
923
+ this.updateCurrentThread();
924
+ }
925
+ };
926
+
927
+ protected registerDebugContributions(configType: string, connection: DebugSessionConnection): void {
928
+ for (const contrib of this.debugContributionProvider.getContributions()) {
929
+ contrib.register(configType, connection);
930
+ }
931
+ };
932
+
933
+ /**
934
+ * Returns the top-most parent session that is responsible for the console. If this session uses a {@link DebugConsoleMode.Separate separate console}
935
+ * or does not have any parent session, undefined is returned.
936
+ */
937
+ public findConsoleParent(): DebugSession | undefined {
938
+ if (this.configuration.consoleMode !== DebugConsoleMode.MergeWithParent) {
939
+ return undefined;
940
+ }
941
+ let debugSession: DebugSession | undefined = this;
942
+ do {
943
+ debugSession = debugSession.parentSession;
944
+ } while (debugSession?.parentSession && debugSession.configuration.consoleMode === DebugConsoleMode.MergeWithParent);
945
+ return debugSession;
946
+ }
947
+ }