@theia/memory-inspector 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 (102) hide show
  1. package/README.md +71 -71
  2. package/lib/browser/diff-widget/memory-diff-options-widget.d.ts +36 -36
  3. package/lib/browser/diff-widget/memory-diff-options-widget.js +132 -132
  4. package/lib/browser/diff-widget/memory-diff-select-widget.d.ts +50 -50
  5. package/lib/browser/diff-widget/memory-diff-select-widget.js +137 -137
  6. package/lib/browser/diff-widget/memory-diff-table-widget.d.ts +77 -77
  7. package/lib/browser/diff-widget/memory-diff-table-widget.js +314 -314
  8. package/lib/browser/diff-widget/memory-diff-widget-types.d.ts +41 -41
  9. package/lib/browser/diff-widget/memory-diff-widget-types.js +23 -23
  10. package/lib/browser/editable-widget/memory-editable-table-widget.d.ts +64 -64
  11. package/lib/browser/editable-widget/memory-editable-table-widget.js +324 -324
  12. package/lib/browser/memory-inspector-frontend-contribution.d.ts +46 -46
  13. package/lib/browser/memory-inspector-frontend-contribution.js +291 -291
  14. package/lib/browser/memory-inspector-frontend-module.d.ts +21 -21
  15. package/lib/browser/memory-inspector-frontend-module.js +87 -87
  16. package/lib/browser/memory-provider/cdt-gdb-memory-provider.d.ts +35 -35
  17. package/lib/browser/memory-provider/cdt-gdb-memory-provider.js +136 -136
  18. package/lib/browser/memory-provider/memory-provider-service.d.ts +36 -36
  19. package/lib/browser/memory-provider/memory-provider-service.js +101 -101
  20. package/lib/browser/memory-provider/memory-provider.d.ts +65 -65
  21. package/lib/browser/memory-provider/memory-provider.js +96 -96
  22. package/lib/browser/memory-provider/memory-provider.spec.d.ts +16 -16
  23. package/lib/browser/memory-provider/memory-provider.spec.js +23 -23
  24. package/lib/browser/memory-widget/memory-options-widget.d.ts +136 -136
  25. package/lib/browser/memory-widget/memory-options-widget.js +564 -564
  26. package/lib/browser/memory-widget/memory-table-widget.d.ts +146 -146
  27. package/lib/browser/memory-widget/memory-table-widget.js +487 -487
  28. package/lib/browser/memory-widget/memory-widget.d.ts +33 -33
  29. package/lib/browser/memory-widget/memory-widget.js +112 -112
  30. package/lib/browser/register-widget/register-filter-service.d.ts +42 -42
  31. package/lib/browser/register-widget/register-filter-service.js +81 -81
  32. package/lib/browser/register-widget/register-options-widget.d.ts +81 -81
  33. package/lib/browser/register-widget/register-options-widget.js +338 -338
  34. package/lib/browser/register-widget/register-table-widget.d.ts +77 -77
  35. package/lib/browser/register-widget/register-table-widget.js +230 -230
  36. package/lib/browser/register-widget/register-widget-types.d.ts +29 -29
  37. package/lib/browser/register-widget/register-widget-types.js +35 -35
  38. package/lib/browser/utils/memory-commands.d.ts +27 -27
  39. package/lib/browser/utils/memory-commands.js +67 -67
  40. package/lib/browser/utils/memory-hover-renderer.d.ts +33 -33
  41. package/lib/browser/utils/memory-hover-renderer.js +111 -111
  42. package/lib/browser/utils/memory-recents.d.ts +27 -27
  43. package/lib/browser/utils/memory-recents.js +52 -52
  44. package/lib/browser/utils/memory-widget-components.d.ts +58 -58
  45. package/lib/browser/utils/memory-widget-components.js +69 -69
  46. package/lib/browser/utils/memory-widget-manager.d.ts +50 -50
  47. package/lib/browser/utils/memory-widget-manager.js +182 -182
  48. package/lib/browser/utils/memory-widget-utils.d.ts +113 -113
  49. package/lib/browser/utils/memory-widget-utils.js +42 -42
  50. package/lib/browser/utils/memory-widget-variable-utils.d.ts +57 -57
  51. package/lib/browser/utils/memory-widget-variable-utils.js +143 -143
  52. package/lib/browser/utils/multi-select-bar.d.ts +31 -31
  53. package/lib/browser/utils/multi-select-bar.js +34 -34
  54. package/lib/browser/wrapper-widgets/memory-dock-panel.d.ts +24 -24
  55. package/lib/browser/wrapper-widgets/memory-dock-panel.js +48 -48
  56. package/lib/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.d.ts +23 -23
  57. package/lib/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.js +57 -57
  58. package/lib/browser/wrapper-widgets/memory-layout-widget.d.ts +51 -51
  59. package/lib/browser/wrapper-widgets/memory-layout-widget.js +191 -191
  60. package/lib/common/util.d.ts +21 -21
  61. package/lib/common/util.js +30 -30
  62. package/lib/common/utils.spec.d.ts +16 -16
  63. package/lib/common/utils.spec.js +45 -45
  64. package/package.json +4 -4
  65. package/src/browser/diff-widget/memory-diff-options-widget.tsx +152 -152
  66. package/src/browser/diff-widget/memory-diff-select-widget.tsx +163 -163
  67. package/src/browser/diff-widget/memory-diff-table-widget.tsx +366 -366
  68. package/src/browser/diff-widget/memory-diff-widget-types.ts +45 -45
  69. package/src/browser/editable-widget/memory-editable-table-widget.tsx +359 -359
  70. package/src/browser/memory-inspector-frontend-contribution.ts +301 -301
  71. package/src/browser/memory-inspector-frontend-module.ts +118 -118
  72. package/src/browser/memory-provider/cdt-gdb-memory-provider.ts +132 -132
  73. package/src/browser/memory-provider/memory-provider-service.ts +86 -86
  74. package/src/browser/memory-provider/memory-provider.spec.ts +23 -23
  75. package/src/browser/memory-provider/memory-provider.ts +119 -119
  76. package/src/browser/memory-widget/memory-options-widget.tsx +738 -738
  77. package/src/browser/memory-widget/memory-table-widget.tsx +625 -625
  78. package/src/browser/memory-widget/memory-widget.ts +114 -114
  79. package/src/browser/register-widget/register-filter-service.ts +76 -76
  80. package/src/browser/register-widget/register-options-widget.tsx +393 -393
  81. package/src/browser/register-widget/register-table-widget.tsx +276 -276
  82. package/src/browser/register-widget/register-widget-types.ts +45 -45
  83. package/src/browser/register-widget/register-widget.css +34 -34
  84. package/src/browser/style/index.css +746 -746
  85. package/src/browser/style/memory-lock.svg +21 -21
  86. package/src/browser/style/memory-view.svg +20 -20
  87. package/src/browser/style/register-lock.svg +29 -29
  88. package/src/browser/style/register-view.svg +28 -28
  89. package/src/browser/utils/memory-commands.ts +76 -76
  90. package/src/browser/utils/memory-hover-renderer.ts +113 -113
  91. package/src/browser/utils/memory-recents.ts +58 -58
  92. package/src/browser/utils/memory-widget-components.tsx +193 -193
  93. package/src/browser/utils/memory-widget-manager.ts +179 -179
  94. package/src/browser/utils/memory-widget-utils.tsx +132 -132
  95. package/src/browser/utils/memory-widget-variable-utils.ts +170 -170
  96. package/src/browser/utils/multi-select-bar.css +61 -61
  97. package/src/browser/utils/multi-select-bar.tsx +75 -75
  98. package/src/browser/wrapper-widgets/memory-dock-panel.ts +51 -51
  99. package/src/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.tsx +38 -38
  100. package/src/browser/wrapper-widgets/memory-layout-widget.tsx +167 -167
  101. package/src/common/util.ts +28 -28
  102. package/src/common/utils.spec.ts +52 -52
