Documentation
¶
Index ¶
- Variables
- func IsSourceFile(file string) bool
- type Command
- type Database
- type Definition
- type Entity
- type EntityInfo
- type EntityKind
- type FieldInfo
- type Index
- func (index *Index) Command(cmd string, args []string) (string, error)
- func (index *Index) DefinitionComment(contextFile, name string) (*EntityInfo, error)
- func (index *Index) DefinitionSource(contextFile, name string, includeLines bool) (*EntityInfo, error)
- func (index *Index) DirIndex(dir string) ([]string, []string, error)
- func (index *Index) FileIndex(file string) ([]Entity, error)
- func (index *Index) FindReferences(contextFile, name, srcPrefix string, contextLines, outputLimit int) ([]ReferenceInfo, int, error)
- func (index *Index) GetStructLayout(contextFile, name string, fieldOffset *uint) ([]FieldInfo, error)
- func (index *Index) ReadFile(file string) (string, error)
- type LineRange
- type RefKind
- type Reference
- type ReferenceInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var Commands = []Command{ {"dir-index", 1, func(index *Index, args []string) (string, error) { subdirs, files, err := index.DirIndex(args[0]) if err != nil { return "", err } b := new(strings.Builder) fmt.Fprintf(b, "directory %v subdirs:\n", args[0]) for _, subdir := range subdirs { fmt.Fprintf(b, " - %v\n", subdir) } fmt.Fprintf(b, "\ndirectory %v files:\n", args[0]) for _, file := range files { fmt.Fprintf(b, " - %v\n", file) } return b.String(), nil }}, {"read-file", 1, func(index *Index, args []string) (string, error) { return index.ReadFile(args[0]) }}, {"file-index", 1, func(index *Index, args []string) (string, error) { entities, err := index.FileIndex(args[0]) if err != nil { return "", err } b := new(strings.Builder) fmt.Fprintf(b, "file %v defines the following entities:\n\n", args[0]) for _, ent := range entities { fmt.Fprintf(b, "%v %v\n", ent.Kind, ent.Name) } return b.String(), nil }}, {"def-comment", 2, func(index *Index, args []string) (string, error) { info, err := index.DefinitionComment(args[0], args[1]) if err != nil { return "", err } if info.Body == "" { return fmt.Sprintf("%v %v is defined in %v and is not commented\n", info.Kind, args[1], info.File), nil } return fmt.Sprintf("%v %v is defined in %v and commented as:\n\n%v", info.Kind, args[1], info.File, info.Body), nil }}, {"def-source", 3, func(index *Index, args []string) (string, error) { info, err := index.DefinitionSource(args[0], args[1], args[2] == "yes") if err != nil { return "", err } return fmt.Sprintf("%v %v is defined in %v:\n\n%v", info.Kind, args[1], info.File, info.Body), nil }}, {"find-references", 5, func(index *Index, args []string) (string, error) { contextLines, err := strconv.Atoi(args[3]) if err != nil { return "", fmt.Errorf("failed to parse number of context lines %q: %w", args[3], err) } outputLimit, err := strconv.Atoi(args[4]) if err != nil { return "", fmt.Errorf("failed to parse output limit %q: %w", args[4], err) } refs, totalCount, err := index.FindReferences(args[0], args[1], args[2], contextLines, outputLimit) if err != nil { return "", err } b := new(strings.Builder) fmt.Fprintf(b, "%v has %v references:\n\n", args[1], totalCount) for _, ref := range refs { fmt.Fprintf(b, "%v %v %v it at %v:%v\n%v\n\n", ref.ReferencingEntityKind, ref.ReferencingEntityName, ref.ReferenceKind, ref.SourceFile, ref.SourceLine, ref.SourceSnippet) } return b.String(), nil }}, {"struct-layout", 0, func(index *Index, args []string) (string, error) { if len(args) != 2 && len(args) != 3 { return "", fmt.Errorf("codesearch command struct-layout requires 2 or 3 args, but %v provided", len(args)) } var fieldOffset *uint if len(args) == 3 { val, err := strconv.ParseUint(args[2], 10, 64) if err != nil { return "", fmt.Errorf("bad offset: %w", err) } fieldOffset = new(uint) *fieldOffset = uint(val) } fields, err := index.GetStructLayout(args[0], args[1], fieldOffset) if err != nil { return "", err } b := new(strings.Builder) fmt.Fprintf(b, "struct %v has %v fields:\n", args[1], len(fields)) for _, f := range fields { fmt.Fprintf(b, "[%v - %v] %v\n", f.OffsetBits, f.OffsetBits+f.SizeBits, f.Name) } return b.String(), nil }}, }
Commands are used to run unit tests and for the syz-codesearch tool.
View Source
var DatabaseFormatHash = func() string { // Semantic version should be bumped when the schema does not change, // but stored values changes. const semanticVersion = "4" schema, err := jsonschema.For[Database](nil) if err != nil { panic(err) } return hash.String(schema, semanticVersion) }()
DatabaseFormatHash contains a hash uniquely identifying format of the database. In covers both structure and semantics of the data, and is supposed to be used for caching of the database files.
Functions ¶
func IsSourceFile ¶
Types ¶
type Database ¶
type Database struct {
Definitions []*Definition `json:"definitions,omitempty"`
// contains filtered or unexported fields
}
type Definition ¶
type Definition struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Kind EntityKind `json:"kind,omitempty"`
IsStatic bool `json:"is_static,omitempty"`
Body LineRange `json:"body,omitempty"`
Comment LineRange `json:"comment,omitempty"`
Refs []Reference `json:"refs,omitempty"`
Fields []FieldInfo `json:"fields,omitempty"`
}
type EntityInfo ¶
type EntityKind ¶
type EntityKind uint8
const ( EntityKindFunction EntityKind EntityKindStruct EntityKindUnion EntityKindGlobalVariable EntityKindMacro EntityKindEnum EntityKindTypedef EntityKindField )
func (*EntityKind) MarshalJSON ¶
func (v *EntityKind) MarshalJSON() ([]byte, error)
func (*EntityKind) String ¶
func (v *EntityKind) String() string
func (*EntityKind) UnmarshalJSON ¶
func (v *EntityKind) UnmarshalJSON(data []byte) error
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func (*Index) DefinitionComment ¶
func (index *Index) DefinitionComment(contextFile, name string) (*EntityInfo, error)
func (*Index) DefinitionSource ¶
func (index *Index) DefinitionSource(contextFile, name string, includeLines bool) (*EntityInfo, error)
func (*Index) FindReferences ¶
func (*Index) GetStructLayout ¶
type RefKind ¶
type RefKind uint8
const ( RefKindUses RefKind RefKindCall RefKindRead RefKindWrite RefKindTakesAddr )
func (*RefKind) MarshalJSON ¶
func (*RefKind) UnmarshalJSON ¶
type Reference ¶
type Reference struct {
Name string `json:"name,omitempty"`
Kind RefKind `json:"kind,omitempty"`
EntityKind EntityKind `json:"entity_kind,omitempty"`
Line uint32 `json:"line,omitempty"`
}
type ReferenceInfo ¶
type ReferenceInfo struct {
ReferencingEntityKind string `jsonschema:"Kind of the referencing entity (function, struct, etc)."`
ReferencingEntityName string `jsonschema:"Name of the referencing entity."`
ReferenceKind string `jsonschema:"Kind of the reference (calls, takes-address, reads, writes-to, etc)."`
SourceFile string `jsonschema:"Source file of the reference."`
SourceLine int `jsonschema:"Source line of the reference."`
SourceSnippet string `jsonschema:"Surrounding code snippet, if requested." json:",omitempty"`
}
Click to show internal directories.
Click to hide internal directories.