Documentation
¶
Overview ¶
Package btf handles data encoded according to the BPF Type Format.
The canonical documentation lives in the Linux kernel repository and is available at https://www.kernel.org/doc/html/latest/bpf/btf.html
The API is very much unstable. You should only use this via the main ebpf library.
Index ¶
- Variables
- func ProgramAppend(s, other *Program) error
- func ProgramFuncInfos(s *Program) (recordSize uint32, bytes []byte, err error)
- func ProgramLineInfos(s *Program) (recordSize uint32, bytes []byte, err error)
- func Sizeof(typ Type) (int, error)
- type Array
- type Const
- type Datasec
- type Enum
- type EnumValue
- type Func
- type FuncParam
- type FuncProto
- type Fwd
- type Handle
- type Int
- type IntEncoding
- type Map
- type Member
- type Name
- type Pointer
- type Program
- type Restrict
- type Spec
- type Struct
- type Type
- type TypeID
- type Typedef
- type Union
- type Var
- type VarSecinfo
- type Void
- type Volatile
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotSupported = internal.ErrNotSupported ErrNotFound = errors.New("not found") ErrNoExtendedInfo = errors.New("no extended info") )
Errors returned by BTF functions.
Functions ¶
func ProgramAppend ¶
ProgramAppend the information from other to the Program.
This is a free function instead of a method to hide it from users of package ebpf.
func ProgramFuncInfos ¶
ProgramFuncInfos returns the binary form of BTF function infos.
This is a free function instead of a method to hide it from users of package ebpf.
func ProgramLineInfos ¶
ProgramLineInfos returns the binary form of BTF line infos.
This is a free function instead of a method to hide it from users of package ebpf.
Types ¶
type Datasec ¶
type Datasec struct {
TypeID
Name
Size uint32
Vars []VarSecinfo
}
Datasec is a global program section containing data.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is a reference to BTF loaded into the kernel.
func NewHandle ¶
NewHandle loads BTF into the kernel.
Returns ErrNotSupported if BTF is not supported.
type Int ¶
type Int struct {
TypeID
Name
// The size of the integer in bytes.
Size uint32
Encoding IntEncoding
// Offset is the starting bit offset. Currently always 0.
// See https://www.kernel.org/doc/html/latest/bpf/btf.html#btf-kind-int
Offset uint32
Bits byte
}
Int is an integer of a given length.
type Member ¶
type Member struct {
Name
Type Type
// Offset is the bit offset of this member
Offset uint32
BitfieldSize uint32
}
Member is part of a Struct or Union.
It is not a valid Type.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is the BTF information for a stream of instructions.
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec represents decoded BTF.
func LoadKernelSpec ¶
LoadKernelSpec returns the current kernel's BTF information.
Requires a >= 5.5 kernel with CONFIG_DEBUG_INFO_BTF enabled. Returns ErrNotSupported if BTF is not enabled.
func LoadSpecFromReader ¶
LoadSpecFromReader reads BTF sections from an ELF.
Returns a nil Spec and no error if no BTF was present.
func MapSpec ¶
MapSpec should be a method on Map, but is a free function to hide it from users of the ebpf package.
func ProgramSpec ¶
ProgramSpec returns the Spec needed for loading function and line infos into the kernel.
This is a free function instead of a method to hide it from users of package ebpf.
func (*Spec) Datasec ¶
Datasec returns the BTF required to create maps which represent data sections.
func (*Spec) FindType ¶
FindType searches for a type with a specific name.
hint determines the type of the returned Type.
Returns an error wrapping ErrNotFound if no matching type exists in spec.
Example ¶
// Acquire a Spec via one of its constructors.
spec := new(Spec)
// Declare a variable of the desired type
var foo Struct
if err := spec.FindType("foo", &foo); err != nil {
// There is no struct with name foo, or there
// are multiple possibilities.
}
// We've found struct foo
fmt.Println(foo.Name)
type Struct ¶
type Struct struct {
TypeID
Name
// The size of the struct including padding, in bytes
Size uint32
Members []Member
}
Struct is a compound type of consecutive members.
type Type ¶
type Type interface {
ID() TypeID
// contains filtered or unexported methods
}
Type represents a type described by BTF.
Example (ValidTypes) ¶
The following are valid Types.
There currently is no better way to document which types implement an interface.
var t Type
t = &Void{}
t = &Int{}
t = &Pointer{}
t = &Array{}
t = &Struct{}
t = &Union{}
t = &Enum{}
t = &Fwd{}
t = &Typedef{}
t = &Volatile{}
t = &Const{}
t = &Restrict{}
t = &Func{}
t = &FuncProto{}
t = &Var{}
t = &Datasec{}
_ = t
type Union ¶
type Union struct {
TypeID
Name
// The size of the union including padding, in bytes.
Size uint32
Members []Member
}
Union is a compound type where members occupy the same memory.
type VarSecinfo ¶
VarSecinfo describes variable in a Datasec