Lines Matching +full:msi +full:- +full:specifier
1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 * BTF-to-C type converter.
25 static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
29 return lvl >= PREFIX_CNT ? PREFIXES : &PREFIXES[PREFIX_CNT - lvl]; in pfx()
44 /* per-type auxiliary state */
52 /* whether unique non-duplicate name was already assigned */
87 /* per-type auxiliary state */
90 /* per-type optional cached unique name, must be freed, if present */
94 /* topo-sorted list of dependent type definitions */
132 return btf__name_by_offset(d->btf, name_off); in btf_name_of()
140 d->printf_fn(d->cb_ctx, fmt, args); in btf_dump_printf()
156 return libbpf_err_ptr(-EINVAL); in btf_dump__new()
159 return libbpf_err_ptr(-EINVAL); in btf_dump__new()
163 return libbpf_err_ptr(-ENOMEM); in btf_dump__new()
165 d->btf = btf; in btf_dump__new()
166 d->printf_fn = printf_fn; in btf_dump__new()
167 d->cb_ctx = ctx; in btf_dump__new()
168 d->ptr_sz = btf__pointer_size(btf) ? : sizeof(void *); in btf_dump__new()
170 d->type_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
171 if (IS_ERR(d->type_names)) { in btf_dump__new()
172 err = PTR_ERR(d->type_names); in btf_dump__new()
173 d->type_names = NULL; in btf_dump__new()
176 d->ident_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
177 if (IS_ERR(d->ident_names)) { in btf_dump__new()
178 err = PTR_ERR(d->ident_names); in btf_dump__new()
179 d->ident_names = NULL; in btf_dump__new()
195 int err, last_id = btf__type_cnt(d->btf) - 1; in btf_dump_resize()
197 if (last_id <= d->last_id) in btf_dump_resize()
200 if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap, in btf_dump_resize()
201 sizeof(*d->type_states), last_id + 1)) in btf_dump_resize()
202 return -ENOMEM; in btf_dump_resize()
203 if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap, in btf_dump_resize()
204 sizeof(*d->cached_names), last_id + 1)) in btf_dump_resize()
205 return -ENOMEM; in btf_dump_resize()
207 if (d->last_id == 0) { in btf_dump_resize()
209 d->type_states[0].order_state = ORDERED; in btf_dump_resize()
210 d->type_states[0].emit_state = EMITTED; in btf_dump_resize()
218 d->last_id = last_id; in btf_dump_resize()
229 free(d->type_states); in btf_dump__free()
230 if (d->cached_names) { in btf_dump__free()
232 for (i = 0; i <= d->last_id; i++) { in btf_dump__free()
233 if (d->cached_names[i]) in btf_dump__free()
234 free((void *)d->cached_names[i]); in btf_dump__free()
237 free(d->cached_names); in btf_dump__free()
238 free(d->emit_queue); in btf_dump__free()
239 free(d->decl_stack); in btf_dump__free()
240 hashmap__free(d->type_names); in btf_dump__free()
241 hashmap__free(d->ident_names); in btf_dump__free()
254 * filter out BTF types according to user-defined criterias and emitted only
259 * Dumping is done in two high-level passes:
269 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
270 return libbpf_err(-EINVAL); in btf_dump__dump_type()
276 d->emit_queue_cnt = 0; in btf_dump__dump_type()
281 for (i = 0; i < d->emit_queue_cnt; i++) in btf_dump__dump_type()
282 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/); in btf_dump__dump_type()
289 * determine top-level anonymous enums that need to be emitted as an
293 * type declaration; or as a top-level anonymous enum, typically used for
296 * top-level anonymous enum won't be referenced by anything, while embedded
301 int i, j, n = btf__type_cnt(d->btf); in btf_dump_mark_referenced()
305 for (i = d->last_id + 1; i < n; i++) { in btf_dump_mark_referenced()
306 t = btf__type_by_id(d->btf, i); in btf_dump_mark_referenced()
326 d->type_states[t->type].referenced = 1; in btf_dump_mark_referenced()
332 d->type_states[a->index_type].referenced = 1; in btf_dump_mark_referenced()
333 d->type_states[a->type].referenced = 1; in btf_dump_mark_referenced()
341 d->type_states[m->type].referenced = 1; in btf_dump_mark_referenced()
348 d->type_states[p->type].referenced = 1; in btf_dump_mark_referenced()
355 d->type_states[v->type].referenced = 1; in btf_dump_mark_referenced()
359 return -EINVAL; in btf_dump_mark_referenced()
370 if (d->emit_queue_cnt >= d->emit_queue_cap) { in btf_dump_add_emit_queue_id()
371 new_cap = max(16, d->emit_queue_cap * 3 / 2); in btf_dump_add_emit_queue_id()
372 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0])); in btf_dump_add_emit_queue_id()
374 return -ENOMEM; in btf_dump_add_emit_queue_id()
375 d->emit_queue = new_queue; in btf_dump_add_emit_queue_id()
376 d->emit_queue_cap = new_cap; in btf_dump_add_emit_queue_id()
379 d->emit_queue[d->emit_queue_cnt++] = id; in btf_dump_add_emit_queue_id()
406 * struct A {}; // if this was forward-declaration: compilation error
418 * between struct A and struct B. If struct A was forward-declared before
425 * - weak link (relationship) between X and Y, if Y *CAN* be
426 * forward-declared at the point of X definition;
427 * - strong link, if Y *HAS* to be fully-defined before X can be defined.
430 * BTF_KIND_PTR type in the chain and at least one non-anonymous type
445 * marked as ORDERED. We can mark PTR as ORDERED as well, as it semi-forces
451 * - 1, if type is part of strong link (so there is strong topological
453 * - 0, if type is part of weak link (so can be satisfied through forward
455 * - <0, on error (e.g., unsatisfiable type loop detected).
462 * stand-alone fwd decl, enum, typedef, struct, union). Ptrs, arrays, in btf_dump_order_type()
466 * So for all non-defining kinds, we never even set ordering state, in btf_dump_order_type()
470 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
476 if (tstate->order_state == ORDERED) in btf_dump_order_type()
479 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
481 if (tstate->order_state == ORDERING) { in btf_dump_order_type()
483 if (btf_is_composite(t) && through_ptr && t->name_off != 0) in btf_dump_order_type()
486 return -ELOOP; in btf_dump_order_type()
492 tstate->order_state = ORDERED; in btf_dump_order_type()
496 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
497 tstate->order_state = ORDERED; in btf_dump_order_type()
501 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
511 if (through_ptr && t->name_off != 0) in btf_dump_order_type()
514 tstate->order_state = ORDERING; in btf_dump_order_type()
518 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
523 if (t->name_off != 0) { in btf_dump_order_type()
529 tstate->order_state = ORDERED; in btf_dump_order_type()
536 * non-anonymous or non-referenced enums are top-level in btf_dump_order_type()
540 if (t->name_off != 0 || !tstate->referenced) { in btf_dump_order_type()
545 tstate->order_state = ORDERED; in btf_dump_order_type()
551 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
555 /* typedef is similar to struct/union w.r.t. fwd-decls */ in btf_dump_order_type()
564 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
571 return btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
577 err = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
584 err = btf_dump_order_type(d, p->type, through_ptr); in btf_dump_order_type()
596 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
600 return -EINVAL; in btf_dump_order_type()
642 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
644 /* __builtin_va_list is a compiler built-in, which causes compilation in btf_dump_is_blacklisted()
647 * C header from BTF). As it is built-in, it should be already defined in btf_dump_is_blacklisted()
650 if (t->name_off == 0) in btf_dump_is_blacklisted()
652 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
656 * Emit C-syntax definitions of types from chains of BTF types.
658 * High-level handling of determining necessary forward declarations are handled
659 * by btf_dump_emit_type() itself, but all nitty-gritty details of emitting type
675 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
680 if (tstate->emit_state == EMITTED) in btf_dump_emit_type()
683 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
686 if (tstate->emit_state == EMITTING) { in btf_dump_emit_type()
687 if (tstate->fwd_emitted) in btf_dump_emit_type()
695 * part of - then no need for fwd declaration in btf_dump_emit_type()
699 if (t->name_off == 0) { in btf_dump_emit_type()
706 tstate->fwd_emitted = 1; in btf_dump_emit_type()
718 tstate->fwd_emitted = 1; in btf_dump_emit_type()
732 tstate->emit_state = EMITTED; in btf_dump_emit_type()
740 tstate->emit_state = EMITTED; in btf_dump_emit_type()
747 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
750 btf_dump_emit_type(d, btf_array(t)->type, cont_id); in btf_dump_emit_type()
755 tstate->emit_state = EMITTED; in btf_dump_emit_type()
758 tstate->emit_state = EMITTING; in btf_dump_emit_type()
759 btf_dump_emit_type(d, t->type, id); in btf_dump_emit_type()
767 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
771 tstate->emit_state = EMITTED; in btf_dump_emit_type()
775 tstate->emit_state = EMITTING; in btf_dump_emit_type()
776 /* if it's a top-level struct/union definition or struct/union in btf_dump_emit_type()
780 * members have necessary forward-declarations, where in btf_dump_emit_type()
783 if (top_level_def || t->name_off == 0) { in btf_dump_emit_type()
788 new_cont_id = t->name_off == 0 ? cont_id : id; in btf_dump_emit_type()
790 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
791 } else if (!tstate->fwd_emitted && id != cont_id) { in btf_dump_emit_type()
794 tstate->fwd_emitted = 1; in btf_dump_emit_type()
800 tstate->emit_state = EMITTED; in btf_dump_emit_type()
802 tstate->emit_state = NOT_EMITTED; in btf_dump_emit_type()
810 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
812 btf_dump_emit_type(d, p->type, cont_id); in btf_dump_emit_type()
829 /* size of a non-packed struct has to be a multiple of its alignment*/ in btf_is_struct_packed()
830 if (align && t->size % align) in btf_is_struct_packed()
835 /* all non-bitfield fields have to be naturally aligned */ in btf_is_struct_packed()
837 align = btf__align_of(btf, m->type); in btf_is_struct_packed()
839 if (align && bit_sz == 0 && m->offset % (8 * align) != 0) in btf_is_struct_packed()
859 int off_diff = m_off - cur_off; in btf_dump_emit_bit_padding()
860 int ptr_bits = d->ptr_sz * 8; in btf_dump_emit_bit_padding()
887 off_diff -= pad_bits; in btf_dump_emit_bit_padding()
896 t->name_off ? " " : "", in btf_dump_emit_struct_fwd()
910 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
914 t->name_off ? " " : "", in btf_dump_emit_struct_def()
921 fname = btf_name_of(d, m->name_off); in btf_dump_emit_struct_def()
924 align = packed ? 1 : btf__align_of(d->btf, m->type); in btf_dump_emit_struct_def()
928 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
934 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type)); in btf_dump_emit_struct_def()
942 align = packed ? 1 : btf__align_of(d->btf, id); in btf_dump_emit_struct_def()
943 btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align, in btf_dump_emit_struct_def()
998 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum32_val()
1000 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum32_val()
1003 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val); in btf_dump_emit_enum32_val()
1006 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val); in btf_dump_emit_enum32_val()
1024 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum64_val()
1025 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum64_val()
1049 t->name_off ? " " : "", in btf_dump_emit_enum_def()
1085 if (t->type == 0 && strcmp(name, "__gnuc_va_list") == 0) { in btf_dump_emit_typedef_def()
1091 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1099 if (d->decl_stack_cnt >= d->decl_stack_cap) { in btf_dump_push_decl_stack_id()
1100 new_cap = max(16, d->decl_stack_cap * 3 / 2); in btf_dump_push_decl_stack_id()
1101 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0])); in btf_dump_push_decl_stack_id()
1103 return -ENOMEM; in btf_dump_push_decl_stack_id()
1104 d->decl_stack = new_stack; in btf_dump_push_decl_stack_id()
1105 d->decl_stack_cap = new_cap; in btf_dump_push_decl_stack_id()
1108 d->decl_stack[d->decl_stack_cnt++] = id; in btf_dump_push_decl_stack_id()
1119 * - function prototypes (especially nesting of function prototypes);
1120 * - arrays;
1121 * - const/volatile/restrict for pointers vs other types.
1135 * [typedef] -> [array] -> [ptr] -> [const] -> [ptr] -> [const] -> [int]
1161 return libbpf_err(-EINVAL); in btf_dump__emit_type_decl()
1169 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1171 d->strip_mods = false; in btf_dump__emit_type_decl()
1182 stack_start = d->decl_stack_cnt; in btf_dump_emit_type_decl()
1184 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_decl()
1185 if (d->strip_mods && btf_is_mod(t)) in btf_dump_emit_type_decl()
1196 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1211 id = t->type; in btf_dump_emit_type_decl()
1214 id = btf_array(t)->type; in btf_dump_emit_type_decl()
1236 * emitting of declarations. Those stack frames are non-overlapping in btf_dump_emit_type_decl()
1237 * portions of shared btf_dump->decl_stack. To make it a bit nicer to in btf_dump_emit_type_decl()
1242 decl_stack.ids = d->decl_stack + stack_start; in btf_dump_emit_type_decl()
1243 decl_stack.cnt = d->decl_stack_cnt - stack_start; in btf_dump_emit_type_decl()
1247 * frame before returning. But it works with a read-only view into in btf_dump_emit_type_decl()
1249 * perspective of shared btf_dump->decl_stack, per se. We need to in btf_dump_emit_type_decl()
1253 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1261 while (decl_stack->cnt) { in btf_dump_emit_mods()
1262 id = decl_stack->ids[decl_stack->cnt - 1]; in btf_dump_emit_mods()
1263 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1278 decl_stack->cnt--; in btf_dump_emit_mods()
1287 while (decl_stack->cnt) { in btf_dump_drop_mods()
1288 id = decl_stack->ids[decl_stack->cnt - 1]; in btf_dump_drop_mods()
1289 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1292 decl_stack->cnt--; in btf_dump_drop_mods()
1312 * for cases where we have single pointer in a chain. E.g., in ptr -> in btf_dump_emit_type_chain()
1323 while (decls->cnt) { in btf_dump_emit_type_chain()
1324 id = decls->ids[--decls->cnt]; in btf_dump_emit_type_chain()
1333 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1340 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1347 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1356 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1383 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1403 if (decls->cnt == 0) { in btf_dump_emit_type_chain()
1405 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1409 next_id = decls->ids[decls->cnt - 1]; in btf_dump_emit_type_chain()
1410 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1412 /* we need space if we have named non-pointer */ in btf_dump_emit_type_chain()
1415 /* no parentheses for multi-dimensional array */ in btf_dump_emit_type_chain()
1421 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1438 if (decls->cnt) { in btf_dump_emit_type_chain()
1452 if (vlen == 1 && p->type == 0) { in btf_dump_emit_type_chain()
1462 if (i == vlen - 1 && p->type == 0) { in btf_dump_emit_type_chain()
1467 name = btf_name_of(d, p->name_off); in btf_dump_emit_type_chain()
1468 btf_dump_emit_type_decl(d, p->type, name, lvl); in btf_dump_emit_type_chain()
1496 if (d->typed_dump->is_array_member) in btf_dump_emit_type_cast()
1502 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_cast()
1509 d->skip_anon_defs = true; in btf_dump_emit_type_cast()
1510 d->strip_mods = true; in btf_dump_emit_type_cast()
1512 d->strip_mods = false; in btf_dump_emit_type_cast()
1513 d->skip_anon_defs = false; in btf_dump_emit_type_cast()
1535 struct btf_dump_type_aux_state *s = &d->type_states[id]; in btf_dump_resolve_name()
1536 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_resolve_name()
1537 const char *orig_name = btf_name_of(d, t->name_off); in btf_dump_resolve_name()
1538 const char **cached_name = &d->cached_names[id]; in btf_dump_resolve_name()
1541 if (t->name_off == 0) in btf_dump_resolve_name()
1544 if (s->name_resolved) in btf_dump_resolve_name()
1548 s->name_resolved = 1; in btf_dump_resolve_name()
1561 s->name_resolved = 1; in btf_dump_resolve_name()
1567 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1572 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1585 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1590 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1595 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth; in btf_dump_data_pfx()
1597 if (d->typed_dump->compact) in btf_dump_data_pfx()
1601 btf_dump_printf(d, "%s", d->typed_dump->indent_str); in btf_dump_data_pfx()
1605 * to the format specifier passed in; these do the work of appending
1607 * in the format specifier + value(s).
1620 return -ENOTSUP; in btf_dump_unsupported_data()
1637 if (t->size > 8) { in btf_dump_get_bitfield_value()
1638 pr_warn("unexpected bitfield size %d\n", t->size); in btf_dump_get_bitfield_value()
1639 return -EINVAL; in btf_dump_get_bitfield_value()
1646 for (i = t->size - 1; i >= 0; i--) in btf_dump_get_bitfield_value()
1650 for (i = 0; i < t->size; i++) in btf_dump_get_bitfield_value()
1652 nr_copy_bits = t->size * 8 - bits_offset; in btf_dump_get_bitfield_value()
1656 left_shift_bits = 64 - nr_copy_bits; in btf_dump_get_bitfield_value()
1657 right_shift_bits = 64 - bit_sz; in btf_dump_get_bitfield_value()
1677 return -ENODATA; in btf_dump_bitfield_check_zero()
1708 /* For pointer types, pointer size is not defined on a per-type basis. in btf_dump_base_type_check_zero()
1712 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1714 nr_bytes = t->size; in btf_dump_base_type_check_zero()
1718 return -EINVAL; in btf_dump_base_type_check_zero()
1722 return -ENODATA; in btf_dump_base_type_check_zero()
1746 int sz = t->size; in btf_dump_int_data()
1750 return -EINVAL; in btf_dump_int_data()
1753 /* handle packed int data - accesses of integers not aligned on in btf_dump_int_data()
1756 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1764 __u64 lsi, msi; in btf_dump_int_data() local
1766 /* avoid use of __int128 as some 32-bit platforms do not in btf_dump_int_data()
1771 msi = ints[1]; in btf_dump_int_data()
1774 msi = ints[0]; in btf_dump_int_data()
1778 if (msi == 0) in btf_dump_int_data()
1781 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1804 if (d->typed_dump->is_array_char) { in btf_dump_int_data()
1806 if (d->typed_dump->is_array_terminated) in btf_dump_int_data()
1809 d->typed_dump->is_array_terminated = true; in btf_dump_int_data()
1824 return -EINVAL; in btf_dump_int_data()
1842 int sz = t->size; in btf_dump_float_data()
1845 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_float_data()
1852 btf_dump_type_values(d, "%Lf", flp->ld); in btf_dump_float_data()
1855 btf_dump_type_values(d, "%lf", flp->d); in btf_dump_float_data()
1858 btf_dump_type_values(d, "%f", flp->f); in btf_dump_float_data()
1862 return -EINVAL; in btf_dump_float_data()
1872 enum btf_func_linkage linkage = btf_var(v)->linkage; in btf_dump_var_data()
1894 type_id = v->type; in btf_dump_var_data()
1895 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
1897 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
1912 elem_type_id = array->type; in btf_dump_array_data()
1913 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_array_data()
1914 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_array_data()
1918 return -EINVAL; in btf_dump_array_data()
1928 d->typed_dump->is_array_char = true; in btf_dump_array_data()
1938 d->typed_dump->depth++; in btf_dump_array_data()
1944 is_array_member = d->typed_dump->is_array_member; in btf_dump_array_data()
1945 d->typed_dump->is_array_member = true; in btf_dump_array_data()
1946 for (i = 0; i < array->nelems; i++, data += elem_size) { in btf_dump_array_data()
1947 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
1951 d->typed_dump->is_array_member = is_array_member; in btf_dump_array_data()
1952 d->typed_dump->depth--; in btf_dump_array_data()
1975 d->typed_dump->depth++; in btf_dump_struct_data()
1984 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_struct_data()
1985 mname = btf_name_of(d, m->name_off); in btf_dump_struct_data()
1989 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8, in btf_dump_struct_data()
1994 d->typed_dump->depth--; in btf_dump_struct_data()
2010 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
2015 memcpy(&pt, data, d->ptr_sz); in btf_dump_ptr_data()
2016 if (d->ptr_sz == 4) in btf_dump_ptr_data()
2032 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
2043 switch (t->size) { in btf_dump_get_enum_value()
2057 pr_warn("unexpected size %d for enum, id:[%u]\n", t->size, id); in btf_dump_get_enum_value()
2058 return -EINVAL; in btf_dump_get_enum_value()
2080 if (value != e->val) in btf_dump_enum_data()
2082 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2093 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2113 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off)); in btf_dump_datasec_data()
2116 var = btf__type_by_id(d->btf, vsi->type); in btf_dump_datasec_data()
2117 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0); in btf_dump_datasec_data()
2125 /* return size of type, or if base type overflows, return -E2BIG. */
2132 __s64 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2137 return -EINVAL; in btf_dump_type_data_check_overflow()
2147 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_overflow()
2151 return -EINVAL; in btf_dump_type_data_check_overflow()
2160 if (data + bits_offset / 8 + size > d->typed_dump->data_end) in btf_dump_type_data_check_overflow()
2161 return -E2BIG; in btf_dump_type_data_check_overflow()
2180 * - we ask for them (emit_zeros) in btf_dump_type_data_check_zero()
2181 * - if we are at top-level so we see "struct empty { }" in btf_dump_type_data_check_zero()
2182 * - or if we are an array member and the array is non-empty and in btf_dump_type_data_check_zero()
2184 * have an integer array 0, 1, 0, 1 and only show non-zero values. in btf_dump_type_data_check_zero()
2186 * with a '\0', the array-level check_zero() will prevent showing it; in btf_dump_type_data_check_zero()
2190 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 || in btf_dump_type_data_check_zero()
2191 (d->typed_dump->is_array_member && in btf_dump_type_data_check_zero()
2192 !d->typed_dump->is_array_char)) in btf_dump_type_data_check_zero()
2195 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_zero()
2211 elem_type_id = array->type; in btf_dump_type_data_check_zero()
2212 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_type_data_check_zero()
2213 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_type_data_check_zero()
2221 * non-zero because the string is terminated. in btf_dump_type_data_check_zero()
2223 for (i = 0; i < array->nelems; i++) { in btf_dump_type_data_check_zero()
2225 return -ENODATA; in btf_dump_type_data_check_zero()
2231 if (err != -ENODATA) in btf_dump_type_data_check_zero()
2234 return -ENODATA; in btf_dump_type_data_check_zero()
2241 /* if any struct/union member is non-zero, the struct/union in btf_dump_type_data_check_zero()
2242 * is considered non-zero and dumped. in btf_dump_type_data_check_zero()
2248 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_type_data_check_zero()
2256 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8, in btf_dump_type_data_check_zero()
2261 return -ENODATA; in btf_dump_type_data_check_zero()
2269 return -ENODATA; in btf_dump_type_data_check_zero()
2295 if (err == -ENODATA) in btf_dump_dump_type_data()
2301 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2307 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2360 BTF_INFO_KIND(t->info), id); in btf_dump_dump_type_data()
2361 return -EINVAL; in btf_dump_dump_type_data()
2377 return libbpf_err(-EINVAL); in btf_dump__dump_type_data()
2379 t = btf__type_by_id(d->btf, id); in btf_dump__dump_type_data()
2381 return libbpf_err(-ENOENT); in btf_dump__dump_type_data()
2383 d->typed_dump = &typed_dump; in btf_dump__dump_type_data()
2384 d->typed_dump->data_end = data + data_sz; in btf_dump__dump_type_data()
2385 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); in btf_dump__dump_type_data()
2389 d->typed_dump->indent_str[0] = '\t'; in btf_dump__dump_type_data()
2391 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str, in btf_dump__dump_type_data()
2392 sizeof(d->typed_dump->indent_str)); in btf_dump__dump_type_data()
2394 d->typed_dump->compact = OPTS_GET(opts, compact, false); in btf_dump__dump_type_data()
2395 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false); in btf_dump__dump_type_data()
2396 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false); in btf_dump__dump_type_data()
2400 d->typed_dump = NULL; in btf_dump__dump_type_data()