Java Code Examples for com.android.dx.dex.code.LocalList#Entry

The following examples show how to use com.android.dx.dex.code.LocalList#Entry . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: DebugInfoEncoder.java    From J2ME-Loader 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 10
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 11
Source File: DebugInfoEncoder.java    From J2ME-Loader 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();
         }

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

     return result;
 }
 
Example 12
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 13
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 14
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 15
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 16
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 17
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
private byte[] convert0() throws IOException {
    ArrayList<PositionList.Entry> sortedPositions = buildSortedPositions();
    ArrayList<LocalList.Entry> methodArgs = extractMethodArguments();

    emitHeader(sortedPositions, methodArgs);

    // TODO: Make this mark be the actual prologue end.
    output.writeByte(DBG_SET_PROLOGUE_END);

    if (annotateTo != null || debugPrint != null) {
        annotate(1, String.format("%04x: prologue end",address));
    }

    int positionsSz = sortedPositions.size();
    int localsSz = locals.size();

    // Current index in sortedPositions
    int curPositionIdx = 0;
    // Current index in locals
    int curLocalIdx = 0;

    for (;;) {
        /*
         * Emit any information for the current address.
         */

        curLocalIdx = emitLocalsAtAddress(curLocalIdx);
        curPositionIdx =
            emitPositionsAtAddress(curPositionIdx, sortedPositions);

        /*
         * Figure out what the next important address is.
         */

        int nextAddrL = Integer.MAX_VALUE; // local variable
        int nextAddrP = Integer.MAX_VALUE; // position (line number)

        if (curLocalIdx < localsSz) {
            nextAddrL = locals.get(curLocalIdx).getAddress();
        }

        if (curPositionIdx < positionsSz) {
            nextAddrP = sortedPositions.get(curPositionIdx).getAddress();
        }

        int next = Math.min(nextAddrP, nextAddrL);

        // No next important address == done.
        if (next == Integer.MAX_VALUE) {
            break;
        }

        /*
         * If the only work remaining are local ends at the end of the
         * block, stop here. Those are implied anyway.
         */
        if (next == codeSize
                && nextAddrL == Integer.MAX_VALUE
                && nextAddrP == Integer.MAX_VALUE) {
            break;
        }

        if (next == nextAddrP) {
            // Combined advance PC + position entry
            emitPosition(sortedPositions.get(curPositionIdx++));
        } else {
            emitAdvancePc(next - address);
        }
    }

    emitEndSequence();

    return output.toByteArray();
}
 
Example 18
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
private byte[] convert0() throws IOException {
    ArrayList<PositionList.Entry> sortedPositions = buildSortedPositions();
    ArrayList<LocalList.Entry> methodArgs = extractMethodArguments();

    emitHeader(sortedPositions, methodArgs);

    // TODO: Make this mark be the actual prologue end.
    output.writeByte(DBG_SET_PROLOGUE_END);

    if (annotateTo != null || debugPrint != null) {
        annotate(1, String.format("%04x: prologue end",address));
    }

    int positionsSz = sortedPositions.size();
    int localsSz = locals.size();

    // Current index in sortedPositions
    int curPositionIdx = 0;
    // Current index in locals
    int curLocalIdx = 0;

    for (;;) {
        /*
         * Emit any information for the current address.
         */

        curLocalIdx = emitLocalsAtAddress(curLocalIdx);
        curPositionIdx =
            emitPositionsAtAddress(curPositionIdx, sortedPositions);

        /*
         * Figure out what the next important address is.
         */

        int nextAddrL = Integer.MAX_VALUE; // local variable
        int nextAddrP = Integer.MAX_VALUE; // position (line number)

        if (curLocalIdx < localsSz) {
            nextAddrL = locals.get(curLocalIdx).getAddress();
        }

        if (curPositionIdx < positionsSz) {
            nextAddrP = sortedPositions.get(curPositionIdx).getAddress();
        }

        int next = Math.min(nextAddrP, nextAddrL);

        // No next important address == done.
        if (next == Integer.MAX_VALUE) {
            break;
        }

        /*
         * If the only work remaining are local ends at the end of the
         * block, stop here. Those are implied anyway.
         */
        if (next == codeSize
                && nextAddrL == Integer.MAX_VALUE
                && nextAddrP == Integer.MAX_VALUE) {
            break;
        }

        if (next == nextAddrP) {
            // Combined advance PC + position entry
            emitPosition(sortedPositions.get(curPositionIdx++));
        } else {
            emitAdvancePc(next - address);
        }
    }

    emitEndSequence();

    return output.toByteArray();
}
 
