Skip to content

Commit 9f95e37

Browse files
yonghong-songborkmann
authored andcommitted
tools: bpftool: refactor btf_dumper_int_bits()
The core dump funcitonality in btf_dumper_int_bits() is refactored into a separate function btf_dumper_bitfield() which will be used by the next patch. Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent d0ebce6 commit 9f95e37

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tools/bpf/bpftool/btf_dumper.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,17 @@ static int btf_dumper_array(const struct btf_dumper *d, __u32 type_id,
7373
return ret;
7474
}
7575

76-
static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
76+
static void btf_dumper_bitfield(__u32 nr_bits, __u8 bit_offset,
7777
const void *data, json_writer_t *jw,
7878
bool is_plain_text)
7979
{
8080
int left_shift_bits, right_shift_bits;
81-
int nr_bits = BTF_INT_BITS(int_type);
82-
int total_bits_offset;
8381
int bytes_to_copy;
8482
int bits_to_copy;
8583
__u64 print_num;
8684

87-
total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
88-
data += BITS_ROUNDDOWN_BYTES(total_bits_offset);
89-
bit_offset = BITS_PER_BYTE_MASKED(total_bits_offset);
85+
data += BITS_ROUNDDOWN_BYTES(bit_offset);
86+
bit_offset = BITS_PER_BYTE_MASKED(bit_offset);
9087
bits_to_copy = bit_offset + nr_bits;
9188
bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy);
9289

@@ -109,6 +106,22 @@ static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
109106
jsonw_printf(jw, "%llu", print_num);
110107
}
111108

109+
110+
static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
111+
const void *data, json_writer_t *jw,
112+
bool is_plain_text)
113+
{
114+
int nr_bits = BTF_INT_BITS(int_type);
115+
int total_bits_offset;
116+
117+
/* bits_offset is at most 7.
118+
* BTF_INT_OFFSET() cannot exceed 64 bits.
119+
*/
120+
total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
121+
btf_dumper_bitfield(nr_bits, total_bits_offset, data, jw,
122+
is_plain_text);
123+
}
124+
112125
static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset,
113126
const void *data, json_writer_t *jw,
114127
bool is_plain_text)

0 commit comments

Comments
 (0)