Skip to content

Commit

Permalink
btf: correct printing size of Int type in bytes
Browse files Browse the repository at this point in the history
It seems OK that the printing size of Int type in bits.

But while printing a struct, like 'struct sk_buff', it seems strange
that the printing size units of Int type and Struct/Union type are
different:

  : offset=1088
  : Union[fields=2]
    size: 4
    csum: offset=0
    csum: Typedef:"__wsum"[Typedef:"__u32"]
      __wsum: Typedef:"__u32"[Int:"unsigned int"]
        __u32: Int:"unsigned int"[unsigned size=32]
    : offset=0
    : Struct[fields=2]
  priority: offset=1120
  priority: Typedef:"__u32"[Int:"unsigned int"]
    __u32: Int:"unsigned int"[unsigned size=32]

So, it's better to make the printing size of Int type in bytes same as
Struct/Union type.

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
  • Loading branch information
Asphaltt committed Oct 22, 2023
1 parent 7d2810c commit bc41df4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion btf/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Int struct {
}

func (i *Int) Format(fs fmt.State, verb rune) {
formatType(fs, verb, i, i.Encoding, "size=", i.Size*8)
formatType(fs, verb, i, i.Encoding, "size=", i.Size)
}

func (i *Int) TypeName() string { return i.Name }
Expand Down
2 changes: 1 addition & 1 deletion btf/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,5 @@ func ExampleCopy_stripQualifiers() {
b := Copy(a, UnderlyingType)
// b has Volatile and Typedef removed.
fmt.Printf("%3v\n", b)
// Output: Pointer[target=Int[unsigned size=16]]
// Output: Pointer[target=Int[unsigned size=2]]
}

0 comments on commit bc41df4

Please sign in to comment.