aboutsummaryrefslogtreecommitdiff
path: root/baksmali
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2016-09-09 13:32:14 +0100
committerNarayan Kamath <narayan@google.com>2016-09-09 13:50:45 +0100
commit94bfbe54ada0ffa8f351952f78fcc57fd3a6763c (patch)
tree40b39046f21249e08875d23b8d1d271179361709 /baksmali
parent649c1501e6183fc4e5ddad949f19889fe16e5235 (diff)
parent7079014a29869e1bac22226681de3471b6dc11b5 (diff)
downloadsmali-94bfbe54ada0ffa8f351952f78fcc57fd3a6763c.tar.gz
smali: update to upstream master.
test: make test-art-host bug: 30550796 Change-Id: I9ae983635a2ad25c9f3a033aaf49c5ea0ef0c3c0
Diffstat (limited to 'baksmali')
-rw-r--r--baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java108
-rw-r--r--baksmali/src/test/java/org/jf/baksmali/LargeLocalTest.java (renamed from baksmali/src/test/java/org/jf/baksmali/LambdaTest.java)29
-rw-r--r--baksmali/src/test/resources/LambdaTest/HelloWorldLambda.smali55
-rw-r--r--baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali11
-rw-r--r--baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali11
-rw-r--r--baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali11
6 files changed, 103 insertions, 122 deletions
diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java
index fc43d6f1..fe85fe00 100644
--- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java
+++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java
@@ -79,11 +79,20 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
return opcode.isVolatileFieldAccessor() || opcode == Opcode.THROW_VERIFICATION_ERROR;
}
+ private String writeInvalidItemIndex(InvalidItemIndex ex, int type, IndentingWriter writer)
+ throws IOException {
+ writer.write("#");
+ writer.write(ex.getMessage());
+ writer.write("\n");
+ return String.format("%s@%d", ReferenceType.toString(type), ex.getInvalidIndex());
+ }
+
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
Opcode opcode = instruction.getOpcode();
String verificationErrorName = null;
String referenceString = null;
+ String referenceString2 = null;
boolean commentOutInstruction = false;
@@ -100,25 +109,19 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
if (instruction instanceof ReferenceInstruction) {
ReferenceInstruction referenceInstruction = (ReferenceInstruction)instruction;
+ String classContext = null;
+ if (methodDef.classDef.options.useImplicitReferences) {
+ classContext = methodDef.method.getDefiningClass();
+ }
+
try {
Reference reference = referenceInstruction.getReference();
-
- String classContext = null;
- if (methodDef.classDef.options.useImplicitReferences) {
- classContext = methodDef.method.getDefiningClass();
- }
-
referenceString = ReferenceUtil.getReferenceString(reference, classContext);
assert referenceString != null;
} catch (InvalidItemIndex ex) {
- writer.write("#");
- writer.write(ex.getMessage());
- writer.write("\n");
commentOutInstruction = true;
-
- referenceString = String.format("%s@%d",
- ReferenceType.toString(referenceInstruction.getReferenceType()),
- ex.getInvalidIndex());
+ referenceString = writeInvalidItemIndex(ex, referenceInstruction.getReferenceType(),
+ writer);
} catch (ReferenceType.InvalidReferenceTypeException ex) {
writer.write("#invalid reference type: ");
writer.printSignedIntAsDec(ex.getReferenceType());
@@ -126,6 +129,25 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
referenceString = "invalid_reference";
}
+
+ if (instruction instanceof DualReferenceInstruction) {
+ DualReferenceInstruction dualReferenceInstruction =
+ (DualReferenceInstruction) instruction;
+ try {
+ Reference reference2 = dualReferenceInstruction.getReference2();
+ referenceString2 = ReferenceUtil.getReferenceString(reference2, classContext);
+ } catch (InvalidItemIndex ex) {
+ commentOutInstruction = true;
+ referenceString2 = writeInvalidItemIndex(ex,
+ dualReferenceInstruction.getReferenceType2(), writer);
+ } catch (ReferenceType.InvalidReferenceTypeException ex) {
+ writer.write("#invalid reference type: ");
+ writer.printSignedIntAsDec(ex.getReferenceType());
+ commentOutInstruction = true;
+
+ referenceString2 = "invalid_reference";
+ }
+ }
}
if (instruction instanceof Instruction31t) {
@@ -308,11 +330,6 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
writer.write(", ");
writeThirdRegister(writer);
break;
- case Format25x:
- writeOpcode(writer);
- writer.write(' ');
- writeInvoke25xRegisters(writer); // vC, {vD, ...}
- break;
case Format35c:
writeOpcode(writer);
writer.write(' ');
@@ -355,6 +372,24 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
writer.write(", ");
writeVtableIndex(writer);
break;
+ case Format45cc:
+ writeOpcode(writer);
+ writer.write(' ');
+ writeInvokeRegisters(writer);
+ writer.write(", ");
+ writer.write(referenceString);
+ writer.write(", ");
+ writer.write(referenceString2);
+ break;
+ case Format4rcc:
+ writeOpcode(writer);
+ writer.write(' ');
+ writeInvokeRangeRegisters(writer);
+ writer.write(", ");
+ writer.write(referenceString);
+ writer.write(", ");
+ writer.write(referenceString2);
+ break;
default:
assert false;
return false;
@@ -438,43 +473,6 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
writer.write('}');
}
- protected void writeInvoke25xRegisters(IndentingWriter writer) throws IOException {
- OneFixedFourParameterRegisterInstruction instruction =
- (OneFixedFourParameterRegisterInstruction)this.instruction;
- final int parameterRegCount = instruction.getParameterRegisterCount();
-
- writeRegister(writer, instruction.getRegisterFixedC()); // fixed register always present
-
- writer.write(", {");
- switch (parameterRegCount) {
- case 1:
- writeRegister(writer, instruction.getRegisterParameterD());
- break;
- case 2:
- writeRegister(writer, instruction.getRegisterParameterD());
- writer.write(", ");
- writeRegister(writer, instruction.getRegisterParameterE());
- break;
- case 3:
- writeRegister(writer, instruction.getRegisterParameterD());
- writer.write(", ");
- writeRegister(writer, instruction.getRegisterParameterE());
- writer.write(", ");
- writeRegister(writer, instruction.getRegisterParameterF());
- break;
- case 4:
- writeRegister(writer, instruction.getRegisterParameterD());
- writer.write(", ");
- writeRegister(writer, instruction.getRegisterParameterE());
- writer.write(", ");
- writeRegister(writer, instruction.getRegisterParameterF());
- writer.write(", ");
- writeRegister(writer, instruction.getRegisterParameterG());
- break;
- }
- writer.write('}');
- }
-
protected void writeInvokeRangeRegisters(IndentingWriter writer) throws IOException {
RegisterRangeInstruction instruction = (RegisterRangeInstruction)this.instruction;
diff --git a/baksmali/src/test/java/org/jf/baksmali/LambdaTest.java b/baksmali/src/test/java/org/jf/baksmali/LargeLocalTest.java
index 5431df54..28def63d 100644
--- a/baksmali/src/test/java/org/jf/baksmali/LambdaTest.java
+++ b/baksmali/src/test/java/org/jf/baksmali/LargeLocalTest.java
@@ -1,18 +1,18 @@
/*
- * Copyright 2015, Google Inc.
+ * Copyright 2016, 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
+ * 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
+ * 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
+ * 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.
*
@@ -33,17 +33,22 @@ package org.jf.baksmali;
import org.junit.Test;
-public class LambdaTest extends IdenticalRoundtripTest {
+/**
+ * Test for a bug related to debug items that refer to a register that's outside the expected range for a method
+ */
+public class LargeLocalTest extends IdenticalRoundtripTest {
+ @Test
+ public void testLargeEndLocal() {
+ runTest("LargeEndLocal");
+ }
- private baksmaliOptions createOptions() {
- baksmaliOptions options = new baksmaliOptions();
- options.apiLevel = 23; // since we need at least level 23 for lambda opcodes
- options.experimental = true; // since these opcodes aren't implemented in runtime yet);
- return options;
+ @Test
+ public void testLargeRestartLocal() {
+ runTest("LargeRestartLocal");
}
@Test
- public void testHelloWorldLambda() {
- runTest("HelloWorldLambda", createOptions());
+ public void testLargeStartLocal() {
+ runTest("LargeStartLocal");
}
}
diff --git a/baksmali/src/test/resources/LambdaTest/HelloWorldLambda.smali b/baksmali/src/test/resources/LambdaTest/HelloWorldLambda.smali
deleted file mode 100644
index d70ced50..00000000
--- a/baksmali/src/test/resources/LambdaTest/HelloWorldLambda.smali
+++ /dev/null
@@ -1,55 +0,0 @@
-.class public LHelloWorldLambda;
-
-#Ye olde hello world application (with lambdas!)
-#To assemble and run this on a phone or emulator:
-#
-#java -jar smali.jar -o classes.dex HelloWorldLambda.smali HelloWorldFunctionalInterface.smali
-#zip HelloWorld.zip classes.dex
-#adb push HelloWorld.zip /data/local
-#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
-#
-#if you get out of memory type errors when running smali.jar, try
-#java -Xmx512m -jar smali.jar HelloWorldLambda.smali
-#instead
-
-.super Ljava/lang/Object;
-
-.method public static doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
- .registers 6 # 4 parameters, 2 locals
- liberate-variable v0, p0, "helloworld"
-
- sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;
- invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
-
- return-void
-.end method
-
-.method public static main([Ljava/lang/String;)V
- .registers 9 # 1 parameter, 8 locals
-
- sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
-
- const-string v1, "Hello World!"
- const-string v2, "How" # vD
- const-string v3, "are" # vE
- const-string v4, "you" # vF
- const-string v5, "doing?" # vG
-
- capture-variable v1, "helloworld"
-
- # TODO: do I need to pass the type of the lambda's functional interface here as a type id?
- create-lambda v1, LHelloWorldLambda;->doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
- # Method descriptor is not required here, because only the single-abstract method is ever invoked.
- invoke-lambda v1, {v2, v3, v4, v5}
-
- box-lambda v6, v1
- invoke-virtual {v6, v2, v3, v4, v5}, LHelloWorldFunctionalInterface;->applyFourStrings(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
-
- # FIXME: should be \HelloWorldFunctionalInterface; instead of L...;
-
- # TODO: do we really need the type descriptor here at all?
- unbox-lambda v7, v6, LHelloWorldFunctionalInterface;
- invoke-lambda v7, {v2, v3, v4, v5}
-
- return-void
-.end method
diff --git a/baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali b/baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali
new file mode 100644
index 00000000..8c7e72ce
--- /dev/null
+++ b/baksmali/src/test/resources/LargeLocalTest/LargeEndLocal.smali
@@ -0,0 +1,11 @@
+.class LLargeRestartLocal;
+.super Ljava/lang/Object;
+
+
+# virtual methods
+.method public static main([Ljava/lang/String;)V
+ .registers 2
+
+ .end local p99
+ return-void
+.end method
diff --git a/baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali b/baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali
new file mode 100644
index 00000000..41c60d02
--- /dev/null
+++ b/baksmali/src/test/resources/LargeLocalTest/LargeRestartLocal.smali
@@ -0,0 +1,11 @@
+.class LLargeEndLocal;
+.super Ljava/lang/Object;
+
+
+# virtual methods
+.method public static main([Ljava/lang/String;)V
+ .registers 2
+
+ .restart local p99
+ return-void
+.end method
diff --git a/baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali b/baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali
new file mode 100644
index 00000000..b811844b
--- /dev/null
+++ b/baksmali/src/test/resources/LargeLocalTest/LargeStartLocal.smali
@@ -0,0 +1,11 @@
+.class LLargeStartLocal;
+.super Ljava/lang/Object;
+
+
+# virtual methods
+.method public static main([Ljava/lang/String;)V
+ .registers 2
+
+ .local p99, "blah":I
+ return-void
+.end method