Lines Matching +full:msi +full:- +full:specifier

1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 * BTF-to-C type converter.
26 static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
30 return lvl >= PREFIX_CNT ? PREFIXES : &PREFIXES[PREFIX_CNT - lvl]; in pfx()
45 /* per-type auxiliary state */
53 /* whether unique non-duplicate name was already assigned */
88 /* per-type auxiliary state */
91 /* per-type optional cached unique name, must be freed, if present */
95 /* topo-sorted list of dependent type definitions */
133 return btf__name_by_offset(d->btf, name_off); in btf_name_of()
141 d->printf_fn(d->cb_ctx, fmt, args); in btf_dump_printf()
157 return libbpf_err_ptr(-EINVAL); in btf_dump__new()
160 return libbpf_err_ptr(-EINVAL); in btf_dump__new()
164 return libbpf_err_ptr(-ENOMEM); in btf_dump__new()
166 d->btf = btf; in btf_dump__new()
167 d->printf_fn = printf_fn; in btf_dump__new()
168 d->cb_ctx = ctx; in btf_dump__new()
169 d->ptr_sz = btf__pointer_size(btf) ? : sizeof(void *); in btf_dump__new()
171 d->type_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
172 if (IS_ERR(d->type_names)) { in btf_dump__new()
173 err = PTR_ERR(d->type_names); in btf_dump__new()
174 d->type_names = NULL; in btf_dump__new()
177 d->ident_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
178 if (IS_ERR(d->ident_names)) { in btf_dump__new()
179 err = PTR_ERR(d->ident_names); in btf_dump__new()
180 d->ident_names = NULL; in btf_dump__new()
196 int err, last_id = btf__type_cnt(d->btf) - 1; in btf_dump_resize()
198 if (last_id <= d->last_id) in btf_dump_resize()
201 if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap, in btf_dump_resize()
202 sizeof(*d->type_states), last_id + 1)) in btf_dump_resize()
203 return -ENOMEM; in btf_dump_resize()
204 if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap, in btf_dump_resize()
205 sizeof(*d->cached_names), last_id + 1)) in btf_dump_resize()
206 return -ENOMEM; in btf_dump_resize()
208 if (d->last_id == 0) { in btf_dump_resize()
210 d->type_states[0].order_state = ORDERED; in btf_dump_resize()
211 d->type_states[0].emit_state = EMITTED; in btf_dump_resize()
219 d->last_id = last_id; in btf_dump_resize()
229 free((void *)cur->pkey); in btf_dump_free_names()
241 free(d->type_states); in btf_dump__free()
242 if (d->cached_names) { in btf_dump__free()
244 for (i = 0; i <= d->last_id; i++) { in btf_dump__free()
245 if (d->cached_names[i]) in btf_dump__free()
246 free((void *)d->cached_names[i]); in btf_dump__free()
249 free(d->cached_names); in btf_dump__free()
250 free(d->emit_queue); in btf_dump__free()
251 free(d->decl_stack); in btf_dump__free()
252 btf_dump_free_names(d->type_names); in btf_dump__free()
253 btf_dump_free_names(d->ident_names); in btf_dump__free()
266 * filter out BTF types according to user-defined criterias and emitted only
271 * Dumping is done in two high-level passes:
281 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
282 return libbpf_err(-EINVAL); in btf_dump__dump_type()
288 d->emit_queue_cnt = 0; in btf_dump__dump_type()
293 for (i = 0; i < d->emit_queue_cnt; i++) in btf_dump__dump_type()
294 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/); in btf_dump__dump_type()
301 * determine top-level anonymous enums that need to be emitted as an
305 * type declaration; or as a top-level anonymous enum, typically used for
308 * top-level anonymous enum won't be referenced by anything, while embedded
313 int i, j, n = btf__type_cnt(d->btf); in btf_dump_mark_referenced()
317 for (i = d->last_id + 1; i < n; i++) { in btf_dump_mark_referenced()
318 t = btf__type_by_id(d->btf, i); in btf_dump_mark_referenced()
338 d->type_states[t->type].referenced = 1; in btf_dump_mark_referenced()
344 d->type_states[a->index_type].referenced = 1; in btf_dump_mark_referenced()
345 d->type_states[a->type].referenced = 1; in btf_dump_mark_referenced()
353 d->type_states[m->type].referenced = 1; in btf_dump_mark_referenced()
360 d->type_states[p->type].referenced = 1; in btf_dump_mark_referenced()
367 d->type_states[v->type].referenced = 1; in btf_dump_mark_referenced()
371 return -EINVAL; in btf_dump_mark_referenced()
382 if (d->emit_queue_cnt >= d->emit_queue_cap) { in btf_dump_add_emit_queue_id()
383 new_cap = max(16, d->emit_queue_cap * 3 / 2); in btf_dump_add_emit_queue_id()
384 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0])); in btf_dump_add_emit_queue_id()
386 return -ENOMEM; in btf_dump_add_emit_queue_id()
387 d->emit_queue = new_queue; in btf_dump_add_emit_queue_id()
388 d->emit_queue_cap = new_cap; in btf_dump_add_emit_queue_id()
391 d->emit_queue[d->emit_queue_cnt++] = id; in btf_dump_add_emit_queue_id()
418 * struct A {}; // if this was forward-declaration: compilation error
430 * between struct A and struct B. If struct A was forward-declared before
437 * - weak link (relationship) between X and Y, if Y *CAN* be
438 * forward-declared at the point of X definition;
439 * - strong link, if Y *HAS* to be fully-defined before X can be defined.
442 * BTF_KIND_PTR type in the chain and at least one non-anonymous type
457 * marked as ORDERED. We can mark PTR as ORDERED as well, as it semi-forces
463 * - 1, if type is part of strong link (so there is strong topological
465 * - 0, if type is part of weak link (so can be satisfied through forward
467 * - <0, on error (e.g., unsatisfiable type loop detected).
474 * stand-alone fwd decl, enum, typedef, struct, union). Ptrs, arrays, in btf_dump_order_type()
478 * So for all non-defining kinds, we never even set ordering state, in btf_dump_order_type()
482 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
488 if (tstate->order_state == ORDERED) in btf_dump_order_type()
491 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
493 if (tstate->order_state == ORDERING) { in btf_dump_order_type()
495 if (btf_is_composite(t) && through_ptr && t->name_off != 0) in btf_dump_order_type()
498 return -ELOOP; in btf_dump_order_type()
504 tstate->order_state = ORDERED; in btf_dump_order_type()
508 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
509 tstate->order_state = ORDERED; in btf_dump_order_type()
513 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
523 if (through_ptr && t->name_off != 0) in btf_dump_order_type()
526 tstate->order_state = ORDERING; in btf_dump_order_type()
530 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
535 if (t->name_off != 0) { in btf_dump_order_type()
541 tstate->order_state = ORDERED; in btf_dump_order_type()
548 * non-anonymous or non-referenced enums are top-level in btf_dump_order_type()
552 if (t->name_off != 0 || !tstate->referenced) { in btf_dump_order_type()
557 tstate->order_state = ORDERED; in btf_dump_order_type()
563 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
567 /* typedef is similar to struct/union w.r.t. fwd-decls */ in btf_dump_order_type()
576 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
583 return btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
589 err = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
596 err = btf_dump_order_type(d, p->type, through_ptr); in btf_dump_order_type()
608 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
612 return -EINVAL; in btf_dump_order_type()
654 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
656 /* __builtin_va_list is a compiler built-in, which causes compilation in btf_dump_is_blacklisted()
659 * C header from BTF). As it is built-in, it should be already defined in btf_dump_is_blacklisted()
662 if (t->name_off == 0) in btf_dump_is_blacklisted()
664 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
668 * Emit C-syntax definitions of types from chains of BTF types.
670 * High-level handling of determining necessary forward declarations are handled
671 * by btf_dump_emit_type() itself, but all nitty-gritty details of emitting type
687 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
692 if (tstate->emit_state == EMITTED) in btf_dump_emit_type()
695 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
698 if (tstate->emit_state == EMITTING) { in btf_dump_emit_type()
699 if (tstate->fwd_emitted) in btf_dump_emit_type()
707 * part of - then no need for fwd declaration in btf_dump_emit_type()
711 if (t->name_off == 0) { in btf_dump_emit_type()
718 tstate->fwd_emitted = 1; in btf_dump_emit_type()
730 tstate->fwd_emitted = 1; in btf_dump_emit_type()
744 tstate->emit_state = EMITTED; in btf_dump_emit_type()
752 tstate->emit_state = EMITTED; in btf_dump_emit_type()
759 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
762 btf_dump_emit_type(d, btf_array(t)->type, cont_id); in btf_dump_emit_type()
767 tstate->emit_state = EMITTED; in btf_dump_emit_type()
770 tstate->emit_state = EMITTING; in btf_dump_emit_type()
771 btf_dump_emit_type(d, t->type, id); in btf_dump_emit_type()
779 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
783 tstate->emit_state = EMITTED; in btf_dump_emit_type()
787 tstate->emit_state = EMITTING; in btf_dump_emit_type()
788 /* if it's a top-level struct/union definition or struct/union in btf_dump_emit_type()
792 * members have necessary forward-declarations, where in btf_dump_emit_type()
795 if (top_level_def || t->name_off == 0) { in btf_dump_emit_type()
800 new_cont_id = t->name_off == 0 ? cont_id : id; in btf_dump_emit_type()
802 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
803 } else if (!tstate->fwd_emitted && id != cont_id) { in btf_dump_emit_type()
806 tstate->fwd_emitted = 1; in btf_dump_emit_type()
812 tstate->emit_state = EMITTED; in btf_dump_emit_type()
814 tstate->emit_state = NOT_EMITTED; in btf_dump_emit_type()
822 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
824 btf_dump_emit_type(d, p->type, cont_id); in btf_dump_emit_type()
842 /* all non-bitfield fields have to be naturally aligned */ in btf_is_struct_packed()
844 align = btf__align_of(btf, m->type); in btf_is_struct_packed()
846 if (align && bit_sz == 0 && m->offset % (8 * align) != 0) in btf_is_struct_packed()
850 /* size of a non-packed struct has to be a multiple of its alignment */ in btf_is_struct_packed()
851 if (t->size % max_align != 0) in btf_is_struct_packed()
868 {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} in btf_dump_emit_bit_padding()
885 * that even if struct itself has, let's say 4-byte alignment in btf_dump_emit_bit_padding()
886 * (i.e., it only uses up to int-aligned types), using `long: in btf_dump_emit_bit_padding()
915 (new_off != next_off && next_off - new_off <= new_off - cur_off)) in btf_dump_emit_bit_padding()
918 in_bitfield ? new_off - cur_off : 0); in btf_dump_emit_bit_padding()
929 bits = min(next_off - cur_off, pad_bits); in btf_dump_emit_bit_padding()
941 for (i = ARRAY_SIZE(pads) - 1; i >= 0; i--) { in btf_dump_emit_bit_padding()
959 t->name_off ? " " : "", in btf_dump_emit_struct_fwd()
974 align = btf__align_of(d->btf, id); in btf_dump_emit_struct_def()
975 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
979 t->name_off ? " " : "", in btf_dump_emit_struct_def()
987 fname = btf_name_of(d, m->name_off); in btf_dump_emit_struct_def()
990 m_align = packed ? 1 : btf__align_of(d->btf, m->type); in btf_dump_emit_struct_def()
996 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
1003 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type)); in btf_dump_emit_struct_def()
1013 btf_dump_emit_bit_padding(d, off, t->size * 8, align, false, lvl + 1); in btf_dump_emit_struct_def()
1019 if (vlen || t->size) { in btf_dump_emit_struct_def()
1073 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum32_val()
1075 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum32_val()
1078 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val); in btf_dump_emit_enum32_val()
1081 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val); in btf_dump_emit_enum32_val()
1099 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum64_val()
1100 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum64_val()
1124 t->name_off ? " " : "", in btf_dump_emit_enum_def()
1138 if (t->size == 1) { in btf_dump_emit_enum_def()
1139 /* one-byte enums can be forced with mode(byte) attribute */ in btf_dump_emit_enum_def()
1141 } else if (t->size == 8 && d->ptr_sz == 8) { in btf_dump_emit_enum_def()
1142 /* enum can be 8-byte sized if one of the enumerator values in btf_dump_emit_enum_def()
1143 * doesn't fit in 32-bit integer, or by adding mode(word) in btf_dump_emit_enum_def()
1144 * attribute (but probably only on 64-bit architectures); do in btf_dump_emit_enum_def()
1151 /* enum can't represent 64-bit values, so we need word mode */ in btf_dump_emit_enum_def()
1155 * non-zero upper 32-bits (which means that all values in btf_dump_emit_enum_def()
1156 * fit in 32-bit integers and won't cause compiler to in btf_dump_emit_enum_def()
1157 * bump enum to be 64-bit naturally in btf_dump_emit_enum_def()
1197 if (t->type == 0 && strcmp(name, "__gnuc_va_list") == 0) { in btf_dump_emit_typedef_def()
1203 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1211 if (d->decl_stack_cnt >= d->decl_stack_cap) { in btf_dump_push_decl_stack_id()
1212 new_cap = max(16, d->decl_stack_cap * 3 / 2); in btf_dump_push_decl_stack_id()
1213 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0])); in btf_dump_push_decl_stack_id()
1215 return -ENOMEM; in btf_dump_push_decl_stack_id()
1216 d->decl_stack = new_stack; in btf_dump_push_decl_stack_id()
1217 d->decl_stack_cap = new_cap; in btf_dump_push_decl_stack_id()
1220 d->decl_stack[d->decl_stack_cnt++] = id; in btf_dump_push_decl_stack_id()
1231 * - function prototypes (especially nesting of function prototypes);
1232 * - arrays;
1233 * - const/volatile/restrict for pointers vs other types.
1247 * [typedef] -> [array] -> [ptr] -> [const] -> [ptr] -> [const] -> [int]
1273 return libbpf_err(-EINVAL); in btf_dump__emit_type_decl()
1281 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1283 d->strip_mods = false; in btf_dump__emit_type_decl()
1294 stack_start = d->decl_stack_cnt; in btf_dump_emit_type_decl()
1296 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_decl()
1297 if (d->strip_mods && btf_is_mod(t)) in btf_dump_emit_type_decl()
1308 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1323 id = t->type; in btf_dump_emit_type_decl()
1326 id = btf_array(t)->type; in btf_dump_emit_type_decl()
1348 * emitting of declarations. Those stack frames are non-overlapping in btf_dump_emit_type_decl()
1349 * portions of shared btf_dump->decl_stack. To make it a bit nicer to in btf_dump_emit_type_decl()
1354 decl_stack.ids = d->decl_stack + stack_start; in btf_dump_emit_type_decl()
1355 decl_stack.cnt = d->decl_stack_cnt - stack_start; in btf_dump_emit_type_decl()
1359 * frame before returning. But it works with a read-only view into in btf_dump_emit_type_decl()
1361 * perspective of shared btf_dump->decl_stack, per se. We need to in btf_dump_emit_type_decl()
1365 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1373 while (decl_stack->cnt) { in btf_dump_emit_mods()
1374 id = decl_stack->ids[decl_stack->cnt - 1]; in btf_dump_emit_mods()
1375 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1390 decl_stack->cnt--; in btf_dump_emit_mods()
1399 while (decl_stack->cnt) { in btf_dump_drop_mods()
1400 id = decl_stack->ids[decl_stack->cnt - 1]; in btf_dump_drop_mods()
1401 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1404 decl_stack->cnt--; in btf_dump_drop_mods()
1424 * for cases where we have single pointer in a chain. E.g., in ptr -> in btf_dump_emit_type_chain()
1435 while (decls->cnt) { in btf_dump_emit_type_chain()
1436 id = decls->ids[--decls->cnt]; in btf_dump_emit_type_chain()
1445 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1452 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1459 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1468 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1495 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1515 if (decls->cnt == 0) { in btf_dump_emit_type_chain()
1517 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1521 next_id = decls->ids[decls->cnt - 1]; in btf_dump_emit_type_chain()
1522 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1524 /* we need space if we have named non-pointer */ in btf_dump_emit_type_chain()
1527 /* no parentheses for multi-dimensional array */ in btf_dump_emit_type_chain()
1533 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1550 if (decls->cnt) { in btf_dump_emit_type_chain()
1564 if (vlen == 1 && p->type == 0) { in btf_dump_emit_type_chain()
1574 if (i == vlen - 1 && p->type == 0) { in btf_dump_emit_type_chain()
1579 name = btf_name_of(d, p->name_off); in btf_dump_emit_type_chain()
1580 btf_dump_emit_type_decl(d, p->type, name, lvl); in btf_dump_emit_type_chain()
1608 if (d->typed_dump->is_array_member) in btf_dump_emit_type_cast()
1614 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_cast()
1621 d->skip_anon_defs = true; in btf_dump_emit_type_cast()
1622 d->strip_mods = true; in btf_dump_emit_type_cast()
1624 d->strip_mods = false; in btf_dump_emit_type_cast()
1625 d->skip_anon_defs = false; in btf_dump_emit_type_cast()
1658 struct btf_dump_type_aux_state *s = &d->type_states[id]; in btf_dump_resolve_name()
1659 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_resolve_name()
1660 const char *orig_name = btf_name_of(d, t->name_off); in btf_dump_resolve_name()
1661 const char **cached_name = &d->cached_names[id]; in btf_dump_resolve_name()
1664 if (t->name_off == 0) in btf_dump_resolve_name()
1667 if (s->name_resolved) in btf_dump_resolve_name()
1671 s->name_resolved = 1; in btf_dump_resolve_name()
1684 s->name_resolved = 1; in btf_dump_resolve_name()
1690 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1695 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1708 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1713 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1718 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth; in btf_dump_data_pfx()
1720 if (d->typed_dump->compact) in btf_dump_data_pfx()
1724 btf_dump_printf(d, "%s", d->typed_dump->indent_str); in btf_dump_data_pfx()
1728 * to the format specifier passed in; these do the work of appending
1730 * in the format specifier + value(s).
1743 return -ENOTSUP; in btf_dump_unsupported_data()
1760 if (t->size > 8) { in btf_dump_get_bitfield_value()
1761 pr_warn("unexpected bitfield size %d\n", t->size); in btf_dump_get_bitfield_value()
1762 return -EINVAL; in btf_dump_get_bitfield_value()
1769 for (i = t->size - 1; i >= 0; i--) in btf_dump_get_bitfield_value()
1773 for (i = 0; i < t->size; i++) in btf_dump_get_bitfield_value()
1775 nr_copy_bits = t->size * 8 - bits_offset; in btf_dump_get_bitfield_value()
1779 left_shift_bits = 64 - nr_copy_bits; in btf_dump_get_bitfield_value()
1780 right_shift_bits = 64 - bit_sz; in btf_dump_get_bitfield_value()
1800 return -ENODATA; in btf_dump_bitfield_check_zero()
1831 /* For pointer types, pointer size is not defined on a per-type basis. in btf_dump_base_type_check_zero()
1835 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1837 nr_bytes = t->size; in btf_dump_base_type_check_zero()
1841 return -EINVAL; in btf_dump_base_type_check_zero()
1845 return -ENODATA; in btf_dump_base_type_check_zero()
1869 int sz = t->size; in btf_dump_int_data()
1873 return -EINVAL; in btf_dump_int_data()
1876 /* handle packed int data - accesses of integers not aligned on in btf_dump_int_data()
1879 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1887 __u64 lsi, msi; in btf_dump_int_data() local
1889 /* avoid use of __int128 as some 32-bit platforms do not in btf_dump_int_data()
1894 msi = ints[1]; in btf_dump_int_data()
1897 msi = ints[0]; in btf_dump_int_data()
1901 if (msi == 0) in btf_dump_int_data()
1904 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1927 if (d->typed_dump->is_array_char) { in btf_dump_int_data()
1929 if (d->typed_dump->is_array_terminated) in btf_dump_int_data()
1932 d->typed_dump->is_array_terminated = true; in btf_dump_int_data()
1947 return -EINVAL; in btf_dump_int_data()
1965 int sz = t->size; in btf_dump_float_data()
1968 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_float_data()
1975 btf_dump_type_values(d, "%Lf", flp->ld); in btf_dump_float_data()
1978 btf_dump_type_values(d, "%lf", flp->d); in btf_dump_float_data()
1981 btf_dump_type_values(d, "%f", flp->f); in btf_dump_float_data()
1985 return -EINVAL; in btf_dump_float_data()
1995 enum btf_func_linkage linkage = btf_var(v)->linkage; in btf_dump_var_data()
2017 type_id = v->type; in btf_dump_var_data()
2018 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
2020 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
2035 elem_type_id = array->type; in btf_dump_array_data()
2036 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_array_data()
2037 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_array_data()
2041 return -EINVAL; in btf_dump_array_data()
2051 d->typed_dump->is_array_char = true; in btf_dump_array_data()
2061 d->typed_dump->depth++; in btf_dump_array_data()
2067 is_array_member = d->typed_dump->is_array_member; in btf_dump_array_data()
2068 d->typed_dump->is_array_member = true; in btf_dump_array_data()
2069 for (i = 0; i < array->nelems; i++, data += elem_size) { in btf_dump_array_data()
2070 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
2074 d->typed_dump->is_array_member = is_array_member; in btf_dump_array_data()
2075 d->typed_dump->depth--; in btf_dump_array_data()
2098 d->typed_dump->depth++; in btf_dump_struct_data()
2107 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_struct_data()
2108 mname = btf_name_of(d, m->name_off); in btf_dump_struct_data()
2112 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8, in btf_dump_struct_data()
2117 d->typed_dump->depth--; in btf_dump_struct_data()
2133 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
2138 memcpy(&pt, data, d->ptr_sz); in btf_dump_ptr_data()
2139 if (d->ptr_sz == 4) in btf_dump_ptr_data()
2155 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
2166 switch (t->size) { in btf_dump_get_enum_value()
2180 pr_warn("unexpected size %d for enum, id:[%u]\n", t->size, id); in btf_dump_get_enum_value()
2181 return -EINVAL; in btf_dump_get_enum_value()
2203 if (value != e->val) in btf_dump_enum_data()
2205 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2216 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2236 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off)); in btf_dump_datasec_data()
2239 var = btf__type_by_id(d->btf, vsi->type); in btf_dump_datasec_data()
2240 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0); in btf_dump_datasec_data()
2248 /* return size of type, or if base type overflows, return -E2BIG. */
2268 return data + nr_bytes > d->typed_dump->data_end ? -E2BIG : nr_bytes; in btf_dump_type_data_check_overflow()
2271 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2276 return -EINVAL; in btf_dump_type_data_check_overflow()
2286 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_overflow()
2290 return -EINVAL; in btf_dump_type_data_check_overflow()
2299 if (data + bits_offset / 8 + size > d->typed_dump->data_end) in btf_dump_type_data_check_overflow()
2300 return -E2BIG; in btf_dump_type_data_check_overflow()
2319 * - we ask for them (emit_zeros) in btf_dump_type_data_check_zero()
2320 * - if we are at top-level so we see "struct empty { }" in btf_dump_type_data_check_zero()
2321 * - or if we are an array member and the array is non-empty and in btf_dump_type_data_check_zero()
2323 * have an integer array 0, 1, 0, 1 and only show non-zero values. in btf_dump_type_data_check_zero()
2325 * with a '\0', the array-level check_zero() will prevent showing it; in btf_dump_type_data_check_zero()
2329 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 || in btf_dump_type_data_check_zero()
2330 (d->typed_dump->is_array_member && in btf_dump_type_data_check_zero()
2331 !d->typed_dump->is_array_char)) in btf_dump_type_data_check_zero()
2334 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_zero()
2350 elem_type_id = array->type; in btf_dump_type_data_check_zero()
2351 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_type_data_check_zero()
2352 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_type_data_check_zero()
2360 * non-zero because the string is terminated. in btf_dump_type_data_check_zero()
2362 for (i = 0; i < array->nelems; i++) { in btf_dump_type_data_check_zero()
2364 return -ENODATA; in btf_dump_type_data_check_zero()
2370 if (err != -ENODATA) in btf_dump_type_data_check_zero()
2373 return -ENODATA; in btf_dump_type_data_check_zero()
2380 /* if any struct/union member is non-zero, the struct/union in btf_dump_type_data_check_zero()
2381 * is considered non-zero and dumped. in btf_dump_type_data_check_zero()
2387 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_type_data_check_zero()
2395 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8, in btf_dump_type_data_check_zero()
2400 return -ENODATA; in btf_dump_type_data_check_zero()
2408 return -ENODATA; in btf_dump_type_data_check_zero()
2434 if (err == -ENODATA) in btf_dump_dump_type_data()
2440 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2446 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2499 BTF_INFO_KIND(t->info), id); in btf_dump_dump_type_data()
2500 return -EINVAL; in btf_dump_dump_type_data()
2516 return libbpf_err(-EINVAL); in btf_dump__dump_type_data()
2518 t = btf__type_by_id(d->btf, id); in btf_dump__dump_type_data()
2520 return libbpf_err(-ENOENT); in btf_dump__dump_type_data()
2522 d->typed_dump = &typed_dump; in btf_dump__dump_type_data()
2523 d->typed_dump->data_end = data + data_sz; in btf_dump__dump_type_data()
2524 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); in btf_dump__dump_type_data()
2528 d->typed_dump->indent_str[0] = '\t'; in btf_dump__dump_type_data()
2530 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str, in btf_dump__dump_type_data()
2531 sizeof(d->typed_dump->indent_str)); in btf_dump__dump_type_data()
2533 d->typed_dump->compact = OPTS_GET(opts, compact, false); in btf_dump__dump_type_data()
2534 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false); in btf_dump__dump_type_data()
2535 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false); in btf_dump__dump_type_data()
2539 d->typed_dump = NULL; in btf_dump__dump_type_data()