Search in sources :

Example 16 with StdTypeList

use of com.android.dx.rop.type.StdTypeList in project buck by facebook.

the class DebugInfoDecoder method decode0.

private void decode0() throws IOException {
    ByteInput bs = new ByteArrayByteInput(encoded);
    line = Leb128.readUnsignedLeb128(bs);
    int szParams = Leb128.readUnsignedLeb128(bs);
    StdTypeList params = desc.getParameterTypes();
    int curReg = getParamBase();
    if (szParams != params.size()) {
        throw new RuntimeException("Mismatch between parameters_size and prototype");
    }
    if (!isStatic) {
        // Start off with implicit 'this' entry
        LocalEntry thisEntry = new LocalEntry(0, true, curReg, thisStringIdx, 0, 0);
        locals.add(thisEntry);
        lastEntryForReg[curReg] = thisEntry;
        curReg++;
    }
    for (int i = 0; i < szParams; i++) {
        Type paramType = params.getType(i);
        LocalEntry le;
        int nameIdx = readStringIndex(bs);
        if (nameIdx == -1) {
            /*
                 * Unnamed parameter; often but not always filled in by an
                 * extended start op after the prologue
                 */
            le = new LocalEntry(0, true, curReg, -1, 0, 0);
        } else {
            // TODO: Final 0 should be idx of paramType.getDescriptor().
            le = new LocalEntry(0, true, curReg, nameIdx, 0, 0);
        }
        locals.add(le);
        lastEntryForReg[curReg] = le;
        curReg += paramType.getCategory();
    }
    for (; ; ) {
        int opcode = bs.readByte() & 0xff;
        switch(opcode) {
            case DBG_START_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    int nameIdx = readStringIndex(bs);
                    int typeIdx = readStringIndex(bs);
                    LocalEntry le = new LocalEntry(address, true, reg, nameIdx, typeIdx, 0);
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_START_LOCAL_EXTENDED:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    int nameIdx = readStringIndex(bs);
                    int typeIdx = readStringIndex(bs);
                    int sigIdx = readStringIndex(bs);
                    LocalEntry le = new LocalEntry(address, true, reg, nameIdx, typeIdx, sigIdx);
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_RESTART_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    LocalEntry prevle;
                    LocalEntry le;
                    try {
                        prevle = lastEntryForReg[reg];
                        if (prevle.isStart) {
                            throw new RuntimeException("nonsensical " + "RESTART_LOCAL on live register v" + reg);
                        }
                        le = new LocalEntry(address, true, reg, prevle.nameIndex, prevle.typeIndex, 0);
                    } catch (NullPointerException ex) {
                        throw new RuntimeException("Encountered RESTART_LOCAL on new v" + reg);
                    }
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_END_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    LocalEntry prevle;
                    LocalEntry le;
                    try {
                        prevle = lastEntryForReg[reg];
                        if (!prevle.isStart) {
                            throw new RuntimeException("nonsensical " + "END_LOCAL on dead register v" + reg);
                        }
                        le = new LocalEntry(address, false, reg, prevle.nameIndex, prevle.typeIndex, prevle.signatureIndex);
                    } catch (NullPointerException ex) {
                        throw new RuntimeException("Encountered END_LOCAL on new v" + reg);
                    }
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_END_SEQUENCE:
                // all done
                return;
            case DBG_ADVANCE_PC:
                address += Leb128.readUnsignedLeb128(bs);
                break;
            case DBG_ADVANCE_LINE:
                line += Leb128.readSignedLeb128(bs);
                break;
            case DBG_SET_PROLOGUE_END:
                //TODO do something with this.
                break;
            case DBG_SET_EPILOGUE_BEGIN:
                //TODO do something with this.
                break;
            case DBG_SET_FILE:
                //TODO do something with this.
                break;
            default:
                if (opcode < DBG_FIRST_SPECIAL) {
                    throw new RuntimeException("Invalid extended opcode encountered " + opcode);
                }
                int adjopcode = opcode - DBG_FIRST_SPECIAL;
                address += adjopcode / DBG_LINE_RANGE;
                line += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE);
                positions.add(new PositionEntry(address, line));
                break;
        }
    }
}
Also used : Type(com.android.dx.rop.type.Type) StdTypeList(com.android.dx.rop.type.StdTypeList) ByteArrayByteInput(com.android.dex.util.ByteArrayByteInput) ByteInput(com.android.dex.util.ByteInput) ByteArrayByteInput(com.android.dex.util.ByteArrayByteInput)

