BTF (BPF Type Format) parsing and type introspection
BTF (BPF Type Format) parsing and type introspection
(btf-available?)Check if BTF is available on this system.
Returns true if /sys/kernel/btf/vmlinux exists and is readable.
Example: (btf-available?) => true
Check if BTF is available on this system. Returns true if /sys/kernel/btf/vmlinux exists and is readable. Example: (btf-available?) => true
Reverse map: kind number to keyword
Reverse map: kind number to keyword
(field-name->index btf type-id field-name)Get the member index for a field by name within a struct/union.
This is used to build CO-RE access strings for bpf_core_read operations.
Parameters:
Returns the 0-based member index, or nil if not found.
Example: (field-name->index btf struct-id "skc_daddr") (field-name->index btf struct-id :skc_daddr)
Get the member index for a field by name within a struct/union. This is used to build CO-RE access strings for bpf_core_read operations. Parameters: - btf: BTF data (from load-btf-file) - type-id: Type ID of the struct/union - field-name: Field name as string or keyword Returns the 0-based member index, or nil if not found. Example: (field-name->index btf struct-id "skc_daddr") (field-name->index btf struct-id :skc_daddr)
(field-path->access-info btf start-type-id field-path)Convert a field path to CO-RE access information.
Given a starting type and a path of field names (or keywords), returns information needed for CO-RE field access including the final offset and type.
Parameters:
Returns map with:
Returns nil if path cannot be resolved.
Example: (field-path->access-info btf sock-type-id [:__sk_common :skc_daddr]) => {:access-string "0:1" :indices [0 1] :final-type-id 123 :bit-offset 96 :byte-offset 12}
Convert a field path to CO-RE access information.
Given a starting type and a path of field names (or keywords), returns
information needed for CO-RE field access including the final offset
and type.
Parameters:
- btf: BTF data (from load-btf-file)
- start-type-id: Starting type ID (struct or pointer to struct)
- field-path: Vector of field names like [:__sk_common :skc_daddr]
Returns map with:
- :access-string - CO-RE access string like "0:1:3"
- :indices - Vector of member indices
- :final-type-id - Type ID of the final field
- :bit-offset - Total bit offset from start
- :byte-offset - Total byte offset from start (if byte-aligned)
Returns nil if path cannot be resolved.
Example:
(field-path->access-info btf sock-type-id [:__sk_common :skc_daddr])
=> {:access-string "0:1"
:indices [0 1]
:final-type-id 123
:bit-offset 96
:byte-offset 12}(field-path->access-string btf start-type-id field-path)Convert a field path to a CO-RE access string.
Simplified version of field-path->access-info that just returns the access string.
Parameters:
Returns access string like "0:1:3" or nil if path invalid.
Example: (field-path->access-string btf sock-id [:__sk_common :skc_daddr]) => "0:1"
Convert a field path to a CO-RE access string. Simplified version of field-path->access-info that just returns the access string. Parameters: - btf: BTF data (from load-btf-file) - start-type-id: Starting type ID - field-path: Vector of field names Returns access string like "0:1:3" or nil if path invalid. Example: (field-path->access-string btf sock-id [:__sk_common :skc_daddr]) => "0:1"
(find-function btf name)Find a function by name.
Parameters:
Returns function type information or nil.
Example: (find-function btf "sys_read")
Find a function by name. Parameters: - btf: BTF data (from load-btf-file) - name: Function name Returns function type information or nil. Example: (find-function btf "sys_read")
(find-type-by-name btf name)Find type by name.
Parameters:
Returns type information or nil if not found.
Example: (find-type-by-name btf "task_struct")
Find type by name. Parameters: - btf: BTF data (from load-btf-file) - name: Type name to search for Returns type information or nil if not found. Example: (find-type-by-name btf "task_struct")
(get-enum-values btf type-info)Get enum values with names.
Parameters:
Returns vector of enum values with :name added.
Example: (get-enum-values btf enum-type)
Get enum values with names. Parameters: - btf: BTF data (from load-btf-file) - type-info: Enum type information Returns vector of enum values with :name added. Example: (get-enum-values btf enum-type)
(get-field-offset btf start-type-id field-path)Get the byte offset of a field within a struct.
Convenience function for direct field access.
Parameters:
Returns byte offset or nil if not found/not byte-aligned.
Example: (get-field-offset btf sock-id [:__sk_common :skc_daddr]) => 12
Get the byte offset of a field within a struct. Convenience function for direct field access. Parameters: - btf: BTF data (from load-btf-file) - start-type-id: Starting type ID - field-path: Vector of field names Returns byte offset or nil if not found/not byte-aligned. Example: (get-field-offset btf sock-id [:__sk_common :skc_daddr]) => 12
(get-field-type btf start-type-id field-path)Get the type ID of a field.
Parameters:
Returns the field's type ID or nil if not found.
Example: (get-field-type btf sock-id [:__sk_common :skc_daddr]) => 42
Get the type ID of a field. Parameters: - btf: BTF data (from load-btf-file) - start-type-id: Starting type ID - field-path: Vector of field names Returns the field's type ID or nil if not found. Example: (get-field-type btf sock-id [:__sk_common :skc_daddr]) => 42
(get-func-params btf type-info)Get function parameters with names.
Parameters:
Returns vector of parameters with :name added.
Example: (get-func-params btf func-proto-type)
Get function parameters with names. Parameters: - btf: BTF data (from load-btf-file) - type-info: Function prototype type information Returns vector of parameters with :name added. Example: (get-func-params btf func-proto-type)
(get-function-signature btf func-type)Get function signature with return type and parameter names/types.
Parameters:
Returns map with :return-type, :params.
Example: (get-function-signature btf func-type)
Get function signature with return type and parameter names/types. Parameters: - btf: BTF data (from load-btf-file) - func-type: Function type information Returns map with :return-type, :params. Example: (get-function-signature btf func-type)
(get-struct-members btf type-info)Get struct or union members with names.
Parameters:
Returns vector of members with :name added.
Example: (get-struct-members btf struct-type)
Get struct or union members with names. Parameters: - btf: BTF data (from load-btf-file) - type-info: Struct/union type information Returns vector of members with :name added. Example: (get-struct-members btf struct-type)
(get-type-by-id btf type-id)Get type information by type ID.
Parameters:
Returns type information or nil if not found.
Example: (get-type-by-id btf 42)
Get type information by type ID. Parameters: - btf: BTF data (from load-btf-file) - type-id: Type ID to look up Returns type information or nil if not found. Example: (get-type-by-id btf 42)
(get-type-name btf type-info)Get the name of a type.
Parameters:
Returns the type name string or nil.
Example: (get-type-name btf type-info)
Get the name of a type. Parameters: - btf: BTF data (from load-btf-file) - type-info: Type information (from get-type-by-id) Returns the type name string or nil. Example: (get-type-name btf type-info)
(get-type-size btf type-id)Get the size of a type in bytes.
Parameters:
Returns size in bytes or nil if size is not defined.
Example: (get-type-size btf type-id)
Get the size of a type in bytes. Parameters: - btf: BTF data (from load-btf-file) - type-id: Type ID Returns size in bytes or nil if size is not defined. Example: (get-type-size btf type-id)
(list-types btf kind)List all types of a specific kind.
Parameters:
Returns vector of matching types.
Example: (list-types btf :struct) (list-types btf :func)
List all types of a specific kind. Parameters: - btf: BTF data (from load-btf-file) - kind: Type kind keyword (e.g., :struct, :func, :typedef) Returns vector of matching types. Example: (list-types btf :struct) (list-types btf :func)
(load-btf-file)(load-btf-file path)Load and parse a BTF file.
Parameters:
Returns a map with:
Example: (load-btf-file) (load-btf-file "/sys/kernel/btf/vmlinux")
Load and parse a BTF file. Parameters: - path: Path to BTF file (default: /sys/kernel/btf/vmlinux) Returns a map with: - :header - BTF header information - :strings - String section lookup map - :types - Vector of types indexed by type ID Example: (load-btf-file) (load-btf-file "/sys/kernel/btf/vmlinux")
(resolve-type btf type-id)Resolve a type through typedef/const/volatile/restrict indirections.
Parameters:
Returns the resolved type ID (may be the same if not an indirection).
Example: (resolve-type btf typedef-id)
Resolve a type through typedef/const/volatile/restrict indirections. Parameters: - btf: BTF data (from load-btf-file) - type-id: Type ID to resolve Returns the resolved type ID (may be the same if not an indirection). Example: (resolve-type btf typedef-id)
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |