mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GT-2875 - Unswingable - review fixes
This commit is contained in:
parent
8dffd377fb
commit
07f0371a50
16 changed files with 395 additions and 374 deletions
|
@ -21,7 +21,7 @@ import ghidra.program.model.address.*;
|
|||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.model.util.CodeUnitInsertionException;
|
||||
import ghidra.util.SystemUtilities;
|
||||
import ghidra.util.Swing;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,7 @@ public class CreateDataBackgroundCmd extends BackgroundCommand {
|
|||
|
||||
// Allow the Swing thread a chance to paint components that may require
|
||||
// a DB lock.
|
||||
SystemUtilities.allowSwingToProcessEvents();
|
||||
Swing.allowSwingToProcessEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ public class MoveBlockTask extends ProgramTask {
|
|||
|
||||
@Override
|
||||
protected void doRun(TaskMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Memory mem = program.getMemory();
|
||||
MemoryBlock block = mem.getBlock(currentStart);
|
||||
|
@ -77,23 +76,23 @@ public class MoveBlockTask extends ProgramTask {
|
|||
}
|
||||
}
|
||||
catch (OutOfMemoryError e) {
|
||||
monitor.setMessage(msg = "Insufficient memory to complete operation");
|
||||
msg = "Insufficient memory to complete operation";
|
||||
cause = e;
|
||||
}
|
||||
catch (NotFoundException exc) {
|
||||
monitor.setMessage(msg = "Memory block not found");
|
||||
msg = "Memory block not found";
|
||||
cause = exc;
|
||||
}
|
||||
catch (MemoryConflictException exc) {
|
||||
monitor.setMessage(msg = exc.getMessage());
|
||||
msg = exc.getMessage();
|
||||
cause = exc;
|
||||
}
|
||||
catch (MemoryBlockException exc) {
|
||||
monitor.setMessage(msg = exc.getMessage());
|
||||
msg = exc.getMessage();
|
||||
cause = exc;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
monitor.setMessage(msg = e.getMessage());
|
||||
msg = e.getMessage();
|
||||
cause = e;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
|
@ -102,25 +101,18 @@ public class MoveBlockTask extends ProgramTask {
|
|||
if (msg == null) {
|
||||
msg = t.toString();
|
||||
}
|
||||
monitor.setMessage(msg);
|
||||
cause = t;
|
||||
}
|
||||
|
||||
monitor.setMessage(msg);
|
||||
listener.moveBlockCompleted(this);
|
||||
throw new RollbackException(msg, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the user cancelled the move command.
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return wasCancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the block was successfully moved.
|
||||
*
|
||||
* @return true if the block was moved
|
||||
*/
|
||||
public boolean getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import ghidra.program.model.lang.Register;
|
|||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.SystemUtilities;
|
||||
import ghidra.util.Swing;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
import ghidra.util.task.TaskMonitorAdapter;
|
||||
|
@ -184,7 +184,7 @@ public class ClearCmd extends BackgroundCommand {
|
|||
monitor.setProgress(progress);
|
||||
|
||||
// Allow Swing a chance to paint components that may require a DB lock
|
||||
SystemUtilities.allowSwingToProcessEvents();
|
||||
Swing.allowSwingToProcessEvents();
|
||||
}
|
||||
}
|
||||
previousRangeAddrCnt += range.getLength();
|
||||
|
@ -295,7 +295,7 @@ public class ClearCmd extends BackgroundCommand {
|
|||
AddressRangeIterator it = clearView.getAddressRanges();
|
||||
while (it.hasNext()) {
|
||||
|
||||
AddressRange currentRange = it.next();
|
||||
AddressRange currentRange = it.next();
|
||||
Address start = currentRange.getMinAddress();
|
||||
Address end = currentRange.getMaxAddress();
|
||||
clearAddresses(monitor, listing, start, end);
|
||||
|
@ -320,7 +320,7 @@ public class ClearCmd extends BackgroundCommand {
|
|||
monitor.incrementProgress(numDone);
|
||||
|
||||
// Allow the Swing thread a chance to paint components that may require a DB lock
|
||||
SystemUtilities.allowSwingToProcessEvents();
|
||||
Swing.allowSwingToProcessEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ package ghidra.app.plugin.core.memory;
|
|||
import java.awt.Cursor;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import docking.DialogComponentProvider;
|
||||
import docking.widgets.label.GDLabel;
|
||||
|
@ -32,7 +30,7 @@ import ghidra.program.model.address.Address;
|
|||
import ghidra.program.model.address.AddressFactory;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.layout.PairLayout;
|
||||
import ghidra.util.task.TaskLauncher;
|
||||
import ghidra.util.task.BackgroundThreadTaskLauncher;
|
||||
import ghidra.util.task.TaskMonitorAdapter;
|
||||
|
||||
/**
|
||||
|
@ -77,22 +75,19 @@ public class MoveBlockDialog extends DialogComponentProvider implements MoveBloc
|
|||
*/
|
||||
@Override
|
||||
public void moveBlockCompleted(final MoveBlockTask cmd) {
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cmd.getStatus()) {
|
||||
Runnable r = () -> {
|
||||
if (cmd.getStatus()) {
|
||||
close();
|
||||
model.dispose();
|
||||
}
|
||||
else {
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
setOkEnabled(false);
|
||||
if (cmd.isCancelled()) {
|
||||
tool.setStatusInfo(getStatusText());
|
||||
close();
|
||||
model.dispose();
|
||||
}
|
||||
else {
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
setOkEnabled(false);
|
||||
if (cmd.isCancelled()) {
|
||||
tool.setStatusInfo(getStatusText());
|
||||
close();
|
||||
model.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(r);
|
||||
|
@ -142,7 +137,9 @@ public class MoveBlockDialog extends DialogComponentProvider implements MoveBloc
|
|||
protected void okCallback() {
|
||||
setOkEnabled(false);
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
new TaskLauncher(model.makeTask(), new TaskMonitorAdapter() {
|
||||
|
||||
BackgroundThreadTaskLauncher launcher = new BackgroundThreadTaskLauncher(model.makeTask());
|
||||
launcher.run(new TaskMonitorAdapter() {
|
||||
@Override
|
||||
public void setMessage(String message) {
|
||||
setStatusText(message);
|
||||
|
@ -176,18 +173,8 @@ public class MoveBlockDialog extends DialogComponentProvider implements MoveBloc
|
|||
newEndField = new AddressInput();
|
||||
newEndField.setName("newEnd");
|
||||
|
||||
newStartField.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
startChanged();
|
||||
}
|
||||
});
|
||||
newEndField.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
endChanged();
|
||||
}
|
||||
});
|
||||
newStartField.addChangeListener(e -> startChanged());
|
||||
newEndField.addChangeListener(e -> endChanged());
|
||||
|
||||
panel.add(new GLabel("Name:", SwingConstants.RIGHT));
|
||||
panel.add(blockNameLabel);
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.junit.*;
|
|||
|
||||
import ghidra.app.cmd.memory.MoveBlockListener;
|
||||
import ghidra.app.cmd.memory.MoveBlockTask;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.program.database.ProgramBuilder;
|
||||
import ghidra.program.database.ProgramDB;
|
||||
import ghidra.program.database.data.DataTypeManagerDB;
|
||||
|
@ -33,32 +32,18 @@ import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
|||
import ghidra.test.TestEnv;
|
||||
import ghidra.util.task.*;
|
||||
|
||||
/**
|
||||
* Test the model that moves a block of memory.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
||||
implements MoveBlockListener {
|
||||
|
||||
private Program notepad;
|
||||
private Program x8051;
|
||||
private PluginTool tool;
|
||||
private TestEnv env;
|
||||
private MoveBlockModel model;
|
||||
private MemoryBlock block;
|
||||
private boolean expectedStatus;
|
||||
private boolean moveCompleted;
|
||||
private boolean status;
|
||||
private String errMsg;
|
||||
|
||||
/**
|
||||
* Constructor for MoveBlockModelTest.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public MoveBlockModelTest() {
|
||||
super();
|
||||
}
|
||||
private volatile boolean moveCompleted;
|
||||
private volatile boolean status;
|
||||
private volatile String errMsg;
|
||||
|
||||
private Program buildProgram1(String programName) throws Exception {
|
||||
ProgramBuilder builder = new ProgramBuilder(programName, ProgramBuilder._TOY);
|
||||
|
@ -84,13 +69,10 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
return builder.getProgram();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
env = new TestEnv();
|
||||
tool = env.getTool();
|
||||
|
||||
notepad = buildProgram1("notepad");
|
||||
x8051 = buildProgram2("x08");
|
||||
block = notepad.getMemory().getBlock(getNotepadAddr(0x1001000));
|
||||
|
@ -109,13 +91,8 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
x8051.endTransaction(transactionID, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see TestCase#tearDown()
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
env.release(x8051);
|
||||
env.release(notepad);
|
||||
env.dispose();
|
||||
}
|
||||
|
||||
|
@ -152,25 +129,23 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
@Test
|
||||
public void testMoveBlockStart() throws Exception {
|
||||
model.setNewStartAddress(getNotepadAddr(0x2000000));
|
||||
expectedStatus = true;
|
||||
|
||||
launch(model.makeTask());
|
||||
|
||||
// wait until the we get the move complete notification
|
||||
while (!moveCompleted || !notepad.canLock()) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
assertEquals("Error message= [" + errMsg + "], ", expectedStatus, status);
|
||||
waitForCondition(() -> moveCompleted && notepad.canLock());
|
||||
assertTrue("Error message= [" + errMsg + "], ", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveBlockEnd() throws Exception {
|
||||
model.setNewEndAddress(getNotepadAddr(0x2007500));
|
||||
expectedStatus = true;
|
||||
|
||||
launch(model.makeTask());
|
||||
|
||||
// wait until the we get the move complete notification
|
||||
while (!moveCompleted || !notepad.canLock()) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
assertEquals("Error message= [" + errMsg + "], ", expectedStatus, status);
|
||||
waitForCondition(() -> moveCompleted && notepad.canLock());
|
||||
assertTrue("Error message= [" + errMsg + "], ", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -194,13 +169,15 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
start = getAddr(x8051, "INTMEM", 0x50);
|
||||
model.setNewStartAddress(start);
|
||||
assertEquals(getAddr(x8051, "INTMEM", 0xcf), model.getNewEndAddress());
|
||||
expectedStatus = false;
|
||||
|
||||
setErrorsExpected(true);
|
||||
launch(model.makeTask());
|
||||
|
||||
// wait until the we get the move complete notification
|
||||
while (!moveCompleted || !x8051.canLock()) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
assertEquals("Error message= [" + errMsg + "], ", expectedStatus, status);
|
||||
waitForCondition(() -> moveCompleted && x8051.canLock());
|
||||
setErrorsExpected(false);
|
||||
|
||||
assertFalse("Error message= [" + errMsg + "], ", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -213,13 +190,12 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
model.initialize(block);
|
||||
start = getAddr(x8051, "CODE", 0x2000);
|
||||
model.setNewStartAddress(start);
|
||||
expectedStatus = true;
|
||||
moveCompleted = false;
|
||||
|
||||
launch(model.makeTask());
|
||||
|
||||
// wait until the we get the move complete notification
|
||||
while (!moveCompleted || !x8051.canLock()) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
waitForCondition(() -> moveCompleted && x8051.canLock());
|
||||
|
||||
// make sure settings on data got moved
|
||||
DataTypeManagerDB dtm = ((ProgramDB) x8051).getDataManager();
|
||||
|
||||
|
@ -257,19 +233,19 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
Address newStart = memBlock.getStart().getNewAddress(0x01002000);
|
||||
model.setNewStartAddress(newStart);
|
||||
|
||||
expectedStatus = false;
|
||||
errMsg = null;
|
||||
|
||||
setErrorsExpected(true);
|
||||
launch(model.makeTask());
|
||||
while (!moveCompleted || !notepad.canLock()) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
assertTrue(!expectedStatus);
|
||||
|
||||
waitForCondition(() -> moveCompleted && notepad.canLock());
|
||||
setErrorsExpected(false);
|
||||
|
||||
assertNotNull(errMsg);
|
||||
}
|
||||
|
||||
private void launch(Task task) {
|
||||
new TaskLauncher(task, new TaskMonitorAdapter() {
|
||||
|
||||
BackgroundThreadTaskLauncher launcher = new BackgroundThreadTaskLauncher(task);
|
||||
launcher.run(new TaskMonitorAdapter() {
|
||||
@Override
|
||||
public void setMessage(String message) {
|
||||
errMsg = message;
|
||||
|
@ -286,21 +262,14 @@ public class MoveBlockModelTest extends AbstractGhidraHeadedIntegrationTest
|
|||
return space.getAddress(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.app.plugin.contrib.memory.MoveBlockListener#moveBlockCompleted(boolean,
|
||||
* java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void moveBlockCompleted(MoveBlockTask cmd) {
|
||||
moveCompleted = true;
|
||||
this.status = cmd.getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.app.plugin.contrib.memory.MoveBlockListener#stateChanged()
|
||||
*/
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
// stub
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue