-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
GraxCode
committed
Apr 23, 2020
1 parent
69cb5b3
commit 8f3e35d
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/me/nov/threadtear/execution/tools/LogAllExceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package me.nov.threadtear.execution.tools; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
|
||
import me.nov.threadtear.execution.Clazz; | ||
import me.nov.threadtear.execution.Execution; | ||
import me.nov.threadtear.execution.ExecutionCategory; | ||
import me.nov.threadtear.execution.ExecutionTag; | ||
import me.nov.threadtear.util.asm.Instructions; | ||
|
||
public class LogAllExceptions extends Execution { | ||
|
||
public LogAllExceptions() { | ||
super(ExecutionCategory.TOOLS, "Log all exceptions", "Adds .printStackTrace() in every try catch block handler.", ExecutionTag.RUNNABLE); | ||
} | ||
|
||
@Override | ||
public boolean execute(Map<String, Clazz> classes, boolean verbose) { | ||
classes.values().stream().map(c -> c.node.methods).flatMap(List::stream).forEach(m -> { | ||
if (m.tryCatchBlocks == null) | ||
return; | ||
m.tryCatchBlocks.forEach(tcb -> { | ||
AbstractInsnNode handler = Instructions.getRealNext(tcb.handler); | ||
m.instructions.insertBefore(handler, new InsnNode(DUP)); | ||
m.instructions.insertBefore(handler, new MethodInsnNode(INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V")); | ||
}); | ||
m.maxStack = Math.max(m.maxStack, 2); | ||
}); | ||
logger.info("Inserted .printStackTrace() in every catch block!"); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters