aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-06-27 19:41:13 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-06-27 19:44:00 +0200
commita2c1dcb323487cc3a78939261b7505544c0713de (patch)
treeb76bff8d36d863bc8c005daa2eca80c191cd9129 /pkg
parent919e77001d3bf564557d8b9c553285ac32d02ca7 (diff)
pkg/report: implement fuchsia reporter
Diffstat (limited to 'pkg')
-rw-r--r--pkg/report/fuchsia.go145
-rw-r--r--pkg/report/testdata/fuchsia/report/02
-rw-r--r--pkg/report/testdata/fuchsia/report/12
-rw-r--r--pkg/report/testdata/fuchsia/report/22
-rw-r--r--pkg/report/testdata/fuchsia/report/3108
5 files changed, 210 insertions, 49 deletions
diff --git a/pkg/report/fuchsia.go b/pkg/report/fuchsia.go
index 4e227fc93..b7da7f3c1 100644
--- a/pkg/report/fuchsia.go
+++ b/pkg/report/fuchsia.go
@@ -4,46 +4,155 @@
package report
import (
+ "bufio"
"bytes"
+ "fmt"
+ "path/filepath"
"regexp"
+ "strconv"
+ "strings"
+
+ "github.com/google/syzkaller/pkg/symbolizer"
+ "github.com/ianlancetaylor/demangle"
)
type fuchsia struct {
- kernelSrc string
- kernelObj string
- ignores []*regexp.Regexp
+ obj string
+ ignores []*regexp.Regexp
}
+var (
+ zirconPanic = []byte("ZIRCON KERNEL PANIC")
+ zirconPanicShort = []byte("KERNEL PANIC")
+ zirconRIP = regexp.MustCompile(` RIP: (0x[0-9a-f]+) `)
+ zirconBT = regexp.MustCompile(`^bt#[0-9]+: (0x[0-9a-f]+)`)
+ zirconReportEnd = []byte("Halted")
+ zirconUnrelated = []*regexp.Regexp{
+ regexp.MustCompile(`^\[\d+\.\d+\] \d+\.\d+`),
+ regexp.MustCompile(`stopping other cpus`),
+ regexp.MustCompile(`^halting cpu`),
+ regexp.MustCompile(`^dso: `),
+ regexp.MustCompile(`^UPTIME: `),
+ regexp.MustCompile(`^BUILDID `),
+ regexp.MustCompile(`^Halting\.\.\.`),
+ }
+ zirconSkip = []*regexp.Regexp{
+ regexp.MustCompile("^platform_halt$"),
+ regexp.MustCompile("^exception_die$"),
+ regexp.MustCompile("^_panic$"),
+ }
+)
+
func ctorFuchsia(kernelSrc, kernelObj string, ignores []*regexp.Regexp) (Reporter, []string, error) {
ctx := &fuchsia{
- kernelSrc: kernelSrc,
- kernelObj: kernelObj,
- ignores: ignores,
+ obj: filepath.Join(kernelObj, "zircon.elf"),
+ ignores: ignores,
}
return ctx, nil, nil
}
func (ctx *fuchsia) ContainsCrash(output []byte) bool {
- return bytes.Contains(output, []byte("ZIRCON KERNEL PANIC")) ||
- bytes.Contains(output, []byte("Supervisor Page Fault"))
+ return bytes.Contains(output, zirconPanic)
}
func (ctx *fuchsia) Parse(output []byte) *Report {
- title, pos := "", 0
- if pos = bytes.Index(output, []byte("ZIRCON KERNEL PANIC")); pos != -1 {
- title = "ZIRCON KERNEL PANIC"
- } else if pos = bytes.Index(output, []byte("Supervisor Page Fault")); pos != -1 {
- title = "Supervisor Page Fault"
- } else {
+ pos := bytes.Index(output, zirconPanic)
+ if pos == -1 {
return nil
}
- return &Report{
- Title: title,
- Report: output,
+ rep := &Report{
+ Title: string(zirconPanicShort),
Output: output,
StartPos: pos,
- EndPos: pos + len(title),
+ EndPos: len(output),
+ }
+ symb := symbolizer.NewSymbolizer()
+ defer symb.Close()
+ where := ""
+ for s := bufio.NewScanner(bytes.NewReader(output[pos:])); s.Scan(); {
+ line := s.Bytes()
+ if len(line) == 0 || matchesAny(line, zirconUnrelated) {
+ continue
+ }
+ if bytes.Equal(line, zirconReportEnd) {
+ break
+ }
+ if bytes.Contains(line, []byte("DEBUG ASSERT FAILED")) {
+ rep.Title = "ASSERT FAILED"
+ }
+ if bytes.Contains(line, []byte("Supervisor Page Fault exception")) {
+ rep.Title = "Supervisor fault"
+ }
+ if match := zirconRIP.FindSubmatchIndex(line); match != nil {
+ ctx.processPC(rep, symb, line, match, false, &where)
+ } else if match := zirconBT.FindSubmatchIndex(line); match != nil {
+ if ctx.processPC(rep, symb, line, match, true, &where) {
+ continue
+ }
+ }
+ rep.Report = append(rep.Report, line...)
+ rep.Report = append(rep.Report, '\n')
+ }
+ if where != "" {
+ rep.Title = fmt.Sprintf("%v in %v", rep.Title, where)
+ }
+ return rep
+}
+
+func (ctx *fuchsia) processPC(rep *Report, symb *symbolizer.Symbolizer,
+ line []byte, match []int, call bool, where *string) bool {
+ prefix := line[match[0]:match[1]]
+ pcStart := match[2] - match[0]
+ pcEnd := match[3] - match[0]
+ pcStr := prefix[pcStart:pcEnd]
+ pc, err := strconv.ParseUint(string(pcStr), 0, 64)
+ if err != nil {
+ return false
+ }
+ shortPC := pc & 0xfffffff
+ pc = 0xffffffff80000000 | shortPC
+ if call {
+ pc--
+ }
+ frames, err := symb.Symbolize(ctx.obj, pc)
+ if err != nil || len(frames) == 0 {
+ return false
+ }
+ for _, frame := range frames {
+ file := ctx.trimFile(frame.File)
+ name := demangle.Filter(frame.Func, demangle.NoParams, demangle.NoTemplateParams)
+ if wrap := "do_syscall<wrapper_"; strings.HasPrefix(name, wrap) {
+ // Work around clang bug which results in demangled name into debug info.
+ if brace := strings.IndexByte(name, '('); brace != -1 {
+ name = name[len(wrap):brace]
+ }
+ }
+ if *where == "" && !matchesAny([]byte(name), zirconSkip) {
+ *where = name
+ }
+ id := "[ inline ]"
+ if !frame.Inline {
+ id = fmt.Sprintf("0x%08x", shortPC)
+ }
+ start := replace(append([]byte{}, prefix...), pcStart, pcEnd, []byte(id))
+ frameLine := fmt.Sprintf("%s %v %v:%v\n", start, name, file, frame.Line)
+ rep.Report = append(rep.Report, frameLine...)
+ }
+ return true
+}
+
+func (ctx *fuchsia) trimFile(file string) string {
+ const (
+ prefix1 = "zircon/kernel/"
+ prefix2 = "zircon/"
+ )
+ if pos := strings.LastIndex(file, prefix1); pos != -1 {
+ return file[pos+len(prefix1):]
+ }
+ if pos := strings.LastIndex(file, prefix2); pos != -1 {
+ return file[pos+len(prefix2):]
}
+ return file
}
func (ctx *fuchsia) Symbolize(rep *Report) error {
diff --git a/pkg/report/testdata/fuchsia/report/0 b/pkg/report/testdata/fuchsia/report/0
index ffa5a4520..ca478b5af 100644
--- a/pkg/report/testdata/fuchsia/report/0
+++ b/pkg/report/testdata/fuchsia/report/0
@@ -1,4 +1,4 @@
-TITLE: ZIRCON KERNEL PANIC
+TITLE: KERNEL PANIC
gfxconsole: rows <PAGE FAULT> Instruction Pointer = 0x10:0xffffffff801a41a7
48<PAGE FAULT> Stack Pointer = 0x18:0xffffff9951906e90
diff --git a/pkg/report/testdata/fuchsia/report/1 b/pkg/report/testdata/fuchsia/report/1
index f1db54cea..6b03e015d 100644
--- a/pkg/report/testdata/fuchsia/report/1
+++ b/pkg/report/testdata/fuchsia/report/1
@@ -1,4 +1,4 @@
-TITLE: ZIRCON KERNEL PANIC
+TITLE: ASSERT FAILED
ZIRCON KERNEL PANIC
diff --git a/pkg/report/testdata/fuchsia/report/2 b/pkg/report/testdata/fuchsia/report/2
index af222743f..0083e11c4 100644
--- a/pkg/report/testdata/fuchsia/report/2
+++ b/pkg/report/testdata/fuchsia/report/2
@@ -1,4 +1,4 @@
-TITLE: ZIRCON KERNEL PANIC
+TITLE: KERNEL PANIC
ZIRCON KERNEL PANIC
diff --git a/pkg/report/testdata/fuchsia/report/3 b/pkg/report/testdata/fuchsia/report/3
index 2dcaa6b00..032b9a807 100644
--- a/pkg/report/testdata/fuchsia/report/3
+++ b/pkg/report/testdata/fuchsia/report/3
@@ -1,35 +1,87 @@
-TITLE: Supervisor Page Fault
+TITLE: Supervisor fault
+[00171.272] 01102.01116> <PAGE FAULT> Error Code Value = 0x0
+ZIRCON KERNEL PANIC
+[00171.272] 01102.01116> <PAGE FAULT> Error Code Type = supervisor read data, page not present
+
+[00171.272] 01102.01116> dump_thread: t 0xffffff80007236c0 (svchost:initial-thread)
+UPTIME: 171276ms
+[00171.272] 01102.01116> state run, curr/last cpu 2/2, cpu_affinity 0xffffffff, priority 20 [16:4,20], remaining time slice 382244
+BUILDID git-d0845c2dca0182181dfbf2209e1c03905ebfd739
+[00171.272] 01102.01116> runtime_ns 631146343, runtime_s 0
+
+[00171.272] 01102.01116> stack 0xffffff99d68d8000, stack_size 8192
+dso: id=8ac492895f1aa9dc4798a997fa132e9b3809a5e6 base=0xffffffff00100000 name=zircon.elf
+[00171.272] 01102.01116> entry 0xffffffff00163be8, arg 0xffffff8000723548, flags 0x0
+stopping other cpus
+halting cpu 0
+halting cpu 1
+halting cpu 3
vector 14
Supervisor Page Fault exception, halting
-CS: 0x10 RIP: 0xffffffff8019fabf EFL: 0x10282 CR2: 0x18
-RAX: 0xffffffff801d1fe0 RBX: 0xffffff806496e0e0 RCX: 0x10000 RDX: 0
-RSI: 0xffffff806496e0e0 RDI: 0 RBP: 0xffffff93ab473d30 RSP: 0xffffff93ab473d20
-R8: 0xa9 R9: 0xffffffff801ccd46 R10: 0 R11: 0xffffffff
-R12: 0xffffff806496e0e0 R13: 0xffffff93ab473e98 R14: 0xffffff93ab473e98 R15: 0xffffff8051d507a8
-errc: 0
-bottom of kernel stack at 0xffffff93ab473c70:
-0xffffff93ab473c70: 00000000 00000000 6496e0e0 ffffff80 |...........d....|
-0xffffff93ab473c80: ab473d30 ffffff93 6496e0e0 ffffff80 |0=G........d....|
-0xffffff93ab473c90: 00000000 00000000 00010000 00000000 |................|
-0xffffff93ab473ca0: 801d1fe0 ffffffff 000000a9 00000000 |................|
-0xffffff93ab473cb0: 801ccd46 ffffffff 00000000 00000000 |F...............|
-0xffffff93ab473cc0: ffffffff 00000000 6496e0e0 ffffff80 |...........d....|
-0xffffff93ab473cd0: ab473e98 ffffff93 ab473e98 ffffff93 |.>G......>G.....|
-0xffffff93ab473ce0: 51d507a8 ffffff80 0000000e 00000000 |...Q............|
+ CS: 0x10 RIP: 0xffffffff00118e64 EFL: 0x10293 CR2: 0x8
+ RAX: 0xff RBX: 0x1 RCX: 0 RDX: 0x1
+ RSI: 0xff RDI: 0x3 RBP: 0xffffff99d68d9cf0 RSP: 0xffffff99d68d9cb0
+ R8: 0x14 R9: 0xffffffff00201419 R10: 0xffffffff0021ec50 R11: 0x1b
+ R12: 0x3 R13: 0x1000000 R14: 0xffffff800961b5c0 R15: 0x7ffffff000
+errc: 0
+bottom of kernel stack at 0xffffff99d68d9c00:
+0xffffff99d68d9c00: 00000003 00000000 000000ff 00000000 |................|
+0xffffff99d68d9c10: d68d9cf0 ffffff99 00000001 00000000 |................|
+0xffffff99d68d9c20: 00000001 00000000 00000000 00000000 |................|
+0xffffff99d68d9c30: 000000ff 00000000 00000014 00000000 |................|
+0xffffff99d68d9c40: 00201419 ffffffff 0021ec50 ffffffff |.. .....P.!.....|
+0xffffff99d68d9c50: 0000001b 00000000 00000003 00000000 |................|
+0xffffff99d68d9c60: 01000000 00000000 0961b5c0 ffffff80 |..........a.....|
+0xffffff99d68d9c70: fffff000 0000007f 0000000e 00000000 |................|
platform_halt suggested_action 0 reason 9
Halting...
-bt#00: 0xffffffff80105861
-bt#01: 0xffffffff801061bb
-bt#02: 0xffffffff80112d0d
-bt#03: 0xffffffff8013c8a0
-bt#04: 0xffffffff801481a1
-bt#05: 0xffffffff80148212
-bt#06: 0xffffffff80148212
-bt#07: 0xffffffff8013cee3
-bt#08: 0xffffffff801b1d55
-bt#09: 0xffffffff80105ad3
-bt#10: end
-cannot create qrcode
+bt#00: 0xffffffff001058a6
+bt#01: 0xffffffff00108359
+bt#02: 0xffffffff00108ee3
+bt#03: 0xffffffff001158d2
+bt#04: 0xffffffff0010d1ce
+bt#05: 0xffffffff001c0ace
+bt#06: 0xffffffff001c0e26
+bt#07: 0xffffffff0015c0f0
+bt#08: 0xffffffff0015ec6b
+bt#09: 0xffffffff0018ed58
+bt#10: 0xffffffff0016fb9a
+bt#11: 0xffffffff00115e7b
+bt#12: end
Halted
entering panic shell loop
+
+REPORT:
+ZIRCON KERNEL PANIC
+vector 14
+Supervisor Page Fault exception, halting
+ CS: 0x10 RIP: 0xffffffff00118e64 EFL: 0x10293 CR2: 0x8
+ RAX: 0xff RBX: 0x1 RCX: 0 RDX: 0x1
+ RSI: 0xff RDI: 0x3 RBP: 0xffffff99d68d9cf0 RSP: 0xffffff99d68d9cb0
+ R8: 0x14 R9: 0xffffffff00201419 R10: 0xffffffff0021ec50 R11: 0x1b
+ R12: 0x3 R13: 0x1000000 R14: 0xffffff800961b5c0 R15: 0x7ffffff000
+errc: 0
+bottom of kernel stack at 0xffffff99d68d9c00:
+0xffffff99d68d9c00: 00000003 00000000 000000ff 00000000 |................|
+0xffffff99d68d9c10: d68d9cf0 ffffff99 00000001 00000000 |................|
+0xffffff99d68d9c20: 00000001 00000000 00000000 00000000 |................|
+0xffffff99d68d9c30: 000000ff 00000000 00000014 00000000 |................|
+0xffffff99d68d9c40: 00201419 ffffffff 0021ec50 ffffffff |.. .....P.!.....|
+0xffffff99d68d9c50: 0000001b 00000000 00000003 00000000 |................|
+0xffffff99d68d9c60: 01000000 00000000 0961b5c0 ffffff80 |..........a.....|
+0xffffff99d68d9c70: fffff000 0000007f 0000000e 00000000 |................|
+platform_halt suggested_action 0 reason 9
+bt#00: 0xffffffff001058a6
+bt#01: 0xffffffff00108359
+bt#02: 0xffffffff00108ee3
+bt#03: 0xffffffff001158d2
+bt#04: 0xffffffff0010d1ce
+bt#05: 0xffffffff001c0ace
+bt#06: 0xffffffff001c0e26
+bt#07: 0xffffffff0015c0f0
+bt#08: 0xffffffff0015ec6b
+bt#09: 0xffffffff0018ed58
+bt#10: 0xffffffff0016fb9a
+bt#11: 0xffffffff00115e7b
+bt#12: end