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

The following examples show how to use com.android.dx.dex.code.PositionList#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 Box with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a list of position entries, sorted by ascending address.
 *
 * @return A sorted positions list
 */
private ArrayList<PositionList.Entry> buildSortedPositions() {
    int sz = (positions == null) ? 0 : positions.size();
    ArrayList<PositionList.Entry> result = new ArrayList(sz);

    for (int i = 0; i < sz; i++) {
        result.add(positions.get(i));
    }

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

        @Override
        public boolean equals (Object obj) {
           return obj == this;
        }
    });
    return result;
}
 
Example 2
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a list of position entries, sorted by ascending address.
 *
 * @return A sorted positions list
 */
private ArrayList<PositionList.Entry> buildSortedPositions() {
    int sz = (positions == null) ? 0 : positions.size();
    ArrayList<PositionList.Entry> result = new ArrayList(sz);

    for (int i = 0; i < sz; i++) {
        result.add(positions.get(i));
    }

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

        @Override
        public boolean equals (Object obj) {
           return obj == this;
        }
    });
    return result;
}
 
Example 3
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
  * Builds a list of position entries, sorted by ascending address.
  *
  * @return A sorted positions list
  */
 private ArrayList<PositionList.Entry> buildSortedPositions() {
     int sz = (positions == null) ? 0 : positions.size();
     ArrayList<PositionList.Entry> result = new ArrayList(sz);

     for (int i = 0; i < sz; i++) {
         result.add(positions.get(i));
     }

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

         public boolean equals (Object obj) {
            return obj == this;
         }
     });
     return result;
 }
 
Example 4
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a list of position entries, sorted by ascending address.
 *
 * @return A sorted positions list
 */
private ArrayList<PositionList.Entry> buildSortedPositions() {
    int sz = (positions == null) ? 0 : positions.size();
    ArrayList<PositionList.Entry> result = new ArrayList(sz);

    for (int i = 0; i < sz; i++) {
        result.add(positions.get(i));
    }

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

        public boolean equals (Object obj) {
           return obj == this;
        }
    });
    return result;
}
 
Example 5
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Emits all positions that occur at the current {@code address}
 *
 * @param curPositionIdx Current index in sortedPositions
 * @param sortedPositions positions, sorted by ascending address
 * @return new value for {@code curPositionIdx}
 * @throws IOException
 */
private int emitPositionsAtAddress(int curPositionIdx,
        ArrayList<PositionList.Entry> sortedPositions)
        throws IOException {
    int positionsSz = sortedPositions.size();
    while ((curPositionIdx < positionsSz)
            && (sortedPositions.get(curPositionIdx).getAddress()
                    == address)) {
        emitPosition(sortedPositions.get(curPositionIdx++));
    }
    return curPositionIdx;
}
 
Example 6
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Emits all positions that occur at the current {@code address}
 *
 * @param curPositionIdx Current index in sortedPositions
 * @param sortedPositions positions, sorted by ascending address
 * @return new value for {@code curPositionIdx}
 * @throws IOException
 */
private int emitPositionsAtAddress(int curPositionIdx,
        ArrayList<PositionList.Entry> sortedPositions)
        throws IOException {
    int positionsSz = sortedPositions.size();
    while ((curPositionIdx < positionsSz)
            && (sortedPositions.get(curPositionIdx).getAddress()
                    == address)) {
        emitPosition(sortedPositions.get(curPositionIdx++));
    }
    return curPositionIdx;
}
 
Example 7
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Emits all positions that occur at the current {@code address}
 *
 * @param curPositionIdx Current index in sortedPositions
 * @param sortedPositions positions, sorted by ascending address
 * @return new value for {@code curPositionIdx}
 * @throws IOException
 */
private int emitPositionsAtAddress(int curPositionIdx,
        ArrayList<PositionList.Entry> sortedPositions)
        throws IOException {
    int positionsSz = sortedPositions.size();
    while ((curPositionIdx < positionsSz)
            && (sortedPositions.get(curPositionIdx).getAddress()
                    == address)) {
        emitPosition(sortedPositions.get(curPositionIdx++));
    }
    return curPositionIdx;
}
 
Example 8
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Emits all positions that occur at the current {@code address}
 *
 * @param curPositionIdx Current index in sortedPositions
 * @param sortedPositions positions, sorted by ascending address
 * @return new value for {@code curPositionIdx}
 * @throws IOException
 */
private int emitPositionsAtAddress(int curPositionIdx,
        ArrayList<PositionList.Entry> sortedPositions)
        throws IOException {
    int positionsSz = sortedPositions.size();
    while ((curPositionIdx < positionsSz)
            && (sortedPositions.get(curPositionIdx).getAddress()
                    == address)) {
        emitPosition(sortedPositions.get(curPositionIdx++));
    }
    return curPositionIdx;
}
 
Example 9
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 10
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Emits the necessary byte sequences to emit the given position table
 * entry. This will typically be a single special opcode, although
 * it may also require DBG_ADVANCE_PC or DBG_ADVANCE_LINE.
 *
 * @param entry position entry to emit.
 * @throws IOException
 */
