@theia/debug 1.28.0-next.1 → 1.28.0-next.13

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 (97) hide show
  1. package/lib/browser/breakpoint/breakpoint-manager.d.ts +13 -1
  2. package/lib/browser/breakpoint/breakpoint-manager.d.ts.map +1 -1
  3. package/lib/browser/breakpoint/breakpoint-manager.js +66 -2
  4. package/lib/browser/breakpoint/breakpoint-manager.js.map +1 -1
  5. package/lib/browser/breakpoint/breakpoint-marker.d.ts +6 -0
  6. package/lib/browser/breakpoint/breakpoint-marker.d.ts.map +1 -1
  7. package/lib/browser/breakpoint/breakpoint-marker.js +14 -1
  8. package/lib/browser/breakpoint/breakpoint-marker.js.map +1 -1
  9. package/lib/browser/debug-frontend-application-contribution.d.ts +3 -0
  10. package/lib/browser/debug-frontend-application-contribution.d.ts.map +1 -1
  11. package/lib/browser/debug-frontend-application-contribution.js +15 -3
  12. package/lib/browser/debug-frontend-application-contribution.js.map +1 -1
  13. package/lib/browser/debug-frontend-module.d.ts.map +1 -1
  14. package/lib/browser/debug-frontend-module.js +2 -0
  15. package/lib/browser/debug-frontend-module.js.map +1 -1
  16. package/lib/browser/debug-preferences.d.ts +1 -0
  17. package/lib/browser/debug-preferences.d.ts.map +1 -1
  18. package/lib/browser/debug-preferences.js +5 -0
  19. package/lib/browser/debug-preferences.js.map +1 -1
  20. package/lib/browser/debug-session-manager.d.ts +8 -0
  21. package/lib/browser/debug-session-manager.d.ts.map +1 -1
  22. package/lib/browser/debug-session-manager.js +12 -3
  23. package/lib/browser/debug-session-manager.js.map +1 -1
  24. package/lib/browser/debug-session.d.ts +5 -0
  25. package/lib/browser/debug-session.d.ts.map +1 -1
  26. package/lib/browser/debug-session.js +36 -9
  27. package/lib/browser/debug-session.js.map +1 -1
  28. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.d.ts +7 -0
  29. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.d.ts.map +1 -0
  30. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.js +39 -0
  31. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.js.map +1 -0
  32. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.d.ts +20 -0
  33. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.d.ts.map +1 -0
  34. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.js +111 -0
  35. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.js.map +1 -0
  36. package/lib/browser/disassembly-view/disassembly-view-contribution.d.ts +25 -0
  37. package/lib/browser/disassembly-view/disassembly-view-contribution.d.ts.map +1 -0
  38. package/lib/browser/disassembly-view/disassembly-view-contribution.js +132 -0
  39. package/lib/browser/disassembly-view/disassembly-view-contribution.js.map +1 -0
  40. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.d.ts +39 -0
  41. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.d.ts.map +1 -0
  42. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.js +223 -0
  43. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.js.map +1 -0
  44. package/lib/browser/disassembly-view/disassembly-view-table-delegate.d.ts +16 -0
  45. package/lib/browser/disassembly-view/disassembly-view-table-delegate.d.ts.map +1 -0
  46. package/lib/browser/disassembly-view/disassembly-view-table-delegate.js +39 -0
  47. package/lib/browser/disassembly-view/disassembly-view-table-delegate.js.map +1 -0
  48. package/lib/browser/disassembly-view/disassembly-view-utilities.d.ts +38 -0
  49. package/lib/browser/disassembly-view/disassembly-view-utilities.d.ts.map +1 -0
  50. package/lib/browser/disassembly-view/disassembly-view-utilities.js +18 -0
  51. package/lib/browser/disassembly-view/disassembly-view-utilities.js.map +1 -0
  52. package/lib/browser/disassembly-view/disassembly-view-widget.d.ts +61 -0
  53. package/lib/browser/disassembly-view/disassembly-view-widget.d.ts.map +1 -0
  54. package/lib/browser/disassembly-view/disassembly-view-widget.js +453 -0
  55. package/lib/browser/disassembly-view/disassembly-view-widget.js.map +1 -0
  56. package/lib/browser/editor/debug-inline-value-decorator.js +3 -3
  57. package/lib/browser/editor/debug-inline-value-decorator.js.map +1 -1
  58. package/lib/browser/model/debug-instruction-breakpoint.d.ts +15 -0
  59. package/lib/browser/model/debug-instruction-breakpoint.d.ts.map +1 -0
  60. package/lib/browser/model/debug-instruction-breakpoint.js +66 -0
  61. package/lib/browser/model/debug-instruction-breakpoint.js.map +1 -0
  62. package/lib/browser/model/debug-thread.d.ts +2 -0
  63. package/lib/browser/model/debug-thread.d.ts.map +1 -1
  64. package/lib/browser/model/debug-thread.js +5 -0
  65. package/lib/browser/model/debug-thread.js.map +1 -1
  66. package/lib/browser/view/debug-breakpoints-source.d.ts.map +1 -1
  67. package/lib/browser/view/debug-breakpoints-source.js +3 -0
  68. package/lib/browser/view/debug-breakpoints-source.js.map +1 -1
  69. package/lib/browser/view/debug-view-model.d.ts +2 -0
  70. package/lib/browser/view/debug-view-model.d.ts.map +1 -1
  71. package/lib/browser/view/debug-view-model.js +3 -0
  72. package/lib/browser/view/debug-view-model.js.map +1 -1
  73. package/lib/common/debug-service.d.ts +3 -2
  74. package/lib/common/debug-service.d.ts.map +1 -1
  75. package/lib/common/debug-service.js +0 -2
  76. package/lib/common/debug-service.js.map +1 -1
  77. package/package.json +15 -15
  78. package/src/browser/breakpoint/breakpoint-manager.ts +81 -7
  79. package/src/browser/breakpoint/breakpoint-marker.ts +17 -0
  80. package/src/browser/debug-frontend-application-contribution.ts +16 -4
  81. package/src/browser/debug-frontend-module.ts +2 -0
  82. package/src/browser/debug-preferences.ts +6 -0
  83. package/src/browser/debug-session-manager.ts +21 -6
  84. package/src/browser/debug-session.tsx +36 -9
  85. package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -0
  86. package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -0
  87. package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -0
  88. package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -0
  89. package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -0
  90. package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -0
  91. package/src/browser/disassembly-view/disassembly-view-widget.ts +464 -0
  92. package/src/browser/editor/debug-inline-value-decorator.ts +3 -3
  93. package/src/browser/model/debug-instruction-breakpoint.tsx +68 -0
  94. package/src/browser/model/debug-thread.tsx +5 -0
  95. package/src/browser/view/debug-breakpoints-source.tsx +3 -0
  96. package/src/browser/view/debug-view-model.ts +6 -1
  97. package/src/common/debug-service.ts +4 -6
