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 0c349b4
Showing 1 changed file with 1 addition and 1 deletion.
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

0 comments on commit 0c349b4

Please sign in to comment.