Lines Matching refs:d

132 static const char *btf_name_of(const struct btf_dump *d, __u32 name_off)
134 return btf__name_by_offset(d->btf, name_off);
137 static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...)
142 d->printf_fn(d->cb_ctx, fmt, args);
146 static int btf_dump_mark_referenced(struct btf_dump *d);
147 static int btf_dump_resize(struct btf_dump *d);
154 struct btf_dump *d;
163 d = calloc(1, sizeof(struct btf_dump));
164 if (!d)
167 d->btf = btf;
168 d->printf_fn = printf_fn;
169 d->cb_ctx = ctx;
170 d->ptr_sz = btf__pointer_size(btf) ? : sizeof(void *);
172 d->type_names = hashmap__new(str_hash_fn, str_equal_fn, NULL);
173 if (IS_ERR(d->type_names)) {
174 err = PTR_ERR(d->type_names);
175 d->type_names = NULL;
178 d->ident_names = hashmap__new(str_hash_fn, str_equal_fn, NULL);
179 if (IS_ERR(d->ident_names)) {
180 err = PTR_ERR(d->ident_names);
181 d->ident_names = NULL;
185 err = btf_dump_resize(d);
189 return d;
191 btf_dump__free(d);
195 static int btf_dump_resize(struct btf_dump *d)
197 int err, last_id = btf__type_cnt(d->btf) - 1;
199 if (last_id <= d->last_id)
202 if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap,
203 sizeof(*d->type_states), last_id + 1))
205 if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap,
206 sizeof(*d->cached_names), last_id + 1))
209 if (d->last_id == 0) {
211 d->type_states[0].order_state = ORDERED;
212 d->type_states[0].emit_state = EMITTED;
216 err = btf_dump_mark_referenced(d);
220 d->last_id = last_id;
238 void btf_dump__free(struct btf_dump *d)
242 if (IS_ERR_OR_NULL(d))
245 free(d->type_states);
246 if (d->cached_names) {
248 for (i = 0; i <= d->last_id; i++) {
249 if (d->cached_names[i])
250 free((void *)d->cached_names[i]);
253 free(d->cached_names);
254 free(d->emit_queue);
255 free(d->decl_stack);
256 btf_dump_free_names(d->type_names);
257 btf_dump_free_names(d->ident_names);
259 free(d);
262 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr);
263 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id);
281 int btf_dump__dump_type(struct btf_dump *d, __u32 id)
285 if (id >= btf__type_cnt(d->btf))
288 err = btf_dump_resize(d);
292 d->emit_queue_cnt = 0;
293 err = btf_dump_order_type(d, id, false);
297 for (i = 0; i < d->emit_queue_cnt; i++)
298 btf_dump_emit_type(d, d->emit_queue[i], 0 /*top-level*/);
315 static int btf_dump_mark_referenced(struct btf_dump *d)
317 int i, j, n = btf__type_cnt(d->btf);
321 for (i = d->last_id + 1; i < n; i++) {
322 t = btf__type_by_id(d->btf, i);
342 d->type_states[t->type].referenced = 1;
348 d->type_states[a->index_type].referenced = 1;
349 d->type_states[a->type].referenced = 1;
357 d->type_states[m->type].referenced = 1;
364 d->type_states[p->type].referenced = 1;
371 d->type_states[v->type].referenced = 1;
381 static int btf_dump_add_emit_queue_id(struct btf_dump *d, __u32 id)
386 if (d->emit_queue_cnt >= d->emit_queue_cap) {
387 new_cap = max(16, d->emit_queue_cap * 3 / 2);
388 new_queue = libbpf_reallocarray(d->emit_queue, new_cap, sizeof(new_queue[0]));
391 d->emit_queue = new_queue;
392 d->emit_queue_cap = new_cap;
395 d->emit_queue[d->emit_queue_cnt++] = id;
473 static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
486 struct btf_dump_type_aux_state *tstate = &d->type_states[id];
495 t = btf__type_by_id(d->btf, id);
512 err = btf_dump_order_type(d, t->type, true);
517 return btf_dump_order_type(d, btf_array(t)->type, false);
534 err = btf_dump_order_type(d, m->type, false);
540 err = btf_dump_add_emit_queue_id(d, id);
557 err = btf_dump_add_emit_queue_id(d, id);
567 is_strong = btf_dump_order_type(d, t->type, through_ptr);
576 err = btf_dump_add_emit_queue_id(d, id);
580 d->type_states[id].order_state = ORDERED;
587 return btf_dump_order_type(d, t->type, through_ptr);
593 err = btf_dump_order_type(d, t->type, through_ptr);
600 err = btf_dump_order_type(d, p->type, through_ptr);
612 d->type_states[id].order_state = ORDERED;
620 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
623 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
625 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
628 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
630 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
633 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
636 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
645 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
647 static void btf_dump_emit_type_chain(struct btf_dump *d,
651 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id);
652 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id);
653 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
656 static bool btf_dump_is_blacklisted(struct btf_dump *d, __u32 id)
658 const struct btf_type *t = btf__type_by_id(d->btf, id);
668 return strcmp(btf_name_of(d, t->name_off), "__builtin_va_list") == 0;
689 static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id)
691 struct btf_dump_type_aux_state *tstate = &d->type_states[id];
699 t = btf__type_by_id(d->btf, id);
720 btf_dump_emit_struct_fwd(d, id, t);
721 btf_dump_printf(d, ";\n\n");
730 if (!btf_dump_is_blacklisted(d, id)) {
731 btf_dump_emit_typedef_def(d, id, t, 0);
732 btf_dump_printf(d, ";\n\n");
746 btf_dump_emit_missing_aliases(d, id, t);
753 btf_dump_emit_enum_def(d, id, t, 0);
754 btf_dump_printf(d, ";\n\n");
763 btf_dump_emit_type(d, t->type, cont_id);
766 btf_dump_emit_type(d, btf_array(t)->type, cont_id);
769 btf_dump_emit_fwd_def(d, id, t);
770 btf_dump_printf(d, ";\n\n");
775 btf_dump_emit_type(d, t->type, id);
783 if (!tstate->fwd_emitted && !btf_dump_is_blacklisted(d, id)) {
784 btf_dump_emit_typedef_def(d, id, t, 0);
785 btf_dump_printf(d, ";\n\n");
806 btf_dump_emit_type(d, m->type, new_cont_id);
808 btf_dump_emit_struct_fwd(d, id, t);
809 btf_dump_printf(d, ";\n\n");
814 btf_dump_emit_struct_def(d, id, t, 0);
815 btf_dump_printf(d, ";\n\n");
826 btf_dump_emit_type(d, t->type, cont_id);
828 btf_dump_emit_type(d, p->type, cont_id);
864 static void btf_dump_emit_bit_padding(const struct btf_dump *d,
872 {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8}
921 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type,
935 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, pad_bits);
951 btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, bits);
958 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
961 btf_dump_printf(d, "%s%s%s",
964 btf_dump_type_name(d, id));
967 static void btf_dump_emit_struct_def(struct btf_dump *d,
978 align = btf__align_of(d->btf, id);
979 packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0;
981 btf_dump_printf(d, "%s%s%s {",
984 btf_dump_type_name(d, id));
991 fname = btf_name_of(d, m->name_off);
994 m_align = packed ? 1 : btf__align_of(d->btf, m->type);
998 btf_dump_emit_bit_padding(d, off, m_off, m_align, in_bitfield, lvl + 1);
999 btf_dump_printf(d, "\n%s", pfx(lvl + 1));
1000 btf_dump_emit_type_decl(d, m->type, fname, lvl + 1);
1003 btf_dump_printf(d, ": %d", m_sz);
1007 m_sz = max((__s64)0, btf__resolve_size(d->btf, m->type));
1012 btf_dump_printf(d, ";");
1017 btf_dump_emit_bit_padding(d, off, t->size * 8, align, false, lvl + 1);
1024 btf_dump_printf(d, "\n");
1025 btf_dump_printf(d, "%s}", pfx(lvl));
1027 btf_dump_printf(d, "}");
1030 btf_dump_printf(d, " __attribute__((packed))");
1044 static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
1047 const char *name = btf_dump_type_name(d, id);
1052 btf_dump_printf(d, "typedef %s %s;\n\n",
1059 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
1062 btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id));
1065 static void btf_dump_emit_enum32_val(struct btf_dump *d,
1077 name = btf_name_of(d, v->name_off);
1079 dup_cnt = btf_dump_name_dups(d, d->ident_names, name);
1081 fmt_str = is_signed ? "\n%s%s___%zd = %d," : "\n%s%s___%zd = %u,";
1082 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val);
1084 fmt_str = is_signed ? "\n%s%s = %d," : "\n%s%s = %u,";
1085 btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val);
1090 static void btf_dump_emit_enum64_val(struct btf_dump *d,
1103 name = btf_name_of(d, v->name_off);
1104 dup_cnt = btf_dump_name_dups(d, d->ident_names, name);
1109 btf_dump_printf(d, fmt_str,
1115 btf_dump_printf(d, fmt_str,
1121 static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
1127 btf_dump_printf(d, "enum%s%s",
1129 btf_dump_type_name(d, id));
1134 btf_dump_printf(d, " {");
1136 btf_dump_emit_enum32_val(d, t, lvl, vlen);
1138 btf_dump_emit_enum64_val(d, t, lvl, vlen);
1139 btf_dump_printf(d, "\n%s}", pfx(lvl));
1144 btf_dump_printf(d, " __attribute__((mode(byte)))");
1145 } else if (t->size == 8 && d->ptr_sz == 8) {
1174 btf_dump_printf(d, " __attribute__((mode(word)))");
1179 static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
1182 const char *name = btf_dump_type_name(d, id);
1185 btf_dump_printf(d, "union %s", name);
1187 btf_dump_printf(d, "struct %s", name);
1190 static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
1193 const char *name = btf_dump_ident_name(d, id);
1202 btf_dump_printf(d, "typedef __builtin_va_list __gnuc_va_list");
1206 btf_dump_printf(d, "typedef ");
1207 btf_dump_emit_type_decl(d, t->type, name, lvl);
1210 static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id)
1215 if (d->decl_stack_cnt >= d->decl_stack_cap) {
1216 new_cap = max(16, d->decl_stack_cap * 3 / 2);
1217 new_stack = libbpf_reallocarray(d->decl_stack, new_cap, sizeof(new_stack[0]));
1220 d->decl_stack = new_stack;
1221 d->decl_stack_cap = new_cap;
1224 d->decl_stack[d->decl_stack_cnt++] = id;
1270 int btf_dump__emit_type_decl(struct btf_dump *d, __u32 id,
1279 err = btf_dump_resize(d);
1285 d->strip_mods = OPTS_GET(opts, strip_mods, false);
1286 btf_dump_emit_type_decl(d, id, fname, lvl);
1287 d->strip_mods = false;
1291 static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
1298 stack_start = d->decl_stack_cnt;
1300 t = btf__type_by_id(d->btf, id);
1301 if (d->strip_mods && btf_is_mod(t))
1304 err = btf_dump_push_decl_stack_id(d, id);
1312 d->decl_stack_cnt = stack_start;
1358 decl_stack.ids = d->decl_stack + stack_start;
1359 decl_stack.cnt = d->decl_stack_cnt - stack_start;
1360 btf_dump_emit_type_chain(d, &decl_stack, fname, lvl);
1369 d->decl_stack_cnt = stack_start;
1372 static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack)
1379 t = btf__type_by_id(d->btf, id);
1383 btf_dump_printf(d, "volatile ");
1386 btf_dump_printf(d, "const ");
1389 btf_dump_printf(d, "restrict ");
1398 static void btf_dump_drop_mods(struct btf_dump *d, struct id_stack *decl_stack)
1405 t = btf__type_by_id(d->btf, id);
1412 static void btf_dump_emit_name(const struct btf_dump *d,
1417 btf_dump_printf(d, "%s%s", separate ? " " : "", name);
1420 static void btf_dump_emit_type_chain(struct btf_dump *d,
1443 btf_dump_emit_mods(d, decls);
1444 btf_dump_printf(d, "void");
1449 t = btf__type_by_id(d->btf, id);
1455 btf_dump_emit_mods(d, decls);
1456 name = btf_name_of(d, t->name_off);
1457 btf_dump_printf(d, "%s", name);
1461 btf_dump_emit_mods(d, decls);
1463 if (t->name_off == 0 && !d->skip_anon_defs)
1464 btf_dump_emit_struct_def(d, id, t, lvl);
1466 btf_dump_emit_struct_fwd(d, id, t);
1470 btf_dump_emit_mods(d, decls);
1472 if (t->name_off == 0 && !d->skip_anon_defs)
1473 btf_dump_emit_enum_def(d, id, t, lvl);
1475 btf_dump_emit_enum_fwd(d, id, t);
1478 btf_dump_emit_mods(d, decls);
1479 btf_dump_emit_fwd_def(d, id, t);
1482 btf_dump_emit_mods(d, decls);
1483 btf_dump_printf(d, "%s", btf_dump_ident_name(d, id));
1486 btf_dump_printf(d, "%s", last_was_ptr ? "*" : " *");
1489 btf_dump_printf(d, " volatile");
1492 btf_dump_printf(d, " const");
1495 btf_dump_printf(d, " restrict");
1498 btf_dump_emit_mods(d, decls);
1499 name = btf_name_of(d, t->name_off);
1501 btf_dump_printf(d, " __attribute__((%s))", name);
1503 btf_dump_printf(d, " __attribute__((btf_type_tag(\"%s\")))", name);
1520 btf_dump_drop_mods(d, decls);
1523 btf_dump_emit_name(d, fname, last_was_ptr);
1524 btf_dump_printf(d, "[%u]", a->nelems);
1529 next_t = btf__type_by_id(d->btf, next_id);
1533 btf_dump_printf(d, " ");
1536 btf_dump_printf(d, "(");
1537 btf_dump_emit_type_chain(d, decls, fname, lvl);
1539 btf_dump_printf(d, ")");
1540 btf_dump_printf(d, "[%u]", a->nelems);
1556 btf_dump_drop_mods(d, decls);
1558 btf_dump_printf(d, " (");
1559 btf_dump_emit_type_chain(d, decls, fname, lvl);
1560 btf_dump_printf(d, ")");
1562 btf_dump_emit_name(d, fname, last_was_ptr);
1564 btf_dump_printf(d, "(");
1574 btf_dump_printf(d, "void)");
1580 btf_dump_printf(d, ", ");
1584 btf_dump_printf(d, "...");
1588 name = btf_name_of(d, p->name_off);
1589 btf_dump_emit_type_decl(d, p->type, name, lvl);
1592 btf_dump_printf(d, ")");
1604 btf_dump_emit_name(d, fname, last_was_ptr);
1608 static void btf_dump_emit_type_cast(struct btf_dump *d, __u32 id,
1617 if (d->typed_dump->is_array_member)
1623 t = btf__type_by_id(d->btf, id);
1628 btf_dump_printf(d, "(");
1630 d->skip_anon_defs = true;
1631 d->strip_mods = true;
1632 btf_dump_emit_type_decl(d, id, "", 0);
1633 d->strip_mods = false;
1634 d->skip_anon_defs = false;
1637 btf_dump_printf(d, ")");
1641 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
1664 static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id,
1667 struct btf_dump_type_aux_state *s = &d->type_states[id];
1668 const struct btf_type *t = btf__type_by_id(d->btf, id);
1669 const char *orig_name = btf_name_of(d, t->name_off);
1670 const char **cached_name = &d->cached_names[id];
1684 dup_cnt = btf_dump_name_dups(d, name_map, orig_name);
1697 static const char *btf_dump_type_name(struct btf_dump *d, __u32 id)
1699 return btf_dump_resolve_name(d, id, d->type_names);
1702 static const char *btf_dump_ident_name(struct btf_dump *d, __u32 id)
1704 return btf_dump_resolve_name(d, id, d->ident_names);
1707 static int btf_dump_dump_type_data(struct btf_dump *d,
1715 static const char *btf_dump_data_newline(struct btf_dump *d)
1717 return d->typed_dump->compact || d->typed_dump->depth == 0 ? "" : "\n";
1720 static const char *btf_dump_data_delim(struct btf_dump *d)
1722 return d->typed_dump->depth == 0 ? "" : ",";
1725 static void btf_dump_data_pfx(struct btf_dump *d)
1727 int i, lvl = d->typed_dump->indent_lvl + d->typed_dump->depth;
1729 if (d->typed_dump->compact)
1733 btf_dump_printf(d, "%s", d->typed_dump->indent_str);
1741 #define btf_dump_type_values(d, fmt, ...) \
1742 btf_dump_printf(d, fmt "%s%s", \
1744 btf_dump_data_delim(d), \
1745 btf_dump_data_newline(d))
1747 static int btf_dump_unsupported_data(struct btf_dump *d,
1751 btf_dump_printf(d, "<unsupported kind:%u>", btf_kind(t));
1755 static int btf_dump_get_bitfield_value(struct btf_dump *d,
1774 if (data + nr_bytes > d->typed_dump->data_end)
1779 pr_warn("unexpected bitfield size %d\n", t->size);
1805 static int btf_dump_bitfield_check_zero(struct btf_dump *d,
1814 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &check_num);
1822 static int btf_dump_bitfield_data(struct btf_dump *d,
1831 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz, &print_num);
1835 btf_dump_type_values(d, "0x%llx", (unsigned long long)print_num);
1841 static int btf_dump_base_type_check_zero(struct btf_dump *d,
1853 nr_bytes = d->ptr_sz;
1858 pr_warn("unexpected size %d for id [%u]\n", nr_bytes, id);
1878 static int btf_dump_int_data(struct btf_dump *d,
1890 pr_warn("unexpected size %d for id [%u]\n", sz, type_id);
1897 if (!ptr_is_aligned(d->btf, type_id, data)) {
1920 btf_dump_type_values(d, "0x%llx", (unsigned long long)lsi);
1922 btf_dump_type_values(d, "0x%llx%016llx", (unsigned long long)msi,
1928 btf_dump_type_values(d, "%lld", *(long long *)data);
1930 btf_dump_type_values(d, "%llu", *(unsigned long long *)data);
1934 btf_dump_type_values(d, "%d", *(__s32 *)data);
1936 btf_dump_type_values(d, "%u", *(__u32 *)data);
1940 btf_dump_type_values(d, "%d", *(__s16 *)data);
1942 btf_dump_type_values(d, "%u", *(__u16 *)data);
1945 if (d->typed_dump->is_array_char) {
1947 if (d->typed_dump->is_array_terminated)
1950 btf_dump_type_values(d, "'\\0'");
1951 d->typed_dump->is_array_terminated = true;
1955 btf_dump_type_values(d, "'%c'", *(char *)data);
1960 btf_dump_type_values(d, "%d", *(__s8 *)data);
1962 btf_dump_type_values(d, "%u", *(__u8 *)data);
1965 pr_warn("unexpected sz %d for id [%u]\n", sz, type_id);
1973 double d;
1977 static int btf_dump_float_data(struct btf_dump *d,
1987 if (!ptr_is_aligned(d->btf, type_id, data)) {
1994 btf_dump_type_values(d, "%Lf", flp->ld);
1997 btf_dump_type_values(d, "%lf", flp->d);
2000 btf_dump_type_values(d, "%f", flp->f);
2003 pr_warn("unexpected size %d for id [%u]\n", sz, type_id);
2009 static int btf_dump_var_data(struct btf_dump *d,
2035 btf_dump_printf(d, "%s", l);
2037 t = btf__type_by_id(d->btf, type_id);
2038 btf_dump_emit_type_cast(d, type_id, false);
2039 btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off));
2040 return btf_dump_dump_type_data(d, NULL, t, type_id, data, 0, 0);
2043 static int btf_dump_string_data(struct btf_dump *d,
2054 if ((void *)(chars + i) >= d->typed_dump->data_end)
2064 btf_dump_data_pfx(d);
2065 btf_dump_printf(d, "\"");
2079 btf_dump_printf(d, "%c", c);
2081 btf_dump_printf(d, "\\x%02x", (__u8)c);
2084 btf_dump_printf(d, "\"");
2089 static int btf_dump_array_data(struct btf_dump *d,
2102 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL);
2103 elem_size = btf__resolve_size(d->btf, elem_type_id);
2117 if (d->typed_dump->emit_strings &&
2118 btf_dump_string_data(d, t, id, data) == 0) {
2121 d->typed_dump->is_array_char = true;
2132 d->typed_dump->depth++;
2133 btf_dump_printf(d, "[%s", btf_dump_data_newline(d));
2138 is_array_member = d->typed_dump->is_array_member;
2139 d->typed_dump->is_array_member = true;
2140 is_array_terminated = d->typed_dump->is_array_terminated;
2141 d->typed_dump->is_array_terminated = false;
2143 if (d->typed_dump->is_array_terminated)
2145 btf_dump_dump_type_data(d, NULL, elem_type, elem_type_id, data, 0, 0);
2147 d->typed_dump->is_array_member = is_array_member;
2148 d->typed_dump->is_array_terminated = is_array_terminated;
2149 d->typed_dump->depth--;
2150 btf_dump_data_pfx(d);
2151 btf_dump_type_values(d, "]");
2156 static int btf_dump_struct_data(struct btf_dump *d,
2172 d->typed_dump->depth++;
2173 btf_dump_printf(d, "{%s", btf_dump_data_newline(d));
2181 mtype = btf__type_by_id(d->btf, m->type);
2182 mname = btf_name_of(d, m->name_off);
2186 err = btf_dump_dump_type_data(d, mname, mtype, m->type, data + moffset / 8,
2191 d->typed_dump->depth--;
2192 btf_dump_data_pfx(d);
2193 btf_dump_type_values(d, "}");
2202 static int btf_dump_ptr_data(struct btf_dump *d,
2207 if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) {
2208 btf_dump_type_values(d, "%p", *(void **)data);
2212 memcpy(&pt, data, d->ptr_sz);
2213 if (d->ptr_sz == 4)
2214 btf_dump_type_values(d, "0x%x", pt.p);
2216 btf_dump_type_values(d, "0x%llx", pt.lp);
2221 static int btf_dump_get_enum_value(struct btf_dump *d,
2229 if (!ptr_is_aligned(d->btf, id, data)) {
2233 err = btf_dump_get_bitfield_value(d, t, data, 0, 0, &val);
2254 pr_warn("unexpected size %d for enum, id:[%u]\n", t->size, id);
2259 static int btf_dump_enum_data(struct btf_dump *d,
2268 err = btf_dump_get_enum_value(d, t, data, id, &value);
2279 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off));
2283 btf_dump_type_values(d, is_signed ? "%d" : "%u", value);
2290 btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off));
2294 btf_dump_type_values(d, is_signed ? "%lldLL" : "%lluULL",
2300 static int btf_dump_datasec_data(struct btf_dump *d,
2310 btf_dump_type_values(d, "SEC(\"%s\") ", btf_name_of(d, t->name_off));
2313 var = btf__type_by_id(d->btf, vsi->type);
2314 err = btf_dump_dump_type_data(d, NULL, var, vsi->type, data + vsi->offset, 0, 0);
2317 btf_dump_printf(d, ";");
2323 static int btf_dump_type_data_check_overflow(struct btf_dump *d,
2342 return data + nr_bytes > d->typed_dump->data_end ? -E2BIG : nr_bytes;
2345 size = btf__resolve_size(d->btf, id);
2360 t = skip_mods_and_typedefs(d->btf, id, NULL);
2373 if (data + bits_offset / 8 + size > d->typed_dump->data_end)
2382 static int btf_dump_type_data_check_zero(struct btf_dump *d,
2403 if (d->typed_dump->emit_zeroes || d->typed_dump->depth == 0 ||
2404 (d->typed_dump->is_array_member &&
2405 !d->typed_dump->is_array_char))
2408 t = skip_mods_and_typedefs(d->btf, id, NULL);
2413 return btf_dump_bitfield_check_zero(d, t, data, bits_offset, bit_sz);
2414 return btf_dump_base_type_check_zero(d, t, id, data);
2417 return btf_dump_base_type_check_zero(d, t, id, data);
2425 elem_size = btf__resolve_size(d->btf, elem_type_id);
2426 elem_type = skip_mods_and_typedefs(d->btf, elem_type_id, NULL);
2439 err = btf_dump_type_data_check_zero(d, elem_type,
2461 mtype = btf__type_by_id(d->btf, m->type);
2469 err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8,
2478 err = btf_dump_get_enum_value(d, t, data, id, &value);
2490 static int btf_dump_dump_type_data(struct btf_dump *d,
2500 size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset, bit_sz);
2503 err = btf_dump_type_data_check_zero(d, t, id, data, bits_offset, bit_sz);
2512 btf_dump_data_pfx(d);
2514 if (!d->typed_dump->skip_names) {
2516 btf_dump_printf(d, ".%s = ", fname);
2517 btf_dump_emit_type_cast(d, id, true);
2520 t = skip_mods_and_typedefs(d->btf, id, NULL);
2528 err = btf_dump_unsupported_data(d, t, id);
2532 err = btf_dump_bitfield_data(d, t, data, bits_offset, bit_sz);
2534 err = btf_dump_int_data(d, t, id, data, bits_offset);
2537 err = btf_dump_float_data(d, t, id, data);
2540 err = btf_dump_ptr_data(d, t, id, data);
2543 err = btf_dump_array_data(d, t, id, data);
2547 err = btf_dump_struct_data(d, t, id, data);
2556 err = btf_dump_get_bitfield_value(d, t, data, bits_offset, bit_sz,
2561 err = btf_dump_enum_data(d, t, id, &enum_val);
2563 err = btf_dump_enum_data(d, t, id, data);
2566 err = btf_dump_var_data(d, t, id, data);
2569 err = btf_dump_datasec_data(d, t, id, data);
2581 int btf_dump__dump_type_data(struct btf_dump *d, __u32 id,
2592 t = btf__type_by_id(d->btf, id);
2596 d->typed_dump = &typed_dump;
2597 d->typed_dump->data_end = data + data_sz;
2598 d->typed_dump->indent_lvl = OPTS_GET(opts, indent_level, 0);
2602 d->typed_dump->indent_str[0] = '\t';
2604 libbpf_strlcpy(d->typed_dump->indent_str, opts->indent_str,
2605 sizeof(d->typed_dump->indent_str));
2607 d->typed_dump->compact = OPTS_GET(opts, compact, false);
2608 d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false);
2609 d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false);
2610 d->typed_dump->emit_strings = OPTS_GET(opts, emit_strings, false);
2612 ret = btf_dump_dump_type_data(d, NULL, t, id, data, 0, 0);
2614 d->typed_dump = NULL;