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()
233 void btf_dump__free(struct btf_dump *d) in btf_dump__free() argument
237 if (IS_ERR_OR_NULL(d)) in btf_dump__free()
240 free(d->type_states); in btf_dump__free()
241 if (d->cached_names) { in btf_dump__free()
243 for (i = 0; i <= d->last_id; i++) { in btf_dump__free()
244 if (d->cached_names[i]) in btf_dump__free()
245 free((void *)d->cached_names[i]); in btf_dump__free()
248 free(d->cached_names); in btf_dump__free()
249 free(d->emit_queue); in btf_dump__free()
250 free(d->decl_stack); in btf_dump__free()
251 btf_dump_free_names(d->type_names); in btf_dump__free()
252 btf_dump_free_names(d->ident_names); in btf_dump__free()
254 free(d); in btf_dump__free()
257 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr);
258 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id);
276 int btf_dump__dump_type(struct btf_dump *d, __u32 id) in btf_dump__dump_type() argument
280 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
283 err = btf_dump_resize(d); in btf_dump__dump_type()
287 d->emit_queue_cnt = 0; in btf_dump__dump_type()
288 err = btf_dump_order_type(d, id, false); in btf_dump__dump_type()
292 for (i = 0; i < d->emit_queue_cnt; i++) in btf_dump__dump_type()
293 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/); in btf_dump__dump_type()
310 static int btf_dump_mark_referenced(struct btf_dump *d) in btf_dump_mark_referenced() argument
312 int i, j, n = btf__type_cnt(d->btf); in btf_dump_mark_referenced()
316 for (i = d->last_id + 1; i < n; i++) { in btf_dump_mark_referenced()
317 t = btf__type_by_id(d->btf, i); in btf_dump_mark_referenced()
337 d->type_states[t->type].referenced = 1; in btf_dump_mark_referenced()
343 d->type_states[a->index_type].referenced = 1; in btf_dump_mark_referenced()
344 d->type_states[a->type].referenced = 1; in btf_dump_mark_referenced()
352 d->type_states[m->type].referenced = 1; in btf_dump_mark_referenced()
359 d->type_states[p->type].referenced = 1; in btf_dump_mark_referenced()
366 d->type_states[v->type].referenced = 1; in btf_dump_mark_referenced()
376 static int btf_dump_add_emit_queue_id(struct btf_dump *d, __u32 id) in btf_dump_add_emit_queue_id() argument
381 if (d->emit_queue_cnt >= d->emit_queue_cap) { in btf_dump_add_emit_queue_id()
382 new_cap = max(16, d->emit_queue_cap * 3 / 2); in btf_dump_add_emit_queue_id()
383 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0])); in btf_dump_add_emit_queue_id()
386 d->emit_queue = new_queue; in btf_dump_add_emit_queue_id()
387 d->emit_queue_cap = new_cap; in btf_dump_add_emit_queue_id()
390 d->emit_queue[d->emit_queue_cnt++] = id; in btf_dump_add_emit_queue_id()
468 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) in btf_dump_order_type() argument
481 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
490 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
507 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
512 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
529 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
535 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
552 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
562 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
571 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
575 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
582 return btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
588 err = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
595 err = btf_dump_order_type(d, p->type, through_ptr); in btf_dump_order_type()
607 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
615 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
618 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
620 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
623 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
625 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
628 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
631 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
640 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
642 static void btf_dump_emit_type_chain(struct btf_dump *d,
646 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id);
647 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id);
648 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
651 static bool btf_dump_is_blacklisted(struct btf_dump *d, __u32 id) in btf_dump_is_blacklisted() argument
653 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
663 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
684 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) in btf_dump_emit_type() argument
686 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
694 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
715 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
716 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
725 if (!btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
726 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
727 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
741 btf_dump_emit_missing_aliases(d, id, t); in btf_dump_emit_type()
748 btf_dump_emit_enum_def(d, id, t, 0); in btf_dump_emit_type()
749 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
758 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
761 btf_dump_emit_type(d, btf_array(t)->type, cont_id); in btf_dump_emit_type()
764 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type()
765 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
770 btf_dump_emit_type(d, t->type, id); in btf_dump_emit_type()
778 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
779 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
780 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
801 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
803 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
804 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
809 btf_dump_emit_struct_def(d, id, t, 0); in btf_dump_emit_type()
810 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
821 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
823 btf_dump_emit_type(d, p->type, cont_id); in btf_dump_emit_type()
866 static void btf_dump_emit_bit_padding(const struct btf_dump *d, in btf_dump_emit_bit_padding() argument
871 int ptr_bits = d->ptr_sz * 8; in btf_dump_emit_bit_padding()
897 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits); in btf_dump_emit_bit_padding()
902 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_struct_fwd() argument
905 btf_dump_printf(d, "%s%s%s", in btf_dump_emit_struct_fwd()
908 btf_dump_type_name(d, id)); in btf_dump_emit_struct_fwd()
911 static void btf_dump_emit_struct_def(struct btf_dump *d, in btf_dump_emit_struct_def() argument
921 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
923 btf_dump_printf(d, "%s%s%s {", in btf_dump_emit_struct_def()
926 btf_dump_type_name(d, id)); in btf_dump_emit_struct_def()
932 fname = btf_name_of(d, m->name_off); in btf_dump_emit_struct_def()
935 align = packed ? 1 : btf__align_of(d->btf, m->type); in btf_dump_emit_struct_def()
937 btf_dump_emit_bit_padding(d, off, m_off, m_sz, align, lvl + 1); in btf_dump_emit_struct_def()
938 btf_dump_printf(d, "\n%s", pfx(lvl + 1)); in btf_dump_emit_struct_def()
939 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
942 btf_dump_printf(d, ": %d", m_sz); in btf_dump_emit_struct_def()
945 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type)); in btf_dump_emit_struct_def()
948 btf_dump_printf(d, ";"); in btf_dump_emit_struct_def()
953 align = packed ? 1 : btf__align_of(d->btf, id); in btf_dump_emit_struct_def()
954 btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align, in btf_dump_emit_struct_def()
959 btf_dump_printf(d, "\n"); in btf_dump_emit_struct_def()
960 btf_dump_printf(d, "%s}", pfx(lvl)); in btf_dump_emit_struct_def()
962 btf_dump_printf(d, " __attribute__((packed))"); in btf_dump_emit_struct_def()
976 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id, in btf_dump_emit_missing_aliases() argument
979 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_missing_aliases()
984 btf_dump_printf(d, "typedef %s %s;\n\n", in btf_dump_emit_missing_aliases()
991 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_fwd() argument
994 btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id)); in btf_dump_emit_enum_fwd()
997 static void btf_dump_emit_enum32_val(struct btf_dump *d, in btf_dump_emit_enum32_val() argument
1009 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum32_val()
1011 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum32_val()
1014 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val); in btf_dump_emit_enum32_val()
1017 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val); in btf_dump_emit_enum32_val()
1022 static void btf_dump_emit_enum64_val(struct btf_dump *d, in btf_dump_emit_enum64_val() argument
1035 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum64_val()
1036 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum64_val()
1041 btf_dump_printf(d, fmt_str, in btf_dump_emit_enum64_val()
1047 btf_dump_printf(d, fmt_str, in btf_dump_emit_enum64_val()
1053 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_def() argument
1059 btf_dump_printf(d, "enum%s%s", in btf_dump_emit_enum_def()
1061 btf_dump_type_name(d, id)); in btf_dump_emit_enum_def()
1066 btf_dump_printf(d, " {"); in btf_dump_emit_enum_def()
1068 btf_dump_emit_enum32_val(d, t, lvl, vlen); in btf_dump_emit_enum_def()
1070 btf_dump_emit_enum64_val(d, t, lvl, vlen); in btf_dump_emit_enum_def()
1071 btf_dump_printf(d, "\n%s}", pfx(lvl)); in btf_dump_emit_enum_def()
1074 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id, in btf_dump_emit_fwd_def() argument
1077 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_fwd_def()
1080 btf_dump_printf(d, "union %s", name); in btf_dump_emit_fwd_def()
1082 btf_dump_printf(d, "struct %s", name); in btf_dump_emit_fwd_def()
1085 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id, in btf_dump_emit_typedef_def() argument
1088 const char *name = btf_dump_ident_name(d, id); in btf_dump_emit_typedef_def()
1097 btf_dump_printf(d, "typedef __builtin_va_list __gnuc_va_list"); in btf_dump_emit_typedef_def()
1101 btf_dump_printf(d, "typedef "); in btf_dump_emit_typedef_def()
1102 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1105 static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id) in btf_dump_push_decl_stack_id() argument
1110 if (d->decl_stack_cnt >= d->decl_stack_cap) { in btf_dump_push_decl_stack_id()
1111 new_cap = max(16, d->decl_stack_cap * 3 / 2); in btf_dump_push_decl_stack_id()
1112 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0])); in btf_dump_push_decl_stack_id()
1115 d->decl_stack = new_stack; in btf_dump_push_decl_stack_id()
1116 d->decl_stack_cap = new_cap; in btf_dump_push_decl_stack_id()
1119 d->decl_stack[d->decl_stack_cnt++] = id; in btf_dump_push_decl_stack_id()
1165 int btf_dump__emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump__emit_type_decl() argument
1174 err = btf_dump_resize(d); in btf_dump__emit_type_decl()
1180 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1181 btf_dump_emit_type_decl(d, id, fname, lvl); in btf_dump__emit_type_decl()
1182 d->strip_mods = false; in btf_dump__emit_type_decl()
1186 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump_emit_type_decl() argument
1193 stack_start = d->decl_stack_cnt; in btf_dump_emit_type_decl()
1195 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_decl()
1196 if (d->strip_mods && btf_is_mod(t)) in btf_dump_emit_type_decl()
1199 err = btf_dump_push_decl_stack_id(d, id); in btf_dump_emit_type_decl()
1207 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1253 decl_stack.ids = d->decl_stack + stack_start; in btf_dump_emit_type_decl()
1254 decl_stack.cnt = d->decl_stack_cnt - stack_start; in btf_dump_emit_type_decl()
1255 btf_dump_emit_type_chain(d, &decl_stack, fname, lvl); in btf_dump_emit_type_decl()
1264 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1267 static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_emit_mods() argument
1274 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1278 btf_dump_printf(d, "volatile "); in btf_dump_emit_mods()
1281 btf_dump_printf(d, "const "); in btf_dump_emit_mods()
1284 btf_dump_printf(d, "restrict "); in btf_dump_emit_mods()
1293 static void btf_dump_drop_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_drop_mods() argument
1300 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1307 static void btf_dump_emit_name(const struct btf_dump *d, in btf_dump_emit_name() argument
1312 btf_dump_printf(d, "%s%s", separate ? " " : "", name); in btf_dump_emit_name()
1315 static void btf_dump_emit_type_chain(struct btf_dump *d, in btf_dump_emit_type_chain() argument
1338 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1339 btf_dump_printf(d, "void"); in btf_dump_emit_type_chain()
1344 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1350 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1351 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1352 btf_dump_printf(d, "%s", name); in btf_dump_emit_type_chain()
1356 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1358 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1359 btf_dump_emit_struct_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1361 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type_chain()
1365 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1367 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1368 btf_dump_emit_enum_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1370 btf_dump_emit_enum_fwd(d, id, t); in btf_dump_emit_type_chain()
1373 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1374 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type_chain()
1377 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1378 btf_dump_printf(d, "%s", btf_dump_ident_name(d, id)); in btf_dump_emit_type_chain()
1381 btf_dump_printf(d, "%s", last_was_ptr ? "*" : " *"); in btf_dump_emit_type_chain()
1384 btf_dump_printf(d, " volatile"); in btf_dump_emit_type_chain()
1387 btf_dump_printf(d, " const"); in btf_dump_emit_type_chain()
1390 btf_dump_printf(d, " restrict"); in btf_dump_emit_type_chain()
1393 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1394 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1395 btf_dump_printf(d, " __attribute__((btf_type_tag(\"%s\")))", name); in btf_dump_emit_type_chain()
1412 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1415 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1416 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1421 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1425 btf_dump_printf(d, " "); in btf_dump_emit_type_chain()
1428 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1429 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1431 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1432 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1448 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1450 btf_dump_printf(d, " ("); in btf_dump_emit_type_chain()
1451 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1452 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1454 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1456 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1464 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1470 btf_dump_printf(d, ", "); in btf_dump_emit_type_chain()
1474 btf_dump_printf(d, "..."); in btf_dump_emit_type_chain()
1478 name = btf_name_of(d, p->name_off); in btf_dump_emit_type_chain()
1479 btf_dump_emit_type_decl(d, p->type, name, lvl); in btf_dump_emit_type_chain()
1482 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1494 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1498 static void btf_dump_emit_type_cast(struct btf_dump *d, __u32 id, in btf_dump_emit_type_cast() argument
1507 if (d->typed_dump->is_array_member) in btf_dump_emit_type_cast()
1513 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_cast()
1518 btf_dump_printf(d, "("); in btf_dump_emit_type_cast()
1520 d->skip_anon_defs = true; in btf_dump_emit_type_cast()
1521 d->strip_mods = true; in btf_dump_emit_type_cast()
1522 btf_dump_emit_type_decl(d, id, "", 0); in btf_dump_emit_type_cast()
1523 d->strip_mods = false; in btf_dump_emit_type_cast()
1524 d->skip_anon_defs = false; in btf_dump_emit_type_cast()
1527 btf_dump_printf(d, ")"); in btf_dump_emit_type_cast()
1531 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map, in btf_dump_name_dups() argument
1555 static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id, in btf_dump_resolve_name() argument
1558 struct btf_dump_type_aux_state *s = &d->type_states[id]; in btf_dump_resolve_name()
1559 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_resolve_name()
1560 const char *orig_name = btf_name_of(d, t->name_off); in btf_dump_resolve_name()
1561 const char **cached_name = &d->cached_names[id]; in btf_dump_resolve_name()
1575 dup_cnt = btf_dump_name_dups(d, name_map, orig_name); in btf_dump_resolve_name()
1588 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id) in btf_dump_type_name() argument
1590 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1593 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id) in btf_dump_ident_name() argument
1595 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1598 static int btf_dump_dump_type_data(struct btf_dump *d,
1606 static const char *btf_dump_data_newline(struct btf_dump *d) in btf_dump_data_newline() argument
1608 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1611 static const char *btf_dump_data_delim(struct btf_dump *d) in btf_dump_data_delim() argument
1613 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1616 static void btf_dump_data_pfx(struct btf_dump *d) in btf_dump_data_pfx() argument
1618 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth; in btf_dump_data_pfx()
1620 if (d->typed_dump->compact) in btf_dump_data_pfx()
1624 btf_dump_printf(d, "%s", d->typed_dump->indent_str); in btf_dump_data_pfx()
1632 #define btf_dump_type_values(d, fmt, ...) \ argument
1633 btf_dump_printf(d, fmt "%s%s", \
1635 btf_dump_data_delim(d), \
1636 btf_dump_data_newline(d))
1638 static int btf_dump_unsupported_data(struct btf_dump *d, in btf_dump_unsupported_data() argument
1642 btf_dump_printf(d, "<unsupported kind:%u>", btf_kind(t)); in btf_dump_unsupported_data()
1646 static int btf_dump_get_bitfield_value(struct btf_dump *d, in btf_dump_get_bitfield_value() argument
1687 static int btf_dump_bitfield_check_zero(struct btf_dump *d, in btf_dump_bitfield_check_zero() argument
1696 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &check_num); in btf_dump_bitfield_check_zero()
1704 static int btf_dump_bitfield_data(struct btf_dump *d, in btf_dump_bitfield_data() argument
1713 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &print_num); in btf_dump_bitfield_data()
1717 btf_dump_type_values(d, "0x%llx", (unsigned long long)print_num); in btf_dump_bitfield_data()
1723 static int btf_dump_base_type_check_zero(struct btf_dump *d, in btf_dump_base_type_check_zero() argument
1735 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1760 static int btf_dump_int_data(struct btf_dump *d, in btf_dump_int_data() argument
1779 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1802 btf_dump_type_values(d, "0x%llx", (unsigned long long)lsi); in btf_dump_int_data()
1804 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1810 btf_dump_type_values(d, "%lld", *(long long *)data); in btf_dump_int_data()
1812 btf_dump_type_values(d, "%llu", *(unsigned long long *)data); in btf_dump_int_data()
1816 btf_dump_type_values(d, "%d", *(__s32 *)data); in btf_dump_int_data()
1818 btf_dump_type_values(d, "%u", *(__u32 *)data); in btf_dump_int_data()
1822 btf_dump_type_values(d, "%d", *(__s16 *)data); in btf_dump_int_data()
1824 btf_dump_type_values(d, "%u", *(__u16 *)data); in btf_dump_int_data()
1827 if (d->typed_dump->is_array_char) { in btf_dump_int_data()
1829 if (d->typed_dump->is_array_terminated) in btf_dump_int_data()
1832 d->typed_dump->is_array_terminated = true; in btf_dump_int_data()
1836 btf_dump_type_values(d, "'%c'", *(char *)data); in btf_dump_int_data()
1841 btf_dump_type_values(d, "%d", *(__s8 *)data); in btf_dump_int_data()
1843 btf_dump_type_values(d, "%u", *(__u8 *)data); in btf_dump_int_data()
1854 double d; member
1858 static int btf_dump_float_data(struct btf_dump *d, in btf_dump_float_data() argument
1868 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_float_data()
1875 btf_dump_type_values(d, "%Lf", flp->ld); in btf_dump_float_data()
1878 btf_dump_type_values(d, "%lf", flp->d); in btf_dump_float_data()
1881 btf_dump_type_values(d, "%f", flp->f); in btf_dump_float_data()
1890 static int btf_dump_var_data(struct btf_dump *d, in btf_dump_var_data() argument
1916 btf_dump_printf(d, "%s", l); in btf_dump_var_data()
1918 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
1919 btf_dump_emit_type_cast(d, type_id, false); in btf_dump_var_data()
1920 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
1921 return btf_dump_dump_type_data(d, NULL, t, type_id, data, 0, 0); in btf_dump_var_data()
1924 static int btf_dump_array_data(struct btf_dump *d, in btf_dump_array_data() argument
1936 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_array_data()
1937 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_array_data()
1951 d->typed_dump->is_array_char = true; in btf_dump_array_data()
1961 d->typed_dump->depth++; in btf_dump_array_data()
1962 btf_dump_printf(d, "[%s", btf_dump_data_newline(d)); in btf_dump_array_data()
1967 is_array_member = d->typed_dump->is_array_member; in btf_dump_array_data()
1968 d->typed_dump->is_array_member = true; in btf_dump_array_data()
1970 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
1972 btf_dump_dump_type_data(d, NULL, elem_type, elem_type_id, data, 0, 0); in btf_dump_array_data()
1974 d->typed_dump->is_array_member = is_array_member; in btf_dump_array_data()
1975 d->typed_dump->depth--; in btf_dump_array_data()
1976 btf_dump_data_pfx(d); in btf_dump_array_data()
1977 btf_dump_type_values(d, "]"); in btf_dump_array_data()
1982 static int btf_dump_struct_data(struct btf_dump *d, in btf_dump_struct_data() argument
1998 d->typed_dump->depth++; in btf_dump_struct_data()
1999 btf_dump_printf(d, "{%s", btf_dump_data_newline(d)); in btf_dump_struct_data()
2007 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_struct_data()
2008 mname = btf_name_of(d, m->name_off); in btf_dump_struct_data()
2012 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8, in btf_dump_struct_data()
2017 d->typed_dump->depth--; in btf_dump_struct_data()
2018 btf_dump_data_pfx(d); in btf_dump_struct_data()
2019 btf_dump_type_values(d, "}"); in btf_dump_struct_data()
2028 static int btf_dump_ptr_data(struct btf_dump *d, in btf_dump_ptr_data() argument
2033 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
2034 btf_dump_type_values(d, "%p", *(void **)data); in btf_dump_ptr_data()
2038 memcpy(&pt, data, d->ptr_sz); in btf_dump_ptr_data()
2039 if (d->ptr_sz == 4) in btf_dump_ptr_data()
2040 btf_dump_type_values(d, "0x%x", pt.p); in btf_dump_ptr_data()
2042 btf_dump_type_values(d, "0x%llx", pt.lp); in btf_dump_ptr_data()
2047 static int btf_dump_get_enum_value(struct btf_dump *d, in btf_dump_get_enum_value() argument
2055 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
2059 err = btf_dump_get_bitfield_value(d, t, data, 0, 0, &val); in btf_dump_get_enum_value()
2085 static int btf_dump_enum_data(struct btf_dump *d, in btf_dump_enum_data() argument
2094 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_enum_data()
2105 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2109 btf_dump_type_values(d, is_signed ? "%d" : "%u", value); in btf_dump_enum_data()
2116 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2120 btf_dump_type_values(d, is_signed ? "%lldLL" : "%lluULL", in btf_dump_enum_data()
2126 static int btf_dump_datasec_data(struct btf_dump *d, in btf_dump_datasec_data() argument
2136 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off)); in btf_dump_datasec_data()
2139 var = btf__type_by_id(d->btf, vsi->type); in btf_dump_datasec_data()
2140 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0); in btf_dump_datasec_data()
2143 btf_dump_printf(d, ";"); in btf_dump_datasec_data()
2149 static int btf_dump_type_data_check_overflow(struct btf_dump *d, in btf_dump_type_data_check_overflow() argument
2155 __s64 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2170 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_overflow()
2183 if (data + bits_offset / 8 + size > d->typed_dump->data_end) in btf_dump_type_data_check_overflow()
2192 static int btf_dump_type_data_check_zero(struct btf_dump *d, in btf_dump_type_data_check_zero() argument
2213 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 || in btf_dump_type_data_check_zero()
2214 (d->typed_dump->is_array_member && in btf_dump_type_data_check_zero()
2215 !d->typed_dump->is_array_char)) in btf_dump_type_data_check_zero()
2218 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_zero()
2223 return btf_dump_bitfield_check_zero(d, t, data, bits_offset, bit_sz); in btf_dump_type_data_check_zero()
2224 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2227 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2235 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_type_data_check_zero()
2236 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_type_data_check_zero()
2249 err = btf_dump_type_data_check_zero(d, elem_type, in btf_dump_type_data_check_zero()
2271 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_type_data_check_zero()
2279 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8, in btf_dump_type_data_check_zero()
2288 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_type_data_check_zero()
2300 static int btf_dump_dump_type_data(struct btf_dump *d, in btf_dump_dump_type_data() argument
2310 size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2313 err = btf_dump_type_data_check_zero(d, t, id, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2322 btf_dump_data_pfx(d); in btf_dump_dump_type_data()
2324 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2326 btf_dump_printf(d, ".%s = ", fname); in btf_dump_dump_type_data()
2327 btf_dump_emit_type_cast(d, id, true); in btf_dump_dump_type_data()
2330 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2338 err = btf_dump_unsupported_data(d, t, id); in btf_dump_dump_type_data()
2342 err = btf_dump_bitfield_data(d, t, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2344 err = btf_dump_int_data(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2347 err = btf_dump_float_data(d, t, id, data); in btf_dump_dump_type_data()
2350 err = btf_dump_ptr_data(d, t, id, data); in btf_dump_dump_type_data()
2353 err = btf_dump_array_data(d, t, id, data); in btf_dump_dump_type_data()
2357 err = btf_dump_struct_data(d, t, id, data); in btf_dump_dump_type_data()
2366 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, in btf_dump_dump_type_data()
2371 err = btf_dump_enum_data(d, t, id, &enum_val); in btf_dump_dump_type_data()
2373 err = btf_dump_enum_data(d, t, id, data); in btf_dump_dump_type_data()
2376 err = btf_dump_var_data(d, t, id, data); in btf_dump_dump_type_data()
2379 err = btf_dump_datasec_data(d, t, id, data); in btf_dump_dump_type_data()
2391 int btf_dump__dump_type_data(struct btf_dump *d, __u32 id, in btf_dump__dump_type_data() argument
2402 t = btf__type_by_id(d->btf, id); in btf_dump__dump_type_data()
2406 d->typed_dump = &typed_dump; in btf_dump__dump_type_data()
2407 d->typed_dump->data_end = data + data_sz; in btf_dump__dump_type_data()
2408 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); in btf_dump__dump_type_data()
2412 d->typed_dump->indent_str[0] = '\t'; in btf_dump__dump_type_data()
2414 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str, in btf_dump__dump_type_data()
2415 sizeof(d->typed_dump->indent_str)); in btf_dump__dump_type_data()
2417 d->typed_dump->compact = OPTS_GET(opts, compact, false); in btf_dump__dump_type_data()
2418 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false); in btf_dump__dump_type_data()
2419 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false); in btf_dump__dump_type_data()
2421 ret = btf_dump_dump_type_data(d, NULL, t, id, data, 0, 0); in btf_dump__dump_type_data()
2423 d->typed_dump = NULL; in btf_dump__dump_type_data()