private void emitPosition(PositionList.Entry entry)
        throws IOException {

    SourcePosition pos = entry.getPosition();
    int newLine = pos.getLine();
    int newAddress = entry.getAddress();

    int opcode;

    int deltaLines = newLine - line;
    int deltaAddress = newAddress - address;

    if (deltaAddress < 0) {
        throw new RuntimeException(
                "Position entries must be in ascending address order");
    }

    if ((deltaLines < DBG_LINE_BASE)
            || (deltaLines > (DBG_LINE_BASE + DBG_LINE_RANGE -1))) {
        emitAdvanceLine(deltaLines);
        deltaLines = 0;
    }

    opcode = computeOpcode (deltaLines, deltaAddress);

    if ((opcode & ~0xff) > 0) {
        emitAdvancePc(deltaAddress);
        deltaAddress = 0;
        opcode = computeOpcode (deltaLines, deltaAddress);

        if ((opcode & ~0xff) > 0) {
            emitAdvanceLine(deltaLines);
            deltaLines = 0;
            opcode = computeOpcode (deltaLines, deltaAddress);
        }
    }

    output.writeByte(opcode);

    line += deltaLines;
    address += deltaAddress;

    if (annotateTo != null || debugPrint != null) {
        annotate(1,
                String.format("%04x: line %d", address, line));
    }
}
 
Example 11
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 12
Source File: DebugInfoEncoder.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Emits the necessary byte sequences to emit the given position table
 * entry. This will typically be a single special opcode, although
 * it may also require DBG_ADVANCE_PC or DBG_ADVANCE_LINE.
 *
 * @param entry position entry to emit.
 * @throws IOException
 */
private void emitPosition(PositionList.Entry entry)
        throws IOException {

    SourcePosition pos = entry.getPosition();
    int newLine = pos.getLine();
    int newAddress = entry.getAddress();

    int opcode;

    int deltaLines = newLine - line;
    int deltaAddress = newAddress - address;

    if (deltaAddress < 0) {
        throw new RuntimeException(
                "Position entries must be in ascending address order");
    }

    if ((deltaLines < DBG_LINE_BASE)
            || (deltaLines > (DBG_LINE_BASE + DBG_LINE_RANGE -1))) {
        emitAdvanceLine(deltaLines);
        deltaLines = 0;
    }

    opcode = computeOpcode (deltaLines, deltaAddress);

    if ((opcode & ~0xff) > 0) {
        emitAdvancePc(deltaAddress);
        deltaAddress = 0;
        opcode = computeOpcode (deltaLines, deltaAddress);

        if ((opcode & ~0xff) > 0) {
            emitAdvanceLine(deltaLines);
            deltaLines = 0;
            opcode = computeOpcode (deltaLines, deltaAddress);
        }
    }

    output.writeByte(opcode);

    line += deltaLines;
    address += deltaAddress;

    if (annotateTo != null || debugPrint != null) {
        annotate(1,
                String.format("%04x: line %d", address, line));
    }
}
 
Example 13
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 14
Source File: DebugInfoEncoder.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Emits the necessary byte sequences to emit the given position table
 * entry. This will typically be a single special opcode, although
 * it may also require DBG_ADVANCE_PC or DBG_ADVANCE_LINE.
 *
 * @param entry position entry to emit.
 * @throws IOException
 */
private void emitPosition(PositionList.Entry entry)
        throws IOException {

    SourcePosition pos = entry.getPosition();
    int newLine = pos.getLine();
    int newAddress = entry.getAddress();

    int opcode;

    int deltaLines = newLine - line;
    int deltaAddress = newAddress - address;

    if (deltaAddress < 0) {
        throw new RuntimeException(
                "Position entries must be in ascending address order");
    }

    if ((deltaLines < DBG_LINE_BASE)
            || (deltaLines > (DBG_LINE_BASE + DBG_LINE_RANGE -1))) {
        emitAdvanceLine(deltaLines);
        deltaLines = 0;
    }

    opcode = computeOpcode (deltaLines, deltaAddress);

    if ((opcode & ~0xff) > 0) {
        emitAdvancePc(deltaAddress);
        deltaAddress = 0;
        opcode = computeOpcode (deltaLines, deltaAddress);

        if ((opcode & ~0xff) > 0) {
            emitAdvanceLine(deltaLines);
            deltaLines = 0;
            opcode = computeOpcode (deltaLines, deltaAddress);
        }
    }

    output.writeByte(opcode);

    line += deltaLines;
    address += deltaAddress;

    if (annotateTo != null || debugPrint != null) {
        annotate(1,
                String.format("%04x: line %d", address, line));
    }
}
 
Example 15
Source File: DebugInfoEncoder.java    From buck 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 16
Source File: DebugInfoEncoder.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Emits the necessary byte sequences to emit the given position table
 * entry. This will typically be a single special opcode, although
 * it may also require DBG_ADVANCE_PC or DBG_ADVANCE_LINE.
 *
 * @param entry position entry to emit.
 * @throws IOException
 */
private void emitPosition(PositionList.Entry entry)
        throws IOException {

    SourcePosition pos = entry.getPosition();
    int newLine = pos.getLine();
    int newAddress = entry.getAddress();

    int opcode;

    int deltaLines = newLine - line;
    int deltaAddress = newAddress - address;

    if (deltaAddress < 0) {
        throw new RuntimeException(
                "Position entries must be in ascending address order");
    }

    if ((deltaLines < DBG_LINE_BASE)
            || (deltaLines > (DBG_LINE_BASE + DBG_LINE_RANGE -1))) {
        emitAdvanceLine(deltaLines);
        deltaLines = 0;
    }

    opcode = computeOpcode (deltaLines, deltaAddress);

    if ((opcode & ~0xff) > 0) {
        emitAdvancePc(deltaAddress);
        deltaAddress = 0;
        opcode = computeOpcode (deltaLines, deltaAddress);

        if ((opcode & ~0xff) > 0) {
            emitAdvanceLine(deltaLines);
            deltaLines = 0;
            opcode = computeOpcode (deltaLines, deltaAddress);
        }
    }

    output.writeByte(opcode);

    line += deltaLines;
    address += deltaAddress;

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