Lines Matching refs:show

371  * Common data to all BTF show operations. Private show functions can add
373 * in the show callback. See btf_type_show() below.
380 * pass is signalled by show->state.depth_check being set, and if we
381 * encounter a non-zero value we set show->state.depth_to_show to
394 * The various data type show functions all start with a call to
415 void *target; /* target of show operation (seq file, buffer) */
416 void (*showfn)(struct btf_show *show, const char *fmt, va_list args);
456 void (*show)(const struct btf *btf, const struct btf_type *t,
458 struct btf_show *show);
942 * Populate show->state.name with type name information.
947 static const char *btf_show_name(struct btf_show *show)
956 const struct btf_member *m = show->state.member;
959 u32 id = show->state.type_id;
965 show->state.name[0] = '\0';
968 * Don't show type name if we're showing an array member;
969 * in that case we show the array type so don't need to repeat
972 if (show->state.array_member)
977 member = btf_name_by_offset(show->btf, m->name_off);
987 * in our show->state points at the resolved type of the typedef.
989 t = btf_type_by_id(show->btf, id);
1007 * or array string backwards so it will show the expected number of
1020 name = btf_name_by_offset(show->btf,
1047 t = btf_type_skip_qualifiers(show->btf, id);
1054 name = btf_name_by_offset(show->btf, t->name_off);
1084 if (show->flags & BTF_SHOW_NONAME)
1085 snprintf(show->state.name, sizeof(show->state.name), "%s",
1088 snprintf(show->state.name, sizeof(show->state.name),
1103 return show->state.name;
1106 static const char *__btf_show_indent(struct btf_show *show)
1111 if ((indent - show->state.depth) >= indents)
1112 return indent - show->state.depth;
1116 static const char *btf_show_indent(struct btf_show *show)
1118 return show->flags & BTF_SHOW_COMPACT ? "" : __btf_show_indent(show);
1121 static const char *btf_show_newline(struct btf_show *show)
1123 return show->flags & BTF_SHOW_COMPACT ? "" : "\n";
1126 static const char *btf_show_delim(struct btf_show *show)
1128 if (show->state.depth == 0)
1131 if ((show->flags & BTF_SHOW_COMPACT) && show->state.type &&
1132 BTF_INFO_KIND(show->state.type->info) == BTF_KIND_UNION)
1138 __printf(2, 3) static void btf_show(struct btf_show *show, const char *fmt, ...)
1142 if (!show->state.depth_check) {
1144 show->showfn(show, fmt, args);
1154 #define btf_show_type_value(show, fmt, value) \
1157 (show->flags & BTF_SHOW_ZERO) || \
1158 show->state.depth == 0) { \
1159 btf_show(show, "%s%s" fmt "%s%s", \
1160 btf_show_indent(show), \
1161 btf_show_name(show), \
1162 value, btf_show_delim(show), \
1163 btf_show_newline(show)); \
1164 if (show->state.depth > show->state.depth_to_show) \
1165 show->state.depth_to_show = show->state.depth; \
1169 #define btf_show_type_values(show, fmt, ...) \
1171 btf_show(show, "%s%s" fmt "%s%s", btf_show_indent(show), \
1172 btf_show_name(show), \
1173 __VA_ARGS__, btf_show_delim(show), \
1174 btf_show_newline(show)); \
1175 if (show->state.depth > show->state.depth_to_show) \
1176 show->state.depth_to_show = show->state.depth; \
1180 static int btf_show_obj_size_left(struct btf_show *show, void *data)
1182 return show->obj.head + show->obj.size - data;
1186 static bool btf_show_obj_is_safe(struct btf_show *show, void *data, int size)
1188 return data >= show->obj.data &&
1189 (data + size) < (show->obj.data + BTF_SHOW_OBJ_SAFE_SIZE);
1198 static void *__btf_show_obj_safe(struct btf_show *show, void *data, int size)
1200 if (btf_show_obj_is_safe(show, data, size))
1201 return show->obj.safe + (data - show->obj.data);
1233 static void *btf_show_obj_safe(struct btf_show *show,
1241 if (show->flags & BTF_SHOW_UNSAFE)
1244 rt = btf_resolve_size(show->btf, t, &size);
1246 show->state.status = PTR_ERR(rt);
1255 if (show->state.depth == 0) {
1256 show->obj.size = size;
1257 show->obj.head = data;
1280 safe = __btf_show_obj_safe(show, data,
1291 size_left = btf_show_obj_size_left(show, data);
1294 show->state.status = copy_from_kernel_nofault(show->obj.safe,
1296 if (!show->state.status) {
1297 show->obj.data = data;
1298 safe = show->obj.safe;
1306 * Set the type we are starting to show and return a safe data pointer
1309 static void *btf_show_start_type(struct btf_show *show,
1313 show->state.type = t;
1314 show->state.type_id = type_id;
1315 show->state.name[0] = '\0';
1317 return btf_show_obj_safe(show, t, data);
1320 static void btf_show_end_type(struct btf_show *show)
1322 show->state.type = NULL;
1323 show->state.type_id = 0;
1324 show->state.name[0] = '\0';
1327 static void *btf_show_start_aggr_type(struct btf_show *show,
1331 void *safe_data = btf_show_start_type(show, t, type_id, data);
1336 btf_show(show, "%s%s%s", btf_show_indent(show),
1337 btf_show_name(show),
1338 btf_show_newline(show));
1339 show->state.depth++;
1343 static void btf_show_end_aggr_type(struct btf_show *show,
1346 show->state.depth--;
1347 btf_show(show, "%s%s%s%s", btf_show_indent(show), suffix,
1348 btf_show_delim(show), btf_show_newline(show));
1349 btf_show_end_type(show);
1352 static void btf_show_start_member(struct btf_show *show,
1355 show->state.member = m;
1358 static void btf_show_start_array_member(struct btf_show *show)
1360 show->state.array_member = 1;
1361 btf_show_start_member(show, NULL);
1364 static void btf_show_end_member(struct btf_show *show)
1366 show->state.member = NULL;
1369 static void btf_show_end_array_member(struct btf_show *show)
1371 show->state.array_member = 0;
1372 btf_show_end_member(show);
1375 static void *btf_show_start_array_type(struct btf_show *show,
1381 show->state.array_encoding = array_encoding;
1382 show->state.array_terminated = 0;
1383 return btf_show_start_aggr_type(show, t, type_id, data);
1386 static void btf_show_end_array_type(struct btf_show *show)
1388 show->state.array_encoding = 0;
1389 show->state.array_terminated = 0;
1390 btf_show_end_aggr_type(show, "]");
1393 static void *btf_show_start_struct_type(struct btf_show *show,
1398 return btf_show_start_aggr_type(show, t, type_id, data);
1401 static void btf_show_end_struct_type(struct btf_show *show)
1403 btf_show_end_aggr_type(show, "}");
2112 struct btf_show *show)
2114 btf_show(show, "<unsupported kind:%u>", BTF_INFO_KIND(t->info));
2287 static void btf_int128_print(struct btf_show *show, void *data)
2306 btf_show_type_value(show, "0x%llx", lower_num);
2308 btf_show_type_values(show, "0x%llx%016llx", upper_num,
2354 u8 nr_bits, struct btf_show *show)
2374 btf_int128_print(show, print_num);
2381 struct btf_show *show)
2394 btf_bitfield_show(data, bits_offset, nr_bits, show);
2399 struct btf_show *show)
2407 safe_data = btf_show_start_type(show, t, type_id, data);
2413 btf_int_bits_show(btf, t, safe_data, bits_offset, show);
2419 btf_int128_print(show, safe_data);
2423 btf_show_type_value(show, "%lld", *(s64 *)safe_data);
2425 btf_show_type_value(show, "%llu", *(u64 *)safe_data);
2429 btf_show_type_value(show, "%d", *(s32 *)safe_data);
2431 btf_show_type_value(show, "%u", *(u32 *)safe_data);
2435 btf_show_type_value(show, "%d", *(s16 *)safe_data);
2437 btf_show_type_value(show, "%u", *(u16 *)safe_data);
2440 if (show->state.array_encoding == BTF_INT_CHAR) {
2442 if (show->state.array_terminated)
2445 show->state.array_terminated = 1;
2449 btf_show_type_value(show, "'%c'",
2455 btf_show_type_value(show, "%d", *(s8 *)safe_data);
2457 btf_show_type_value(show, "%u", *(u8 *)safe_data);
2460 btf_int_bits_show(btf, t, safe_data, bits_offset, show);
2464 btf_show_end_type(show);
2473 .show = btf_int_show,
2748 u8 bits_offset, struct btf_show *show)
2755 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
2760 struct btf_show *show)
2764 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
2769 struct btf_show *show)
2773 safe_data = btf_show_start_type(show, t, type_id, data);
2778 if (show->flags & BTF_SHOW_PTR_RAW)
2779 btf_show_type_value(show, "0x%px", *(void **)safe_data);
2781 btf_show_type_value(show, "0x%p", *(void **)safe_data);
2782 btf_show_end_type(show);
2797 .show = btf_modifier_show,
2806 .show = btf_ptr_show,
2847 .show = btf_df_show,
3008 struct btf_show *show)
3035 if (!btf_show_start_array_type(show, t, type_id, encoding, data))
3044 btf_show_start_array_member(show);
3046 elem_ops->show(btf, elem_type, elem_type_id, data,
3047 bits_offset, show);
3050 btf_show_end_array_member(show);
3052 if (show->state.array_terminated)
3056 btf_show_end_array_type(show);
3061 struct btf_show *show)
3063 const struct btf_member *m = show->state.member;
3070 if (show->state.depth > 0 && !(show->flags & BTF_SHOW_ZERO)) {
3071 if (!show->state.depth_check) {
3072 show->state.depth_check = show->state.depth + 1;
3073 show->state.depth_to_show = 0;
3075 __btf_array_show(btf, t, type_id, data, bits_offset, show);
3076 show->state.member = m;
3078 if (show->state.depth_check != show->state.depth + 1)
3080 show->state.depth_check = 0;
3082 if (show->state.depth_to_show <= show->state.depth)
3089 __btf_array_show(btf, t, type_id, data, bits_offset, show);
3098 .show = btf_array_show,
3978 struct btf_show *show)
3984 safe_data = btf_show_start_struct_type(show, t, type_id, data);
3996 btf_show_start_member(show, member);
4003 safe_data = btf_show_start_type(show, member_type,
4009 bitfield_size, show);
4010 btf_show_end_type(show);
4013 ops->show(btf, member_type, member->type,
4014 data + bytes_offset, bits8_offset, show);
4017 btf_show_end_member(show);
4020 btf_show_end_struct_type(show);
4025 struct btf_show *show)
4027 const struct btf_member *m = show->state.member;
4034 if (show->state.depth > 0 && !(show->flags & BTF_SHOW_ZERO)) {
4035 if (!show->state.depth_check) {
4036 show->state.depth_check = show->state.depth + 1;
4037 show->state.depth_to_show = 0;
4039 __btf_struct_show(btf, t, type_id, data, bits_offset, show);
4041 show->state.member = m;
4042 if (show->state.depth_check != show->state.depth + 1)
4044 show->state.depth_check = 0;
4046 if (show->state.depth_to_show <= show->state.depth)
4054 __btf_struct_show(btf, t, type_id, data, bits_offset, show);
4063 .show = btf_struct_show,
4193 struct btf_show *show)
4200 safe_data = btf_show_start_type(show, t, type_id, data);
4210 btf_show_type_value(show, "%s",
4214 btf_show_end_type(show);
4219 btf_show_type_value(show, "%d", v);
4221 btf_show_type_value(show, "%u", v);
4222 btf_show_end_type(show);
4231 .show = btf_enum_show,
4296 struct btf_show *show)
4303 safe_data = btf_show_start_type(show, t, type_id, data);
4313 btf_show_type_value(show, "%s",
4317 btf_show_end_type(show);
4322 btf_show_type_value(show, "%lld", v);
4324 btf_show_type_value(show, "%llu", v);
4325 btf_show_end_type(show);
4334 .show = btf_enum64_show,
4421 .show = btf_df_show,
4470 .show = btf_df_show,
4534 .show = btf_var_show,
4659 struct btf_show *show)
4665 if (!btf_show_start_type(show, t, type_id, data))
4668 btf_show_type_value(show, "section (\"%s\") = {",
4673 btf_show(show, ",");
4674 btf_type_ops(var)->show(btf, var, vsi->type,
4675 data + vsi->offset, bits_offset, show);
4677 btf_show_end_type(show);
4686 .show = btf_datasec_show,
4761 .show = btf_df_show,
4865 .show = btf_df_show,
7341 struct btf_show *show)
7345 show->btf = btf;
7346 memset(&show->state, 0, sizeof(show->state));
7347 memset(&show->obj, 0, sizeof(show->obj));
7349 btf_type_ops(t)->show(btf, t, type_id, obj, 0, show);
7352 static void btf_seq_show(struct btf_show *show, const char *fmt,
7355 seq_vprintf((struct seq_file *)show->target, fmt, args);
7381 struct btf_show show;
7386 static void btf_snprintf_show(struct btf_show *show, const char *fmt,
7389 struct btf_show_snprintf *ssnprintf = (struct btf_show_snprintf *)show;
7392 len = vsnprintf(show->target, ssnprintf->len_left, fmt, args);
7404 show->target += len;
7413 ssnprintf.show.target = buf;
7414 ssnprintf.show.flags = flags;
7415 ssnprintf.show.showfn = btf_snprintf_show;
7422 if (ssnprintf.show.state.status)
7423 return ssnprintf.show.state.status;