@theia/memory-inspector 1.53.0-next.5 → 1.53.0-next.55

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 (40) hide show
  1. package/README.md +71 -71
  2. package/package.json +4 -4
  3. package/src/browser/diff-widget/memory-diff-options-widget.tsx +152 -152
  4. package/src/browser/diff-widget/memory-diff-select-widget.tsx +163 -163
  5. package/src/browser/diff-widget/memory-diff-table-widget.tsx +366 -366
  6. package/src/browser/diff-widget/memory-diff-widget-types.ts +45 -45
  7. package/src/browser/editable-widget/memory-editable-table-widget.tsx +359 -359
  8. package/src/browser/memory-inspector-frontend-contribution.ts +301 -301
  9. package/src/browser/memory-inspector-frontend-module.ts +118 -118
  10. package/src/browser/memory-provider/cdt-gdb-memory-provider.ts +132 -132
  11. package/src/browser/memory-provider/memory-provider-service.ts +86 -86
  12. package/src/browser/memory-provider/memory-provider.spec.ts +23 -23
  13. package/src/browser/memory-provider/memory-provider.ts +119 -119
  14. package/src/browser/memory-widget/memory-options-widget.tsx +738 -738
  15. package/src/browser/memory-widget/memory-table-widget.tsx +625 -625
  16. package/src/browser/memory-widget/memory-widget.ts +114 -114
  17. package/src/browser/register-widget/register-filter-service.ts +76 -76
  18. package/src/browser/register-widget/register-options-widget.tsx +393 -393
  19. package/src/browser/register-widget/register-table-widget.tsx +276 -276
  20. package/src/browser/register-widget/register-widget-types.ts +45 -45
  21. package/src/browser/register-widget/register-widget.css +34 -34
  22. package/src/browser/style/index.css +746 -746
  23. package/src/browser/style/memory-lock.svg +21 -21
  24. package/src/browser/style/memory-view.svg +20 -20
  25. package/src/browser/style/register-lock.svg +29 -29
  26. package/src/browser/style/register-view.svg +28 -28
  27. package/src/browser/utils/memory-commands.ts +76 -76
  28. package/src/browser/utils/memory-hover-renderer.ts +113 -113
  29. package/src/browser/utils/memory-recents.ts +58 -58
  30. package/src/browser/utils/memory-widget-components.tsx +193 -193
  31. package/src/browser/utils/memory-widget-manager.ts +179 -179
  32. package/src/browser/utils/memory-widget-utils.tsx +132 -132
  33. package/src/browser/utils/memory-widget-variable-utils.ts +170 -170
  34. package/src/browser/utils/multi-select-bar.css +61 -61
  35. package/src/browser/utils/multi-select-bar.tsx +75 -75
  36. package/src/browser/wrapper-widgets/memory-dock-panel.ts +51 -51
  37. package/src/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.tsx +38 -38
  38. package/src/browser/wrapper-widgets/memory-layout-widget.tsx +167 -167
  39. package/src/common/util.ts +28 -28
  40. package/src/common/utils.spec.ts +52 -52
