Skip to content

Commit

Permalink
ZEsarUX: automatic loading enabled again.
Browse files Browse the repository at this point in the history
  • Loading branch information
maziac committed Mar 23, 2020
1 parent ad7749b commit b0bfa13
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 101 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

# 0.13.4
- Fix: Internal simulator: Write watchpoint was indicated as read watchpoint.
- Fix: Internal simulator: corrected "LD (IX/IY+d),n".
- Internal simulator
- Fix: Write-watchpoint was indicated as read-watchpoint.
- Fix: corrected "LD (IX/IY+d),n".
- Performance improvement
- ZEsarUX: automatic loading enabled again. But added launch.json parameters to wait before and after loading ("debug_wait_before" and "debug_wait_after" in ms).
- Visual update corrected after MovePcToCursor.

# 0.13.3
- PC jumps to correct location after state restore.
Expand Down
5 changes: 2 additions & 3 deletions src/debugadapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2229,9 +2229,8 @@ Notes:
// Now change Program Counter
Remote.setProgramCounter(addr)
.then(() => {
// line is not updated. See https://github.com/Microsoft/vscode/issues/51716
//this.sendEvent(new StoppedEvent('PC-change', EmulDebugAdapter.THREAD_ID));
this.sendEventContinued();
Remote.clearCallStack();
//this.sendEventContinued();
this.sendEvent(new StoppedEvent('PC-change', DebugSessionClass.THREAD_ID));
// Handle decorations
StepHistory?.emitHistory();
Expand Down
60 changes: 30 additions & 30 deletions src/remotes/cpuhistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class CpuHistoryClass extends StepHistoryClass{
/// The virtual stack used during reverse debugging.
protected reverseDbgStack: RefList<CallStackFrame>;

// Mirror of the settings historySpotCount.
protected spotCount: number;

/**
* Sets the static CpuHistory singleton.
Expand All @@ -81,6 +83,7 @@ export class CpuHistoryClass extends StepHistoryClass{
*/
public init() {
super.init();
this.spotCount=Settings.launch.history.spotCount;
}


Expand All @@ -89,12 +92,10 @@ export class CpuHistoryClass extends StepHistoryClass{
*/
public clear() {
(async () => {
const release=await this.historyMutex.acquire();
this.history.length=0;
this.historyIndex=-1;
this.revDbgHistory.length=0;
this.reverseDbgStack=undefined as any;
release();
})();
}

Expand All @@ -106,7 +107,9 @@ export class CpuHistoryClass extends StepHistoryClass{
* @param index The index to retrieve. Starts at 0.
* @returns A string with the registers.
*/
// TODO: Maybe change to use index AND length to obtain several items at once.
protected async getRemoteHistoryIndex(index: number): Promise<HistoryInstructionInfo|undefined> {
assert(false);
return undefined;
}

Expand All @@ -127,27 +130,14 @@ export class CpuHistoryClass extends StepHistoryClass{
*/
protected async emitHistorySpot(): Promise<void> {
// Check if history spot is enabled
const count=Settings.launch.history.spotCount;
const count=this.spotCount;
if (count<=0)
return;

// Otherwise calculate addresses.

// Make sure that this.history is not changed in between
const release=await this.historyMutex.acquire();

// Check how many history entries need to be retrieved from the remote.
let index=this.getHistoryIndex()+1;
let endHistory=index+count;
while (endHistory>this.history.length) {
if (this.history.length>this.maxSize)
break;
// Retrieve items
const line=await this.getRemoteHistoryIndex(this.history.length);
if (!line)
break;
this.history.push(line);
}

// Get start index
let startIndex=index-count;
Expand All @@ -164,8 +154,6 @@ export class CpuHistoryClass extends StepHistoryClass{
addresses.push(pc);
}

release();

// Emit code coverage event
this.emit('historySpot', startIndex, addresses);
}
Expand All @@ -174,21 +162,33 @@ export class CpuHistoryClass extends StepHistoryClass{
/**
* Retrieves the registers at the previous instruction from the Remote's cpu history.
* Is async.
* @returns A string with the registers or undefined if at the end of the history.
* @returns Data with the registers or undefined if at the end of the history.
*/
public async getPrevRegistersAsync(): Promise<HistoryInstructionInfo|undefined> {
const release=await this.historyMutex.acquire();
let currentLine= await super.getPrevRegistersAsync();
if(!currentLine)
{
const index = this.historyIndex + 1;
currentLine = await this.getRemoteHistoryIndex(index);
if(currentLine) {
this.historyIndex = index;
this.history.push(currentLine);
}
// Check if, for the history spot, it is necessary to acquire more items
let count=this.spotCount;
if (count<1)
count=1; // Get at least one item
let index=this.historyIndex+1;
const len=this.history.length-index;
const additionalItems=count-len;
const endIndex=index+additionalItems;
for (let i=index; i<endIndex; i++) {
// Get new history item from remote
const line=await this.getRemoteHistoryIndex(i);
if (!line)
break;
this.historyIndex=index;
this.history.push(line);
}
release();

// Check if item available
if (index>=this.history.length)
return undefined;

// Return an item
const currentLine=this.history[index];
this.historyIndex=index;
return currentLine;
}

Expand Down
9 changes: 1 addition & 8 deletions src/remotes/stephistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {RefList} from '../reflist';
import {Remote} from './remotefactory';
import {Utility} from '../misc/utility';
import {Settings} from '../settings';
import {Mutex} from 'async-mutex';



/**
Expand Down Expand Up @@ -51,9 +49,6 @@ export class StepHistoryClass extends EventEmitter {
// The current history index.
protected historyIndex=-1;

// A mutext to coordinate access to the histroy array.
protected historyMutex=new Mutex();

// The maximum size of the history array.
protected maxSize=0;

Expand Down Expand Up @@ -145,9 +140,8 @@ export class StepHistoryClass extends EventEmitter {
* @param line One line of history.
* @param exchange true if the element should be exchanged rather than added.
*/
public async pushHistoryInfo(line: HistoryInstructionInfo, exchange = false): Promise<void> {
public pushHistoryInfo(line: HistoryInstructionInfo, exchange = false) {
assert(line);
const release=await this.historyMutex.acquire();
if (exchange&&this.history.length>0) {
// Exchange
this.history[0]=line;
Expand All @@ -158,7 +152,6 @@ export class StepHistoryClass extends EventEmitter {
if (this.history.length>this.maxSize)
this.history.pop();
}
release();
}


Expand Down
107 changes: 56 additions & 51 deletions src/remotes/zesarux/zesaruxremote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class ZesaruxRemote extends RemoteBase {
const err = new Error('ZEsarUX terminated the connection!');
this.emit('error', err);
});
zSocket.on('connected', () => {
zSocket.on('connected', async () => {
if(this.terminating)
return;

Expand Down Expand Up @@ -208,64 +208,69 @@ export class ZesaruxRemote extends RemoteBase {
this.zesaruxConnected();

// Wait for previous command to finish
zSocket.executeWhenQueueIsEmpty().then(() => {
var debug_settings = (Settings.launch.skipInterrupt) ? 32 : 0;
zSocket.send('set-debug-settings ' + debug_settings);

// Reset the cpu before loading.
if(Settings.launch.resetOnLaunch)
zSocket.send('hard-reset-cpu');

// Enter step-mode (stop)
zSocket.send('enter-cpu-step');

// Load sna or tap file
// TODO: Re-enable:
//const loadPath = Settings.launch.load;
//if (loadPath)
// zSocket.send('smartload ' + Settings.launch.load);

// Load obj file(s) unit
for(let loadObj of Settings.launch.loadObjs) {
if(loadObj.path) {
// Convert start address
const start = Labels.getNumberFromString(loadObj.start);
if(isNaN(start))
throw Error("Cannot evaluate 'loadObjs[].start' (" + loadObj.start + ").");
zSocket.send('load-binary ' + loadObj.path + ' ' + start + ' 0'); // 0 = load entire file
}
await zSocket.executeWhenQueueIsEmpty();

var debug_settings = (Settings.launch.skipInterrupt) ? 32 : 0;
zSocket.send('set-debug-settings ' + debug_settings);

// Reset the cpu before loading.
if(Settings.launch.resetOnLaunch)
zSocket.send('hard-reset-cpu');

// Enter step-mode (stop)
zSocket.send('enter-cpu-step');

// Load sna, nex or tap file
const loadPath = Settings.launch.load;
if (loadPath) {
const waitBeforeMs=Settings.launch.debug_wait_before;
await Utility.timeout(waitBeforeMs); // TODO: Remove
zSocket.send('smartload '+Settings.launch.load);
const waitAfterMs=Settings.launch.debug_wait_after;
await Utility.timeout(waitAfterMs); // TODO: Remove
}

// Load obj file(s) unit
for(let loadObj of Settings.launch.loadObjs) {
if(loadObj.path) {
// Convert start address
const start = Labels.getNumberFromString(loadObj.start);
if(isNaN(start))
throw Error("Cannot evaluate 'loadObjs[].start' (" + loadObj.start + ").");
zSocket.send('load-binary ' + loadObj.path + ' ' + start + ' 0'); // 0 = load entire file
}
}

// Set Program Counter to execAddress
if(Settings.launch.execAddress) {
const execAddress = Labels.getNumberFromString(Settings.launch.execAddress);
if(isNaN(execAddress)) {
error = new Error("Cannot evaluate 'execAddress' (" + Settings.launch.execAddress + ").");
return;
}
// Set PC
this.setProgramCounter(execAddress);
// Set Program Counter to execAddress
if(Settings.launch.execAddress) {
const execAddress = Labels.getNumberFromString(Settings.launch.execAddress);
if(isNaN(execAddress)) {
error = new Error("Cannot evaluate 'execAddress' (" + Settings.launch.execAddress + ").");
return;
}
// Set PC
this.setProgramCounter(execAddress);
}

// Initialize breakpoints
this.initBreakpoints();
// Initialize breakpoints
this.initBreakpoints();


// Code coverage
if(Settings.launch.history.codeCoverageEnabled) {
zSocket.send('cpu-code-coverage enabled yes', () => {}, true); // suppress any error
zSocket.send('cpu-code-coverage clear');
}
else
zSocket.send('cpu-code-coverage enabled no', () => {}, true); // suppress any error
// Code coverage
if(Settings.launch.history.codeCoverageEnabled) {
zSocket.send('cpu-code-coverage enabled yes', () => {}, true); // suppress any error
zSocket.send('cpu-code-coverage clear');
}
else
zSocket.send('cpu-code-coverage enabled no', () => {}, true); // suppress any error

// Reverse debugging.
CpuHistory.init();
// Reverse debugging.
CpuHistory.init();

// Enable extended stack
zSocket.send('extended-stack enabled no', () => {}, true); // bug in ZEsarUX
zSocket.send('extended-stack enabled yes');

// Enable extended stack
zSocket.send('extended-stack enabled no', () => {}, true); // bug in ZEsarUX
zSocket.send('extended-stack enabled yes');
});

zSocket.executeWhenQueueIsEmpty().then(() => {
// Check for console.error
Expand Down
1 change: 0 additions & 1 deletion src/remotes/zxsimulator/zxmemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as fs from 'fs';
import {ImageConvert} from '../../imageconvert';
import {Utility} from '../../misc/utility';
import {MemBuffer} from '../../misc/membuffer';
import {start} from 'repl';


/**
Expand Down
20 changes: 18 additions & 2 deletions src/remotes/zxsimulator/zxsimcpuhistory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//import * as assert from 'assert';
import {CpuHistoryClass} from '../cpuhistory';
import {HistoryInstructionInfo} from '../decodehistinfo';



Expand All @@ -14,13 +15,28 @@ export class ZxSimCpuHistory extends CpuHistoryClass {
*/
public clear() {
(async () => {
const release=await this.historyMutex.acquire();
this.historyIndex=-1;
this.revDbgHistory.length=0;
this.reverseDbgStack=undefined as any;
release();
})();
}


/**
* Retrieves the registers at the previous instruction from the Remote's cpu history.
* Is async.
* @returns Data with the registers or undefined if at the end of the history.
*/
public async getPrevRegistersAsync(): Promise<HistoryInstructionInfo|undefined> {
// Check if item available
let index=this.historyIndex+1;
if (index>=this.history.length)
return undefined;

// Return an item
const currentLine=this.history[index];
this.historyIndex=index;
return currentLine;
}
}

2 changes: 1 addition & 1 deletion src/remotes/zxsimulator/zxsimremote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class ZxSimulatorRemote extends DzrpRemote {
const exchange=(pc==this.previouslyStoredPCHistory);
this.previouslyStoredPCHistory=pc;
// Store
await CpuHistory.pushHistoryInfo(hist, exchange);
CpuHistory.pushHistoryInfo(hist, exchange);
}


Expand Down
Loading

0 comments on commit b0bfa13

Please sign in to comment.