@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.
- package/README.md +71 -71
- package/lib/browser/diff-widget/memory-diff-options-widget.d.ts +36 -36
- package/lib/browser/diff-widget/memory-diff-options-widget.js +132 -132
- package/lib/browser/diff-widget/memory-diff-select-widget.d.ts +50 -50
- package/lib/browser/diff-widget/memory-diff-select-widget.js +137 -137
- package/lib/browser/diff-widget/memory-diff-table-widget.d.ts +77 -77
- package/lib/browser/diff-widget/memory-diff-table-widget.js +314 -314
- package/lib/browser/diff-widget/memory-diff-widget-types.d.ts +41 -41
- package/lib/browser/diff-widget/memory-diff-widget-types.js +23 -23
- package/lib/browser/editable-widget/memory-editable-table-widget.d.ts +64 -64
- package/lib/browser/editable-widget/memory-editable-table-widget.js +324 -324
- package/lib/browser/memory-inspector-frontend-contribution.d.ts +46 -46
- package/lib/browser/memory-inspector-frontend-contribution.js +291 -291
- package/lib/browser/memory-inspector-frontend-module.d.ts +21 -21
- package/lib/browser/memory-inspector-frontend-module.js +87 -87
- package/lib/browser/memory-provider/cdt-gdb-memory-provider.d.ts +35 -35
- package/lib/browser/memory-provider/cdt-gdb-memory-provider.js +136 -136
- package/lib/browser/memory-provider/memory-provider-service.d.ts +36 -36
- package/lib/browser/memory-provider/memory-provider-service.js +101 -101
- package/lib/browser/memory-provider/memory-provider.d.ts +65 -65
- package/lib/browser/memory-provider/memory-provider.js +96 -96
- package/lib/browser/memory-provider/memory-provider.spec.d.ts +16 -16
- package/lib/browser/memory-provider/memory-provider.spec.js +23 -23
- package/lib/browser/memory-widget/memory-options-widget.d.ts +136 -136
- package/lib/browser/memory-widget/memory-options-widget.js +564 -564
- package/lib/browser/memory-widget/memory-table-widget.d.ts +146 -146
- package/lib/browser/memory-widget/memory-table-widget.js +487 -487
- package/lib/browser/memory-widget/memory-widget.d.ts +33 -33
- package/lib/browser/memory-widget/memory-widget.js +112 -112
- package/lib/browser/register-widget/register-filter-service.d.ts +42 -42
- package/lib/browser/register-widget/register-filter-service.js +81 -81
- package/lib/browser/register-widget/register-options-widget.d.ts +81 -81
- package/lib/browser/register-widget/register-options-widget.js +338 -338
- package/lib/browser/register-widget/register-table-widget.d.ts +77 -77
- package/lib/browser/register-widget/register-table-widget.js +230 -230
- package/lib/browser/register-widget/register-widget-types.d.ts +29 -29
- package/lib/browser/register-widget/register-widget-types.js +35 -35
- package/lib/browser/utils/memory-commands.d.ts +27 -27
- package/lib/browser/utils/memory-commands.js +67 -67
- package/lib/browser/utils/memory-hover-renderer.d.ts +33 -33
- package/lib/browser/utils/memory-hover-renderer.js +111 -111
- package/lib/browser/utils/memory-recents.d.ts +27 -27
- package/lib/browser/utils/memory-recents.js +52 -52
- package/lib/browser/utils/memory-widget-components.d.ts +58 -58
- package/lib/browser/utils/memory-widget-components.js +69 -69
- package/lib/browser/utils/memory-widget-manager.d.ts +50 -50
- package/lib/browser/utils/memory-widget-manager.js +182 -182
- package/lib/browser/utils/memory-widget-utils.d.ts +113 -113
- package/lib/browser/utils/memory-widget-utils.js +42 -42
- package/lib/browser/utils/memory-widget-variable-utils.d.ts +57 -57
- package/lib/browser/utils/memory-widget-variable-utils.js +143 -143
- package/lib/browser/utils/multi-select-bar.d.ts +31 -31
- package/lib/browser/utils/multi-select-bar.js +34 -34
- package/lib/browser/wrapper-widgets/memory-dock-panel.d.ts +24 -24
- package/lib/browser/wrapper-widgets/memory-dock-panel.js +48 -48
- package/lib/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.d.ts +23 -23
- package/lib/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.js +57 -57
- package/lib/browser/wrapper-widgets/memory-layout-widget.d.ts +51 -51
- package/lib/browser/wrapper-widgets/memory-layout-widget.js +191 -191
- package/lib/common/util.d.ts +21 -21
- package/lib/common/util.js +30 -30
- package/lib/common/utils.spec.d.ts +16 -16
- package/lib/common/utils.spec.js +45 -45
- package/package.json +4 -4
- package/src/browser/diff-widget/memory-diff-options-widget.tsx +152 -152
- package/src/browser/diff-widget/memory-diff-select-widget.tsx +163 -163
- package/src/browser/diff-widget/memory-diff-table-widget.tsx +366 -366
- package/src/browser/diff-widget/memory-diff-widget-types.ts +45 -45
- package/src/browser/editable-widget/memory-editable-table-widget.tsx +359 -359
- package/src/browser/memory-inspector-frontend-contribution.ts +301 -301
- package/src/browser/memory-inspector-frontend-module.ts +118 -118
- package/src/browser/memory-provider/cdt-gdb-memory-provider.ts +132 -132
- package/src/browser/memory-provider/memory-provider-service.ts +86 -86
- package/src/browser/memory-provider/memory-provider.spec.ts +23 -23
- package/src/browser/memory-provider/memory-provider.ts +119 -119
- package/src/browser/memory-widget/memory-options-widget.tsx +738 -738
- package/src/browser/memory-widget/memory-table-widget.tsx +625 -625
- package/src/browser/memory-widget/memory-widget.ts +114 -114
- package/src/browser/register-widget/register-filter-service.ts +76 -76
- package/src/browser/register-widget/register-options-widget.tsx +393 -393
- package/src/browser/register-widget/register-table-widget.tsx +276 -276
- package/src/browser/register-widget/register-widget-types.ts +45 -45
- package/src/browser/register-widget/register-widget.css +34 -34
- package/src/browser/style/index.css +746 -746
- package/src/browser/style/memory-lock.svg +21 -21
- package/src/browser/style/memory-view.svg +20 -20
- package/src/browser/style/register-lock.svg +29 -29
- package/src/browser/style/register-view.svg +28 -28
- package/src/browser/utils/memory-commands.ts +76 -76
- package/src/browser/utils/memory-hover-renderer.ts +113 -113
- package/src/browser/utils/memory-recents.ts +58 -58
- package/src/browser/utils/memory-widget-components.tsx +193 -193
- package/src/browser/utils/memory-widget-manager.ts +179 -179
- package/src/browser/utils/memory-widget-utils.tsx +132 -132
- package/src/browser/utils/memory-widget-variable-utils.ts +170 -170
- package/src/browser/utils/multi-select-bar.css +61 -61
- package/src/browser/utils/multi-select-bar.tsx +75 -75
- package/src/browser/wrapper-widgets/memory-dock-panel.ts +51 -51
- package/src/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.tsx +38 -38
- package/src/browser/wrapper-widgets/memory-layout-widget.tsx +167 -167
- package/src/common/util.ts +28 -28
- package/src/common/utils.spec.ts +52 -52
|
@@ -1,625 +1,625 @@
|
|
|
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 { ContextMenuRenderer, ReactWidget, Widget } from '@theia/core/lib/browser';
|
|
18
|
-
import { ThemeService } from '@theia/core/lib/browser/theming';
|
|
19
|
-
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
20
|
-
import { ThemeChangeEvent } from '@theia/core/lib/common/theme';
|
|
21
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
22
|
-
import * as React from '@theia/core/shared/react';
|
|
23
|
-
import { hexStrToUnsignedLong } from '../../common/util';
|
|
24
|
-
import { MemoryProviderService } from '../memory-provider/memory-provider-service';
|
|
25
|
-
import { EasilyMappedObject, MemoryHoverRendererService } from '../utils/memory-hover-renderer';
|
|
26
|
-
import { MWMoreMemorySelect } from '../utils/memory-widget-components';
|
|
27
|
-
import {
|
|
28
|
-
Constants, Interfaces, Utils
|
|
29
|
-
} from '../utils/memory-widget-utils';
|
|
30
|
-
import { VariableDecoration, VariableFinder } from '../utils/memory-widget-variable-utils';
|
|
31
|
-
import { MemoryOptionsWidget } from './memory-options-widget';
|
|
32
|
-
import debounce = require('@theia/core/shared/lodash.debounce');
|
|
33
|
-
|
|
34
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
35
|
-
export namespace MemoryTable {
|
|
36
|
-
export interface WrapperHandlers {
|
|
37
|
-
onKeyDown?: React.KeyboardEventHandler;
|
|
38
|
-
onClick?: React.MouseEventHandler;
|
|
39
|
-
onContextMenu?: React.MouseEventHandler;
|
|
40
|
-
onMouseMove?: React.MouseEventHandler;
|
|
41
|
-
onFocus?(e: React.FocusEvent<HTMLDivElement>): any;
|
|
42
|
-
onBlur?(e: React.FocusEvent<HTMLDivElement>): any;
|
|
43
|
-
}
|
|
44
|
-
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
45
|
-
|
|
46
|
-
export interface StylableNodeAttributes {
|
|
47
|
-
className?: string;
|
|
48
|
-
style?: React.CSSProperties;
|
|
49
|
-
variable?: VariableDecoration;
|
|
50
|
-
title?: string;
|
|
51
|
-
isHighlighted?: boolean;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface GroupData {
|
|
55
|
-
node: React.ReactNode;
|
|
56
|
-
ascii: string; index: number;
|
|
57
|
-
variables: VariableDecoration[];
|
|
58
|
-
isHighlighted?: boolean;
|
|
59
|
-
}
|
|
60
|
-
export interface ByteData {
|
|
61
|
-
node: React.ReactNode;
|
|
62
|
-
ascii: string; index: number;
|
|
63
|
-
variables: VariableDecoration[];
|
|
64
|
-
isHighlighted?: boolean;
|
|
65
|
-
}
|
|
66
|
-
export interface ItemData {
|
|
67
|
-
node: React.ReactNode;
|
|
68
|
-
content: string;
|
|
69
|
-
variable?: VariableDecoration;
|
|
70
|
-
index: number;
|
|
71
|
-
isHighlighted?: boolean;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface RowOptions {
|
|
75
|
-
address: string;
|
|
76
|
-
groups: React.ReactNode;
|
|
77
|
-
ascii?: string;
|
|
78
|
-
variables?: VariableDecoration[];
|
|
79
|
-
doShowDivider?: boolean;
|
|
80
|
-
index: number;
|
|
81
|
-
isHighlighted?: boolean;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const ROW_CLASS = 't-mv-view-row';
|
|
85
|
-
export const ROW_DIVIDER_CLASS = 't-mv-view-row-highlight';
|
|
86
|
-
export const ADDRESS_DATA_CLASS = 't-mv-view-address';
|
|
87
|
-
export const MEMORY_DATA_CLASS = 't-mv-view-data';
|
|
88
|
-
export const EXTRA_COLUMN_DATA_CLASS = 't-mv-view-code';
|
|
89
|
-
export const GROUP_SPAN_CLASS = 'byte-group';
|
|
90
|
-
export const BYTE_SPAN_CLASS = 'single-byte';
|
|
91
|
-
export const EIGHT_BIT_SPAN_CLASS = 'eight-bits';
|
|
92
|
-
export const HEADER_LABEL_CONTAINER_CLASS = 't-mv-header-label-container';
|
|
93
|
-
export const HEADER_LABEL_CLASS = 't-mv-header-label';
|
|
94
|
-
export const VARIABLE_LABEL_CLASS = 't-mv-variable-label';
|
|
95
|
-
export const HEADER_ROW_CLASS = 't-mv-header';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
@injectable()
|
|
99
|
-
export class MemoryTableWidget extends ReactWidget {
|
|
100
|
-
static CONTEXT_MENU = ['memory.view.context.menu'];
|
|
101
|
-
static ID = 'memory-table-widget';
|
|
102
|
-
|
|
103
|
-
@inject(ThemeService) protected readonly themeService: ThemeService;
|
|
104
|
-
@inject(MemoryOptionsWidget) readonly optionsWidget: MemoryOptionsWidget;
|
|
105
|
-
@inject(MemoryProviderService) protected readonly memoryProvider: MemoryProviderService;
|
|
106
|
-
@inject(MemoryHoverRendererService) protected readonly hoverRenderer: MemoryHoverRendererService;
|
|
107
|
-
@inject(ContextMenuRenderer) protected readonly contextMenuRenderer: ContextMenuRenderer;
|
|
108
|
-
|
|
109
|
-
protected previousBytes: Interfaces.LabeledUint8Array | undefined;
|
|
110
|
-
protected memory: Interfaces.WidgetMemoryState;
|
|
111
|
-
protected options: Interfaces.MemoryOptions;
|
|
112
|
-
protected variableFinder: VariableFinder | undefined;
|
|
113
|
-
protected deferredScrollContainer = new Deferred<HTMLDivElement>();
|
|
114
|
-
|
|
115
|
-
@postConstruct()
|
|
116
|
-
protected init(): void {
|
|
117
|
-
this.doInit();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
protected async doInit(): Promise<void> {
|
|
121
|
-
this.id = MemoryTableWidget.ID;
|
|
122
|
-
this.addClass(MemoryTableWidget.ID);
|
|
123
|
-
this.scrollOptions = { ...this.scrollOptions, suppressScrollX: false };
|
|
124
|
-
this.toDispose.push(this.optionsWidget.onOptionsChanged(optionId => this.handleOptionChange(optionId)));
|
|
125
|
-
this.toDispose.push(this.optionsWidget.onMemoryChanged(e => this.handleMemoryChange(e)));
|
|
126
|
-
this.toDispose.push(this.themeService.onDidColorThemeChange(e => this.handleThemeChange(e)));
|
|
127
|
-
|
|
128
|
-
this.getStateAndUpdate();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
protected handleOptionChange(_id?: string): Promise<void> {
|
|
132
|
-
this.getStateAndUpdate();
|
|
133
|
-
return Promise.resolve();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
override update(): void {
|
|
137
|
-
super.update();
|
|
138
|
-
this.updateColumnWidths();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
protected override onResize(msg: Widget.ResizeMessage): void {
|
|
142
|
-
this.updateColumnWidths();
|
|
143
|
-
super.onResize(msg);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
protected updateColumnWidths = debounce(this.doUpdateColumnWidths.bind(this), Constants.DEBOUNCE_TIME);
|
|
147
|
-
|
|
148
|
-
protected doUpdateColumnWidths(): void {
|
|
149
|
-
setTimeout(() => {
|
|
150
|
-
const firstTR = this.node.querySelector('tr');
|
|
151
|
-
const header = this.node.querySelector(`.${MemoryTable.HEADER_ROW_CLASS}`) as HTMLDivElement;
|
|
152
|
-
if (firstTR && header) {
|
|
153
|
-
const allTDs = Array.from(firstTR.querySelectorAll('td'));
|
|
154
|
-
const allSizes = allTDs.map(td => `minmax(max-content, ${td.clientWidth}px)`);
|
|
155
|
-
header.style.gridTemplateColumns = allSizes.join(' ');
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
protected areSameRegion(a: Interfaces.MemoryReadResult, b: Interfaces.MemoryReadResult): boolean {
|
|
161
|
-
return a.address.equals(b?.address) && a.bytes.length === b?.bytes.length;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
protected handleMemoryChange(newMemory: Interfaces.MemoryReadResult): void {
|
|
165
|
-
if (this.areSameRegion(this.memory, newMemory)) {
|
|
166
|
-
this.previousBytes = this.memory.bytes;
|
|
167
|
-
} else {
|
|
168
|
-
this.previousBytes = undefined;
|
|
169
|
-
}
|
|
170
|
-
this.getStateAndUpdate();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
protected handleThemeChange(_themeChange: ThemeChangeEvent): void {
|
|
174
|
-
this.getStateAndUpdate();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
protected getState(): void {
|
|
178
|
-
this.options = this.optionsWidget.options;
|
|
179
|
-
this.memory = this.optionsWidget.memory;
|
|
180
|
-
const isHighContrast = this.themeService.getCurrentTheme().type === 'hc';
|
|
181
|
-
this.variableFinder = this.optionsWidget.options.columnsDisplayed.variables.doRender
|
|
182
|
-
? new VariableFinder(this.memory.variables, isHighContrast)
|
|
183
|
-
: undefined;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
protected getStateAndUpdate(): void {
|
|
187
|
-
this.getState();
|
|
188
|
-
this.update();
|
|
189
|
-
this.scrollIntoViewIfNecessary();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
protected scrollIntoViewIfNecessary(): Promise<void> {
|
|
193
|
-
return new Promise(resolve => setTimeout(() => {
|
|
194
|
-
this.deferredScrollContainer.promise.then(scrollContainer => {
|
|
195
|
-
const table = scrollContainer.querySelector('table');
|
|
196
|
-
if (table && scrollContainer.scrollTop > table.clientHeight) {
|
|
197
|
-
const valueToGetInWindow = table.clientHeight - this.node.clientHeight;
|
|
198
|
-
const scrollHere = Math.max(valueToGetInWindow, 0);
|
|
199
|
-
scrollContainer.scrollTo(scrollContainer.scrollLeft, scrollHere);
|
|
200
|
-
}
|
|
201
|
-
this.scrollBar?.update();
|
|
202
|
-
resolve();
|
|
203
|
-
});
|
|
204
|
-
}));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
protected getWrapperHandlers(): MemoryTable.WrapperHandlers {
|
|
208
|
-
return { onMouseMove: this.handleTableMouseMove };
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
protected assignScrollContainerRef = (element: HTMLDivElement): void => {
|
|
212
|
-
this.deferredScrollContainer.resolve(element);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
override async getScrollContainer(): Promise<HTMLDivElement> {
|
|
216
|
-
return this.deferredScrollContainer.promise;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
render(): React.ReactNode {
|
|
220
|
-
const rows = this.getTableRows();
|
|
221
|
-
const { onClick, onContextMenu, onFocus, onBlur, onKeyDown, onMouseMove } = this.getWrapperHandlers();
|
|
222
|
-
const headers: Interfaces.ColumnIDs[] = Object.entries(this.options.columnsDisplayed)
|
|
223
|
-
.filter(([, { doRender }]) => doRender)
|
|
224
|
-
.map(([id, { label }]) => ({ label, id }));
|
|
225
|
-
|
|
226
|
-
return (
|
|
227
|
-
<div
|
|
228
|
-
className={this.getWrapperClass()}
|
|
229
|
-
onClick={onClick}
|
|
230
|
-
onContextMenu={onContextMenu}
|
|
231
|
-
onFocus={onFocus}
|
|
232
|
-
onBlur={onBlur}
|
|
233
|
-
onKeyDown={onKeyDown}
|
|
234
|
-
onMouseMove={onMouseMove}
|
|
235
|
-
role='textbox'
|
|
236
|
-
tabIndex={0}
|
|
237
|
-
>
|
|
238
|
-
<div
|
|
239
|
-
className={this.getTableHeaderClass()}
|
|
240
|
-
style={this.getTableHeaderStyle(headers.length)}
|
|
241
|
-
>
|
|
242
|
-
{this.getTableHeaders(headers)}
|
|
243
|
-
</div>
|
|
244
|
-
<div
|
|
245
|
-
className='t-mv-view-container'
|
|
246
|
-
style={{ position: 'relative' }}
|
|
247
|
-
ref={this.assignScrollContainerRef}
|
|
248
|
-
>
|
|
249
|
-
{this.getBeforeTableContent()}
|
|
250
|
-
<table className='t-mv-view'>
|
|
251
|
-
<tbody>
|
|
252
|
-
{rows}
|
|
253
|
-
</tbody>
|
|
254
|
-
</table>
|
|
255
|
-
{this.getAfterTableContent()}
|
|
256
|
-
</div>
|
|
257
|
-
{this.getTableFooter()}
|
|
258
|
-
</div>
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
protected getWrapperClass(): string {
|
|
263
|
-
return `t-mv-memory-container${this.options.isFrozen ? ' frozen' : ''}`;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
protected getTableHeaderClass(): string {
|
|
267
|
-
return MemoryTable.HEADER_ROW_CLASS + ' no-select';
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
protected getTableHeaderStyle(numLabels: number): React.CSSProperties {
|
|
271
|
-
const safePercentage = Math.floor(100 / numLabels);
|
|
272
|
-
const gridTemplateColumns = ` ${safePercentage}% `.repeat(numLabels);
|
|
273
|
-
return { gridTemplateColumns };
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
protected getTableHeaders(labels: Interfaces.ColumnIDs[]): React.ReactNode {
|
|
277
|
-
return labels.map(label => this.getTableHeader(label));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
protected getTableHeader({ label, id }: Interfaces.ColumnIDs): React.ReactNode {
|
|
281
|
-
return (
|
|
282
|
-
<div key={id} className={MemoryTable.HEADER_LABEL_CONTAINER_CLASS}>
|
|
283
|
-
<span className='t-mv-header-label'>{label}</span>
|
|
284
|
-
</div>
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
protected getBeforeTableContent(): React.ReactNode {
|
|
289
|
-
return (
|
|
290
|
-
!!this.memory.bytes.length && (<MWMoreMemorySelect
|
|
291
|
-
options={[128, 256, 512]}
|
|
292
|
-
direction='above'
|
|
293
|
-
handler={this.loadMoreMemory}
|
|
294
|
-
/>)
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
protected getAfterTableContent(): React.ReactNode {
|
|
299
|
-
return (
|
|
300
|
-
!!this.memory.bytes.length && (<MWMoreMemorySelect
|
|
301
|
-
options={[128, 256, 512]}
|
|
302
|
-
direction='below'
|
|
303
|
-
handler={this.loadMoreMemory}
|
|
304
|
-
/>)
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
protected loadMoreMemory = async (options: Interfaces.MoreMemoryOptions): Promise<void> => {
|
|
309
|
-
const { direction, numBytes } = options;
|
|
310
|
-
const { address, offset, length } = this.optionsWidget.options;
|
|
311
|
-
let newOffset = 0;
|
|
312
|
-
const newLength = length + numBytes;
|
|
313
|
-
if (direction === 'above') {
|
|
314
|
-
newOffset = offset - numBytes;
|
|
315
|
-
}
|
|
316
|
-
await this.optionsWidget.setAddressAndGo(`${address}`, newOffset, newLength, direction);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
protected getTableFooter(): React.ReactNode {
|
|
320
|
-
return undefined;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
protected getTableRows(): React.ReactNode {
|
|
324
|
-
return [...this.renderRows()];
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
protected *renderRows(iteratee: Interfaces.LabeledUint8Array = this.memory.bytes): IterableIterator<React.ReactNode> {
|
|
328
|
-
const bytesPerRow = this.options.bytesPerGroup * this.options.groupsPerRow;
|
|
329
|
-
let rowsYielded = 0;
|
|
330
|
-
let groups: React.ReactNode[] = [];
|
|
331
|
-
let ascii = '';
|
|
332
|
-
let variables: VariableDecoration[] = [];
|
|
333
|
-
let isRowHighlighted = false;
|
|
334
|
-
for (const { node, index, ascii: groupAscii, variables: groupVariables, isHighlighted = false } of this.renderGroups(iteratee)) {
|
|
335
|
-
groups.push(node);
|
|
336
|
-
ascii += groupAscii;
|
|
337
|
-
variables.push(...groupVariables);
|
|
338
|
-
isRowHighlighted = isRowHighlighted || isHighlighted;
|
|
339
|
-
if (groups.length === this.options.groupsPerRow || index === iteratee.length - 1) {
|
|
340
|
-
const rowAddress = this.memory.address.add(bytesPerRow * rowsYielded);
|
|
341
|
-
const options: MemoryTable.RowOptions = {
|
|
342
|
-
address: `0x${rowAddress.toString(16)}`,
|
|
343
|
-
doShowDivider: (rowsYielded % 4) === 3,
|
|
344
|
-
isHighlighted: isRowHighlighted,
|
|
345
|
-
ascii,
|
|
346
|
-
groups,
|
|
347
|
-
variables,
|
|
348
|
-
index,
|
|
349
|
-
};
|
|
350
|
-
yield this.renderRow(options);
|
|
351
|
-
ascii = '';
|
|
352
|
-
variables = [];
|
|
353
|
-
groups = [];
|
|
354
|
-
rowsYielded += 1;
|
|
355
|
-
isRowHighlighted = false;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
protected renderRow(
|
|
361
|
-
options: MemoryTable.RowOptions,
|
|
362
|
-
getRowAttributes: Interfaces.RowDecorator = this.getRowAttributes.bind(this),
|
|
363
|
-
): React.ReactNode {
|
|
364
|
-
const { address, groups } = options;
|
|
365
|
-
const { className, style, title } = getRowAttributes(options);
|
|
366
|
-
return (
|
|
367
|
-
<tr
|
|
368
|
-
// Add a marker to help visual navigation when scrolling
|
|
369
|
-
className={className}
|
|
370
|
-
style={style}
|
|
371
|
-
title={title}
|
|
372
|
-
key={address}
|
|
373
|
-
>
|
|
374
|
-
<td className={MemoryTable.ADDRESS_DATA_CLASS}>{address}</td>
|
|
375
|
-
<td className={MemoryTable.MEMORY_DATA_CLASS}>{groups}</td>
|
|
376
|
-
{this.getExtraColumn(options)}
|
|
377
|
-
</tr>
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
protected getRowAttributes(options: Partial<MemoryTable.RowOptions>): Partial<Interfaces.StylableNodeAttributes> {
|
|
382
|
-
let className = MemoryTable.ROW_CLASS;
|
|
383
|
-
if (options.doShowDivider) {
|
|
384
|
-
className += ` ${MemoryTable.ROW_DIVIDER_CLASS}`;
|
|
385
|
-
}
|
|
386
|
-
return { className };
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
protected getExtraColumn(options: Pick<MemoryTable.RowOptions, 'ascii' | 'variables'>): React.ReactNode {
|
|
390
|
-
const { variables } = options;
|
|
391
|
-
const additionalColumns = [];
|
|
392
|
-
if (this.options.columnsDisplayed.variables.doRender) {
|
|
393
|
-
additionalColumns.push(
|
|
394
|
-
<td className={MemoryTable.EXTRA_COLUMN_DATA_CLASS} key='variables'>
|
|
395
|
-
{!!variables?.length && (
|
|
396
|
-
<span className='variable-container'>
|
|
397
|
-
{variables.map(({ name, color }) => (
|
|
398
|
-
<span
|
|
399
|
-
key={name}
|
|
400
|
-
className={MemoryTable.VARIABLE_LABEL_CLASS}
|
|
401
|
-
style={{ color }}
|
|
402
|
-
>
|
|
403
|
-
{name}
|
|
404
|
-
</span>
|
|
405
|
-
))}
|
|
406
|
-
</span>
|
|
407
|
-
)}
|
|
408
|
-
</td>,
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
if (this.options.columnsDisplayed.ascii.doRender) {
|
|
412
|
-
const asciiColumn = this.options.columnsDisplayed.ascii.doRender && <td className={MemoryTable.EXTRA_COLUMN_DATA_CLASS} key='ascii'>{options.ascii}</td>;
|
|
413
|
-
additionalColumns.push(asciiColumn);
|
|
414
|
-
}
|
|
415
|
-
return additionalColumns;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
protected *renderGroups(iteratee: Interfaces.LabeledUint8Array = this.memory.bytes): IterableIterator<MemoryTable.GroupData> {
|
|
419
|
-
let bytesInGroup: React.ReactNode[] = [];
|
|
420
|
-
let ascii = '';
|
|
421
|
-
let variables: VariableDecoration[] = [];
|
|
422
|
-
let isGroupHighlighted = false;
|
|
423
|
-
for (const { node, index, ascii: byteAscii, variables: byteVariables, isHighlighted = false } of this.renderBytes(iteratee)) {
|
|
424
|
-
this.buildGroupByEndianness(bytesInGroup, node);
|
|
425
|
-
ascii += byteAscii;
|
|
426
|
-
variables.push(...byteVariables);
|
|
427
|
-
isGroupHighlighted = isGroupHighlighted || isHighlighted;
|
|
428
|
-
if (bytesInGroup.length === this.options.bytesPerGroup || index === iteratee.length - 1) {
|
|
429
|
-
const itemID = this.memory.address.add(index);
|
|
430
|
-
yield {
|
|
431
|
-
node: <span className='byte-group' key={itemID.toString(16)}>{bytesInGroup}</span>,
|
|
432
|
-
ascii,
|
|
433
|
-
index,
|
|
434
|
-
variables,
|
|
435
|
-
isHighlighted: isGroupHighlighted,
|
|
436
|
-
};
|
|
437
|
-
bytesInGroup = [];
|
|
438
|
-
ascii = '';
|
|
439
|
-
variables = [];
|
|
440
|
-
isGroupHighlighted = false;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
protected buildGroupByEndianness(oldBytes: React.ReactNode[], newByte: React.ReactNode): void {
|
|
446
|
-
if (this.options.endianness === Interfaces.Endianness.Big) {
|
|
447
|
-
oldBytes.push(newByte);
|
|
448
|
-
} else {
|
|
449
|
-
oldBytes.unshift(newByte);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
protected *renderBytes(iteratee: Interfaces.LabeledUint8Array = this.memory.bytes): IterableIterator<MemoryTable.ByteData> {
|
|
454
|
-
const itemsPerByte = this.options.byteSize / 8;
|
|
455
|
-
let currentByte = 0;
|
|
456
|
-
let chunksInByte: React.ReactNode[] = [];
|
|
457
|
-
let variables: VariableDecoration[] = [];
|
|
458
|
-
let isByteHighlighted = false;
|
|
459
|
-
for (const { node, content, index, variable, isHighlighted = false } of this.renderArrayItems(iteratee)) {
|
|
460
|
-
chunksInByte.push(node);
|
|
461
|
-
const numericalValue = parseInt(content, 16);
|
|
462
|
-
currentByte = (currentByte << 8) + numericalValue;
|
|
463
|
-
isByteHighlighted = isByteHighlighted || isHighlighted;
|
|
464
|
-
if (variable?.firstAppearance) {
|
|
465
|
-
variables.push(variable);
|
|
466
|
-
}
|
|
467
|
-
if (chunksInByte.length === itemsPerByte || index === iteratee.length - 1) {
|
|
468
|
-
const itemID = this.memory.address.add(index);
|
|
469
|
-
const ascii = this.getASCIIForSingleByte(currentByte);
|
|
470
|
-
yield {
|
|
471
|
-
node: <span className='single-byte' key={itemID.toString(16)}>{chunksInByte}</span>,
|
|
472
|
-
ascii,
|
|
473
|
-
index,
|
|
474
|
-
variables,
|
|
475
|
-
isHighlighted: isByteHighlighted,
|
|
476
|
-
};
|
|
477
|
-
currentByte = 0;
|
|
478
|
-
chunksInByte = [];
|
|
479
|
-
variables = [];
|
|
480
|
-
isByteHighlighted = false;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
protected getASCIIForSingleByte(byte: number | undefined): string {
|
|
486
|
-
return typeof byte === 'undefined'
|
|
487
|
-
? ' ' : Utils.isPrintableAsAscii(byte) ? String.fromCharCode(byte) : '.';
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
protected *renderArrayItems(
|
|
491
|
-
iteratee: Interfaces.LabeledUint8Array = this.memory.bytes,
|
|
492
|
-
getBitAttributes: Interfaces.BitDecorator = this.getBitAttributes.bind(this),
|
|
493
|
-
): IterableIterator<MemoryTable.ItemData> {
|
|
494
|
-
const { address } = this.memory;
|
|
495
|
-
|
|
496
|
-
for (let i = 0; i < iteratee.length; i += 1) {
|
|
497
|
-
const itemID = address.add(i).toString(16);
|
|
498
|
-
const { content = '', className, style, variable, title, isHighlighted } = getBitAttributes(i, iteratee);
|
|
499
|
-
const node = (
|
|
500
|
-
<span
|
|
501
|
-
style={style}
|
|
502
|
-
key={itemID}
|
|
503
|
-
className={className}
|
|
504
|
-
data-id={itemID}
|
|
505
|
-
title={title}
|
|
506
|
-
>
|
|
507
|
-
{content}
|
|
508
|
-
</span>
|
|
509
|
-
);
|
|
510
|
-
yield {
|
|
511
|
-
node,
|
|
512
|
-
content,
|
|
513
|
-
index: i,
|
|
514
|
-
variable,
|
|
515
|
-
isHighlighted,
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
protected getBitAttributes(arrayOffset: number, iteratee: Interfaces.LabeledUint8Array): Partial<Interfaces.FullNodeAttributes> {
|
|
521
|
-
const itemAddress = this.memory.address.add(arrayOffset * 8 / this.options.byteSize);
|
|
522
|
-
const classNames = [MemoryTable.EIGHT_BIT_SPAN_CLASS];
|
|
523
|
-
const isChanged = this.previousBytes && iteratee[arrayOffset] !== this.previousBytes[arrayOffset];
|
|
524
|
-
const variable = this.variableFinder?.getVariableForAddress(itemAddress);
|
|
525
|
-
if (!this.options.isFrozen) {
|
|
526
|
-
if (isChanged) {
|
|
527
|
-
classNames.push('changed');
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return {
|
|
531
|
-
className: classNames.join(' '),
|
|
532
|
-
variable,
|
|
533
|
-
style: { color: variable?.color },
|
|
534
|
-
content: iteratee[arrayOffset].toString(16).padStart(2, '0')
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
protected handleTableMouseMove = (e: React.MouseEvent): void => {
|
|
539
|
-
const { target } = e; // react events can't be put into the debouncer
|
|
540
|
-
this.debounceHandleMouseTableMove(target);
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
protected debounceHandleMouseTableMove = debounce(this.doHandleTableMouseMove.bind(this), Constants.DEBOUNCE_TIME, { trailing: true });
|
|
544
|
-
|
|
545
|
-
protected doHandleTableMouseMove(targetSpan: React.MouseEvent['target']): void {
|
|
546
|
-
const target = targetSpan instanceof HTMLElement && targetSpan;
|
|
547
|
-
if (target) {
|
|
548
|
-
const { x, y } = target.getBoundingClientRect();
|
|
549
|
-
const anchor = { x: Math.round(x), y: Math.round(y + target.clientHeight) };
|
|
550
|
-
if (target.classList.contains(MemoryTable.EIGHT_BIT_SPAN_CLASS)) {
|
|
551
|
-
const properties = this.getHoverForChunk(target);
|
|
552
|
-
this.hoverRenderer.render(this.node, anchor, properties);
|
|
553
|
-
} else if (target.classList.contains(MemoryTable.VARIABLE_LABEL_CLASS)) {
|
|
554
|
-
const properties = this.getHoverForVariable(target);
|
|
555
|
-
this.hoverRenderer.render(this.node, anchor, properties);
|
|
556
|
-
} else {
|
|
557
|
-
this.hoverRenderer.hide();
|
|
558
|
-
}
|
|
559
|
-
} else {
|
|
560
|
-
this.hoverRenderer.hide();
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
protected getHoverForChunk(span: HTMLElement): EasilyMappedObject | undefined {
|
|
565
|
-
if (span.classList.contains(MemoryTable.EIGHT_BIT_SPAN_CLASS)) {
|
|
566
|
-
const parentByteContainer = span.parentElement;
|
|
567
|
-
if (parentByteContainer?.textContent) {
|
|
568
|
-
const hex = parentByteContainer.textContent ?? '';
|
|
569
|
-
const decimal = parseInt(hex, 16);
|
|
570
|
-
const binary = this.getPaddedBinary(decimal);
|
|
571
|
-
const UTF8 = String.fromCodePoint(decimal);
|
|
572
|
-
return { hex, binary, decimal, UTF8 };
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
return undefined;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
protected getPaddedBinary(decimal: number): string {
|
|
579
|
-
const paddedBinary = decimal.toString(2).padStart(this.options.byteSize, '0');
|
|
580
|
-
let paddedAndSpacedBinary = '';
|
|
581
|
-
for (let i = 8; i <= paddedBinary.length; i += 8) {
|
|
582
|
-
paddedAndSpacedBinary += ` ${paddedBinary.slice(i - 8, i)}`;
|
|
583
|
-
}
|
|
584
|
-
return paddedAndSpacedBinary.trim();
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
protected getHoverForVariable(span: HTMLElement): EasilyMappedObject | undefined {
|
|
588
|
-
const variable = this.variableFinder?.searchForVariable(span.textContent ?? '');
|
|
589
|
-
if (variable?.type) {
|
|
590
|
-
return { type: variable.type };
|
|
591
|
-
}
|
|
592
|
-
return undefined;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
protected handleTableRightClick = (e: React.MouseEvent): void => this.doHandleTableRightClick(e);
|
|
596
|
-
|
|
597
|
-
protected doHandleTableRightClick(event: React.MouseEvent): void {
|
|
598
|
-
event.preventDefault();
|
|
599
|
-
const target = event.target as HTMLElement;
|
|
600
|
-
if (target.classList?.contains('eight-bits')) {
|
|
601
|
-
const { right, top } = target.getBoundingClientRect();
|
|
602
|
-
this.update();
|
|
603
|
-
event.stopPropagation();
|
|
604
|
-
this.contextMenuRenderer.render({
|
|
605
|
-
menuPath: MemoryTableWidget.CONTEXT_MENU,
|
|
606
|
-
anchor: { x: right, y: top },
|
|
607
|
-
args: this.getContextMenuArgs(event),
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
protected getContextMenuArgs(event: React.MouseEvent): unknown[] {
|
|
613
|
-
const args: unknown[] = [this];
|
|
614
|
-
const id = (event.target as HTMLElement).getAttribute('data-id');
|
|
615
|
-
if (id) {
|
|
616
|
-
const location = hexStrToUnsignedLong(id);
|
|
617
|
-
args.push(location);
|
|
618
|
-
const offset = this.memory.address.multiply(-1).add(location);
|
|
619
|
-
const cellAddress = this.memory.address.add(offset.multiply(8 / this.options.byteSize));
|
|
620
|
-
const variableAtLocation = this.variableFinder?.searchForVariable(cellAddress);
|
|
621
|
-
args.push(variableAtLocation);
|
|
622
|
-
}
|
|
623
|
-
return args;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
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 { ContextMenuRenderer, ReactWidget, Widget } from '@theia/core/lib/browser';
|
|
18
|
+
import { ThemeService } from '@theia/core/lib/browser/theming';
|
|
19
|
+
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
20
|
+
import { ThemeChangeEvent } from '@theia/core/lib/common/theme';
|
|
21
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
22
|
+
import * as React from '@theia/core/shared/react';
|
|
23
|
+
import { hexStrToUnsignedLong } from '../../common/util';
|
|
24
|
+
import { MemoryProviderService } from '../memory-provider/memory-provider-service';
|
|
25
|
+
import { EasilyMappedObject, MemoryHoverRendererService } from '../utils/memory-hover-renderer';
|
|
26
|
+
import { MWMoreMemorySelect } from '../utils/memory-widget-components';
|
|
27
|
+
import {
|
|
28
|
+
Constants, Interfaces, Utils
|
|
29
|
+
} from '../utils/memory-widget-utils';
|
|
30
|
+
import { VariableDecoration, VariableFinder } from '../utils/memory-widget-variable-utils';
|
|
31
|
+
import { MemoryOptionsWidget } from './memory-options-widget';
|
|
32
|
+
import debounce = require('@theia/core/shared/lodash.debounce');
|
|
33
|
+
|
|
34
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
35
|
+
export namespace MemoryTable {
|
|
36
|
+
export interface WrapperHandlers {
|
|
37
|
+
onKeyDown?: React.KeyboardEventHandler;
|
|
38
|
+
onClick?: React.MouseEventHandler;
|
|
39
|
+
onContextMenu?: React.MouseEventHandler;
|
|
40
|
+
onMouseMove?: React.MouseEventHandler;
|
|
41
|
+
onFocus?(e: React.FocusEvent<HTMLDivElement>): any;
|
|
42
|
+
onBlur?(e: React.FocusEvent<HTMLDivElement>): any;
|
|
43
|
+
}
|
|
44
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
45
|
+
|
|
46
|
+
export interface StylableNodeAttributes {
|
|
47
|
+
className?: string;
|
|
48
|
+
style?: React.CSSProperties;
|
|
49
|
+
variable?: VariableDecoration;
|
|
50
|
+
title?: string;
|
|
51
|
+
isHighlighted?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface GroupData {
|
|
55
|
+
node: React.ReactNode;
|
|
56
|
+
ascii: string; index: number;
|
|
57
|
+
variables: VariableDecoration[];
|
|
58
|
+
isHighlighted?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface ByteData {
|
|
61
|
+
node: React.ReactNode;
|
|
62
|
+
ascii: string; index: number;
|
|
63
|
+
variables: VariableDecoration[];
|
|
64
|
+
isHighlighted?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface ItemData {
|
|
67
|
+
node: React.ReactNode;
|
|
68
|
+
content: string;
|
|
69
|
+
variable?: VariableDecoration;
|
|
70
|
+
index: number;
|
|
71
|
+
isHighlighted?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface RowOptions {
|
|
75
|
+
address: string;
|
|
76
|
+
groups: React.ReactNode;
|
|
77
|
+
ascii?: string;
|
|
78
|
+
variables?: VariableDecoration[];
|
|
79
|
+
doShowDivider?: boolean;
|
|
80
|
+
index: number;
|
|
81
|
+
isHighlighted?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const ROW_CLASS = 't-mv-view-row';
|
|
85
|
+
export const ROW_DIVIDER_CLASS = 't-mv-view-row-highlight';
|
|
86
|
+
export const ADDRESS_DATA_CLASS = 't-mv-view-address';
|
|
87
|
+
export const MEMORY_DATA_CLASS = 't-mv-view-data';
|
|
88
|
+
export const EXTRA_COLUMN_DATA_CLASS = 't-mv-view-code';
|
|
89
|
+
export const GROUP_SPAN_CLASS = 'byte-group';
|
|
90
|
+
export const BYTE_SPAN_CLASS = 'single-byte';
|
|
91
|
+
export const EIGHT_BIT_SPAN_CLASS = 'eight-bits';
|
|
92
|
+
export const HEADER_LABEL_CONTAINER_CLASS = 't-mv-header-label-container';
|
|
93
|
+
export const HEADER_LABEL_CLASS = 't-mv-header-label';
|
|
94
|
+
export const VARIABLE_LABEL_CLASS = 't-mv-variable-label';
|
|
95
|
+
export const HEADER_ROW_CLASS = 't-mv-header';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@injectable()
|
|
99
|
+
export class MemoryTableWidget extends ReactWidget {
|
|
100
|
+
static CONTEXT_MENU = ['memory.view.context.menu'];
|
|
101
|
+
static ID = 'memory-table-widget';
|
|
102
|
+
|
|
103
|
+
@inject(ThemeService) protected readonly themeService: ThemeService;
|
|
104
|
+
@inject(MemoryOptionsWidget) readonly optionsWidget: MemoryOptionsWidget;
|
|
105
|
+
@inject(MemoryProviderService) protected readonly memoryProvider: MemoryProviderService;
|
|
106
|
+
@inject(MemoryHoverRendererService) protected readonly hoverRenderer: MemoryHoverRendererService;
|
|
107
|
+
@inject(ContextMenuRenderer) protected readonly contextMenuRenderer: ContextMenuRenderer;
|
|
108
|
+
|
|
109
|
+
protected previousBytes: Interfaces.LabeledUint8Array | undefined;
|
|
110
|
+
protected memory: Interfaces.WidgetMemoryState;
|
|
111
|
+
protected options: Interfaces.MemoryOptions;
|
|
112
|
+
protected variableFinder: VariableFinder | undefined;
|
|
113
|
+
protected deferredScrollContainer = new Deferred<HTMLDivElement>();
|
|
114
|
+
|
|
115
|
+
@postConstruct()
|
|
116
|
+
protected init(): void {
|
|
117
|
+
this.doInit();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected async doInit(): Promise<void> {
|
|
121
|
+
this.id = MemoryTableWidget.ID;
|
|
122
|
+
this.addClass(MemoryTableWidget.ID);
|
|
123
|
+
this.scrollOptions = { ...this.scrollOptions, suppressScrollX: false };
|
|
124
|
+
this.toDispose.push(this.optionsWidget.onOptionsChanged(optionId => this.handleOptionChange(optionId)));
|
|
125
|
+
this.toDispose.push(this.optionsWidget.onMemoryChanged(e => this.handleMemoryChange(e)));
|
|
126
|
+
this.toDispose.push(this.themeService.onDidColorThemeChange(e => this.handleThemeChange(e)));
|
|
127
|
+
|
|
128
|
+
this.getStateAndUpdate();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected handleOptionChange(_id?: string): Promise<void> {
|
|
132
|
+
this.getStateAndUpdate();
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override update(): void {
|
|
137
|
+
super.update();
|
|
138
|
+
this.updateColumnWidths();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
protected override onResize(msg: Widget.ResizeMessage): void {
|
|
142
|
+
this.updateColumnWidths();
|
|
143
|
+
super.onResize(msg);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
protected updateColumnWidths = debounce(this.doUpdateColumnWidths.bind(this), Constants.DEBOUNCE_TIME);
|
|
147
|
+
|
|
148
|
+
protected doUpdateColumnWidths(): void {
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
const firstTR = this.node.querySelector('tr');
|
|
151
|
+
const header = this.node.querySelector(`.${MemoryTable.HEADER_ROW_CLASS}`) as HTMLDivElement;
|
|
152
|
+
if (firstTR && header) {
|
|
153
|
+
const allTDs = Array.from(firstTR.querySelectorAll('td'));
|
|
154
|
+
const allSizes = allTDs.map(td => `minmax(max-content, ${td.clientWidth}px)`);
|
|
155
|
+
header.style.gridTemplateColumns = allSizes.join(' ');
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected areSameRegion(a: Interfaces.MemoryReadResult, b: Interfaces.MemoryReadResult): boolean {
|
|
161
|
+
return a.address.equals(b?.address) && a.bytes.length === b?.bytes.length;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
protected handleMemoryChange(newMemory: Interfaces.MemoryReadResult): void {
|
|
165
|
+
if (this.areSameRegion(this.memory, newMemory)) {
|
|
166
|
+
this.previousBytes = this.memory.bytes;
|
|
167
|
+
} else {
|
|
168
|
+
this.previousBytes = undefined;
|
|
169
|
+
}
|
|
170
|
+
this.getStateAndUpdate();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
protected handleThemeChange(_themeChange: ThemeChangeEvent): void {
|
|
174
|
+
this.getStateAndUpdate();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
protected getState(): void {
|
|
178
|
+
this.options = this.optionsWidget.options;
|
|
179
|
+
this.memory = this.optionsWidget.memory;
|
|
180
|
+
const isHighContrast = this.themeService.getCurrentTheme().type === 'hc';
|
|
181
|
+
this.variableFinder = this.optionsWidget.options.columnsDisplayed.variables.doRender
|
|
182
|
+
? new VariableFinder(this.memory.variables, isHighContrast)
|
|
183
|
+
: undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
protected getStateAndUpdate(): void {
|
|
187
|
+
this.getState();
|
|
188
|
+
this.update();
|
|
189
|
+
this.scrollIntoViewIfNecessary();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
protected scrollIntoViewIfNecessary(): Promise<void> {
|
|
193
|
+
return new Promise(resolve => setTimeout(() => {
|
|
194
|
+
this.deferredScrollContainer.promise.then(scrollContainer => {
|
|
195
|
+
const table = scrollContainer.querySelector('table');
|
|
196
|
+
if (table && scrollContainer.scrollTop > table.clientHeight) {
|
|
197
|
+
const valueToGetInWindow = table.clientHeight - this.node.clientHeight;
|
|
198
|
+
const scrollHere = Math.max(valueToGetInWindow, 0);
|
|
199
|
+
scrollContainer.scrollTo(scrollContainer.scrollLeft, scrollHere);
|
|
200
|
+
}
|
|
201
|
+
this.scrollBar?.update();
|
|
202
|
+
resolve();
|
|
203
|
+
});
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
protected getWrapperHandlers(): MemoryTable.WrapperHandlers {
|
|
208
|
+
return { onMouseMove: this.handleTableMouseMove };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
protected assignScrollContainerRef = (element: HTMLDivElement): void => {
|
|
212
|
+
this.deferredScrollContainer.resolve(element);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
override async getScrollContainer(): Promise<HTMLDivElement> {
|
|
216
|
+
return this.deferredScrollContainer.promise;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
render(): React.ReactNode {
|
|
220
|
+
const rows = this.getTableRows();
|
|
221
|
+
const { onClick, onContextMenu, onFocus, onBlur, onKeyDown, onMouseMove } = this.getWrapperHandlers();
|
|
222
|
+
const headers: Interfaces.ColumnIDs[] = Object.entries(this.options.columnsDisplayed)
|
|
223
|
+
.filter(([, { doRender }]) => doRender)
|
|
224
|
+
.map(([id, { label }]) => ({ label, id }));
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<div
|
|
228
|
+
className={this.getWrapperClass()}
|
|
229
|
+
onClick={onClick}
|
|
230
|
+
onContextMenu={onContextMenu}
|
|
231
|
+
onFocus={onFocus}
|
|
232
|
+
onBlur={onBlur}
|
|
233
|
+
onKeyDown={onKeyDown}
|
|
234
|
+
onMouseMove={onMouseMove}
|
|
235
|
+
role='textbox'
|
|
236
|
+
tabIndex={0}
|
|
237
|
+
>
|
|
238
|
+
<div
|
|
239
|
+
className={this.getTableHeaderClass()}
|
|
240
|
+
style={this.getTableHeaderStyle(headers.length)}
|
|
241
|
+
>
|
|
242
|
+
{this.getTableHeaders(headers)}
|
|
243
|
+
</div>
|
|
244
|
+
<div
|
|
245
|
+
className='t-mv-view-container'
|
|
246
|
+
style={{ position: 'relative' }}
|
|
247
|
+
ref={this.assignScrollContainerRef}
|
|
248
|
+
>
|
|
249
|
+
{this.getBeforeTableContent()}
|
|
250
|
+
<table className='t-mv-view'>
|
|
251
|
+
<tbody>
|
|
252
|
+
{rows}
|
|
253
|
+
</tbody>
|
|
254
|
+
</table>
|
|
255
|
+
{this.getAfterTableContent()}
|
|
256
|
+
</div>
|
|
257
|
+
{this.getTableFooter()}
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
protected getWrapperClass(): string {
|
|
263
|
+
return `t-mv-memory-container${this.options.isFrozen ? ' frozen' : ''}`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
protected getTableHeaderClass(): string {
|
|
267
|
+
return MemoryTable.HEADER_ROW_CLASS + ' no-select';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protected getTableHeaderStyle(numLabels: number): React.CSSProperties {
|
|
271
|
+
const safePercentage = Math.floor(100 / numLabels);
|
|
272
|
+
const gridTemplateColumns = ` ${safePercentage}% `.repeat(numLabels);
|
|
273
|
+
return { gridTemplateColumns };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
protected getTableHeaders(labels: Interfaces.ColumnIDs[]): React.ReactNode {
|
|
277
|
+
return labels.map(label => this.getTableHeader(label));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
protected getTableHeader({ label, id }: Interfaces.ColumnIDs): React.ReactNode {
|
|
281
|
+
return (
|
|
282
|
+
<div key={id} className={MemoryTable.HEADER_LABEL_CONTAINER_CLASS}>
|
|
283
|
+
<span className='t-mv-header-label'>{label}</span>
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
protected getBeforeTableContent(): React.ReactNode {
|
|
289
|
+
return (
|
|
290
|
+
!!this.memory.bytes.length && (<MWMoreMemorySelect
|
|
291
|
+
options={[128, 256, 512]}
|
|
292
|
+
direction='above'
|
|
293
|
+
handler={this.loadMoreMemory}
|
|
294
|
+
/>)
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
protected getAfterTableContent(): React.ReactNode {
|
|
299
|
+
return (
|
|
300
|
+
!!this.memory.bytes.length && (<MWMoreMemorySelect
|
|
301
|
+
options={[128, 256, 512]}
|
|
302
|
+
direction='below'
|
|
303
|
+
handler={this.loadMoreMemory}
|
|
304
|
+
/>)
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
protected loadMoreMemory = async (options: Interfaces.MoreMemoryOptions): Promise<void> => {
|
|
309
|
+
const { direction, numBytes } = options;
|
|
310
|
+
const { address, offset, length } = this.optionsWidget.options;
|
|
311
|
+
let newOffset = 0;
|
|
312
|
+
const newLength = length + numBytes;
|
|
313
|
+
if (direction === 'above') {
|
|
314
|
+
newOffset = offset - numBytes;
|
|
315
|
+
}
|
|
316
|
+
await this.optionsWidget.setAddressAndGo(`${address}`, newOffset, newLength, direction);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
protected getTableFooter(): React.ReactNode {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
protected getTableRows(): React.ReactNode {
|
|
324
|
+
return [...this.renderRows()];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
protected *renderRows(iteratee: Interfaces.LabeledUint8Array = this.memory.bytes): IterableIterator<React.ReactNode> {
|
|
328
|
+
const bytesPerRow = this.options.bytesPerGroup * this.options.groupsPerRow;
|
|
329
|
+
let rowsYielded = 0;
|
|
330
|
+
let groups: React.ReactNode[] = [];
|
|
331
|
+
let ascii = '';
|
|
332
|
+
let variables: VariableDecoration[] = [];
|
|
333
|
+
let isRowHighlighted = false;
|
|
334
|
+
for (const { node, index, ascii: groupAscii, variables: groupVariables, isHighlighted = false } of this.renderGroups(iteratee)) {
|
|
335
|
+
groups.push(node);
|
|
336
|
+
ascii += groupAscii;
|
|
337
|
+
variables.push(...groupVariables);
|
|
338
|
+
isRowHighlighted = isRowHighlighted || isHighlighted;
|
|
339
|
+
if (groups.length === this.options.groupsPerRow || index === iteratee.length - 1) {
|
|
340
|
+
const rowAddress = this.memory.address.add(bytesPerRow * rowsYielded);
|
|
341
|
+
const options: MemoryTable.RowOptions = {
|
|
342
|
+
address: `0x${rowAddress.toString(16)}`,
|
|
343
|
+
doShowDivider: (rowsYielded % 4) === 3,
|
|
344
|
+
isHighlighted: isRowHighlighted,
|
|
345
|
+
ascii,
|
|
346
|
+
groups,
|
|
347
|
+
variables,
|
|
348
|
+
index,
|
|
349
|
+
};
|
|
350
|
+
yield this.renderRow(options);
|
|
351
|
+
ascii = '';
|
|
352
|
+
variables = [];
|
|
353
|
+
groups = [];
|
|
354
|
+
rowsYielded += 1;
|
|
355
|
+
isRowHighlighted = false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
protected renderRow(
|
|
361
|
+
options: MemoryTable.RowOptions,
|
|
362
|
+
getRowAttributes: Interfaces.RowDecorator = this.getRowAttributes.bind(this),
|
|
363
|
+
): React.ReactNode {
|
|
364
|
+
const { address, groups } = options;
|
|
365
|
+
const { className, style, title } = getRowAttributes(options);
|
|
366
|
+
return (
|
|
367
|
+
<tr
|
|
368
|
+
// Add a marker to help visual navigation when scrolling
|
|
369
|
+
className={className}
|
|
370
|
+
style={style}
|
|
371
|
+
title={title}
|
|
372
|
+
key={address}
|
|
373
|
+
>
|
|
374
|
+
<td className={MemoryTable.ADDRESS_DATA_CLASS}>{address}</td>
|
|
375
|
+
<td className={MemoryTable.MEMORY_DATA_CLASS}>{groups}</td>
|
|
376
|
+
{this.getExtraColumn(options)}
|
|
377
|
+
</tr>
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
protected getRowAttributes(options: Partial<MemoryTable.RowOptions>): Partial<Interfaces.StylableNodeAttributes> {
|
|
382
|
+
let className = MemoryTable.ROW_CLASS;
|
|
383
|
+
if (options.doShowDivider) {
|
|
384
|
+
className += ` ${MemoryTable.ROW_DIVIDER_CLASS}`;
|
|
385
|
+
}
|
|
386
|
+
return { className };
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
protected getExtraColumn(options: Pick<MemoryTable.RowOptions, 'ascii' | 'variables'>): React.ReactNode {
|
|
390
|
+
const { variables } = options;
|
|
391
|
+
const additionalColumns = [];
|
|
392
|
+
if (this.options.columnsDisplayed.variables.doRender) {
|
|
393
|
+
additionalColumns.push(
|
|
394
|
+
<td className={MemoryTable.EXTRA_COLUMN_DATA_CLASS} key='variables'>
|
|
395
|
+
{!!variables?.length && (
|
|
396
|
+
<span className='variable-container'>
|
|
397
|
+
{variables.map(({ name, color }) => (
|
|
398
|
+
<span
|
|
399
|
+
key={name}
|
|
400
|
+
className={MemoryTable.VARIABLE_LABEL_CLASS}
|
|
401
|
+
style={{ color }}
|
|
402
|
+
>
|
|
403
|
+
{name}
|
|
404
|
+
</span>
|
|
405
|
+
))}
|
|
406
|
+
</span>
|
|
407
|
+
)}
|
|
408
|
+
</td>,
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
if (this.options.columnsDisplayed.ascii.doRender) {
|
|
412
|
+
const asciiColumn = this.options.columnsDisplayed.ascii.doRender && <td className={MemoryTable.EXTRA_COLUMN_DATA_CLASS} key='ascii'>{options.ascii}</td>;
|
|
413
|
+
additionalColumns.push(asciiColumn);
|
|
414
|
+
}
|
|
415
|
+
return additionalColumns;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
protected *renderGroups(iteratee: Interfaces.LabeledUint8Array = this.memory.bytes): IterableIterator<MemoryTable.GroupData> {
|
|
419
|
+
let bytesInGroup: React.ReactNode[] = [];
|
|
420
|
+
let ascii = '';
|
|
421
|
+
let variables: VariableDecoration[] = [];
|
|
422
|
+
let isGroupHighlighted = false;
|
|
423
|
+
for (const { node, index, ascii: byteAscii, variables: byteVariables, isHighlighted = false } of this.renderBytes(iteratee)) {
|
|
424
|
+
this.buildGroupByEndianness(bytesInGroup, node);
|
|
425
|
+
ascii += byteAscii;
|
|
426
|
+
variables.push(...byteVariables);
|
|
427
|
+
isGroupHighlighted = isGroupHighlighted || isHighlighted;
|
|
428
|
+
if (bytesInGroup.length === this.options.bytesPerGroup || index === iteratee.length - 1) {
|
|
429
|
+
const itemID = this.memory.address.add(index);
|
|
430
|
+
yield {
|
|
431
|
+
node: <span className='byte-group' key={itemID.toString(16)}>{bytesInGroup}</span>,
|
|
432
|
+
ascii,
|
|
433
|
+
index,
|
|
434
|
+
variables,
|
|
435
|
+
isHighlighted: isGroupHighlighted,
|
|
436
|
+
};
|
|
437
|
+
bytesInGroup = [];
|
|
438
|
+
ascii = '';
|
|
439
|
+
variables = [];
|
|
440
|
+
isGroupHighlighted = false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
protected buildGroupByEndianness(oldBytes: React.ReactNode[], newByte: React.ReactNode): void {
|
|
446
|
+
if (this.options.endianness === Interfaces.Endianness.Big) {
|
|
447
|
+
oldBytes.push(newByte);
|
|
448
|
+
} else {
|
|
449
|
+
oldBytes.unshift(newByte);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
protected *renderBytes(iteratee: Interfaces.LabeledUint8Array = this.memory.bytes): IterableIterator<MemoryTable.ByteData> {
|
|
454
|
+
const itemsPerByte = this.options.byteSize / 8;
|
|
455
|
+
let currentByte = 0;
|
|
456
|
+
let chunksInByte: React.ReactNode[] = [];
|
|
457
|
+
let variables: VariableDecoration[] = [];
|
|
458
|
+
let isByteHighlighted = false;
|
|
459
|
+
for (const { node, content, index, variable, isHighlighted = false } of this.renderArrayItems(iteratee)) {
|
|
460
|
+
chunksInByte.push(node);
|
|
461
|
+
const numericalValue = parseInt(content, 16);
|
|
462
|
+
currentByte = (currentByte << 8) + numericalValue;
|
|
463
|
+
isByteHighlighted = isByteHighlighted || isHighlighted;
|
|
464
|
+
if (variable?.firstAppearance) {
|
|
465
|
+
variables.push(variable);
|
|
466
|
+
}
|
|
467
|
+
if (chunksInByte.length === itemsPerByte || index === iteratee.length - 1) {
|
|
468
|
+
const itemID = this.memory.address.add(index);
|
|
469
|
+
const ascii = this.getASCIIForSingleByte(currentByte);
|
|
470
|
+
yield {
|
|
471
|
+
node: <span className='single-byte' key={itemID.toString(16)}>{chunksInByte}</span>,
|
|
472
|
+
ascii,
|
|
473
|
+
index,
|
|
474
|
+
variables,
|
|
475
|
+
isHighlighted: isByteHighlighted,
|
|
476
|
+
};
|
|
477
|
+
currentByte = 0;
|
|
478
|
+
chunksInByte = [];
|
|
479
|
+
variables = [];
|
|
480
|
+
isByteHighlighted = false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
protected getASCIIForSingleByte(byte: number | undefined): string {
|
|
486
|
+
return typeof byte === 'undefined'
|
|
487
|
+
? ' ' : Utils.isPrintableAsAscii(byte) ? String.fromCharCode(byte) : '.';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
protected *renderArrayItems(
|
|
491
|
+
iteratee: Interfaces.LabeledUint8Array = this.memory.bytes,
|
|
492
|
+
getBitAttributes: Interfaces.BitDecorator = this.getBitAttributes.bind(this),
|
|
493
|
+
): IterableIterator<MemoryTable.ItemData> {
|
|
494
|
+
const { address } = this.memory;
|
|
495
|
+
|
|
496
|
+
for (let i = 0; i < iteratee.length; i += 1) {
|
|
497
|
+
const itemID = address.add(i).toString(16);
|
|
498
|
+
const { content = '', className, style, variable, title, isHighlighted } = getBitAttributes(i, iteratee);
|
|
499
|
+
const node = (
|
|
500
|
+
<span
|
|
501
|
+
style={style}
|
|
502
|
+
key={itemID}
|
|
503
|
+
className={className}
|
|
504
|
+
data-id={itemID}
|
|
505
|
+
title={title}
|
|
506
|
+
>
|
|
507
|
+
{content}
|
|
508
|
+
</span>
|
|
509
|
+
);
|
|
510
|
+
yield {
|
|
511
|
+
node,
|
|
512
|
+
content,
|
|
513
|
+
index: i,
|
|
514
|
+
variable,
|
|
515
|
+
isHighlighted,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
protected getBitAttributes(arrayOffset: number, iteratee: Interfaces.LabeledUint8Array): Partial<Interfaces.FullNodeAttributes> {
|
|
521
|
+
const itemAddress = this.memory.address.add(arrayOffset * 8 / this.options.byteSize);
|
|
522
|
+
const classNames = [MemoryTable.EIGHT_BIT_SPAN_CLASS];
|
|
523
|
+
const isChanged = this.previousBytes && iteratee[arrayOffset] !== this.previousBytes[arrayOffset];
|
|
524
|
+
const variable = this.variableFinder?.getVariableForAddress(itemAddress);
|
|
525
|
+
if (!this.options.isFrozen) {
|
|
526
|
+
if (isChanged) {
|
|
527
|
+
classNames.push('changed');
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return {
|
|
531
|
+
className: classNames.join(' '),
|
|
532
|
+
variable,
|
|
533
|
+
style: { color: variable?.color },
|
|
534
|
+
content: iteratee[arrayOffset].toString(16).padStart(2, '0')
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
protected handleTableMouseMove = (e: React.MouseEvent): void => {
|
|
539
|
+
const { target } = e; // react events can't be put into the debouncer
|
|
540
|
+
this.debounceHandleMouseTableMove(target);
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
protected debounceHandleMouseTableMove = debounce(this.doHandleTableMouseMove.bind(this), Constants.DEBOUNCE_TIME, { trailing: true });
|
|
544
|
+
|
|
545
|
+
protected doHandleTableMouseMove(targetSpan: React.MouseEvent['target']): void {
|
|
546
|
+
const target = targetSpan instanceof HTMLElement && targetSpan;
|
|
547
|
+
if (target) {
|
|
548
|
+
const { x, y } = target.getBoundingClientRect();
|
|
549
|
+
const anchor = { x: Math.round(x), y: Math.round(y + target.clientHeight) };
|
|
550
|
+
if (target.classList.contains(MemoryTable.EIGHT_BIT_SPAN_CLASS)) {
|
|
551
|
+
const properties = this.getHoverForChunk(target);
|
|
552
|
+
this.hoverRenderer.render(this.node, anchor, properties);
|
|
553
|
+
} else if (target.classList.contains(MemoryTable.VARIABLE_LABEL_CLASS)) {
|
|
554
|
+
const properties = this.getHoverForVariable(target);
|
|
555
|
+
this.hoverRenderer.render(this.node, anchor, properties);
|
|
556
|
+
} else {
|
|
557
|
+
this.hoverRenderer.hide();
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
this.hoverRenderer.hide();
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
protected getHoverForChunk(span: HTMLElement): EasilyMappedObject | undefined {
|
|
565
|
+
if (span.classList.contains(MemoryTable.EIGHT_BIT_SPAN_CLASS)) {
|
|
566
|
+
const parentByteContainer = span.parentElement;
|
|
567
|
+
if (parentByteContainer?.textContent) {
|
|
568
|
+
const hex = parentByteContainer.textContent ?? '';
|
|
569
|
+
const decimal = parseInt(hex, 16);
|
|
570
|
+
const binary = this.getPaddedBinary(decimal);
|
|
571
|
+
const UTF8 = String.fromCodePoint(decimal);
|
|
572
|
+
return { hex, binary, decimal, UTF8 };
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
protected getPaddedBinary(decimal: number): string {
|
|
579
|
+
const paddedBinary = decimal.toString(2).padStart(this.options.byteSize, '0');
|
|
580
|
+
let paddedAndSpacedBinary = '';
|
|
581
|
+
for (let i = 8; i <= paddedBinary.length; i += 8) {
|
|
582
|
+
paddedAndSpacedBinary += ` ${paddedBinary.slice(i - 8, i)}`;
|
|
583
|
+
}
|
|
584
|
+
return paddedAndSpacedBinary.trim();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
protected getHoverForVariable(span: HTMLElement): EasilyMappedObject | undefined {
|
|
588
|
+
const variable = this.variableFinder?.searchForVariable(span.textContent ?? '');
|
|
589
|
+
if (variable?.type) {
|
|
590
|
+
return { type: variable.type };
|
|
591
|
+
}
|
|
592
|
+
return undefined;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
protected handleTableRightClick = (e: React.MouseEvent): void => this.doHandleTableRightClick(e);
|
|
596
|
+
|
|
597
|
+
protected doHandleTableRightClick(event: React.MouseEvent): void {
|
|
598
|
+
event.preventDefault();
|
|
599
|
+
const target = event.target as HTMLElement;
|
|
600
|
+
if (target.classList?.contains('eight-bits')) {
|
|
601
|
+
const { right, top } = target.getBoundingClientRect();
|
|
602
|
+
this.update();
|
|
603
|
+
event.stopPropagation();
|
|
604
|
+
this.contextMenuRenderer.render({
|
|
605
|
+
menuPath: MemoryTableWidget.CONTEXT_MENU,
|
|
606
|
+
anchor: { x: right, y: top },
|
|
607
|
+
args: this.getContextMenuArgs(event),
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
protected getContextMenuArgs(event: React.MouseEvent): unknown[] {
|
|
613
|
+
const args: unknown[] = [this];
|
|
614
|
+
const id = (event.target as HTMLElement).getAttribute('data-id');
|
|
615
|
+
if (id) {
|
|
616
|
+
const location = hexStrToUnsignedLong(id);
|
|
617
|
+
args.push(location);
|
|
618
|
+
const offset = this.memory.address.multiply(-1).add(location);
|
|
619
|
+
const cellAddress = this.memory.address.add(offset.multiply(8 / this.options.byteSize));
|
|
620
|
+
const variableAtLocation = this.variableFinder?.searchForVariable(cellAddress);
|
|
621
|
+
args.push(variableAtLocation);
|
|
622
|
+
}
|
|
623
|
+
return args;
|
|
624
|
+
}
|
|
625
|
+
}
|