@@ -1,393 +1,393 @@
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 { Disposable, DisposableCollection, Emitter, nls } from '@theia/core';
18
- import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
19
- import * as React from '@theia/core/shared/react';
20
- import { DebugSession, DebugState } from '@theia/debug/lib/browser/debug-session';
21
- import { ASCII_TOGGLE_ID, AUTO_UPDATE_TOGGLE_ID, MemoryOptionsWidget } from '../memory-widget/memory-options-widget';
22
- import { MWInputWithSelect } from '../utils/memory-widget-components';
23
- import { Constants, Interfaces, RegisterWidgetOptions } from '../utils/memory-widget-utils';
24
- import { getRegisters, RegisterReadResult } from '../utils/memory-widget-variable-utils';
25
- import { MWMultiSelect } from '../utils/multi-select-bar';
26
- import { RegisterFilterService } from './register-filter-service';
27
- import debounce = require('@theia/core/shared/lodash.debounce');
28
-
29
- export const EMPTY_REGISTERS: RegisterReadResult = {
30
- threadId: undefined,
31
- registers: [],
32
- };
33
-
34
- export const REGISTER_FIELD_ID = 't-mv-register';
35
- export const REGISTER_RADIX_ID = 't-mv-radix';
36
- export const REGISTER_PRE_SETS_ID = 't-mv-pre-set';
37
-
38
- export interface RegisterOptions extends Interfaces.MemoryOptions {
39
- reg: string;
40
- noRadixColumnDisplayed: boolean;
41
- }
42
-
43
- @injectable()
44
- export class RegisterOptionsWidget extends MemoryOptionsWidget {
45
- override iconClass = 'register-view-icon';
46
- override lockIconClass = 'register-lock-icon';
47
-
48
- protected readonly LABEL_PREFIX = nls.localize('theia/memory-inspector/register', 'Register');
49
-
50
- protected readonly onRegisterChangedEmitter = new Emitter<[RegisterReadResult, boolean]>();
51
- readonly onRegisterChanged = this.onRegisterChangedEmitter.event;
52
-
53
- protected registerReadResult: RegisterReadResult = EMPTY_REGISTERS;
54
-
55
- protected reg: string;
56
- protected registerField: HTMLInputElement | undefined;
57
- protected registerDisplaySet = new Set();
58
- protected registerDisplayAll = true;
59
- protected registerFilterUpdate = false;
60
- protected registerReadError = nls.localize('theia/memory-inspector/register/readError', 'No Registers currently available.');
61
- protected showRegisterError = false;
62
- protected noRadixColumnDisplayed = this.noRadixDisplayed();
63
- protected override columnsDisplayed: Interfaces.ColumnsDisplayed = {
64
- register: {
65
- label: nls.localize('theia/memory-inspector/register', 'Register'),
66
- doRender: true
67
- },
68
- hexadecimal: {
69
- label: nls.localize('theia/memory-inspector/hexadecimal', 'Hexadecimal'),
70
- doRender: true
71
- },
72
- decimal: {
73
- label: nls.localize('theia/memory-inspector/decimal', 'Decimal'),
74
- doRender: false
75
- },
76
- octal: {
77
- label: nls.localize('theia/memory-inspector/octal', 'Octal'),
78
- doRender: false
79
- },
80
- binary: {
81
- label: nls.localize('theia/memory-inspector/binary', 'Binary'),
82
- doRender: false
83
- },
84
- };
85
-
86
- @inject(RegisterWidgetOptions) protected override readonly memoryWidgetOptions: RegisterWidgetOptions;
87
- @inject(RegisterFilterService) protected readonly filterService: RegisterFilterService;
88
-
89
- get registers(): RegisterReadResult {
90
- return {
91
- ...this.registerReadResult,
92
- };
93
- }
94
-
95
- override get options(): RegisterOptions {
96
- return this.storeState();
97
- }
98
-
99
- displayReg(element: string): boolean {
100
- return this.registerDisplayAll ||
101
- this.registerDisplaySet.has(element);
102
- }
103
-
104
- handleRadixRendering(regVal: string, radix: number, _regName?: string): string {
105
- // check if too big for integer
106
- const bInt = BigInt(regVal);
107
- return bInt.toString(radix);
108
- }
109
-
110
- @postConstruct()
111
- protected override init(): void {
112
- this.addClass(MemoryOptionsWidget.ID);
113
- this.addClass('reg-options-widget');
114
-
115
- this.title.label = `${this.LABEL_PREFIX} (${this.memoryWidgetOptions.identifier})`;
116
- this.title.caption = `${this.LABEL_PREFIX} (${this.memoryWidgetOptions.identifier})`;
117
- this.title.iconClass = this.iconClass;
118
- this.title.closable = true;
119
-
120
- if (this.memoryWidgetOptions.dynamic !== false) {
121
- this.toDispose.push(this.sessionManager.onDidChangeActiveDebugSession(({ current }) => {
122
- this.setUpListeners(current);
123
- }));
124
-
125
- this.toDispose.push(this.sessionManager.onDidCreateDebugSession(current => {
126
- this.setUpListeners(current);
127
- }));
128
- this.setUpListeners(this.sessionManager.currentSession);
129
- }
130
- this.toDispose.push(this.onOptionsChanged(() => this.update()));
131
-
132
- this.update();
133
- }
134
-
135
- setRegAndUpdate(regName: string): void {
136
- this.handleRegFromDebugWidgetSelection(regName);
137
- }
138
-
139
- protected override setUpListeners(session?: DebugSession): void {
140
- this.sessionListeners.dispose();
141
- this.sessionListeners = new DisposableCollection(Disposable.create(() => this.handleActiveSessionChange()));
142
- if (session) {
143
- this.sessionListeners.push(session.onDidChange(() => this.handleSessionChange()));
144
- }
145
- }
146
-
147
- protected override handleActiveSessionChange(): void {
148
- const isDynamic = this.memoryWidgetOptions.dynamic !== false;
149
- if (isDynamic && this.doUpdateAutomatically) {
150
- this.registerReadResult = EMPTY_REGISTERS;
151
- this.fireDidChangeRegister();
152
- }
153
- }
154
-
155
- protected override handleSessionChange(): void {
156
- const debugState = this.sessionManager.currentSession?.state;
157
- if (debugState === DebugState.Inactive) {
158
- this.registerReadResult = EMPTY_REGISTERS;
159
- this.fireDidChangeRegister();
160
- } else if (debugState === DebugState.Stopped) {
161
- const isReadyForQuery = !!this.sessionManager.currentSession?.currentFrame;
162
- const isDynamic = this.memoryWidgetOptions.dynamic !== false;
163
- if (isReadyForQuery && isDynamic && this.doUpdateAutomatically && this.registerReadResult !== EMPTY_REGISTERS) {
164
- this.updateRegisterView();
165
- }
166
- }
167
- }
168
-
169
- protected override acceptFocus(): void {
170
- if (this.doUpdateAutomatically) {
171
- if (this.registerField) {
172
- this.registerField.focus();
173
- this.registerField.select();
174
- }
175
- } else {
176
- const multiSelectBar = this.node.querySelector('.multi-select-bar') as HTMLDivElement;
177
- multiSelectBar?.focus();
178
- }
179
- }
180
-
181
- protected assignRegisterRef: React.LegacyRef<HTMLInputElement> = reg => {
182
- this.registerField = reg ?? undefined;
183
- };
184
-
185
- protected setRegFilterFromSelect = (e: React.ChangeEvent<HTMLSelectElement>): void => {
186
- if (this.registerField) {
187
- this.registerField.value = e.target.value;
188
- }
189
- };
190
-
191
- protected radixDisplayed(): boolean {
192
- const { register, ...radices } = this.columnsDisplayed;
193
- for (const val of Object.values(radices)) {
194
- if (val['doRender']) {
195
- return true;
196
- }
197
- }
198
- return false;
199
- }
200
-
201
- protected noRadixDisplayed(): boolean {
202
- return !this.radixDisplayed();
203
- }
204
-
205
- protected renderRegisterFieldGroup(): React.ReactNode {
206
- return (
207
- <>
208
- <div className='t-mv-group view-group'>
209
- <MWInputWithSelect
210
- id={REGISTER_FIELD_ID}
211
- label={nls.localize('theia/memory-inspector/registers', 'Registers')}
212
- placeholder={nls.localize('theia/memory-inspector/register-widget/filter-placeholder', 'Filter (starts with)')}
213
- onSelectChange={this.setRegFilterFromSelect}
214
- passRef={this.assignRegisterRef}
215
- onKeyDown={this.doRefresh}
216
- options={[...this.recentLocations.values]}
217
- disabled={!this.doUpdateAutomatically}
218
- />
219
- <MWMultiSelect
220
- id={ASCII_TOGGLE_ID}
221
- label={nls.localize('theia/memory-inspector/columns', 'Columns')}
222
- items={this.getOptionalColumns().map(column => ({ ...column, label: column.label.slice(0, 3) }))}
223
- onSelectionChanged={this.handleColumnSelectionChange}
224
- />
225
- <button
226
- type='button'
227
- className='theia-button main view-group-go-button'
228
- onClick={this.doRefresh}
229
- disabled={!this.doUpdateAutomatically}
230
- >
231
- {nls.localizeByDefault('Go')}
232
- </button>
233
- </div>
234
- <div className={`t-mv-memory-fetch-error${this.showRegisterError ? ' show' : ' hide'}`}>
235
- {this.registerReadError}
236
- </div>
237
- </>
238
- );
239
- }
240
-
241
- protected override doHandleColumnSelectionChange(columnLabel: string, doShow: boolean): void {
242
- const trueColumnLabel = Object.keys(this.columnsDisplayed).find(key => key.startsWith(columnLabel));
243
- if (trueColumnLabel) {
244
- super.doHandleColumnSelectionChange(trueColumnLabel, doShow);
245
- }
246
- }
247
-
248
- protected override getObligatoryColumnIds(): string[] {
249
- return ['register'];
250
- }
251
-
252
- protected override renderInputContainer(): React.ReactNode {
253
- return (
254
- <div className='t-mv-settings-container'>
255
- <div className='t-mv-wrapper'>
256
- {this.renderToolbar()}
257
- {this.renderRegisterFieldGroup()}
258
- </div>
259
- </div>);
260
- }
261
-
262
- protected handleRegFromDebugWidgetSelection(regName: string): void {
263
- this.registerDisplaySet.clear();
264
- if (this.registerField) {
265
- this.registerField.value = regName;
266
- this.registerDisplayAll = false;
267
- }
268
- this.doUpdateRegisterView();
269
- }
270
-
271
- protected override renderToolbar(): React.ReactNode {
272
- return (
273
- <div className='memory-widget-toolbar'>
274
- {this.memoryWidgetOptions.dynamic !== false && (
275
- <div className='memory-widget-auto-updates-container'>
276
- <div
277
- className={`fa fa-${this.doUpdateAutomatically ? 'unlock' : 'lock'}`}
278
- id={AUTO_UPDATE_TOGGLE_ID}
279
- title={this.doUpdateAutomatically ?
280
- nls.localize('theia/memory-inspector/register/freeze', 'Freeze memory view') :
281
- nls.localize('theia/memory-inspector/register/unfreeze', 'Unfreeze memory view')
282
- }
283
- onClick={this.toggleAutoUpdate}
284
- onKeyDown={this.toggleAutoUpdate}
285
- role='button'
286
- tabIndex={0}
287
- />
288
- </div>
289
- )}
290
- {this.renderEditableTitleField()}
291
- </div>
292
- );
293
- }
294
-
295
- protected validateInputRegs(input: string): void {
296
- // identify sequences of alphanumeric characters
297
- const searchTexts = input.match(/\w+/g) ?? [];
298
-
299
- if (searchTexts.length !== 0) {
300
- this.registerDisplayAll = false;
301
- this.registerDisplaySet.clear();
302
- this.recentLocations.add(input);
303
- for (const { name } of this.registerReadResult.registers) {
304
- if (searchTexts.some(x => name.startsWith(x))) {
305
- this.registerDisplaySet.add(name);
306
- }
307
- }
308
- } else {
309
- this.registerDisplayAll = true;
310
- this.registerDisplaySet.clear();
311
- }
312
- }
313
-
314
- protected updateRegisterView = debounce(this.doUpdateRegisterView.bind(this), Constants.DEBOUNCE_TIME, { trailing: true });
315
-
316
- protected async doUpdateRegisterView(): Promise<void> {
317
- try {
318
- if (!this.registerReadResult.registers || this.registerReadResult.threadId !== this.sessionManager.currentThread?.id) {
319
- this.registerReadResult = await this.getRegisters();
320
- }
321
- this.updateRegDisplayFilter();
322
- this.fireDidChangeRegister();
323
- this.doShowRegisterErrors(true);
324
- } catch (err) {
325
- this.registerReadError = nls.localize('theia/memory-inspector/registerReadError', 'There was an error fetching registers.');
326
- console.error('Failed to read registers', err);
327
- this.doShowRegisterErrors();
328
- } finally {
329
- this.registerFilterUpdate = false;
330
- this.update();
331
- }
332
- }
333
-
334
- protected updateRegDisplayFilter(): void {
335
- if (this.registerField) {
336
- if (this.registerField.value.length === 0) {
337
- this.registerDisplayAll = true;
338
- } else {
339
- this.validateInputRegs(this.registerField.value);
340
- }
341
- }
342
- }
343
-
344
- protected override doRefresh = (event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
345
- if ('key' in event && event.key !== 'Enter') {
346
- return;
347
- }
348
- this.registerFilterUpdate = true;
349
- this.updateRegisterView();
350
- };
351
-
352
- protected async getRegisters(): Promise<RegisterReadResult> {
353
- const regResult = await getRegisters(this.sessionManager.currentSession);
354
- const threadResult = this.sessionManager.currentSession?.currentThread?.id;
355
- return { threadId: threadResult, registers: regResult };
356
- }
357
-
358
- protected fireDidChangeRegister(): void {
359
- this.onRegisterChangedEmitter.fire([this.registerReadResult, this.registerFilterUpdate]);
360
- }
361
-
362
- override storeState(): RegisterOptions {
363
- return {
364
- ...super.storeState(),
365
- reg: this.registerField?.value ?? this.reg,
366
- noRadixColumnDisplayed: this.noRadixDisplayed(),
367
- };
368
- }
369
-
370
- override restoreState(oldState: RegisterOptions): void {
371
- this.reg = oldState.reg ?? this.reg;
372
- this.noRadixColumnDisplayed = oldState.noRadixColumnDisplayed;
373
- }
374
-
375
- protected doShowRegisterErrors = (doClearError = false): void => {
376
- if (this.errorTimeout !== undefined) {
377
- clearTimeout(this.errorTimeout);
378
- }
379
- if (doClearError) {
380
- this.showRegisterError = false;
381
- this.update();
382
- this.errorTimeout = undefined;
383
- return;
384
- }
385
- this.showRegisterError = true;
386
- this.update();
387
- this.errorTimeout = setTimeout(() => {
388
- this.showRegisterError = false;
389
- this.update();
390
- this.errorTimeout = undefined;
391
- }, Constants.ERROR_TIMEOUT);
392
- };
393
- }
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 { Disposable, DisposableCollection, Emitter, nls } from '@theia/core';
18
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
19
+ import * as React from '@theia/core/shared/react';
20
+ import { DebugSession, DebugState } from '@theia/debug/lib/browser/debug-session';
21
+ import { ASCII_TOGGLE_ID, AUTO_UPDATE_TOGGLE_ID, MemoryOptionsWidget } from '../memory-widget/memory-options-widget';
22
+ import { MWInputWithSelect } from '../utils/memory-widget-components';
23
+ import { Constants, Interfaces, RegisterWidgetOptions } from '../utils/memory-widget-utils';
24
+ import { getRegisters, RegisterReadResult } from '../utils/memory-widget-variable-utils';
25
+ import { MWMultiSelect } from '../utils/multi-select-bar';
26
+ import { RegisterFilterService } from './register-filter-service';
27
+ import debounce = require('@theia/core/shared/lodash.debounce');
28
+
29
+ export const EMPTY_REGISTERS: RegisterReadResult = {
30
+ threadId: undefined,
31
+ registers: [],
32
+ };
33
+
34
+ export const REGISTER_FIELD_ID = 't-mv-register';
35
+ export const REGISTER_RADIX_ID = 't-mv-radix';
36
+ export const REGISTER_PRE_SETS_ID = 't-mv-pre-set';
37
+
38
+ export interface RegisterOptions extends Interfaces.MemoryOptions {
39
+ reg: string;
40
+ noRadixColumnDisplayed: boolean;
41
+ }
42
+
43
+ @injectable()
44
+ export class RegisterOptionsWidget extends MemoryOptionsWidget {
45
+ override iconClass = 'register-view-icon';
46
+ override lockIconClass = 'register-lock-icon';
47
+
48
+ protected readonly LABEL_PREFIX = nls.localize('theia/memory-inspector/register', 'Register');
49
+
50
+ protected readonly onRegisterChangedEmitter = new Emitter<[RegisterReadResult, boolean]>();
51
+ readonly onRegisterChanged = this.onRegisterChangedEmitter.event;
52
+
53
+ protected registerReadResult: RegisterReadResult = EMPTY_REGISTERS;
54
+
55
+ protected reg: string;
56
+ protected registerField: HTMLInputElement | undefined;
57
+ protected registerDisplaySet = new Set();
58
+ protected registerDisplayAll = true;
59
+ protected registerFilterUpdate = false;
60
+ protected registerReadError = nls.localize('theia/memory-inspector/register/readError', 'No Registers currently available.');
61
+ protected showRegisterError = false;
62
+ protected noRadixColumnDisplayed = this.noRadixDisplayed();
63
+ protected override columnsDisplayed: Interfaces.ColumnsDisplayed = {
64
+ register: {
65
+ label: nls.localize('theia/memory-inspector/register', 'Register'),
66
+ doRender: true
67
+ },
68
+ hexadecimal: {
69
+ label: nls.localize('theia/memory-inspector/hexadecimal', 'Hexadecimal'),
70
+ doRender: true
71
+ },
72
+ decimal: {
73
+ label: nls.localize('theia/memory-inspector/decimal', 'Decimal'),
74
+ doRender: false
75
+ },
76
+ octal: {
77
+ label: nls.localize('theia/memory-inspector/octal', 'Octal'),
78
+ doRender: false
79
+ },
80
+ binary: {
81
+ label: nls.localize('theia/memory-inspector/binary', 'Binary'),
82
+ doRender: false
83
+ },
84
+ };
85
+
86
+ @inject(RegisterWidgetOptions) protected override readonly memoryWidgetOptions: RegisterWidgetOptions;
87
+ @inject(RegisterFilterService) protected readonly filterService: RegisterFilterService;
88
+
89
+ get registers(): RegisterReadResult {
90
+ return {
91
+ ...this.registerReadResult,
92
+ };
93
+ }
94
+
95
+ override get options(): RegisterOptions {
96
+ return this.storeState();
97
+ }
98
+
99
+ displayReg(element: string): boolean {
100
+ return this.registerDisplayAll ||
101
+ this.registerDisplaySet.has(element);
102
+ }
103
+
104
+ handleRadixRendering(regVal: string, radix: number, _regName?: string): string {
105
+ // check if too big for integer
106
+ const bInt = BigInt(regVal);
107
+ return bInt.toString(radix);
108
+ }
109
+
110
+ @postConstruct()
111
+ protected override init(): void {
112
+ this.addClass(MemoryOptionsWidget.ID);
113
+ this.addClass('reg-options-widget');
114
+
115
+ this.title.label = `${this.LABEL_PREFIX} (${this.memoryWidgetOptions.identifier})`;
116
+ this.title.caption = `${this.LABEL_PREFIX} (${this.memoryWidgetOptions.identifier})`;
117
+ this.title.iconClass = this.iconClass;
118
+ this.title.closable = true;
119
+
120
+ if (this.memoryWidgetOptions.dynamic !== false) {
121
+ this.toDispose.push(this.sessionManager.onDidChangeActiveDebugSession(({ current }) => {
122
+ this.setUpListeners(current);
123
+ }));
124
+
125
+ this.toDispose.push(this.sessionManager.onDidCreateDebugSession(current => {
126
+ this.setUpListeners(current);
127
+ }));
128
+ this.setUpListeners(this.sessionManager.currentSession);
129
+ }
130
+ this.toDispose.push(this.onOptionsChanged(() => this.update()));
131
+
132
+ this.update();
133
+ }
134
+
135
+ setRegAndUpdate(regName: string): void {
136
+ this.handleRegFromDebugWidgetSelection(regName);
137
+ }
138
+
139
+ protected override setUpListeners(session?: DebugSession): void {
140
+ this.sessionListeners.dispose();
141
+ this.sessionListeners = new DisposableCollection(Disposable.create(() => this.handleActiveSessionChange()));
142
+ if (session) {
143
+ this.sessionListeners.push(session.onDidChange(() => this.handleSessionChange()));
144
+ }
145
+ }
146
+
147
+ protected override handleActiveSessionChange(): void {
148
+ const isDynamic = this.memoryWidgetOptions.dynamic !== false;
149
+ if (isDynamic && this.doUpdateAutomatically) {
150
+ this.registerReadResult = EMPTY_REGISTERS;
151
+ this.fireDidChangeRegister();
152
+ }
153
+ }
154
+
155
+ protected override handleSessionChange(): void {
156
+ const debugState = this.sessionManager.currentSession?.state;
157
+ if (debugState === DebugState.Inactive) {
158
+ this.registerReadResult = EMPTY_REGISTERS;
159
+ this.fireDidChangeRegister();
160
+ } else if (debugState === DebugState.Stopped) {
161
+ const isReadyForQuery = !!this.sessionManager.currentSession?.currentFrame;
162
+ const isDynamic = this.memoryWidgetOptions.dynamic !== false;
163
+ if (isReadyForQuery && isDynamic && this.doUpdateAutomatically && this.registerReadResult !== EMPTY_REGISTERS) {
164
+ this.updateRegisterView();
165
+ }
166
+ }
167
+ }
168
+
169
+ protected override acceptFocus(): void {
170
+ if (this.doUpdateAutomatically) {
171
+ if (this.registerField) {
172
+ this.registerField.focus();
173
+ this.registerField.select();
174
+ }
175
+ } else {
176
+ const multiSelectBar = this.node.querySelector('.multi-select-bar') as HTMLDivElement;
177
+ multiSelectBar?.focus();
178
+ }
179
+ }
180
+
181
+ protected assignRegisterRef: React.LegacyRef<HTMLInputElement> = reg => {
182
+ this.registerField = reg ?? undefined;
183
+ };
184
+
185
+ protected setRegFilterFromSelect = (e: React.ChangeEvent<HTMLSelectElement>): void => {
186
+ if (this.registerField) {
187
+ this.registerField.value = e.target.value;
188
+ }
189
+ };
190
+
191
+ protected radixDisplayed(): boolean {
192
+ const { register, ...radices } = this.columnsDisplayed;
193
+ for (const val of Object.values(radices)) {
194
+ if (val['doRender']) {
195
+ return true;
196
+ }
197
+ }
198
+ return false;
199
+ }
200
+
201
+ protected noRadixDisplayed(): boolean {
202
+ return !this.radixDisplayed();
203
+ }
204
+
205
+ protected renderRegisterFieldGroup(): React.ReactNode {
206
+ return (
207
+ <>
208
+ <div className='t-mv-group view-group'>
209
+ <MWInputWithSelect
210
+ id={REGISTER_FIELD_ID}
211
+ label={nls.localize('theia/memory-inspector/registers', 'Registers')}
212
+ placeholder={nls.localize('theia/memory-inspector/register-widget/filter-placeholder', 'Filter (starts with)')}
213
+ onSelectChange={this.setRegFilterFromSelect}
214
+ passRef={this.assignRegisterRef}
215
+ onKeyDown={this.doRefresh}
216
+ options={[...this.recentLocations.values]}
217
+ disabled={!this.doUpdateAutomatically}
218
+ />
219
+ <MWMultiSelect
220
+ id={ASCII_TOGGLE_ID}
221
+ label={nls.localize('theia/memory-inspector/columns', 'Columns')}
222
+ items={this.getOptionalColumns().map(column => ({ ...column, label: column.label.slice(0, 3) }))}
223
+ onSelectionChanged={this.handleColumnSelectionChange}
224
+ />
225
+ <button
226
+ type='button'
227
+ className='theia-button main view-group-go-button'
228
+ onClick={this.doRefresh}
229
+ disabled={!this.doUpdateAutomatically}
230
+ >
231
+ {nls.localizeByDefault('Go')}
232
+ </button>
233
+ </div>
234
+ <div className={`t-mv-memory-fetch-error${this.showRegisterError ? ' show' : ' hide'}`}>
235
+ {this.registerReadError}
236
+ </div>
237
+ </>
238
+ );
239
+ }
240
+
241
+ protected override doHandleColumnSelectionChange(columnLabel: string, doShow: boolean): void {
242
+ const trueColumnLabel = Object.keys(this.columnsDisplayed).find(key => key.startsWith(columnLabel));
243
+ if (trueColumnLabel) {
244
+ super.doHandleColumnSelectionChange(trueColumnLabel, doShow);
245
+ }
246
+ }
247
+
248
+ protected override getObligatoryColumnIds(): string[] {
249
+ return ['register'];
250
+ }
251
+
252
+ protected override renderInputContainer(): React.ReactNode {
253
+ return (
254
+ <div className='t-mv-settings-container'>
255
+ <div className='t-mv-wrapper'>
256
+ {this.renderToolbar()}
257
+ {this.renderRegisterFieldGroup()}
258
+ </div>
259
+ </div>);
260
+ }
261
+
262
+ protected handleRegFromDebugWidgetSelection(regName: string): void {
263
+ this.registerDisplaySet.clear();
264
+ if (this.registerField) {
265
+ this.registerField.value = regName;
266
+ this.registerDisplayAll = false;
267
+ }
268
+ this.doUpdateRegisterView();
269
+ }
270
+
271
+ protected override renderToolbar(): React.ReactNode {
272
+ return (
273
+ <div className='memory-widget-toolbar'>
274
+ {this.memoryWidgetOptions.dynamic !== false && (
275
+ <div className='memory-widget-auto-updates-container'>
276
+ <div
277
+ className={`fa fa-${this.doUpdateAutomatically ? 'unlock' : 'lock'}`}
278
+ id={AUTO_UPDATE_TOGGLE_ID}
279
+ title={this.doUpdateAutomatically ?
280
+ nls.localize('theia/memory-inspector/register/freeze', 'Freeze memory view') :
281
+ nls.localize('theia/memory-inspector/register/unfreeze', 'Unfreeze memory view')
282
+ }
283
+ onClick={this.toggleAutoUpdate}
284
+ onKeyDown={this.toggleAutoUpdate}
285
+ role='button'
286
+ tabIndex={0}
287
+ />
288
+ </div>
289
+ )}
290
+ {this.renderEditableTitleField()}
291
+ </div>
292
+ );
293
+ }
294
+
295
+ protected validateInputRegs(input: string): void {
296
+ // identify sequences of alphanumeric characters
297
+ const searchTexts = input.match(/\w+/g) ?? [];
298
+
299
+ if (searchTexts.length !== 0) {
300
+ this.registerDisplayAll = false;
301
+ this.registerDisplaySet.clear();
302
+ this.recentLocations.add(input);
303
+ for (const { name } of this.registerReadResult.registers) {
304
+ if (searchTexts.some(x => name.startsWith(x))) {
305
+ this.registerDisplaySet.add(name);
306
+ }
307
+ }
308
+ } else {
309
+ this.registerDisplayAll = true;
310
+ this.registerDisplaySet.clear();
311
+ }
312
+ }
313
+
314
+ protected updateRegisterView = debounce(this.doUpdateRegisterView.bind(this), Constants.DEBOUNCE_TIME, { trailing: true });
315
+
316
+ protected async doUpdateRegisterView(): Promise<void> {
317
+ try {
318
+ if (!this.registerReadResult.registers || this.registerReadResult.threadId !== this.sessionManager.currentThread?.id) {
319
+ this.registerReadResult = await this.getRegisters();
320
+ }
321
+ this.updateRegDisplayFilter();
322
+ this.fireDidChangeRegister();
323
+ this.doShowRegisterErrors(true);
324
+ } catch (err) {
325
+ this.registerReadError = nls.localize('theia/memory-inspector/registerReadError', 'There was an error fetching registers.');
326
+ console.error('Failed to read registers', err);
327
+ this.doShowRegisterErrors();
328
+ } finally {
329
+ this.registerFilterUpdate = false;
330
+ this.update();
331
+ }
332
+ }
333
+
334
+ protected updateRegDisplayFilter(): void {
335
+ if (this.registerField) {
336
+ if (this.registerField.value.length === 0) {
337
+ this.registerDisplayAll = true;
338
+ } else {
339
+ this.validateInputRegs(this.registerField.value);
340
+ }
341
+ }
342
+ }
343
+
344
+ protected override doRefresh = (event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
345
+ if ('key' in event && event.key !== 'Enter') {
346
+ return;
347
+ }
348
+ this.registerFilterUpdate = true;
349
+ this.updateRegisterView();
350
+ };
351
+
352
+ protected async getRegisters(): Promise<RegisterReadResult> {
353
+ const regResult = await getRegisters(this.sessionManager.currentSession);
354
+ const threadResult = this.sessionManager.currentSession?.currentThread?.id;
355
+ return { threadId: threadResult, registers: regResult };
356
+ }
357
+
358
+ protected fireDidChangeRegister(): void {
359
+ this.onRegisterChangedEmitter.fire([this.registerReadResult, this.registerFilterUpdate]);
360
+ }
361
+
362
+ override storeState(): RegisterOptions {
363
+ return {
364
+ ...super.storeState(),
365
+ reg: this.registerField?.value ?? this.reg,
366
+ noRadixColumnDisplayed: this.noRadixDisplayed(),
367
+ };
368
+ }
369
+
370
+ override restoreState(oldState: RegisterOptions): void {
371
+ this.reg = oldState.reg ?? this.reg;
372
+ this.noRadixColumnDisplayed = oldState.noRadixColumnDisplayed;
373
+ }
374
+
375
+ protected doShowRegisterErrors = (doClearError = false): void => {
376
+ if (this.errorTimeout !== undefined) {
377
+ clearTimeout(this.errorTimeout);
378
+ }
379
+ if (doClearError) {
380
+ this.showRegisterError = false;
381
+ this.update();
382
+ this.errorTimeout = undefined;
383
+ return;
384
+ }
385
+ this.showRegisterError = true;
386
+ this.update();
387
+ this.errorTimeout = setTimeout(() => {
388
+ this.showRegisterError = false;
389
+ this.update();
390
+ this.errorTimeout = undefined;
391
+ }, Constants.ERROR_TIMEOUT);
392
+ };
393
+ }