Skip to content

Commit

Permalink
Fix inline method references
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed Oct 7, 2024
1 parent 9f9fda2 commit 119ad2a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private fun PeekingIterator<String>.readClass(classHeader: String): Class {
throw IllegalStateException("Expected '}' but got '${peek()}'")
}
}
return Class(classHeader, methods)
return Class(classHeader, methods, false)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Code(
return buildCode(codeStyle) {
val indexedMethods = buildIndexedMethods(classes)
classes.forEachIndexed { classIndex, clazz ->
if (clazz.builtIn) return@forEachIndexed
startClass(clazz)
val notLastClass = classIndex < classes.size - 1
clazz.methods.forEachIndexed { methodIndex, method ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ enum class ISA(val branchInstructions: ScatterSet<String>, val returnInstruction
)
}

data class Class(val header: String, val methods: List<Method>)
data class Class(val header: String, val methods: List<Method>, val builtIn: Boolean)

data class Method(val header: String, val instructionSet: InstructionSet, val index: Int = -1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal class DexDumpParser {
}
}
}
return Class("class $className", methods)
return Class("class $className", methods, false)
}

private fun Iterator<String>.readMethod(className: String): Method {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ internal class OatDumpParser {
jumpRegex: Regex,
methodCallRegex: Regex
): Class? {
if (className.matches(BuiltInKotlinClass)) {
return null
}
val builtIn = className.matches(BuiltInKotlinClass)
val methods = buildList {
while (hasNext()) {
val line = peek()
Expand All @@ -103,28 +101,30 @@ internal class OatDumpParser {

val match = MethodRegex.matchEntire(line)
if (match != null) {
add(readMethod(match, jumpRegex, methodCallRegex))
add(readMethod(match, jumpRegex, methodCallRegex, builtIn))
}
}
}
}
}
return Class("class $className", methods)
return Class("class $className", methods, builtIn)
}

private fun PeekingIterator<String>.readMethod(
match: MatchResult,
jumpRegex: Regex,
methodCallRegex: Regex
methodCallRegex: Regex,
builtIn: Boolean = false
): Method {
consumeUntil("DEX CODE:")
val methodReferences = readMethodReferences()

consumeUntil("CODE:")
val instructions = readNativeInstructions(jumpRegex, methodCallRegex)
val instructions = readNativeInstructions(jumpRegex, methodCallRegex, builtIn)

val method = match.getValue("method")
val index = match.getValue("methodIndex").toInt()

return Method(method, InstructionSet(isa, instructions, methodReferences), index)
}

Expand Down Expand Up @@ -157,7 +157,8 @@ internal class OatDumpParser {

private fun PeekingIterator<String>.readNativeInstructions(
jumpRegex: Regex,
methodCallRegex: Regex
methodCallRegex: Regex,
builtIn: Boolean
): List<Instruction> {
return buildList {
while (hasNext()) {
Expand All @@ -168,6 +169,7 @@ internal class OatDumpParser {
else -> {
val match = CodeRegex.matchEntire(next())
if (match != null) {
if (builtIn) continue
add(
readNativeInstruction(
this@readNativeInstructions,
Expand Down Expand Up @@ -202,13 +204,16 @@ internal class OatDumpParser {
// Skip the StackMap line
iterator.next()
// Check the InlineInfo if present
val methodIndex = DexInlineInfoRegex.matchEntire(iterator.peek())
if (methodIndex != null) {
callAddress = methodIndex.getValue("callAddress").toInt(16)
methodIndex.getValue("methodIndex").toInt()
} else {
-1
}
var index = -1
do {
val methodIndex = DexInlineInfoRegex.matchEntire(iterator.peek())
if (methodIndex != null) {
callAddress = methodIndex.getValue("callAddress").toInt(16)
index = methodIndex.getValue("methodIndex").toInt()
iterator.next()
}
} while (methodIndex != null)
index
} else {
-1
}
Expand Down

0 comments on commit 119ad2a

Please sign in to comment.