xref: /freebsd-src/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dis.c (revision 51688136b161089b317edc34c3a3e9b40d54a18a)
16ff6d951SJohn Birrell /*
26ff6d951SJohn Birrell  * CDDL HEADER START
36ff6d951SJohn Birrell  *
46ff6d951SJohn Birrell  * The contents of this file are subject to the terms of the
56ff6d951SJohn Birrell  * Common Development and Distribution License, Version 1.0 only
66ff6d951SJohn Birrell  * (the "License").  You may not use this file except in compliance
76ff6d951SJohn Birrell  * with the License.
86ff6d951SJohn Birrell  *
96ff6d951SJohn Birrell  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
106ff6d951SJohn Birrell  * or http://www.opensolaris.org/os/licensing.
116ff6d951SJohn Birrell  * See the License for the specific language governing permissions
126ff6d951SJohn Birrell  * and limitations under the License.
136ff6d951SJohn Birrell  *
146ff6d951SJohn Birrell  * When distributing Covered Code, include this CDDL HEADER in each
156ff6d951SJohn Birrell  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
166ff6d951SJohn Birrell  * If applicable, add the following below this CDDL HEADER, with the
176ff6d951SJohn Birrell  * fields enclosed by brackets "[]" replaced with your own identifying
186ff6d951SJohn Birrell  * information: Portions Copyright [yyyy] [name of copyright owner]
196ff6d951SJohn Birrell  *
206ff6d951SJohn Birrell  * CDDL HEADER END
216ff6d951SJohn Birrell  */
22ba6cafe2SMark Johnston 
236ff6d951SJohn Birrell /*
246ff6d951SJohn Birrell  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
256ff6d951SJohn Birrell  * Use is subject to license terms.
266ff6d951SJohn Birrell  */
276ff6d951SJohn Birrell 
28ba6cafe2SMark Johnston /*
298e648814SRui Paulo  * Copyright (c) 2013 by Delphix. All rights reserved.
308e648814SRui Paulo  * Copyright (c) 2013 Joyent, Inc. All rights reserved.
31ba6cafe2SMark Johnston  */
326ff6d951SJohn Birrell 
336ff6d951SJohn Birrell #include <strings.h>
346ff6d951SJohn Birrell #include <stdio.h>
356ff6d951SJohn Birrell 
366ff6d951SJohn Birrell #include <dt_impl.h>
376ff6d951SJohn Birrell #include <dt_ident.h>
386ff6d951SJohn Birrell 
396ff6d951SJohn Birrell /*ARGSUSED*/
406ff6d951SJohn Birrell static void
416ff6d951SJohn Birrell dt_dis_log(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
426ff6d951SJohn Birrell {
436ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u, %%r%u, %%r%u", name,
446ff6d951SJohn Birrell 	    DIF_INSTR_R1(in), DIF_INSTR_R2(in), DIF_INSTR_RD(in));
456ff6d951SJohn Birrell }
466ff6d951SJohn Birrell 
476ff6d951SJohn Birrell /*ARGSUSED*/
486ff6d951SJohn Birrell static void
496ff6d951SJohn Birrell dt_dis_branch(const dtrace_difo_t *dp, const char *name,
506ff6d951SJohn Birrell 	dif_instr_t in, FILE *fp)
516ff6d951SJohn Birrell {
526ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %u", name, DIF_INSTR_LABEL(in));
536ff6d951SJohn Birrell }
546ff6d951SJohn Birrell 
556ff6d951SJohn Birrell /*ARGSUSED*/
566ff6d951SJohn Birrell static void
576ff6d951SJohn Birrell dt_dis_load(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
586ff6d951SJohn Birrell {
596ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s [%%r%u], %%r%u", name,
606ff6d951SJohn Birrell 	    DIF_INSTR_R1(in), DIF_INSTR_RD(in));
616ff6d951SJohn Birrell }
626ff6d951SJohn Birrell 
636ff6d951SJohn Birrell /*ARGSUSED*/
646ff6d951SJohn Birrell static void
656ff6d951SJohn Birrell dt_dis_store(const dtrace_difo_t *dp, const char *name,
666ff6d951SJohn Birrell 	dif_instr_t in, FILE *fp)
676ff6d951SJohn Birrell {
686ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u, [%%r%u]", name,
696ff6d951SJohn Birrell 	    DIF_INSTR_R1(in), DIF_INSTR_RD(in));
706ff6d951SJohn Birrell }
716ff6d951SJohn Birrell 
726ff6d951SJohn Birrell /*ARGSUSED*/
736ff6d951SJohn Birrell static void
746ff6d951SJohn Birrell dt_dis_str(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
756ff6d951SJohn Birrell {
766ff6d951SJohn Birrell 	(void) fprintf(fp, "%s", name);
776ff6d951SJohn Birrell }
786ff6d951SJohn Birrell 
796ff6d951SJohn Birrell /*ARGSUSED*/
806ff6d951SJohn Birrell static void
816ff6d951SJohn Birrell dt_dis_r1rd(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
826ff6d951SJohn Birrell {
836ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u, %%r%u", name,
846ff6d951SJohn Birrell 	    DIF_INSTR_R1(in), DIF_INSTR_RD(in));
856ff6d951SJohn Birrell }
866ff6d951SJohn Birrell 
876ff6d951SJohn Birrell /*ARGSUSED*/
886ff6d951SJohn Birrell static void
896ff6d951SJohn Birrell dt_dis_cmp(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
906ff6d951SJohn Birrell {
916ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u, %%r%u", name,
926ff6d951SJohn Birrell 	    DIF_INSTR_R1(in), DIF_INSTR_R2(in));
936ff6d951SJohn Birrell }
946ff6d951SJohn Birrell 
956ff6d951SJohn Birrell /*ARGSUSED*/
966ff6d951SJohn Birrell static void
976ff6d951SJohn Birrell dt_dis_tst(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
986ff6d951SJohn Birrell {
996ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u", name, DIF_INSTR_R1(in));
1006ff6d951SJohn Birrell }
1016ff6d951SJohn Birrell 
1026ff6d951SJohn Birrell static const char *
1036ff6d951SJohn Birrell dt_dis_varname(const dtrace_difo_t *dp, uint_t id, uint_t scope)
1046ff6d951SJohn Birrell {
1056ff6d951SJohn Birrell 	const dtrace_difv_t *dvp = dp->dtdo_vartab;
1066ff6d951SJohn Birrell 	uint_t i;
1076ff6d951SJohn Birrell 
1086ff6d951SJohn Birrell 	for (i = 0; i < dp->dtdo_varlen; i++, dvp++) {
1096ff6d951SJohn Birrell 		if (dvp->dtdv_id == id && dvp->dtdv_scope == scope) {
1106ff6d951SJohn Birrell 			if (dvp->dtdv_name < dp->dtdo_strlen)
1116ff6d951SJohn Birrell 				return (dp->dtdo_strtab + dvp->dtdv_name);
1126ff6d951SJohn Birrell 			break;
1136ff6d951SJohn Birrell 		}
1146ff6d951SJohn Birrell 	}
1156ff6d951SJohn Birrell 
1166ff6d951SJohn Birrell 	return (NULL);
1176ff6d951SJohn Birrell }
1186ff6d951SJohn Birrell 
1196ff6d951SJohn Birrell static uint_t
1206ff6d951SJohn Birrell dt_dis_scope(const char *name)
1216ff6d951SJohn Birrell {
1226ff6d951SJohn Birrell 	switch (name[2]) {
1236ff6d951SJohn Birrell 	case 'l': return (DIFV_SCOPE_LOCAL);
1246ff6d951SJohn Birrell 	case 't': return (DIFV_SCOPE_THREAD);
1256ff6d951SJohn Birrell 	case 'g': return (DIFV_SCOPE_GLOBAL);
1266ff6d951SJohn Birrell 	default: return (-1u);
1276ff6d951SJohn Birrell 	}
1286ff6d951SJohn Birrell }
1296ff6d951SJohn Birrell 
1306ff6d951SJohn Birrell static void
1316ff6d951SJohn Birrell dt_dis_lda(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1326ff6d951SJohn Birrell {
1336ff6d951SJohn Birrell 	uint_t var = DIF_INSTR_R1(in);
1346ff6d951SJohn Birrell 	const char *vname;
1356ff6d951SJohn Birrell 
1366ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s DT_VAR(%u), %%r%u, %%r%u", name,
1376ff6d951SJohn Birrell 	    var, DIF_INSTR_R2(in), DIF_INSTR_RD(in));
1386ff6d951SJohn Birrell 
1396ff6d951SJohn Birrell 	if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL)
1406ff6d951SJohn Birrell 		(void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname);
1416ff6d951SJohn Birrell }
1426ff6d951SJohn Birrell 
1436ff6d951SJohn Birrell static void
1446ff6d951SJohn Birrell dt_dis_ldv(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1456ff6d951SJohn Birrell {
1466ff6d951SJohn Birrell 	uint_t var = DIF_INSTR_VAR(in);
1476ff6d951SJohn Birrell 	const char *vname;
1486ff6d951SJohn Birrell 
1496ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s DT_VAR(%u), %%r%u",
1506ff6d951SJohn Birrell 	    name, var, DIF_INSTR_RD(in));
1516ff6d951SJohn Birrell 
1526ff6d951SJohn Birrell 	if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL)
1536ff6d951SJohn Birrell 		(void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname);
1546ff6d951SJohn Birrell }
1556ff6d951SJohn Birrell 
1566ff6d951SJohn Birrell static void
1576ff6d951SJohn Birrell dt_dis_stv(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1586ff6d951SJohn Birrell {
1596ff6d951SJohn Birrell 	uint_t var = DIF_INSTR_VAR(in);
1606ff6d951SJohn Birrell 	const char *vname;
1616ff6d951SJohn Birrell 
1626ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u, DT_VAR(%u)",
1636ff6d951SJohn Birrell 	    name, DIF_INSTR_RS(in), var);
1646ff6d951SJohn Birrell 
1656ff6d951SJohn Birrell 	if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL)
1666ff6d951SJohn Birrell 		(void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname);
1676ff6d951SJohn Birrell }
1686ff6d951SJohn Birrell 
1696ff6d951SJohn Birrell static void
1706ff6d951SJohn Birrell dt_dis_setx(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1716ff6d951SJohn Birrell {
1726ff6d951SJohn Birrell 	uint_t intptr = DIF_INSTR_INTEGER(in);
1736ff6d951SJohn Birrell 
1746ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s DT_INTEGER[%u], %%r%u", name,
1756ff6d951SJohn Birrell 	    intptr, DIF_INSTR_RD(in));
1766ff6d951SJohn Birrell 
1776ff6d951SJohn Birrell 	if (intptr < dp->dtdo_intlen) {
1786ff6d951SJohn Birrell 		(void) fprintf(fp, "\t\t! 0x%llx",
1796ff6d951SJohn Birrell 		    (u_longlong_t)dp->dtdo_inttab[intptr]);
1806ff6d951SJohn Birrell 	}
1816ff6d951SJohn Birrell }
1826ff6d951SJohn Birrell 
1836ff6d951SJohn Birrell static void
1846ff6d951SJohn Birrell dt_dis_sets(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1856ff6d951SJohn Birrell {
1866ff6d951SJohn Birrell 	uint_t strptr = DIF_INSTR_STRING(in);
1876ff6d951SJohn Birrell 
1886ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s DT_STRING[%u], %%r%u", name,
1896ff6d951SJohn Birrell 	    strptr, DIF_INSTR_RD(in));
1906ff6d951SJohn Birrell 
1916ff6d951SJohn Birrell 	if (strptr < dp->dtdo_strlen)
1926ff6d951SJohn Birrell 		(void) fprintf(fp, "\t\t! \"%s\"", dp->dtdo_strtab + strptr);
1936ff6d951SJohn Birrell }
1946ff6d951SJohn Birrell 
1956ff6d951SJohn Birrell /*ARGSUSED*/
1966ff6d951SJohn Birrell static void
1976ff6d951SJohn Birrell dt_dis_ret(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1986ff6d951SJohn Birrell {
1996ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s %%r%u", name, DIF_INSTR_RD(in));
2006ff6d951SJohn Birrell }
2016ff6d951SJohn Birrell 
2026ff6d951SJohn Birrell /*ARGSUSED*/
2036ff6d951SJohn Birrell static void
2046ff6d951SJohn Birrell dt_dis_call(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
2056ff6d951SJohn Birrell {
2066ff6d951SJohn Birrell 	uint_t subr = DIF_INSTR_SUBR(in);
2076ff6d951SJohn Birrell 
2086ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s DIF_SUBR(%u), %%r%u\t\t! %s",
2096ff6d951SJohn Birrell 	    name, subr, DIF_INSTR_RD(in), dtrace_subrstr(NULL, subr));
2106ff6d951SJohn Birrell }
2116ff6d951SJohn Birrell 
2126ff6d951SJohn Birrell /*ARGSUSED*/
2136ff6d951SJohn Birrell static void
2146ff6d951SJohn Birrell dt_dis_pushts(const dtrace_difo_t *dp,
2156ff6d951SJohn Birrell     const char *name, dif_instr_t in, FILE *fp)
2166ff6d951SJohn Birrell {
2176ff6d951SJohn Birrell 	static const char *const tnames[] = { "D type", "string" };
2186ff6d951SJohn Birrell 	uint_t type = DIF_INSTR_TYPE(in);
219ba6cafe2SMark Johnston 	const char *pad;
2206ff6d951SJohn Birrell 
221ba6cafe2SMark Johnston 	if (DIF_INSTR_OP(in) == DIF_OP_PUSHTV) {
222ba6cafe2SMark Johnston 		(void) fprintf(fp, "%-4s DT_TYPE(%u), %%r%u",
223ba6cafe2SMark Johnston 		    name, type, DIF_INSTR_RS(in));
224ba6cafe2SMark Johnston 		pad = "\t\t";
225ba6cafe2SMark Johnston 	} else {
2266ff6d951SJohn Birrell 		(void) fprintf(fp, "%-4s DT_TYPE(%u), %%r%u, %%r%u",
2276ff6d951SJohn Birrell 		    name, type, DIF_INSTR_R2(in), DIF_INSTR_RS(in));
228ba6cafe2SMark Johnston 		pad = "\t";
229ba6cafe2SMark Johnston 	}
2306ff6d951SJohn Birrell 
231ba6cafe2SMark Johnston 	if (type < sizeof (tnames) / sizeof (tnames[0])) {
232ba6cafe2SMark Johnston 		(void) fprintf(fp, "%s! DT_TYPE(%u) = %s", pad,
233ba6cafe2SMark Johnston 		    type, tnames[type]);
234ba6cafe2SMark Johnston 	}
2356ff6d951SJohn Birrell }
2366ff6d951SJohn Birrell 
2376ff6d951SJohn Birrell static void
2386ff6d951SJohn Birrell dt_dis_xlate(const dtrace_difo_t *dp,
2396ff6d951SJohn Birrell     const char *name, dif_instr_t in, FILE *fp)
2406ff6d951SJohn Birrell {
2416ff6d951SJohn Birrell 	uint_t xlr = DIF_INSTR_XLREF(in);
2426ff6d951SJohn Birrell 
2436ff6d951SJohn Birrell 	(void) fprintf(fp, "%-4s DT_XLREF[%u], %%r%u",
2446ff6d951SJohn Birrell 	    name, xlr, DIF_INSTR_RD(in));
2456ff6d951SJohn Birrell 
2466ff6d951SJohn Birrell 	if (xlr < dp->dtdo_xlmlen) {
2476ff6d951SJohn Birrell 		(void) fprintf(fp, "\t\t! DT_XLREF[%u] = %u.%s", xlr,
2486ff6d951SJohn Birrell 		    (uint_t)dp->dtdo_xlmtab[xlr]->dn_membexpr->dn_xlator->dx_id,
2496ff6d951SJohn Birrell 		    dp->dtdo_xlmtab[xlr]->dn_membname);
2506ff6d951SJohn Birrell 	}
2516ff6d951SJohn Birrell }
2526ff6d951SJohn Birrell 
2536ff6d951SJohn Birrell static char *
2546ff6d951SJohn Birrell dt_dis_typestr(const dtrace_diftype_t *t, char *buf, size_t len)
2556ff6d951SJohn Birrell {
2566ff6d951SJohn Birrell 	char kind[16], ckind[16];
2576ff6d951SJohn Birrell 
2586ff6d951SJohn Birrell 	switch (t->dtdt_kind) {
2596ff6d951SJohn Birrell 	case DIF_TYPE_CTF:
2606ff6d951SJohn Birrell 		(void) strcpy(kind, "D type");
2616ff6d951SJohn Birrell 		break;
2626ff6d951SJohn Birrell 	case DIF_TYPE_STRING:
2636ff6d951SJohn Birrell 		(void) strcpy(kind, "string");
2646ff6d951SJohn Birrell 		break;
2656ff6d951SJohn Birrell 	default:
2666ff6d951SJohn Birrell 		(void) snprintf(kind, sizeof (kind), "0x%x", t->dtdt_kind);
2676ff6d951SJohn Birrell 	}
2686ff6d951SJohn Birrell 
2696ff6d951SJohn Birrell 	switch (t->dtdt_ckind) {
2706ff6d951SJohn Birrell 	case CTF_K_UNKNOWN:
2716ff6d951SJohn Birrell 		(void) strcpy(ckind, "unknown");
2726ff6d951SJohn Birrell 		break;
2736ff6d951SJohn Birrell 	case CTF_K_INTEGER:
2746ff6d951SJohn Birrell 		(void) strcpy(ckind, "integer");
2756ff6d951SJohn Birrell 		break;
2766ff6d951SJohn Birrell 	case CTF_K_FLOAT:
2776ff6d951SJohn Birrell 		(void) strcpy(ckind, "float");
2786ff6d951SJohn Birrell 		break;
2796ff6d951SJohn Birrell 	case CTF_K_POINTER:
2806ff6d951SJohn Birrell 		(void) strcpy(ckind, "pointer");
2816ff6d951SJohn Birrell 		break;
2826ff6d951SJohn Birrell 	case CTF_K_ARRAY:
2836ff6d951SJohn Birrell 		(void) strcpy(ckind, "array");
2846ff6d951SJohn Birrell 		break;
2856ff6d951SJohn Birrell 	case CTF_K_FUNCTION:
2866ff6d951SJohn Birrell 		(void) strcpy(ckind, "function");
2876ff6d951SJohn Birrell 		break;
2886ff6d951SJohn Birrell 	case CTF_K_STRUCT:
2896ff6d951SJohn Birrell 		(void) strcpy(ckind, "struct");
2906ff6d951SJohn Birrell 		break;
2916ff6d951SJohn Birrell 	case CTF_K_UNION:
2926ff6d951SJohn Birrell 		(void) strcpy(ckind, "union");
2936ff6d951SJohn Birrell 		break;
2946ff6d951SJohn Birrell 	case CTF_K_ENUM:
2956ff6d951SJohn Birrell 		(void) strcpy(ckind, "enum");
2966ff6d951SJohn Birrell 		break;
2976ff6d951SJohn Birrell 	case CTF_K_FORWARD:
2986ff6d951SJohn Birrell 		(void) strcpy(ckind, "forward");
2996ff6d951SJohn Birrell 		break;
3006ff6d951SJohn Birrell 	case CTF_K_TYPEDEF:
3016ff6d951SJohn Birrell 		(void) strcpy(ckind, "typedef");
3026ff6d951SJohn Birrell 		break;
3036ff6d951SJohn Birrell 	case CTF_K_VOLATILE:
3046ff6d951SJohn Birrell 		(void) strcpy(ckind, "volatile");
3056ff6d951SJohn Birrell 		break;
3066ff6d951SJohn Birrell 	case CTF_K_CONST:
3076ff6d951SJohn Birrell 		(void) strcpy(ckind, "const");
3086ff6d951SJohn Birrell 		break;
3096ff6d951SJohn Birrell 	case CTF_K_RESTRICT:
3106ff6d951SJohn Birrell 		(void) strcpy(ckind, "restrict");
3116ff6d951SJohn Birrell 		break;
3126ff6d951SJohn Birrell 	default:
3136ff6d951SJohn Birrell 		(void) snprintf(ckind, sizeof (ckind), "0x%x", t->dtdt_ckind);
3146ff6d951SJohn Birrell 	}
3156ff6d951SJohn Birrell 
3168e648814SRui Paulo 	if (t->dtdt_flags & (DIF_TF_BYREF | DIF_TF_BYUREF)) {
3178e648814SRui Paulo 		(void) snprintf(buf, len, "%s (%s) by %sref (size %lu)",
3188e648814SRui Paulo 		    kind, ckind, (t->dtdt_flags & DIF_TF_BYUREF) ? "user " : "",
3198e648814SRui Paulo 		    (ulong_t)t->dtdt_size);
3206ff6d951SJohn Birrell 	} else {
3216ff6d951SJohn Birrell 		(void) snprintf(buf, len, "%s (%s) (size %lu)",
3226ff6d951SJohn Birrell 		    kind, ckind, (ulong_t)t->dtdt_size);
3236ff6d951SJohn Birrell 	}
3246ff6d951SJohn Birrell 
3256ff6d951SJohn Birrell 	return (buf);
3266ff6d951SJohn Birrell }
3276ff6d951SJohn Birrell 
3286ff6d951SJohn Birrell static void
3296ff6d951SJohn Birrell dt_dis_rtab(const char *rtag, const dtrace_difo_t *dp, FILE *fp,
3306ff6d951SJohn Birrell     const dof_relodesc_t *rp, uint32_t len)
3316ff6d951SJohn Birrell {
3326ff6d951SJohn Birrell 	(void) fprintf(fp, "\n%-4s %-8s %-8s %s\n",
3336ff6d951SJohn Birrell 	    rtag, "OFFSET", "DATA", "NAME");
3346ff6d951SJohn Birrell 
3356ff6d951SJohn Birrell 	for (; len != 0; len--, rp++) {
3366ff6d951SJohn Birrell 		(void) fprintf(fp, "%-4u %-8llu %-8llu %s\n",
3376ff6d951SJohn Birrell 		    rp->dofr_type, (u_longlong_t)rp->dofr_offset,
3386ff6d951SJohn Birrell 		    (u_longlong_t)rp->dofr_data,
3396ff6d951SJohn Birrell 		    &dp->dtdo_strtab[rp->dofr_name]);
3406ff6d951SJohn Birrell 	}
3416ff6d951SJohn Birrell }
3426ff6d951SJohn Birrell 
3436ff6d951SJohn Birrell void
3446ff6d951SJohn Birrell dt_dis(const dtrace_difo_t *dp, FILE *fp)
3456ff6d951SJohn Birrell {
3466ff6d951SJohn Birrell 	static const struct opent {
3476ff6d951SJohn Birrell 		const char *op_name;
3486ff6d951SJohn Birrell 		void (*op_func)(const dtrace_difo_t *, const char *,
3496ff6d951SJohn Birrell 		    dif_instr_t, FILE *);
3506ff6d951SJohn Birrell 	} optab[] = {
351*51688136SMark Johnston 		[0] = { "(illegal opcode)", dt_dis_str },
352*51688136SMark Johnston 		[DIF_OP_OR] = { "or", dt_dis_log },
353*51688136SMark Johnston 		[DIF_OP_XOR] = { "xor", dt_dis_log },
354*51688136SMark Johnston 		[DIF_OP_AND] = { "and", dt_dis_log },
355*51688136SMark Johnston 		[DIF_OP_SLL] = { "sll", dt_dis_log },
356*51688136SMark Johnston 		[DIF_OP_SRL] = { "srl", dt_dis_log },
357*51688136SMark Johnston 		[DIF_OP_SUB] = { "sub", dt_dis_log },
358*51688136SMark Johnston 		[DIF_OP_ADD] = { "add", dt_dis_log },
359*51688136SMark Johnston 		[DIF_OP_MUL] = { "mul", dt_dis_log },
360*51688136SMark Johnston 		[DIF_OP_SDIV] = { "sdiv", dt_dis_log },
361*51688136SMark Johnston 		[DIF_OP_UDIV] = { "udiv", dt_dis_log },
362*51688136SMark Johnston 		[DIF_OP_SREM] = { "srem", dt_dis_log },
363*51688136SMark Johnston 		[DIF_OP_UREM] = { "urem", dt_dis_log },
364*51688136SMark Johnston 		[DIF_OP_NOT] = { "not", dt_dis_r1rd },
365*51688136SMark Johnston 		[DIF_OP_MOV] = { "mov", dt_dis_r1rd },
366*51688136SMark Johnston 		[DIF_OP_CMP] = { "cmp", dt_dis_cmp },
367*51688136SMark Johnston 		[DIF_OP_TST] = { "tst", dt_dis_tst },
368*51688136SMark Johnston 		[DIF_OP_BA] = { "ba", dt_dis_branch },
369*51688136SMark Johnston 		[DIF_OP_BE] = { "be", dt_dis_branch },
370*51688136SMark Johnston 		[DIF_OP_BNE] = { "bne", dt_dis_branch },
371*51688136SMark Johnston 		[DIF_OP_BG] = { "bg", dt_dis_branch },
372*51688136SMark Johnston 		[DIF_OP_BGU] = { "bgu", dt_dis_branch },
373*51688136SMark Johnston 		[DIF_OP_BGE] = { "bge", dt_dis_branch },
374*51688136SMark Johnston 		[DIF_OP_BGEU] = { "bgeu", dt_dis_branch },
375*51688136SMark Johnston 		[DIF_OP_BL] = { "bl", dt_dis_branch },
376*51688136SMark Johnston 		[DIF_OP_BLU] = { "blu", dt_dis_branch },
377*51688136SMark Johnston 		[DIF_OP_BLE] = { "ble", dt_dis_branch },
378*51688136SMark Johnston 		[DIF_OP_BLEU] = { "bleu", dt_dis_branch },
379*51688136SMark Johnston 		[DIF_OP_LDSB] = { "ldsb", dt_dis_load },
380*51688136SMark Johnston 		[DIF_OP_LDSH] = { "ldsh", dt_dis_load },
381*51688136SMark Johnston 		[DIF_OP_LDSW] = { "ldsw", dt_dis_load },
382*51688136SMark Johnston 		[DIF_OP_LDUB] = { "ldub", dt_dis_load },
383*51688136SMark Johnston 		[DIF_OP_LDUH] = { "lduh", dt_dis_load },
384*51688136SMark Johnston 		[DIF_OP_LDUW] = { "lduw", dt_dis_load },
385*51688136SMark Johnston 		[DIF_OP_LDX] = { "ldx", dt_dis_load },
386*51688136SMark Johnston 		[DIF_OP_RET] = { "ret", dt_dis_ret },
387*51688136SMark Johnston 		[DIF_OP_NOP] = { "nop", dt_dis_str },
388*51688136SMark Johnston 		[DIF_OP_SETX] = { "setx", dt_dis_setx },
389*51688136SMark Johnston 		[DIF_OP_SETS] = { "sets", dt_dis_sets },
390*51688136SMark Johnston 		[DIF_OP_SCMP] = { "scmp", dt_dis_cmp },
391*51688136SMark Johnston 		[DIF_OP_LDGA] = { "ldga", dt_dis_lda },
392*51688136SMark Johnston 		[DIF_OP_LDGS] = { "ldgs", dt_dis_ldv },
393*51688136SMark Johnston 		[DIF_OP_STGS] = { "stgs", dt_dis_stv },
394*51688136SMark Johnston 		[DIF_OP_LDTA] = { "ldta", dt_dis_lda },
395*51688136SMark Johnston 		[DIF_OP_LDTS] = { "ldts", dt_dis_ldv },
396*51688136SMark Johnston 		[DIF_OP_STTS] = { "stts", dt_dis_stv },
397*51688136SMark Johnston 		[DIF_OP_SRA] = { "sra", dt_dis_log },
398*51688136SMark Johnston 		[DIF_OP_CALL] = { "call", dt_dis_call },
399*51688136SMark Johnston 		[DIF_OP_PUSHTR] = { "pushtr", dt_dis_pushts },
400*51688136SMark Johnston 		[DIF_OP_PUSHTV] = { "pushtv", dt_dis_pushts },
401*51688136SMark Johnston 		[DIF_OP_POPTS] = { "popts", dt_dis_str },
402*51688136SMark Johnston 		[DIF_OP_FLUSHTS] = { "flushts", dt_dis_str },
403*51688136SMark Johnston 		[DIF_OP_LDGAA] = { "ldgaa", dt_dis_ldv },
404*51688136SMark Johnston 		[DIF_OP_LDTAA] = { "ldtaa", dt_dis_ldv },
405*51688136SMark Johnston 		[DIF_OP_STGAA] = { "stgaa", dt_dis_stv },
406*51688136SMark Johnston 		[DIF_OP_STTAA] = { "sttaa", dt_dis_stv },
407*51688136SMark Johnston 		[DIF_OP_LDLS] = { "ldls", dt_dis_ldv },
408*51688136SMark Johnston 		[DIF_OP_STLS] = { "stls", dt_dis_stv },
409*51688136SMark Johnston 		[DIF_OP_ALLOCS] = { "allocs", dt_dis_r1rd },
410*51688136SMark Johnston 		[DIF_OP_COPYS] = { "copys", dt_dis_log },
411*51688136SMark Johnston 		[DIF_OP_STB] = { "stb", dt_dis_store },
412*51688136SMark Johnston 		[DIF_OP_STH] = { "sth", dt_dis_store },
413*51688136SMark Johnston 		[DIF_OP_STW] = { "stw", dt_dis_store },
414*51688136SMark Johnston 		[DIF_OP_STX] = { "stx", dt_dis_store },
415*51688136SMark Johnston 		[DIF_OP_ULDSB] = { "uldsb", dt_dis_load },
416*51688136SMark Johnston 		[DIF_OP_ULDSH] = { "uldsh", dt_dis_load },
417*51688136SMark Johnston 		[DIF_OP_ULDSW] = { "uldsw", dt_dis_load },
418*51688136SMark Johnston 		[DIF_OP_ULDUB] = { "uldub", dt_dis_load },
419*51688136SMark Johnston 		[DIF_OP_ULDUH] = { "ulduh", dt_dis_load },
420*51688136SMark Johnston 		[DIF_OP_ULDUW] = { "ulduw", dt_dis_load },
421*51688136SMark Johnston 		[DIF_OP_ULDX] = { "uldx", dt_dis_load },
422*51688136SMark Johnston 		[DIF_OP_RLDSB] = { "rldsb", dt_dis_load },
423*51688136SMark Johnston 		[DIF_OP_RLDSH] = { "rldsh", dt_dis_load },
424*51688136SMark Johnston 		[DIF_OP_RLDSW] = { "rldsw", dt_dis_load },
425*51688136SMark Johnston 		[DIF_OP_RLDUB] = { "rldub", dt_dis_load },
426*51688136SMark Johnston 		[DIF_OP_RLDUH] = { "rlduh", dt_dis_load },
427*51688136SMark Johnston 		[DIF_OP_RLDUW] = { "rlduw", dt_dis_load },
428*51688136SMark Johnston 		[DIF_OP_RLDX] = { "rldx", dt_dis_load },
429*51688136SMark Johnston 		[DIF_OP_XLATE] = { "xlate", dt_dis_xlate },
430*51688136SMark Johnston 		[DIF_OP_XLARG] = { "xlarg", dt_dis_xlate },
4316ff6d951SJohn Birrell 	};
4326ff6d951SJohn Birrell 
4336ff6d951SJohn Birrell 	const struct opent *op;
4346ff6d951SJohn Birrell 	ulong_t i = 0;
4356ff6d951SJohn Birrell 	char type[DT_TYPE_NAMELEN];
4366ff6d951SJohn Birrell 
43711a7f121SMark Johnston 	(void) fprintf(fp, "\nDIFO %p returns %s\n", (void *)dp,
4386ff6d951SJohn Birrell 	    dt_dis_typestr(&dp->dtdo_rtype, type, sizeof (type)));
4396ff6d951SJohn Birrell 
4406ff6d951SJohn Birrell 	(void) fprintf(fp, "%-3s %-8s    %s\n",
4416ff6d951SJohn Birrell 	    "OFF", "OPCODE", "INSTRUCTION");
4426ff6d951SJohn Birrell 
4436ff6d951SJohn Birrell 	for (i = 0; i < dp->dtdo_len; i++) {
4446ff6d951SJohn Birrell 		dif_instr_t instr = dp->dtdo_buf[i];
4456ff6d951SJohn Birrell 		dif_instr_t opcode = DIF_INSTR_OP(instr);
4466ff6d951SJohn Birrell 
4476ff6d951SJohn Birrell 		if (opcode >= sizeof (optab) / sizeof (optab[0]))
4486ff6d951SJohn Birrell 			opcode = 0; /* force invalid opcode message */
4496ff6d951SJohn Birrell 
4506ff6d951SJohn Birrell 		op = &optab[opcode];
4516ff6d951SJohn Birrell 		(void) fprintf(fp, "%02lu: %08x    ", i, instr);
4526ff6d951SJohn Birrell 		op->op_func(dp, op->op_name, instr, fp);
4536ff6d951SJohn Birrell 		(void) fprintf(fp, "\n");
4546ff6d951SJohn Birrell 	}
4556ff6d951SJohn Birrell 
4566ff6d951SJohn Birrell 	if (dp->dtdo_varlen != 0) {
4576ff6d951SJohn Birrell 		(void) fprintf(fp, "\n%-16s %-4s %-3s %-3s %-4s %s\n",
4586ff6d951SJohn Birrell 		    "NAME", "ID", "KND", "SCP", "FLAG", "TYPE");
4596ff6d951SJohn Birrell 	}
4606ff6d951SJohn Birrell 
4616ff6d951SJohn Birrell 	for (i = 0; i < dp->dtdo_varlen; i++) {
4626ff6d951SJohn Birrell 		dtrace_difv_t *v = &dp->dtdo_vartab[i];
4636ff6d951SJohn Birrell 		char kind[4], scope[4], flags[16] = { 0 };
4646ff6d951SJohn Birrell 
4656ff6d951SJohn Birrell 		switch (v->dtdv_kind) {
4666ff6d951SJohn Birrell 		case DIFV_KIND_ARRAY:
4676ff6d951SJohn Birrell 			(void) strcpy(kind, "arr");
4686ff6d951SJohn Birrell 			break;
4696ff6d951SJohn Birrell 		case DIFV_KIND_SCALAR:
4706ff6d951SJohn Birrell 			(void) strcpy(kind, "scl");
4716ff6d951SJohn Birrell 			break;
4726ff6d951SJohn Birrell 		default:
4736ff6d951SJohn Birrell 			(void) snprintf(kind, sizeof (kind),
4746ff6d951SJohn Birrell 			    "%u", v->dtdv_kind);
4756ff6d951SJohn Birrell 		}
4766ff6d951SJohn Birrell 
4776ff6d951SJohn Birrell 		switch (v->dtdv_scope) {
4786ff6d951SJohn Birrell 		case DIFV_SCOPE_GLOBAL:
4796ff6d951SJohn Birrell 			(void) strcpy(scope, "glb");
4806ff6d951SJohn Birrell 			break;
4816ff6d951SJohn Birrell 		case DIFV_SCOPE_THREAD:
4826ff6d951SJohn Birrell 			(void) strcpy(scope, "tls");
4836ff6d951SJohn Birrell 			break;
4846ff6d951SJohn Birrell 		case DIFV_SCOPE_LOCAL:
4856ff6d951SJohn Birrell 			(void) strcpy(scope, "loc");
4866ff6d951SJohn Birrell 			break;
4876ff6d951SJohn Birrell 		default:
4886ff6d951SJohn Birrell 			(void) snprintf(scope, sizeof (scope),
4896ff6d951SJohn Birrell 			    "%u", v->dtdv_scope);
4906ff6d951SJohn Birrell 		}
4916ff6d951SJohn Birrell 
4926ff6d951SJohn Birrell 		if (v->dtdv_flags & ~(DIFV_F_REF | DIFV_F_MOD)) {
4936ff6d951SJohn Birrell 			(void) snprintf(flags, sizeof (flags), "/0x%x",
4946ff6d951SJohn Birrell 			    v->dtdv_flags & ~(DIFV_F_REF | DIFV_F_MOD));
4956ff6d951SJohn Birrell 		}
4966ff6d951SJohn Birrell 
4976ff6d951SJohn Birrell 		if (v->dtdv_flags & DIFV_F_REF)
4986ff6d951SJohn Birrell 			(void) strcat(flags, "/r");
4996ff6d951SJohn Birrell 		if (v->dtdv_flags & DIFV_F_MOD)
5006ff6d951SJohn Birrell 			(void) strcat(flags, "/w");
5016ff6d951SJohn Birrell 
502a46000e8SMark Johnston 		(void) fprintf(fp, "%-16s %-4u %-3s %-3s %-4s %s\n",
5036ff6d951SJohn Birrell 		    &dp->dtdo_strtab[v->dtdv_name],
5046ff6d951SJohn Birrell 		    v->dtdv_id, kind, scope, flags + 1,
5056ff6d951SJohn Birrell 		    dt_dis_typestr(&v->dtdv_type, type, sizeof (type)));
5066ff6d951SJohn Birrell 	}
5076ff6d951SJohn Birrell 
5086ff6d951SJohn Birrell 	if (dp->dtdo_xlmlen != 0) {
5096ff6d951SJohn Birrell 		(void) fprintf(fp, "\n%-4s %-3s %-12s %s\n",
5106ff6d951SJohn Birrell 		    "XLID", "ARG", "MEMBER", "TYPE");
5116ff6d951SJohn Birrell 	}
5126ff6d951SJohn Birrell 
5136ff6d951SJohn Birrell 	for (i = 0; i < dp->dtdo_xlmlen; i++) {
5146ff6d951SJohn Birrell 		dt_node_t *dnp = dp->dtdo_xlmtab[i];
5156ff6d951SJohn Birrell 		dt_xlator_t *dxp = dnp->dn_membexpr->dn_xlator;
5166ff6d951SJohn Birrell 		(void) fprintf(fp, "%-4u %-3d %-12s %s\n",
5176ff6d951SJohn Birrell 		    (uint_t)dxp->dx_id, dxp->dx_arg, dnp->dn_membname,
5186ff6d951SJohn Birrell 		    dt_node_type_name(dnp, type, sizeof (type)));
5196ff6d951SJohn Birrell 	}
5206ff6d951SJohn Birrell 
5216ff6d951SJohn Birrell 	if (dp->dtdo_krelen != 0)
5226ff6d951SJohn Birrell 		dt_dis_rtab("KREL", dp, fp, dp->dtdo_kreltab, dp->dtdo_krelen);
5236ff6d951SJohn Birrell 
5246ff6d951SJohn Birrell 	if (dp->dtdo_urelen != 0)
5256ff6d951SJohn Birrell 		dt_dis_rtab("UREL", dp, fp, dp->dtdo_ureltab, dp->dtdo_urelen);
5266ff6d951SJohn Birrell }
527