override fun extract()

in src/main/kotlin/com/github/mkartashev/hserr/miner/artifact/Header.kt [24:48]


    override fun extract(log: HsErrLog): HeaderArtifact {
        var headerLine = log.start
        while (log.charAt(headerLine) == '#') headerLine = headerLine.moveToNextLine()

        if (headerLine == log.start) fail("Not one line with # in the beginning of the crash log")

        val header = log.start.selectUpTo(headerLine.moveToPrevLine().moveToLineEnd())
        val pidString = header.start.moveToString("pid=").moveToNextChar(4)
            .selectCurrentWord().toString().trimEnd(',')
        val pid = ArtifactExtractor.parseLong(pidString)

        // #  Internal Error (relocInfo_x86.cpp:155), pid=13063, tid=13109
        // #  guarantee(which == Assembler::imm_operand) failed: must be immediate operand
        // or
        // #  Out of Memory Error (./src/hotspot/os/windows/os_windows.cpp:3521), pid=1284, tid=11844
        val pidLineStart = log.start.moveToLineWith("pid=")
        val pidLine = pidLineStart.selectUpToEOL().toString()
        val reason = pidLine.substringBefore('(', "").trimEnd().trimStart('#', ' ')
        val sourceLocation =
            if (reason.startsWith("EXCEPTION_") || reason.startsWith("SIG")) "" else
                pidLine.substringAfter('(', "").substringBefore(')')
        val assertion = pidLineStart.moveToNextLine().selectUpToEOL().toString().trimStart('#', ' ')

        return HeaderArtifact(log, header, pid, reason, sourceLocation, assertion)
    }