Skip to content

Commit

Permalink
Integrate Memory Inspector in Theia repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Grant committed Jul 12, 2022
1 parent c0ee4dc commit b6db786
Show file tree
Hide file tree
Showing 49 changed files with 6,409 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@theia/git": "1.27.0",
"@theia/keymaps": "1.27.0",
"@theia/markers": "1.27.0",
"@theia/memory-inspector": "1.27.0",
"@theia/messages": "1.27.0",
"@theia/metrics": "1.27.0",
"@theia/mini-browser": "1.27.0",
Expand Down
3 changes: 3 additions & 0 deletions examples/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
{
"path": "../../packages/markers"
},
{
"path": "../../packages/memory-inspector"
},
{
"path": "../../packages/messages"
},
Expand Down
1 change: 1 addition & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@theia/git": "1.27.0",
"@theia/keymaps": "1.27.0",
"@theia/markers": "1.27.0",
"@theia/memory-inspector": "1.27.0",
"@theia/messages": "1.27.0",
"@theia/metrics": "1.27.0",
"@theia/mini-browser": "1.27.0",
Expand Down
3 changes: 3 additions & 0 deletions examples/electron/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
{
"path": "../../packages/markers"
},
{
"path": "../../packages/memory-inspector"
},
{
"path": "../../packages/messages"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/memory-inspector/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: [
'../../configs/build.eslintrc.json'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json'
}
};
42 changes: 42 additions & 0 deletions packages/memory-inspector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# memory-inspector

This extension contributes a set of widgets for viewing memory in different ways.

## Requirements

