findTargetInModule attempts to find a named type in any loaded module. base must contain the kernel's types and is used to parse kmod BTF. Modules are searched in the order they were loaded. Returns btf.ErrNotFound if the target can't be found in any module.
(typeName string, target *btf.Type, cache *btf.Cache)
| 1277 | // |
| 1278 | // Returns btf.ErrNotFound if the target can't be found in any module. |
| 1279 | func findTargetInModule(typeName string, target *btf.Type, cache *btf.Cache) (*btf.Spec, *btf.Handle, error) { |
| 1280 | it := new(btf.HandleIterator) |
| 1281 | defer it.Handle.Close() |
| 1282 | |
| 1283 | for it.Next() { |
| 1284 | info, err := it.Handle.Info() |
| 1285 | if err != nil { |
| 1286 | return nil, nil, fmt.Errorf("get info for BTF ID %d: %w", it.ID, err) |
| 1287 | } |
| 1288 | |
| 1289 | if !info.IsModule() { |
| 1290 | continue |
| 1291 | } |
| 1292 | |
| 1293 | spec, err := cache.Module(info.Name) |
| 1294 | if err != nil { |
| 1295 | return nil, nil, fmt.Errorf("parse types for module %s: %w", info.Name, err) |
| 1296 | } |
| 1297 | |
| 1298 | err = spec.TypeByName(typeName, target) |
| 1299 | if errors.Is(err, btf.ErrNotFound) { |
| 1300 | continue |
| 1301 | } |
| 1302 | if err != nil { |
| 1303 | return nil, nil, fmt.Errorf("lookup type in module %s: %w", info.Name, err) |
| 1304 | } |
| 1305 | |
| 1306 | return spec, it.Take(), nil |
| 1307 | } |
| 1308 | if err := it.Err(); err != nil { |
| 1309 | return nil, nil, fmt.Errorf("iterate modules: %w", err) |
| 1310 | } |
| 1311 | |
| 1312 | return nil, nil, btf.ErrNotFound |
| 1313 | } |
| 1314 | |
| 1315 | // find an attach target type in a program. |
| 1316 | // |
no test coverage detected
searching dependent graphs…