Commit 75d8a01c authored by Skylot's avatar Skylot

core: improve error reporting

parent 0968f75e
...@@ -252,8 +252,8 @@ public class ClassGen { ...@@ -252,8 +252,8 @@ public class ClassGen {
} }
private void addMethod(CodeWriter code, MethodNode mth) throws CodegenException { private void addMethod(CodeWriter code, MethodNode mth) throws CodegenException {
MethodGen mthGen = new MethodGen(this, mth);
if (mth.getAccessFlags().isAbstract() || mth.getAccessFlags().isNative()) { if (mth.getAccessFlags().isAbstract() || mth.getAccessFlags().isNative()) {
MethodGen mthGen = new MethodGen(this, mth);
mthGen.addDefinition(code); mthGen.addDefinition(code);
if (cls.getAccessFlags().isAnnotation()) { if (cls.getAccessFlags().isAnnotation()) {
Object def = annotationGen.getAnnotationDefaultValue(mth.getName()); Object def = annotationGen.getAnnotationDefaultValue(mth.getName());
...@@ -270,6 +270,12 @@ public class ClassGen { ...@@ -270,6 +270,12 @@ public class ClassGen {
code.startLine("/* Code decompiled incorrectly, please refer to instructions dump. */"); code.startLine("/* Code decompiled incorrectly, please refer to instructions dump. */");
ErrorsCounter.methodError(mth, "Inconsistent code"); ErrorsCounter.methodError(mth, "Inconsistent code");
} }
MethodGen mthGen;
if (badCode || mth.contains(AType.JADX_ERROR)) {
mthGen = MethodGen.getFallbackMethodGen(mth);
} else {
mthGen = new MethodGen(this, mth);
}
if (mthGen.addDefinition(code)) { if (mthGen.addDefinition(code)) {
code.add(' '); code.add(' ');
} }
......
...@@ -9,7 +9,6 @@ import jadx.core.dex.instructions.args.ArgType; ...@@ -9,7 +9,6 @@ import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.RegisterArg; import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.Region;
import jadx.core.dex.trycatch.CatchAttr; import jadx.core.dex.trycatch.CatchAttr;
import jadx.core.dex.visitors.DepthTraversal; import jadx.core.dex.visitors.DepthTraversal;
import jadx.core.dex.visitors.FallbackModeVisitor; import jadx.core.dex.visitors.FallbackModeVisitor;
...@@ -151,11 +150,14 @@ public class MethodGen { ...@@ -151,11 +150,14 @@ public class MethodGen {
} }
public void addInstructions(CodeWriter code) throws CodegenException { public void addInstructions(CodeWriter code) throws CodegenException {
if (mth.contains(AType.JADX_ERROR)) { if (mth.contains(AType.JADX_ERROR)
code.startLine("throw new UnsupportedOperationException(\"Method not decompiled: "); || mth.contains(AFlag.INCONSISTENT_CODE)
code.add(mth.toString()); || mth.getRegion() == null) {
code.add("\");"); code.startLine("throw new UnsupportedOperationException(\"Method not decompiled: ")
.add(mth.toString())
.add("\");");
if (mth.contains(AType.JADX_ERROR)) {
JadxErrorAttr err = mth.get(AType.JADX_ERROR); JadxErrorAttr err = mth.get(AType.JADX_ERROR);
code.startLine("/* JADX: method processing error */"); code.startLine("/* JADX: method processing error */");
Throwable cause = err.getCause(); Throwable cause = err.getCause();
...@@ -165,33 +167,14 @@ public class MethodGen { ...@@ -165,33 +167,14 @@ public class MethodGen {
code.startLine("Error: ").add(Utils.getStackTrace(cause)); code.startLine("Error: ").add(Utils.getStackTrace(cause));
code.add("*/"); code.add("*/");
} }
makeMethodDump(code); }
} else if (mth.contains(AFlag.INCONSISTENT_CODE)) {
code.startLine("/*"); code.startLine("/*");
addFallbackMethodCode(code); addFallbackMethodCode(code);
code.startLine("*/"); code.startLine("*/");
code.newLine();
} else { } else {
Region startRegion = mth.getRegion(); RegionGen regionGen = new RegionGen(this);
if (startRegion != null) { regionGen.makeRegion(code, mth.getRegion());
(new RegionGen(this)).makeRegion(code, startRegion);
} else {
addFallbackMethodCode(code);
}
}
} }
private void makeMethodDump(CodeWriter code) {
code.startLine("/*");
getFallbackMethodGen(mth).addDefinition(code);
code.add(" {");
code.incIndent();
addFallbackMethodCode(code);
code.decIndent();
code.startLine('}');
code.startLine("*/");
} }
public void addFallbackMethodCode(CodeWriter code) { public void addFallbackMethodCode(CodeWriter code) {
...@@ -212,7 +195,7 @@ public class MethodGen { ...@@ -212,7 +195,7 @@ public class MethodGen {
return; return;
} }
if (mth.getThisArg() != null) { if (mth.getThisArg() != null) {
code.startLine(getFallbackMethodGen(mth).nameGen.useArg(mth.getThisArg())).add(" = this;"); code.startLine(nameGen.useArg(mth.getThisArg())).add(" = this;");
} }
addFallbackInsns(code, mth, insnArr, true); addFallbackInsns(code, mth, insnArr, true);
} }
...@@ -248,7 +231,7 @@ public class MethodGen { ...@@ -248,7 +231,7 @@ public class MethodGen {
/** /**
* Return fallback variant of method codegen * Return fallback variant of method codegen
*/ */
private static MethodGen getFallbackMethodGen(MethodNode mth) { static MethodGen getFallbackMethodGen(MethodNode mth) {
ClassGen clsGen = new ClassGen(mth.getParentClass(), null, true); ClassGen clsGen = new ClassGen(mth.getParentClass(), null, true);
return new MethodGen(clsGen, mth); return new MethodGen(clsGen, mth);
} }
......
...@@ -91,7 +91,7 @@ public class NameGen { ...@@ -91,7 +91,7 @@ public class NameGen {
String name = arg.getName(); String name = arg.getName();
if (fallback) { if (fallback) {
String base = "r" + arg.getRegNum(); String base = "r" + arg.getRegNum();
if (name != null) { if (name != null && !name.equals("this")) {
return base + "_" + name; return base + "_" + name;
} }
return base; return base;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment