usr/src/lib/libdtrace/common/dt_cc.c
changeset 13758 23432da34147
parent 13501 c3a7090dbc16
child 13944 bbcbb468dc37
equal deleted inserted replaced
13757:2e70a48f5fe2 13758:23432da34147
    20  */
    20  */
    21 
    21 
    22 /*
    22 /*
    23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
    23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
    24  * Copyright (c) 2011, Joyent Inc. All rights reserved.
    24  * Copyright (c) 2011, Joyent Inc. All rights reserved.
    25  * Copyright (c) 2011 by Delphix. All rights reserved.
    25  * Copyright (c) 2012 by Delphix. All rights reserved.
    26  */
    26  */
    27 
    27 
    28 /*
    28 /*
    29  * DTrace D Language Compiler
    29  * DTrace D Language Compiler
    30  *
    30  *
   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 
  1071 		dt_action_normalize(dtp, dnp->dn_expr, sdp);
  1056 		dt_action_normalize(dtp, dnp->dn_expr, sdp);
  1072 		break;
  1057 		break;
  1073 	case DT_ACT_PANIC:
  1058 	case DT_ACT_PANIC:
  1074 		dt_action_panic(dtp, dnp->dn_expr, sdp);
  1059 		dt_action_panic(dtp, dnp->dn_expr, sdp);
  1075 		break;
  1060 		break;
       
  1061 	case DT_ACT_PRINT:
       
  1062 		dt_action_trace(dtp, dnp->dn_expr, sdp);
       
  1063 		break;
  1076 	case DT_ACT_PRINTA:
  1064 	case DT_ACT_PRINTA:
  1077 		dt_action_printa(dtp, dnp->dn_expr, sdp);
  1065 		dt_action_printa(dtp, dnp->dn_expr, sdp);
  1078 		break;
  1066 		break;
  1079 	case DT_ACT_PRINTF:
  1067 	case DT_ACT_PRINTF:
  1080 		dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_PRINTF);
  1068 		dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_PRINTF);
  1100 	case DT_ACT_SYSTEM:
  1088 	case DT_ACT_SYSTEM:
  1101 		dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_SYSTEM);
  1089 		dt_action_printflike(dtp, dnp->dn_expr, sdp, DTRACEACT_SYSTEM);
  1102 		break;
  1090 		break;
  1103 	case DT_ACT_TRACE:
  1091 	case DT_ACT_TRACE:
  1104 		dt_action_trace(dtp, dnp->dn_expr, sdp);
  1092 		dt_action_trace(dtp, dnp->dn_expr, sdp);
  1105 		break;
       
  1106 	case DT_ACT_PRINT:
       
  1107 		dt_action_print(dtp, dnp->dn_expr, sdp);
       
  1108 		break;
  1093 		break;
  1109 	case DT_ACT_TRACEMEM:
  1094 	case DT_ACT_TRACEMEM:
  1110 		dt_action_tracemem(dtp, dnp->dn_expr, sdp);
  1095 		dt_action_tracemem(dtp, dnp->dn_expr, sdp);
  1111 		break;
  1096 		break;
  1112 	case DT_ACT_TRUNC:
  1097 	case DT_ACT_TRUNC:
  2460 		rv = NULL;
  2445 		rv = NULL;
  2461 		break;
  2446 		break;
  2462 	}
  2447 	}
  2463 
  2448 
  2464 out:
  2449 out:
  2465 	if (context != DT_CTX_DTYPE && DT_TREEDUMP_PASS(dtp, 3))
  2450 	if (context != DT_CTX_DTYPE && yypcb->pcb_root != NULL &&
       
  2451 	    DT_TREEDUMP_PASS(dtp, 3))
  2466 		dt_node_printr(yypcb->pcb_root, stderr, 0);
  2452 		dt_node_printr(yypcb->pcb_root, stderr, 0);
  2467 
  2453 
  2468 	if (dtp->dt_cdefs_fd != -1 && (ftruncate64(dtp->dt_cdefs_fd, 0) == -1 ||
  2454 	if (dtp->dt_cdefs_fd != -1 && (ftruncate64(dtp->dt_cdefs_fd, 0) == -1 ||
  2469 	    lseek64(dtp->dt_cdefs_fd, 0, SEEK_SET) == -1 ||
  2455 	    lseek64(dtp->dt_cdefs_fd, 0, SEEK_SET) == -1 ||
  2470 	    ctf_write(dtp->dt_cdefs->dm_ctfp, dtp->dt_cdefs_fd) == CTF_ERR))
  2456 	    ctf_write(dtp->dt_cdefs->dm_ctfp, dtp->dt_cdefs_fd) == CTF_ERR))