Code Monkey home page Code Monkey logo

tracehash's Introduction

TraceHash

TraceHash hashes your exceptions into exception signatures that formalize the intuitive notion of "exception sameness": exceptions with the same signature are normally considered "the same" (e.g. when filing bug reports).

Usage

tracehash.stackTraceHash(exception)
// will produce something like
// "SOE-b33ffcec6a101750802bcebecae59e6a657145aa"
// or "IOOBE-1b4035e1d5b6023ecd1ef2673278057b5a3bb44c"

Motivation

Say you are fuzzing a Java application, and find an AssertionError:

java.lang.AssertionError: assertion failed: position error: position not set for Ident(<error>) # 5299
        at scala.Predef$.assert(Predef.scala:219)
        at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:179)
        at dotty.tools.dotc.ast.Positioned.$anonfun$checkPos$4(Positioned.scala:203)
        at dotty.tools.dotc.ast.Positioned.$anonfun$checkPos$4$adapted(Positioned.scala:203)
        at scala.collection.immutable.List.foreach(List.scala:389)
        at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:203)
        at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:216)
        ....

If the same AssertionError happens with a different input file, the two errors are probably related, and you should only file one issue for both of them. But what exactly do we mean by "same error"? What algorithm should we use to compare different exception traces?

Should we compare the entire stacktrace? No, folklore and experience tells us that only the last few stacktrace entries are important.

Should we compare exception messages? Unless we can inspect the code generating messages, we don't know which parts of the message stay constant and which depend on a particular fuzzer input or change non-deterministically.

Should we compare line numbers? If someone changes one of the files appearing in the stacktrace without fixing the error, line numbers might change, but the error won't. Therefore, we should not take line numbers into account.

Should we compare file names? File names are less important than class names, especially in Scala, where a single file can contain multiple classes.


TraceHash would simplify the above exception down to:

java.lang.AssertionError
        at scala.Predef$.assert
        at dotty.tools.dotc.ast.Positioned.check$1
        at dotty.tools.dotc.ast.Positioned.$anonfun$checkPos$4
        at dotty.tools.dotc.ast.Positioned.$anonfun$checkPos$4$adapted
        at scala.collection.immutable.List.foreach

and then hash it using SHA-1.

Stack overflows

Special care needs to be taken to simplify StackOverflowException, such as:

java.lang.StackOverflowError
        at dotty.tools.dotc.core.Types$TypeProxy.superType(Types.scala:1460)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:192)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:182)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:192)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:178)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:192)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:182)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:192)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:178)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:192)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:182)

We can see that this stacktrace consists of a repeating fragment of length 11:

        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:182)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:192)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1(TypeApplications.scala:178)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:171)

and a prefix of length 1:

        at dotty.tools.dotc.core.Types$TypeProxy.superType(Types.scala:1460)

Clearly, the prefix is not important, only the repeating fragment is.

Note that looking at the very end of a StackOveflowException stacktrace, we can not tell how the repeating fragment started. For instance, let's imagine that our stacktrace ends in d b a b c a b c a b c. We can not tell if the repeating fragment is a b c or b c a or c a b. In order to produce consistent signatures, TraceHash sorts all possible options in lexicographic order.

TraceHash would simplify the above exception stacktrace down to (modulo possible reordering of the entries as explained above):

java.lang.StackOverflowError
        at dotty.tools.dotc.util.Stats$.track
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1
        at dotty.tools.dotc.util.Stats$.track
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1
        at dotty.tools.dotc.util.Stats$.track
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$typeParams$extension$1
        at dotty.tools.dotc.util.Stats$.track
        at dotty.tools.dotc.core.TypeApplications$.typeParams$extension

tracehash's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.