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

1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 * BTF-to-C type converter.
27 static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
31 return lvl >= PREFIX_CNT ? PREFIXES : &PREFIXES[PREFIX_CNT - lvl]; in pfx()
46 /* per-type auxiliary state */
54 /* whether unique non-duplicate name was already assigned */
89 /* per-type auxiliary state */
92 /* per-type optional cached unique name, must be freed, if present */
96 /* topo-sorted list of dependent type definitions */
134 return btf__name_by_offset(d->btf, name_off); in btf_name_of()
142 d->printf_fn(d->cb_ctx, fmt, args); in btf_dump_printf()
158 return libbpf_err_ptr(-EINVAL); in btf_dump__new()
161 return libbpf_err_ptr(-EINVAL); in btf_dump__new()
165 return libbpf_err_ptr(-ENOMEM); in btf_dump__new()
167 d->btf = btf; in btf_dump__new()
168 d->printf_fn = printf_fn; in btf_dump__new()
169 d->cb_ctx = ctx; in btf_dump__new()
170 d->ptr_sz = btf__pointer_size(btf) ? : sizeof(void *); in btf_dump__new()
172 d->type_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
173 if (IS_ERR(d->type_names)) { in btf_dump__new()
174 err = PTR_ERR(d->type_names); in btf_dump__new()
175 d->type_names = NULL; in btf_dump__new()
178 d->ident_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
179 if (IS_ERR(d->ident_names)) { in btf_dump__new()
180 err = PTR_ERR(d->ident_names); in btf_dump__new()
181 d->ident_names = NULL; in btf_dump__new()
197 int err, last_id = btf__type_cnt(d->btf) - 1; in btf_dump_resize()
199 if (last_id <= d->last_id) in btf_dump_resize()
202 if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap, in btf_dump_resize()
203 sizeof(*d->type_states), last_id + 1)) in btf_dump_resize()
204 return -ENOMEM; in btf_dump_resize()
205 if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap, in btf_dump_resize()
206 sizeof(*d->cached_names), last_id + 1)) in btf_dump_resize()
207 return -ENOMEM; in btf_dump_resize()
209 if (d->last_id == 0) { in btf_dump_resize()
211 d->type_states[0].order_state = ORDERED; in btf_dump_resize()
212 d->type_states[0].emit_state = EMITTED; in btf_dump_resize()
220 d->last_id = last_id; in btf_dump_resize()
230 free((void *)cur->pkey); in btf_dump_free_names()
242 free(d->type_states); in btf_dump__free()
243 if (d->cached_names) { in btf_dump__free()
245 for (i = 0; i <= d->last_id; i++) { in btf_dump__free()
246 if (d->cached_names[i]) in btf_dump__free()
247 free((void *)d->cached_names[i]); in btf_dump__free()
250 free(d->cached_names); in btf_dump__free()
251 free(d->emit_queue); in btf_dump__free()
252 free(d->decl_stack); in btf_dump__free()
253 btf_dump_free_names(d->type_names); in btf_dump__free()
254 btf_dump_free_names(d->ident_names); in btf_dump__free()
267 * filter out BTF types according to user-defined criterias and emitted only
272 * Dumping is done in two high-level passes:
282 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
283 return libbpf_err(-EINVAL); in btf_dump__dump_type()
289 d->emit_queue_cnt = 0; in btf_dump__dump_type()
294 for (i = 0; i < d->emit_queue_cnt; i++) in btf_dump__dump_type()
295 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/); in btf_dump__dump_type()
302 * determine top-level anonymous enums that need to be emitted as an
306 * type declaration; or as a top-level anonymous enum, typically used for
309 * top-level anonymous enum won't be referenced by anything, while embedded
314 int i, j, n = btf__type_cnt(d->btf); in btf_dump_mark_referenced()
318 for (i = d->last_id + 1; i < n; i++) { in btf_dump_mark_referenced()
319 t = btf__type_by_id(d->btf, i); in btf_dump_mark_referenced()
339 d->type_states[t->type].referenced = 1; in btf_dump_mark_referenced()
345 d->type_states[a->index_type].referenced = 1; in btf_dump_mark_referenced()
346 d->type_states[a->type].referenced = 1; in btf_dump_mark_referenced()
354 d->type_states[m->type].referenced = 1; in btf_dump_mark_referenced()
361 d->type_states[p->type].referenced = 1; in btf_dump_mark_referenced()
368 d->type_states[v->type].referenced = 1; in btf_dump_mark_referenced()
372 return -EINVAL; in btf_dump_mark_referenced()
383 if (d->emit_queue_cnt >= d->emit_queue_cap) { in btf_dump_add_emit_queue_id()
384 new_cap = max(16, d->emit_queue_cap * 3 / 2); in btf_dump_add_emit_queue_id()
385 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0])); in btf_dump_add_emit_queue_id()
387 return -ENOMEM; in btf_dump_add_emit_queue_id()
388 d->emit_queue = new_queue; in btf_dump_add_emit_queue_id()
389 d->emit_queue_cap = new_cap; in btf_dump_add_emit_queue_id()
392 d->emit_queue[d->emit_queue_cnt++] = id; in btf_dump_add_emit_queue_id()
419 * struct A {}; // if this was forward-declaration: compilation error
431 * between struct A and struct B. If struct A was forward-declared before
438 * - weak link (relationship) between X and Y, if Y *CAN* be
439 * forward-declared at the point of X definition;
440 * - strong link, if Y *HAS* to be fully-defined before X can be defined.
443 * BTF_KIND_PTR type in the chain and at least one non-anonymous type
458 * marked as ORDERED. We can mark PTR as ORDERED as well, as it semi-forces
464 * - 1, if type is part of strong link (so there is strong topological
466 * - 0, if type is part of weak link (so can be satisfied through forward
468 * - <0, on error (e.g., unsatisfiable type loop detected).
475 * stand-alone fwd decl, enum, typedef, struct, union). Ptrs, arrays, in btf_dump_order_type()
479 * So for all non-defining kinds, we never even set ordering state, in btf_dump_order_type()
483 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
489 if (tstate->order_state == ORDERED) in btf_dump_order_type()
492 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
494 if (tstate->order_state == ORDERING) { in btf_dump_order_type()
496 if (btf_is_composite(t) && through_ptr && t->name_off != 0) in btf_dump_order_type()
499 return -ELOOP; in btf_dump_order_type()
505 tstate->order_state = ORDERED; in btf_dump_order_type()
509 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
510 tstate->order_state = ORDERED; in btf_dump_order_type()
514 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
524 if (through_ptr && t->name_off != 0) in btf_dump_order_type()
527 tstate->order_state = ORDERING; in btf_dump_order_type()
531 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
536 if (t->name_off != 0) { in btf_dump_order_type()
542 tstate->order_state = ORDERED; in btf_dump_order_type()
549 * non-anonymous or non-referenced enums are top-level in btf_dump_order_type()
553 if (t->name_off != 0 || !tstate->referenced) { in btf_dump_order_type()
558 tstate->order_state = ORDERED; in btf_dump_order_type()
564 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
568 /* typedef is similar to struct/union w.r.t. fwd-decls */ in btf_dump_order_type()
577 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
584 return btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
590 err = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
597 err = btf_dump_order_type(d, p->type, through_ptr); in btf_dump_order_type()
609 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
613 return -EINVAL; in btf_dump_order_type()
655 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
657 /* __builtin_va_list is a compiler built-in, which causes compilation in btf_dump_is_blacklisted()
660 * C header from BTF). As it is built-in, it should be already defined in btf_dump_is_blacklisted()
663 if (t->name_off == 0) in btf_dump_is_blacklisted()
665 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
669 * Emit C-syntax definitions of types from chains of BTF types.
671 * High-level handling of determining necessary forward declarations are handled
672 * by btf_dump_emit_type() itself, but all nitty-gritty details of emitting type
688 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
693 if (tstate->emit_state == EMITTED) in btf_dump_emit_type()
696 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
699 if (tstate->emit_state == EMITTING) { in btf_dump_emit_type()
700 if (tstate->fwd_emitted) in btf_dump_emit_type()
708 * part of - then no need for fwd declaration in btf_dump_emit_type()
712 if (t->name_off == 0) { in btf_dump_emit_type()
719 tstate->fwd_emitted = 1; in btf_dump_emit_type()
731 tstate->fwd_emitted = 1; in btf_dump_emit_type()
745 tstate->emit_state = EMITTED; in btf_dump_emit_type()
753 tstate->emit_state = EMITTED; in btf_dump_emit_type()
760 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
763 btf_dump_emit_type(d, btf_array(t)->type, cont_id); in btf_dump_emit_type()
768 tstate->emit_state = EMITTED; in btf_dump_emit_type()
771 tstate->emit_state = EMITTING; in btf_dump_emit_type()
772 btf_dump_emit_type(d, t->type, id); in btf_dump_emit_type()
780 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
784 tstate->emit_state = EMITTED; in btf_dump_emit_type()
788 tstate->emit_state = EMITTING; in btf_dump_emit_type()
789 /* if it's a top-level struct/union definition or struct/union in btf_dump_emit_type()
793 * members have necessary forward-declarations, where in btf_dump_emit_type()
796 if (top_level_def || t->name_off == 0) { in btf_dump_emit_type()
801 new_cont_id = t->name_off == 0 ? cont_id : id; in btf_dump_emit_type()
803 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
804 } else if (!tstate->fwd_emitted && id != cont_id) { in btf_dump_emit_type()
807 tstate->fwd_emitted = 1; in btf_dump_emit_type()
813 tstate->emit_state = EMITTED; in btf_dump_emit_type()
815 tstate->emit_state = NOT_EMITTED; in btf_dump_emit_type()
823 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
825 btf_dump_emit_type(d, p->type, cont_id); in btf_dump_emit_type()
843 /* all non-bitfield fields have to be naturally aligned */ in btf_is_struct_packed()
845 align = btf__align_of(btf, m->type); in btf_is_struct_packed()
847 if (align && bit_sz == 0 && m->offset % (8 * align) != 0) in btf_is_struct_packed()
851 /* size of a non-packed struct has to be a multiple of its alignment */ in btf_is_struct_packed()
852 if (t->size % max_align != 0) in btf_is_struct_packed()
869 {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} in btf_dump_emit_bit_padding()
886 * that even if struct itself has, let's say 4-byte alignment in btf_dump_emit_bit_padding()
887 * (i.e., it only uses up to int-aligned types), using `long: in btf_dump_emit_bit_padding()
916 (new_off != next_off && next_off - new_off <= new_off - cur_off)) in btf_dump_emit_bit_padding()
919 in_bitfield ? new_off - cur_off : 0); in btf_dump_emit_bit_padding()
930 bits = min(next_off - cur_off, pad_bits); in btf_dump_emit_bit_padding()
942 for (i = ARRAY_SIZE(pads) - 1; i >= 0; i--) { in btf_dump_emit_bit_padding()
960 t->name_off ? " " : "", in btf_dump_emit_struct_fwd()
975 align = btf__align_of(d->btf, id); in btf_dump_emit_struct_def()
976 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
980 t->name_off ? " " : "", in btf_dump_emit_struct_def()
988 fname = btf_name_of(d, m->name_off); in btf_dump_emit_struct_def()
991 m_align = packed ? 1 : btf__align_of(d->btf, m->type); in btf_dump_emit_struct_def()
997 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
1004 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type)); in btf_dump_emit_struct_def()
1014 btf_dump_emit_bit_padding(d, off, t->size * 8, align, false, lvl + 1); in btf_dump_emit_struct_def()
1020 if (vlen || t->size) { in btf_dump_emit_struct_def()
1074 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum32_val()
1076 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum32_val()
1079 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val); in btf_dump_emit_enum32_val()
1082 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val); in btf_dump_emit_enum32_val()
1100 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum64_val()
1101 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum64_val()
1125 t->name_off ? " " : "", in btf_dump_emit_enum_def()
1139 if (t->size == 1) { in btf_dump_emit_enum_def()
1140 /* one-byte enums can be forced with mode(byte) attribute */ in btf_dump_emit_enum_def()
1142 } else if (t->size == 8 && d->ptr_sz == 8) { in btf_dump_emit_enum_def()
1143 /* enum can be 8-byte sized if one of the enumerator values in btf_dump_emit_enum_def()
1144 * doesn't fit in 32-bit integer, or by adding mode(word) in btf_dump_emit_enum_def()
1145 * attribute (but probably only on 64-bit architectures); do in btf_dump_emit_enum_def()
1152 /* enum can't represent 64-bit values, so we need word mode */ in btf_dump_emit_enum_def()
1156 * non-zero upper 32-bits (which means that all values in btf_dump_emit_enum_def()
1157 * fit in 32-bit integers and won't cause compiler to in btf_dump_emit_enum_def()
1158 * bump enum to be 64-bit naturally in btf_dump_emit_enum_def()
1198 if (t->type == 0 && strcmp(name, "__gnuc_va_list") == 0) { in btf_dump_emit_typedef_def()
1204 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1212 if (d->decl_stack_cnt >= d->decl_stack_cap) { in btf_dump_push_decl_stack_id()
1213 new_cap = max(16, d->decl_stack_cap * 3 / 2); in btf_dump_push_decl_stack_id()
1214 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0])); in btf_dump_push_decl_stack_id()
1216 return -ENOMEM; in btf_dump_push_decl_stack_id()
1217 d->decl_stack = new_stack; in btf_dump_push_decl_stack_id()
1218 d->decl_stack_cap = new_cap; in btf_dump_push_decl_stack_id()
1221 d->decl_stack[d->decl_stack_cnt++] = id; in btf_dump_push_decl_stack_id()
1232 * - function prototypes (especially nesting of function prototypes);
1233 * - arrays;
1234 * - const/volatile/restrict for pointers vs other types.
1248 * [typedef] -> [array] -> [ptr] -> [const] -> [ptr] -> [const] -> [int]
1274 return libbpf_err(-EINVAL); in btf_dump__emit_type_decl()
1282 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1284 d->strip_mods = false; in btf_dump__emit_type_decl()
1295 stack_start = d->decl_stack_cnt; in btf_dump_emit_type_decl()
1297 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_decl()
1298 if (d->strip_mods && btf_is_mod(t)) in btf_dump_emit_type_decl()
1309 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1324 id = t->type; in btf_dump_emit_type_decl()
1327 id = btf_array(t)->type; in btf_dump_emit_type_decl()
1349 * emitting of declarations. Those stack frames are non-overlapping in btf_dump_emit_type_decl()
1350 * portions of shared btf_dump->decl_stack. To make it a bit nicer to in btf_dump_emit_type_decl()
1355 decl_stack.ids = d->decl_stack + stack_start; in btf_dump_emit_type_decl()
1356 decl_stack.cnt = d->decl_stack_cnt - stack_start; in btf_dump_emit_type_decl()
1360 * frame before returning. But it works with a read-only view into in btf_dump_emit_type_decl()
1362 * perspective of shared btf_dump->decl_stack, per se. We need to in btf_dump_emit_type_decl()
1366 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1374 while (decl_stack->cnt) { in btf_dump_emit_mods()
1375 id = decl_stack->ids[decl_stack->cnt - 1]; in btf_dump_emit_mods()
1376 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1391 decl_stack->cnt--; in btf_dump_emit_mods()
1400 while (decl_stack->cnt) { in btf_dump_drop_mods()
1401 id = decl_stack->ids[decl_stack->cnt - 1]; in btf_dump_drop_mods()
1402 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1405 decl_stack->cnt--; in btf_dump_drop_mods()
1425 * for cases where we have single pointer in a chain. E.g., in ptr -> in btf_dump_emit_type_chain()
1436 while (decls->cnt) { in btf_dump_emit_type_chain()
1437 id = decls->ids[--decls->cnt]; in btf_dump_emit_type_chain()
1446 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1453 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1460 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1469 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1496 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1516 if (decls->cnt == 0) { in btf_dump_emit_type_chain()
1518 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1522 next_id = decls->ids[decls->cnt - 1]; in btf_dump_emit_type_chain()
1523 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1525 /* we need space if we have named non-pointer */ in btf_dump_emit_type_chain()
1528 /* no parentheses for multi-dimensional array */ in btf_dump_emit_type_chain()
1534 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1551 if (decls->cnt) { in btf_dump_emit_type_chain()
1565 * no args case can be special-cased here as well. in btf_dump_emit_type_chain()
1567 if (vlen == 0 || (vlen == 1 && p->type == 0)) { in btf_dump_emit_type_chain()
1577 if (i == vlen - 1 && p->type == 0) { in btf_dump_emit_type_chain()
1582 name = btf_name_of(d, p->name_off); in btf_dump_emit_type_chain()
1583 btf_dump_emit_type_decl(d, p->type, name, lvl); in btf_dump_emit_type_chain()
1611 if (d->typed_dump->is_array_member) in btf_dump_emit_type_cast()
1617 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_cast()
1624 d->skip_anon_defs = true; in btf_dump_emit_type_cast()
1625 d->strip_mods = true; in btf_dump_emit_type_cast()
1627 d->strip_mods = false; in btf_dump_emit_type_cast()
1628 d->skip_anon_defs = false; in btf_dump_emit_type_cast()
1661 struct btf_dump_type_aux_state *s = &d->type_states[id]; in btf_dump_resolve_name()
1662 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_resolve_name()
1663 const char *orig_name = btf_name_of(d, t->name_off); in btf_dump_resolve_name()
1664 const char **cached_name = &d->cached_names[id]; in btf_dump_resolve_name()
1667 if (t->name_off == 0) in btf_dump_resolve_name()
1670 if (s->name_resolved) in btf_dump_resolve_name()
1674 s->name_resolved = 1; in btf_dump_resolve_name()
1687 s->name_resolved = 1; in btf_dump_resolve_name()
1693 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1698 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1711 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1716 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1721 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth; in btf_dump_data_pfx()
1723 if (d->typed_dump->compact) in btf_dump_data_pfx()
1727 btf_dump_printf(d, "%s", d->typed_dump->indent_str); in btf_dump_data_pfx()
1731 * to the format specifier passed in; these do the work of appending
1733 * in the format specifier + value(s).
1746 return -ENOTSUP; in btf_dump_unsupported_data()
1763 if (t->size > 8) { in btf_dump_get_bitfield_value()
1764 pr_warn("unexpected bitfield size %d\n", t->size); in btf_dump_get_bitfield_value()
1765 return -EINVAL; in btf_dump_get_bitfield_value()
1772 for (i = t->size - 1; i >= 0; i--) in btf_dump_get_bitfield_value()
1776 for (i = 0; i < t->size; i++) in btf_dump_get_bitfield_value()
1778 nr_copy_bits = t->size * 8 - bits_offset; in btf_dump_get_bitfield_value()
1782 left_shift_bits = 64 - nr_copy_bits; in btf_dump_get_bitfield_value()
1783 right_shift_bits = 64 - bit_sz; in btf_dump_get_bitfield_value()
1803 return -ENODATA; in btf_dump_bitfield_check_zero()
1834 /* For pointer types, pointer size is not defined on a per-type basis. in btf_dump_base_type_check_zero()
1838 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1840 nr_bytes = t->size; in btf_dump_base_type_check_zero()
1844 return -EINVAL; in btf_dump_base_type_check_zero()
1848 return -ENODATA; in btf_dump_base_type_check_zero()
1872 int sz = t->size; in btf_dump_int_data()
1876 return -EINVAL; in btf_dump_int_data()
1879 /* handle packed int data - accesses of integers not aligned on in btf_dump_int_data()
1882 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1890 __u64 lsi, msi; in btf_dump_int_data() local
1892 /* avoid use of __int128 as some 32-bit platforms do not in btf_dump_int_data()
1897 msi = ints[1]; in btf_dump_int_data()
1900 msi = ints[0]; in btf_dump_int_data()
1904 if (msi == 0) in btf_dump_int_data()
1907 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1930 if (d->typed_dump->is_array_char) { in btf_dump_int_data()
1932 if (d->typed_dump->is_array_terminated) in btf_dump_int_data()
1936 d->typed_dump->is_array_terminated = true; in btf_dump_int_data()
1951 return -EINVAL; in btf_dump_int_data()
1969 int sz = t->size; in btf_dump_float_data()
1972 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_float_data()
1979 btf_dump_type_values(d, "%Lf", flp->ld); in btf_dump_float_data()
1982 btf_dump_type_values(d, "%lf", flp->d); in btf_dump_float_data()
1985 btf_dump_type_values(d, "%f", flp->f); in btf_dump_float_data()
1989 return -EINVAL; in btf_dump_float_data()
1999 enum btf_func_linkage linkage = btf_var(v)->linkage; in btf_dump_var_data()
2021 type_id = v->type; in btf_dump_var_data()
2022 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
2024 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
2040 elem_type_id = array->type; in btf_dump_array_data()
2041 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_array_data()
2042 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_array_data()
2046 return -EINVAL; in btf_dump_array_data()
2056 d->typed_dump->is_array_char = true; in btf_dump_array_data()
2066 d->typed_dump->depth++; in btf_dump_array_data()
2072 is_array_member = d->typed_dump->is_array_member; in btf_dump_array_data()
2073 d->typed_dump->is_array_member = true; in btf_dump_array_data()
2074 is_array_terminated = d->typed_dump->is_array_terminated; in btf_dump_array_data()
2075 d->typed_dump->is_array_terminated = false; in btf_dump_array_data()
2076 for (i = 0; i < array->nelems; i++, data += elem_size) { in btf_dump_array_data()
2077 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
2081 d->typed_dump->is_array_member = is_array_member; in btf_dump_array_data()
2082 d->typed_dump->is_array_terminated = is_array_terminated; in btf_dump_array_data()
2083 d->typed_dump->depth--; in btf_dump_array_data()
2106 d->typed_dump->depth++; in btf_dump_struct_data()
2115 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_struct_data()
2116 mname = btf_name_of(d, m->name_off); in btf_dump_struct_data()
2120 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8, in btf_dump_struct_data()
2125 d->typed_dump->depth--; in btf_dump_struct_data()
2141 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
2146 memcpy(&pt, data, d->ptr_sz); in btf_dump_ptr_data()
2147 if (d->ptr_sz == 4) in btf_dump_ptr_data()
2163 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
2174 switch (t->size) { in btf_dump_get_enum_value()
2188 pr_warn("unexpected size %d for enum, id:[%u]\n", t->size, id); in btf_dump_get_enum_value()
2189 return -EINVAL; in btf_dump_get_enum_value()
2211 if (value != e->val) in btf_dump_enum_data()
2213 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2224 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2244 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off)); in btf_dump_datasec_data()
2247 var = btf__type_by_id(d->btf, vsi->type); in btf_dump_datasec_data()
2248 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0); in btf_dump_datasec_data()
2256 /* return size of type, or if base type overflows, return -E2BIG. */
2276 return data + nr_bytes > d->typed_dump->data_end ? -E2BIG : nr_bytes; in btf_dump_type_data_check_overflow()
2279 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2284 return -EINVAL; in btf_dump_type_data_check_overflow()
2294 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_overflow()
2298 return -EINVAL; in btf_dump_type_data_check_overflow()
2307 if (data + bits_offset / 8 + size > d->typed_dump->data_end) in btf_dump_type_data_check_overflow()
2308 return -E2BIG; in btf_dump_type_data_check_overflow()
2327 * - we ask for them (emit_zeros) in btf_dump_type_data_check_zero()
2328 * - if we are at top-level so we see "struct empty { }" in btf_dump_type_data_check_zero()
2329 * - or if we are an array member and the array is non-empty and in btf_dump_type_data_check_zero()
2331 * have an integer array 0, 1, 0, 1 and only show non-zero values. in btf_dump_type_data_check_zero()
2333 * with a '\0', the array-level check_zero() will prevent showing it; in btf_dump_type_data_check_zero()
2337 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 || in btf_dump_type_data_check_zero()
2338 (d->typed_dump->is_array_member && in btf_dump_type_data_check_zero()
2339 !d->typed_dump->is_array_char)) in btf_dump_type_data_check_zero()
2342 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_zero()
2358 elem_type_id = array->type; in btf_dump_type_data_check_zero()
2359 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_type_data_check_zero()
2360 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_type_data_check_zero()
2368 * non-zero because the string is terminated. in btf_dump_type_data_check_zero()
2370 for (i = 0; i < array->nelems; i++) { in btf_dump_type_data_check_zero()
2372 return -ENODATA; in btf_dump_type_data_check_zero()
2378 if (err != -ENODATA) in btf_dump_type_data_check_zero()
2381 return -ENODATA; in btf_dump_type_data_check_zero()
2388 /* if any struct/union member is non-zero, the struct/union in btf_dump_type_data_check_zero()
2389 * is considered non-zero and dumped. in btf_dump_type_data_check_zero()
2395 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_type_data_check_zero()
2403 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8, in btf_dump_type_data_check_zero()
2408 return -ENODATA; in btf_dump_type_data_check_zero()
2416 return -ENODATA; in btf_dump_type_data_check_zero()
2442 if (err == -ENODATA) in btf_dump_dump_type_data()
2448 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2454 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2507 BTF_INFO_KIND(t->info), id); in btf_dump_dump_type_data()
2508 return -EINVAL; in btf_dump_dump_type_data()
2524 return libbpf_err(-EINVAL); in btf_dump__dump_type_data()
2526 t = btf__type_by_id(d->btf, id); in btf_dump__dump_type_data()
2528 return libbpf_err(-ENOENT); in btf_dump__dump_type_data()
2530 d->typed_dump = &typed_dump; in btf_dump__dump_type_data()
2531 d->typed_dump->data_end = data + data_sz; in btf_dump__dump_type_data()
2532 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); in btf_dump__dump_type_data()
2536 d->typed_dump->indent_str[0] = '\t'; in btf_dump__dump_type_data()
2538 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str, in btf_dump__dump_type_data()
2539 sizeof(d->typed_dump->indent_str)); in btf_dump__dump_type_data()
2541 d->typed_dump->compact = OPTS_GET(opts, compact, false); in btf_dump__dump_type_data()
2542 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false); in btf_dump__dump_type_data()
2543 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false); in btf_dump__dump_type_data()
2547 d->typed_dump = NULL; in btf_dump__dump_type_data()