Skip to content

Commit

Permalink
Todo fixes, symbolic stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
CaelmBleidd committed Jul 19, 2023
1 parent 72af3be commit 14c17e5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
15 changes: 15 additions & 0 deletions usvm-core/src/main/kotlin/org/usvm/CallStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ data class UCallStackFrame<Method, Statement>(
val returnSite: Statement?,
)

data class UStackTraceFrame<Method, Statement>(
val method: Method,
val instruction: Statement,
)

class UCallStack<Method, Statement> private constructor(
private val stack: ArrayDeque<UCallStackFrame<Method, Statement>>,
) : Collection<UCallStackFrame<Method, Statement>> by stack {
Expand All @@ -30,6 +35,16 @@ class UCallStack<Method, Statement> private constructor(
return UCallStack(newStack)
}

fun stackTrace(currentInstruction: Statement): List<UStackTraceFrame<Method, Statement>> {
val stacktrace: MutableList<UStackTraceFrame<Method, Statement>> = stack
.zipWithNext()
.mapTo(mutableListOf()) {
UStackTraceFrame(it.first.method, it.second.returnSite!!)
}

return stacktrace + UStackTraceFrame(stack.last().method, currentInstruction)
}

override fun toString(): String {
var frameCounter = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ fun createStopStrategy(

val stepsFromLastCovered = options.stepsFromLastCovered
if (stepsFromLastCovered != null) {
stopStrategies.add(StepsFromLastCoveredStopStrategy(stepsFromLastCovered.toULong(), getCollectedStatesCount))
val stepsFromLastCoveredStopStrategy = StepsFromLastCoveredStopStrategy(
stepsFromLastCovered.toULong(),
getCollectedStatesCount
)
stopStrategies.add(stepsFromLastCoveredStopStrategy)
}

if (stopStrategies.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.jacodb.impl.features.SyncUsagesExtension
import org.usvm.statistics.ApplicationGraph
import java.util.concurrent.ConcurrentHashMap

// TODO: add trap handlers
/**
* A [JcApplicationGraphImpl] wrapper.
*/
Expand Down
2 changes: 1 addition & 1 deletion usvm-jvm/src/main/kotlin/org/usvm/machine/JcInterpreter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class JcInterpreter(

@Suppress("UNUSED_PARAMETER")
private fun visitCatchStmt(scope: JcStepScope, stmt: JcCatchInst) {
TODO("Not yet implemented")
error("The catch instruction must be unfolded during processing of the instructions led to it")
}

private fun visitSwitchStmt(scope: JcStepScope, stmt: JcSwitchInst) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.usvm.machine.state

import org.jacodb.api.JcMethod
import org.jacodb.api.JcType
import org.jacodb.api.cfg.JcInst
import org.usvm.UExpr
import org.usvm.UHeapRef
import org.usvm.USort
import org.usvm.UStackTraceFrame

/**
* Represents a result of a method invocation.
Expand All @@ -29,7 +31,7 @@ sealed interface JcMethodResult {
open class JcException(
val address: UHeapRef,
val type: JcType,
// val symbolicStackTrace: List<JcMethod> // TODO should it contain locations? Probably, yes. Add message?
val symbolicStackTrace: List<UStackTraceFrame<JcMethod, JcInst>>
) : JcMethodResult {
override fun toString(): String = "${this::class.simpleName}: Address: $address, type: ${type.typeName}"
}
Expand All @@ -45,5 +47,6 @@ sealed interface JcMethodResult {
class UnprocessedJcException(
address: UHeapRef,
type: JcType,
) : JcException(address, type)
symbolicStackTrace: List<UStackTraceFrame<JcMethod, JcInst>>
) : JcException(address, type, symbolicStackTrace)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ fun JcState.returnValue(valueToReturn: UExpr<out USort>) {
}

/**
* TODO change docs
* Create an unprocessed exception from the [exception] and assign it to the [JcState.methodResult].
* Create an unprocessed exception with the [address] and the [type] and assign it to the [JcState.methodResult].
*/
fun JcState.createUnprocessedException(address: UHeapRef, type: JcType) {
methodResult = JcMethodResult.UnprocessedJcException(address, type)
methodResult = JcMethodResult.UnprocessedJcException(address, type, callStack.stackTrace(lastStmt))
}

fun JcState.throwException(exception: JcMethodResult.JcException) {
Expand All @@ -47,7 +46,7 @@ fun JcState.throwException(exception: JcMethodResult.JcException) {

// TODO: the last place where we distinguish implicitly thrown and explicitly thrown exceptions
methodResult = if (exception is JcMethodResult.UnprocessedJcException) {
JcMethodResult.JcException(exception.address, exception.type)
JcMethodResult.JcException(exception.address, exception.type, exception.symbolicStackTrace)
} else {
exception
}
Expand Down

0 comments on commit 14c17e5

Please sign in to comment.