diff --git a/cddl/contrib/opensolaris/tools/ctf/dump/dump.c b/cddl/contrib/opensolaris/tools/ctf/dump/dump.c index 740485ddff03..7e50979790be 100644 --- a/cddl/contrib/opensolaris/tools/ctf/dump/dump.c +++ b/cddl/contrib/opensolaris/tools/ctf/dump/dump.c @@ -388,16 +388,13 @@ static int read_types(const ctf_header_t *hp, const ctf_data_t *cd) { void *v = (void *) (cd->cd_ctfdata + hp->cth_typeoff); - const ctf_type_t *tp = v; + ctf_type_t *tp = v; v = (void *) (cd->cd_ctfdata + hp->cth_stroff); - const ctf_type_t *end = v; + ctf_type_t *end = v; ulong_t id; - if (flags != F_STATS) - print_line("- Types "); - if (hp->cth_typeoff & 3) WARN("cth_typeoff is not aligned properly\n"); if (hp->cth_typeoff >= cd->cd_ctflen) @@ -411,6 +408,9 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) if (hp->cth_parlabel || hp->cth_parname) id += 1 << CTF_PARENT_SHIFT; + (void) printf("digraph ctf_types {\n"); + + /* Dump labels */ for (/* */; tp < end; id++) { ulong_t i, n = CTF_INFO_VLEN(tp->ctt_info); size_t size, increment, vlen = 0; @@ -426,7 +426,7 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) } u; if (flags != F_STATS) { - (void) printf(" %c%lu%c ", + (void) printf(" %lu [label=\"%c%lu%c ", id, "[<"[CTF_INFO_ISROOT(tp->ctt_info)], id, "]>"[CTF_INFO_ISROOT(tp->ctt_info)]); } @@ -480,7 +480,7 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) case CTF_K_ARRAY: if (flags != F_STATS) { (void) printf("ARRAY %s content: %u index: %u " - "nelems: %u\n", ref_to_str(tp->ctt_name, + "nelems: %u", ref_to_str(tp->ctt_name, hp, cd), u.ap->cta_contents, u.ap->cta_index, u.ap->cta_nelems); } @@ -526,9 +526,10 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) } if (flags != F_STATS) { - (void) printf(" %s (%zd bytes)\n", - ref_to_str(tp->ctt_name, hp, cd), size); + (void) printf(" %s", + ref_to_str(tp->ctt_name, hp, cd)); +/* if (size >= CTF_LSTRUCT_THRESH) { for (i = 0; i < n; i++, u.lmp++) { (void) printf( @@ -547,6 +548,7 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) u.mp->ctm_offset); } } +*/ } vlen = n * (size >= CTF_LSTRUCT_THRESH ? @@ -555,14 +557,16 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) case CTF_K_ENUM: if (flags != F_STATS) { - (void) printf("ENUM %s\n", + (void) printf("ENUM %s", ref_to_str(tp->ctt_name, hp, cd)); + /* for (i = 0; i < n; i++, u.ep++) { (void) printf("\t%s = %d\n", ref_to_str(u.ep->cte_name, hp, cd), u.ep->cte_value); } + */ } stats.s_nemem += n; @@ -580,33 +584,29 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) case CTF_K_TYPEDEF: if (flags != F_STATS) { - (void) printf("TYPEDEF %s refers to %u", - ref_to_str(tp->ctt_name, hp, cd), - tp->ctt_type); + (void) printf("TYPEDEF %s", + ref_to_str(tp->ctt_name, hp, cd)); } break; case CTF_K_VOLATILE: if (flags != F_STATS) { - (void) printf("VOLATILE %s refers to %u", - ref_to_str(tp->ctt_name, hp, cd), - tp->ctt_type); + (void) printf("VOLATILE %s", + ref_to_str(tp->ctt_name, hp, cd)); } break; case CTF_K_CONST: if (flags != F_STATS) { - (void) printf("CONST %s refers to %u", - ref_to_str(tp->ctt_name, hp, cd), - tp->ctt_type); + (void) printf("CONST %s", + ref_to_str(tp->ctt_name, hp, cd)); } break; case CTF_K_RESTRICT: if (flags != F_STATS) { - (void) printf("RESTRICT %s refers to %u", - ref_to_str(tp->ctt_name, hp, cd), - tp->ctt_type); + (void) printf("RESTRICT %s", + ref_to_str(tp->ctt_name, hp, cd)); } break; @@ -619,7 +619,7 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) } if (flags != F_STATS) - (void) printf("\n"); + (void) printf("\"];\n"); stats.s_ntypes++; stats.s_types[kind]++; @@ -627,6 +627,130 @@ read_types(const ctf_header_t *hp, const ctf_data_t *cd) tp = (ctf_type_t *)((uintptr_t)tp + increment + vlen); } + v = (void *) (cd->cd_ctfdata + hp->cth_typeoff); + tp = v; + + v = (void *) (cd->cd_ctfdata + hp->cth_stroff); + end = v; + + id = 1; + + /* Dump edges */ + for (/* */; tp < end; id++) { + ulong_t i, n = CTF_INFO_VLEN(tp->ctt_info); + size_t size, increment, vlen = 0; + int kind = CTF_INFO_KIND(tp->ctt_info); + + union { + const void *ptr; + ctf_array_t *ap; + const ctf_member_t *mp; + const ctf_lmember_t *lmp; + const ctf_enum_t *ep; + const ushort_t *argp; + } u; + + if (tp->ctt_size == CTF_LSIZE_SENT) { + increment = sizeof (ctf_type_t); + size = (size_t)CTF_TYPE_LSIZE(tp); + } else { + increment = sizeof (ctf_stype_t); + size = tp->ctt_size; + } + u.ptr = (const char *)tp + increment; + + switch (kind) { + case CTF_K_INTEGER: + case CTF_K_FLOAT: + vlen = sizeof (uint_t); + break; + case CTF_K_POINTER: + if (flags != F_STATS) { + (void) printf(" %lu -> %u;\n", id, tp->ctt_type); + } + break; + + case CTF_K_ARRAY: + if (flags != F_STATS) { + /* content */ + (void) printf(" %lu -> %u;\n", id, u.ap->cta_contents); + /* index */ + (void) printf(" %lu -> %u;\n", id, u.ap->cta_index); + } + vlen = sizeof (ctf_array_t); + break; + + case CTF_K_FUNCTION: + if (flags != F_STATS) { + (void) printf(" %lu -> %u [label=\"returns\"];\n", + id, tp->ctt_type); + if (n != 0) { + (void) printf(" %lu -> %u;\n", id, *u.argp++); + for (i = 1; i < n; i++, u.argp++) + (void) printf(" %lu -> %u;\n", id, *u.argp); + } + } + + vlen = sizeof (ushort_t) * (n + (n & 1)); + break; + + case CTF_K_STRUCT: + case CTF_K_UNION: + if (flags != F_STATS) { + if (size >= CTF_LSTRUCT_THRESH) { + for (i = 0; i < n; i++, u.lmp++) { + (void) printf( + " %lu -> %u [label=\"%s\"];\n", + id, u.lmp->ctlm_type, + ref_to_str(u.lmp->ctlm_name, + hp, cd)); + } + } else { + for (i = 0; i < n; i++, u.mp++) { + (void) printf( + " %lu -> %u [label=\"%s\"];\n", + id, u.mp->ctm_type, + ref_to_str(u.mp->ctm_name, + hp, cd)); + } + } + } + + vlen = n * (size >= CTF_LSTRUCT_THRESH ? + sizeof (ctf_lmember_t) : sizeof (ctf_member_t)); + break; + + case CTF_K_ENUM: + vlen = sizeof (ctf_enum_t) * n; + break; + + case CTF_K_FORWARD: + break; + + case CTF_K_TYPEDEF: + case CTF_K_VOLATILE: + case CTF_K_CONST: + case CTF_K_RESTRICT: + if (flags != F_STATS) { + (void) printf(" %lu -> %u;\n", id, + tp->ctt_type); + } + break; + + case CTF_K_UNKNOWN: + break; /* hole in type id space */ + + default: + (void) printf("unexpected kind %u\n", kind); + return (E_ERROR); + } + + + tp = (ctf_type_t *)((uintptr_t)tp + increment + vlen); + } + if (flags != F_STATS) + (void) printf("\n}\n"); + return (E_SUCCESS); }