Skip to content

Commit

Permalink
Fixed #65: Uncaught errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
maziac committed Aug 18, 2021
1 parent ea4b061 commit ce00891
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

# 2.3.1
- Fixed #65: Uncaught errors.

# 2.3.0
- Added "-addexpr/delexpr" command to add/remove expressions (variables/labels) to the VARIABLEs pane.
- Added "-mvw" to display a memory viewer that display the memory organized in words instead of bytes.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 49 additions & 49 deletions src/decoration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { Labels, SourceFileEntry } from './labels/labels';
import {Labels, SourceFileEntry} from './labels/labels';
//import {Log} from './log';
//import { Settings } from './settings';
import {Disassembly, DisassemblyClass} from './misc/disassembly';
Expand All @@ -20,7 +20,7 @@ class DecorationFileMap {
public decoType: vscode.TextEditorDecorationType;

/// Holds a map with filenames associated with the lines.
public fileMap: Map<string, Array<vscode.Range>|Array<vscode.DecorationOptions>>;
public fileMap: Map<string, Array<vscode.Range> | Array<vscode.DecorationOptions>>;
}


Expand Down Expand Up @@ -108,14 +108,14 @@ export class DecorationClass {
gutterIconSize: 'auto',
light: {
// this color will be used in light color themes
// backgroundColor: '#89C2D3',
// backgroundColor: '#89C2D3',
after: {
color: "#808080",
}
},
dark: {
// this color will be used in dark color themes
// backgroundColor: '#022031',
// backgroundColor: '#022031',
after: {
color: "#808080",
}
Expand Down Expand Up @@ -185,7 +185,7 @@ export class DecorationClass {
decoFileMap.fileMap = new Map<string, Array<vscode.DecorationOptions>>();
this.decorationFileMaps.set(this.HISTORY_SPOT, decoFileMap);

this.unassignedCodeCoverageAddresses=new Set<number>();
this.unassignedCodeCoverageAddresses = new Set<number>();

// Watch the text editors to decorate them.
vscode.window.onDidChangeActiveTextEditor(editor => {
Expand Down Expand Up @@ -235,14 +235,14 @@ export class DecorationClass {
* @param mapName E.g. COVERAGE, REVERSE_DEBUG, SHORT_HISTORY or BREAK.
*/
protected clearDecorations(mapName: string) {
const map=this.decorationFileMaps.get(mapName) as DecorationFileMap;
const map = this.decorationFileMaps.get(mapName) as DecorationFileMap;
map.fileMap.clear();
const editors=vscode.window.visibleTextEditors;
const editors = vscode.window.visibleTextEditors;
for (const editor of editors) {
editor.setDecorations(map.decoType, []);
}
// Additionally clear array
if (mapName==this.COVERAGE)
if (mapName == this.COVERAGE)
this.unassignedCodeCoverageAddresses.clear();
}

Expand All @@ -253,7 +253,7 @@ export class DecorationClass {
public clearAllDecorations() {
for (const [, map] of this.decorationFileMaps) {
map.fileMap.clear();
const editors=vscode.window.visibleTextEditors;
const editors = vscode.window.visibleTextEditors;
for (const editor of editors) {
editor.setDecorations(map.decoType, []);
}
Expand All @@ -268,9 +268,9 @@ export class DecorationClass {
*/
public clearAllButCodeCoverageDecorations() {
for (const [name, map] of this.decorationFileMaps) {
if (name!=this.COVERAGE) {
if (name != this.COVERAGE) {
map.fileMap.clear();
const editors=vscode.window.visibleTextEditors;
const editors = vscode.window.visibleTextEditors;
for (const editor of editors) {
editor.setDecorations(map.decoType, []);
}
Expand All @@ -283,8 +283,8 @@ export class DecorationClass {
* Sets decorations for all types.
* Coverage, revers debug, breaks, short history.
*/
protected setAllDecorations(editor: vscode.TextEditor|undefined) {
if(!editor)
protected setAllDecorations(editor: vscode.TextEditor | undefined) {
if (!editor)
return;

// Go through all coverage maps
Expand All @@ -301,11 +301,11 @@ export class DecorationClass {
*/
protected setDecorations(editor: vscode.TextEditor, fileMapName: string) {
// Get filename
const edFilename=editor.document.fileName;
const edFilename = editor.document.fileName;

// Special case for disassembly file and coverage.
if (fileMapName==this.COVERAGE) {
if (edFilename==DisassemblyClass.getAbsFilePath()) {
if (fileMapName == this.COVERAGE) {
if (edFilename == DisassemblyClass.getAbsFilePath()) {
// Handle disassembly file
this.setDisasmCoverageDecoration(editor);
return; // Skip normal case
Expand All @@ -318,8 +318,8 @@ export class DecorationClass {

// Get lines
const fileMap = decoMap.fileMap;
const decorations=fileMap.get(edFilename);
if(decorations) {
const decorations = fileMap.get(edFilename);
if (decorations) {
// Set decorations
editor.setDecorations(decoMap.decoType, decorations);
}
Expand All @@ -331,11 +331,11 @@ export class DecorationClass {
*/
public setDisasmCoverageDecoration(editor: vscode.TextEditor) {
// Coverage
const lines=Disassembly.getLinesForAddresses(this.unassignedCodeCoverageAddresses);
const decorations=lines.map(lineNr => new vscode.Range(lineNr, 0, lineNr, 1000));
const lines = Disassembly.getLinesForAddresses(this.unassignedCodeCoverageAddresses);
const decorations = lines.map(lineNr => new vscode.Range(lineNr, 0, lineNr, 1000));
if (decorations) {
// Set decorations
const decoMap=this.decorationFileMaps.get(this.COVERAGE) as DecorationFileMap;
const decoMap = this.decorationFileMaps.get(this.COVERAGE) as DecorationFileMap;
editor.setDecorations(decoMap.decoType, decorations);
}
}
Expand All @@ -357,23 +357,23 @@ export class DecorationClass {
//fileMap.clear();
coveredAddresses.forEach(addr => {
// Get file location for address
let location=Labels.getFileAndLineForAddress(addr);
let location = Labels.getFileAndLineForAddress(addr);
let filename = location.fileName;
if (filename.length==0) {
if (filename.length == 0) {
// No file found, so remember address
this.unassignedCodeCoverageAddresses.add(addr);
return;
}
// Get filename set
let lines = fileMap.get(filename) as Array<vscode.Range>;
if(!lines) {
if (!lines) {
// Create a new
lines = new Array<vscode.Range>();
fileMap.set(filename, lines);
}
const lineNr=location.lineNr;
const lineNr = location.lineNr;
// REMARK: Could be optimized. Here it is possible that coverage for that line already exists and would then be added 2 or more times.
const range = new vscode.Range(lineNr,0, lineNr,1000);
const range = new vscode.Range(lineNr, 0, lineNr, 1000);
// Add address to set
lines.push(range);
});
Expand Down Expand Up @@ -404,25 +404,25 @@ export class DecorationClass {
// Get file location for address
const location = this.getFileAndLineForAddress(addr);
const filename = location.fileName;
if(filename.length == 0)
if (filename.length == 0)
return;
// Get filename set
let lines = fileMap.get(filename) as Array<vscode.Range>;
if(!lines) {
if (!lines) {
// Create a new
lines = new Array<vscode.Range>();
fileMap.set(filename, lines);
}
// Add address to set
const lineNr = location.lineNr;
const range = new vscode.Range(lineNr,0, lineNr,1000);
const range = new vscode.Range(lineNr, 0, lineNr, 1000);
// Add address to set
lines.push(range);
});

// Loop through all open editors.
const editors = vscode.window.visibleTextEditors;
for(const editor of editors) {
for (const editor of editors) {
this.setDecorations(editor, this.REVERSE_DEBUG);
}
}
Expand All @@ -444,23 +444,23 @@ export class DecorationClass {
// Get file location for pc
const location = this.getFileAndLineForAddress(pc);
const filename = location.fileName;
if(filename.length > 0) {
if (filename.length > 0) {
// Get filename set
let lines = fileMap.get(filename) as Array<vscode.DecorationOptions>;
if(!lines) {
if (!lines) {
// Create a new
lines = new Array<vscode.DecorationOptions>();
fileMap.set(filename, lines);
}
const lineNr = location.lineNr;
const deco = {
range: new vscode.Range(lineNr,0, lineNr,1000),
range: new vscode.Range(lineNr, 0, lineNr, 1000),
hoverMessage: undefined,
renderOptions: {
after: {
contentText: text,
margin: "1.5em"
},
after: {
contentText: text,
margin: "1.5em"
},
},
};

Expand All @@ -470,7 +470,7 @@ export class DecorationClass {

// Loop through all open editors.
const editors = vscode.window.visibleTextEditors;
for(const editor of editors) {
for (const editor of editors) {
this.setDecorations(editor, this.BREAK);
}
}
Expand Down Expand Up @@ -517,16 +517,16 @@ export class DecorationClass {
});

// Loop over all addresses
for(const [locString, entry] of addressMap) {
for (const [locString, entry] of addressMap) {
// Get file location for address
//const location = Labels.getFileAndLineForAddress(addr);
const k = locString.indexOf(';');
const filename = locString.substr(k+1);
if(filename.length == 0)
const filename = locString.substr(k + 1);
if (filename.length == 0)
break;
// Get filename set
let lines = fileMap.get(filename) as Array<vscode.DecorationOptions>;
if(!lines) {
if (!lines) {
// Create a new
lines = new Array<vscode.DecorationOptions>();
fileMap.set(filename, lines);
Expand Down Expand Up @@ -563,7 +563,7 @@ export class DecorationClass {

// Loop through all open editors.
const editors = vscode.window.visibleTextEditors;
for(const editor of editors) {
for (const editor of editors) {
this.setDecorations(editor, this.HISTORY_SPOT);
}
}
Expand All @@ -574,14 +574,14 @@ export class DecorationClass {
* @param addr The address to convert.
*/
protected getFileAndLineForAddress(addr: number): SourceFileEntry {
const location=Labels.getFileAndLineForAddress(addr);
if (location.fileName.length==0) {
const location = Labels.getFileAndLineForAddress(addr);
if (location.fileName.length == 0) {
// Try disasm file
const lineNr=Disassembly.getLineForAddress(addr);
if (lineNr!=undefined) {
const lineNr = Disassembly.getLineForAddress(addr);
if (lineNr != undefined) {
// Use disassembly file
location.fileName=DisassemblyClass.getAbsFilePath();
location.lineNr=lineNr;
location.fileName = DisassemblyClass.getAbsFilePath();
location.lineNr = lineNr;
}
}
return location;
Expand Down
3 changes: 3 additions & 0 deletions src/misc/disassembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ export class DisassemblyClass extends Disassembler {
/**
* Returns the file path of the temporary disassembly file.
* @returns The relative file path, e.g. ".tmp/disasm.asm".
* Or undefined if Settings.launch not yet created.
*/
public static getAbsFilePath(): string {
if (!Settings.launch)
return undefined as any;
const relPath=Utility.getRelTmpFilePath(TmpDasmFileName);
const absPath=Utility.getAbsFilePath(relPath);
return absPath;
Expand Down

0 comments on commit ce00891

Please sign in to comment.