661 |
661 |
662 static void |
662 static void |
663 dt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) |
663 dt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) |
664 { |
664 { |
665 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); |
665 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); |
|
666 boolean_t istrace = (dnp->dn_ident->di_id == DT_ACT_TRACE); |
|
667 const char *act = istrace ? "trace" : "print"; |
666 |
668 |
667 if (dt_node_is_void(dnp->dn_args)) { |
669 if (dt_node_is_void(dnp->dn_args)) { |
668 dnerror(dnp->dn_args, D_TRACE_VOID, |
670 dnerror(dnp->dn_args, istrace ? D_TRACE_VOID : D_PRINT_VOID, |
669 "trace( ) may not be applied to a void expression\n"); |
671 "%s( ) may not be applied to a void expression\n", act); |
670 } |
672 } |
671 |
673 |
672 if (dt_node_is_dynamic(dnp->dn_args)) { |
674 if (dt_node_resolve(dnp->dn_args, DT_IDENT_XLPTR) != NULL) { |
673 dnerror(dnp->dn_args, D_TRACE_DYN, |
675 dnerror(dnp->dn_args, istrace ? D_TRACE_DYN : D_PRINT_DYN, |
674 "trace( ) may not be applied to a dynamic expression\n"); |
676 "%s( ) may not be applied to a translated pointer\n", act); |
675 } |
677 } |
676 |
678 |
677 dt_cg(yypcb, dnp->dn_args); |
679 dt_cg(yypcb, dnp->dn_args); |
678 ap->dtad_difo = dt_as(yypcb); |
680 |
679 ap->dtad_kind = DTRACEACT_DIFEXPR; |
681 /* |
680 } |
682 * The print() action behaves identically to trace(), except that it |
681 |
683 * stores the CTF type of the argument (if present) within the DOF for |
682 /* |
684 * the DIFEXPR action. To do this, we set the 'dtsd_strdata' to point |
683 * The print() action behaves identically to trace(), except that it stores the |
685 * to the fully-qualified CTF type ID for the result of the DIF |
684 * CTF type of the argument (if present) within the DOF for the DIFEXPR action. |
686 * action. We use the ID instead of the name to handles complex types |
685 * To do this, we set the 'dtsd_strdata' to point to the fully-qualified CTF |
687 * like arrays and function pointers that can't be resolved by |
686 * type ID for the result of the DIF action. We use the ID instead of the name |
688 * ctf_type_lookup(). This is later processed by dtrace_dof_create() |
687 * to handles complex types like arrays and function pointers that can't be |
689 * and turned into a reference into the string table so that we can |
688 * resolved by ctf_type_lookup(). This is later processed by |
690 * get the type information when we process the data after the fact. |
689 * dtrace_dof_create() and turned into a reference into the string table so |
691 */ |
690 * that we can get the type information when we process the data after the |
692 if (dnp->dn_ident->di_id == DT_ACT_PRINT) { |
691 * fact. |
693 dt_node_t *dret; |
692 */ |
694 size_t n; |
693 static void |
695 dt_module_t *dmp; |
694 dt_action_print(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) |
696 |
695 { |
697 dret = yypcb->pcb_dret; |
696 dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); |
698 dmp = dt_module_lookup_by_ctf(dtp, dret->dn_ctfp); |
697 dt_node_t *dret; |
699 |
698 size_t len; |
700 n = snprintf(NULL, 0, "%s`%d", dmp->dm_name, dret->dn_type) + 1; |
699 dt_module_t *dmp; |
701 sdp->dtsd_strdata = dt_alloc(dtp, n); |
700 |
702 if (sdp->dtsd_strdata == NULL) |
701 if (dt_node_is_void(dnp->dn_args)) { |
703 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); |
702 dnerror(dnp->dn_args, D_PRINT_VOID, |
704 (void) snprintf(sdp->dtsd_strdata, n, "%s`%d", dmp->dm_name, |
703 "print( ) may not be applied to a void expression\n"); |
705 dret->dn_type); |
704 } |
706 } |
705 |
|
706 if (dt_node_is_dynamic(dnp->dn_args)) { |
|
707 dnerror(dnp->dn_args, D_PRINT_DYN, |
|
708 "print( ) may not be applied to a dynamic expression\n"); |
|
709 } |
|
710 |
|
711 dt_cg(yypcb, dnp->dn_args); |
|
712 |
|
713 dret = yypcb->pcb_dret; |
|
714 dmp = dt_module_lookup_by_ctf(dtp, dret->dn_ctfp); |
|
715 |
|
716 len = snprintf(NULL, 0, "%s`%d", dmp->dm_name, dret->dn_type) + 1; |
|
717 sdp->dtsd_strdata = dt_alloc(dtp, len); |
|
718 if (sdp->dtsd_strdata == NULL) |
|
719 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); |
|
720 (void) snprintf(sdp->dtsd_strdata, len, "%s`%d", dmp->dm_name, |
|
721 dret->dn_type); |
|
722 |
707 |
723 ap->dtad_difo = dt_as(yypcb); |
708 ap->dtad_difo = dt_as(yypcb); |
724 ap->dtad_kind = DTRACEACT_DIFEXPR; |
709 ap->dtad_kind = DTRACEACT_DIFEXPR; |
725 } |
710 } |
726 |
711 |