com.android.dx.dex.code.LocalList Java Examples

The following examples show how to use com.android.dx.dex.code.LocalList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebugInfoDecoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #2
Source File: DebugInfoItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #3
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_END_LOCAL DBG_END_LOCAL} sequence.
 *
 * @param entry {@code entry non-null;} entry associated with end.
 * @throws IOException
 */
private void emitLocalEnd(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_END_LOCAL);
    output.writeUleb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: -local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local end");
    }
}
 
Example #4
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStartExtended(LocalList.Entry entry)
    throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL_EXTENDED);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());
    emitStringIndex(entry.getSignature());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +localx %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #5
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL}
 * sequence.
 *
 * @param entry entry associated with this restart
 * @throws IOException
 */
private void emitLocalRestart(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_RESTART_LOCAL);
    emitUnsignedLeb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local restart %s",
                        address, entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local restart");
    }
}
 
Example #6
Source File: DebugInfoDecoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #7
Source File: DebugInfoItem.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #8
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_END_LOCAL DBG_END_LOCAL} sequence.
 *
 * @param entry {@code entry non-null;} entry associated with end.
 * @throws IOException
 */
private void emitLocalEnd(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_END_LOCAL);
    output.writeUleb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: -local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local end");
    }
}
 
Example #9
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStartExtended(LocalList.Entry entry)
    throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL_EXTENDED);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());
    emitStringIndex(entry.getSignature());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +localx %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #10
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL}
 * sequence.
 *
 * @param entry entry associated with this restart
 * @throws IOException
 */
private void emitLocalRestart(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_RESTART_LOCAL);
    emitUnsignedLeb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local restart %s",
                        address, entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local restart");
    }
}
 
Example #11
Source File: DebugInfoDecoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #12
Source File: DebugInfoItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #13
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_END_LOCAL DBG_END_LOCAL} sequence.
 *
 * @param entry {@code entry non-null;} entry associated with end.
 * @throws IOException
 */
private void emitLocalEnd(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_END_LOCAL);
    output.writeUleb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: -local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local end");
    }
}
 
Example #14
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStartExtended(LocalList.Entry entry)
    throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL_EXTENDED);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());
    emitStringIndex(entry.getSignature());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +localx %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #15
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL}
 * sequence.
 *
 * @param entry entry associated with this restart
 * @throws IOException
 */
private void emitLocalRestart(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_RESTART_LOCAL);
    emitUnsignedLeb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local restart %s",
                        address, entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local restart");
    }
}
 
Example #16
Source File: DebugInfoDecoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #17
Source File: DebugInfoItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #18
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL}
 * sequence.
 *
 * @param entry entry associated with this restart
 * @throws IOException
 */
private void emitLocalRestart(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_RESTART_LOCAL);
    emitUnsignedLeb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local restart %s",
                        address, entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local restart");
    }
}
 
Example #19
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStartExtended(LocalList.Entry entry)
    throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL_EXTENDED);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());
    emitStringIndex(entry.getSignature());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +localx %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #20
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_END_LOCAL DBG_END_LOCAL} sequence.
 *
 * @param entry {@code entry non-null;} entry associated with end.
 * @throws IOException
 */
private void emitLocalEnd(LocalList.Entry entry)
        throws IOException {

    int mark = output.getCursor();

    output.writeByte(DBG_END_LOCAL);
    output.writeUleb128(entry.getRegister());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: -local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local end");
    }
}
 
