-
Notifications
You must be signed in to change notification settings - Fork 741
Member sizes read from btf are always zero #1788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi 👋 |
pahole and bpftool are both working properly with btf:
|
Hi @jschwinger233 .
From the debugger screenshot, we can see that the The code needs to distinguish between bitfield members and regular members, then use the appropriate method to calculate the size: // ... existing code ...
iter := btfSpec.Iterate()
for iter.Next() {
if strct, ok := iter.Type.(*btf.Struct); ok && strct.Name == "__sk_buff" {
for _, member := range strct.Members {
offsetInBytes := member.Offset.Bytes()
// Check if this is a bitfield member
var sizeInBytes uint32
if member.BitfieldSize > 0 {
// For bitfield members, use BitfieldSize
sizeInBytes = member.BitfieldSize.Bytes()
} else {
// For regular members, calculate size from type
size, err := btf.Sizeof(member.Type)
if err != nil {
fmt.Printf("Failed to get size for member %s: %v\n", member.Name, err)
continue
}
sizeInBytes = uint32(size)
}
println("Member:", member.Name, "Offset:", offsetInBytes, "Size:", sizeInBytes)
}
}
}
// ... existing code ... |
Closed as resolved. Thank you @Ghostbaby 🙏 |
Describe the bug
I tried to read __sk_buff->gso_size's offset and size from BTF, found zero size as a result.
How to reproduce
The output is:
Version information
github.com/cilium/ebpf v0.18.0
The text was updated successfully, but these errors were encountered: