Skip to content

Commit 8ea6fd7

Browse files
Fix: Cleanup Visualizer
* Added args to Run Current File * Protection for host/port and cut off stack/heap * Updated configurations * Removing program from attach * Updating visualizer bugs Co-authored-by: Joshua Mitchener <jmitchen@uci.edu>
1 parent 03f8ec4 commit 8ea6fd7

File tree

5 files changed

+72
-27
lines changed

5 files changed

+72
-27
lines changed

package.json

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
"configurationAttributes": {
125125
"launch": {
126126
"required": [
127+
"host",
128+
"port",
127129
"program"
128130
],
129131
"properties": {
@@ -140,12 +142,12 @@
140142
"cwd": {
141143
"type": "string",
142144
"description": "Path to terminal",
143-
"default": "${workspaceFolder}"
145+
"default": "^\"\\${workspaceFolder}\""
144146
},
145147
"program": {
146148
"type": "string",
147149
"description": "Path to mips file with main label",
148-
"default": "${file}"
150+
"default": "^\"\\${file}\""
149151
},
150152
"registerFormat": {
151153
"enum": [
@@ -234,17 +236,19 @@
234236
"type": "dashmips",
235237
"request": "launch",
236238
"name": "Dashmips (Run Current File)",
237-
"program": "${file}",
239+
"program": "^\"\\${file}\"",
238240
"registerFormat": "dec",
239-
"cwd": "${workspaceFolder}",
241+
"host": "localhost",
242+
"port": 2390,
243+
"cwd": "^\"\\${workspaceFolder}\"",
240244
"dashmipsCommand": "python -m dashmips debug",
241245
"dashmipsArgs": [
242246
"-i",
243247
"localhost",
244248
"-p",
245-
"2390",
246-
"-l"
249+
"2390"
247250
],
251+
"args": [],
248252
"stopOnEntry": false
249253
},
250254
{
@@ -259,22 +263,38 @@
259263
],
260264
"configurationSnippets": [
261265
{
262-
"label": "Dashmips Debug: Launch",
263-
"description": "A new configuration for 'debugging' a user selected mips file.",
266+
"label": "Dashmips (Run Current File)",
267+
"description": "Run the current MIPS file.",
264268
"body": {
265269
"type": "dashmips",
266270
"request": "launch",
267-
"name": "dashmips (Run Current File)",
271+
"name": "Dashmips (Run Current File)",
268272
"program": "^\"\\${file}\"",
269273
"registerFormat": "dec",
274+
"cwd": "^\"\\${workspaceFolder}\"",
275+
"host": "localhost",
276+
"port": 2390,
270277
"dashmipsCommand": "python -m dashmips debug",
271278
"dashmipsArgs": [
272-
"-l",
273279
"-i",
274280
"localhost",
275281
"-p",
276282
"2390"
277-
]
283+
],
284+
"args": [],
285+
"stopOnEntry": false
286+
}
287+
},
288+
{"label": "Dashmips (Attach)",
289+
"description": "Attach to a debugging session of a MIPS file.",
290+
"body": {
291+
"type": "dashmips",
292+
"request": "attach",
293+
"name": "Dashmips (Attach)",
294+
"registerFormat": "dec",
295+
"host": "localhost",
296+
"port": 2390,
297+
"stopOnEntry": false
278298
}
279299
}
280300
]

src/dashmips.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ type BuildTermParams = [
133133
export function buildTerminalLaunchRequestParams(launchArgs: any): BuildTermParams {
134134
// This will never reject, since vscode is weird with long running processes
135135
// We will detect failure to launch when we are unable to connect to ws
136-
const args = [...launchArgs.dashmipsCommand.split(' '), ...launchArgs.dashmipsArgs, launchArgs.program]
136+
const args = [...launchArgs.dashmipsCommand.split(' '), ...launchArgs.dashmipsArgs, launchArgs.program, ...launchArgs.args]
137137
if (launchArgs.args && launchArgs.args.length > 0) {
138138
// Mips arguments
139139
args.push('-a', ...launchArgs.args)

src/debug.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class DashmipsDebugSession extends LoggingDebugSession {
6262
private client: DashmipsDebugClient
6363
private config?: LaunchRequestArguments | AttachRequestArguments | any
6464
public memoryProvider?: any
65+
public program_path: string = ''
6566

6667
private set loggingEnabled(value: boolean) {
6768
logger.setup(value ? Logger.LogLevel.Verbose : Logger.LogLevel.Stop, true)
@@ -96,7 +97,7 @@ export class DashmipsDebugSession extends LoggingDebugSession {
9697
if (
9798
vscode.workspace.textDocuments[i].uri.scheme == 'visual' &&
9899
vscode.workspace.textDocuments[i].uri.authority.split(pattern).join('/') ==
99-
vscode.window.activeTextEditor?.document.uri.path.toLowerCase()
100+
this.program_path
100101
) {
101102
update_files += vscode.workspace.textDocuments[i].uri.path
102103
}
@@ -108,11 +109,12 @@ export class DashmipsDebugSession extends LoggingDebugSession {
108109
if (
109110
vscode.workspace.textDocuments[i].uri.scheme == 'visual' &&
110111
vscode.workspace.textDocuments[i].uri.authority.split(pattern).join('/') ==
111-
vscode.window.activeTextEditor?.document.uri.path.toLowerCase()
112+
this.program_path
112113
) {
113114
await this.memoryProvider.onDidChangeEmitter.fire(vscode.workspace.textDocuments[i].uri)
114115
}
115116
}
117+
this.memoryProvider.text = null // <-- This acts as a check if the debug session is active
116118
})
117119
}
118120

@@ -141,6 +143,11 @@ export class DashmipsDebugSession extends LoggingDebugSession {
141143

142144
protected async launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments) {
143145
this.config = args
146+
if (!args.host || !args.port) {
147+
vscode.window.showErrorMessage("Please include host and/or port in launch.json.")
148+
this.sendEvent(new TerminatedEvent())
149+
return
150+
}
144151
this.runInTerminalRequest(...buildTerminalLaunchRequestParams(args))
145152

146153
this.client.connect(args.host, args.port)
@@ -155,8 +162,10 @@ export class DashmipsDebugSession extends LoggingDebugSession {
155162
this.client.dashmipsPid = pid.pid
156163
if (this.config.stopOnEntry) {
157164
this.sendEvent(new StoppedEvent('entry', THREAD_ID))
165+
this.visualize()
158166
} else if (this.breakpoints.length && this.client.stopEntry) {
159167
this.sendEvent(new StoppedEvent('breakpoint', THREAD_ID))
168+
this.visualize()
160169
} else {
161170
this.client.call('continue', this.breakpoints)
162171
}
@@ -178,8 +187,10 @@ export class DashmipsDebugSession extends LoggingDebugSession {
178187
this.client.dashmipsPid = pid.pid
179188
if (this.config.stopOnEntry) {
180189
this.sendEvent(new StoppedEvent('entry', THREAD_ID))
190+
this.visualize()
181191
} else if (this.breakpoints.length && this.client.stopEntry) {
182192
this.sendEvent(new StoppedEvent('breakpoint', THREAD_ID))
193+
this.visualize()
183194
} else {
184195
this.client.call('continue', this.breakpoints)
185196
}
@@ -200,6 +211,10 @@ export class DashmipsDebugSession extends LoggingDebugSession {
200211
return this.sendResponse(response)
201212
}
202213

214+
if (!this.program_path) {
215+
this.program_path = this.convertDebuggerPathToClient(args.source.path!).toLowerCase()
216+
}
217+
203218
this.breakpoints = args.breakpoints.map((bp, idx) => {
204219
const path = this.convertDebuggerPathToClient(args.source.path!)
205220
return {
@@ -337,11 +352,11 @@ export class DashmipsDebugSession extends LoggingDebugSession {
337352
break
338353
}
339354
case VARIABLE_REF.MEMORY_STACK: {
340-
variables.push(...program.memory.stack.split('\n').map(makeMemoryRowIntoVariable))
355+
variables.push(...program.memory.stack.split('\n').slice(0, Math.floor((100663296 - program.registers["lowest_stack"]) / 4) + 1).map(makeMemoryRowIntoVariable))
341356
break
342357
}
343358
case VARIABLE_REF.MEMORY_HEAP: {
344-
variables.push(...program.memory.heap.split('\n').map(makeMemoryRowIntoVariable))
359+
variables.push(...program.memory.heap.split('\n').slice(0, Math.floor((program.registers["end_heap"] - 6291456) / 4)).map(makeMemoryRowIntoVariable))
345360
break
346361
}
347362
case VARIABLE_REF.MEMORY_DATA: {

src/extension.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ async function activateUnsafe(context: vscode.ExtensionContext) {
5252
registerCommands()
5353

5454
vscode.workspace.onDidSaveTextDocument((e: vscode.TextDocument) => {
55-
for (let i = 0; i < vscode.workspace.textDocuments.length; i++) {
56-
if (
57-
vscode.workspace.textDocuments[i].uri.scheme == 'visual' &&
58-
vscode.workspace.textDocuments[i].uri.authority.split(pattern).join(path.sep) == e.uri.path.toLowerCase()
59-
) {
60-
const documentUriToUpdate = vscode.workspace.textDocuments[i].uri
61-
memoryProvider.onDidChangeEmitter.fire(documentUriToUpdate)
55+
if (!vscode.debug.activeDebugSession) {
56+
for (let i = 0; i < vscode.workspace.textDocuments.length; i++) {
57+
if (
58+
vscode.workspace.textDocuments[i].uri.scheme == 'visual' &&
59+
vscode.workspace.textDocuments[i].uri.authority.split(pattern).join(path.sep) == e.uri.path.toLowerCase()
60+
) {
61+
const documentUriToUpdate = vscode.workspace.textDocuments[i].uri
62+
memoryProvider.onDidChangeEmitter.fire(documentUriToUpdate)
63+
}
6264
}
6365
}
6466
})

src/memory_content.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class MemoryContentProvider implements vscode.TextDocumentContentProvider
2121
return text.split(s + ' ')[i]
2222
}
2323
}
24-
if (vscode.debug.activeDebugSession && this.text) {
24+
if (this.text) {
2525
if (uri.path.includes('Stack: Ascii')) {
2626
return check(this.text, 0)
2727
} else if (uri.path.includes('Stack: Int')) {
@@ -42,10 +42,18 @@ export class MemoryContentProvider implements vscode.TextDocumentContentProvider
4242
return check(this.text, 8)
4343
}
4444
} else {
45+
var filename
46+
for (let i = 0; i < vscode.workspace.textDocuments.length; i++) {
47+
if (vscode.workspace.textDocuments[i].fileName.toLowerCase() == uri.authority.split(pattern).join(path.sep))
48+
{ // The uri filename is automatically lowercased, so this code recovers the normal version
49+
filename = vscode.workspace.textDocuments[i].fileName
50+
break
51+
}
52+
}
4553
if (uri.path.includes('Stack')) {
4654
let command =
4755
'python -m dashmips v ' +
48-
uri.authority.split(pattern).join(path.sep)
56+
filename
4957
if (uri.path.includes('Int')) {
5058
command += ' --si'
5159
} else if (uri.path.includes('Float')) {
@@ -59,7 +67,7 @@ export class MemoryContentProvider implements vscode.TextDocumentContentProvider
5967
} else if (uri.path.includes('Heap')) {
6068
let command =
6169
'python -m dashmips v ' +
62-
uri.authority.split(pattern).join(path.sep)
70+
filename
6371
if (uri.path.includes('Int')) {
6472
command += ' --hi'
6573
} else if (uri.path.includes('Float')) {
@@ -73,7 +81,7 @@ export class MemoryContentProvider implements vscode.TextDocumentContentProvider
7381
} else if (uri.path.includes('Data')) {
7482
let command =
7583
'python -m dashmips v ' +
76-
uri.authority.split(pattern).join(path.sep)
84+
filename
7785
if (uri.path.includes('Int')) {
7886
command += ' --di'
7987
} else if (uri.path.includes('Float')) {

0 commit comments

Comments
 (0)