This extension must be used in conjunction with a Debug Adapter that implements a ReadMemoryRequest handler or alternative custom request that returns memory data. It has been tested against the [CDT-GDB Adapter](https://github.com/eclipse-cdt/cdt-gdb-adapter) used as the backend for the
[CDT-GDB VSCode](https://github.com/eclipse-cdt/cdt-gdb-vscode) plugin. This repository is configured to download that plugin as part of its build routine.
If you intend to use this extension with a different debug adapter, you may need to implement a custom
[`MemoryProvider`](./src/browser/memory-provider/memory-provider-service.ts) to handle any peculiarities of the requests and responses used by your adapter.

## The Widgets

### Memory Widget

The basic [`MemoryWidget` class](./src/browser/memory-widget/memory-widget.ts) is a wrapper around two functional widgets, a `MemoryOptionsWidget` and
a`MemoryTableWidget`. The [`MemoryOptionsWidget`](./src/browser/memory-widget/memory-options-widget.tsx) is responsible for configuring the display
and fetching memory, and the [`MemoryTableWidget`](./src/browser/memory-widget/memory-table-widget.tsx) renders the memory according to the options
specified by the user in the `MemoryOptionsWidget`. The basic combination of these three classes offers variable highlighting, ascii display, and
dynamic updating in response to events from the debug session, as well as the option to lock the view to ignore changes from the session.

### Diff Widget

The [`MemoryDiffWidget`](./src/browser/diff-widget/memory-diff-widget-types.ts) is an elaboration of the `MemoryWidget` type that allows side-by-side
comparison of the contents of two `MemoryWidgets`.

### Register Widget

The [`RegisterWidget`](./src/browser/register-widget/register-widget-types.ts) offers functionality to view and
manipulate those values when using a debug adapter that reports register contents.

### Editable Widget

The [`MemoryEditableTableWidget`](./src/browser/editable-widget/memory-editable-table-widget.tsx) adds UI functionality to allow users to modify values in
the table display and send them to a backend that supports that operation.

## Using the Widgets

The widgets are created by the [`MemoryWidgetManager`](./src/browser/utils/memory-widget-manager.ts), and modifying the `createNewMemoryWidget()`
method of that service allows you to change what kind of widget is instantiated and under what circumstances. The widgets get memory through the
[`MemoryProviderService`](./src/browser/memory-provider/memory-provider-service.ts), which delegates to implementations `MemoryProvider` interface
that are bound as `MemoryProvider` contributions.
46 changes: 46 additions & 0 deletions packages/memory-inspector/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@theia/memory-inspector",
"version": "1.27.0",
"description": "Theia - Memory Inspector",
"keywords": [
"theia-extension"
],
"homepage": "https://github.com/eclipse-theia/theia",
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
"repository": {
"type": "git",
"url": "https://github.com/eclipse-theia/theia.git"
},
"bugs": {
"url": "https://github.com/eclipse-theia/theia/issues"
},
"files": [
"lib",
"src"
],
"scripts": {
"build": "theiaext build",
"clean": "theiaext clean",
"compile": "theiaext compile",
"lint": "theiaext lint",
"test": "theiaext test",
"watch": "theiaext watch"
},
"dependencies": {
"@theia/core": "1.27.0",
"@theia/debug": "1.27.0",
"long": "^4.0.0",
"vscode-debugprotocol": "^1.48.0"
},
"devDependencies": {
"@types/long": "^4.0.0"
},
"theiaExtensions": [
{
"frontend": "lib/browser/memory-inspector-frontend-module"
}
],
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/********************************************************************************
* Copyright (C) 2021 Ericsson and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Key, KeyCode } from '@theia/core/lib/browser';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import * as React from '@theia/core/shared/react';
import { ThemeType } from '@theia/core/lib/common/theme';
import { LENGTH_FIELD_ID, LOCATION_OFFSET_FIELD_ID, MemoryOptionsWidget } from '../memory-widget/memory-options-widget';
import { MWInput } from '../utils/memory-widget-components';
import { Interfaces, MemoryDiffWidgetData, Utils } from '../utils/memory-widget-utils';
import { DiffLabels } from './memory-diff-widget-types';

export interface DiffMemoryOptions extends Interfaces.MemoryOptions {
beforeOffset: number;
afterOffset: number;
}

@injectable()
export class MemoryDiffOptionsWidget extends MemoryOptionsWidget {
@inject(MemoryDiffWidgetData) protected override memoryWidgetOptions: MemoryDiffWidgetData;

protected themeType: ThemeType;

override get options(): DiffMemoryOptions {
return this.storeState();
}

updateDiffData(newDiffData: Partial<MemoryDiffWidgetData>): void {
this.memoryWidgetOptions = { ...this.memoryWidgetOptions, ...newDiffData };
this.init();
}

@postConstruct()
protected override init(): void {
this.addClass(MemoryOptionsWidget.ID);
this.addClass('diff-options-widget');
const { identifier, beforeBytes, afterBytes } = this.memoryWidgetOptions;
this.id = `${MemoryDiffOptionsWidget.ID}-${identifier}`;
this.title.label = `Diff: ${identifier}`;
this.title.caption = this.title.label;
this.title.iconClass = this.iconClass;
this.title.closable = true;

this.toDispose.push(this.onOptionsChanged(() => this.update()));

beforeBytes.label = DiffLabels.Before;
afterBytes.label = DiffLabels.After;

this.columnsDisplayed = {
beforeAddress: { label: 'Address', doRender: true },
beforeData: { label: this.memoryWidgetOptions.titles[0], doRender: true },
afterAddress: { label: 'Address', doRender: true },
afterData: { label: this.memoryWidgetOptions.titles[1], doRender: true },
variables: { label: 'Variables', doRender: false },
ascii: { label: 'ASCII', doRender: false },
};

this.update();
}

protected override acceptFocus(): void {
const settingsCog = this.node.querySelector('.toggle-settings-click-zone') as HTMLDivElement;
settingsCog?.focus();
}

protected override renderMemoryLocationGroup(): React.ReactNode {
const { titles: [beforeTitle, afterTitle] } = this.memoryWidgetOptions;
return (
<div className='t-mv-group view-group'>
<MWInput
id={LOCATION_OFFSET_FIELD_ID}
label={`${beforeTitle} Offset`}
title={`Bytes to offset the memory from ${beforeTitle}`}
defaultValue='0'
passRef={this.assignOffsetRef}
onChange={Utils.validateNumericalInputs}
onKeyDown={this.doRefresh}
/>
<MWInput
id={LENGTH_FIELD_ID}
label={`${afterTitle} Offset`}
title={`Bytes to offset the memory from ${afterTitle}`}
defaultValue='0'
passRef={this.assignReadLengthRef}
onChange={Utils.validateNumericalInputs}
onKeyDown={this.doRefresh}
/>
<button
type='button'
className='theia-button main view-group-go-button'
onClick={this.doRefresh}
>
Go
</button>
</div>
);
}

protected override getObligatoryColumnIds(): string[] {
return ['beforeAddress', 'beforeData', 'afterAddress', 'afterData'];
}

protected override doRefresh = (event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
if ('key' in event && KeyCode.createKeyCode(event.nativeEvent).key?.keyCode !== Key.ENTER.keyCode) {
return;
}
this.fireDidChangeOptions();
};

override storeState(): DiffMemoryOptions {
return {
...super.storeState(),
// prefix a 0. It'll do nothing if it's a number, but if it's an empty string or garbage, it'll make parseInt return 0.
beforeOffset: parseInt(`0${this.offsetField?.value ?? 0}`),
afterOffset: parseInt(`0${this.readLengthField?.value ?? 0}`),
};
}
}
Loading

0 comments on commit b6db786

Please sign in to comment.