Lines Matching refs:d

130 static const char *btf_name_of(const struct btf_dump *d, __u32 name_off)  in btf_name_of()  argument
132 return btf__name_by_offset(d->btf, name_off); in btf_name_of()
135 static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...) in btf_dump_printf() argument
140 d->printf_fn(d->cb_ctx, fmt, args); in btf_dump_printf()
144 static int btf_dump_mark_referenced(struct btf_dump *d);
145 static int btf_dump_resize(struct btf_dump *d);
152 struct btf_dump *d; in btf_dump__new() local
161 d = calloc(1, sizeof(struct btf_dump)); in btf_dump__new()
162 if (!d) 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()
183 err = btf_dump_resize(d); in btf_dump__new()
187 return d; in btf_dump__new()
189 btf_dump__free(d); in btf_dump__new()
193 static int btf_dump_resize(struct btf_dump *d) in btf_dump_resize() argument
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()
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()
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()
214 err = btf_dump_mark_referenced(d); in btf_dump_resize()
218 d->last_id = last_id; in btf_dump_resize()
222 void btf_dump__free(struct btf_dump *d) in btf_dump__free() argument
226 if (IS_ERR_OR_NULL(d)) in btf_dump__free()
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()
243 free(d); in btf_dump__free()
246 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr);
247 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id);
265 int btf_dump__dump_type(struct btf_dump *d, __u32 id) in btf_dump__dump_type() argument
269 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
272 err = btf_dump_resize(d); in btf_dump__dump_type()
276 d->emit_queue_cnt = 0; in btf_dump__dump_type()
277 err = btf_dump_order_type(d, id, false); 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()
299 static int btf_dump_mark_referenced(struct btf_dump *d) in btf_dump_mark_referenced() argument
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()
365 static int btf_dump_add_emit_queue_id(struct btf_dump *d, __u32 id) in btf_dump_add_emit_queue_id() argument
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()
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()
457 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) in btf_dump_order_type() argument
470 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
479 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
496 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
501 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
518 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
524 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
541 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
551 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
560 err = btf_dump_add_emit_queue_id(d, id); 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()
604 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
607 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
609 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
612 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
614 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
617 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
620 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
629 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
631 static void btf_dump_emit_type_chain(struct btf_dump *d,
635 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id);
636 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id);
637 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
640 static bool btf_dump_is_blacklisted(struct btf_dump *d, __u32 id) in btf_dump_is_blacklisted() argument
642 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
652 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
673 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) in btf_dump_emit_type() argument
675 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
683 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
704 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
705 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
714 if (!btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
715 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
716 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
730 btf_dump_emit_missing_aliases(d, id, t); in btf_dump_emit_type()
737 btf_dump_emit_enum_def(d, id, t, 0); in btf_dump_emit_type()
738 btf_dump_printf(d, ";\n\n"); 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()
753 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type()
754 btf_dump_printf(d, ";\n\n"); 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()
768 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
769 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
790 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
792 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
793 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
798 btf_dump_emit_struct_def(d, id, t, 0); in btf_dump_emit_type()
799 btf_dump_printf(d, ";\n\n"); 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()
855 static void btf_dump_emit_bit_padding(const struct btf_dump *d, in btf_dump_emit_bit_padding() argument
860 int ptr_bits = d->ptr_sz * 8; in btf_dump_emit_bit_padding()
886 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits); in btf_dump_emit_bit_padding()
891 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_struct_fwd() argument
894 btf_dump_printf(d, "%s%s%s", in btf_dump_emit_struct_fwd()
897 btf_dump_type_name(d, id)); in btf_dump_emit_struct_fwd()
900 static void btf_dump_emit_struct_def(struct btf_dump *d, in btf_dump_emit_struct_def() argument
910 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
912 btf_dump_printf(d, "%s%s%s {", in btf_dump_emit_struct_def()
915 btf_dump_type_name(d, id)); 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()
926 btf_dump_emit_bit_padding(d, off, m_off, m_sz, align, lvl + 1); in btf_dump_emit_struct_def()
927 btf_dump_printf(d, "\n%s", pfx(lvl + 1)); in btf_dump_emit_struct_def()
928 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
931 btf_dump_printf(d, ": %d", m_sz); 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()
937 btf_dump_printf(d, ";"); 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()
948 btf_dump_printf(d, "\n"); in btf_dump_emit_struct_def()
949 btf_dump_printf(d, "%s}", pfx(lvl)); in btf_dump_emit_struct_def()
951 btf_dump_printf(d, " __attribute__((packed))"); in btf_dump_emit_struct_def()
965 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id, in btf_dump_emit_missing_aliases() argument
968 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_missing_aliases()
973 btf_dump_printf(d, "typedef %s %s;\n\n", in btf_dump_emit_missing_aliases()
980 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_fwd() argument
983 btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id)); in btf_dump_emit_enum_fwd()
986 static void btf_dump_emit_enum32_val(struct btf_dump *d, in btf_dump_emit_enum32_val() argument
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()
1011 static void btf_dump_emit_enum64_val(struct btf_dump *d, in btf_dump_emit_enum64_val() argument
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()
1030 btf_dump_printf(d, fmt_str, in btf_dump_emit_enum64_val()
1036 btf_dump_printf(d, fmt_str, in btf_dump_emit_enum64_val()
1042 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_def() argument
1048 btf_dump_printf(d, "enum%s%s", in btf_dump_emit_enum_def()
1050 btf_dump_type_name(d, id)); in btf_dump_emit_enum_def()
1055 btf_dump_printf(d, " {"); in btf_dump_emit_enum_def()
1057 btf_dump_emit_enum32_val(d, t, lvl, vlen); in btf_dump_emit_enum_def()
1059 btf_dump_emit_enum64_val(d, t, lvl, vlen); in btf_dump_emit_enum_def()
1060 btf_dump_printf(d, "\n%s}", pfx(lvl)); in btf_dump_emit_enum_def()
1063 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id, in btf_dump_emit_fwd_def() argument
1066 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_fwd_def()
1069 btf_dump_printf(d, "union %s", name); in btf_dump_emit_fwd_def()
1071 btf_dump_printf(d, "struct %s", name); in btf_dump_emit_fwd_def()
1074 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id, in btf_dump_emit_typedef_def() argument
1077 const char *name = btf_dump_ident_name(d, id); in btf_dump_emit_typedef_def()
1086 btf_dump_printf(d, "typedef __builtin_va_list __gnuc_va_list"); in btf_dump_emit_typedef_def()
1090 btf_dump_printf(d, "typedef "); in btf_dump_emit_typedef_def()
1091 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1094 static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id) in btf_dump_push_decl_stack_id() argument
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()
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()
1154 int btf_dump__emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump__emit_type_decl() argument
1163 err = btf_dump_resize(d); in btf_dump__emit_type_decl()
1169 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1170 btf_dump_emit_type_decl(d, id, fname, lvl); in btf_dump__emit_type_decl()
1171 d->strip_mods = false; in btf_dump__emit_type_decl()
1175 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump_emit_type_decl() argument
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()
1188 err = btf_dump_push_decl_stack_id(d, id); in btf_dump_emit_type_decl()
1196 d->decl_stack_cnt = stack_start; 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()
1244 btf_dump_emit_type_chain(d, &decl_stack, fname, lvl); in btf_dump_emit_type_decl()
1253 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1256 static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_emit_mods() argument
1263 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1267 btf_dump_printf(d, "volatile "); in btf_dump_emit_mods()
1270 btf_dump_printf(d, "const "); in btf_dump_emit_mods()
1273 btf_dump_printf(d, "restrict "); in btf_dump_emit_mods()
1282 static void btf_dump_drop_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_drop_mods() argument
1289 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1296 static void btf_dump_emit_name(const struct btf_dump *d, in btf_dump_emit_name() argument
1301 btf_dump_printf(d, "%s%s", separate ? " " : "", name); in btf_dump_emit_name()
1304 static void btf_dump_emit_type_chain(struct btf_dump *d, in btf_dump_emit_type_chain() argument
1327 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1328 btf_dump_printf(d, "void"); in btf_dump_emit_type_chain()
1333 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1339 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1340 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1341 btf_dump_printf(d, "%s", name); in btf_dump_emit_type_chain()
1345 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1347 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1348 btf_dump_emit_struct_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1350 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type_chain()
1354 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1356 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1357 btf_dump_emit_enum_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1359 btf_dump_emit_enum_fwd(d, id, t); in btf_dump_emit_type_chain()
1362 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1363 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type_chain()
1366 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1367 btf_dump_printf(d, "%s", btf_dump_ident_name(d, id)); in btf_dump_emit_type_chain()
1370 btf_dump_printf(d, "%s", last_was_ptr ? "*" : " *"); in btf_dump_emit_type_chain()
1373 btf_dump_printf(d, " volatile"); in btf_dump_emit_type_chain()
1376 btf_dump_printf(d, " const"); in btf_dump_emit_type_chain()
1379 btf_dump_printf(d, " restrict"); in btf_dump_emit_type_chain()
1382 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1383 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1384 btf_dump_printf(d, " __attribute__((btf_type_tag(\"%s\")))", name); in btf_dump_emit_type_chain()
1401 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1404 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1405 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1410 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1414 btf_dump_printf(d, " "); in btf_dump_emit_type_chain()
1417 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1418 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1420 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1421 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1437 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1439 btf_dump_printf(d, " ("); in btf_dump_emit_type_chain()
1440 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1441 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1443 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1445 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1453 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1459 btf_dump_printf(d, ", "); in btf_dump_emit_type_chain()
1463 btf_dump_printf(d, "..."); 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()
1471 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1483 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1487 static void btf_dump_emit_type_cast(struct btf_dump *d, __u32 id, in btf_dump_emit_type_cast() argument
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()
1507 btf_dump_printf(d, "("); 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()
1511 btf_dump_emit_type_decl(d, id, "", 0); 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()
1516 btf_dump_printf(d, ")"); in btf_dump_emit_type_cast()
1520 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map, in btf_dump_name_dups() argument
1532 static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id, in btf_dump_resolve_name() argument
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()
1552 dup_cnt = btf_dump_name_dups(d, name_map, orig_name); in btf_dump_resolve_name()
1565 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id) in btf_dump_type_name() argument
1567 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1570 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id) in btf_dump_ident_name() argument
1572 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1575 static int btf_dump_dump_type_data(struct btf_dump *d,
1583 static const char *btf_dump_data_newline(struct btf_dump *d) in btf_dump_data_newline() argument
1585 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1588 static const char *btf_dump_data_delim(struct btf_dump *d) in btf_dump_data_delim() argument
1590 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1593 static void btf_dump_data_pfx(struct btf_dump *d) in btf_dump_data_pfx() argument
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()
1609 #define btf_dump_type_values(d, fmt, ...) \ argument
1610 btf_dump_printf(d, fmt "%s%s", \
1612 btf_dump_data_delim(d), \
1613 btf_dump_data_newline(d))
1615 static int btf_dump_unsupported_data(struct btf_dump *d, in btf_dump_unsupported_data() argument
1619 btf_dump_printf(d, "<unsupported kind:%u>", btf_kind(t)); in btf_dump_unsupported_data()
1623 static int btf_dump_get_bitfield_value(struct btf_dump *d, in btf_dump_get_bitfield_value() argument
1664 static int btf_dump_bitfield_check_zero(struct btf_dump *d, in btf_dump_bitfield_check_zero() argument
1673 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &check_num); in btf_dump_bitfield_check_zero()
1681 static int btf_dump_bitfield_data(struct btf_dump *d, in btf_dump_bitfield_data() argument
1690 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &print_num); in btf_dump_bitfield_data()
1694 btf_dump_type_values(d, "0x%llx", (unsigned long long)print_num); in btf_dump_bitfield_data()
1700 static int btf_dump_base_type_check_zero(struct btf_dump *d, in btf_dump_base_type_check_zero() argument
1712 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1737 static int btf_dump_int_data(struct btf_dump *d, in btf_dump_int_data() argument
1756 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1779 btf_dump_type_values(d, "0x%llx", (unsigned long long)lsi); in btf_dump_int_data()
1781 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1787 btf_dump_type_values(d, "%lld", *(long long *)data); in btf_dump_int_data()
1789 btf_dump_type_values(d, "%llu", *(unsigned long long *)data); in btf_dump_int_data()
1793 btf_dump_type_values(d, "%d", *(__s32 *)data); in btf_dump_int_data()
1795 btf_dump_type_values(d, "%u", *(__u32 *)data); in btf_dump_int_data()
1799 btf_dump_type_values(d, "%d", *(__s16 *)data); in btf_dump_int_data()
1801 btf_dump_type_values(d, "%u", *(__u16 *)data); 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()
1813 btf_dump_type_values(d, "'%c'", *(char *)data); in btf_dump_int_data()
1818 btf_dump_type_values(d, "%d", *(__s8 *)data); in btf_dump_int_data()
1820 btf_dump_type_values(d, "%u", *(__u8 *)data); in btf_dump_int_data()
1831 double d; member
1835 static int btf_dump_float_data(struct btf_dump *d, in btf_dump_float_data() argument
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()
1867 static int btf_dump_var_data(struct btf_dump *d, in btf_dump_var_data() argument
1893 btf_dump_printf(d, "%s", l); in btf_dump_var_data()
1895 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
1896 btf_dump_emit_type_cast(d, type_id, false); in btf_dump_var_data()
1897 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
1898 return btf_dump_dump_type_data(d, NULL, t, type_id, data, 0, 0); in btf_dump_var_data()
1901 static int btf_dump_array_data(struct btf_dump *d, in btf_dump_array_data() argument
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()
1928 d->typed_dump->is_array_char = true; in btf_dump_array_data()
1938 d->typed_dump->depth++; in btf_dump_array_data()
1939 btf_dump_printf(d, "[%s", btf_dump_data_newline(d)); 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()
1947 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
1949 btf_dump_dump_type_data(d, NULL, elem_type, elem_type_id, data, 0, 0); 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()
1953 btf_dump_data_pfx(d); in btf_dump_array_data()
1954 btf_dump_type_values(d, "]"); in btf_dump_array_data()
1959 static int btf_dump_struct_data(struct btf_dump *d, in btf_dump_struct_data() argument
1975 d->typed_dump->depth++; in btf_dump_struct_data()
1976 btf_dump_printf(d, "{%s", btf_dump_data_newline(d)); 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()
1995 btf_dump_data_pfx(d); in btf_dump_struct_data()
1996 btf_dump_type_values(d, "}"); in btf_dump_struct_data()
2005 static int btf_dump_ptr_data(struct btf_dump *d, in btf_dump_ptr_data() argument
2010 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
2011 btf_dump_type_values(d, "%p", *(void **)data); 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()
2017 btf_dump_type_values(d, "0x%x", pt.p); in btf_dump_ptr_data()
2019 btf_dump_type_values(d, "0x%llx", pt.lp); in btf_dump_ptr_data()
2024 static int btf_dump_get_enum_value(struct btf_dump *d, in btf_dump_get_enum_value() argument
2032 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
2036 err = btf_dump_get_bitfield_value(d, t, data, 0, 0, &val); in btf_dump_get_enum_value()
2062 static int btf_dump_enum_data(struct btf_dump *d, in btf_dump_enum_data() argument
2071 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_enum_data()
2082 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2086 btf_dump_type_values(d, is_signed ? "%d" : "%u", value); in btf_dump_enum_data()
2093 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2097 btf_dump_type_values(d, is_signed ? "%lldLL" : "%lluULL", in btf_dump_enum_data()
2103 static int btf_dump_datasec_data(struct btf_dump *d, in btf_dump_datasec_data() argument
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()
2120 btf_dump_printf(d, ";"); in btf_dump_datasec_data()
2126 static int btf_dump_type_data_check_overflow(struct btf_dump *d, in btf_dump_type_data_check_overflow() argument
2132 __s64 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2147 t = skip_mods_and_typedefs(d->btf, id, NULL); 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()
2169 static int btf_dump_type_data_check_zero(struct btf_dump *d, in btf_dump_type_data_check_zero() argument
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()
2200 return btf_dump_bitfield_check_zero(d, t, data, bits_offset, bit_sz); in btf_dump_type_data_check_zero()
2201 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2204 return btf_dump_base_type_check_zero(d, t, id, data); 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()
2226 err = btf_dump_type_data_check_zero(d, elem_type, 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()
2265 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_type_data_check_zero()
2277 static int btf_dump_dump_type_data(struct btf_dump *d, in btf_dump_dump_type_data() argument
2287 size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2290 err = btf_dump_type_data_check_zero(d, t, id, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2299 btf_dump_data_pfx(d); in btf_dump_dump_type_data()
2301 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2303 btf_dump_printf(d, ".%s = ", fname); in btf_dump_dump_type_data()
2304 btf_dump_emit_type_cast(d, id, true); in btf_dump_dump_type_data()
2307 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2315 err = btf_dump_unsupported_data(d, t, id); in btf_dump_dump_type_data()
2319 err = btf_dump_bitfield_data(d, t, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2321 err = btf_dump_int_data(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2324 err = btf_dump_float_data(d, t, id, data); in btf_dump_dump_type_data()
2327 err = btf_dump_ptr_data(d, t, id, data); in btf_dump_dump_type_data()
2330 err = btf_dump_array_data(d, t, id, data); in btf_dump_dump_type_data()
2334 err = btf_dump_struct_data(d, t, id, data); in btf_dump_dump_type_data()
2343 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, in btf_dump_dump_type_data()
2348 err = btf_dump_enum_data(d, t, id, &enum_val); in btf_dump_dump_type_data()
2350 err = btf_dump_enum_data(d, t, id, data); in btf_dump_dump_type_data()
2353 err = btf_dump_var_data(d, t, id, data); in btf_dump_dump_type_data()
2356 err = btf_dump_datasec_data(d, t, id, data); in btf_dump_dump_type_data()
2368 int btf_dump__dump_type_data(struct btf_dump *d, __u32 id, in btf_dump__dump_type_data() argument
2379 t = btf__type_by_id(d->btf, id); 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()
2398 ret = btf_dump_dump_type_data(d, NULL, t, id, data, 0, 0); in btf_dump__dump_type_data()
2400 d->typed_dump = NULL; in btf_dump__dump_type_data()