Example #21
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL DBG_START_LOCAL} or
 * {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStart(LocalList.Entry entry)
    throws IOException {

    if (entry.getSignature() != null) {
        emitLocalStartExtended(entry);
        return;
    }

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #22
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance.
 *
 * @param positions {@code null-ok;} positions (line numbers) to encode
 * @param locals {@code null-ok;} local variables to encode
 * @param file {@code null-ok;} may only be {@code null} if simply using
 * this class to do a debug print
 * @param codeSize
 * @param regSize
 * @param isStatic
 * @param ref
 */
public DebugInfoEncoder(PositionList positions, LocalList locals,
        DexFile file, int codeSize, int regSize,
        boolean isStatic, CstMethodRef ref) {
    this.positions = positions;
    this.locals = locals;
    this.file = file;
    this.desc = ref.getPrototype();
    this.isStatic = isStatic;
    this.codeSize = codeSize;
    this.regSize = regSize;

    output = new ByteArrayAnnotatedOutput();
    lastEntryForReg = new LocalList.Entry[regSize];
}
 
Example #23
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL DBG_START_LOCAL} or
 * {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStart(LocalList.Entry entry)
    throws IOException {

    if (entry.getSignature() != null) {
        emitLocalStartExtended(entry);
        return;
    }

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #24
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts method arguments from a locals list. These will be collected
 * from the input list and sorted by ascending register in the
 * returned list.
 *
 * @return list of non-{@code this} method argument locals,
 * sorted by ascending register
 */
private ArrayList<LocalList.Entry> extractMethodArguments() {
    ArrayList<LocalList.Entry> result
            = new ArrayList(desc.getParameterTypes().size());
    int argBase = getParamBase();
    BitSet seen = new BitSet(regSize - argBase);
    int sz = locals.size();

    for (int i = 0; i < sz; i++) {
        LocalList.Entry e = locals.get(i);
        int reg = e.getRegister();

        if (reg < argBase) {
            continue;
        }

        // only the lowest-start-address entry is included.
        if (seen.get(reg - argBase)) {
            continue;
        }

        seen.set(reg - argBase);
        result.add(e);
    }

    // Sort by ascending register.
    Collections.sort(result, new Comparator<LocalList.Entry>() {
        @Override
        public int compare(LocalList.Entry a, LocalList.Entry b) {
            return a.getRegister() - b.getRegister();
        }

        @Override
        public boolean equals(Object obj) {
           return obj == this;
        }
    });

    return result;
}
 
Example #25
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a string representation of this LocalList entry that is
 * appropriate for emitting as an annotation.
 *
 * @param e {@code non-null;} entry
 * @return {@code non-null;} annotation string
 */
private String entryAnnotationString(LocalList.Entry e) {
    StringBuilder sb = new StringBuilder();

    sb.append(RegisterSpec.PREFIX);
    sb.append(e.getRegister());
    sb.append(' ');

    CstString name = e.getName();
    if (name == null) {
        sb.append("null");
    } else {
        sb.append(name.toHuman());
    }
    sb.append(' ');

    CstType type = e.getType();
    if (type == null) {
        sb.append("null");
    } else {
        sb.append(type.toHuman());
    }

    CstString signature = e.getSignature();

    if (signature != null) {
        sb.append(' ');
        sb.append(signature.toHuman());
    }

    return sb.toString();
}
 
Example #26
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts method arguments from a locals list. These will be collected
 * from the input list and sorted by ascending register in the
 * returned list.
 *
 * @return list of non-{@code this} method argument locals,
 * sorted by ascending register
 */
private ArrayList<LocalList.Entry> extractMethodArguments() {
    ArrayList<LocalList.Entry> result
            = new ArrayList(desc.getParameterTypes().size());
    int argBase = getParamBase();
    BitSet seen = new BitSet(regSize - argBase);
    int sz = locals.size();

    for (int i = 0; i < sz; i++) {
        LocalList.Entry e = locals.get(i);
        int reg = e.getRegister();

        if (reg < argBase) {
            continue;
        }

        // only the lowest-start-address entry is included.
        if (seen.get(reg - argBase)) {
            continue;
        }

        seen.set(reg - argBase);
        result.add(e);
    }

    // Sort by ascending register.
    Collections.sort(result, new Comparator<LocalList.Entry>() {
        public int compare(LocalList.Entry a, LocalList.Entry b) {
            return a.getRegister() - b.getRegister();
        }

        public boolean equals(Object obj) {
           return obj == this;
        }
    });

    return result;
}
 
Example #27
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance.
 *
 * @param positions {@code null-ok;} positions (line numbers) to encode
 * @param locals {@code null-ok;} local variables to encode
 * @param file {@code null-ok;} may only be {@code null} if simply using
 * this class to do a debug print
 * @param codeSize
 * @param regSize
 * @param isStatic
 * @param ref
 */
public DebugInfoEncoder(PositionList positions, LocalList locals,
        DexFile file, int codeSize, int regSize,
        boolean isStatic, CstMethodRef ref) {
    this.positions = positions;
    this.locals = locals;
    this.file = file;
    this.desc = ref.getPrototype();
    this.isStatic = isStatic;
    this.codeSize = codeSize;
    this.regSize = regSize;

    output = new ByteArrayAnnotatedOutput();
    lastEntryForReg = new LocalList.Entry[regSize];
}
 
Example #28
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a string representation of this LocalList entry that is
 * appropriate for emitting as an annotation.
 *
 * @param e {@code non-null;} entry
 * @return {@code non-null;} annotation string
 */
private String entryAnnotationString(LocalList.Entry e) {
    StringBuilder sb = new StringBuilder();

    sb.append(RegisterSpec.PREFIX);
    sb.append(e.getRegister());
    sb.append(' ');

    CstString name = e.getName();
    if (name == null) {
        sb.append("null");
    } else {
        sb.append(name.toHuman());
    }
    sb.append(' ');

    CstType type = e.getType();
    if (type == null) {
        sb.append("null");
    } else {
        sb.append(type.toHuman());
    }

    CstString signature = e.getSignature();

    if (signature != null) {
        sb.append(' ');
        sb.append(signature.toHuman());
    }

    return sb.toString();
}
 
Example #29
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Emits a {@link DebugInfoConstants#DBG_START_LOCAL DBG_START_LOCAL} or
 * {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED
 * DBG_START_LOCAL_EXTENDED} sequence.
 *
 * @param entry entry to emit
 * @throws IOException
 */
private void emitLocalStart(LocalList.Entry entry)
    throws IOException {

    if (entry.getSignature() != null) {
        emitLocalStartExtended(entry);
        return;
    }

    int mark = output.getCursor();

    output.writeByte(DBG_START_LOCAL);

    emitUnsignedLeb128(entry.getRegister());
    emitStringIndex(entry.getName());
    emitTypeIndex(entry.getType());

    if (annotateTo != null || debugPrint != null) {
        annotate(output.getCursor() - mark,
                String.format("%04x: +local %s", address,
                        entryAnnotationString(entry)));
    }

    if (DEBUG) {
        System.err.println("emit local start");
    }
}
 
Example #30
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts method arguments from a locals list. These will be collected
 * from the input list and sorted by ascending register in the
 * returned list.
 *
 * @return list of non-{@code this} method argument locals,
 * sorted by ascending register
 */
private ArrayList<LocalList.Entry> extractMethodArguments() {
    ArrayList<LocalList.Entry> result
            = new ArrayList(desc.getParameterTypes().size());
    int argBase = getParamBase();
    BitSet seen = new BitSet(regSize - argBase);
    int sz = locals.size();

    for (int i = 0; i < sz; i++) {
        LocalList.Entry e = locals.get(i);
        int reg = e.getRegister();

        if (reg < argBase) {
            continue;
        }

        // only the lowest-start-address entry is included.
        if (seen.get(reg - argBase)) {
            continue;
        }

        seen.set(reg - argBase);
        result.add(e);
    }

    // Sort by ascending register.
    Collections.sort(result, new Comparator<LocalList.Entry>() {
        @Override
        public int compare(LocalList.Entry a, LocalList.Entry b) {
            return a.getRegister() - b.getRegister();
        }

        @Override
        public boolean equals(Object obj) {
           return obj == this;
        }
    });

    return result;
}