4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 * Copyright (c) 2013 by Delphix. All rights reserved.
30 * Copyright (c) 2013 Joyent, Inc. All rights reserved.
41 dt_dis_log(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
43 (void) fprintf(fp
, "%-4s %%r%u, %%r%u, %%r%u", name
,
44 DIF_INSTR_R1(in
), DIF_INSTR_R2(in
), DIF_INSTR_RD(in
));
49 dt_dis_branch(const dtrace_difo_t
*dp
, const char *name
,
50 dif_instr_t in
, FILE *fp
)
52 (void) fprintf(fp
, "%-4s %u", name
, DIF_INSTR_LABEL(in
));
57 dt_dis_load(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
59 (void) fprintf(fp
, "%-4s [%%r%u], %%r%u", name
,
60 DIF_INSTR_R1(in
), DIF_INSTR_RD(in
));
65 dt_dis_store(const dtrace_difo_t
*dp
, const char *name
,
66 dif_instr_t in
, FILE *fp
)
68 (void) fprintf(fp
, "%-4s %%r%u, [%%r%u]", name
,
69 DIF_INSTR_R1(in
), DIF_INSTR_RD(in
));
74 dt_dis_str(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
76 (void) fprintf(fp
, "%s", name
);
81 dt_dis_r1rd(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
83 (void) fprintf(fp
, "%-4s %%r%u, %%r%u", name
,
84 DIF_INSTR_R1(in
), DIF_INSTR_RD(in
));
89 dt_dis_cmp(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
91 (void) fprintf(fp
, "%-4s %%r%u, %%r%u", name
,
92 DIF_INSTR_R1(in
), DIF_INSTR_R2(in
));
97 dt_dis_tst(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
99 (void) fprintf(fp
, "%-4s %%r%u", name
, DIF_INSTR_R1(in
));
103 dt_dis_varname(const dtrace_difo_t
*dp
, uint_t id
, uint_t scope
)
105 const dtrace_difv_t
*dvp
= dp
->dtdo_vartab
;
108 for (i
= 0; i
< dp
->dtdo_varlen
; i
++, dvp
++) {
109 if (dvp
->dtdv_id
== id
&& dvp
->dtdv_scope
== scope
) {
110 if (dvp
->dtdv_name
< dp
->dtdo_strlen
)
111 return (dp
->dtdo_strtab
+ dvp
->dtdv_name
);
120 dt_dis_scope(const char *name
)
123 case 'l': return (DIFV_SCOPE_LOCAL
);
124 case 't': return (DIFV_SCOPE_THREAD
);
125 case 'g': return (DIFV_SCOPE_GLOBAL
);
126 default: return (-1u);
131 dt_dis_lda(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
133 uint_t var
= DIF_INSTR_R1(in
);
136 (void) fprintf(fp
, "%-4s DT_VAR(%u), %%r%u, %%r%u", name
,
137 var
, DIF_INSTR_R2(in
), DIF_INSTR_RD(in
));
139 if ((vname
= dt_dis_varname(dp
, var
, dt_dis_scope(name
))) != NULL
)
140 (void) fprintf(fp
, "\t\t! DT_VAR(%u) = \"%s\"", var
, vname
);
144 dt_dis_ldv(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
146 uint_t var
= DIF_INSTR_VAR(in
);
149 (void) fprintf(fp
, "%-4s DT_VAR(%u), %%r%u",
150 name
, var
, DIF_INSTR_RD(in
));
152 if ((vname
= dt_dis_varname(dp
, var
, dt_dis_scope(name
))) != NULL
)
153 (void) fprintf(fp
, "\t\t! DT_VAR(%u) = \"%s\"", var
, vname
);
157 dt_dis_stv(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
159 uint_t var
= DIF_INSTR_VAR(in
);
162 (void) fprintf(fp
, "%-4s %%r%u, DT_VAR(%u)",
163 name
, DIF_INSTR_RS(in
), var
);
165 if ((vname
= dt_dis_varname(dp
, var
, dt_dis_scope(name
))) != NULL
)
166 (void) fprintf(fp
, "\t\t! DT_VAR(%u) = \"%s\"", var
, vname
);
170 dt_dis_setx(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
172 uint_t intptr
= DIF_INSTR_INTEGER(in
);
174 (void) fprintf(fp
, "%-4s DT_INTEGER[%u], %%r%u", name
,
175 intptr
, DIF_INSTR_RD(in
));
177 if (intptr
< dp
->dtdo_intlen
) {
178 (void) fprintf(fp
, "\t\t! 0x%llx",
179 (u_longlong_t
)dp
->dtdo_inttab
[intptr
]);
184 dt_dis_sets(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
186 uint_t strptr
= DIF_INSTR_STRING(in
);
188 (void) fprintf(fp
, "%-4s DT_STRING[%u], %%r%u", name
,
189 strptr
, DIF_INSTR_RD(in
));
191 if (strptr
< dp
->dtdo_strlen
)
192 (void) fprintf(fp
, "\t\t! \"%s\"", dp
->dtdo_strtab
+ strptr
);
197 dt_dis_ret(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
199 (void) fprintf(fp
, "%-4s %%r%u", name
, DIF_INSTR_RD(in
));
204 dt_dis_call(const dtrace_difo_t
*dp
, const char *name
, dif_instr_t in
, FILE *fp
)
206 uint_t subr
= DIF_INSTR_SUBR(in
);
208 (void) fprintf(fp
, "%-4s DIF_SUBR(%u), %%r%u\t\t! %s",
209 name
, subr
, DIF_INSTR_RD(in
), dtrace_subrstr(NULL
, subr
));
214 dt_dis_pushts(const dtrace_difo_t
*dp
,
215 const char *name
, dif_instr_t in
, FILE *fp
)
217 static const char *const tnames
[] = { "D type", "string" };
218 uint_t type
= DIF_INSTR_TYPE(in
);
221 if (DIF_INSTR_OP(in
) == DIF_OP_PUSHTV
) {
222 (void) fprintf(fp
, "%-4s DT_TYPE(%u), %%r%u",
223 name
, type
, DIF_INSTR_RS(in
));
226 (void) fprintf(fp
, "%-4s DT_TYPE(%u), %%r%u, %%r%u",
227 name
, type
, DIF_INSTR_R2(in
), DIF_INSTR_RS(in
));
231 if (type
< sizeof (tnames
) / sizeof (tnames
[0])) {
232 (void) fprintf(fp
, "%s! DT_TYPE(%u) = %s", pad
,
238 dt_dis_xlate(const dtrace_difo_t
*dp
,
239 const char *name
, dif_instr_t in
, FILE *fp
)
241 uint_t xlr
= DIF_INSTR_XLREF(in
);
243 (void) fprintf(fp
, "%-4s DT_XLREF[%u], %%r%u",
244 name
, xlr
, DIF_INSTR_RD(in
));
246 if (xlr
< dp
->dtdo_xlmlen
) {
247 (void) fprintf(fp
, "\t\t! DT_XLREF[%u] = %u.%s", xlr
,
248 (uint_t
)dp
->dtdo_xlmtab
[xlr
]->dn_membexpr
->dn_xlator
->dx_id
,
249 dp
->dtdo_xlmtab
[xlr
]->dn_membname
);
254 dt_dis_typestr(const dtrace_diftype_t
*t
, char *buf
, size_t len
)
256 char kind
[16], ckind
[16];
258 switch (t
->dtdt_kind
) {
260 (void) strcpy(kind
, "D type");
262 case DIF_TYPE_STRING
:
263 (void) strcpy(kind
, "string");
266 (void) snprintf(kind
, sizeof (kind
), "0x%x", t
->dtdt_kind
);
269 switch (t
->dtdt_ckind
) {
271 (void) strcpy(ckind
, "unknown");
274 (void) strcpy(ckind
, "integer");
277 (void) strcpy(ckind
, "float");
280 (void) strcpy(ckind
, "pointer");
283 (void) strcpy(ckind
, "array");
286 (void) strcpy(ckind
, "function");
289 (void) strcpy(ckind
, "struct");
292 (void) strcpy(ckind
, "union");
295 (void) strcpy(ckind
, "enum");
298 (void) strcpy(ckind
, "forward");
301 (void) strcpy(ckind
, "typedef");
304 (void) strcpy(ckind
, "volatile");
307 (void) strcpy(ckind
, "const");
310 (void) strcpy(ckind
, "restrict");
313 (void) snprintf(ckind
, sizeof (ckind
), "0x%x", t
->dtdt_ckind
);
316 if (t
->dtdt_flags
& (DIF_TF_BYREF
| DIF_TF_BYUREF
)) {
317 (void) snprintf(buf
, len
, "%s (%s) by %sref (size %lu)",
318 kind
, ckind
, (t
->dtdt_flags
& DIF_TF_BYUREF
) ? "user " : "",
319 (ulong_t
)t
->dtdt_size
);
321 (void) snprintf(buf
, len
, "%s (%s) (size %lu)",
322 kind
, ckind
, (ulong_t
)t
->dtdt_size
);
329 dt_dis_rtab(const char *rtag
, const dtrace_difo_t
*dp
, FILE *fp
,
330 const dof_relodesc_t
*rp
, uint32_t len
)
332 (void) fprintf(fp
, "\n%-4s %-8s %-8s %s\n",
333 rtag
, "OFFSET", "DATA", "NAME");
335 for (; len
!= 0; len
--, rp
++) {
336 (void) fprintf(fp
, "%-4u %-8llu %-8llu %s\n",
337 rp
->dofr_type
, (u_longlong_t
)rp
->dofr_offset
,
338 (u_longlong_t
)rp
->dofr_data
,
339 &dp
->dtdo_strtab
[rp
->dofr_name
]);
344 dt_dis(const dtrace_difo_t
*dp
, FILE *fp
)
346 static const struct opent
{
348 void (*op_func
)(const dtrace_difo_t
*, const char *,
349 dif_instr_t
, FILE *);
351 { "(illegal opcode)", dt_dis_str
},
352 { "or", dt_dis_log
}, /* DIF_OP_OR */
353 { "xor", dt_dis_log
}, /* DIF_OP_XOR */
354 { "and", dt_dis_log
}, /* DIF_OP_AND */
355 { "sll", dt_dis_log
}, /* DIF_OP_SLL */
356 { "srl", dt_dis_log
}, /* DIF_OP_SRL */
357 { "sub", dt_dis_log
}, /* DIF_OP_SUB */
358 { "add", dt_dis_log
}, /* DIF_OP_ADD */
359 { "mul", dt_dis_log
}, /* DIF_OP_MUL */
360 { "sdiv", dt_dis_log
}, /* DIF_OP_SDIV */
361 { "udiv", dt_dis_log
}, /* DIF_OP_UDIV */
362 { "srem", dt_dis_log
}, /* DIF_OP_SREM */
363 { "urem", dt_dis_log
}, /* DIF_OP_UREM */
364 { "not", dt_dis_r1rd
}, /* DIF_OP_NOT */
365 { "mov", dt_dis_r1rd
}, /* DIF_OP_MOV */
366 { "cmp", dt_dis_cmp
}, /* DIF_OP_CMP */
367 { "tst", dt_dis_tst
}, /* DIF_OP_TST */
368 { "ba", dt_dis_branch
}, /* DIF_OP_BA */
369 { "be", dt_dis_branch
}, /* DIF_OP_BE */
370 { "bne", dt_dis_branch
}, /* DIF_OP_BNE */
371 { "bg", dt_dis_branch
}, /* DIF_OP_BG */
372 { "bgu", dt_dis_branch
}, /* DIF_OP_BGU */
373 { "bge", dt_dis_branch
}, /* DIF_OP_BGE */
374 { "bgeu", dt_dis_branch
}, /* DIF_OP_BGEU */
375 { "bl", dt_dis_branch
}, /* DIF_OP_BL */
376 { "blu", dt_dis_branch
}, /* DIF_OP_BLU */
377 { "ble", dt_dis_branch
}, /* DIF_OP_BLE */
378 { "bleu", dt_dis_branch
}, /* DIF_OP_BLEU */
379 { "ldsb", dt_dis_load
}, /* DIF_OP_LDSB */
380 { "ldsh", dt_dis_load
}, /* DIF_OP_LDSH */
381 { "ldsw", dt_dis_load
}, /* DIF_OP_LDSW */
382 { "ldub", dt_dis_load
}, /* DIF_OP_LDUB */
383 { "lduh", dt_dis_load
}, /* DIF_OP_LDUH */
384 { "lduw", dt_dis_load
}, /* DIF_OP_LDUW */
385 { "ldx", dt_dis_load
}, /* DIF_OP_LDX */
386 { "ret", dt_dis_ret
}, /* DIF_OP_RET */
387 { "nop", dt_dis_str
}, /* DIF_OP_NOP */
388 { "setx", dt_dis_setx
}, /* DIF_OP_SETX */
389 { "sets", dt_dis_sets
}, /* DIF_OP_SETS */
390 { "scmp", dt_dis_cmp
}, /* DIF_OP_SCMP */
391 { "ldga", dt_dis_lda
}, /* DIF_OP_LDGA */
392 { "ldgs", dt_dis_ldv
}, /* DIF_OP_LDGS */
393 { "stgs", dt_dis_stv
}, /* DIF_OP_STGS */
394 { "ldta", dt_dis_lda
}, /* DIF_OP_LDTA */
395 { "ldts", dt_dis_ldv
}, /* DIF_OP_LDTS */
396 { "stts", dt_dis_stv
}, /* DIF_OP_STTS */
397 { "sra", dt_dis_log
}, /* DIF_OP_SRA */
398 { "call", dt_dis_call
}, /* DIF_OP_CALL */
399 { "pushtr", dt_dis_pushts
}, /* DIF_OP_PUSHTR */
400 { "pushtv", dt_dis_pushts
}, /* DIF_OP_PUSHTV */
401 { "popts", dt_dis_str
}, /* DIF_OP_POPTS */
402 { "flushts", dt_dis_str
}, /* DIF_OP_FLUSHTS */
403 { "ldgaa", dt_dis_ldv
}, /* DIF_OP_LDGAA */
404 { "ldtaa", dt_dis_ldv
}, /* DIF_OP_LDTAA */
405 { "stgaa", dt_dis_stv
}, /* DIF_OP_STGAA */
406 { "sttaa", dt_dis_stv
}, /* DIF_OP_STTAA */
407 { "ldls", dt_dis_ldv
}, /* DIF_OP_LDLS */
408 { "stls", dt_dis_stv
}, /* DIF_OP_STLS */
409 { "allocs", dt_dis_r1rd
}, /* DIF_OP_ALLOCS */
410 { "copys", dt_dis_log
}, /* DIF_OP_COPYS */
411 { "stb", dt_dis_store
}, /* DIF_OP_STB */
412 { "sth", dt_dis_store
}, /* DIF_OP_STH */
413 { "stw", dt_dis_store
}, /* DIF_OP_STW */
414 { "stx", dt_dis_store
}, /* DIF_OP_STX */
415 { "uldsb", dt_dis_load
}, /* DIF_OP_ULDSB */
416 { "uldsh", dt_dis_load
}, /* DIF_OP_ULDSH */
417 { "uldsw", dt_dis_load
}, /* DIF_OP_ULDSW */
418 { "uldub", dt_dis_load
}, /* DIF_OP_ULDUB */
419 { "ulduh", dt_dis_load
}, /* DIF_OP_ULDUH */
420 { "ulduw", dt_dis_load
}, /* DIF_OP_ULDUW */
421 { "uldx", dt_dis_load
}, /* DIF_OP_ULDX */
422 { "rldsb", dt_dis_load
}, /* DIF_OP_RLDSB */
423 { "rldsh", dt_dis_load
}, /* DIF_OP_RLDSH */
424 { "rldsw", dt_dis_load
}, /* DIF_OP_RLDSW */
425 { "rldub", dt_dis_load
}, /* DIF_OP_RLDUB */
426 { "rlduh", dt_dis_load
}, /* DIF_OP_RLDUH */
427 { "rlduw", dt_dis_load
}, /* DIF_OP_RLDUW */
428 { "rldx", dt_dis_load
}, /* DIF_OP_RLDX */
429 { "xlate", dt_dis_xlate
}, /* DIF_OP_XLATE */
430 { "xlarg", dt_dis_xlate
}, /* DIF_OP_XLARG */
433 const struct opent
*op
;
435 char type
[DT_TYPE_NAMELEN
];
437 (void) fprintf(fp
, "\nDIFO 0x%p returns %s\n", (void *)dp
,
438 dt_dis_typestr(&dp
->dtdo_rtype
, type
, sizeof (type
)));
440 (void) fprintf(fp
, "%-3s %-8s %s\n",
441 "OFF", "OPCODE", "INSTRUCTION");
443 for (i
= 0; i
< dp
->dtdo_len
; i
++) {
444 dif_instr_t instr
= dp
->dtdo_buf
[i
];
445 dif_instr_t opcode
= DIF_INSTR_OP(instr
);
447 if (opcode
>= sizeof (optab
) / sizeof (optab
[0]))
448 opcode
= 0; /* force invalid opcode message */
451 (void) fprintf(fp
, "%02lu: %08x ", i
, instr
);
452 op
->op_func(dp
, op
->op_name
, instr
, fp
);
453 (void) fprintf(fp
, "\n");
456 if (dp
->dtdo_varlen
!= 0) {
457 (void) fprintf(fp
, "\n%-16s %-4s %-3s %-3s %-4s %s\n",
458 "NAME", "ID", "KND", "SCP", "FLAG", "TYPE");
461 for (i
= 0; i
< dp
->dtdo_varlen
; i
++) {
462 dtrace_difv_t
*v
= &dp
->dtdo_vartab
[i
];
463 char kind
[4], scope
[4], flags
[16] = { 0 };
465 switch (v
->dtdv_kind
) {
466 case DIFV_KIND_ARRAY
:
467 (void) strcpy(kind
, "arr");
469 case DIFV_KIND_SCALAR
:
470 (void) strcpy(kind
, "scl");
473 (void) snprintf(kind
, sizeof (kind
),
477 switch (v
->dtdv_scope
) {
478 case DIFV_SCOPE_GLOBAL
:
479 (void) strcpy(scope
, "glb");
481 case DIFV_SCOPE_THREAD
:
482 (void) strcpy(scope
, "tls");
484 case DIFV_SCOPE_LOCAL
:
485 (void) strcpy(scope
, "loc");
488 (void) snprintf(scope
, sizeof (scope
),
489 "%u", v
->dtdv_scope
);
492 if (v
->dtdv_flags
& ~(DIFV_F_REF
| DIFV_F_MOD
)) {
493 (void) snprintf(flags
, sizeof (flags
), "/0x%x",
494 v
->dtdv_flags
& ~(DIFV_F_REF
| DIFV_F_MOD
));
497 if (v
->dtdv_flags
& DIFV_F_REF
)
498 (void) strcat(flags
, "/r");
499 if (v
->dtdv_flags
& DIFV_F_MOD
)
500 (void) strcat(flags
, "/w");
502 (void) fprintf(fp
, "%-16s %-4x %-3s %-3s %-4s %s\n",
503 &dp
->dtdo_strtab
[v
->dtdv_name
],
504 v
->dtdv_id
, kind
, scope
, flags
+ 1,
505 dt_dis_typestr(&v
->dtdv_type
, type
, sizeof (type
)));
508 if (dp
->dtdo_xlmlen
!= 0) {
509 (void) fprintf(fp
, "\n%-4s %-3s %-12s %s\n",
510 "XLID", "ARG", "MEMBER", "TYPE");
513 for (i
= 0; i
< dp
->dtdo_xlmlen
; i
++) {
514 dt_node_t
*dnp
= dp
->dtdo_xlmtab
[i
];
515 dt_xlator_t
*dxp
= dnp
->dn_membexpr
->dn_xlator
;
516 (void) fprintf(fp
, "%-4u %-3d %-12s %s\n",
517 (uint_t
)dxp
->dx_id
, dxp
->dx_arg
, dnp
->dn_membname
,
518 dt_node_type_name(dnp
, type
, sizeof (type
)));
521 if (dp
->dtdo_krelen
!= 0)
522 dt_dis_rtab("KREL", dp
, fp
, dp
->dtdo_kreltab
, dp
->dtdo_krelen
);
524 if (dp
->dtdo_urelen
!= 0)
525 dt_dis_rtab("UREL", dp
, fp
, dp
->dtdo_ureltab
, dp
->dtdo_urelen
);