Skip to content

Commit

Permalink
Improve memory viewer and search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazwh0 committed Apr 20, 2024
1 parent 60f1beb commit 3e53eaa
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Bitmagic.VscExtension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bitmagic",
"displayName": "BitMagic X16 Debugger",
"description": "BitMagic X16 Debugger and Development Solution",
"version": "0.1.22",
"version": "0.1.23",
"preview": false,
"publisher": "yazwh0",
"icon": "package/butterfly.png",
Expand Down
3 changes: 2 additions & 1 deletion Bitmagic.VscExtension/src/layerView/layerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class LayerView {
'Layer View',
columnToShowIn || ViewColumn.One,
{
enableScripts: true
enableScripts: true,
retainContextWhenHidden: true
}
);

Expand Down
11 changes: 11 additions & 0 deletions Bitmagic.VscExtension/src/memoryView/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class messages
{
public static search = "search";
public static resetSearch = "resetSearch";
public static updateRows = "updateRows";
public static updateMemoryDisplay = "memoryUpdate";
public static displaySearchResults = "memoryValueLocations";

public static debuggerSearch = "getMemoryValueLocations"; // DEBUGGER
public static getMemoryUse = "getMemoryUse"; // DEBUGGER
}
26 changes: 26 additions & 0 deletions Bitmagic.VscExtension/src/memoryView/memoryView.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,29 @@ div.control_holder
{
margin: 0 5px;
}

#search_results
{
min-width: 200px;
min-height: 200px;
}

div.search_control_box
{
margin-top: 10px;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
align-items: flex-end;
}

.search_control
{
margin-right:10px;
}

.search_results_container
{
width: auto;
}
80 changes: 74 additions & 6 deletions Bitmagic.VscExtension/src/memoryView/memoryView.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Disposable, Webview, WebviewPanel, window, Uri, ViewColumn, ExtensionContext, commands, debug } from "vscode";
import { Disposable, Webview, WebviewPanel, window, Uri, ViewColumn, ExtensionContext, commands, debug, WebviewPanelOnDidChangeViewStateEvent } from "vscode";
import { getUri } from "../utilities/getUri";
import { getNonce } from "../utilities/getNonce";
import { Dictionary } from "../utilities/dictionary";
import { messages } from "./common";

export class MemoryView {

public static currentPanel: MemoryView | undefined;
private _lastSearchResult: MemoryValueTrackerResponse | undefined; // store this here as the webview can be recycled

public static activate(context: ExtensionContext) {

Expand All @@ -25,7 +28,8 @@ export class MemoryView {
'Memory View',
columnToShowIn || ViewColumn.One,
{
enableScripts: true
enableScripts: true,
retainContextWhenHidden: true
}
);

Expand All @@ -50,6 +54,7 @@ export class MemoryView {

private dispose() {
MemoryView.currentPanel = undefined;
this._lastSearchResult = undefined;

this._panel.dispose();

Expand All @@ -67,9 +72,17 @@ export class MemoryView {
const command = message.command;

switch (command) {
case "getMemoryUse":
case messages.getMemoryUse:
this._updateMemoryUse(webview);
return;
case messages.search:
this._search(webview, message.toFind, message.searchType, message.searchWidth);
return;
case messages.resetSearch:
if (this._lastSearchResult) {
this._lastSearchResult.Locations = [];
}
return;
}
},
undefined,
Expand All @@ -78,11 +91,30 @@ export class MemoryView {
}

private _updateMemoryUse(webview: Webview) {
debug.activeDebugSession?.customRequest("getMemoryUse").then(i => {
webview.postMessage({ command: "memoryUpdate", payload: JSON.stringify(i) });
debug.activeDebugSession?.customRequest(messages.getMemoryUse).then(i => {
webview.postMessage({ command: messages.updateMemoryDisplay, payload: JSON.stringify(i) });
});
}

private _search(webview: Webview, toFind: number, searchType: string, searchWidth: string) {
let current: memoryValue[] = [];
if (this._lastSearchResult) {
if (this._lastSearchResult.Locations) {
current = this._lastSearchResult.Locations;
}
}

debug.activeDebugSession?.customRequest(messages.debuggerSearch,
{ SearchWidth: searchWidth, ToFind: toFind, SearchType: searchType, Locations: current }
).then(i => {
this._lastSearchResult = i;
webview.postMessage({
command: messages.displaySearchResults, payload:
JSON.stringify(i)
});
});
}

private _getWebviewContent(webview: Webview, extensionUri: Uri) {
const webviewUri = getUri(webview, extensionUri, ["out", "memoryView.webview.js"]);
const nonce = getNonce();
Expand Down Expand Up @@ -114,8 +146,44 @@ export class MemoryView {
</div>
</div>
</div>
<div class="memory_value_tracker">
<div class="search_control_box">
<vscode-dropdown id="search_width" class="search_control" >
<vscode-option>Byte</vscode-option>
<vscode-option>Word</vscode-option>
</vscode-dropdown>
<vscode-text-field id="value_to_find" class="search_control" placeholder="Start with $ or 0x for hex"">Value To Find</vscode-text-field>
<vscode-dropdown disabled id="search_type" class="search_control" >
<vscode-option>Equal</vscode-option>
<vscode-option>Not Equal</vscode-option>
<vscode-option>Less Than</vscode-option>
<vscode-option>Greater Than</vscode-option>
<vscode-option>Changed</vscode-option>
<vscode-option>Not Changed</vscode-option>
<vscode-option>Gone Up</vscode-option>
<vscode-option>Gone Down</vscode-option>
</vscode-dropdown>
<vscode-button id="search" class="search_control" >Search</vscode-button>
<vscode-button id="reset_search" class="search_control" >Reset</vscode-button>
</div>
<div class="search_results_container display_control">
<vscode-data-grid id="search_results"></vscode-data-grid>
</div>
</div>
<script type="module" nonce="${nonce}" src="${webviewUri}"></script>
</body>
</html>`;
}
}

class MemoryValueTrackerResponse {
ToFind: number | undefined;
Locations: memoryValue[] | undefined;
Stepping: boolean | undefined;
}

class memoryValue {
Location: number = 0;
Value: number = 0;
}

Loading

0 comments on commit 3e53eaa

Please sign in to comment.