Search in sources :

Example 1 with LineNumberTableAttr

use of jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr in project jadx by skylot.

the class JavaCodeReader method getDebugInfo.

@Override
@Nullable
public IDebugInfo getDebugInfo() {
    int maxStack = readMaxStack();
    reader.skip(2);
    reader.skip(reader.readU4());
    reader.skip(reader.readU2() * 8);
    JavaAttrStorage attrs = clsData.getAttributesReader().load(reader);
    LineNumberTableAttr linesAttr = attrs.get(JavaAttrType.LINE_NUMBER_TABLE);
    LocalVarsAttr varsAttr = attrs.get(JavaAttrType.LOCAL_VAR_TABLE);
    if (linesAttr == null && varsAttr == null) {
        return null;
    }
    Map<Integer, Integer> linesMap = linesAttr != null ? linesAttr.getLineMap() : Collections.emptyMap();
    List<ILocalVar> vars;
    if (varsAttr == null) {
        vars = Collections.emptyList();
    } else {
        List<JavaLocalVar> javaVars = varsAttr.getVars();
        LocalVarTypesAttr typedVars = attrs.get(JavaAttrType.LOCAL_VAR_TYPE_TABLE);
        if (typedVars != null && !typedVars.getVars().isEmpty()) {
            // merge signature from typedVars into javaVars
            Map<JavaLocalVar, JavaLocalVar> varsMap = new HashMap<>(javaVars.size());
            javaVars.forEach(v -> varsMap.put(v, v));
            for (JavaLocalVar typedVar : typedVars.getVars()) {
                JavaLocalVar jv = varsMap.get(typedVar);
                if (jv != null) {
                    jv.setSignature(typedVar.getSignature());
                }
            }
        }
        javaVars.forEach(v -> v.shiftRegNum(maxStack));
        vars = Collections.unmodifiableList(javaVars);
    }
    return new DebugInfo(linesMap, vars);
}
Also used : LocalVarTypesAttr(jadx.plugins.input.java.data.attributes.debuginfo.LocalVarTypesAttr) HashMap(java.util.HashMap) LocalVarsAttr(jadx.plugins.input.java.data.attributes.debuginfo.LocalVarsAttr) LineNumberTableAttr(jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr) ILocalVar(jadx.api.plugins.input.data.ILocalVar) JavaLocalVar(jadx.plugins.input.java.data.attributes.debuginfo.JavaLocalVar) JavaAttrStorage(jadx.plugins.input.java.data.attributes.JavaAttrStorage) DebugInfo(jadx.api.plugins.input.data.impl.DebugInfo) IDebugInfo(jadx.api.plugins.input.data.IDebugInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IDebugInfo (jadx.api.plugins.input.data.IDebugInfo)1 ILocalVar (jadx.api.plugins.input.data.ILocalVar)1 DebugInfo (jadx.api.plugins.input.data.impl.DebugInfo)1 JavaAttrStorage (jadx.plugins.input.java.data.attributes.JavaAttrStorage)1 JavaLocalVar (jadx.plugins.input.java.data.attributes.debuginfo.JavaLocalVar)1 LineNumberTableAttr (jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr)1 LocalVarTypesAttr (jadx.plugins.input.java.data.attributes.debuginfo.LocalVarTypesAttr)1 LocalVarsAttr (jadx.plugins.input.java.data.attributes.debuginfo.LocalVarsAttr)1 HashMap (java.util.HashMap)1 Nullable (org.jetbrains.annotations.Nullable)1