Example 17 with StdTypeList

use of com.android.dx.rop.type.StdTypeList in project buck by facebook.

the class DebugInfoEncoder method emitHeader.

/**
     * Emits the header sequence, which consists of LEB128-encoded initial
     * line number and string indicies for names of all non-"this" arguments.
     *
     * @param sortedPositions positions, sorted by ascending address
     * @param methodArgs local list entries for method argumens arguments,
     * in left-to-right order omitting "this"
     * @throws IOException
     */
private void emitHeader(ArrayList<PositionList.Entry> sortedPositions, ArrayList<LocalList.Entry> methodArgs) throws IOException {
    boolean annotate = (annotateTo != null) || (debugPrint != null);
    int mark = output.getCursor();
    // Start by initializing the line number register.
    if (sortedPositions.size() > 0) {
        PositionList.Entry entry = sortedPositions.get(0);
        line = entry.getPosition().getLine();
    }
    output.writeUleb128(line);
    if (annotate) {
        annotate(output.getCursor() - mark, "line_start: " + line);
    }
    int curParam = getParamBase();
    // paramTypes will not include 'this'
    StdTypeList paramTypes = desc.getParameterTypes();
    int szParamTypes = paramTypes.size();
    /*
         * Initialize lastEntryForReg to have an initial
         * entry for the 'this' pointer.
         */
    if (!isStatic) {
        for (LocalList.Entry arg : methodArgs) {
            if (curParam == arg.getRegister()) {
                lastEntryForReg[curParam] = arg;
                break;
            }
        }
        curParam++;
    }
    // Write out the number of parameter entries that will follow.
    mark = output.getCursor();
    output.writeUleb128(szParamTypes);
    if (annotate) {
        annotate(output.getCursor() - mark, String.format("parameters_size: %04x", szParamTypes));
    }
    /*
         * Then emit the string indicies of all the method parameters.
         * Note that 'this', if applicable, is excluded.
         */
    for (int i = 0; i < szParamTypes; i++) {
        Type pt = paramTypes.get(i);
        LocalList.Entry found = null;
        mark = output.getCursor();
        for (LocalList.Entry arg : methodArgs) {
            if (curParam == arg.getRegister()) {
                found = arg;
                if (arg.getSignature() != null) {
                    /*
                         * Parameters with signatures will be re-emitted
                         * in complete as LOCAL_START_EXTENDED's below.
                         */
                    emitStringIndex(null);
                } else {
                    emitStringIndex(arg.getName());
                }
                lastEntryForReg[curParam] = arg;
                break;
            }
        }
        if (found == null) {
            /*
                 * Emit a null symbol for "unnamed." This is common
                 * for, e.g., synthesized methods and inner-class
                 * this$0 arguments.
                 */
            emitStringIndex(null);
        }
        if (annotate) {
            String parameterName = (found == null || found.getSignature() != null) ? "<unnamed>" : found.getName().toHuman();
            annotate(output.getCursor() - mark, "parameter " + parameterName + " " + RegisterSpec.PREFIX + curParam);
        }
        curParam += pt.getCategory();
    }
    for (LocalList.Entry arg : lastEntryForReg) {
        if (arg == null) {
            continue;
        }
        CstString signature = arg.getSignature();
        if (signature != null) {
            emitLocalStartExtended(arg);
        }
    }
}
Also used : LocalList(com.android.dx.dex.code.LocalList) Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) StdTypeList(com.android.dx.rop.type.StdTypeList) PositionList(com.android.dx.dex.code.PositionList) CstString(com.android.dx.rop.cst.CstString) CstString(com.android.dx.rop.cst.CstString)

