pkg/report: add ParseAll

ParseAll returns all reports in output.
Use it in syz-symbolize.
This commit is contained in:
Dmitry Vyukov 2020-05-13 20:49:07 +02:00
parent 1e61c8bc14
commit 50749f54cd
2 changed files with 34 additions and 13 deletions

View File

@ -224,6 +224,18 @@ func IsSuppressed(reporter Reporter, output []byte) bool {
bytes.Contains(output, gceConsoleHangup)
}
// ParseAll returns all successive reports in output.
func ParseAll(reporter Reporter, output []byte) (reports []*Report) {
for {
rep := reporter.Parse(output)
if rep == nil {
return
}
reports = append(reports, rep)
output = output[rep.SkipPos:]
}
}
// GCE console connection sometimes fails with this message.
// The message frequently happens right after a kernel panic.
// So if we see it in output where we recognized a crash, we mark the report as corrupted

View File

@ -50,21 +50,30 @@ func main() {
fmt.Fprintf(os.Stderr, "failed to open input file: %v\n", err)
os.Exit(1)
}
rep := reporter.Parse(text)
if rep == nil {
rep = &report.Report{Report: text}
} else if *flagOutDir != "" {
saveCrash(rep, *flagOutDir)
reps := report.ParseAll(reporter, text)
if len(reps) == 0 {
rep := &report.Report{Report: text}
if err := reporter.Symbolize(rep); err != nil {
fmt.Fprintf(os.Stderr, "failed to symbolize report: %v\n", err)
os.Exit(1)
}
os.Stdout.Write(rep.Report)
return
}
if err := reporter.Symbolize(rep); err != nil {
fmt.Fprintf(os.Stderr, "failed to symbolize report: %v\n", err)
os.Exit(1)
for _, rep := range reps {
if *flagOutDir != "" {
saveCrash(rep, *flagOutDir)
}
if err := reporter.Symbolize(rep); err != nil {
fmt.Fprintf(os.Stderr, "failed to symbolize report: %v\n", err)
}
fmt.Printf("TITLE: %v\n", rep.Title)
fmt.Printf("CORRUPTED: %v (%v)\n", rep.Corrupted, rep.CorruptedReason)
fmt.Printf("MAINTAINERS: %v\n", rep.Maintainers)
fmt.Printf("\n")
os.Stdout.Write(rep.Report)
fmt.Printf("\n\n")
}
fmt.Printf("TITLE: %v\n", rep.Title)
fmt.Printf("CORRUPTED: %v (%v)\n", rep.Corrupted, rep.CorruptedReason)
fmt.Printf("MAINTAINERS: %v\n", rep.Maintainers)
fmt.Printf("\n")
os.Stdout.Write(rep.Report)
}
func saveCrash(rep *report.Report, path string) {