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->opts.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
156 d = calloc(1, sizeof(struct btf_dump)); in btf_dump__new()
157 if (!d) in btf_dump__new()
160 d->btf = btf; in btf_dump__new()
161 d->btf_ext = btf_ext; in btf_dump__new()
162 d->printf_fn = printf_fn; in btf_dump__new()
163 d->opts.ctx = opts ? opts->ctx : NULL; in btf_dump__new()
164 d->ptr_sz = btf__pointer_size(btf) ? : sizeof(void *); in btf_dump__new()
166 d->type_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
167 if (IS_ERR(d->type_names)) { in btf_dump__new()
168 err = PTR_ERR(d->type_names); in btf_dump__new()
169 d->type_names = NULL; in btf_dump__new()
172 d->ident_names = hashmap__new(str_hash_fn, str_equal_fn, NULL); in btf_dump__new()
173 if (IS_ERR(d->ident_names)) { in btf_dump__new()
174 err = PTR_ERR(d->ident_names); in btf_dump__new()
175 d->ident_names = NULL; in btf_dump__new()
179 err = btf_dump_resize(d); in btf_dump__new()
183 return d; in btf_dump__new()
185 btf_dump__free(d); in btf_dump__new()
189 static int btf_dump_resize(struct btf_dump *d) in btf_dump_resize() argument
191 int err, last_id = btf__type_cnt(d->btf) - 1; in btf_dump_resize()
193 if (last_id <= d->last_id) in btf_dump_resize()
196 if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap, in btf_dump_resize()
197 sizeof(*d->type_states), last_id + 1)) in btf_dump_resize()
199 if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap, in btf_dump_resize()
200 sizeof(*d->cached_names), last_id + 1)) in btf_dump_resize()
203 if (d->last_id == 0) { in btf_dump_resize()
205 d->type_states[0].order_state = ORDERED; in btf_dump_resize()
206 d->type_states[0].emit_state = EMITTED; in btf_dump_resize()
210 err = btf_dump_mark_referenced(d); in btf_dump_resize()
214 d->last_id = last_id; in btf_dump_resize()
218 void btf_dump__free(struct btf_dump *d) in btf_dump__free() argument
222 if (IS_ERR_OR_NULL(d)) in btf_dump__free()
225 free(d->type_states); in btf_dump__free()
226 if (d->cached_names) { in btf_dump__free()
228 for (i = 0; i <= d->last_id; i++) { in btf_dump__free()
229 if (d->cached_names[i]) in btf_dump__free()
230 free((void *)d->cached_names[i]); in btf_dump__free()
233 free(d->cached_names); in btf_dump__free()
234 free(d->emit_queue); in btf_dump__free()
235 free(d->decl_stack); in btf_dump__free()
236 hashmap__free(d->type_names); in btf_dump__free()
237 hashmap__free(d->ident_names); in btf_dump__free()
239 free(d); in btf_dump__free()
242 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr);
243 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id);
261 int btf_dump__dump_type(struct btf_dump *d, __u32 id) in btf_dump__dump_type() argument
265 if (id >= btf__type_cnt(d->btf)) in btf_dump__dump_type()
268 err = btf_dump_resize(d); in btf_dump__dump_type()
272 d->emit_queue_cnt = 0; in btf_dump__dump_type()
273 err = btf_dump_order_type(d, id, false); in btf_dump__dump_type()
277 for (i = 0; i < d->emit_queue_cnt; i++) in btf_dump__dump_type()
278 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/); in btf_dump__dump_type()
295 static int btf_dump_mark_referenced(struct btf_dump *d) in btf_dump_mark_referenced() argument
297 int i, j, n = btf__type_cnt(d->btf); in btf_dump_mark_referenced()
301 for (i = d->last_id + 1; i < n; i++) { in btf_dump_mark_referenced()
302 t = btf__type_by_id(d->btf, i); in btf_dump_mark_referenced()
320 d->type_states[t->type].referenced = 1; in btf_dump_mark_referenced()
326 d->type_states[a->index_type].referenced = 1; in btf_dump_mark_referenced()
327 d->type_states[a->type].referenced = 1; in btf_dump_mark_referenced()
335 d->type_states[m->type].referenced = 1; in btf_dump_mark_referenced()
342 d->type_states[p->type].referenced = 1; in btf_dump_mark_referenced()
349 d->type_states[v->type].referenced = 1; in btf_dump_mark_referenced()
359 static int btf_dump_add_emit_queue_id(struct btf_dump *d, __u32 id) in btf_dump_add_emit_queue_id() argument
364 if (d->emit_queue_cnt >= d->emit_queue_cap) { in btf_dump_add_emit_queue_id()
365 new_cap = max(16, d->emit_queue_cap * 3 / 2); in btf_dump_add_emit_queue_id()
366 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0])); in btf_dump_add_emit_queue_id()
369 d->emit_queue = new_queue; in btf_dump_add_emit_queue_id()
370 d->emit_queue_cap = new_cap; in btf_dump_add_emit_queue_id()
373 d->emit_queue[d->emit_queue_cnt++] = id; in btf_dump_add_emit_queue_id()
451 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) in btf_dump_order_type() argument
464 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_order_type()
473 t = btf__type_by_id(d->btf, id); in btf_dump_order_type()
490 err = btf_dump_order_type(d, t->type, true); in btf_dump_order_type()
495 return btf_dump_order_type(d, btf_array(t)->type, false); in btf_dump_order_type()
512 err = btf_dump_order_type(d, m->type, false); in btf_dump_order_type()
518 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
534 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
544 is_strong = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
553 err = btf_dump_add_emit_queue_id(d, id); in btf_dump_order_type()
557 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
563 return btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
569 err = btf_dump_order_type(d, t->type, through_ptr); in btf_dump_order_type()
576 err = btf_dump_order_type(d, p->type, through_ptr); in btf_dump_order_type()
588 d->type_states[id].order_state = ORDERED; in btf_dump_order_type()
596 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
599 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
601 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
604 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
606 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
609 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
612 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
621 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
623 static void btf_dump_emit_type_chain(struct btf_dump *d,
627 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id);
628 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id);
629 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
632 static bool btf_dump_is_blacklisted(struct btf_dump *d, __u32 id) in btf_dump_is_blacklisted() argument
634 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_is_blacklisted()
644 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0; in btf_dump_is_blacklisted()
665 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) in btf_dump_emit_type() argument
667 struct btf_dump_type_aux_state *tstate = &d->type_states[id]; in btf_dump_emit_type()
675 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type()
696 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
697 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
706 if (!btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
707 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
708 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
722 btf_dump_emit_missing_aliases(d, id, t); in btf_dump_emit_type()
728 btf_dump_emit_enum_def(d, id, t, 0); in btf_dump_emit_type()
729 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
737 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
740 btf_dump_emit_type(d, btf_array(t)->type, cont_id); in btf_dump_emit_type()
743 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type()
744 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
749 btf_dump_emit_type(d, t->type, id); in btf_dump_emit_type()
757 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) { in btf_dump_emit_type()
758 btf_dump_emit_typedef_def(d, id, t, 0); in btf_dump_emit_type()
759 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
780 btf_dump_emit_type(d, m->type, new_cont_id); in btf_dump_emit_type()
782 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type()
783 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
788 btf_dump_emit_struct_def(d, id, t, 0); in btf_dump_emit_type()
789 btf_dump_printf(d, ";\n\n"); in btf_dump_emit_type()
800 btf_dump_emit_type(d, t->type, cont_id); in btf_dump_emit_type()
802 btf_dump_emit_type(d, p->type, cont_id); in btf_dump_emit_type()
845 static void btf_dump_emit_bit_padding(const struct btf_dump *d, in btf_dump_emit_bit_padding() argument
850 int ptr_bits = d->ptr_sz * 8; in btf_dump_emit_bit_padding()
876 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits); in btf_dump_emit_bit_padding()
881 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_struct_fwd() argument
884 btf_dump_printf(d, "%s%s%s", in btf_dump_emit_struct_fwd()
887 btf_dump_type_name(d, id)); in btf_dump_emit_struct_fwd()
890 static void btf_dump_emit_struct_def(struct btf_dump *d, in btf_dump_emit_struct_def() argument
900 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; in btf_dump_emit_struct_def()
902 btf_dump_printf(d, "%s%s%s {", in btf_dump_emit_struct_def()
905 btf_dump_type_name(d, id)); in btf_dump_emit_struct_def()
911 fname = btf_name_of(d, m->name_off); in btf_dump_emit_struct_def()
914 align = packed ? 1 : btf__align_of(d->btf, m->type); in btf_dump_emit_struct_def()
916 btf_dump_emit_bit_padding(d, off, m_off, m_sz, align, lvl + 1); in btf_dump_emit_struct_def()
917 btf_dump_printf(d, "\n%s", pfx(lvl + 1)); in btf_dump_emit_struct_def()
918 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1); in btf_dump_emit_struct_def()
921 btf_dump_printf(d, ": %d", m_sz); in btf_dump_emit_struct_def()
924 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type)); in btf_dump_emit_struct_def()
927 btf_dump_printf(d, ";"); in btf_dump_emit_struct_def()
932 align = packed ? 1 : btf__align_of(d->btf, id); in btf_dump_emit_struct_def()
933 btf_dump_emit_bit_padding(d, off, t->size * 8, 0, align, in btf_dump_emit_struct_def()
938 btf_dump_printf(d, "\n"); in btf_dump_emit_struct_def()
939 btf_dump_printf(d, "%s}", pfx(lvl)); in btf_dump_emit_struct_def()
941 btf_dump_printf(d, " __attribute__((packed))"); in btf_dump_emit_struct_def()
955 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id, in btf_dump_emit_missing_aliases() argument
958 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_missing_aliases()
963 btf_dump_printf(d, "typedef %s %s;\n\n", in btf_dump_emit_missing_aliases()
970 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_fwd() argument
973 btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id)); in btf_dump_emit_enum_fwd()
976 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id, in btf_dump_emit_enum_def() argument
986 btf_dump_printf(d, "enum%s%s", in btf_dump_emit_enum_def()
988 btf_dump_type_name(d, id)); in btf_dump_emit_enum_def()
991 btf_dump_printf(d, " {"); in btf_dump_emit_enum_def()
993 name = btf_name_of(d, v->name_off); in btf_dump_emit_enum_def()
995 dup_cnt = btf_dump_name_dups(d, d->ident_names, name); in btf_dump_emit_enum_def()
997 btf_dump_printf(d, "\n%s%s___%zu = %u,", in btf_dump_emit_enum_def()
1001 btf_dump_printf(d, "\n%s%s = %u,", in btf_dump_emit_enum_def()
1006 btf_dump_printf(d, "\n%s}", pfx(lvl)); in btf_dump_emit_enum_def()
1010 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id, in btf_dump_emit_fwd_def() argument
1013 const char *name = btf_dump_type_name(d, id); in btf_dump_emit_fwd_def()
1016 btf_dump_printf(d, "union %s", name); in btf_dump_emit_fwd_def()
1018 btf_dump_printf(d, "struct %s", name); in btf_dump_emit_fwd_def()
1021 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id, in btf_dump_emit_typedef_def() argument
1024 const char *name = btf_dump_ident_name(d, id); in btf_dump_emit_typedef_def()
1033 btf_dump_printf(d, "typedef __builtin_va_list __gnuc_va_list"); in btf_dump_emit_typedef_def()
1037 btf_dump_printf(d, "typedef "); in btf_dump_emit_typedef_def()
1038 btf_dump_emit_type_decl(d, t->type, name, lvl); in btf_dump_emit_typedef_def()
1041 static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id) in btf_dump_push_decl_stack_id() argument
1046 if (d->decl_stack_cnt >= d->decl_stack_cap) { in btf_dump_push_decl_stack_id()
1047 new_cap = max(16, d->decl_stack_cap * 3 / 2); in btf_dump_push_decl_stack_id()
1048 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0])); in btf_dump_push_decl_stack_id()
1051 d->decl_stack = new_stack; in btf_dump_push_decl_stack_id()
1052 d->decl_stack_cap = new_cap; in btf_dump_push_decl_stack_id()
1055 d->decl_stack[d->decl_stack_cnt++] = id; in btf_dump_push_decl_stack_id()
1101 int btf_dump__emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump__emit_type_decl() argument
1110 err = btf_dump_resize(d); in btf_dump__emit_type_decl()
1116 d->strip_mods = OPTS_GET(opts, strip_mods, false); in btf_dump__emit_type_decl()
1117 btf_dump_emit_type_decl(d, id, fname, lvl); in btf_dump__emit_type_decl()
1118 d->strip_mods = false; in btf_dump__emit_type_decl()
1122 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, in btf_dump_emit_type_decl() argument
1129 stack_start = d->decl_stack_cnt; in btf_dump_emit_type_decl()
1131 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_decl()
1132 if (d->strip_mods && btf_is_mod(t)) in btf_dump_emit_type_decl()
1135 err = btf_dump_push_decl_stack_id(d, id); in btf_dump_emit_type_decl()
1143 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1187 decl_stack.ids = d->decl_stack + stack_start; in btf_dump_emit_type_decl()
1188 decl_stack.cnt = d->decl_stack_cnt - stack_start; in btf_dump_emit_type_decl()
1189 btf_dump_emit_type_chain(d, &decl_stack, fname, lvl); in btf_dump_emit_type_decl()
1198 d->decl_stack_cnt = stack_start; in btf_dump_emit_type_decl()
1201 static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_emit_mods() argument
1208 t = btf__type_by_id(d->btf, id); in btf_dump_emit_mods()
1212 btf_dump_printf(d, "volatile "); in btf_dump_emit_mods()
1215 btf_dump_printf(d, "const "); in btf_dump_emit_mods()
1218 btf_dump_printf(d, "restrict "); in btf_dump_emit_mods()
1227 static void btf_dump_drop_mods(struct btf_dump *d, struct id_stack *decl_stack) in btf_dump_drop_mods() argument
1234 t = btf__type_by_id(d->btf, id); in btf_dump_drop_mods()
1241 static void btf_dump_emit_name(const struct btf_dump *d, in btf_dump_emit_name() argument
1246 btf_dump_printf(d, "%s%s", separate ? " " : "", name); in btf_dump_emit_name()
1249 static void btf_dump_emit_type_chain(struct btf_dump *d, in btf_dump_emit_type_chain() argument
1272 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1273 btf_dump_printf(d, "void"); in btf_dump_emit_type_chain()
1278 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_chain()
1284 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1285 name = btf_name_of(d, t->name_off); in btf_dump_emit_type_chain()
1286 btf_dump_printf(d, "%s", name); in btf_dump_emit_type_chain()
1290 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1292 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1293 btf_dump_emit_struct_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1295 btf_dump_emit_struct_fwd(d, id, t); in btf_dump_emit_type_chain()
1298 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1300 if (t->name_off == 0 && !d->skip_anon_defs) in btf_dump_emit_type_chain()
1301 btf_dump_emit_enum_def(d, id, t, lvl); in btf_dump_emit_type_chain()
1303 btf_dump_emit_enum_fwd(d, id, t); in btf_dump_emit_type_chain()
1306 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1307 btf_dump_emit_fwd_def(d, id, t); in btf_dump_emit_type_chain()
1310 btf_dump_emit_mods(d, decls); in btf_dump_emit_type_chain()
1311 btf_dump_printf(d, "%s", btf_dump_ident_name(d, id)); in btf_dump_emit_type_chain()
1314 btf_dump_printf(d, "%s", last_was_ptr ? "*" : " *"); in btf_dump_emit_type_chain()
1317 btf_dump_printf(d, " volatile"); in btf_dump_emit_type_chain()
1320 btf_dump_printf(d, " const"); in btf_dump_emit_type_chain()
1323 btf_dump_printf(d, " restrict"); in btf_dump_emit_type_chain()
1340 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1343 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1344 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1349 next_t = btf__type_by_id(d->btf, next_id); in btf_dump_emit_type_chain()
1353 btf_dump_printf(d, " "); in btf_dump_emit_type_chain()
1356 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1357 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1359 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1360 btf_dump_printf(d, "[%u]", a->nelems); in btf_dump_emit_type_chain()
1376 btf_dump_drop_mods(d, decls); in btf_dump_emit_type_chain()
1378 btf_dump_printf(d, " ("); in btf_dump_emit_type_chain()
1379 btf_dump_emit_type_chain(d, decls, fname, lvl); in btf_dump_emit_type_chain()
1380 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1382 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1384 btf_dump_printf(d, "("); in btf_dump_emit_type_chain()
1392 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1398 btf_dump_printf(d, ", "); in btf_dump_emit_type_chain()
1402 btf_dump_printf(d, "..."); in btf_dump_emit_type_chain()
1406 name = btf_name_of(d, p->name_off); in btf_dump_emit_type_chain()
1407 btf_dump_emit_type_decl(d, p->type, name, lvl); in btf_dump_emit_type_chain()
1410 btf_dump_printf(d, ")"); in btf_dump_emit_type_chain()
1422 btf_dump_emit_name(d, fname, last_was_ptr); in btf_dump_emit_type_chain()
1426 static void btf_dump_emit_type_cast(struct btf_dump *d, __u32 id, in btf_dump_emit_type_cast() argument
1435 if (d->typed_dump->is_array_member) in btf_dump_emit_type_cast()
1441 t = btf__type_by_id(d->btf, id); in btf_dump_emit_type_cast()
1446 btf_dump_printf(d, "("); in btf_dump_emit_type_cast()
1448 d->skip_anon_defs = true; in btf_dump_emit_type_cast()
1449 d->strip_mods = true; in btf_dump_emit_type_cast()
1450 btf_dump_emit_type_decl(d, id, "", 0); in btf_dump_emit_type_cast()
1451 d->strip_mods = false; in btf_dump_emit_type_cast()
1452 d->skip_anon_defs = false; in btf_dump_emit_type_cast()
1455 btf_dump_printf(d, ")"); in btf_dump_emit_type_cast()
1459 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map, in btf_dump_name_dups() argument
1471 static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id, in btf_dump_resolve_name() argument
1474 struct btf_dump_type_aux_state *s = &d->type_states[id]; in btf_dump_resolve_name()
1475 const struct btf_type *t = btf__type_by_id(d->btf, id); in btf_dump_resolve_name()
1476 const char *orig_name = btf_name_of(d, t->name_off); in btf_dump_resolve_name()
1477 const char **cached_name = &d->cached_names[id]; in btf_dump_resolve_name()
1486 dup_cnt = btf_dump_name_dups(d, name_map, orig_name); in btf_dump_resolve_name()
1499 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id) in btf_dump_type_name() argument
1501 return btf_dump_resolve_name(d, id, d->type_names); in btf_dump_type_name()
1504 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id) in btf_dump_ident_name() argument
1506 return btf_dump_resolve_name(d, id, d->ident_names); in btf_dump_ident_name()
1509 static int btf_dump_dump_type_data(struct btf_dump *d,
1517 static const char *btf_dump_data_newline(struct btf_dump *d) in btf_dump_data_newline() argument
1519 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n"; in btf_dump_data_newline()
1522 static const char *btf_dump_data_delim(struct btf_dump *d) in btf_dump_data_delim() argument
1524 return d->typed_dump->depth == 0 ? "" : ","; in btf_dump_data_delim()
1527 static void btf_dump_data_pfx(struct btf_dump *d) in btf_dump_data_pfx() argument
1529 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth; in btf_dump_data_pfx()
1531 if (d->typed_dump->compact) in btf_dump_data_pfx()
1535 btf_dump_printf(d, "%s", d->typed_dump->indent_str); in btf_dump_data_pfx()
1543 #define btf_dump_type_values(d, fmt, ...) \ argument
1544 btf_dump_printf(d, fmt "%s%s", \
1546 btf_dump_data_delim(d), \
1547 btf_dump_data_newline(d))
1549 static int btf_dump_unsupported_data(struct btf_dump *d, in btf_dump_unsupported_data() argument
1553 btf_dump_printf(d, "<unsupported kind:%u>", btf_kind(t)); in btf_dump_unsupported_data()
1557 static int btf_dump_get_bitfield_value(struct btf_dump *d, in btf_dump_get_bitfield_value() argument
1598 static int btf_dump_bitfield_check_zero(struct btf_dump *d, in btf_dump_bitfield_check_zero() argument
1607 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &check_num); in btf_dump_bitfield_check_zero()
1615 static int btf_dump_bitfield_data(struct btf_dump *d, in btf_dump_bitfield_data() argument
1624 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &print_num); in btf_dump_bitfield_data()
1628 btf_dump_type_values(d, "0x%llx", (unsigned long long)print_num); in btf_dump_bitfield_data()
1634 static int btf_dump_base_type_check_zero(struct btf_dump *d, in btf_dump_base_type_check_zero() argument
1646 nr_bytes = d->ptr_sz; in btf_dump_base_type_check_zero()
1671 static int btf_dump_int_data(struct btf_dump *d, in btf_dump_int_data() argument
1690 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_int_data()
1713 btf_dump_type_values(d, "0x%llx", (unsigned long long)lsi); in btf_dump_int_data()
1715 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi, in btf_dump_int_data()
1721 btf_dump_type_values(d, "%lld", *(long long *)data); in btf_dump_int_data()
1723 btf_dump_type_values(d, "%llu", *(unsigned long long *)data); in btf_dump_int_data()
1727 btf_dump_type_values(d, "%d", *(__s32 *)data); in btf_dump_int_data()
1729 btf_dump_type_values(d, "%u", *(__u32 *)data); in btf_dump_int_data()
1733 btf_dump_type_values(d, "%d", *(__s16 *)data); in btf_dump_int_data()
1735 btf_dump_type_values(d, "%u", *(__u16 *)data); in btf_dump_int_data()
1738 if (d->typed_dump->is_array_char) { in btf_dump_int_data()
1740 if (d->typed_dump->is_array_terminated) in btf_dump_int_data()
1743 d->typed_dump->is_array_terminated = true; in btf_dump_int_data()
1747 btf_dump_type_values(d, "'%c'", *(char *)data); in btf_dump_int_data()
1752 btf_dump_type_values(d, "%d", *(__s8 *)data); in btf_dump_int_data()
1754 btf_dump_type_values(d, "%u", *(__u8 *)data); in btf_dump_int_data()
1765 double d; member
1769 static int btf_dump_float_data(struct btf_dump *d, in btf_dump_float_data() argument
1779 if (!ptr_is_aligned(d->btf, type_id, data)) { in btf_dump_float_data()
1786 btf_dump_type_values(d, "%Lf", flp->ld); in btf_dump_float_data()
1789 btf_dump_type_values(d, "%lf", flp->d); in btf_dump_float_data()
1792 btf_dump_type_values(d, "%f", flp->f); in btf_dump_float_data()
1801 static int btf_dump_var_data(struct btf_dump *d, in btf_dump_var_data() argument
1827 btf_dump_printf(d, "%s", l); in btf_dump_var_data()
1829 t = btf__type_by_id(d->btf, type_id); in btf_dump_var_data()
1830 btf_dump_emit_type_cast(d, type_id, false); in btf_dump_var_data()
1831 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off)); in btf_dump_var_data()
1832 return btf_dump_dump_type_data(d, NULL, t, type_id, data, 0, 0); in btf_dump_var_data()
1835 static int btf_dump_array_data(struct btf_dump *d, in btf_dump_array_data() argument
1846 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_array_data()
1847 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_array_data()
1860 d->typed_dump->is_array_char = true; in btf_dump_array_data()
1870 d->typed_dump->depth++; in btf_dump_array_data()
1871 btf_dump_printf(d, "[%s", btf_dump_data_newline(d)); in btf_dump_array_data()
1876 is_array_member = d->typed_dump->is_array_member; in btf_dump_array_data()
1877 d->typed_dump->is_array_member = true; in btf_dump_array_data()
1879 if (d->typed_dump->is_array_terminated) in btf_dump_array_data()
1881 btf_dump_dump_type_data(d, NULL, elem_type, elem_type_id, data, 0, 0); in btf_dump_array_data()
1883 d->typed_dump->is_array_member = is_array_member; in btf_dump_array_data()
1884 d->typed_dump->depth--; in btf_dump_array_data()
1885 btf_dump_data_pfx(d); in btf_dump_array_data()
1886 btf_dump_type_values(d, "]"); in btf_dump_array_data()
1891 static int btf_dump_struct_data(struct btf_dump *d, in btf_dump_struct_data() argument
1907 d->typed_dump->depth++; in btf_dump_struct_data()
1908 btf_dump_printf(d, "{%s", btf_dump_data_newline(d)); in btf_dump_struct_data()
1916 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_struct_data()
1917 mname = btf_name_of(d, m->name_off); in btf_dump_struct_data()
1921 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8, in btf_dump_struct_data()
1926 d->typed_dump->depth--; in btf_dump_struct_data()
1927 btf_dump_data_pfx(d); in btf_dump_struct_data()
1928 btf_dump_type_values(d, "}"); in btf_dump_struct_data()
1937 static int btf_dump_ptr_data(struct btf_dump *d, in btf_dump_ptr_data() argument
1942 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) { in btf_dump_ptr_data()
1943 btf_dump_type_values(d, "%p", *(void **)data); in btf_dump_ptr_data()
1947 memcpy(&pt, data, d->ptr_sz); in btf_dump_ptr_data()
1948 if (d->ptr_sz == 4) in btf_dump_ptr_data()
1949 btf_dump_type_values(d, "0x%x", pt.p); in btf_dump_ptr_data()
1951 btf_dump_type_values(d, "0x%llx", pt.lp); in btf_dump_ptr_data()
1956 static int btf_dump_get_enum_value(struct btf_dump *d, in btf_dump_get_enum_value() argument
1963 if (!ptr_is_aligned(d->btf, id, data)) { in btf_dump_get_enum_value()
1967 err = btf_dump_get_bitfield_value(d, t, data, 0, 0, &val); in btf_dump_get_enum_value()
1993 static int btf_dump_enum_data(struct btf_dump *d, in btf_dump_enum_data() argument
2002 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_enum_data()
2009 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off)); in btf_dump_enum_data()
2013 btf_dump_type_values(d, "%d", value); in btf_dump_enum_data()
2017 static int btf_dump_datasec_data(struct btf_dump *d, in btf_dump_datasec_data() argument
2027 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off)); in btf_dump_datasec_data()
2030 var = btf__type_by_id(d->btf, vsi->type); in btf_dump_datasec_data()
2031 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0); in btf_dump_datasec_data()
2034 btf_dump_printf(d, ";"); in btf_dump_datasec_data()
2040 static int btf_dump_type_data_check_overflow(struct btf_dump *d, in btf_dump_type_data_check_overflow() argument
2046 __s64 size = btf__resolve_size(d->btf, id); in btf_dump_type_data_check_overflow()
2061 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_overflow()
2073 if (data + bits_offset / 8 + size > d->typed_dump->data_end) in btf_dump_type_data_check_overflow()
2082 static int btf_dump_type_data_check_zero(struct btf_dump *d, in btf_dump_type_data_check_zero() argument
2103 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 || in btf_dump_type_data_check_zero()
2104 (d->typed_dump->is_array_member && in btf_dump_type_data_check_zero()
2105 !d->typed_dump->is_array_char)) in btf_dump_type_data_check_zero()
2108 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_type_data_check_zero()
2113 return btf_dump_bitfield_check_zero(d, t, data, bits_offset, bit_sz); in btf_dump_type_data_check_zero()
2114 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2117 return btf_dump_base_type_check_zero(d, t, id, data); in btf_dump_type_data_check_zero()
2125 elem_size = btf__resolve_size(d->btf, elem_type_id); in btf_dump_type_data_check_zero()
2126 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL); in btf_dump_type_data_check_zero()
2139 err = btf_dump_type_data_check_zero(d, elem_type, in btf_dump_type_data_check_zero()
2161 mtype = btf__type_by_id(d->btf, m->type); in btf_dump_type_data_check_zero()
2169 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8, in btf_dump_type_data_check_zero()
2177 err = btf_dump_get_enum_value(d, t, data, id, &value); in btf_dump_type_data_check_zero()
2189 static int btf_dump_dump_type_data(struct btf_dump *d, in btf_dump_dump_type_data() argument
2199 size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2202 err = btf_dump_type_data_check_zero(d, t, id, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2211 btf_dump_data_pfx(d); in btf_dump_dump_type_data()
2213 if (!d->typed_dump->skip_names) { in btf_dump_dump_type_data()
2215 btf_dump_printf(d, ".%s = ", fname); in btf_dump_dump_type_data()
2216 btf_dump_emit_type_cast(d, id, true); in btf_dump_dump_type_data()
2219 t = skip_mods_and_typedefs(d->btf, id, NULL); in btf_dump_dump_type_data()
2227 err = btf_dump_unsupported_data(d, t, id); in btf_dump_dump_type_data()
2231 err = btf_dump_bitfield_data(d, t, data, bits_offset, bit_sz); in btf_dump_dump_type_data()
2233 err = btf_dump_int_data(d, t, id, data, bits_offset); in btf_dump_dump_type_data()
2236 err = btf_dump_float_data(d, t, id, data); in btf_dump_dump_type_data()
2239 err = btf_dump_ptr_data(d, t, id, data); in btf_dump_dump_type_data()
2242 err = btf_dump_array_data(d, t, id, data); in btf_dump_dump_type_data()
2246 err = btf_dump_struct_data(d, t, id, data); in btf_dump_dump_type_data()
2254 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, in btf_dump_dump_type_data()
2259 err = btf_dump_enum_data(d, t, id, &enum_val); in btf_dump_dump_type_data()
2261 err = btf_dump_enum_data(d, t, id, data); in btf_dump_dump_type_data()
2264 err = btf_dump_var_data(d, t, id, data); in btf_dump_dump_type_data()
2267 err = btf_dump_datasec_data(d, t, id, data); in btf_dump_dump_type_data()
2279 int btf_dump__dump_type_data(struct btf_dump *d, __u32 id, in btf_dump__dump_type_data() argument
2290 t = btf__type_by_id(d->btf, id); in btf_dump__dump_type_data()
2294 d->typed_dump = &typed_dump; in btf_dump__dump_type_data()
2295 d->typed_dump->data_end = data + data_sz; in btf_dump__dump_type_data()
2296 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0); in btf_dump__dump_type_data()
2300 d->typed_dump->indent_str[0] = '\t'; in btf_dump__dump_type_data()
2302 strncat(d->typed_dump->indent_str, opts->indent_str, in btf_dump__dump_type_data()
2303 sizeof(d->typed_dump->indent_str) - 1); in btf_dump__dump_type_data()
2305 d->typed_dump->compact = OPTS_GET(opts, compact, false); in btf_dump__dump_type_data()
2306 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false); in btf_dump__dump_type_data()
2307 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false); in btf_dump__dump_type_data()
2309 ret = btf_dump_dump_type_data(d, NULL, t, id, data, 0, 0); in btf_dump__dump_type_data()
2311 d->typed_dump = NULL; in btf_dump__dump_type_data()