diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2026-01-19 15:54:08 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2026-01-20 08:35:12 +0000 |
| commit | 75769ae79e1f7c200dfc52bd7711b2b43f88f28c (patch) | |
| tree | 081441d182ac0e3d05fcdfd9d7bbbc56b6188bc5 /tools | |
| parent | faf99a10ff35487a689ef7a183b1081da5369152 (diff) | |
pkg/subsystem: export debug info
Make it possible to print more debugging information when (re)generating
a subsystem list.
Include parent inference details to the source code itself and add a
-debug flag to list the source files assigned to each subsystem.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/syz-query-subsystems/generator.go | 31 | ||||
| -rw-r--r-- | tools/syz-query-subsystems/query_subsystems.go | 19 |
2 files changed, 42 insertions, 8 deletions
diff --git a/tools/syz-query-subsystems/generator.go b/tools/syz-query-subsystems/generator.go index a7db17d3f..3e2251747 100644 --- a/tools/syz-query-subsystems/generator.go +++ b/tools/syz-query-subsystems/generator.go @@ -8,6 +8,7 @@ import ( "fmt" "go/format" "regexp" + "slices" "sort" "strings" "text/template" @@ -18,7 +19,8 @@ import ( "github.com/google/syzkaller/pkg/vcs" ) -func generateSubsystemsFile(name string, list []*subsystem.Subsystem, commit *vcs.Commit) ([]byte, error) { +func generateSubsystemsFile(name string, list []*subsystem.Subsystem, commit *vcs.Commit, + debugInfo *subsystem.DebugInfo) ([]byte, error) { // Set names first -- we'll need them for filling in the Parents array. objToName := map[*subsystem.Subsystem]string{} for _, entry := range list { @@ -41,11 +43,16 @@ func generateSubsystemsFile(name string, list []*subsystem.Subsystem, commit *vc // The serializer does not understand parent references and just prints all the // nested structures. // Therefore we call it separately for the fields it can understand. - parents := []string{} + parents := []parentInfo{} for _, p := range entry.Parents { - parents = append(parents, objToName[p]) + parents = append(parents, parentInfo{ + Name: objToName[p], + Comment: debugInfo.ParentChildComment[p][entry], + }) } - sort.Strings(parents) + slices.SortFunc(parents, func(a, b parentInfo) int { + return strings.Compare(a.Name, b.Name) + }) subsystem := &templateSubsystem{ VarName: varName, Name: serializer.WriteString(entry.Name), @@ -121,11 +128,16 @@ type templateSubsystem struct { PathRules string Lists string Maintainers string - Parents []string + Parents []parentInfo NoReminders bool NoIndirectCc bool } +type parentInfo struct { + Name string + Comment string +} + type templateVars struct { Name string Version int @@ -171,7 +183,14 @@ var {{range $i, $item := .List}} Maintainers: {{.Maintainers}}, {{- end}} {{- if .Parents}} - Parents: []*Subsystem{ {{range .Parents}} &{{.}}, {{end}} }, + Parents: []*Subsystem{ + {{- range .Parents}} + {{- if .Comment}} + // {{.Comment}} + {{- end}} + &{{.Name}}, + {{end -}} +}, {{- end}} PathRules: {{.PathRules}}, {{- if .NoReminders}} diff --git a/tools/syz-query-subsystems/query_subsystems.go b/tools/syz-query-subsystems/query_subsystems.go index 8f0fbae76..74da8ee8d 100644 --- a/tools/syz-query-subsystems/query_subsystems.go +++ b/tools/syz-query-subsystems/query_subsystems.go @@ -28,6 +28,7 @@ var ( flagName = flag.String("name", "", "the name under which the list should be saved") flagFilter = flag.String("filter", "", "comma-separated list of subsystems to keep") flagEmails = flag.Bool("emails", true, "save lists and maintainer fields") + flagDebug = flag.Bool("debug", false, "print the debugging information") ) var nameRe = regexp.MustCompile(`^[a-z]\w*$`) @@ -48,10 +49,11 @@ func main() { tool.Failf("the name is not acceptable") } // Query the subsystems. - list, err := linux.ListFromRepo(*flagKernelRepo) + list, debugInfo, err := linux.ListFromRepo(*flagKernelRepo) if err != nil { tool.Failf("failed to query subsystems: %v", err) } + printDebugInfo(debugInfo) list = postProcessList(list) // Save the list. folder := filepath.Join(*flagSyzkallerRepo, "pkg", "subsystem", "lists") @@ -62,7 +64,7 @@ func main() { if err != nil { tool.Failf("failed to fetch commit info: %v", err) } - code, err := generateSubsystemsFile(*flagName, list, commitInfo) + code, err := generateSubsystemsFile(*flagName, list, commitInfo, debugInfo) if err != nil { tool.Failf("failed to generate code: %s", err) } @@ -72,6 +74,19 @@ func main() { } } +func printDebugInfo(info *subsystem.DebugInfo) { + if !*flagDebug { + return + } + for item, list := range info.FileLists { + fmt.Printf("****\n") + fmt.Printf("Subsystem %q (%d paths)\n", item.Name, len(list)) + for _, path := range list { + fmt.Printf("%s\n", path) + } + } +} + func postProcessList(list []*subsystem.Subsystem) []*subsystem.Subsystem { if *flagFilter != "" { list = subsystem.FilterList(list, prepareFilter()) |
