override fun extract()

in src/main/kotlin/com/github/mkartashev/hserr/miner/artifact/CrashAddress.kt [30:60]


    override fun extract(log: HsErrLog): CrashAddressArtifact {
        val header = log.getArtifact(HeaderArtifact::class) ?: fail("No header section found")

        val headerLoc = header.location
        var pcFromSummarySelection = headerLoc.start.moveToString("pc=", stopAtBeginning = false).selectCurrentWord()
        if (pcFromSummarySelection.toString().endsWith(",")) pcFromSummarySelection =
            pcFromSummarySelection.trimRight(1)
        if (pcFromSummarySelection.endInclusive !in headerLoc) fail("pc= not found in the header")
        val pcString = pcFromSummarySelection.toString()
        if (!pcString.startsWith("0x")) fail("pc value in does not start with 0x")
        val pc = ArtifactExtractor.parseAddr(pcString) ?: fail("Failed to convert $pcString to integer")

        val resultSelections = mutableSetOf(pcFromSummarySelection)

        val instructionsArtifact = log.getArtifact(InstructionsArtifact::class)
        if (instructionsArtifact != null && pc != 0UL) {
            val start = instructionsArtifact.location.start
            val instrPCSelection = start.moveToString(pcString).selectCurrentHexNumber()
            if (!instrPCSelection.isEmpty()) resultSelections.add(instrPCSelection)

            val instrSelection = instrPCSelection.endInclusive.moveToString(pcString).selectCurrentHexNumber()
            if (!instrPCSelection.isEmpty()) resultSelections.add(instrSelection)
        }

        val registersArtifact = log.getArtifact(RegistersArtifact::class)
        if (registersArtifact != null) {
            resultSelections.addAll(registersArtifact.pcLocations)
        }

        return CrashAddressArtifact(log, resultSelections, pc)
    }