@@ -42,6 +42,7 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
42
42
  import { DebugContribution } from './debug-contribution';
43
43
  import { waitForEvent } from '@theia/core/lib/common/promise-util';
44
44
  import { WorkspaceService } from '@theia/workspace/lib/browser';
45
+ import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
45
46
 
46
47
  export enum DebugState {
47
48
  Inactive,
@@ -57,6 +58,10 @@ export class DebugSession implements CompositeTreeElement {
57
58
  protected fireDidChange(): void {
58
59
  this.onDidChangeEmitter.fire(undefined);
59
60
  }
61
+ protected readonly onDidFocusStackFrameEmitter = new Emitter<DebugStackFrame | undefined>();
62
+ get onDidFocusStackFrame(): Event<DebugStackFrame | undefined> {
63
+ return this.onDidFocusStackFrameEmitter.event;
64
+ }
60
65
 
61
66
  protected readonly onDidChangeBreakpointsEmitter = new Emitter<URI>();
62
67
  readonly onDidChangeBreakpoints: Event<URI> = this.onDidChangeBreakpointsEmitter.event;
@@ -235,6 +240,7 @@ export class DebugSession implements CompositeTreeElement {
235
240
  this.fireDidChange();
236
241
  if (thread) {
237
242
  this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));
243
+ this.toDisposeOnCurrentThread.push(thread.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
238
244
 
239
245
  // If this thread is missing stack frame information, then load that.
240
246
  this.updateFrames();
@@ -513,13 +519,15 @@ export class DebugSession implements CompositeTreeElement {
513
519
  }
514
520
 
515
521
  getFunctionBreakpoints(): DebugFunctionBreakpoint[] {
516
- const breakpoints = [];
517
- for (const breakpoint of this.getBreakpoints(BreakpointManager.FUNCTION_URI)) {
518
- if (breakpoint instanceof DebugFunctionBreakpoint) {
519
- breakpoints.push(breakpoint);
520
- }
522
+ return this.getBreakpoints(BreakpointManager.FUNCTION_URI).filter((breakpoint): breakpoint is DebugFunctionBreakpoint => breakpoint instanceof DebugFunctionBreakpoint);
523
+ }
524
+
525
+ getInstructionBreakpoints(): DebugInstructionBreakpoint[] {
526
+ if (this.capabilities.supportsInstructionBreakpoints) {
527
+ return this.getBreakpoints(BreakpointManager.FUNCTION_URI)
528
+ .filter((breakpoint): breakpoint is DebugInstructionBreakpoint => breakpoint instanceof DebugInstructionBreakpoint);
521
529
  }
522
- return breakpoints;
530
+ return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, this.asDebugBreakpointOptions()));
523
531
  }
524
532
 
525
533
  getBreakpoints(uri?: URI): DebugBreakpoint[] {
@@ -614,6 +622,8 @@ export class DebugSession implements CompositeTreeElement {
614
622
  await this.sendExceptionBreakpoints();
615
623
  } else if (affectedUri.toString() === BreakpointManager.FUNCTION_URI.toString()) {
616
624
  await this.sendFunctionBreakpoints(affectedUri);
625
+ } else if (affectedUri.toString() === BreakpointManager.INSTRUCTION_URI.toString()) {
626
+ await this.sendInstructionBreakpoints();
617
627
  } else {
618
628
  await this.sendSourceBreakpoints(affectedUri, sourceModified);
619
629
  }
@@ -640,7 +650,7 @@ export class DebugSession implements CompositeTreeElement {
640
650
  const response = await this.sendRequest('setFunctionBreakpoints', {
641
651
  breakpoints: enabled.map(b => b.origin.raw)
642
652
  });
643
- response.body.breakpoints.map((raw, index) => {
653
+ response.body.breakpoints.forEach((raw, index) => {
644
654
  // node debug adapter returns more breakpoints sometimes
645
655
  if (enabled[index]) {
646
656
  enabled[index].update({ raw });
@@ -679,7 +689,7 @@ export class DebugSession implements CompositeTreeElement {
679
689
  sourceModified,
680
690
  breakpoints: enabled.map(({ origin }) => origin.raw)
681
691
  });
682
- response.body.breakpoints.map((raw, index) => {
692
+ response.body.breakpoints.forEach((raw, index) => {
683
693
  // node debug adapter returns more breakpoints sometimes
684
694
  if (enabled[index]) {
685
695
  enabled[index].update({ raw });
@@ -705,6 +715,23 @@ export class DebugSession implements CompositeTreeElement {
705
715
  this.setSourceBreakpoints(affectedUri, all);
706
716
  }
707
717
 
718
+ protected async sendInstructionBreakpoints(): Promise<void> {
719
+ if (!this.capabilities.supportsInstructionBreakpoints) {
720
+ return;
721
+ }
722
+ const all = this.breakpoints.getInstructionBreakpoints().map(breakpoint => new DebugInstructionBreakpoint(breakpoint, this.asDebugBreakpointOptions()));
723
+ const enabled = all.filter(breakpoint => breakpoint.enabled);
724
+ try {
725
+ const response = await this.sendRequest('setInstructionBreakpoints', {
726
+ breakpoints: enabled.map(renderable => renderable.origin),
727
+ });
728
+ response.body.breakpoints.forEach((raw, index) => enabled[index]?.update({ raw }));
729
+ } catch {
730
+ enabled.forEach(breakpoint => breakpoint.update({ raw: { verified: false } }));
731
+ }
732
+ this.setBreakpoints(BreakpointManager.INSTRUCTION_URI, all);
733
+ }
734
+
708
735
  protected setBreakpoints(uri: URI, breakpoints: DebugBreakpoint[]): void {
709
736
  this._breakpoints.set(uri.toString(), breakpoints);
710
737
  this.fireDidChangeBreakpoints(uri);
@@ -834,7 +861,7 @@ export class DebugSession implements CompositeTreeElement {
834
861
  }
835
862
  let debugSession: DebugSession | undefined = this;
836
863
  do {
837
- debugSession = this.parentSession;
864
+ debugSession = debugSession.parentSession;
838
865
  } while (debugSession?.parentSession && debugSession.configuration.consoleMode === DebugConsoleMode.MergeWithParent);
839
866
  return debugSession;
840
867
  }
@@ -0,0 +1,43 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { nls } from '@theia/core';
18
+ import { IListAccessibilityProvider } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/list/listWidget';
19
+ import { DisassembledInstructionEntry } from './disassembly-view-utilities';
20
+
21
+ // This file is adapted from https://github.com/microsoft/vscode/blob/c061ce5c24fc480342fbc5f23244289d633c56eb/src/vs/workbench/contrib/debug/browser/disassemblyView.ts
22
+
23
+ export class AccessibilityProvider implements IListAccessibilityProvider<DisassembledInstructionEntry> {
24
+
25
+ getWidgetAriaLabel(): string {
26
+ return nls.localize('disassemblyView', 'Disassembly View');
27
+ }
28
+
29
+ getAriaLabel(element: DisassembledInstructionEntry): string | null {
30
+ let label = '';
31
+
32
+ const instruction = element.instruction;
33
+ if (instruction.address !== '-1') {
34
+ label += `${nls.localize('theia/debug/instructionAddress', 'Address')}: ${instruction.address}`;
35
+ }
36
+ if (instruction.instructionBytes) {
37
+ label += `, ${nls.localize('theia/debug/instructionBytes', 'Bytes')}: ${instruction.instructionBytes}`;
38
+ }
39
+ label += `, ${nls.localize('theia/debug/instructionText', 'Instruction')}: ${instruction.instruction}`;
40
+
41
+ return label;
42
+ }
43
+ }
@@ -0,0 +1,119 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { append, $, addStandardDisposableListener } from '@theia/monaco-editor-core/esm/vs/base/browser/dom';
18
+ import { ITableRenderer } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/table/table';
19
+ import { dispose } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
20
+ import { BreakpointManager } from '../breakpoint/breakpoint-manager';
21
+ import { BreakpointColumnTemplateData, DisassembledInstructionEntry, DisassemblyViewRendererReference } from './disassembly-view-utilities';
22
+
23
+ // This file is adapted from https://github.com/microsoft/vscode/blob/c061ce5c24fc480342fbc5f23244289d633c56eb/src/vs/workbench/contrib/debug/browser/disassemblyView.ts
24
+
25
+ export class BreakpointRenderer implements ITableRenderer<DisassembledInstructionEntry, BreakpointColumnTemplateData> {
26
+
27
+ static readonly TEMPLATE_ID = 'breakpoint';
28
+
29
+ templateId: string = BreakpointRenderer.TEMPLATE_ID;
30
+
31
+ protected readonly _breakpointIcon = 'codicon-debug-breakpoint';
32
+ protected readonly _breakpointDisabledIcon = 'codicon-debug-breakpoint-disabled';
33
+ protected readonly _breakpointHintIcon = 'codicon-debug-hint';
34
+ protected readonly _debugStackframe = 'codicon-debug-stackframe';
35
+ protected readonly _debugStackframeFocused = 'codicon-debug-stackframe-focused';
36
+
37
+ constructor(
38
+ protected readonly _disassemblyView: DisassemblyViewRendererReference,
39
+ protected readonly _debugService: BreakpointManager,
40
+ ) { }
41
+
42
+ renderTemplate(container: HTMLElement): BreakpointColumnTemplateData {
43
+ // align from the bottom so that it lines up with instruction when source code is present.
44
+ container.style.alignSelf = 'flex-end';
45
+
46
+ const icon = append(container, $('.disassembly-view'));
47
+ icon.classList.add('codicon');
48
+ icon.style.display = 'flex';
49
+ icon.style.alignItems = 'center';
50
+ icon.style.justifyContent = 'center';
51
+ icon.style.height = this._disassemblyView.fontInfo.lineHeight + 'px';
52
+
53
+ const currentElement: { element?: DisassembledInstructionEntry } = { element: undefined };
54
+
55
+ const disposables = [
56
+ this._disassemblyView.onDidChangeStackFrame(() => this.rerenderDebugStackframe(icon, currentElement.element)),
57
+ addStandardDisposableListener(container, 'mouseover', () => {
58
+ if (currentElement.element?.allowBreakpoint) {
59
+ icon.classList.add(this._breakpointHintIcon);
60
+ }
61
+ }),
62
+ addStandardDisposableListener(container, 'mouseout', () => {
63
+ if (currentElement.element?.allowBreakpoint) {
64
+ icon.classList.remove(this._breakpointHintIcon);
65
+ }
66
+ }),
67
+ addStandardDisposableListener(container, 'click', () => {
68
+ if (currentElement.element?.allowBreakpoint) {
69
+ // click show hint while waiting for BP to resolve.
70
+ icon.classList.add(this._breakpointHintIcon);
71
+ if (currentElement.element.isBreakpointSet) {
72
+ this._debugService.removeInstructionBreakpoint(currentElement.element.instruction.address);
73
+
74
+ } else if (currentElement.element.allowBreakpoint && !currentElement.element.isBreakpointSet) {
75
+ this._debugService.addInstructionBreakpoint(currentElement.element.instruction.address, 0);
76
+ }
77
+ }
78
+ })
79
+ ];
80
+
81
+ return { currentElement, icon, disposables };
82
+ }
83
+
84
+ renderElement(element: DisassembledInstructionEntry, index: number, templateData: BreakpointColumnTemplateData, height: number | undefined): void {
85
+ templateData.currentElement.element = element;
86
+ this.rerenderDebugStackframe(templateData.icon, element);
87
+ }
88
+
89
+ disposeTemplate(templateData: BreakpointColumnTemplateData): void {
90
+ dispose(templateData.disposables);
91
+ templateData.disposables = [];
92
+ }
93
+
94
+ protected rerenderDebugStackframe(icon: HTMLElement, element?: DisassembledInstructionEntry): void {
95
+ if (element?.instruction.address === this._disassemblyView.focusedCurrentInstructionAddress) {
96
+ icon.classList.add(this._debugStackframe);
97
+ } else if (element?.instruction.address === this._disassemblyView.focusedInstructionAddress) {
98
+ icon.classList.add(this._debugStackframeFocused);
99
+ } else {
100
+ icon.classList.remove(this._debugStackframe);
101
+ icon.classList.remove(this._debugStackframeFocused);
102
+ }
103
+
104
+ icon.classList.remove(this._breakpointHintIcon);
105
+
106
+ if (element?.isBreakpointSet) {
107
+ if (element.isBreakpointEnabled) {
108
+ icon.classList.add(this._breakpointIcon);
109
+ icon.classList.remove(this._breakpointDisabledIcon);
110
+ } else {
111
+ icon.classList.remove(this._breakpointIcon);
112
+ icon.classList.add(this._breakpointDisabledIcon);
113
+ }
114
+ } else {
115
+ icon.classList.remove(this._breakpointIcon);
116
+ icon.classList.remove(this._breakpointDisabledIcon);
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,109 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
18
+ import { AbstractViewContribution, bindViewContribution, WidgetFactory } from '@theia/core/lib/browser';
19
+ import { DisassemblyViewWidget } from './disassembly-view-widget';
20
+ import { Command, CommandRegistry, MenuModelRegistry, nls } from '@theia/core';
21
+ import { DebugService } from '../../common/debug-service';
22
+ import { EditorManager, EDITOR_CONTEXT_MENU } from '@theia/editor/lib/browser';
23
+ import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
24
+ import { DebugSessionManager } from '../debug-session-manager';
25
+ import { DebugStackFrame } from '../model/debug-stack-frame';
26
+ import { DebugSession, DebugState } from '../debug-session';
27
+ import { DebugStackFramesWidget } from '../view/debug-stack-frames-widget';
28
+
29
+ export const OPEN_DISASSEMBLY_VIEW_COMMAND: Command = {
30
+ id: 'open-disassembly-view',
31
+ label: nls.localize('theia/debug/open-disassembly-view', 'Open Disassembly View')
32
+ };
33
+
34
+ export const LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST = 'languageSupportsDisassembleRequest';
35
+ export const FOCUSED_STACK_FRAME_HAS_INSTRUCTION_REFERENCE = 'focusedStackFrameHasInstructionReference';
36
+ export const DISASSEMBLE_REQUEST_SUPPORTED = 'disassembleRequestSupported';
37
+ export const DISASSEMBLY_VIEW_FOCUS = 'disassemblyViewFocus';
38
+
39
+ @injectable()
40
+ export class DisassemblyViewContribution extends AbstractViewContribution<DisassemblyViewWidget> {
41
+ @inject(DebugService) protected readonly debugService: DebugService;
42
+ @inject(EditorManager) protected readonly editorManager: EditorManager;
43
+ @inject(ContextKeyService) protected readonly contextKeyService: ContextKeyService;
44
+ @inject(DebugSessionManager) protected readonly debugSessionManager: DebugSessionManager;
45
+
46
+ constructor() {
47
+ super({
48
+ widgetId: DisassemblyViewWidget.ID,
49
+ widgetName: 'Disassembly View',
50
+ defaultWidgetOptions: { area: 'main' }
51
+ });
52
+ }
53
+
54
+ @postConstruct()
55
+ protected init(): void {
56
+ let activeEditorChangeCancellation = { cancelled: false };
57
+ const updateLanguageSupportsDisassemblyKey = async () => {
58
+ const editor = this.editorManager.currentEditor;
59
+ activeEditorChangeCancellation.cancelled = true;
60
+ const localCancellation = activeEditorChangeCancellation = { cancelled: false };
61
+
62
+ const language = editor?.editor.document.languageId;
63
+ const debuggersForLanguage = language && await this.debugService.getDebuggersForLanguage(language);
64
+ if (!localCancellation.cancelled) {
65
+ this.contextKeyService.setContext(LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST, Boolean(debuggersForLanguage?.length));
66
+ }
67
+ };
68
+ this.editorManager.onCurrentEditorChanged(updateLanguageSupportsDisassemblyKey);
69
+ this.debugService.onDidChangeDebuggers?.(updateLanguageSupportsDisassemblyKey);
70
+ let lastSession: DebugSession | undefined;
71
+ let lastFrame: DebugStackFrame | undefined;
72
+ this.debugSessionManager.onDidChange(() => {
73
+ const { currentFrame, currentSession } = this.debugSessionManager;
74
+ if (currentFrame !== lastFrame) {
75
+ lastFrame = currentFrame;
76
+ this.contextKeyService.setContext(FOCUSED_STACK_FRAME_HAS_INSTRUCTION_REFERENCE, Boolean(currentFrame?.raw.instructionPointerReference));
77
+ }
78
+ if (currentSession !== lastSession) {
79
+ lastSession = currentSession;
80
+ this.contextKeyService.setContext(DISASSEMBLE_REQUEST_SUPPORTED, Boolean(currentSession?.capabilities.supportsDisassembleRequest));
81
+ }
82
+ });
83
+ this.shell.onDidChangeCurrentWidget(widget => {
84
+ this.contextKeyService.setContext(DISASSEMBLY_VIEW_FOCUS, widget instanceof DisassemblyViewWidget);
85
+ });
86
+ }
87
+
88
+ override registerCommands(commands: CommandRegistry): void {
89
+ commands.registerCommand(OPEN_DISASSEMBLY_VIEW_COMMAND, {
90
+ isEnabled: () => this.debugSessionManager.inDebugMode
91
+ && this.debugSessionManager.state === DebugState.Stopped
92
+ && this.contextKeyService.match('focusedStackFrameHasInstructionReference'),
93
+ execute: () => this.openView({ activate: true }),
94
+ });
95
+ }
96
+
97
+ override registerMenus(menus: MenuModelRegistry): void {
98
+ menus.registerMenuAction(DebugStackFramesWidget.CONTEXT_MENU,
99
+ { commandId: OPEN_DISASSEMBLY_VIEW_COMMAND.id, label: OPEN_DISASSEMBLY_VIEW_COMMAND.label });
100
+ menus.registerMenuAction([...EDITOR_CONTEXT_MENU, 'a_debug'],
101
+ { commandId: OPEN_DISASSEMBLY_VIEW_COMMAND.id, label: OPEN_DISASSEMBLY_VIEW_COMMAND.label, when: LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST });
102
+ }
103
+ }
104
+
105
+ export function bindDisassemblyView(bind: interfaces.Bind): void {
106
+ bind(DisassemblyViewWidget).toSelf();
107
+ bind(WidgetFactory).toDynamicValue(({ container }) => ({ id: DisassemblyViewWidget.ID, createWidget: () => container.get(DisassemblyViewWidget) }));
108
+ bindViewContribution(bind, DisassemblyViewContribution);
109
+ }
@@ -0,0 +1,245 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { open, OpenerService } from '@theia/core/lib/browser';
18
+ import { URI as TheiaURI } from '@theia/core/lib/common/uri';
19
+ import { EditorOpenerOptions } from '@theia/editor/lib/browser';
20
+ import { IDisposable, Uri as URI } from '@theia/monaco-editor-core';
21
+ import { $, addStandardDisposableListener, append } from '@theia/monaco-editor-core/esm/vs/base/browser/dom';
22
+ import { ITableRenderer } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/table/table';
23
+ import { Color } from '@theia/monaco-editor-core/esm/vs/base/common/color';
24
+ import { Disposable, dispose } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
25
+ import { isAbsolute } from '@theia/monaco-editor-core/esm/vs/base/common/path';
26
+ import { Constants } from '@theia/monaco-editor-core/esm/vs/base/common/uint';
27
+ import { applyFontInfo } from '@theia/monaco-editor-core/esm/vs/editor/browser/config/domFontInfo';
28
+ import { createStringBuilder } from '@theia/monaco-editor-core/esm/vs/editor/common/core/stringBuilder';
29
+ import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
30
+ import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
31
+ import { IThemeService } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
32
+ import { DebugProtocol } from 'vscode-debugprotocol';
33
+ import { DebugSource } from '../model/debug-source';
34
+ import { DisassembledInstructionEntry, DisassemblyViewRendererReference, InstructionColumnTemplateData } from './disassembly-view-utilities';
35
+
36
+ // This file is adapted from https://github.com/microsoft/vscode/blob/c061ce5c24fc480342fbc5f23244289d633c56eb/src/vs/workbench/contrib/debug/browser/disassemblyView.ts
37
+
38
+ const topStackFrameColor = 'editor.stackFrameHighlightBackground';
39
+ const focusedStackFrameColor = 'editor.focusedStackFrameHighlightBackground';
40
+
41
+ export class InstructionRenderer extends Disposable implements ITableRenderer<DisassembledInstructionEntry, InstructionColumnTemplateData> {
42
+
43
+ static readonly TEMPLATE_ID = 'instruction';
44
+
45
+ protected static readonly INSTRUCTION_ADDR_MIN_LENGTH = 25;
46
+ protected static readonly INSTRUCTION_BYTES_MIN_LENGTH = 30;
47
+
48
+ templateId: string = InstructionRenderer.TEMPLATE_ID;
49
+
50
+ protected _topStackFrameColor: Color | undefined;
51
+ protected _focusedStackFrameColor: Color | undefined;
52
+
53
+ constructor(
54
+ protected readonly _disassemblyView: DisassemblyViewRendererReference,
55
+ protected readonly openerService: OpenerService,
56
+ protected readonly uriService: { asCanonicalUri(uri: URI): URI },
57
+ @IThemeService themeService: IThemeService,
58
+ @ITextModelService protected readonly textModelService: ITextModelService,
59
+ ) {
60
+ super();
61
+
62
+ this._topStackFrameColor = themeService.getColorTheme().getColor(topStackFrameColor);
63
+ this._focusedStackFrameColor = themeService.getColorTheme().getColor(focusedStackFrameColor);
64
+
65
+ this._register(themeService.onDidColorThemeChange(e => {
66
+ this._topStackFrameColor = e.getColor(topStackFrameColor);
67
+ this._focusedStackFrameColor = e.getColor(focusedStackFrameColor);
68
+ }));
69
+ }
70
+
71
+ renderTemplate(container: HTMLElement): InstructionColumnTemplateData {
72
+ const sourcecode = append(container, $('.sourcecode'));
73
+ const instruction = append(container, $('.instruction'));
74
+ this.applyFontInfo(sourcecode);
75
+ this.applyFontInfo(instruction);
76
+ const currentElement: { element?: DisassembledInstructionEntry } = { element: undefined };
77
+ const cellDisposable: IDisposable[] = [];
78
+
79
+ const disposables = [
80
+ this._disassemblyView.onDidChangeStackFrame(() => this.rerenderBackground(instruction, sourcecode, currentElement.element)),
81
+ addStandardDisposableListener(sourcecode, 'dblclick', () => this.openSourceCode(currentElement.element?.instruction!)),
82
+ ];
83
+
84
+ return { currentElement, instruction, sourcecode, cellDisposable, disposables };
85
+ }
86
+
87
+ renderElement(element: DisassembledInstructionEntry, index: number, templateData: InstructionColumnTemplateData, height: number | undefined): void {
88
+ this.renderElementInner(element, index, templateData, height);
89
+ }
90
+
91
+ protected async renderElementInner(element: DisassembledInstructionEntry, index: number, column: InstructionColumnTemplateData, height: number | undefined): Promise<void> {
92
+ column.currentElement.element = element;
93
+ const instruction = element.instruction;
94
+ column.sourcecode.innerText = '';
95
+ const sb = createStringBuilder(1000);
96
+
97
+ if (this._disassemblyView.isSourceCodeRender && instruction.location?.path && instruction.line) {
98
+ const sourceURI = this.getUriFromSource(instruction);
99
+
100
+ if (sourceURI) {
101
+ let textModel: ITextModel | undefined = undefined;
102
+ const sourceSB = createStringBuilder(10000);
103
+ const ref = await this.textModelService.createModelReference(sourceURI);
104
+ textModel = ref.object.textEditorModel;
105
+ column.cellDisposable.push(ref);
106
+
107
+ // templateData could have moved on during async. Double check if it is still the same source.
108
+ if (textModel && column.currentElement.element === element) {
109
+ let lineNumber = instruction.line;
110
+
111
+ while (lineNumber && lineNumber >= 1 && lineNumber <= textModel.getLineCount()) {
112
+ const lineContent = textModel.getLineContent(lineNumber);
113
+ sourceSB.appendASCIIString(` ${lineNumber}: `);
114
+ sourceSB.appendASCIIString(lineContent + '\n');
115
+
116
+ if (instruction.endLine && lineNumber < instruction.endLine) {
117
+ lineNumber++;
118
+ continue;
119
+ }
120
+
121
+ break;
122
+ }
123
+
124
+ column.sourcecode.innerText = sourceSB.build();
125
+ }
126
+ }
127
+ }
128
+
129
+ let spacesToAppend = 10;
130
+
131
+ if (instruction.address !== '-1') {
132
+ sb.appendASCIIString(instruction.address);
133
+ if (instruction.address.length < InstructionRenderer.INSTRUCTION_ADDR_MIN_LENGTH) {
134
+ spacesToAppend = InstructionRenderer.INSTRUCTION_ADDR_MIN_LENGTH - instruction.address.length;
135
+ }
136
+ for (let i = 0; i < spacesToAppend; i++) {
137
+ sb.appendASCIIString(' ');
138
+ }
139
+ }
140
+
141
+ if (instruction.instructionBytes) {
142
+ sb.appendASCIIString(instruction.instructionBytes);
143
+ spacesToAppend = 10;
144
+ if (instruction.instructionBytes.length < InstructionRenderer.INSTRUCTION_BYTES_MIN_LENGTH) {
145
+ spacesToAppend = InstructionRenderer.INSTRUCTION_BYTES_MIN_LENGTH - instruction.instructionBytes.length;
146
+ }
147
+ for (let i = 0; i < spacesToAppend; i++) {
148
+ sb.appendASCIIString(' ');
149
+ }
150
+ }
151
+
152
+ sb.appendASCIIString(instruction.instruction);
153
+ column.instruction.innerText = sb.build();
154
+
155
+ this.rerenderBackground(column.instruction, column.sourcecode, element);
156
+ }
157
+
158
+ disposeElement(element: DisassembledInstructionEntry, index: number, templateData: InstructionColumnTemplateData, height: number | undefined): void {
159
+ dispose(templateData.cellDisposable);
160
+ templateData.cellDisposable = [];
161
+ }
162
+
163
+ disposeTemplate(templateData: InstructionColumnTemplateData): void {
164
+ dispose(templateData.disposables);
165
+ templateData.disposables = [];
166
+ }
167
+
168
+ protected rerenderBackground(instruction: HTMLElement, sourceCode: HTMLElement, element?: DisassembledInstructionEntry): void {
169
+ if (element && this._disassemblyView.currentInstructionAddresses.includes(element.instruction.address)) {
170
+ instruction.style.background = this._topStackFrameColor?.toString() || 'transparent';
171
+ } else if (element?.instruction.address === this._disassemblyView.focusedInstructionAddress) {
172
+ instruction.style.background = this._focusedStackFrameColor?.toString() || 'transparent';
173
+ } else {
174
+ instruction.style.background = 'transparent';
175
+ }
176
+ }
177
+
178
+ protected openSourceCode(instruction: DebugProtocol.DisassembledInstruction | undefined): void {
179
+ if (instruction) {
180
+ const sourceURI = this.getUriFromSource(instruction);
181
+ const selection: EditorOpenerOptions['selection'] = instruction.endLine ? {
182
+ start: { line: instruction.line!, character: instruction.column ?? 0 },
183
+ end: { line: instruction.endLine, character: instruction.endColumn ?? Constants.MAX_SAFE_SMALL_INTEGER }
184
+ } : {
185
+ start: { line: instruction.line!, character: instruction.column ?? 0 },
186
+ end: { line: instruction.line, character: instruction.endColumn ?? Constants.MAX_SAFE_SMALL_INTEGER }
187
+ };
188
+
189
+ const openerOptions: EditorOpenerOptions = {
190
+ selection,
191
+ mode: 'activate',
192
+ widgetOptions: { area: 'main' }
193
+ };
194
+ open(this.openerService, new TheiaURI(sourceURI), openerOptions);
195
+ }
196
+ }
197
+
198
+ protected getUriFromSource(instruction: DebugProtocol.DisassembledInstruction): URI {
199
+ // Try to resolve path before consulting the debugSession.
200
+ const path = instruction.location!.path;
201
+ if (path && isUri(path)) { // path looks like a uri
202
+ return this.uriService.asCanonicalUri(URI.parse(path));
203
+ }
204
+ // assume a filesystem path
205
+ if (path && isAbsolute(path)) {
206
+ return this.uriService.asCanonicalUri(URI.file(path));
207
+ }
208
+
209
+ return getUriFromSource(instruction.location!, instruction.location!.path, this._disassemblyView.debugSession!.id, this.uriService);
210
+ }
211
+
212
+ protected applyFontInfo(element: HTMLElement): void {
213
+ applyFontInfo(element, this._disassemblyView.fontInfo);
214
+ element.style.whiteSpace = 'pre';
215
+ }
216
+ }
217
+
218
+ export function getUriFromSource(raw: DebugProtocol.Source, path: string | undefined, sessionId: string, uriIdentityService: { asCanonicalUri(uri: URI): URI }): URI {
219
+ if (typeof raw.sourceReference === 'number' && raw.sourceReference > 0) {
220
+ return URI.from({
221
+ scheme: DebugSource.SCHEME,
222
+ path,
223
+ query: `session=${sessionId}&ref=${raw.sourceReference}`
224
+ });
225
+ }
226
+
227
+ if (path && isUri(path)) { // path looks like a uri
228
+ return uriIdentityService.asCanonicalUri(URI.parse(path));
229
+ }
230
+ // assume a filesystem path
231
+ if (path && isAbsolute(path)) {
232
+ return uriIdentityService.asCanonicalUri(URI.file(path));
233
+ }
234
+ // path is relative: since VS Code cannot deal with this by itself
235
+ // create a debug url that will result in a DAP 'source' request when the url is resolved.
236
+ return uriIdentityService.asCanonicalUri(URI.from({
237
+ scheme: DebugSource.SCHEME,
238
+ path,
239
+ query: `session=${sessionId}`
240
+ }));
241
+ }
242
+
243
+ function isUri(candidate: string | undefined): boolean {
244
+ return Boolean(candidate && candidate.match(DebugSource.SCHEME_PATTERN));
245
+ }
@@ -0,0 +1,39 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { ITableVirtualDelegate } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/table/table';
18
+ import { BareFontInfo } from '@theia/monaco-editor-core/esm/vs/editor/common/config/fontInfo';
19
+ import { DisassembledInstructionEntry } from './disassembly-view-utilities';
20
+
21
+ // This file is adapted from https://github.com/microsoft/vscode/blob/c061ce5c24fc480342fbc5f23244289d633c56eb/src/vs/workbench/contrib/debug/browser/disassemblyView.ts
22
+
23
+ export class DisassemblyViewTableDelegate implements ITableVirtualDelegate<DisassembledInstructionEntry> {
24
+ constructor(protected readonly fontInfoProvider: { fontInfo: BareFontInfo, isSourceCodeRender: boolean }) { }
25
+
26
+ headerRowHeight = 0;
27
+
28
+ getHeight(row: DisassembledInstructionEntry): number {
29
+ if (this.fontInfoProvider.isSourceCodeRender && row.instruction.location?.path && row.instruction.line !== undefined) {
30
+ if (row.instruction.endLine !== undefined) {
31
+ return this.fontInfoProvider.fontInfo.lineHeight + (row.instruction.endLine - row.instruction.line + 2);
32
+ } else {
33
+ return this.fontInfoProvider.fontInfo.lineHeight * 2;
34
+ }
35
+ }
36
+
37
+ return this.fontInfoProvider.fontInfo.lineHeight;
38
+ }
39
+ }