switch (t->size) { case 8:
value = *(__s64 *)data; break; case 4:
value = *(__s32 *)data; break; case 2:
value = *(__s16 *)data; break; case 1:
value = *(__s8 *)data; break; default: return -EINVAL;
}
for (i = 0; i < btf_vlen(t); i++) { if (value == enums[i].val) {
jsonw_string(d->jw,
btf__name_by_offset(d->btf,
enums[i].name_off)); return 0;
}
}
elem_type = btf__type_by_id(btf, arr->type); /* Not skipping typedef. typedef to char does not count as * a string now.
*/ while (elem_type && btf_is_mod(elem_type))
elem_type = btf__type_by_id(btf, elem_type->type);
if (!elem_type || !btf_is_int(elem_type) || elem_type->size != 1) returnfalse;
if (btf_int_encoding(elem_type) != BTF_INT_CHAR &&
strcmp("char", btf__name_by_offset(btf, elem_type->name_off))) returnfalse;
end_s = s + arr->nelems; while (s < end_s) { if (!*s) returntrue; if (*s <= 0x1f || *s >= 0x7f) returnfalse;
s++;
}
staticint btf_dumper_datasec(conststruct btf_dumper *d, __u32 type_id, constvoid *data)
{ struct btf_var_secinfo *vsi; conststruct btf_type *t; int ret = 0, i, vlen;
t = btf__type_by_id(d->btf, type_id); if (!t) return -EINVAL;
vlen = BTF_INFO_VLEN(t->info);
vsi = (struct btf_var_secinfo *)(t + 1);
jsonw_start_object(d->jw);
jsonw_name(d->jw, btf__name_by_offset(d->btf, t->name_off));
jsonw_start_array(d->jw); for (i = 0; i < vlen; i++) {
ret = btf_dumper_do_type(d, vsi[i].type, 0, data + vsi[i].offset); if (ret) break;
}
jsonw_end_array(d->jw);
jsonw_end_object(d->jw);
if (!type_id) {
BTF_PRINT_ARG("void "); return pos;
}
t = btf__type_by_id(btf, type_id);
switch (BTF_INFO_KIND(t->info)) { case BTF_KIND_INT: case BTF_KIND_TYPEDEF: case BTF_KIND_FLOAT:
BTF_PRINT_ARG("%s ", btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_STRUCT:
BTF_PRINT_ARG("struct %s ",
btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_UNION:
BTF_PRINT_ARG("union %s ",
btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_ENUM: case BTF_KIND_ENUM64:
BTF_PRINT_ARG("enum %s ",
btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_ARRAY:
array = (struct btf_array *)(t + 1);
BTF_PRINT_TYPE(array->type);
BTF_PRINT_ARG("[%u]", array->nelems); break; case BTF_KIND_PTR:
BTF_PRINT_TYPE(t->type);
BTF_PRINT_ARG("* "); break; case BTF_KIND_FWD:
BTF_PRINT_ARG("%s %s ",
BTF_INFO_KFLAG(t->info) ? "union" : "struct",
btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_VOLATILE:
BTF_PRINT_ARG("volatile ");
BTF_PRINT_TYPE(t->type); break; case BTF_KIND_CONST:
BTF_PRINT_ARG("const ");
BTF_PRINT_TYPE(t->type); break; case BTF_KIND_RESTRICT:
BTF_PRINT_ARG("restrict ");
BTF_PRINT_TYPE(t->type); break; case BTF_KIND_FUNC_PROTO:
pos = btf_dump_func(btf, func_sig, t, NULL, pos, size); if (pos == -1) return -1; break; case BTF_KIND_FUNC:
proto_type = btf__type_by_id(btf, t->type);
pos = btf_dump_func(btf, func_sig, proto_type, t, pos, size); if (pos == -1) return -1; break; case BTF_KIND_VAR:
var = (struct btf_var *)(t + 1); if (var->linkage == BTF_VAR_STATIC)
BTF_PRINT_ARG("static ");
BTF_PRINT_TYPE(t->type);
BTF_PRINT_ARG(" %s",
btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_DATASEC:
BTF_PRINT_ARG("section (\"%s\") ",
btf__name_by_offset(btf, t->name_off)); break; case BTF_KIND_UNKN: default: return -1;
}
return pos;
}
staticint btf_dump_func(conststruct btf *btf, char *func_sig, conststruct btf_type *func_proto, conststruct btf_type *func, int pos, int size)
{ int i, vlen;
BTF_PRINT_TYPE(func_proto->type); if (func)
BTF_PRINT_ARG("%s(", btf__name_by_offset(btf, func->name_off)); else
BTF_PRINT_ARG("(");
vlen = BTF_INFO_VLEN(func_proto->info); for (i = 0; i < vlen; i++) { struct btf_param *arg = &((struct btf_param *)(func_proto + 1))[i];
if (i)
BTF_PRINT_ARG(", "); if (arg->type) {
BTF_PRINT_TYPE(arg->type); if (arg->name_off)
BTF_PRINT_ARG("%s",
btf__name_by_offset(btf, arg->name_off)); elseif (pos && func_sig[pos - 1] == ' ') /* Remove unnecessary space for * FUNC_PROTO that does not have * arg->name_off
*/
func_sig[--pos] = '\0';
} else {
BTF_PRINT_ARG("...");
}
}
BTF_PRINT_ARG(")");
return pos;
}
void btf_dumper_type_only(conststruct btf *btf, __u32 type_id, char *func_sig, int size)
{ int err;
/* Search for last '/' under the MAX_PATH_LEN limit */
shortpath = strchr(path + len - MAX_PATH_LEN, '/'); if (shortpath) { if (shortpath < path + strlen("...")) /* We removed a very short prefix, e.g. "/w", and we'll * make the path longer by prefixing with the ellipsis. * Not worth it, keep initial path.
*/ return path; return shortpath;
}
/* File base name length is > MAX_PATH_LEN, search for last '/' */
shortpath = strrchr(path, '/'); if (shortpath) return shortpath;
if (!line || !strlen(line)) return;
line = ltrim(line);
if (linum) { constchar *file = btf__name_by_offset(btf, linfo->file_name_off); constchar *shortfile;
/* More forgiving on file because linum option is * expected to provide more info than the already * available src line.
*/ if (!file)
shortfile = ""; else
shortfile = shorten_path(file);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.