Skip to content

Commit f46a821

Browse files
committed
fancier new memory output GUI, fix #158
1 parent f50962a commit f46a821

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/frontend/extension.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function examineMemory() {
7272
}
7373
const pickedFile = (file) => {
7474
vscode.window.showInputBox({ placeHolder: "Memory Location or Range", validateInput: range => getMemoryRange(range) === undefined ? "Range must either be in format 0xF00-0xF01, 0xF100+32 or 0xABC154" : "" }).then(range => {
75-
vscode.commands.executeCommand("vscode.previewHtml", vscode.Uri.parse("debugmemory://" + file + "#" + getMemoryRange(range)));
75+
vscode.window.showTextDocument(vscode.Uri.parse("debugmemory://" + file + "#" + getMemoryRange(range)));
7676
});
7777
};
7878
if (files.length == 1)
@@ -89,7 +89,7 @@ function examineMemory() {
8989
class MemoryContentProvider implements vscode.TextDocumentContentProvider {
9090
provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): Thenable<string> {
9191
return new Promise((resolve, reject) => {
92-
const conn = net.connect(path.join(os.tmpdir(), "code-debug-sockets", uri.authority));
92+
const conn = net.connect(path.join(os.tmpdir(), "code-debug-sockets", uri.authority.toLowerCase()));
9393
let from, to;
9494
let highlightAt = -1;
9595
const splits = uri.fragment.split("&");
@@ -110,24 +110,38 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
110110
return reject("Negative Range");
111111
conn.write("examineMemory " + JSON.stringify([from, to - from + 1]));
112112
conn.once("data", data => {
113-
let formattedCode = "";
113+
let formattedCode = " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n";
114+
var index: number = from;
114115
const hexString = data.toString();
115116
let x = 0;
116117
let asciiLine = "";
117118
let byteNo = 0;
118119
for (let i = 0; i < hexString.length; i += 2) {
120+
if (x == 0) {
121+
var addr = index.toString(16);
122+
while (addr.length < 16) addr = '0' + addr;
123+
formattedCode += addr + " ";
124+
}
125+
index++;
126+
119127
const digit = hexString.substr(i, 2);
120128
const digitNum = parseInt(digit, 16);
121129
if (digitNum >= 32 && digitNum <= 126)
122130
asciiLine += String.fromCharCode(digitNum);
123131
else
124132
asciiLine += ".";
133+
125134
if (highlightAt == byteNo) {
126-
formattedCode += "<b>" + digit + "</b> ";
127-
} else
135+
formattedCode = formattedCode.slice(0, -1) + "[" + digit + "]";
136+
} else {
128137
formattedCode += digit + " ";
129-
if (++x > 16) {
130-
formattedCode += asciiLine + "\n";
138+
}
139+
140+
if (x == 7)
141+
formattedCode += " ";
142+
143+
if (++x >= 16) {
144+
formattedCode += " " + asciiLine + "\n";
131145
x = 0;
132146
asciiLine = "";
133147
}
@@ -137,11 +151,25 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
137151
for (let i = 0; i <= 16 - x; i++) {
138152
formattedCode += " ";
139153
}
154+
if (x >= 8)
155+
formattedCode = formattedCode.slice(0, -2);
156+
else
157+
formattedCode = formattedCode.slice(0, -1);
140158
formattedCode += asciiLine;
141159
}
142-
resolve("<h2>Memory Range from 0x" + from.toString(16) + " to 0x" + to.toString(16) + "</h2><code><pre>" + formattedCode + "</pre></code>");
160+
resolve(center("Memory Range from 0x" + from.toString(16) + " to 0x" + to.toString(16), 84) + "\n\n" + formattedCode);
143161
conn.destroy();
144162
});
145163
});
146164
}
147165
}
166+
167+
function center(str: string, width: number): string {
168+
var left = true;
169+
while (str.length < width) {
170+
if (left) str = ' ' + str;
171+
else str = str + ' ';
172+
left = !left;
173+
}
174+
return str;
175+
}

src/mibase.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class MI2DebugSession extends DebugSession {
3737
protected debugReady: boolean;
3838
protected miDebugger: MI2;
3939
protected commandServer: net.Server;
40+
protected serverPath: string;
4041

4142
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
4243
super(debuggerLinesStartAt1, isServer);
@@ -77,7 +78,7 @@ export class MI2DebugSession extends DebugSession {
7778
});
7879
if (!fs.existsSync(systemPath.join(os.tmpdir(), "code-debug-sockets")))
7980
fs.mkdirSync(systemPath.join(os.tmpdir(), "code-debug-sockets"));
80-
this.commandServer.listen(systemPath.join(os.tmpdir(), "code-debug-sockets", "Debug-Instance-" + Math.floor(Math.random() * 36 * 36 * 36 * 36).toString(36)));
81+
this.commandServer.listen(this.serverPath = systemPath.join(os.tmpdir(), "code-debug-sockets", ("Debug-Instance-" + Math.floor(Math.random() * 36 * 36 * 36 * 36).toString(36)).toLowerCase()));
8182
} catch (e) {
8283
if (process.platform != "win32")
8384
this.handleMsg("stderr", "Code-Debug WARNING: Utility Command Server: Failed to start " + e.toString() + "\nCode-Debug WARNING: The examine memory location command won't work");
@@ -148,6 +149,11 @@ export class MI2DebugSession extends DebugSession {
148149
protected quitEvent() {
149150
this.quit = true;
150151
this.sendEvent(new TerminatedEvent());
152+
153+
if (this.serverPath)
154+
fs.unlink(this.serverPath, (err) => {
155+
console.error("Failed to unlink debug server");
156+
});
151157
}
152158

153159
protected launchError(err: any) {

0 commit comments

Comments
 (0)