@@ -1,86 +1,86 @@
1
- /********************************************************************************
2
- * Copyright (C) 2021 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-only WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import { ContributionProvider } from '@theia/core';
18
- import { inject, injectable, named } from '@theia/core/shared/inversify';
19
- import { DebugVariable } from '@theia/debug/lib/browser/console/debug-console-items';
20
- import { DebugSession } from '@theia/debug/lib/browser/debug-session';
21
- import { DebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
22
- import { DebugProtocol } from '@vscode/debugprotocol';
23
- import { Interfaces } from '../utils/memory-widget-utils';
24
- import { VariableRange } from '../utils/memory-widget-variable-utils';
25
- import { DefaultMemoryProvider, MemoryProvider } from './memory-provider';
26
- import { nls } from '@theia/core/lib/common/nls';
27
-
28
- @injectable()
29
- export class MemoryProviderService {
30
- @inject(DebugSessionManager) protected readonly sessionManager: DebugSessionManager;
31
- @inject(DefaultMemoryProvider) protected readonly defaultProvider: DefaultMemoryProvider;
32
- @inject(ContributionProvider) @named(MemoryProvider)
33
- protected readonly contributions: ContributionProvider<MemoryProvider>;
34
-
35
- readMemory(readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult> {
36
- const readError = nls.localize('theia/memory-inspector/provider/readError', 'Cannot read memory. No active debug session.');
37
- const session = this.getSession(readError);
38
- if (!session.capabilities.supportsReadMemoryRequest) {
39
- throw new Error('Cannot read memory. The current session does not support the request.');
40
- }
41
- const provider = this.getProvider(session);
42
- return provider.readMemory(session, readMemoryArguments);
43
- }
44
-
45
- writeMemory(writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse> {
46
- const writeError = nls.localize('theia/memory-inspector/provider/writeError', 'Cannot write memory. No active debug session.');
47
- const session = this.getSession(writeError);
48
- if (!session.capabilities.supportsWriteMemoryRequest) {
49
- throw new Error('Cannot write memory. The current session does not support the request.');
50
- }
51
- const provider = this.getProvider(session, 'writeMemory');
52
-
53
- return provider.writeMemory(session, writeMemoryArguments);
54
- }
55
-
56
- getLocals(): Promise<VariableRange[]> {
57
- const localsError = nls.localize('theia/memory-inspector/provider/localsError', 'Cannot read local variables. No active debug session.');
58
- const session = this.getSession(localsError);
59
- const provider = this.getProvider(session, 'getLocals');
60
- return provider.getLocals(session);
61
- }
62
-
63
- supportsVariableReferenceSyntax(variable?: DebugVariable): boolean {
64
- if (!this.sessionManager.currentSession) { return false; }
65
- const provider = this.getProvider(this.sessionManager.currentSession, 'supportsVariableReferenceSyntax');
66
- return provider.supportsVariableReferenceSyntax(this.sessionManager.currentSession, variable);
67
- }
68
-
69
- formatVariableReference(variable?: DebugVariable): string {
70
- if (!this.sessionManager.currentSession) { return ''; }
71
- const provider = this.getProvider(this.sessionManager.currentSession, 'formatVariableReference');
72
- return provider.formatVariableReference(this.sessionManager.currentSession, variable);
73
- }
74
-
75
- /** @throws with {@link message} if there is no active debug session. */
76
- protected getSession(message: string): DebugSession {
77
- if (this.sessionManager.currentSession) { return this.sessionManager.currentSession; }
78
- throw new Error(message);
79
- }
80
-
81
- protected getProvider(session: DebugSession, ensure?: keyof MemoryProvider): Required<MemoryProvider> {
82
- return this.contributions.getContributions()
83
- .find((candidate): candidate is Required<MemoryProvider> => Boolean(!ensure || candidate[ensure]) && candidate.canHandle(session))
84
- ?? this.defaultProvider;
85
- }
86
- }
1
+ /********************************************************************************
2
+ * Copyright (C) 2021 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-only WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ import { ContributionProvider } from '@theia/core';
18
+ import { inject, injectable, named } from '@theia/core/shared/inversify';
19
+ import { DebugVariable } from '@theia/debug/lib/browser/console/debug-console-items';
20
+ import { DebugSession } from '@theia/debug/lib/browser/debug-session';
21
+ import { DebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
22
+ import { DebugProtocol } from '@vscode/debugprotocol';
23
+ import { Interfaces } from '../utils/memory-widget-utils';
24
+ import { VariableRange } from '../utils/memory-widget-variable-utils';
25
+ import { DefaultMemoryProvider, MemoryProvider } from './memory-provider';
26
+ import { nls } from '@theia/core/lib/common/nls';
27
+
28
+ @injectable()
29
+ export class MemoryProviderService {
30
+ @inject(DebugSessionManager) protected readonly sessionManager: DebugSessionManager;
31
+ @inject(DefaultMemoryProvider) protected readonly defaultProvider: DefaultMemoryProvider;
32
+ @inject(ContributionProvider) @named(MemoryProvider)
33
+ protected readonly contributions: ContributionProvider<MemoryProvider>;
34
+
35
+ readMemory(readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult> {
36
+ const readError = nls.localize('theia/memory-inspector/provider/readError', 'Cannot read memory. No active debug session.');
37
+ const session = this.getSession(readError);
38
+ if (!session.capabilities.supportsReadMemoryRequest) {
39
+ throw new Error('Cannot read memory. The current session does not support the request.');
40
+ }
41
+ const provider = this.getProvider(session);
42
+ return provider.readMemory(session, readMemoryArguments);
43
+ }
44
+
45
+ writeMemory(writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse> {
46
+ const writeError = nls.localize('theia/memory-inspector/provider/writeError', 'Cannot write memory. No active debug session.');
47
+ const session = this.getSession(writeError);
48
+ if (!session.capabilities.supportsWriteMemoryRequest) {
49
+ throw new Error('Cannot write memory. The current session does not support the request.');
50
+ }
51
+ const provider = this.getProvider(session, 'writeMemory');
52
+
53
+ return provider.writeMemory(session, writeMemoryArguments);
54
+ }
55
+
56
+ getLocals(): Promise<VariableRange[]> {
57
+ const localsError = nls.localize('theia/memory-inspector/provider/localsError', 'Cannot read local variables. No active debug session.');
58
+ const session = this.getSession(localsError);
59
+ const provider = this.getProvider(session, 'getLocals');
60
+ return provider.getLocals(session);
61
+ }
62
+
63
+ supportsVariableReferenceSyntax(variable?: DebugVariable): boolean {
64
+ if (!this.sessionManager.currentSession) { return false; }
65
+ const provider = this.getProvider(this.sessionManager.currentSession, 'supportsVariableReferenceSyntax');
66
+ return provider.supportsVariableReferenceSyntax(this.sessionManager.currentSession, variable);
67
+ }
68
+
69
+ formatVariableReference(variable?: DebugVariable): string {
70
+ if (!this.sessionManager.currentSession) { return ''; }
71
+ const provider = this.getProvider(this.sessionManager.currentSession, 'formatVariableReference');
72
+ return provider.formatVariableReference(this.sessionManager.currentSession, variable);
73
+ }
74
+
75
+ /** @throws with {@link message} if there is no active debug session. */
76
+ protected getSession(message: string): DebugSession {
77
+ if (this.sessionManager.currentSession) { return this.sessionManager.currentSession; }
78
+ throw new Error(message);
79
+ }
80
+
81
+ protected getProvider(session: DebugSession, ensure?: keyof MemoryProvider): Required<MemoryProvider> {
82
+ return this.contributions.getContributions()
83
+ .find((candidate): candidate is Required<MemoryProvider> => Boolean(!ensure || candidate[ensure]) && candidate.canHandle(session))
84
+ ?? this.defaultProvider;
85
+ }
86
+ }
@@ -1,23 +1,23 @@
1
- /********************************************************************************
2
- * Copyright (C) 2019 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-only WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import { expect } from 'chai';
18
-
19
- describe('memory-inspector', () => {
20
- it('should pass', () => {
21
- expect(true).to.equal(true);
22
- });
23
- });
1
+ /********************************************************************************
2
+ * Copyright (C) 2019 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-only WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ import { expect } from 'chai';
18
+
19
+ describe('memory-inspector', () => {
20
+ it('should pass', () => {
21
+ expect(true).to.equal(true);
22
+ });
23
+ });
@@ -1,119 +1,119 @@
1
- /********************************************************************************
2
- * Copyright (C) 2019 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-only WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import { inject, injectable } from '@theia/core/shared/inversify';
18
- import { DebugVariable } from '@theia/debug/lib/browser/console/debug-console-items';
19
- import { DebugSession } from '@theia/debug/lib/browser/debug-session';
20
- import { DebugProtocol } from '@vscode/debugprotocol';
21
- import { Interfaces } from '../utils/memory-widget-utils';
22
- import { VariableRange } from '../utils/memory-widget-variable-utils';
23
- import Long = require('long');
24
-
25
- export const MemoryProvider = Symbol('MemoryProvider');
26
- /**
27
- * Representation of a memory provider. It is only necessary to implement a new Memory Provider if the behavior of the Debug Adapter for a given session type
28
- * deviates from the Debug Adapter Protocol. Otherwise, the DefaultMemoryProvider should handle standard DAP requests and responses.
29
- *
30
- * Specific peculiarities that might require special handling include: restrictions on the formatting of memory location identifiers (only hex numbers, e.g.)
31
- * or deviations from the DAP in the format of the response to a given request.
32
- */
33
- export interface MemoryProvider {
34
- /**
35
- * @param session
36
- * @return whether the given MemoryProvider can handle memory reading / writing for a session of the type submitted.
37
- */
38
- canHandle(session: DebugSession): boolean;
39
- readMemory(session: DebugSession, readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult>;
40
- writeMemory?(session: DebugSession, writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse>;
41
- getLocals?(session: DebugSession): Promise<VariableRange[]>;
42
- /**
43
- * Whether the current debugger supports variable reference syntax (e.g. &a) in the `memoryReference` field of
44
- * @link DebugProtocol.ReadMemoryArguments, ReadMemoryArguments}
45
- */
46
- supportsVariableReferenceSyntax?(session: DebugSession, variable?: DebugVariable): boolean;
47
- formatVariableReference?(session: DebugSession, variable?: DebugVariable): string;
48
- }
49
-
50
- /**
51
- * Convert a base64-encoded string of bytes to the Uint8Array equivalent.
52
- */
53
- export function base64ToBytes(base64: string): Interfaces.LabeledUint8Array {
54
- return Buffer.from(base64, 'base64');
55
- }
56
-
57
- @injectable()
58
- export class DefaultMemoryProvider implements Required<MemoryProvider> {
59
- // This provider should only be used a fallback - it shouldn't volunteer to handle any session.
60
- canHandle(): false {
61
- return false;
62
- }
63
-
64
- async readMemory(session: DebugSession, readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult> {
65
- console.log('Requesting memory with the following arguments:', readMemoryArguments);
66
- const result = await session.sendRequest('readMemory', readMemoryArguments) as DebugProtocol.ReadMemoryResponse;
67
-
68
- if (result.body?.data) {
69
- const { body: { data, address } } = result;
70
- const bytes = base64ToBytes(data);
71
- const longAddress = result.body.address.startsWith('0x') ? Long.fromString(address, true, 16) : Long.fromString(address, true, 10);
72
- return { bytes, address: longAddress };
73
- }
74
- throw new Error('Received no data from debug adapter.');
75
- }
76
-
77
- async writeMemory(session: DebugSession, writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse> {
78
- return session.sendRequest('writeMemory', writeMemoryArguments);
79
- }
80
-
81
- async getLocals(session: DebugSession): Promise<VariableRange[]> {
82
- return [];
83
- }
84
-
85
- supportsVariableReferenceSyntax(session: DebugSession, variable?: DebugVariable | undefined): boolean {
86
- return false;
87
- }
88
-
89
- formatVariableReference(session: DebugSession, variable?: DebugVariable | undefined): string {
90
- return '';
91
- }
92
- }
93
-
94
- @injectable()
95
- export abstract class AbstractMemoryProvider implements Required<MemoryProvider> {
96
- @inject(DefaultMemoryProvider) protected readonly defaultProvider: DefaultMemoryProvider;
97
-
98
- abstract canHandle(session: DebugSession): boolean;
99
-
100
- readMemory(session: DebugSession, readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult> {
101
- return this.defaultProvider.readMemory(session, readMemoryArguments);
102
- }
103
-
104
- writeMemory(session: DebugSession, writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse> {
105
- return this.defaultProvider.writeMemory(session, writeMemoryArguments);
106
- }
107
-
108
- getLocals(session: DebugSession): Promise<VariableRange[]> {
109
- return this.defaultProvider.getLocals(session);
110
- }
111
-
112
- supportsVariableReferenceSyntax(session: DebugSession, variable?: DebugVariable | undefined): boolean {
113
- return this.defaultProvider.supportsVariableReferenceSyntax(session, variable);
114
- }
115
-
116
- formatVariableReference(session: DebugSession, variable?: DebugVariable | undefined): string {
117
- return this.defaultProvider.formatVariableReference(session, variable);
118
- }
119
- }
1
+ /********************************************************************************
2
+ * Copyright (C) 2019 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-only WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import { DebugVariable } from '@theia/debug/lib/browser/console/debug-console-items';
19
+ import { DebugSession } from '@theia/debug/lib/browser/debug-session';
20
+ import { DebugProtocol } from '@vscode/debugprotocol';
21
+ import { Interfaces } from '../utils/memory-widget-utils';
22
+ import { VariableRange } from '../utils/memory-widget-variable-utils';
23
+ import Long = require('long');
24
+
25
+ export const MemoryProvider = Symbol('MemoryProvider');
26
+ /**
27
+ * Representation of a memory provider. It is only necessary to implement a new Memory Provider if the behavior of the Debug Adapter for a given session type
28
+ * deviates from the Debug Adapter Protocol. Otherwise, the DefaultMemoryProvider should handle standard DAP requests and responses.
29
+ *
30
+ * Specific peculiarities that might require special handling include: restrictions on the formatting of memory location identifiers (only hex numbers, e.g.)
31
+ * or deviations from the DAP in the format of the response to a given request.
32
+ */
33
+ export interface MemoryProvider {
34
+ /**
35
+ * @param session
36
+ * @return whether the given MemoryProvider can handle memory reading / writing for a session of the type submitted.
37
+ */
38
+ canHandle(session: DebugSession): boolean;
39
+ readMemory(session: DebugSession, readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult>;
40
+ writeMemory?(session: DebugSession, writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse>;
41
+ getLocals?(session: DebugSession): Promise<VariableRange[]>;
42
+ /**
43
+ * Whether the current debugger supports variable reference syntax (e.g. &a) in the `memoryReference` field of
44
+ * @link DebugProtocol.ReadMemoryArguments, ReadMemoryArguments}
45
+ */
46
+ supportsVariableReferenceSyntax?(session: DebugSession, variable?: DebugVariable): boolean;
47
+ formatVariableReference?(session: DebugSession, variable?: DebugVariable): string;
48
+ }
49
+
50
+ /**
51
+ * Convert a base64-encoded string of bytes to the Uint8Array equivalent.
52
+ */
53
+ export function base64ToBytes(base64: string): Interfaces.LabeledUint8Array {
54
+ return Buffer.from(base64, 'base64');
55
+ }
56
+
57
+ @injectable()
58
+ export class DefaultMemoryProvider implements Required<MemoryProvider> {
59
+ // This provider should only be used a fallback - it shouldn't volunteer to handle any session.
60
+ canHandle(): false {
61
+ return false;
62
+ }
63
+
64
+ async readMemory(session: DebugSession, readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult> {
65
+ console.log('Requesting memory with the following arguments:', readMemoryArguments);
66
+ const result = await session.sendRequest('readMemory', readMemoryArguments) as DebugProtocol.ReadMemoryResponse;
67
+
68
+ if (result.body?.data) {
69
+ const { body: { data, address } } = result;
70
+ const bytes = base64ToBytes(data);
71
+ const longAddress = result.body.address.startsWith('0x') ? Long.fromString(address, true, 16) : Long.fromString(address, true, 10);
72
+ return { bytes, address: longAddress };
73
+ }
74
+ throw new Error('Received no data from debug adapter.');
75
+ }
76
+
77
+ async writeMemory(session: DebugSession, writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse> {
78
+ return session.sendRequest('writeMemory', writeMemoryArguments);
79
+ }
80
+
81
+ async getLocals(session: DebugSession): Promise<VariableRange[]> {
82
+ return [];
83
+ }
84
+
85
+ supportsVariableReferenceSyntax(session: DebugSession, variable?: DebugVariable | undefined): boolean {
86
+ return false;
87
+ }
88
+
89
+ formatVariableReference(session: DebugSession, variable?: DebugVariable | undefined): string {
90
+ return '';
91
+ }
92
+ }
93
+
94
+ @injectable()
95
+ export abstract class AbstractMemoryProvider implements Required<MemoryProvider> {
96
+ @inject(DefaultMemoryProvider) protected readonly defaultProvider: DefaultMemoryProvider;
97
+
98
+ abstract canHandle(session: DebugSession): boolean;
99
+
100
+ readMemory(session: DebugSession, readMemoryArguments: DebugProtocol.ReadMemoryArguments): Promise<Interfaces.MemoryReadResult> {
101
+ return this.defaultProvider.readMemory(session, readMemoryArguments);
102
+ }
103
+
104
+ writeMemory(session: DebugSession, writeMemoryArguments: DebugProtocol.WriteMemoryArguments): Promise<DebugProtocol.WriteMemoryResponse> {
105
+ return this.defaultProvider.writeMemory(session, writeMemoryArguments);
106
+ }
107
+
108
+ getLocals(session: DebugSession): Promise<VariableRange[]> {
109
+ return this.defaultProvider.getLocals(session);
110
+ }
111
+
112
+ supportsVariableReferenceSyntax(session: DebugSession, variable?: DebugVariable | undefined): boolean {
113
+ return this.defaultProvider.supportsVariableReferenceSyntax(session, variable);
114
+ }
115
+
116
+ formatVariableReference(session: DebugSession, variable?: DebugVariable | undefined): string {
117
+ return this.defaultProvider.formatVariableReference(session, variable);
118
+ }
119
+ }