Search in sources :

Example 6 with DebugItem

use of org.jf.dexlib2.iface.debug.DebugItem in project smali by JesusFreke.

the class DexWriter method writeDebugItem.

private int writeDebugItem(@Nonnull DexDataWriter writer, @Nonnull DebugWriter<StringKey, TypeKey> debugWriter, @Nullable Iterable<? extends StringKey> parameterNames, @Nullable Iterable<? extends DebugItem> debugItems) throws IOException {
    int parameterCount = 0;
    int lastNamedParameterIndex = -1;
    if (parameterNames != null) {
        parameterCount = Iterables.size(parameterNames);
        int index = 0;
        for (StringKey parameterName : parameterNames) {
            if (parameterName != null) {
                lastNamedParameterIndex = index;
            }
            index++;
        }
    }
    if (lastNamedParameterIndex == -1 && (debugItems == null || Iterables.isEmpty(debugItems))) {
        return NO_OFFSET;
    }
    numDebugInfoItems++;
    int debugItemOffset = writer.getPosition();
    int startingLineNumber = 0;
    if (debugItems != null) {
        for (org.jf.dexlib2.iface.debug.DebugItem debugItem : debugItems) {
            if (debugItem instanceof LineNumber) {
                startingLineNumber = ((LineNumber) debugItem).getLineNumber();
                break;
            }
        }
    }
    writer.writeUleb128(startingLineNumber);
    writer.writeUleb128(parameterCount);
    if (parameterNames != null) {
        int index = 0;
        for (StringKey parameterName : parameterNames) {
            if (index == parameterCount) {
                break;
            }
            index++;
            writer.writeUleb128(stringSection.getNullableItemIndex(parameterName) + 1);
        }
    }
    if (debugItems != null) {
        debugWriter.reset(startingLineNumber);
        for (DebugItem debugItem : debugItems) {
            classSection.writeDebugItem(debugWriter, debugItem);
        }
    }
    // write an END_SEQUENCE opcode, to end the debug item
    writer.write(0);
    return debugItemOffset;
}
Also used : DebugItem(org.jf.dexlib2.iface.debug.DebugItem) DebugItem(org.jf.dexlib2.iface.debug.DebugItem) LineNumber(org.jf.dexlib2.iface.debug.LineNumber)

Example 7 with DebugItem

use of org.jf.dexlib2.iface.debug.DebugItem in project smali by JesusFreke.

the class ClassPool method internDebug.

private void internDebug(@Nonnull Method method) {
    for (MethodParameter param : method.getParameters()) {
        String paramName = param.getName();
        if (paramName != null) {
            dexPool.stringSection.intern(paramName);
        }
    }
    MethodImplementation methodImpl = method.getImplementation();
    if (methodImpl != null) {
        for (DebugItem debugItem : methodImpl.getDebugItems()) {
            switch(debugItem.getDebugItemType()) {
                case DebugItemType.START_LOCAL:
                    StartLocal startLocal = (StartLocal) debugItem;
                    dexPool.stringSection.internNullable(startLocal.getName());
                    dexPool.typeSection.internNullable(startLocal.getType());
                    dexPool.stringSection.internNullable(startLocal.getSignature());
                    break;
                case DebugItemType.SET_SOURCE_FILE:
                    dexPool.stringSection.internNullable(((SetSourceFile) debugItem).getSourceFile());
                    break;
            }
        }
    }
}
Also used : MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation)

Aggregations

DebugItem (org.jf.dexlib2.iface.debug.DebugItem)3 Instruction (org.jf.dexlib2.iface.instruction.Instruction)3 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)2 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Nonnull (javax.annotation.Nonnull)1 Nullable (org.jetbrains.annotations.Nullable)1 Opcode (org.jf.dexlib2.Opcode)1 BuilderInstruction10t (org.jf.dexlib2.builder.instruction.BuilderInstruction10t)1 BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)1 BuilderInstruction21c (org.jf.dexlib2.builder.instruction.BuilderInstruction21c)1 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)1 ExceptionHandler (org.jf.dexlib2.iface.ExceptionHandler)1 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)1 LineNumber (org.jf.dexlib2.iface.debug.LineNumber)1 OneRegisterInstruction (org.jf.dexlib2.iface.instruction.OneRegisterInstruction)1 Instruction21c (org.jf.dexlib2.iface.instruction.formats.Instruction21c)1