kopia lustrzana https://github.com/maccasoft/z80-tools
Better debugger thread handling
rodzic
80ffb7e3d3
commit
8a725613ca
|
@ -103,7 +103,7 @@ import nl.grauw.glass.directives.Include;
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static final String APP_TITLE = "Z80 Tools";
|
public static final String APP_TITLE = "Z80 Tools";
|
||||||
public static final String APP_VERSION = "1.2.0";
|
public static final String APP_VERSION = "1.2.1";
|
||||||
|
|
||||||
Display display;
|
Display display;
|
||||||
Shell shell;
|
Shell shell;
|
||||||
|
@ -131,7 +131,7 @@ public class Application {
|
||||||
DebugTMS9918 debugTMS9918;
|
DebugTMS9918 debugTMS9918;
|
||||||
|
|
||||||
Debugger debugger;
|
Debugger debugger;
|
||||||
Thread debuggerThread;
|
final AtomicReference<Thread> debuggerThread = new AtomicReference<Thread>();
|
||||||
|
|
||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
|
|
||||||
|
@ -2375,18 +2375,6 @@ public class Application {
|
||||||
super.poke8(address, value);
|
super.poke8(address, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doUpdateDebuggerState() {
|
|
||||||
super.doUpdateDebuggerState();
|
|
||||||
display.syncExec(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateDebuggerState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isBreakpoint(int address) {
|
protected boolean isBreakpoint(int address) {
|
||||||
return viewer.isBreakpoint(address);
|
return viewer.isBreakpoint(address);
|
||||||
|
@ -2435,6 +2423,17 @@ public class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSwitchToEditor() {
|
private void handleSwitchToEditor() {
|
||||||
|
Thread thread = debuggerThread.get();
|
||||||
|
if (thread != null) {
|
||||||
|
debugger.doStop();
|
||||||
|
try {
|
||||||
|
thread.join(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
debuggerThread.set(null);
|
||||||
|
}
|
||||||
|
|
||||||
Menu menu = shell.getMenuBar();
|
Menu menu = shell.getMenuBar();
|
||||||
menu.getItem(menu.getItemCount() - 2).dispose();
|
menu.getItem(menu.getItemCount() - 2).dispose();
|
||||||
|
|
||||||
|
@ -2448,6 +2447,10 @@ public class Application {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tabItem.getControl().setFocus();
|
tabItem.getControl().setFocus();
|
||||||
|
|
||||||
|
if (debugger != null) {
|
||||||
|
debugger = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reparentControls() {
|
void reparentControls() {
|
||||||
|
@ -2462,7 +2465,7 @@ public class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleReset() {
|
private void handleReset() {
|
||||||
if (debuggerThread != null) {
|
if (debuggerThread.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2485,7 +2488,7 @@ public class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStep() {
|
private void handleStep() {
|
||||||
if (debuggerThread != null) {
|
if (debuggerThread.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2493,20 +2496,30 @@ public class Application {
|
||||||
viewer.getControl().setFocus();
|
viewer.getControl().setFocus();
|
||||||
viewer.setHighlighCurrentLine(false);
|
viewer.setHighlighCurrentLine(false);
|
||||||
|
|
||||||
debuggerThread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
debugger.stepInto();
|
debugger.stepInto();
|
||||||
debuggerThread = null;
|
display.syncExec(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (debugger != null) {
|
||||||
|
updateDebuggerState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
debuggerThread.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
debuggerThread.start();
|
debuggerThread.set(thread);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStepOver() {
|
private void handleStepOver() {
|
||||||
if (debuggerThread != null) {
|
if (debuggerThread.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2514,20 +2527,30 @@ public class Application {
|
||||||
viewer.getControl().setFocus();
|
viewer.getControl().setFocus();
|
||||||
viewer.setHighlighCurrentLine(false);
|
viewer.setHighlighCurrentLine(false);
|
||||||
|
|
||||||
debuggerThread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
debugger.stepOver();
|
debugger.stepOver();
|
||||||
debuggerThread = null;
|
display.syncExec(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (debugger != null) {
|
||||||
|
updateDebuggerState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
debuggerThread.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
debuggerThread.start();
|
debuggerThread.set(thread);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRunToLine() {
|
private void handleRunToLine() {
|
||||||
if (debuggerThread != null) {
|
if (debuggerThread.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2540,16 +2563,26 @@ public class Application {
|
||||||
|
|
||||||
final LineEntry lineEntry = viewer.getSourceMap().getLines().get(lineAtOffset);
|
final LineEntry lineEntry = viewer.getSourceMap().getLines().get(lineAtOffset);
|
||||||
|
|
||||||
debuggerThread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
debugger.runToAddress(lineEntry.address);
|
debugger.runToAddress(lineEntry.address);
|
||||||
debuggerThread = null;
|
display.syncExec(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (debugger != null) {
|
||||||
|
updateDebuggerState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
debuggerThread.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
debuggerThread.start();
|
debuggerThread.set(thread);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStop() {
|
private void handleStop() {
|
||||||
|
@ -2573,7 +2606,7 @@ public class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRun() {
|
private void handleRun() {
|
||||||
if (debuggerThread != null) {
|
if (debuggerThread.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2581,16 +2614,26 @@ public class Application {
|
||||||
viewer.getControl().setFocus();
|
viewer.getControl().setFocus();
|
||||||
viewer.setHighlighCurrentLine(false);
|
viewer.setHighlighCurrentLine(false);
|
||||||
|
|
||||||
debuggerThread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
debugger.run();
|
debugger.run();
|
||||||
debuggerThread = null;
|
debuggerThread.set(null);
|
||||||
|
display.asyncExec(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (debugger != null) {
|
||||||
|
updateDebuggerState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
debuggerThread.start();
|
debuggerThread.set(thread);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDebuggerState() {
|
void updateDebuggerState() {
|
||||||
|
|
|
@ -285,7 +285,7 @@ public class Debugger extends MemIoOps implements NotifyOps {
|
||||||
else {
|
else {
|
||||||
proc.execute();
|
proc.execute();
|
||||||
}
|
}
|
||||||
doUpdateDebuggerState();
|
tms9918.redrawFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stepInto() {
|
public void stepInto() {
|
||||||
|
@ -315,27 +315,49 @@ public class Debugger extends MemIoOps implements NotifyOps {
|
||||||
else {
|
else {
|
||||||
proc.execute();
|
proc.execute();
|
||||||
}
|
}
|
||||||
doUpdateDebuggerState();
|
tms9918.redrawFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
stop = false;
|
LineEntry lineEntry = sourceMap.getLineAtAddress(proc.getRegPC());
|
||||||
|
if (lineEntry != null) {
|
||||||
|
int stepOverPC1 = proc.getRegPC() + lineEntry.code.length;
|
||||||
|
int stepOverPC2 = peek16(proc.getRegSP());
|
||||||
|
int stepOverSP = proc.getRegSP();
|
||||||
|
|
||||||
int count = 0;
|
stop = false;
|
||||||
do {
|
do {
|
||||||
proc.execute();
|
proc.execute();
|
||||||
|
|
||||||
if (isBreakpoint(proc.getRegPC())) {
|
lineEntry = sourceMap.getLineAtAddress(proc.getRegPC());
|
||||||
break;
|
if (lineEntry != null) {
|
||||||
|
stepOverPC1 = proc.getRegPC() + lineEntry.code.length;
|
||||||
|
stepOverPC2 = peek16(proc.getRegSP());
|
||||||
|
stepOverSP = proc.getRegSP();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isBreakpoint(proc.getRegPC())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (!stop);
|
||||||
|
|
||||||
|
if (sourceMap.getLineAtAddress(proc.getRegPC()) == null) {
|
||||||
|
stop = false;
|
||||||
|
do {
|
||||||
|
int currentPC = proc.getRegPC();
|
||||||
|
proc.execute();
|
||||||
|
|
||||||
|
if (isBreakpoint(proc.getRegPC())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (proc.getRegPC() == stepOverPC1 || proc.getRegPC() == stepOverPC2 || (proc.getRegPC() != currentPC && proc.getRegSP() == stepOverSP)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (!stop);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (count++ >= 16) {
|
tms9918.redrawFrame();
|
||||||
doUpdateDebuggerState();
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
} while (!stop);
|
|
||||||
|
|
||||||
doUpdateDebuggerState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runToAddress(int addr) {
|
public void runToAddress(int addr) {
|
||||||
|
@ -350,18 +372,13 @@ public class Debugger extends MemIoOps implements NotifyOps {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (!stop);
|
} while (!stop);
|
||||||
|
tms9918.redrawFrame();
|
||||||
doUpdateDebuggerState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isBreakpoint(int address) {
|
protected boolean isBreakpoint(int address) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doUpdateDebuggerState() {
|
|
||||||
tms9918.redrawFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resetBreakpoints() {
|
public void resetBreakpoints() {
|
||||||
proc.resetBreakpoints();
|
proc.resetBreakpoints();
|
||||||
proc.setBreakpoint(0x0005, true);
|
proc.setBreakpoint(0x0005, true);
|
||||||
|
|
Ładowanie…
Reference in New Issue