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 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;
|
||||
Shell shell;
|
||||
|
@ -131,7 +131,7 @@ public class Application {
|
|||
DebugTMS9918 debugTMS9918;
|
||||
|
||||
Debugger debugger;
|
||||
Thread debuggerThread;
|
||||
final AtomicReference<Thread> debuggerThread = new AtomicReference<Thread>();
|
||||
|
||||
Preferences preferences;
|
||||
|
||||
|
@ -2375,18 +2375,6 @@ public class Application {
|
|||
super.poke8(address, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUpdateDebuggerState() {
|
||||
super.doUpdateDebuggerState();
|
||||
display.syncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updateDebuggerState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isBreakpoint(int address) {
|
||||
return viewer.isBreakpoint(address);
|
||||
|
@ -2435,6 +2423,17 @@ public class Application {
|
|||
}
|
||||
|
||||
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.getItem(menu.getItemCount() - 2).dispose();
|
||||
|
||||
|
@ -2448,6 +2447,10 @@ public class Application {
|
|||
return;
|
||||
}
|
||||
tabItem.getControl().setFocus();
|
||||
|
||||
if (debugger != null) {
|
||||
debugger = null;
|
||||
}
|
||||
}
|
||||
|
||||
void reparentControls() {
|
||||
|
@ -2462,7 +2465,7 @@ public class Application {
|
|||
}
|
||||
|
||||
private void handleReset() {
|
||||
if (debuggerThread != null) {
|
||||
if (debuggerThread.get() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2485,7 +2488,7 @@ public class Application {
|
|||
}
|
||||
|
||||
private void handleStep() {
|
||||
if (debuggerThread != null) {
|
||||
if (debuggerThread.get() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2493,20 +2496,30 @@ public class Application {
|
|||
viewer.getControl().setFocus();
|
||||
viewer.setHighlighCurrentLine(false);
|
||||
|
||||
debuggerThread = new Thread(new Runnable() {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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() {
|
||||
if (debuggerThread != null) {
|
||||
if (debuggerThread.get() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2514,20 +2527,30 @@ public class Application {
|
|||
viewer.getControl().setFocus();
|
||||
viewer.setHighlighCurrentLine(false);
|
||||
|
||||
debuggerThread = new Thread(new Runnable() {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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() {
|
||||
if (debuggerThread != null) {
|
||||
if (debuggerThread.get() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2540,16 +2563,26 @@ public class Application {
|
|||
|
||||
final LineEntry lineEntry = viewer.getSourceMap().getLines().get(lineAtOffset);
|
||||
|
||||
debuggerThread = new Thread(new Runnable() {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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() {
|
||||
|
@ -2573,7 +2606,7 @@ public class Application {
|
|||
}
|
||||
|
||||
private void handleRun() {
|
||||
if (debuggerThread != null) {
|
||||
if (debuggerThread.get() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2581,16 +2614,26 @@ public class Application {
|
|||
viewer.getControl().setFocus();
|
||||
viewer.setHighlighCurrentLine(false);
|
||||
|
||||
debuggerThread = new Thread(new Runnable() {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void 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() {
|
||||
|
|
|
@ -285,7 +285,7 @@ public class Debugger extends MemIoOps implements NotifyOps {
|
|||
else {
|
||||
proc.execute();
|
||||
}
|
||||
doUpdateDebuggerState();
|
||||
tms9918.redrawFrame();
|
||||
}
|
||||
|
||||
public void stepInto() {
|
||||
|
@ -315,27 +315,49 @@ public class Debugger extends MemIoOps implements NotifyOps {
|
|||
else {
|
||||
proc.execute();
|
||||
}
|
||||
doUpdateDebuggerState();
|
||||
tms9918.redrawFrame();
|
||||
}
|
||||
|
||||
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;
|
||||
do {
|
||||
proc.execute();
|
||||
stop = false;
|
||||
do {
|
||||
proc.execute();
|
||||
|
||||
if (isBreakpoint(proc.getRegPC())) {
|
||||
break;
|
||||
lineEntry = sourceMap.getLineAtAddress(proc.getRegPC());
|
||||
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) {
|
||||
doUpdateDebuggerState();
|
||||
count = 0;
|
||||
}
|
||||
} while (!stop);
|
||||
|
||||
doUpdateDebuggerState();
|
||||
tms9918.redrawFrame();
|
||||
}
|
||||
|
||||
public void runToAddress(int addr) {
|
||||
|
@ -350,18 +372,13 @@ public class Debugger extends MemIoOps implements NotifyOps {
|
|||
break;
|
||||
}
|
||||
} while (!stop);
|
||||
|
||||
doUpdateDebuggerState();
|
||||
tms9918.redrawFrame();
|
||||
}
|
||||
|
||||
protected boolean isBreakpoint(int address) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void doUpdateDebuggerState() {
|
||||
tms9918.redrawFrame();
|
||||
}
|
||||
|
||||
public void resetBreakpoints() {
|
||||
proc.resetBreakpoints();
|
||||
proc.setBreakpoint(0x0005, true);
|
||||
|
|
Ładowanie…
Reference in New Issue