From 9c60ef2a1034e9f8d111907e4fceb3a4ca2e7e69 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Fri, 26 Oct 2012 22:23:20 -0700 Subject: [PATCH] Add support in dexlib2 for debug info --- .../java/org/jf/dexlib2/DebugItemType.java | 49 ++++ .../jf/dexlib2/dexbacked/DexBackedMethod.java | 2 +- .../DexBackedMethodImplementation.java | 17 ++ .../dexlib2/dexbacked/util/DebugItemList.java | 235 ++++++++++++++++++ .../dexbacked/util/VariableSizeList.java | 14 +- .../util/VariableSizeListWithContext.java | 14 +- .../dexlib2/iface/MethodImplementation.java | 2 + .../org/jf/dexlib2/iface/debug/DebugItem.java | 37 +++ .../org/jf/dexlib2/iface/debug/EndLocal.java | 36 +++ .../jf/dexlib2/iface/debug/EpilogueBegin.java | 35 +++ .../jf/dexlib2/iface/debug/LineNumber.java | 36 +++ .../org/jf/dexlib2/iface/debug/LocalInfo.java | 40 +++ .../jf/dexlib2/iface/debug/PrologueEnd.java | 35 +++ .../jf/dexlib2/iface/debug/RestartLocal.java | 36 +++ .../jf/dexlib2/iface/debug/SetSourceFile.java | 38 +++ .../jf/dexlib2/iface/debug/StartLocal.java | 36 +++ .../ImmutableMethodImplementation.java | 15 +- .../immutable/debug/ImmutableDebugItem.java | 97 ++++++++ .../immutable/debug/ImmutableEndLocal.java | 86 +++++++ .../debug/ImmutableEpilogueBegin.java | 53 ++++ .../immutable/debug/ImmutableLineNumber.java | 61 +++++ .../immutable/debug/ImmutablePrologueEnd.java | 53 ++++ .../debug/ImmutableRestartLocal.java | 86 +++++++ .../debug/ImmutableSetSourceFile.java | 62 +++++ .../immutable/debug/ImmutableStartLocal.java | 77 ++++++ .../util/InstructionOffsetMapTest.java | 2 +- 26 files changed, 1237 insertions(+), 17 deletions(-) create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/DebugItemType.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/DebugItem.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EndLocal.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EpilogueBegin.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LineNumber.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LocalInfo.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/PrologueEnd.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/RestartLocal.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/SetSourceFile.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/iface/debug/StartLocal.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableDebugItem.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEndLocal.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEpilogueBegin.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableLineNumber.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutablePrologueEnd.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableRestartLocal.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableSetSourceFile.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableStartLocal.java diff --git a/dexlib2/src/main/java/org/jf/dexlib2/DebugItemType.java b/dexlib2/src/main/java/org/jf/dexlib2/DebugItemType.java new file mode 100644 index 00000000..344b22db --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/DebugItemType.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2; + +public abstract class DebugItemType { + // The debug items that directly correspond with one of the dexlib2.iface.debug interfaces + public static final int START_LOCAL = 0x03; + public static final int END_LOCAL = 0x05; + public static final int RESTART_LOCAL = 0x06; + public static final int PROLOGUE_END = 0x07; + public static final int EPILOGUE_BEGIN = 0x08; + public static final int SET_SOURCE_FILE = 0x09; + public static final int LINE_NUMBER = 0x0a; + + // Other items, which are typically handled internally + public static final int END_SEQUENCE = 0x00; + public static final int ADVANCE_PC = 0x01; + public static final int ADVANCE_LINE = 0x02; + public static final int START_LOCAL_EXTENDED = 0x04; +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethod.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethod.java index b2189bc1..daf9cf11 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethod.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethod.java @@ -142,7 +142,7 @@ public class DexBackedMethod implements Method { @Override public MethodImplementation getImplementation() { if (codeOffset > 0) { - return new DexBackedMethodImplementation(dexBuf, codeOffset); + return new DexBackedMethodImplementation(dexBuf, this, codeOffset); } return null; } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java index f825cd33..aa2bc795 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedMethodImplementation.java @@ -33,9 +33,11 @@ package org.jf.dexlib2.dexbacked; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction; +import org.jf.dexlib2.dexbacked.util.DebugItemList; import org.jf.dexlib2.dexbacked.util.FixedSizeList; import org.jf.dexlib2.iface.MethodImplementation; import org.jf.dexlib2.iface.TryBlock; +import org.jf.dexlib2.iface.debug.DebugItem; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.util.AlignmentUtils; @@ -43,8 +45,10 @@ import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +//TODO: consider making this extends DexBackedMethod, rather than passing in the associated DexBackedMethod public class DexBackedMethodImplementation implements MethodImplementation { @Nonnull public final DexBuffer dexBuf; + @Nonnull public final DexBackedMethod method; private final int codeOffset; public final int registerCount; @@ -52,14 +56,17 @@ public class DexBackedMethodImplementation implements MethodImplementation { // code_item offsets private static final int TRIES_SIZE_OFFSET = 6; + private static final int DEBUG_OFFSET_OFFSET = 8; private static final int INSTRUCTIONS_SIZE_OFFSET = 12; private static final int INSTRUCTIONS_START_OFFSET = 16; private static final int TRY_ITEM_SIZE = 8; public DexBackedMethodImplementation(@Nonnull DexBuffer dexBuf, + @Nonnull DexBackedMethod method, int codeOffset) { this.dexBuf = dexBuf; + this.method = method; this.codeOffset = codeOffset; this.registerCount = dexBuf.readUshort(codeOffset); @@ -97,6 +104,16 @@ public class DexBackedMethodImplementation implements MethodImplementation { return ImmutableList.of(); } + @Nonnull + @Override + public List getDebugItems() { + final int debugInfoOffset = dexBuf.readSmallUint(codeOffset + DEBUG_OFFSET_OFFSET); + if (debugInfoOffset > 0) { + return new DebugItemList(dexBuf, debugInfoOffset, method); + } + return ImmutableList.of(); + } + @Nonnull private ImmutableList buildInstructionList() { // instructionsSize is the number of 16-bit code units in the instruction list, not the number of instructions diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java new file mode 100644 index 00000000..f9ac3e48 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugItemList.java @@ -0,0 +1,235 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.dexbacked.util; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.dexbacked.DexBuffer; +import org.jf.dexlib2.dexbacked.DexReader; +import org.jf.dexlib2.iface.Method; +import org.jf.dexlib2.iface.MethodImplementation; +import org.jf.dexlib2.iface.MethodParameter; +import org.jf.dexlib2.iface.debug.DebugItem; +import org.jf.dexlib2.iface.debug.EndLocal; +import org.jf.dexlib2.iface.debug.LocalInfo; +import org.jf.dexlib2.immutable.debug.*; +import org.jf.util.ExceptionWithContext; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; + +public class DebugItemList extends VariableSizeListWithContext { + @Nonnull public final DexBuffer dexBuf; + private final int debugInfoOffset; + @Nonnull private final Method method; + @Nonnull private final MethodImplementation methodImpl; + + public DebugItemList(@Nonnull DexBuffer dexBuf, + int debugInfoOffset, + @Nonnull Method method) { + this.dexBuf = dexBuf; + this.debugInfoOffset = debugInfoOffset; + this.method = method; + MethodImplementation methodImpl = method.getImplementation(); + if (methodImpl == null) { + throw new ExceptionWithContext("Creating a DebugItemList for a method with no implementation. WTF?"); + } + this.methodImpl = methodImpl; + } + + private static final LocalInfo EMPTY_LOCAL_INFO = new LocalInfo() { + @Nullable @Override public String getName() { return null; } + @Nullable @Override public String getType() { return null; } + @Nullable @Override public String getSignature() { return null; } + }; + + @Nonnull + @Override + public Iterator listIterator() { + DexReader initialReader = dexBuf.readerAt(debugInfoOffset); + // TODO: this unsigned value could legitimally be > MAX_INT + final int lineNumberStart = initialReader.readSmallUleb128(); + int registerCount = methodImpl.getRegisterCount(); + + //TODO: does dalvik allow references to invalid registers? + final LocalInfo[] locals = new LocalInfo[registerCount]; + Arrays.fill(locals, EMPTY_LOCAL_INFO); + + List parameters = method.getParameters(); + + //TODO: need to add parameter info to MethodParameter. Is there some way we could use the same reader for that? + int debugParametersSize = initialReader.readSmallUleb128(); + if (debugParametersSize > parameters.size()) { + //TODO: make sure that dalvik doesn't allow this + throw new ExceptionWithContext("DebugInfoItem has more parameters than the method itself does. WTF?"); + } + for (int i=0; i-1; i--) { + LocalInfo currentLocal = locals[i]; + locals[localIndex] = currentLocal; + locals[i] = EMPTY_LOCAL_INFO; + String type = currentLocal.getType(); + localIndex--; + if (type != null && (type.equals("J") || type.equals("D"))) { + localIndex--; + } + } + } + + return new Iterator(dexBuf, initialReader.getOffset()) { + private boolean finished = false; + private int codeAddress = 0; + private int lineNumber = lineNumberStart; + + @Nonnull + @Override + protected DebugItem readItem(@Nonnull DexReader reader, int index) { + if (finished) { + throw new NoSuchElementException(); + } + while (true) { + int next = reader.readUbyte(); + switch (next) { + case DebugItemType.END_SEQUENCE: { + finished = true; + throw new NoSuchElementException(); + } + case DebugItemType.ADVANCE_PC: { + int addressDiff = reader.readSmallUleb128(); + codeAddress += addressDiff; + continue; + } + case DebugItemType.ADVANCE_LINE: { + int lineDiff = reader.readSleb128(); + lineNumber += lineDiff; + continue; + } + case DebugItemType.START_LOCAL: { + int register = reader.readSmallUleb128(); + String name = dexBuf.getOptionalString(reader.readSmallUleb128() - 1); + String type = dexBuf.getOptionalType(reader.readSmallUleb128() - 1); + ImmutableStartLocal startLocal = + new ImmutableStartLocal(codeAddress, register, name, type, null); + locals[register] = startLocal; + return startLocal; + } + case DebugItemType.START_LOCAL_EXTENDED: { + int register = reader.readSmallUleb128(); + String name = dexBuf.getOptionalString(reader.readSmallUleb128() - 1); + String type = dexBuf.getOptionalType(reader.readSmallUleb128() - 1); + String signature = dexBuf.getOptionalString(reader.readSmallUleb128() - 1); + ImmutableStartLocal startLocal = + new ImmutableStartLocal(codeAddress, register, name, type, signature); + locals[register] = startLocal; + return startLocal; + } + case DebugItemType.END_LOCAL: { + int register = reader.readSmallUleb128(); + LocalInfo localInfo = locals[register]; + boolean replaceLocalInTable = true; + if (localInfo instanceof EndLocal) { + localInfo = EMPTY_LOCAL_INFO; + // don't replace the local info in locals. The new EndLocal won't have any info at all, + // and we dont want to wipe out what's there, so that it is available for a subsequent + // RestartLocal + replaceLocalInTable = false; + } + ImmutableEndLocal endLocal = + new ImmutableEndLocal(codeAddress, register, localInfo.getName(), + localInfo.getType(), localInfo.getSignature()); + if (replaceLocalInTable) { + locals[register] = endLocal; + } + return endLocal; + } + case DebugItemType.RESTART_LOCAL: { + int register = reader.readSmallUleb128(); + LocalInfo localInfo = locals[register]; + ImmutableRestartLocal restartLocal = + new ImmutableRestartLocal(codeAddress, register, localInfo.getName(), + localInfo.getType(), localInfo.getSignature()); + locals[register] = restartLocal; + return restartLocal; + } + case DebugItemType.PROLOGUE_END: { + return new ImmutablePrologueEnd(codeAddress); + } + case DebugItemType.EPILOGUE_BEGIN: { + return new ImmutableEpilogueBegin(codeAddress); + } + case DebugItemType.SET_SOURCE_FILE: { + String sourceFile = dexBuf.getOptionalString(reader.readSmallUleb128() - 1); + return new ImmutableSetSourceFile(codeAddress, sourceFile); + } + default: { + int base = ((next & 0xFF) - 0x0A); + codeAddress += base / 15; + lineNumber += (base % 15) - 4; + return new ImmutableLineNumber(codeAddress, lineNumber); + } + } + } + } + + @Override + protected void skipItem(@Nonnull DexReader reader, int index) { + super.skipItem(reader, index); + } + + @Override + protected void checkBounds(int index) { + // skip the bounds check here. We'll throw NoSuchElementException directly from readItem + } + }; + } + + @Override + public int size() { + throw new UnsupportedOperationException(); + } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeList.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeList.java index a79456ea..0783f1c0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeList.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeList.java @@ -85,19 +85,21 @@ public abstract class VariableSizeList extends AbstractSequentialList { @Override public boolean hasNext() { return index < size(); } @Override public int nextIndex() { return index; } - @Nonnull - @Override - public T next() { + protected void checkBounds(int index) { if (index >= size()) { throw new NoSuchElementException(); } + } + + @Nonnull + @Override + public T next() { + checkBounds(index); return readItem(reader, index++); } public void skip() { - if (index >= size()) { - throw new NoSuchElementException(); - } + checkBounds(index); skipItem(reader, index++); } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeListWithContext.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeListWithContext.java index ce42ea62..5a83b06e 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeListWithContext.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/VariableSizeListWithContext.java @@ -95,19 +95,21 @@ public abstract class VariableSizeListWithContext extends AbstractSequentialL @Override public boolean hasNext() { return index < size(); } @Override public int nextIndex() { return index; } - @Nonnull - @Override - public T next() { + protected void checkBounds(int index) { if (index >= size()) { throw new NoSuchElementException(); } + } + + @Nonnull + @Override + public T next() { + checkBounds(index); return readItem(reader, index++); } public void skip() { - if (index >= size()) { - throw new NoSuchElementException(); - } + checkBounds(index); skipItem(reader, index++); } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/MethodImplementation.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/MethodImplementation.java index 38c2254e..50ad0f3d 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/iface/MethodImplementation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/MethodImplementation.java @@ -31,6 +31,7 @@ package org.jf.dexlib2.iface; +import org.jf.dexlib2.iface.debug.DebugItem; import org.jf.dexlib2.iface.instruction.Instruction; import javax.annotation.Nonnull; @@ -40,4 +41,5 @@ public interface MethodImplementation { int getRegisterCount(); @Nonnull List getInstructions(); @Nonnull List getTryBlocks(); + @Nonnull List getDebugItems(); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/DebugItem.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/DebugItem.java new file mode 100644 index 00000000..fbe9e747 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/DebugItem.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface DebugItem { + int getDebugItemType(); + int getCodeAddress(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EndLocal.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EndLocal.java new file mode 100644 index 00000000..bc8d2b16 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EndLocal.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface EndLocal extends DebugItem, LocalInfo { + int getRegister(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EpilogueBegin.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EpilogueBegin.java new file mode 100644 index 00000000..bc5dc024 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/EpilogueBegin.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface EpilogueBegin extends DebugItem { +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LineNumber.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LineNumber.java new file mode 100644 index 00000000..daa9d0a5 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LineNumber.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface LineNumber extends DebugItem { + int getLineNumber(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LocalInfo.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LocalInfo.java new file mode 100644 index 00000000..4d3b179d --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/LocalInfo.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +import javax.annotation.Nullable; + +public interface LocalInfo { + @Nullable String getName(); + @Nullable String getType(); + @Nullable String getSignature(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/PrologueEnd.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/PrologueEnd.java new file mode 100644 index 00000000..13f45d2d --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/PrologueEnd.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface PrologueEnd extends DebugItem { +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/RestartLocal.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/RestartLocal.java new file mode 100644 index 00000000..fece839a --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/RestartLocal.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface RestartLocal extends DebugItem, LocalInfo { + int getRegister(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/SetSourceFile.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/SetSourceFile.java new file mode 100644 index 00000000..d992423d --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/SetSourceFile.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +import javax.annotation.Nullable; + +public interface SetSourceFile extends DebugItem { + @Nullable String getSourceFile(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/StartLocal.java b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/StartLocal.java new file mode 100644 index 00000000..01ec1e09 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/iface/debug/StartLocal.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.iface.debug; + +public interface StartLocal extends DebugItem, LocalInfo { + int getRegister(); +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java index 57d0cac5..a07caa78 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java @@ -35,7 +35,9 @@ import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.MethodImplementation; import org.jf.dexlib2.iface.TryBlock; +import org.jf.dexlib2.iface.debug.DebugItem; import org.jf.dexlib2.iface.instruction.Instruction; +import org.jf.dexlib2.immutable.debug.ImmutableDebugItem; import org.jf.dexlib2.immutable.instruction.ImmutableInstruction; import javax.annotation.Nonnull; @@ -46,21 +48,26 @@ public class ImmutableMethodImplementation implements MethodImplementation { public final int registerCount; @Nonnull public final ImmutableList instructions; @Nonnull public final ImmutableList tryBlocks; + @Nonnull public final ImmutableList debugItems; public ImmutableMethodImplementation(int registerCount, @Nullable List instructions, - @Nullable List tryBlocks) { + @Nullable List tryBlocks, + @Nullable List debugItems) { this.registerCount = registerCount; this.instructions = ImmutableInstruction.immutableListOf(instructions); this.tryBlocks = ImmutableTryBlock.immutableListOf(tryBlocks); + this.debugItems = ImmutableDebugItem.immutableListOf(debugItems); } public ImmutableMethodImplementation(int registerCount, @Nullable ImmutableList instructions, - @Nullable ImmutableList tryBlocks) { + @Nullable ImmutableList tryBlocks, + @Nullable ImmutableList debugItems) { this.registerCount = registerCount; this.instructions = Objects.firstNonNull(instructions, ImmutableList.of()); this.tryBlocks = Objects.firstNonNull(tryBlocks, ImmutableList.of()); + this.debugItems = Objects.firstNonNull(debugItems, ImmutableList.of()); } public static ImmutableMethodImplementation of(MethodImplementation methodImplementation) { @@ -70,10 +77,12 @@ public class ImmutableMethodImplementation implements MethodImplementation { return new ImmutableMethodImplementation( methodImplementation.getRegisterCount(), methodImplementation.getInstructions(), - methodImplementation.getTryBlocks()); + methodImplementation.getTryBlocks(), + methodImplementation.getDebugItems()); } @Override public int getRegisterCount() { return 0; } @Nonnull @Override public ImmutableList getInstructions() { return instructions; } @Nonnull @Override public ImmutableList getTryBlocks() { return tryBlocks; } + @Nonnull @Override public ImmutableList getDebugItems() { return debugItems; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableDebugItem.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableDebugItem.java new file mode 100644 index 00000000..0e5beedf --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableDebugItem.java @@ -0,0 +1,97 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import com.google.common.collect.ImmutableList; +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.*; +import org.jf.dexlib2.iface.instruction.Instruction; +import org.jf.util.ExceptionWithContext; +import org.jf.util.ImmutableListConverter; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; + +public abstract class ImmutableDebugItem implements DebugItem { + public final int codeAddress; + + public ImmutableDebugItem(int codeAddress) { + this.codeAddress = codeAddress; + } + + @Nonnull + public static ImmutableDebugItem of(DebugItem debugItem) { + if (debugItem instanceof ImmutableDebugItem) { + return (ImmutableDebugItem)debugItem; + } + switch (debugItem.getDebugItemType()) { + case DebugItemType.START_LOCAL: + return ImmutableStartLocal.of((StartLocal)debugItem); + case DebugItemType.END_LOCAL: + return ImmutableEndLocal.of((EndLocal)debugItem); + case DebugItemType.RESTART_LOCAL: + return ImmutableRestartLocal.of((RestartLocal)debugItem); + case DebugItemType.PROLOGUE_END: + return ImmutablePrologueEnd.of((PrologueEnd)debugItem); + case DebugItemType.EPILOGUE_BEGIN: + return ImmutableEpilogueBegin.of((EpilogueBegin)debugItem); + case DebugItemType.SET_SOURCE_FILE: + return ImmutableSetSourceFile.of((SetSourceFile)debugItem); + case DebugItemType.LINE_NUMBER: + return ImmutableLineNumber.of((LineNumber)debugItem); + default: + throw new ExceptionWithContext("Invalid debug item type: %d", debugItem.getDebugItemType()); + } + } + + @Override public int getCodeAddress() { return codeAddress; } + + @Nonnull + public static ImmutableList immutableListOf(@Nullable List list) { + return CONVERTER.convert(list); + } + + private static final ImmutableListConverter CONVERTER = + new ImmutableListConverter() { + @Override + protected boolean isImmutable(DebugItem item) { + return item instanceof ImmutableDebugItem; + } + + @Nonnull + @Override + protected ImmutableDebugItem makeImmutable(DebugItem item) { + return ImmutableDebugItem.of(item); + } + }; +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEndLocal.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEndLocal.java new file mode 100644 index 00000000..48c9dd5a --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEndLocal.java @@ -0,0 +1,86 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.EndLocal; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ImmutableEndLocal extends ImmutableDebugItem implements EndLocal { + public final int register; + @Nullable public final String name; + @Nullable public final String type; + @Nullable public final String signature; + + public ImmutableEndLocal(int codeAddress, + int register) { + super(codeAddress); + this.register = register; + this.name = null; + this.type = null; + this.signature = null; + } + + public ImmutableEndLocal(int codeAddress, + int register, + @Nullable String name, + @Nullable String type, + @Nullable String signature) { + super(codeAddress); + this.register = register; + this.name = name; + this.type = type; + this.signature = signature; + } + + @Nonnull + public static ImmutableEndLocal of(@Nonnull EndLocal endLocal) { + if (endLocal instanceof ImmutableEndLocal) { + return (ImmutableEndLocal)endLocal; + } + return new ImmutableEndLocal( + endLocal.getCodeAddress(), + endLocal.getRegister(), + endLocal.getType(), + endLocal.getName(), + endLocal.getSignature()); + } + + @Override public int getRegister() { return register; } + @Nullable @Override public String getName() { return name; } + @Nullable @Override public String getType() { return type; } + @Nullable @Override public String getSignature() { return signature; } + + @Override public int getDebugItemType() { return DebugItemType.END_LOCAL; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEpilogueBegin.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEpilogueBegin.java new file mode 100644 index 00000000..dcb95673 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableEpilogueBegin.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.EpilogueBegin; + +import javax.annotation.Nonnull; + +public class ImmutableEpilogueBegin extends ImmutableDebugItem implements EpilogueBegin { + public ImmutableEpilogueBegin(int codeAddress) { + super(codeAddress); + } + + @Nonnull + public static ImmutableEpilogueBegin of(@Nonnull EpilogueBegin epilogueBegin) { + if (epilogueBegin instanceof ImmutableEpilogueBegin) { + return (ImmutableEpilogueBegin)epilogueBegin; + } + return new ImmutableEpilogueBegin(epilogueBegin.getCodeAddress()); + } + + @Override public int getDebugItemType() { return DebugItemType.EPILOGUE_BEGIN; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableLineNumber.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableLineNumber.java new file mode 100644 index 00000000..1c85b956 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableLineNumber.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.LineNumber; + +import javax.annotation.Nonnull; + +public class ImmutableLineNumber extends ImmutableDebugItem implements LineNumber { + public final int lineNumber; + + public ImmutableLineNumber(int codeAddress, + int lineNumber) { + super(codeAddress); + this.lineNumber = lineNumber; + } + + @Nonnull + public static ImmutableLineNumber of(@Nonnull LineNumber lineNumber) { + if (lineNumber instanceof ImmutableLineNumber) { + return (ImmutableLineNumber)lineNumber; + } + return new ImmutableLineNumber( + lineNumber.getCodeAddress(), + lineNumber.getLineNumber()); + } + + @Override public int getLineNumber() { return lineNumber; } + + @Override public int getDebugItemType() { return DebugItemType.LINE_NUMBER; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutablePrologueEnd.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutablePrologueEnd.java new file mode 100644 index 00000000..dac53507 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutablePrologueEnd.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.PrologueEnd; + +import javax.annotation.Nonnull; + +public class ImmutablePrologueEnd extends ImmutableDebugItem implements PrologueEnd { + public ImmutablePrologueEnd(int codeAddress) { + super(codeAddress); + } + + @Nonnull + public static ImmutablePrologueEnd of(@Nonnull PrologueEnd prologueEnd) { + if (prologueEnd instanceof ImmutablePrologueEnd) { + return (ImmutablePrologueEnd)prologueEnd; + } + return new ImmutablePrologueEnd(prologueEnd.getCodeAddress()); + } + + @Override public int getDebugItemType() { return DebugItemType.PROLOGUE_END; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableRestartLocal.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableRestartLocal.java new file mode 100644 index 00000000..b487dfb0 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableRestartLocal.java @@ -0,0 +1,86 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.RestartLocal; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ImmutableRestartLocal extends ImmutableDebugItem implements RestartLocal { + public final int register; + @Nullable public final String name; + @Nullable public final String type; + @Nullable public final String signature; + + public ImmutableRestartLocal(int codeAddress, + int register) { + super(codeAddress); + this.register = register; + this.name = null; + this.type = null; + this.signature = null; + } + + public ImmutableRestartLocal(int codeAddress, + int register, + @Nullable String name, + @Nullable String type, + @Nullable String signature) { + super(codeAddress); + this.register = register; + this.name = name; + this.type = type; + this.signature = signature; + } + + @Nonnull + public static ImmutableRestartLocal of(@Nonnull RestartLocal restartLocal) { + if (restartLocal instanceof ImmutableRestartLocal) { + return (ImmutableRestartLocal)restartLocal; + } + return new ImmutableRestartLocal( + restartLocal.getCodeAddress(), + restartLocal.getRegister(), + restartLocal.getType(), + restartLocal.getName(), + restartLocal.getSignature()); + } + + @Override public int getRegister() { return register; } + @Nullable @Override public String getName() { return name; } + @Nullable @Override public String getType() { return type; } + @Nullable @Override public String getSignature() { return signature; } + + @Override public int getDebugItemType() { return DebugItemType.RESTART_LOCAL; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableSetSourceFile.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableSetSourceFile.java new file mode 100644 index 00000000..ee4db48e --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableSetSourceFile.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.SetSourceFile; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ImmutableSetSourceFile extends ImmutableDebugItem implements SetSourceFile { + @Nullable public final String sourceFile; + + public ImmutableSetSourceFile(int codeAddress, + @Nullable String sourceFile) { + super(codeAddress); + this.sourceFile = sourceFile; + } + + @Nonnull + public static ImmutableSetSourceFile of (@Nonnull SetSourceFile setSourceFile) { + if (setSourceFile instanceof ImmutableSetSourceFile) { + return (ImmutableSetSourceFile)setSourceFile; + } + return new ImmutableSetSourceFile( + setSourceFile.getCodeAddress(), + setSourceFile.getSourceFile()); + } + + @Nullable @Override public String getSourceFile() { return sourceFile; } + + @Override public int getDebugItemType() { return DebugItemType.SET_SOURCE_FILE; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableStartLocal.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableStartLocal.java new file mode 100644 index 00000000..4d3daadc --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/debug/ImmutableStartLocal.java @@ -0,0 +1,77 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.debug; + +import org.jf.dexlib2.DebugItemType; +import org.jf.dexlib2.iface.debug.StartLocal; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ImmutableStartLocal extends ImmutableDebugItem implements StartLocal { + public final int register; + @Nullable public final String name; + @Nullable public final String type; + @Nullable public final String signature; + + public ImmutableStartLocal(int codeAddress, + int register, + @Nullable String name, + @Nullable String type, + @Nullable String signature) { + super(codeAddress); + this.register = register; + this.name = name; + this.type = type; + this.signature = signature; + } + + @Nonnull + public static ImmutableStartLocal of(@Nonnull StartLocal startLocal) { + if (startLocal instanceof ImmutableStartLocal) { + return (ImmutableStartLocal)startLocal; + } + return new ImmutableStartLocal( + startLocal.getCodeAddress(), + startLocal.getRegister(), + startLocal.getType(), + startLocal.getName(), + startLocal.getSignature()); + } + + @Override public int getRegister() { return register; } + @Nullable @Override public String getName() { return name; } + @Nullable @Override public String getType() { return type; } + @Nullable @Override public String getSignature() { return signature; } + + @Override public int getDebugItemType() { return DebugItemType.START_LOCAL; } +} diff --git a/dexlib2/src/test/java/org/jf/dexlib2/util/InstructionOffsetMapTest.java b/dexlib2/src/test/java/org/jf/dexlib2/util/InstructionOffsetMapTest.java index 11c889db..8dd01768 100644 --- a/dexlib2/src/test/java/org/jf/dexlib2/util/InstructionOffsetMapTest.java +++ b/dexlib2/src/test/java/org/jf/dexlib2/util/InstructionOffsetMapTest.java @@ -70,7 +70,7 @@ public class InstructionOffsetMapTest { /*24: 0x32*/ new ImmutableInstruction51l(Opcode.CONST_WIDE, 32, 33), /*25: 0x37*/ new ImmutableInstruction10t(Opcode.GOTO, 1) ); - ImmutableMethodImplementation impl = new ImmutableMethodImplementation(33, instructions, null); + ImmutableMethodImplementation impl = new ImmutableMethodImplementation(33, instructions, null, null); InstructionOffsetMap instructionOffsetMap = new InstructionOffsetMap(impl); int[] expectedOffsets = new int[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f, 0x11,