aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeronica Radu <veronicaradu@google.com>2019-09-10 09:16:41 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-09-23 15:35:26 +0200
commitd2db54aab721059334f9542aeba3e31e9de1e472 (patch)
treed0835c27b3f163fb89f306cfe18147df04019801
parent5a7028d005c1b6be0aa0288ea1bcf3fdd1163560 (diff)
tools/syz-showprio: add a tool to visualize the priority table
-rw-r--r--tools/syz-showprio/showprio.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/tools/syz-showprio/showprio.go b/tools/syz-showprio/showprio.go
new file mode 100644
index 000000000..96bc401d5
--- /dev/null
+++ b/tools/syz-showprio/showprio.go
@@ -0,0 +1,69 @@
+// Copyright 2019 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// syz-showprio visualizes the call to call priorities from the prog package.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "runtime"
+ "strings"
+
+ "github.com/google/syzkaller/pkg/db"
+ "github.com/google/syzkaller/pkg/mgrconfig"
+ "github.com/google/syzkaller/prog"
+)
+
+var (
+ flagOS = flag.String("os", runtime.GOOS, "target os")
+ flagArch = flag.String("arch", runtime.GOARCH, "target arch")
+ flagEnable = flag.String("enable", "", "comma-separated list of enabled syscalls")
+ flagCorpus = flag.String("corpus", "", "name of the corpus file")
+)
+
+func main() {
+ flag.Parse()
+ target, err := prog.GetTarget(*flagOS, *flagArch)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%v", err)
+ os.Exit(1)
+ }
+ if *flagEnable == "" {
+ fmt.Fprintf(os.Stderr, "no syscalls enabled")
+ os.Exit(1)
+ }
+ enabled := strings.Split(*flagEnable, ",")
+ _, err = mgrconfig.ParseEnabledSyscalls(target, enabled, nil)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to parse enabled syscalls: %v", err)
+ os.Exit(1)
+ }
+ corpus, err := db.ReadCorpus(*flagCorpus, target)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to read corpus: %v", err)
+ os.Exit(1)
+ }
+ showPriorities(enabled, target.CalculatePriorities(corpus), target)
+}
+
+func showPriorities(calls []string, prios [][]float32, target *prog.Target) {
+ printLine(append([]string{"CALLS"}, calls...))
+ for _, callRow := range calls {
+ line := []string{callRow}
+ for _, callCol := range calls {
+ val := prios[target.SyscallMap[callRow].ID][target.SyscallMap[callCol].ID]
+ line = append(line, fmt.Sprintf("%.2f", val))
+ }
+ printLine(line)
+ }
+}
+
+func printLine(values []string) {
+ fmt.Printf("|")
+ for _, val := range values {
+ fmt.Printf("%-20v|", val)
+ }
+ fmt.Printf("\n")
+}