GP-6808:Continued clean up of System.out/.err usage.

This commit is contained in:
ghidravision
2026-08-26 13:40:07 +00:00
parent 5f97b9b573
commit 52fd511adf
20 changed files with 72 additions and 108 deletions
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,7 +48,6 @@ public class DBAnnotatedObjectProcessor extends AbstractProcessor {
*/
@Override
public synchronized void init(ProcessingEnvironment env) {
//System.err.println("HERE4");
super.init(env);
ctx = new ValidationContext(env);
}
@@ -233,10 +233,6 @@ public class MemviewPanel extends JPanel implements MouseListener, MouseMotionLi
provider.refresh();
}
if (e.getButton() == MouseEvent.BUTTON2) {
System.err.println("BUTTON2");
}
if (e.getButton() == MouseEvent.BUTTON3) {
ctrlPressed = true;
enableDrag = true;
@@ -307,10 +307,10 @@ public class SymStateSpace {
for (SymEntry ent : map.values()) {
Register register = ent.getRegister(language);
if (register != null) {
System.err.println(prefix + register + " = " + ent.sym);
Msg.info(this, prefix + register + " = " + ent.sym);
continue;
}
System.err.println(prefix + ent);
Msg.info(this, prefix + ent);
}
}
@@ -219,7 +219,7 @@ public class AngrTaintState extends AbstractTaintState {
taintAddressSet.add(address);
}
else {
System.err.println(line);
Msg.error(this, line);
}
}
bufferedReader.close();
@@ -101,7 +101,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
byte[] ins = res.getInstruction().getVals();
// HACK to avoid 16-bit CALL.... TODO: Why does this happen?
if (ins.length >= 2 && ins[0] == (byte) 0x66 && ins[1] == (byte) 0xe8) {
System.err.println(
Msg.error(StackUnwinderTest.class,
"Filtered 16-bit call " + NumericUtilities.convertBytesToString(ins));
continue;
}
@@ -41,6 +41,7 @@ public class GhidraApplicationConfiguration extends HeadlessGhidraApplicationCon
public GhidraApplicationConfiguration() {
if (GraphicsEnvironment.isHeadless()) {
// NOTE: System.err must be used here because Messaging hasn't been initialized yet
System.err.println(
"ERROR: Unable to launch Ghidra GUI application in headless environment.");
System.err.println(
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -66,15 +66,4 @@ public class UniversalIdGenerator {
}
return newTime;
}
public static void main(String[] args) {
UniversalIdGenerator gen = new UniversalIdGenerator();
UniversalIdGenerator gen2 = new UniversalIdGenerator();
for (int i = 0; i < 500; i++) {
System.out.println("id = " + gen.getNextID().getValue() + " next = " +
Long.toHexString(gen.getNextID().getValue()));
System.out.println("id2 = " + gen2.getNextID().getValue() + " next = " +
Long.toHexString(gen2.getNextID().getValue()));
}
}
}
@@ -16,7 +16,7 @@
package agent.dbgeng.rmi;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.*;
import java.io.*;
import java.net.*;
@@ -166,6 +166,7 @@ public abstract class AbstractDbgEngTraceRmiTest extends AbstractGhidraHeadedDeb
}
}
catch (RuntimeException e) {
// Should not happen since we maintain library on host test machine
}
return Paths.get(DummyProc.which("python"));
}
@@ -203,10 +204,6 @@ public abstract class AbstractDbgEngTraceRmiTest extends AbstractGhidraHeadedDeb
if (stderr.contains("Error") || (0 != exitCode && 1 != exitCode && 143 != exitCode)) {
throw new PythonError(exitCode, stdout, stderr);
}
System.out.println("--stdout--");
System.out.println(stdout);
System.out.println("--stderr--");
System.out.println(stderr);
return stdout;
}
}
@@ -15,8 +15,7 @@
*/
package agent.dbgeng.rmi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
@@ -67,8 +66,7 @@ import ghidra.trace.database.ToyDBTraceBuilder;
import ghidra.trace.database.module.DBTraceStaticMappingManager;
import ghidra.trace.model.Trace;
import ghidra.trace.model.modules.TraceStaticMapping;
import ghidra.util.InvalidNameException;
import ghidra.util.NumericUtilities;
import ghidra.util.*;
import ghidra.util.exception.CancelledException;
import junit.framework.AssertionFailedError;
@@ -636,7 +634,7 @@ public class DbgEngStackUnwindTest extends AbstractDbgEngTraceRmiTest {
byte[] ins = res.getInstruction().getVals();
// HACK to avoid 16-bit CALL.... TODO: Why does this happen?
if (ins.length >= 2 && ins[0] == (byte) 0x66 && ins[1] == (byte) 0xe8) {
System.err.println(
Msg.error(DbgEngStackUnwindTest.class,
"Filtered 16-bit call " + NumericUtilities.convertBytesToString(ins));
continue;
}
@@ -18,7 +18,7 @@ package agent.lldb.rmi;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.*;
import java.util.*;
@@ -45,6 +45,7 @@ import ghidra.trace.model.target.TraceObject;
import ghidra.trace.model.target.TraceObjectValue;
import ghidra.trace.model.target.path.PathFilter;
import ghidra.trace.model.target.path.PathPattern;
import ghidra.util.Msg;
@Category(NightlyCategory.class) // this may actually be an @PortSensitive test
public class LldbMethodsTest extends AbstractLldbTraceRmiTest {
@@ -688,7 +689,7 @@ public class LldbMethodsTest extends AbstractLldbTraceRmiTest {
stepToCall(conn, step_over, thread);
String dis2 = conn.executeCapture("dis -c2 -s '$pc'");
System.err.println(dis2);
Msg.info(this, dis2);
CallInstr instr = CallInstr.parse(dis2);
// This winds up a step_into if lldb can't place its breakpoint
@@ -66,8 +66,7 @@ import ghidra.trace.database.ToyDBTraceBuilder;
import ghidra.trace.database.module.DBTraceStaticMappingManager;
import ghidra.trace.model.Trace;
import ghidra.trace.model.modules.TraceStaticMapping;
import ghidra.util.InvalidNameException;
import ghidra.util.NumericUtilities;
import ghidra.util.*;
import ghidra.util.exception.CancelledException;
import junit.framework.AssertionFailedError;
@@ -649,7 +648,7 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {
byte[] ins = res.getInstruction().getVals();
// HACK to avoid 16-bit CALL.... TODO: Why does this happen?
if (ins.length >= 2 && ins[0] == (byte) 0x66 && ins[1] == (byte) 0xe8) {
System.err.println(
Msg.error(LldbStackUnwindTest.class,
"Filtered 16-bit call " + NumericUtilities.convertBytesToString(ins));
continue;
}
@@ -16,7 +16,7 @@
package agent.x64dbg.rmi;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.*;
import java.io.*;
import java.net.*;
@@ -160,6 +160,7 @@ public abstract class AbstractX64dbgTraceRmiTest extends AbstractGhidraHeadedDeb
}
}
catch (RuntimeException e) {
// Should not happen since we maintain library on host test machine
}
return Paths.get(DummyProc.which("python"));
}
@@ -208,10 +209,6 @@ public abstract class AbstractX64dbgTraceRmiTest extends AbstractGhidraHeadedDeb
if (stderr.contains("Error") || (0 != exitCode && 1 != exitCode && 143 != exitCode)) {
throw new PythonError(exitCode, stdout, stderr);
}
System.out.println("--stdout--");
System.out.println(stdout);
System.out.println("--stderr--");
System.out.println(stderr);
return stdout;
}
}
@@ -54,7 +54,6 @@ import ghidra.debug.api.action.AutoReadMemorySpec;
import ghidra.debug.api.control.ControlMode;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.model.*;
import ghidra.pcode.exec.DebuggerPcodeUtils;
import ghidra.program.model.address.*;
import ghidra.program.model.data.PointerDataType;
import ghidra.program.model.lang.Register;
@@ -76,6 +75,7 @@ import ghidra.trace.model.stack.TraceStack;
import ghidra.trace.model.target.TraceObject;
import ghidra.trace.model.target.schema.SchemaContext;
import ghidra.trace.model.thread.TraceThread;
import ghidra.util.Msg;
@Category(NightlyCategory.class)
public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerIntegrationTest {
@@ -1304,9 +1304,9 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerInt
DomainObjectListener spyListener = new DomainObjectListener() {
@Override
public void domainObjectChanged(DomainObjectChangedEvent ev) {
System.err.println(ev);
Msg.info(this, ev);
for (DomainObjectChangeRecord rec : ev) {
System.err.println(" " + rec);
Msg.info(this, " " + rec);
}
}
};
@@ -15,9 +15,8 @@
*/
package ghidra.app.plugin.core.terminal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.io.File;
import java.io.UnsupportedEncodingException;
@@ -122,7 +121,6 @@ public class TerminalProviderTest extends AbstractGhidraHeadedDebuggerTest {
term.addTerminalListener(new TerminalListener() {
@Override
public void resized(short cols, short rows) {
// System.err.println("resized: " + cols + "x" + rows);
child.setWindowSize(cols, rows);
}
});
@@ -157,7 +155,6 @@ public class TerminalProviderTest extends AbstractGhidraHeadedDebuggerTest {
term.addTerminalListener(new TerminalListener() {
@Override
public void resized(short cols, short rows) {
// System.err.println("resized: " + cols + "x" + rows);
child.setWindowSize(cols, rows);
}
});
@@ -189,7 +186,6 @@ public class TerminalProviderTest extends AbstractGhidraHeadedDebuggerTest {
term.addTerminalListener(new TerminalListener() {
@Override
public void resized(short cols, short rows) {
// System.err.println("resized: " + cols + "x" + rows);
child.setWindowSize(cols, rows);
}
});
@@ -38,6 +38,7 @@ import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.listing.Program;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.util.Msg;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -81,7 +82,7 @@ public class ProjectInfoDialogTest extends AbstractGhidraHeadedIntegrationTest {
RepositoryAdapter rep = null;
try {
// this can throw a NotConnectedException
System.err.println(getClass().getName() + "\tstarting server...");
Msg.info(this, getClass().getName() + "\tstarting server...");
rep = SharedProjectUtil.startServer();
}
catch (Exception e) {
@@ -99,9 +100,9 @@ public class ProjectInfoDialogTest extends AbstractGhidraHeadedIntegrationTest {
try {
DockingActionIf saveAction = getAction("Save Project");
System.err.println("\tsaving project");
Msg.info(this, "\tsaving project");
performAction(saveAction, true);
System.err.println("\tclosing project");
Msg.info(this, "\tclosing project");
DockingActionIf action = getAction("Close Project");
performAction(action, true);
}
@@ -112,21 +113,21 @@ public class ProjectInfoDialogTest extends AbstractGhidraHeadedIntegrationTest {
}
private void cleanupResources() throws Exception {
System.err.println(getClass().getName() + ".cleanupResources()...");
Msg.info(this, getClass().getName() + ".cleanupResources()...");
try {
System.err.println(getClass().getName() + "\tdisposing...");
Msg.info(this, getClass().getName() + "\tdisposing...");
env.dispose();
System.err.println(getClass().getName() + "\tstoring preferences...");
Msg.info(this, getClass().getName() + "\tstoring preferences...");
Preferences.setProperty("ServerInfo", null);
Preferences.store();
}
finally {
System.err.println(getClass().getName() + "\tdeleting server root...");
Msg.info(this, getClass().getName() + "\tdeleting server root...");
SharedProjectUtil.deleteServerRoot();
System.err.println(getClass().getName() + "\tdeleting test project...");
Msg.info(this, getClass().getName() + "\tdeleting test project...");
SharedProjectUtil.deleteTestProject("TestProject");
}
System.err.println(getClass().getName() + ".cleanupResources() done!s");
Msg.info(this, getClass().getName() + ".cleanupResources() done!s");
}
@Test
@@ -377,7 +378,7 @@ public class ProjectInfoDialogTest extends AbstractGhidraHeadedIntegrationTest {
}
private void stepThroughWizard(boolean doFinish, final String repositoryName) throws Exception {
System.err.println(getClass().getName() + ".stepThroughWizard()...");
Msg.info(this, getClass().getName() + ".stepThroughWizard()...");
windowForComponent(dialog.getComponent());
WizardDialog wm = waitForDialogComponent(WizardDialog.class);
assertNotNull(wm);
@@ -397,13 +398,13 @@ public class ProjectInfoDialogTest extends AbstractGhidraHeadedIntegrationTest {
portNumberField.setText(Integer.toString(SharedProjectUtil.SERVER_PORT));
});
System.err.println(getClass().getName() + ".stepThroughWizard()\tpressing next button...");
Msg.info(this, getClass().getName() + ".stepThroughWizard()\tpressing next button...");
pressButton(nextButton);
// next panel should be the repository panel
RepositoryPanel repPanel = findComponent(wm, RepositoryPanel.class);
System.err.println(
Msg.info(this,
getClass().getName() + ".stepThroughWizard()\tfound repPanel: " + repPanel);
final JList<?> repList = findComponent(repPanel, JList.class);
ListModel<?> model = repList.getModel();
@@ -429,6 +430,6 @@ public class ProjectInfoDialogTest extends AbstractGhidraHeadedIntegrationTest {
assertTrue("The wizard panel is not closed for some reason", !wm.isShowing());
System.err.println(getClass().getName() + ".stepThroughWizard() done!");
Msg.info(this, getClass().getName() + ".stepThroughWizard() done!");
}
}
@@ -35,6 +35,7 @@ import ghidra.framework.main.wizard.project.*;
import ghidra.framework.model.*;
import ghidra.server.remote.ServerTestUtil;
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
import ghidra.util.Msg;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.UserAccessException;
import utilities.util.FileUtilities;
@@ -63,7 +64,8 @@ public class SharedProjectUtil {
public static boolean createSharedProject(FrontEndTool frontEndTool, final String projectName)
throws Exception {
// create shared project against existing repository
System.err.println("SharedProjectUtil.createSharedProject(): " + projectName);
Msg.info(SharedProjectUtil.class,
"SharedProjectUtil.createSharedProject(): " + projectName);
UtilProjectListener projectListener = new UtilProjectListener();
frontEndTool.addProjectListener(projectListener);
@@ -130,7 +132,7 @@ public class SharedProjectUtil {
AbstractGuiTest.pressButton(finishButton, true);
AbstractGuiTest.waitForSwing();
boolean didOpen = waitForProjectToOpen(projectName, projectListener);
System.err.println("\tdid the project get opened?: " + didOpen);
Msg.info(SharedProjectUtil.class, "\tdid the project get opened?: " + didOpen);
return didOpen;
}
@@ -148,7 +150,8 @@ public class SharedProjectUtil {
AbstractGuiTest.waitForSwing();
boolean success = desiredProjectName.equals(lastOpenedProjectName);
if (!success) {
System.err.println("\tOpen windows: " + AbstractDockingTest.getOpenWindowsAsString());
Msg.info(SharedProjectUtil.class,
"\tOpen windows: " + AbstractDockingTest.getOpenWindowsAsString());
}
return success;
@@ -167,14 +170,14 @@ public class SharedProjectUtil {
Thread.sleep(50);
}
catch (InterruptedException e) {
e.printStackTrace();
Msg.error(SharedProjectUtil.class, e, e);
}
AbstractGhidraHeadlessIntegrationTest.deleteProject(projectDirectory.getAbsolutePath(),
projectName);
}
if (count > 500) {
System.err.println("Could not delete " + projectName);
Msg.warn(SharedProjectUtil.class, "Could not delete " + projectName);
return false;
}
return true;
@@ -192,7 +195,7 @@ public class SharedProjectUtil {
* @throws Exception if there are any exceptions starting the server
*/
public static RepositoryAdapter startServer() throws Exception {
System.err.println("SharedProjectUtil.startServer()...");
Msg.info(SharedProjectUtil.class, "SharedProjectUtil.startServer()...");
repositoryServer = null;
File parent = new File(AbstractGTest.getTestDirectoryPath());
@@ -200,16 +203,19 @@ public class SharedProjectUtil {
serverRoot = new File(parent, "My_Server");
FileUtilities.deleteDir(serverRoot);
System.err.println("SharedProjectUtil.startServer()\tgetting server adapter...");
Msg.info(SharedProjectUtil.class,
"SharedProjectUtil.startServer()\tgetting server adapter...");
repositoryServer = ServerTestUtil.getServerAdapter(serverRoot, new String[] { USER });
System.err.println("SharedProjectUtil.startServer()\tchecking connection...");
Msg.info(SharedProjectUtil.class,
"SharedProjectUtil.startServer()\tchecking connection...");
if (repositoryServer == null || !repositoryServer.isConnected()) {
deleteServerRoot();
fail("Server connect failed");
}
System.err.println("SharedProjectUtil.startServer()\tcreating repository...");
Msg.info(SharedProjectUtil.class,
"SharedProjectUtil.startServer()\tcreating repository...");
return repositoryServer.createRepository("My_Repository");
}
@@ -243,12 +249,14 @@ public class SharedProjectUtil {
@Override
public void projectClosed(Project project) {
System.err.println(getClass().getSimpleName() + ".projectClosed(): " + project);
Msg.info(UtilProjectListener.class,
getClass().getSimpleName() + ".projectClosed(): " + project);
}
@Override
public void projectOpened(Project project) {
System.err.println(getClass().getSimpleName() + ".projectOpened(): " + project);
Msg.info(UtilProjectListener.class,
getClass().getSimpleName() + ".projectOpened(): " + project);
lastOpenedProjectName = project.getName();
}
@@ -23,7 +23,8 @@ import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.TreePath;
import org.junit.*;
@@ -273,20 +274,6 @@ public class FrontEndPluginOpenProgramActionsTest extends AbstractGhidraHeadedIn
// make sure that the tool is loaded and processes all of the tasks it launches
Window window = waitForToolLaunch();
// DEBUG:
if (window == null) {
// see if any tools have been launched
PluginTool[] runningTools = frontEndTool.getToolServices().getRunningTools();
for (PluginTool tool : runningTools) {
System.err.println("\t\"" + tool.getName() + "\"");
JFrame toolFrame = tool.getToolFrame();
System.err.println("\t\twith window: " + toolFrame.getTitle());
}
System.err.println("Open Windows: ");
System.err.println(getOpenWindowsAsString());
}
assertNotNull(window);
waitForBusyTool(env.getProject().getToolManager().getRunningTools()[0]);
waitForTasks();
@@ -15,8 +15,7 @@
*/
package ghidra.pcode.emu.jit.gen;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import java.io.*;
import java.lang.invoke.MethodHandles;
@@ -52,8 +51,7 @@ import ghidra.program.model.lang.*;
import ghidra.program.model.pcode.PcodeOp;
import ghidra.program.model.pcode.Varnode;
import ghidra.program.util.DefaultLanguageService;
import ghidra.util.NumericUtilities;
import ghidra.util.SystemUtilities;
import ghidra.util.*;
@SuppressWarnings("javadoc")
public abstract class AbstractJitCodeGeneratorTest extends AbstractJitTest {
@@ -69,7 +67,7 @@ public abstract class AbstractJitCodeGeneratorTest extends AbstractJitTest {
if (!DEBUG_ENABLED) {
return;
}
System.out.println(program);
Msg.debug(AbstractJitCodeGeneratorTest.class, program);
}
public static void dumpClass(byte[] classbytes) throws Exception {
@@ -287,7 +285,6 @@ public abstract class AbstractJitCodeGeneratorTest extends AbstractJitTest {
@PcodeUserop(functional = true)
public int tap_int(int a) {
System.err.println("tap: %x".formatted(a));
return a;
}
}
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,8 +15,7 @@
*/
package ghidra.util.task;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.awt.Container;
import java.util.Random;
@@ -412,7 +411,7 @@ public class RunManagerTest extends AbstractGhidraHeadedIntegrationTest {
}
private void trace(String message) {
System.err.println(message);
Msg.debug(this, message);
}
//==================================================================================================
@@ -442,8 +441,7 @@ public class RunManagerTest extends AbstractGhidraHeadedIntegrationTest {
startBarrier.await();
}
catch (Exception e1) {
System.err.println("Interrupted while waiting to begin: " + getName());
e1.printStackTrace();
Msg.error(this, "Interrupted while waiting to begin: " + getName(), e1);
}
int runnableCount = random.nextInt(MAX_RUNNABLES_FROM_THREAD);
@@ -534,9 +532,8 @@ public class RunManagerTest extends AbstractGhidraHeadedIntegrationTest {
delayLatch.await();
}
catch (Exception e) {
System.err.println(
"Interrupted while waiting to begin: " + testName.getMethodName());
e.printStackTrace();
Msg.error(this,
"Interrupted while waiting to begin: " + testName.getMethodName(), e);
}
try {
@@ -58,6 +58,7 @@ public class LaunchSupport {
// Validate command line arguments
if (args.length < 2 || args.length > 4) {
// Logging has not been initialized and is not available to use
System.err.println("LaunchSupport expected 2 to 4 arguments but got " + args.length);
System.exit(exitCode);
}