Example 19
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Emits all local variable activity that occurs at the current
 * {@link #address} starting at the given index into {@code
 * locals} and including all subsequent activity at the same
 * address.
 *
 * @param curLocalIdx Current index in locals
 * @return new value for {@code curLocalIdx}
 * @throws IOException
 */
private int emitLocalsAtAddress(int curLocalIdx)
        throws IOException {
    int sz = locals.size();

    // TODO: Don't emit ends implied by starts.

    while ((curLocalIdx < sz)
            && (locals.get(curLocalIdx).getAddress() == address)) {
        LocalList.Entry entry = locals.get(curLocalIdx++);
        int reg = entry.getRegister();
        LocalList.Entry prevEntry = lastEntryForReg[reg];

        if (entry == prevEntry) {
            /*
             * Here we ignore locals entries for parameters,
             * which have already been represented and placed in the
             * lastEntryForReg array.
             */
            continue;
        }

        // At this point we have a new entry one way or another.
        lastEntryForReg[reg] = entry;

        if (entry.isStart()) {
            if ((prevEntry != null) && entry.matches(prevEntry)) {
                /*
                 * The previous local in this register has the same
                 * name and type as the one being introduced now, so
                 * use the more efficient "restart" form.
                 */
                if (prevEntry.isStart()) {
                    /*
                     * We should never be handed a start when a
                     * a matching local is already active.
                     */
                    throw new RuntimeException("shouldn't happen");
                }
                emitLocalRestart(entry);
            } else {
                emitLocalStart(entry);
            }
        } else {
            /*
             * Only emit a local end if it is *not* due to a direct
             * replacement. Direct replacements imply an end of the
             * previous local in the same register.
             *
             * TODO: Make sure the runtime can deal with implied
             * local ends from category-2 interactions, and when so,
             * also stop emitting local ends for those cases.
             */
            if (entry.getDisposition()
                    != LocalList.Disposition.END_REPLACED) {
                emitLocalEnd(entry);
            }
        }
    }

    return curLocalIdx;
}
 
Example 20
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
private byte[] convert0() throws IOException {
    ArrayList<PositionList.Entry> sortedPositions = buildSortedPositions();
    ArrayList<LocalList.Entry> methodArgs = extractMethodArguments();

    emitHeader(sortedPositions, methodArgs);

    // TODO: Make this mark be the actual prologue end.
    output.writeByte(DBG_SET_PROLOGUE_END);

    if (annotateTo != null || debugPrint != null) {
        annotate(1, String.format("%04x: prologue end",address));
    }

    int positionsSz = sortedPositions.size();
    int localsSz = locals.size();

    // Current index in sortedPositions
    int curPositionIdx = 0;
    // Current index in locals
    int curLocalIdx = 0;

    for (;;) {
        /*
         * Emit any information for the current address.
         */

        curLocalIdx = emitLocalsAtAddress(curLocalIdx);
        curPositionIdx =
            emitPositionsAtAddress(curPositionIdx, sortedPositions);

        /*
         * Figure out what the next important address is.
         */

        int nextAddrL = Integer.MAX_VALUE; // local variable
        int nextAddrP = Integer.MAX_VALUE; // position (line number)

        if (curLocalIdx < localsSz) {
            nextAddrL = locals.get(curLocalIdx).getAddress();
        }

        if (curPositionIdx < positionsSz) {
            nextAddrP = sortedPositions.get(curPositionIdx).getAddress();
        }

        int next = Math.min(nextAddrP, nextAddrL);

        // No next important address == done.
        if (next == Integer.MAX_VALUE) {
            break;
        }

        /*
         * If the only work remaining are local ends at the end of the
         * block, stop here. Those are implied anyway.
         */
        if (next == codeSize
                && nextAddrL == Integer.MAX_VALUE
                && nextAddrP == Integer.MAX_VALUE) {
            break;
        }

        if (next == nextAddrP) {
            // Combined advance PC + position entry
            emitPosition(sortedPositions.get(curPositionIdx++));
        } else {
            emitAdvancePc(next - address);
        }
    }

    emitEndSequence();

    return output.toByteArray();
}