Lines Matching refs:d
131 static const char *btf_name_of(const struct btf_dump *d, __u32 name_off) in btf_name_of() argument
133 return btf__name_by_offset(d->btf, name_off); in btf_name_of()
136 static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...) in btf_dump_printf() argument
141 d->printf_fn(d->cb_ctx, fmt, args); in btf_dump_printf()
145 static int btf_dump_mark_referenced(struct btf_dump *d);
146 static int btf_dump_resize(struct btf_dump *d);
153 struct btf_dump *d; in btf_dump__new() local
162 d = calloc(1, sizeof(struct btf_dump)); in btf_dump__new()
163 if (!d) in btf_dump__new()
166 d->btf = btf; in btf_dump__new()
167 d->printf_fn = printf_fn; in btf_dump__new()
168 d->cb_ctx = ctx; in btf_dump__new()
169 d->ptr_sz = btf__pointer_size(btf) ? : sizeof(void *); in btf_dump__new()
171 d->type_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
172 if (IS_ERR(d->type_names)) { in btf_dump__new()
173 err = PTR_ERR(d->type_names); in btf_dump__new()
174 d->type_names = NULL; in btf_dump__new()
177 d->ident_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
178 if (IS_ERR(d->ident_names)) { in btf_dump__new()
179 err = PTR_ERR(d->ident_names); in btf_dump__new()
180 d->ident_names = NULL; in btf_dump__new()
184 err = btf_dump_resize(d); in btf_dump__new()
188 return d; in btf_dump__new()
190 btf_dump__free(d); in btf_dump__new()
194 static int btf_dump_resize(struct btf_dump *d) in btf_dump_resize() argument
196 int err, last_id = btf__type_cnt(d->btf) - 1; in btf_dump_resize()
198 if (last_id <= d->last_id) in btf_dump_resize()
201 if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap, in btf_dump_resize()
202 sizeof(*d->type_states), last_id + 1)) in btf_dump_resize()
204 if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap, in btf_dump_resize()
205 sizeof(*d->cached_names), last_id + 1)) in btf_dump_resize()
208 if (d->last_id == 0) { in btf_dump_resize()
210 d->type_states[0].order_state = ORDERED; in btf_dump_resize()
211 d->type_states[0].emit_state = EMITTED; in btf_dump_resize()
215 err = btf_dump_mark_referenced(d); in btf_dump_resize()
219 d->last_id = last_id; in btf_dump_resize()
234 void btf_dump__free(struct btf_dump *d) in btf_dump__free() argument
238 if (IS_ERR_OR_NULL(d)) in btf_dump__free()
241 free(d->type_states); in btf_dump__free()
242 if (d->cached_names) { in btf_dump__free()
244 for (i = 0; i <= d->last_id; i++) { in btf_dump__free()
245 if (d->cached_names[i]) in btf_dump__free()
246 free((void *)d->cached_names[i]); in btf_dump__free()
249 free(d->cached_names); in btf_dump__free()
250 free(d->emit_queue); in btf_dump__free()
251 free(d->decl_stack); in btf_dump__free()
252 btf_dump_free_names(d->type_names); in btf_dump__free()
253 btf_dump_free_names(d->ident_names); in btf_dump__free()
255 free(d); in btf_dump__free()
258 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr);
259 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id);
277 int btf_dump__dump_type(struct btf_dump *d, __u32 id) in btf_dump__dump_type() argument
281 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
284 err = btf_dump_resize(d); in btf_dump__dump_type()
288 d->emit_queue_cnt = 0; in btf_dump__dump_type()
289 err = btf_dump_order_type(d, id, false); in btf_dump__dump_type()
293 for (i = 0; i < d->emit_queue_cnt; i++) in btf_dump__dump_type()
294 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/); in btf_dump__dump_type()
311 static int btf_dump_mark_referenced(struct btf_dump *d) in btf_dump_mark_referenced() argument
313 int i, j, n = btf__type_cnt(d->btf); in btf_dump_mark_referenced()
317 for (i = d->last_id + 1; i < n; i++) { in btf_dump_mark_referenced()
318 t = btf__type_by_id(d->btf, i); in btf_dump_mark_referenced()
338 d->type_states[t->type].referenced = 1; in btf_dump_mark_referenced()
344 d->type_states[a->index_type].referenced = 1; in btf_dump_mark_referenced()
345 d->type_states[a->type].referenced = 1; in btf_dump_mark_referenced()
353 d->type_states[m->type].referenced = 1; in btf_dump_mark_referenced()
360 d->type_states[p->type].referenced = 1; in btf_dump_mark_referenced()
367 d->type_states[v->type].referenced = 1; in btf_dump_mark_referenced()
377 static int btf_dump_add_emit_queue_id(struct btf_dump *d, __u32 id) in btf_dump_add_emit_queue_id() argument
382 if (d->emit_queue_cnt >= d->emit_queue_cap) { in btf_dump_add_emit_queue_id()
383 new_cap = max(16, d->emit_queue_cap * 3 / 2); in btf_dump_add_emit_queue_id()
384 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0])); in btf_dump_add_emit_queue_id()
387 d->emit_queue = new_queue; in btf_dump_add_emit_queue_id()
388 d->emit_queue_cap = new_cap; in btf_dump_add_emit_queue_id()
391 d->emit_queue[d->emit_queue_cnt++] = id; in btf_dump_add_emit_queue_id()
469 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) in btf_dump_order_type() argument
482 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
491 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
508 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
513 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
530 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
536 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
553 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
563 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
572 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
576 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
583 return btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
589 err = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
596 err = btf_dump_order_type(d, p->type, through_ptr); in btf_dump_order_type()
608 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
616 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
619 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
621 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
624 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
626 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
629 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
632 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
641 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
643 static void btf_dump_emit_type_chain(struct btf_dump *d,
647 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id);
648 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id);
649 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
652 static bool btf_dump_is_blacklisted(struct btf_dump *d, __u32 id) in btf_dump_is_blacklisted() argument
654 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
664 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
685 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) in btf_dump_emit_type() argument
687 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
695 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
716 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
717 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
726 if (!btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
727 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
728 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
742 btf_dump_emit_missing_aliases(d, id, t); in btf_dump_emit_type()
749 btf_dump_emit_enum_def(d, id, t, 0); in btf_dump_emit_type()
750 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
759 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
762 btf_dump_emit_type(d, btf_array(t)->type, cont_id); in btf_dump_emit_type()
765 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type()
766 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
771 btf_dump_emit_type(d, t->type, id); in btf_dump_emit_type()
779 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
780 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
781 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
802 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
804 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
805 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
810 btf_dump_emit_struct_def(d, id, t, 0); in btf_dump_emit_type()
811 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
822 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
824 btf_dump_emit_type(d, p->type, cont_id); in btf_dump_emit_type()
860 static void btf_dump_emit_bit_padding(const struct btf_dump *d, in btf_dump_emit_bit_padding() argument
868 {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} in btf_dump_emit_bit_padding()
917 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, in btf_dump_emit_bit_padding()
931 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits); in btf_dump_emit_bit_padding()
947 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, bits); in btf_dump_emit_bit_padding()
954 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_struct_fwd() argument
957 btf_dump_printf(d, "%s%s%s", in btf_dump_emit_struct_fwd()
960 btf_dump_type_name(d, id)); in btf_dump_emit_struct_fwd()
963 static void btf_dump_emit_struct_def(struct btf_dump *d, in btf_dump_emit_struct_def() argument
974 align = btf__align_of(d->btf, id); in btf_dump_emit_struct_def()
975 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
977 btf_dump_printf(d, "%s%s%s {", in btf_dump_emit_struct_def()
980 btf_dump_type_name(d, id)); in btf_dump_emit_struct_def()
987 fname = btf_name_of(d, m->name_off); in btf_dump_emit_struct_def()
990 m_align = packed ? 1 : btf__align_of(d->btf, m->type); in btf_dump_emit_struct_def()
994 btf_dump_emit_bit_padding(d, off, m_off, m_align, in_bitfield, lvl + 1); in btf_dump_emit_struct_def()
995 btf_dump_printf(d, "\n%s", pfx(lvl + 1)); in btf_dump_emit_struct_def()
996 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
999 btf_dump_printf(d, ": %d", m_sz); in btf_dump_emit_struct_def()
1003 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type)); in btf_dump_emit_struct_def()
1008 btf_dump_printf(d, ";"); in btf_dump_emit_struct_def()
1013 btf_dump_emit_bit_padding(d, off, t->size * 8, align, false, lvl + 1); in btf_dump_emit_struct_def()
1020 btf_dump_printf(d, "\n"); in btf_dump_emit_struct_def()
1021 btf_dump_printf(d, "%s}", pfx(lvl)); in btf_dump_emit_struct_def()
1023 btf_dump_printf(d, "}"); in btf_dump_emit_struct_def()
1026 btf_dump_printf(d, " __attribute__((packed))"); in btf_dump_emit_struct_def()
1040 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id, in btf_dump_emit_missing_aliases() argument
1043 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_missing_aliases()
1048 btf_dump_printf(d, "typedef %s %s;\n\n", in btf_dump_emit_missing_aliases()
1055 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_fwd() argument
1058 btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id)); in btf_dump_emit_enum_fwd()
1061 static void btf_dump_emit_enum32_val(struct btf_dump *d, in btf_dump_emit_enum32_val() argument
1073 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum32_val()
1075 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum32_val()
1078 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val); in btf_dump_emit_enum32_val()
1081 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val); in btf_dump_emit_enum32_val()
1086 static void btf_dump_emit_enum64_val(struct btf_dump *d, in btf_dump_emit_enum64_val() argument
1099 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum64_val()
1100 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum64_val()
1105 btf_dump_printf(d, fmt_str, in btf_dump_emit_enum64_val()
1111 btf_dump_printf(d, fmt_str, in btf_dump_emit_enum64_val()
1117 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_def() argument
1123 btf_dump_printf(d, "enum%s%s", in btf_dump_emit_enum_def()
1125 btf_dump_type_name(d, id)); in btf_dump_emit_enum_def()
1130 btf_dump_printf(d, " {"); in btf_dump_emit_enum_def()
1132 btf_dump_emit_enum32_val(d, t, lvl, vlen); in btf_dump_emit_enum_def()
1134 btf_dump_emit_enum64_val(d, t, lvl, vlen); in btf_dump_emit_enum_def()
1135 btf_dump_printf(d, "\n%s}", pfx(lvl)); in btf_dump_emit_enum_def()
1140 btf_dump_printf(d, " __attribute__((mode(byte)))"); in btf_dump_emit_enum_def()
1141 } else if (t->size == 8 && d->ptr_sz == 8) { in btf_dump_emit_enum_def()
1170 btf_dump_printf(d, " __attribute__((mode(word)))"); in btf_dump_emit_enum_def()
1175 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id, in btf_dump_emit_fwd_def() argument
1178 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_fwd_def()
1181 btf_dump_printf(d, "union %s", name); in btf_dump_emit_fwd_def()
1183 btf_dump_printf(d, "struct %s", name); in btf_dump_emit_fwd_def()
1186 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id, in btf_dump_emit_typedef_def() argument
1189 const char *name = btf_dump_ident_name(d, id); in btf_dump_emit_typedef_def()
1198 btf_dump_printf(d, "typedef __builtin_va_list __gnuc_va_list"); in btf_dump_emit_typedef_def()
1202 btf_dump_printf(d, "typedef "); in btf_dump_emit_typedef_def()
1203 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1206 static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id) in btf_dump_push_decl_stack_id() argument
1211 if (d->decl_stack_cnt >= d->decl_stack_cap) { in btf_dump_push_decl_stack_id()
1212 new_cap = max(16, d->decl_stack_cap * 3 / 2); in btf_dump_push_decl_stack_id()
1213 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0])); in btf_dump_push_decl_stack_id()
1216 d->decl_stack = new_stack; in btf_dump_push_decl_stack_id()
1217 d->decl_stack_cap = new_cap; in btf_dump_push_decl_stack_id()
1220 d->decl_stack[d->decl_stack_cnt++] = id; in btf_dump_push_decl_stack_id()
1266 int btf_dump__emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump__emit_type_decl() argument
1275 err = btf_dump_resize(d); in btf_dump__emit_type_decl()
1281 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1282 btf_dump_emit_type_decl(d, id, fname, lvl); in btf_dump__emit_type_decl()
1283 d->strip_mods = false; in btf_dump__emit_type_decl()
1287 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump_emit_type_decl() argument
1294 stack_start = d->decl_stack_cnt; in btf_dump_emit_type_decl()
1296 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_decl()
1297 if (d->strip_mods && btf_is_mod(t)) in btf_dump_emit_type_decl()
1300 err = btf_dump_push_decl_stack_id(d, id); in btf_dump_emit_type_decl()
1308 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1354 decl_stack.ids = d->decl_stack + stack_start; in btf_dump_emit_type_decl()
1355 decl_stack.cnt = d->decl_stack_cnt - stack_start; in btf_dump_emit_type_decl()
1356 btf_dump_emit_type_chain(d, &decl_stack, fname, lvl); in btf_dump_emit_type_decl()
1365 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1368 static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_emit_mods() argument
1375 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1379 btf_dump_printf(d, "volatile "); in btf_dump_emit_mods()
1382 btf_dump_printf(d, "const "); in btf_dump_emit_mods()
1385 btf_dump_printf(d, "restrict "); in btf_dump_emit_mods()
1394 static void btf_dump_drop_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_drop_mods() argument
1401 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1408 static void btf_dump_emit_name(const struct btf_dump *d, in btf_dump_emit_name() argument
1413 btf_dump_printf(d, "%s%s", separate ? " " : "", name); in btf_dump_emit_name()
1416 static void btf_dump_emit_type_chain(struct btf_dump *d, in btf_dump_emit_type_chain() argument
1439 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1440 btf_dump_printf(d, "void"); in btf_dump_emit_type_chain()
1445 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1451 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1452 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1453 btf_dump_printf(d, "%s", name); in btf_dump_emit_type_chain()
1457 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1459 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1460 btf_dump_emit_struct_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1462 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type_chain()
1466 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1468 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1469 btf_dump_emit_enum_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1471 btf_dump_emit_enum_fwd(d, id, t); in btf_dump_emit_type_chain()
1474 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1475 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type_chain()
1478 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1479 btf_dump_printf(d, "%s", btf_dump_ident_name(d, id)); in btf_dump_emit_type_chain()
1482 btf_dump_printf(d, "%s", last_was_ptr ? "*" : " *"); in btf_dump_emit_type_chain()
1485 btf_dump_printf(d, " volatile"); in btf_dump_emit_type_chain()
1488 btf_dump_printf(d, " const"); in btf_dump_emit_type_chain()
1491 btf_dump_printf(d, " restrict"); in btf_dump_emit_type_chain()
1494 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1495 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1496 btf_dump_printf(d, " __attribute__((btf_type_tag(\"%s\")))", name); in btf_dump_emit_type_chain()
1513 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1516 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1517 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1522 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1526 btf_dump_printf(d, " "); in btf_dump_emit_type_chain()
1529 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1530 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1532 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1533 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1549 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1551 btf_dump_printf(d, " ("); in btf_dump_emit_type_chain()
1552 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1553 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1555 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1557 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1565 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1571 btf_dump_printf(d, ", "); in btf_dump_emit_type_chain()
1575 btf_dump_printf(d, "..."); in btf_dump_emit_type_chain()
1579 name = btf_name_of(d, p->name_off); in btf_dump_emit_type_chain()
1580 btf_dump_emit_type_decl(d, p->type, name, lvl); in btf_dump_emit_type_chain()
1583 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1595 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1599 static void btf_dump_emit_type_cast(struct btf_dump *d, __u32 id, in btf_dump_emit_type_cast() argument
1608 if (d->typed_dump->is_array_member) in btf_dump_emit_type_cast()
1614 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_cast()
1619 btf_dump_printf(d, "("); in btf_dump_emit_type_cast()
1621 d->skip_anon_defs = true; in btf_dump_emit_type_cast()
1622 d->strip_mods = true; in btf_dump_emit_type_cast()
1623 btf_dump_emit_type_decl(d, id, "", 0); in btf_dump_emit_type_cast()
1624 d->strip_mods = false; in btf_dump_emit_type_cast()
1625 d->skip_anon_defs = false; in btf_dump_emit_type_cast()
1628 btf_dump_printf(d, ")"); in btf_dump_emit_type_cast()
1632 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map, in btf_dump_name_dups() argument
1655 static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id, in btf_dump_resolve_name() argument
1658 struct btf_dump_type_aux_state *s = &d->type_states[id]; in btf_dump_resolve_name()
1659 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_resolve_name()
1660 const char *orig_name = btf_name_of(d, t->name_off); in btf_dump_resolve_name()
1661 const char **cached_name = &d->cached_names[id]; in btf_dump_resolve_name()
1675 dup_cnt = btf_dump_name_dups(d, name_map, orig_name); in btf_dump_resolve_name()
1688 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id) in btf_dump_type_name() argument
1690 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1693 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id) in btf_dump_ident_name() argument
1695 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1698 static int btf_dump_dump_type_data(struct btf_dump *d,
1706 static const char *btf_dump_data_newline(struct btf_dump *d) in btf_dump_data_newline() argument
1708 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1711 static const char *btf_dump_data_delim(struct btf_dump *d) in btf_dump_data_delim() argument
1713 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1716 static void btf_dump_data_pfx(struct btf_dump *d) in btf_dump_data_pfx() argument
1718 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth; in btf_dump_data_pfx()
1720 if (d->typed_dump->compact) in btf_dump_data_pfx()
1724 btf_dump_printf(d, "%s", d->typed_dump->indent_str); in btf_dump_data_pfx()
1732 #define btf_dump_type_values(d, fmt, ...) \ argument
1733 btf_dump_printf(d, fmt "%s%s", \
1735 btf_dump_data_delim(d), \
1736 btf_dump_data_newline(d))
1738 static int btf_dump_unsupported_data(struct btf_dump *d, in btf_dump_unsupported_data() argument
1742 btf_dump_printf(d, "<unsupported kind:%u>", btf_kind(t)); in btf_dump_unsupported_data()
1746 static int btf_dump_get_bitfield_value(struct btf_dump *d, in btf_dump_get_bitfield_value() argument
1787 static int btf_dump_bitfield_check_zero(struct btf_dump *d, in btf_dump_bitfield_check_zero() argument
1796 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &check_num); in btf_dump_bitfield_check_zero()
1804 static int btf_dump_bitfield_data(struct btf_dump *d, in btf_dump_bitfield_data() argument
1813 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &print_num); in btf_dump_bitfield_data()
1817 btf_dump_type_values(d, "0x%llx", (unsigned long long)print_num); in btf_dump_bitfield_data()
1823 static int btf_dump_base_type_check_zero(struct btf_dump *d, in btf_dump_base_type_check_zero() argument
1835 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1860 static int btf_dump_int_data(struct btf_dump *d, in btf_dump_int_data() argument
1879 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1902 btf_dump_type_values(d, "0x%llx", (unsigned long long)lsi); in btf_dump_int_data()
1904 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1910 btf_dump_type_values(d, "%lld", *(long long *)data); in btf_dump_int_data()
1912 btf_dump_type_values(d, "%llu", *(unsigned long long *)data); in btf_dump_int_data()
1916 btf_dump_type_values(d, "%d", *(__s32 *)data); in btf_dump_int_data()
1918 btf_dump_type_values(d, "%u", *(__u32 *)data); in btf_dump_int_data()
1922 btf_dump_type_values(d, "%d", *(__s16 *)data); in btf_dump_int_data()
1924 btf_dump_type_values(d, "%u", *(__u16 *)data); in btf_dump_int_data()
1927 if (d->typed_dump->is_array_char) { in btf_dump_int_data()
1929 if (d->typed_dump->is_array_terminated) in btf_dump_int_data()
1932 d->typed_dump->is_array_terminated = true; in btf_dump_int_data()
1936 btf_dump_type_values(d, "'%c'", *(char *)data); in btf_dump_int_data()
1941 btf_dump_type_values(d, "%d", *(__s8 *)data); in btf_dump_int_data()
1943 btf_dump_type_values(d, "%u", *(__u8 *)data); in btf_dump_int_data()
1954 double d; member
1958 static int btf_dump_float_data(struct btf_dump *d, in btf_dump_float_data() argument
1968 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_float_data()
1975 btf_dump_type_values(d, "%Lf", flp->ld); in btf_dump_float_data()
1978 btf_dump_type_values(d, "%lf", flp->d); in btf_dump_float_data()
1981 btf_dump_type_values(d, "%f", flp->f); in btf_dump_float_data()
1990 static int btf_dump_var_data(struct btf_dump *d, in btf_dump_var_data() argument
2016 btf_dump_printf(d, "%s", l); in btf_dump_var_data()
2018 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
2019 btf_dump_emit_type_cast(d, type_id, false); in btf_dump_var_data()
2020 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
2021 return btf_dump_dump_type_data(d, NULL, t, type_id, data, 0, 0); in btf_dump_var_data()
2024 static int btf_dump_array_data(struct btf_dump *d, in btf_dump_array_data() argument
2036 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_array_data()
2037 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_array_data()
2051 d->typed_dump->is_array_char = true; in btf_dump_array_data()
2061 d->typed_dump->depth++; in btf_dump_array_data()
2062 btf_dump_printf(d, "[%s", btf_dump_data_newline(d)); in btf_dump_array_data()
2067 is_array_member = d->typed_dump->is_array_member; in btf_dump_array_data()
2068 d->typed_dump->is_array_member = true; in btf_dump_array_data()
2070 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
2072 btf_dump_dump_type_data(d, NULL, elem_type, elem_type_id, data, 0, 0); in btf_dump_array_data()
2074 d->typed_dump->is_array_member = is_array_member; in btf_dump_array_data()
2075 d->typed_dump->depth--; in btf_dump_array_data()
2076 btf_dump_data_pfx(d); in btf_dump_array_data()
2077 btf_dump_type_values(d, "]"); in btf_dump_array_data()
2082 static int btf_dump_struct_data(struct btf_dump *d, in btf_dump_struct_data() argument
2098 d->typed_dump->depth++; in btf_dump_struct_data()
2099 btf_dump_printf(d, "{%s", btf_dump_data_newline(d)); in btf_dump_struct_data()
2107 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_struct_data()
2108 mname = btf_name_of(d, m->name_off); in btf_dump_struct_data()
2112 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8, in btf_dump_struct_data()
2117 d->typed_dump->depth--; in btf_dump_struct_data()
2118 btf_dump_data_pfx(d); in btf_dump_struct_data()
2119 btf_dump_type_values(d, "}"); in btf_dump_struct_data()
2128 static int btf_dump_ptr_data(struct btf_dump *d, in btf_dump_ptr_data() argument
2133 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
2134 btf_dump_type_values(d, "%p", *(void **)data); in btf_dump_ptr_data()
2138 memcpy(&pt, data, d->ptr_sz); in btf_dump_ptr_data()
2139 if (d->ptr_sz == 4) in btf_dump_ptr_data()
2140 btf_dump_type_values(d, "0x%x", pt.p); in btf_dump_ptr_data()
2142 btf_dump_type_values(d, "0x%llx", pt.lp); in btf_dump_ptr_data()
2147 static int btf_dump_get_enum_value(struct btf_dump *d, in btf_dump_get_enum_value() argument
2155 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
2159 err = btf_dump_get_bitfield_value(d, t, data, 0, 0, &val); in btf_dump_get_enum_value()
2185 static int btf_dump_enum_data(struct btf_dump *d, in btf_dump_enum_data() argument
2194 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_enum_data()
2205 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2209 btf_dump_type_values(d, is_signed ? "%d" : "%u", value); in btf_dump_enum_data()
2216 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2220 btf_dump_type_values(d, is_signed ? "%lldLL" : "%lluULL", in btf_dump_enum_data()
2226 static int btf_dump_datasec_data(struct btf_dump *d, in btf_dump_datasec_data() argument
2236 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off)); in btf_dump_datasec_data()
2239 var = btf__type_by_id(d->btf, vsi->type); in btf_dump_datasec_data()
2240 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0); in btf_dump_datasec_data()
2243 btf_dump_printf(d, ";"); in btf_dump_datasec_data()
2249 static int btf_dump_type_data_check_overflow(struct btf_dump *d, in btf_dump_type_data_check_overflow() argument
2268 return data + nr_bytes > d->typed_dump->data_end ? -E2BIG : nr_bytes; in btf_dump_type_data_check_overflow()
2271 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2286 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_overflow()
2299 if (data + bits_offset / 8 + size > d->typed_dump->data_end) in btf_dump_type_data_check_overflow()
2308 static int btf_dump_type_data_check_zero(struct btf_dump *d, in btf_dump_type_data_check_zero() argument
2329 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 || in btf_dump_type_data_check_zero()
2330 (d->typed_dump->is_array_member && in btf_dump_type_data_check_zero()
2331 !d->typed_dump->is_array_char)) in btf_dump_type_data_check_zero()
2334 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_zero()
2339 return btf_dump_bitfield_check_zero(d, t, data, bits_offset, bit_sz); in btf_dump_type_data_check_zero()
2340 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2343 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2351 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_type_data_check_zero()
2352 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_type_data_check_zero()
2365 err = btf_dump_type_data_check_zero(d, elem_type, in btf_dump_type_data_check_zero()
2387 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_type_data_check_zero()
2395 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8, in btf_dump_type_data_check_zero()
2404 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_type_data_check_zero()
2416 static int btf_dump_dump_type_data(struct btf_dump *d, in btf_dump_dump_type_data() argument
2426 size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2429 err = btf_dump_type_data_check_zero(d, t, id, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2438 btf_dump_data_pfx(d); in btf_dump_dump_type_data()
2440 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2442 btf_dump_printf(d, ".%s = ", fname); in btf_dump_dump_type_data()
2443 btf_dump_emit_type_cast(d, id, true); in btf_dump_dump_type_data()
2446 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2454 err = btf_dump_unsupported_data(d, t, id); in btf_dump_dump_type_data()
2458 err = btf_dump_bitfield_data(d, t, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2460 err = btf_dump_int_data(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2463 err = btf_dump_float_data(d, t, id, data); in btf_dump_dump_type_data()
2466 err = btf_dump_ptr_data(d, t, id, data); in btf_dump_dump_type_data()
2469 err = btf_dump_array_data(d, t, id, data); in btf_dump_dump_type_data()
2473 err = btf_dump_struct_data(d, t, id, data); in btf_dump_dump_type_data()
2482 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, in btf_dump_dump_type_data()
2487 err = btf_dump_enum_data(d, t, id, &enum_val); in btf_dump_dump_type_data()
2489 err = btf_dump_enum_data(d, t, id, data); in btf_dump_dump_type_data()
2492 err = btf_dump_var_data(d, t, id, data); in btf_dump_dump_type_data()
2495 err = btf_dump_datasec_data(d, t, id, data); in btf_dump_dump_type_data()
2507 int btf_dump__dump_type_data(struct btf_dump *d, __u32 id, in btf_dump__dump_type_data() argument
2518 t = btf__type_by_id(d->btf, id); in btf_dump__dump_type_data()
2522 d->typed_dump = &typed_dump; in btf_dump__dump_type_data()
2523 d->typed_dump->data_end = data + data_sz; in btf_dump__dump_type_data()
2524 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); in btf_dump__dump_type_data()
2528 d->typed_dump->indent_str[0] = '\t'; in btf_dump__dump_type_data()
2530 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str, in btf_dump__dump_type_data()
2531 sizeof(d->typed_dump->indent_str)); in btf_dump__dump_type_data()
2533 d->typed_dump->compact = OPTS_GET(opts, compact, false); in btf_dump__dump_type_data()
2534 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false); in btf_dump__dump_type_data()
2535 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false); in btf_dump__dump_type_data()
2537 ret = btf_dump_dump_type_data(d, NULL, t, id, data, 0, 0); in btf_dump__dump_type_data()
2539 d->typed_dump = NULL; in btf_dump__dump_type_data()