Skip to content

Commit

Permalink
Various warning fixes in debug examples
Browse files Browse the repository at this point in the history
Reduces compiler warnings in workspace and I-build reports.
  • Loading branch information
akurtakov committed Jan 4, 2024
1 parent ec85999 commit 9e3779f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ void run() {

PDAThread[] threadsCopy = fThreads.values().toArray(new PDAThread[fThreads.size()]);
allThreadsSuspended = true;
for (int i = 0; i < threadsCopy.length; i++) {
PDAThread thread = threadsCopy[i];
for (PDAThread element : threadsCopy) {
PDAThread thread = element;
if (thread.fSuspend == null) {
allThreadsSuspended = false;

Expand Down Expand Up @@ -562,33 +562,33 @@ void doOneInstruction(PDAThread thread, String instr) {

boolean opValid = true;
if (op.equals("add")) { //$NON-NLS-1$
iAdd(thread, args);
iAdd(thread);
} else if (op.equals("branch_not_zero")) { //$NON-NLS-1$
iBranchNotZero(thread, args);
} else if (op.equals("call")) { //$NON-NLS-1$
iCall(thread, args);
} else if (op.equals("dec")) { //$NON-NLS-1$
iDec(thread, args);
iDec(thread);
} else if (op.equals("def")) { //$NON-NLS-1$
iDef(thread, args);
iDef(args);
} else if (op.equals("dup")) { //$NON-NLS-1$
iDup(thread, args);
iDup(thread);
} else if (op.equals("exec")) { //$NON-NLS-1$
iExec(thread, args);
} else if (op.equals("halt")) { //$NON-NLS-1$
iHalt(thread, args);
iHalt(thread);
} else if (op.equals("output")) { //$NON-NLS-1$
iOutput(thread, args);
iOutput(thread);
} else if (op.equals("pop")) { //$NON-NLS-1$
iPop(thread, args);
} else if (op.equals("push")) { //$NON-NLS-1$
iPush(thread, args);
} else if (op.equals("return")) { //$NON-NLS-1$
iReturn(thread, args);
iReturn(thread);
} else if (op.equals("var")) { //$NON-NLS-1$
iVar(thread, args);
} else if (op.equals("xyzzy")) { //$NON-NLS-1$
iInternalEndEval(thread, args);
iInternalEndEval(thread);
} else if (op.startsWith(":")) {} // label //$NON-NLS-1$
else if (op.startsWith("#")) {} // comment //$NON-NLS-1$
else {
Expand All @@ -614,8 +614,7 @@ else if (op.startsWith("#")) {} // comment //$NON-NLS-1$

void checkForBreakpoint() {
if (fDebug) {
for (Iterator<PDAThread> itr = fThreads.values().iterator(); itr.hasNext();) {
PDAThread thread = itr.next();
for (PDAThread thread : fThreads.values()) {
Integer pc = Integer.valueOf(thread.fCurrentFrame.fPC);
// Suspend for breakpoint if:
// - the VM is not yet set to suspend, for e.g. as a result of step end,
Expand Down Expand Up @@ -669,8 +668,7 @@ void debugUI() {
// Clear all stepping flags. In case the VM suspended while
// a step operation was being performed for the VM or some thread.
fStepVM = fStepReturnVM = false;
for (Iterator<PDAThread> itr = fThreads.values().iterator(); itr.hasNext();) {
PDAThread thread = itr.next();
for (PDAThread thread : fThreads.values()) {
thread.fSuspend = null;
thread.fStep = thread.fStepReturn = thread.fPerformingEval = false;
}
Expand Down Expand Up @@ -722,15 +720,15 @@ void processDebugCommand(String line) {
} else if ("frame".equals(command)) { //$NON-NLS-1$
debugFrame(args);
} else if ("groups".equals(command)) { //$NON-NLS-1$
debugGroups(args);
debugGroups();
} else if ("popdata".equals(command)) { //$NON-NLS-1$
debugPopData(args);
} else if ("pushdata".equals(command)) { //$NON-NLS-1$
debugPushData(args);
} else if ("registers".equals(command)) { //$NON-NLS-1$
debugRegisters(args);
} else if ("restart".equals(command)) { //$NON-NLS-1$
debugRestart(args);
debugRestart();
} else if ("resume".equals(command)) { //$NON-NLS-1$
debugResume(args);
} else if ("set".equals(command)) { //$NON-NLS-1$
Expand Down Expand Up @@ -783,8 +781,7 @@ void debugChildren(Args args) {

String varDot = var + "."; //$NON-NLS-1$
List<String> children = new ArrayList<>();
for (Iterator<String> itr = frame.fLocalVariables.keySet().iterator(); itr.hasNext();) {
String localVar = itr.next();
for (String localVar : frame.fLocalVariables.keySet()) {
if (localVar.startsWith(varDot) && localVar.indexOf('.', varDot.length() + 1) == -1) {
children.add(localVar);
}
Expand Down Expand Up @@ -932,10 +929,9 @@ void debugFrame(Args args) {
sendCommandResponse(printFrame(frame) + "\n"); //$NON-NLS-1$
}

void debugGroups(Args args) {
void debugGroups() {
TreeSet<String> groups = new TreeSet<>();
for (Iterator<Register> itr = fRegisters.values().iterator(); itr.hasNext();) {
Register reg = itr.next();
for (Register reg : fRegisters.values()) {
groups.add(reg.fGroup);
}
StringBuilder response = new StringBuilder();
Expand Down Expand Up @@ -974,23 +970,20 @@ void debugRegisters(Args args) {
String group = args.getNextStringArg();

StringBuilder response = new StringBuilder();
for (Iterator<Register> itr = fRegisters.values().iterator(); itr.hasNext();) {
Register reg = itr.next();
for (Register reg : fRegisters.values()) {
if (group.equals(reg.fGroup)) {
response.append(reg.fName);
response.append(' ');
response.append(reg.fIsWriteable);
for (Iterator<BitField> itr2 = reg.fBitFields.values().iterator(); itr2.hasNext();) {
BitField bitField = itr2.next();
for (BitField bitField : reg.fBitFields.values()) {
response.append('|');
response.append(bitField.fName);
response.append(' ');
response.append(bitField.fBitOffset);
response.append(' ');
response.append(bitField.fBitCount);
response.append(' ');
for (Iterator<Entry<String, Integer>> itr3 = bitField.fMnemonics.entrySet().iterator(); itr3.hasNext();) {
Entry<String, Integer> mnemonicEntry = itr3.next();
for (Entry<String, Integer> mnemonicEntry : bitField.fMnemonics.entrySet()) {
response.append(mnemonicEntry.getKey());
response.append(' ');
response.append(mnemonicEntry.getValue());
Expand All @@ -1005,11 +998,10 @@ void debugRegisters(Args args) {
sendCommandResponse(response.toString());
}

void debugRestart(Args args) {
void debugRestart() {
fSuspendVM = "restart"; //$NON-NLS-1$

for (Iterator<Integer> itr = fThreads.keySet().iterator(); itr.hasNext();) {
Integer id = itr.next();
for (Integer id : fThreads.keySet()) {
sendDebugEvent("exited " + id, false); //$NON-NLS-1$
}
fThreads.clear();
Expand Down Expand Up @@ -1101,8 +1093,7 @@ void debugStack(Args args) {

StringBuilder result = new StringBuilder();

for (Iterator<Frame> itr = thread.fFrames.iterator(); itr.hasNext();) {
Frame frame = itr.next();
for (Frame frame : thread.fFrames) {
result.append(printFrame(frame));
result.append('#');
}
Expand Down Expand Up @@ -1132,8 +1123,7 @@ private String printFrame(Frame frame) {
buf.append(frame.fPC);
buf.append('|');
buf.append(frame.fFunction);
for (Iterator<String> itr = frame.fLocalVariables.keySet().iterator(); itr.hasNext();) {
String var = itr.next();
for (String var : frame.fLocalVariables.keySet()) {
if (var.indexOf('.') == -1) {
buf.append('|');
buf.append(var);
Expand Down Expand Up @@ -1287,12 +1277,12 @@ void debugWatch(Args args) {
sendCommandResponse("ok\n"); //$NON-NLS-1$
}

void iAdd(PDAThread thread, Args args) {
void iAdd(PDAThread thread) {
Object val1 = thread.fStack.pop();
Object val2 = thread.fStack.pop();
if (val1 instanceof Integer && val2 instanceof Integer) {
int intVal1 = ((Integer) val1).intValue();
int intVal2 = ((Integer) val2).intValue();
if (val1 instanceof Integer int1 && val2 instanceof Integer int2) {
int intVal1 = int1.intValue();
int intVal2 = int2.intValue();
thread.fStack.push( Integer.valueOf(intVal1 + intVal2) );
} else {
thread.fStack.push( Integer.valueOf(-1) );
Expand Down Expand Up @@ -1330,15 +1320,15 @@ void iCall(PDAThread thread, Args args) {
}
}

void iDec(PDAThread thread, Args args) {
void iDec(PDAThread thread) {
Object val = thread.fStack.pop();
if (val instanceof Integer) {
val = Integer.valueOf(((Integer) val).intValue() - 1);
}
thread.fStack.push(val);
}

void iDef(PDAThread thread, Args args) {
void iDef(Args args) {
String type = args.getNextStringArg();

String name = args.getNextStringArg();
Expand Down Expand Up @@ -1390,7 +1380,7 @@ private String getBitFieldPartOfName(String name) {
return null;
}

void iDup(PDAThread thread, Args args) {
void iDup(PDAThread thread) {
Object val = thread.fStack.pop();
thread.fStack.push(val);
thread.fStack.push(val);
Expand All @@ -1411,11 +1401,11 @@ void iExec(PDAThread thread, Args args) {
}
}

void iHalt(PDAThread thread, Args args) {
void iHalt(PDAThread thread) {
thread.fRun = false;
}

void iOutput(PDAThread thread, Args args) {
void iOutput(PDAThread thread) {
System.out.println(thread.fStack.pop());
}

Expand Down Expand Up @@ -1467,7 +1457,7 @@ void iPush(PDAThread thread, Args args) {
}
}

void iReturn(PDAThread thread, Args args) {
void iReturn(PDAThread thread) {
if (!thread.fFrames.isEmpty()) {
thread.fCurrentFrame = thread.fFrames.remove(thread.fFrames.size() - 1);
} else {
Expand All @@ -1482,7 +1472,7 @@ void iVar(PDAThread thread, Args args) {
thread.fCurrentFrame.set(var, Integer.valueOf(0));
}

void iInternalEndEval(PDAThread thread, Args args) {
void iInternalEndEval(PDAThread thread) {
Object result = thread.fStack.pop();
thread.fThreadCode = fCode;
thread.fThreadLabels = fLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ public boolean supportsBreakpoint(IBreakpoint breakpoint) {
String program = getLaunch().getLaunchConfiguration().getAttribute(DebugCorePlugin.ATTR_PDA_PROGRAM, (String)null);
if (program != null) {
IResource resource = null;
if (breakpoint instanceof PDARunToLineBreakpoint) {
PDARunToLineBreakpoint rtl = (PDARunToLineBreakpoint) breakpoint;
if (breakpoint instanceof PDARunToLineBreakpoint rtl) {
resource = rtl.getSourceFile();
} else {
IMarker marker = breakpoint.getMarker();
Expand Down Expand Up @@ -375,7 +374,7 @@ public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugE
* Notification we have connected to the VM and it has started.
* Resume the VM.
*/
private void vmStarted(PDAVMStartedEvent event) {
private void vmStarted() {
fireCreationEvent();
installDeferredBreakpoints();
try {
Expand Down Expand Up @@ -496,18 +495,18 @@ public void breakpointManagerEnablementChanged(boolean enabled) {

@Override
public void handleEvent(PDAEvent event) {
if (event instanceof PDAStartedEvent) {
started((PDAStartedEvent)event);
} else if (event instanceof PDAExitedEvent) {
exited((PDAExitedEvent)event);
if (event instanceof PDAStartedEvent startedEvent) {
started(startedEvent);
} else if (event instanceof PDAExitedEvent exitedEvent) {
exited(exitedEvent);
} else if (event instanceof PDAVMStartedEvent) {
vmStarted((PDAVMStartedEvent)event);
vmStarted();
} else if (event instanceof PDAVMTerminatedEvent) {
vmTerminated();
} else if (event instanceof PDAVMSuspendedEvent) {
vmSuspended((PDAVMSuspendedEvent)event);
} else if (event instanceof PDAVMResumedEvent) {
vmResumed((PDAVMResumedEvent)event);
} else if (event instanceof PDAVMSuspendedEvent suspendedEvent) {
vmSuspended(suspendedEvent);
} else if (event instanceof PDAVMResumedEvent resumedEvent) {
vmResumed(resumedEvent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public String getModelIdentifier() {
public IMemoryBlockExtension getExtendedMemoryBlock(String expression, Object context) throws DebugException {

// ask debug engine for an address
BigInteger address = getEngine().evaluateExpression(expression, context);
BigInteger address = getEngine().evaluateExpression(expression);

// if address can be evaluated to an address, create memory block
if (address != null) {
Expand Down
Loading

0 comments on commit 9e3779f

Please sign in to comment.