Skip to content

Commit

Permalink
fix: add more details for variable with type inference error
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Dec 25, 2018
1 parent 76cf4f0 commit 2dea6f5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package jadx.core.dex.instructions.args;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.AttrNode;
import jadx.core.dex.attributes.nodes.RegDebugInfoAttr;
import jadx.core.dex.instructions.PhiInsn;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.visitors.typeinference.TypeInfo;

public class SSAVar extends AttrNode {
Expand Down Expand Up @@ -146,4 +152,44 @@ public int hashCode() {
public String toString() {
return "r" + regNum + ":" + version + " " + typeInfo.getType();
}

public String getDetailedVarInfo(MethodNode mth) {
Set<ArgType> types = new HashSet<>();
Set<String> names = Collections.emptySet();

List<RegisterArg> useArgs = new ArrayList<>(1 + useList.size());
useArgs.add(assign);
useArgs.addAll(useList);

if (mth.contains(AType.LOCAL_VARS_DEBUG_INFO)) {
names = new HashSet<>();
for (RegisterArg arg : useArgs) {
RegDebugInfoAttr debugInfoAttr = arg.get(AType.REG_DEBUG_INFO);
if (debugInfoAttr != null) {
names.add(debugInfoAttr.getName());
types.add(debugInfoAttr.getRegType());
}
}
}

for (RegisterArg arg : useArgs) {
ArgType initType = arg.getInitType();
if (initType.isTypeKnown()) {
types.add(initType);
}
ArgType type = arg.getType();
if (type.isTypeKnown()) {
types.add(type);
}
}
StringBuilder sb = new StringBuilder();
sb.append('r').append(regNum).append('v').append(version);
if (!names.isEmpty()) {
sb.append(", names: ").append(names);
}
if (!types.isEmpty()) {
sb.append(", types: ").append(types);
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void visit(MethodNode mth) {
if (type != null && !type.isTypeKnown()) {
boolean changed = tryAllTypes(var, type);
if (!changed) {
mth.addComment("JADX WARNING: type inference failed for: " + var + ", bounds: " + typeInfo.getBounds());
mth.addComment("JADX WARNING: type inference failed for: " + var.getDetailedVarInfo(mth));
}
}
});
Expand Down

0 comments on commit 2dea6f5

Please sign in to comment.