Merge remote-tracking branch 'zerny/debuginfo'

This commit is contained in:
oSumAtrIX 2023-01-16 16:01:28 +01:00
commit 7419b19f9a
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 15 additions and 9 deletions

View File

@ -75,7 +75,7 @@ public class CDexBackedMethodImplementation extends DexBackedMethodImplementatio
}
@Override
protected int getInstructionsSize() {
public int getInstructionsSize() {
int instructionsSize = dexFile.getDataBuffer().readUshort(
codeOffset + CDEX_INSTRUCTIONS_SIZE_AND_PREHEADER_FLAGS_OFFSET) >>
CDEX_INSTRUCTIONS_SIZE_SHIFT;

View File

@ -66,7 +66,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
return dexFile.getDataBuffer().readUshort(codeOffset);
}
protected int getInstructionsSize() {
public int getInstructionsSize() {
return dexFile.getDataBuffer().readSmallUint(codeOffset + CodeItem.INSTRUCTION_COUNT_OFFSET);
}
@ -172,13 +172,11 @@ public class DexBackedMethodImplementation implements MethodImplementation {
/**
* Calculate and return the private size of a method implementation.
*
* Calculated as: debug info size + instructions size + try-catch size
* Calculated as: instructions size + try-catch size
*
* @return size in bytes
*/
public int getSize() {
int debugSize = getDebugInfo().getSize();
//set last offset just before bytecode instructions (after insns_size)
int lastOffset = getInstructionsStartOffset();
@ -195,7 +193,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
lastOffset = ((VariableSizeListIterator)tryHandlerIter).getReaderOffset();
}
//method impl size = debug block size + code_item size
return debugSize + (lastOffset - codeOffset);
//method impl size = code_item size
return lastOffset - codeOffset;
}
}

View File

@ -32,6 +32,7 @@
package org.jf.dexlib2.dexbacked.util;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
@ -117,6 +118,10 @@ public abstract class DebugInfo implements Iterable<DebugItem> {
DexReader reader = dexFile.getDataBuffer().readerAt(debugInfoOffset);
final int lineNumberStart = reader.readBigUleb128();
int registerCount = methodImpl.getRegisterCount();
// Debug information can have events for addresses past the instructions.
// They have no relevance for the method in question and are excluded from the iterator.
final int lastInstructionAddress = methodImpl.getInstructionsSize()
- Iterators.getLast(methodImpl.getInstructions().iterator()).getCodeUnits();
//TODO: does dalvik allow references to invalid registers?
final LocalInfo[] locals = new LocalInfo[registerCount];
@ -172,7 +177,7 @@ public abstract class DebugInfo implements Iterable<DebugItem> {
@Nullable
protected DebugItem readNextItem(@Nonnull DexReader reader) {
while (true) {
while (codeAddress <= lastInstructionAddress) {
int next = reader.readUbyte();
switch (next) {
case DebugItemType.END_SEQUENCE: {
@ -270,10 +275,13 @@ public abstract class DebugInfo implements Iterable<DebugItem> {
int adjusted = next - 0x0A;
codeAddress += adjusted / 15;
lineNumber += (adjusted % 15) - 4;
return new ImmutableLineNumber(codeAddress, lineNumber);
return codeAddress <= lastInstructionAddress
? new ImmutableLineNumber(codeAddress, lineNumber)
: endOfData();
}
}
}
return endOfData();
}
};
}