Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ability to refresh memory view when stepping through code. plus removed some boilerplate code #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
"Other"
],
"activationEvents": [
"onCommand:memoryViewer.helloWorld",
"onView:memoryViewer.webview"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "memoryViewer.helloWorld",
"title": "Hello World"
}
],
"views": {
"debug": [
Expand Down
23 changes: 23 additions & 0 deletions src/MemoryViewerViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CancellationToken, Uri, Webview, WebviewView, WebviewViewProvider, Webv
import { getUri } from "./utilites/getUri";
import * as vscode from 'vscode';

let global_message: MemoryViewerReadMemoryRequest;
export class MemoryViewerViewProvider implements WebviewViewProvider {
public static readonly viewType = "memoryViewer.webview";

Expand Down Expand Up @@ -69,6 +70,7 @@ export class MemoryViewerViewProvider implements WebviewViewProvider {
case "readMemory":
const activeDebugSession = vscode.debug.activeDebugSession;
if (activeDebugSession !== undefined) {
global_message = message;
try {
activeDebugSession.customRequest("readMemory", {
memoryReference: message.address,
Expand All @@ -88,6 +90,27 @@ export class MemoryViewerViewProvider implements WebviewViewProvider {
break;
}
});
vscode.window.onDidChangeTextEditorSelection(e => {
const activeDebugSession = vscode.debug.activeDebugSession;
if (activeDebugSession !== undefined) {
try {
activeDebugSession.customRequest("readMemory", {
memoryReference: global_message.address,
// offset: global_message.offset,
count: global_message.bufferSize,
}).then((response: MemoryViewerReadMemoryResponse) => {
console.log("Got response onDidChangeTextEditorSelection ", response);
response.direction = global_message.offset >= 0 ? "POSITIVE" : "NEGATIVE";
webviewView.webview.postMessage(response);

});
} catch (e) {
console.error("THERE WAS AN ERROR",e);
}
} else {
// console.warn("Not is a valid debug session is running...");
}
});
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ export function activate(context: vscode.ExtensionContext) {

// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "memoryViewer" is now active!');

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('memoryViewer.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from Memory Viewer!');
});

const provider = new MemoryViewerViewProvider(context.extensionUri);

Expand All @@ -27,9 +21,8 @@ export function activate(context: vscode.ExtensionContext) {
MemoryViewerViewProvider.viewType,
provider
);

context.subscriptions.push(memoryViewDisposable);
context.subscriptions.push(disposable);
}

// this method is called when your extension is deactivated
Expand Down
2 changes: 1 addition & 1 deletion webview/src/MemoryViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function MemoryViewer() {
const [activePositiveOffset, setActivePositiveOffset] = createSignal(0);
const onMessageCallback = (message: any) => {
console.log("Message", message);
setBytes([]);
var binaryString = window.atob(message.data.data);
var len = binaryString.length;
var collectedBytes = new Array(len);
Expand Down Expand Up @@ -59,7 +60,6 @@ export default function MemoryViewer() {
<div class={styles.MemoryViewer}>
<MemoryViewerHeader
onRefresh={() => {
setBytes([]);
vscode.postMessage({
command: "readMemory",
address: address(),
Expand Down