1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-05-28 23:41:32 +00:00

class DebugSymbols to hold symbol info

This commit is contained in:
Steven Hugg 2018-09-17 16:09:09 -04:00
parent 51bf1226d0
commit 50ac618e86
5 changed files with 35 additions and 37 deletions

View File

@ -1,6 +1,6 @@
import { RAM, RasterVideo, dumpRAM, lookupSymbol } from "./emu";
import { hex, printFlags } from "./util";
import { hex, printFlags, invertMap } from "./util";
import { CodeAnalyzer } from "./analysis";
import { disassemble6502 } from "./cpu/disasm6502";
import { disassembleZ80 } from "./cpu/disasmz80";
@ -38,6 +38,21 @@ export type DisasmLine = {
isaddr:boolean
};
export type SymbolMap = {[ident:string]:number};
export type AddrSymbolMap = {[address:number]:string};
export class DebugSymbols {
symbolmap : SymbolMap; // symbol -> address
addr2symbol : AddrSymbolMap; // address -> symbol
constructor(symbolmap : SymbolMap) {
this.symbolmap = symbolmap;
this.addr2symbol = invertMap(symbolmap);
if (!this.addr2symbol[0x0]) this.addr2symbol[0x0] = '__START__'; // needed for ...
this.addr2symbol[0x10000] = '__END__'; // ... dump memory to work
}
}
export interface Platform {
start() : void;
reset() : void;
@ -80,6 +95,8 @@ export interface Platform {
setRecorder?(recorder : EmuRecorder) : void;
advance?(novideo? : boolean) : void;
debugSymbols? : DebugSymbols;
}
export interface Preset {
@ -107,6 +124,7 @@ export interface EmuRecorder {
export abstract class BasePlatform {
recorder : EmuRecorder = null;
debugSymbols : DebugSymbols;
abstract loadState(state : EmuState) : void;
abstract saveState() : EmuState;
@ -534,10 +552,11 @@ export abstract class BaseZ80Platform extends BaseDebugPlatform {
switch (category) {
case 'CPU': return cpuStateToLongString_Z80(state.c);
case 'Stack': {
var sp = state.c.SP-1;
var sp = (state.c.SP-1) & 0xffff;
var start = sp & 0xff00;
var end = start + 0xff;
if (sp == 0) sp = 0x10000;
console.log(sp,start,end);
return dumpStackToString(<Platform><any>this, [], start, end, sp, 0xcd);
}
}

View File

@ -5,7 +5,6 @@ import { PLATFORMS, RAM, newAddressDecoder, dumpRAM } from "../emu";
import { hex, lpad, tobin, byte2signed } from "../util";
import { CodeAnalyzer_vcs } from "../analysis";
import { disassemble6502 } from "../cpu/disasm6502";
import { platform, symbolmap, addr2symbol } from "../ui";
declare var Javatari : any;
declare var jt : any; // 6502
@ -259,22 +258,6 @@ class VCSPlatform extends BasePlatform {
disassemble(pc:number, read:(addr:number)=>number) : DisasmLine {
return disassemble6502(pc, read(pc), read(pc+1), read(pc+2));
}
inspect(ident : string) : string {
if (this.isRunning()) return; // only inspect when stopped
var result;
var addr = symbolmap && (symbolmap[ident]); // || symbolmap['_'+ident]);
if (addr >= 0x80 && addr < 0x100) { // in RAM?
var size=4;
result = "$" + hex(addr,4) + ":";
for (var i=0; i<size; i++) {
var byte = platform.readAddress(addr+i);
result += " $" + hex(byte,2) + " (" + byte + ")";
if (addr2symbol[addr+1]) break; // stop if we hit another symbol
else if (i==size-1) result += " ...";
}
}
return result;
}
};
// TODO: mixin for Base6502Platform?

View File

@ -7,7 +7,7 @@ import * as bootstrap from "bootstrap";
import { CodeProject } from "./project";
import { WorkerResult, SourceFile, WorkerError } from "./workertypes";
import { ProjectWindows } from "./windows";
import { Platform, Preset } from "./baseplatform";
import { Platform, Preset, DebugSymbols } from "./baseplatform";
import { PLATFORMS } from "./emu";
import * as Views from "./views";
import { createNewPersistentStore } from "./store";
@ -60,8 +60,6 @@ var current_preset_entry : Preset; // current preset object (if selected)
var main_file_id : string; // main file ID
var store; // persistent store
export var symbolmap; // symbol map
export var addr2symbol; // address to symbol name map
export var compparams; // received build params from worker
export var lastDebugState; // last debug state (object)
@ -497,10 +495,7 @@ function setCompileOutput(data: WorkerResult) {
showErrorAlert(data.errors);
} else {
// process symbol map
symbolmap = data.symbolmap;
addr2symbol = invertMap(symbolmap);
if (!addr2symbol[0x0]) addr2symbol[0x0] = '__START__'; // needed for ...
addr2symbol[0x10000] = '__END__'; // needed for dump memory to work
platform.debugSymbols = new DebugSymbols(data.symbolmap);
compparams = data.params;
// load ROM
var rom = data.output;
@ -692,11 +687,14 @@ function _breakExpression() {
}
function getSymbolAtAddress(a : number) {
if (addr2symbol[a]) return addr2symbol[a];
var i=0;
while (--a >= 0) {
i++;
if (addr2symbol[a]) return addr2symbol[a] + '+' + i;
var addr2symbol = platform.debugSymbols && platform.debugSymbols.addr2symbol;
if (addr2symbol) {
if (addr2symbol[a]) return addr2symbol[a];
var i=0;
while (--a >= 0) {
i++;
if (addr2symbol[a]) return addr2symbol[a] + '+' + i;
}
}
return '';
}

View File

@ -7,7 +7,7 @@ import { SourceFile, WorkerError } from "./workertypes";
import { Platform, EmuState } from "./baseplatform";
import { hex, lpad, rpad } from "./util";
import { CodeAnalyzer } from "./analysis";
import { platform, platform_id, compparams, symbolmap, addr2symbol, current_project, lastDebugState } from "./ui";
import { platform, platform_id, compparams, current_project, lastDebugState } from "./ui";
export interface ProjectView {
createDiv(parent:HTMLElement, text:string) : HTMLElement;
@ -429,6 +429,7 @@ export class DisassemblerView implements ProjectView {
var pc = state.c ? state.c.PC : 0;
var curline = 0;
var selline = 0;
var addr2symbol = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {};
// TODO: not perfect disassembler
var disassemble = (start, end) => {
if (start < 0) start = 0;
@ -652,10 +653,7 @@ export class MemoryView implements ProjectView {
// TODO: addr2symbol for ca65; and make it work without symbols
getDumpLines() {
var addr2sym = addr2symbol;
if (!addr2sym) addr2sym = {};
if (!addr2sym[0x0]) addr2sym[0x0] = '__START__';
addr2sym[0x10000] = '__END__';
var addr2sym = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {};
if (!this.dumplines) {
this.dumplines = [];
var ofs = 0;

View File

@ -175,7 +175,7 @@ describe('Worker', function() {
assert.ok(fn);
done(err, msg);
};
doBuild(msgs, done2, 2781, 0, 0);
doBuild(msgs, done2, 2764, 0, 0);
});
it('should NOT compile verilog example', function(done) {
var csource = "foobar";