Skip to content

Commit fa9df5c

Browse files
Expose AnyTypesByName from Spec Object (#14)
* expose AnyTypesByName * notice * Update spec.go Co-authored-by: Andrew Kroh <[email protected]> * Change spec_test.go names Co-authored-by: Andrew Kroh <[email protected]> * Change specTypes name Co-authored-by: Andrew Kroh <[email protected]> --------- Co-authored-by: Andrew Kroh <[email protected]>
1 parent de488bb commit fa9df5c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tk-btf
2-
Copyright 2023-2024 Elasticsearch BV
2+
Copyright 2023-2025 Elasticsearch BV
33

44
================================================================================
55
Third party libraries used by tk-btf:

spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ func (s *Spec) ContainsSymbol(symbolName string) bool {
198198
return s.spec.TypeByName(symbolName, &funcType) == nil
199199
}
200200

201+
// AnyTypesByName returns all [btf.Type] interfaces that match the given name.
202+
// It returns a slice since multiple distinct types can share the same name in BTF.
203+
// Each element of the slice can then be type-asserted to a more specific type,
204+
// such as a [*btf.Struct] or [*btf.Enum].
205+
func (s *Spec) AnyTypesByName(name string) ([]btf.Type, error) {
206+
return s.spec.AnyTypesByName(name)
207+
}
208+
201209
func (b *btfSpecWrapper) AnyTypesByName(name string) ([]btf.Type, error) {
202210
return b.spec.AnyTypesByName(name)
203211
}

spec_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,16 @@ func TestSpec_ContainsSymbol(t *testing.T) {
143143
require.False(t, mockSpec.ContainsSymbol("unknown"))
144144
require.True(t, mockSpec.ContainsSymbol("dentry"))
145145
}
146+
147+
func TestSpec_AnyTypesByName(t *testing.T) {
148+
mockSpec := &Spec{
149+
spec: newMockedBTFSpecWithTypesMap(map[string]btf.Type{
150+
"dentry": &btf.Func{},
151+
}),
152+
regs: nil,
153+
}
154+
155+
foundTypes, err := mockSpec.AnyTypesByName("dentry")
156+
require.NoError(t, err)
157+
require.Len(t, foundTypes, 1)
158+
}

0 commit comments

Comments
 (0)