Example 18 with StdTypeList

use of com.android.dx.rop.type.StdTypeList in project buck by facebook.

the class ByteCatchList method toRopCatchList.

/**
     * Returns a rop-style catches list equivalent to this one.
     *
     * @return {@code non-null;} the converted instance
     */
public TypeList toRopCatchList() {
    int sz = size();
    if (sz == 0) {
        return StdTypeList.EMPTY;
    }
    StdTypeList result = new StdTypeList(sz);
    for (int i = 0; i < sz; i++) {
        result.set(i, get(i).getExceptionClass().getClassType());
    }
    result.setImmutable();
    return result;
}
Also used : StdTypeList(com.android.dx.rop.type.StdTypeList)

Example 19 with StdTypeList

use of com.android.dx.rop.type.StdTypeList in project J2ME-Loader by nikita36078.

the class DebugInfoDecoder method decode0.

private void decode0() throws IOException {
    ByteInput bs = new ByteArrayByteInput(encoded);
    line = Leb128.readUnsignedLeb128(bs);
    int szParams = Leb128.readUnsignedLeb128(bs);
    StdTypeList params = desc.getParameterTypes();
    int curReg = getParamBase();
    if (szParams != params.size()) {
        throw new RuntimeException("Mismatch between parameters_size and prototype");
    }
    if (!isStatic) {
        // Start off with implicit 'this' entry
        LocalEntry thisEntry = new LocalEntry(0, true, curReg, thisStringIdx, 0, 0);
        locals.add(thisEntry);
        lastEntryForReg[curReg] = thisEntry;
        curReg++;
    }
    for (int i = 0; i < szParams; i++) {
        Type paramType = params.getType(i);
        LocalEntry le;
        int nameIdx = readStringIndex(bs);
        if (nameIdx == -1) {
            /*
                 * Unnamed parameter; often but not always filled in by an
                 * extended start op after the prologue
                 */
            le = new LocalEntry(0, true, curReg, -1, 0, 0);
        } else {
            // TODO: Final 0 should be idx of paramType.getDescriptor().
            le = new LocalEntry(0, true, curReg, nameIdx, 0, 0);
        }
        locals.add(le);
        lastEntryForReg[curReg] = le;
        curReg += paramType.getCategory();
    }
    for (; ; ) {
        int opcode = bs.readByte() & 0xff;
        switch(opcode) {
            case DBG_START_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    int nameIdx = readStringIndex(bs);
                    int typeIdx = readStringIndex(bs);
                    LocalEntry le = new LocalEntry(address, true, reg, nameIdx, typeIdx, 0);
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_START_LOCAL_EXTENDED:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    int nameIdx = readStringIndex(bs);
                    int typeIdx = readStringIndex(bs);
                    int sigIdx = readStringIndex(bs);
                    LocalEntry le = new LocalEntry(address, true, reg, nameIdx, typeIdx, sigIdx);
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_RESTART_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    LocalEntry prevle;
                    LocalEntry le;
                    try {
                        prevle = lastEntryForReg[reg];
                        if (prevle.isStart) {
                            throw new RuntimeException("nonsensical " + "RESTART_LOCAL on live register v" + reg);
                        }
                        le = new LocalEntry(address, true, reg, prevle.nameIndex, prevle.typeIndex, 0);
                    } catch (NullPointerException ex) {
                        throw new RuntimeException("Encountered RESTART_LOCAL on new v" + reg);
                    }
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_END_LOCAL:
                {
                    int reg = Leb128.readUnsignedLeb128(bs);
                    LocalEntry prevle;
                    LocalEntry le;
                    try {
                        prevle = lastEntryForReg[reg];
                        if (!prevle.isStart) {
                            throw new RuntimeException("nonsensical " + "END_LOCAL on dead register v" + reg);
                        }
                        le = new LocalEntry(address, false, reg, prevle.nameIndex, prevle.typeIndex, prevle.signatureIndex);
                    } catch (NullPointerException ex) {
                        throw new RuntimeException("Encountered END_LOCAL on new v" + reg);
                    }
                    locals.add(le);
                    lastEntryForReg[reg] = le;
                }
                break;
            case DBG_END_SEQUENCE:
                // all done
                return;
            case DBG_ADVANCE_PC:
                address += Leb128.readUnsignedLeb128(bs);
                break;
            case DBG_ADVANCE_LINE:
                line += Leb128.readSignedLeb128(bs);
                break;
            case DBG_SET_PROLOGUE_END:
                // TODO do something with this.
                break;
            case DBG_SET_EPILOGUE_BEGIN:
                // TODO do something with this.
                break;
            case DBG_SET_FILE:
                // TODO do something with this.
                break;
            default:
                if (opcode < DBG_FIRST_SPECIAL) {
                    throw new RuntimeException("Invalid extended opcode encountered " + opcode);
                }
                int adjopcode = opcode - DBG_FIRST_SPECIAL;
                address += adjopcode / DBG_LINE_RANGE;
                line += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE);
                positions.add(new PositionEntry(address, line));
                break;
        }
    }
}
Also used : Type(com.android.dx.rop.type.Type) StdTypeList(com.android.dx.rop.type.StdTypeList) ByteArrayByteInput(com.android.dex.util.ByteArrayByteInput) ByteInput(com.android.dex.util.ByteInput) ByteArrayByteInput(com.android.dex.util.ByteArrayByteInput)

Example 20 with StdTypeList

use of com.android.dx.rop.type.StdTypeList in project J2ME-Loader by nikita36078.

the class ProtoIdItem method writeTo.

/**
 * {@inheritDoc}
 */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int shortyIdx = file.getStringIds().indexOf(shortForm);
    int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType());
    int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);
    if (out.annotates()) {
        StringBuilder sb = new StringBuilder();
        sb.append(prototype.getReturnType().toHuman());
        sb.append(" proto(");
        StdTypeList params = prototype.getParameterTypes();
        int size = params.size();
        for (int i = 0; i < size; i++) {
            if (i != 0) {
                sb.append(", ");
            }
            sb.append(params.getType(i).toHuman());
        }
        sb.append(")");
        out.annotate(0, indexString() + ' ' + sb.toString());
        out.annotate(4, "  shorty_idx:      " + Hex.u4(shortyIdx) + " // " + shortForm.toQuoted());
        out.annotate(4, "  return_type_idx: " + Hex.u4(returnIdx) + " // " + prototype.getReturnType().toHuman());
        out.annotate(4, "  parameters_off:  " + Hex.u4(paramsOff));
    }
    out.writeInt(shortyIdx);
    out.writeInt(returnIdx);
    out.writeInt(paramsOff);
}
Also used : StdTypeList(com.android.dx.rop.type.StdTypeList)

Aggregations

StdTypeList (com.android.dx.rop.type.StdTypeList)21 CstType (com.android.dx.rop.cst.CstType)10 Type (com.android.dx.rop.type.Type)10 CstString (com.android.dx.rop.cst.CstString)4 Prototype (com.android.dx.rop.type.Prototype)4 ByteArrayByteInput (com.android.dex.util.ByteArrayByteInput)2 ByteInput (com.android.dex.util.ByteInput)2 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)2 AttRuntimeInvisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)2 AttRuntimeInvisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)2 AttRuntimeVisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)2 AttRuntimeVisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)2 InnerClassList (com.android.dx.cf.attrib.InnerClassList)2 LocalList (com.android.dx.dex.code.LocalList)2 PositionList (com.android.dx.dex.code.PositionList)2 Annotations (com.android.dx.rop.annotation.Annotations)2 BasicBlock (com.android.dx.rop.code.BasicBlock)2 Insn (com.android.dx.rop.code.Insn)2 InsnList (com.android.dx.rop.code.InsnList)2 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)2