Print this page
4474 DTrace Userland CTF Support
4475 DTrace userland Keyword
4476 DTrace tests should be better citizens
4479 pid provider types
4480 dof emulation missing checks
Reviewed by: Bryan Cantrill <bryan@joyent.com>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.

  25  */
  26 
  27 #include <strings.h>
  28 #include <stdlib.h>
  29 #include <limits.h>
  30 #include <alloca.h>
  31 #include <assert.h>
  32 
  33 #include <dt_decl.h>
  34 #include <dt_parser.h>
  35 #include <dt_module.h>
  36 #include <dt_impl.h>
  37 
  38 static dt_decl_t *
  39 dt_decl_check(dt_decl_t *ddp)
  40 {
  41         if (ddp->dd_kind == CTF_K_UNKNOWN)
  42                 return (ddp); /* nothing to check if the type is not yet set */
  43 
  44         if (ddp->dd_name != NULL && strcmp(ddp->dd_name, "char") == 0 &&


 758                         xyerror(D_DECL_IDRED,
 759                             "identifier redeclared: %s\n", name);
 760                 } else
 761                         return;
 762         }
 763 
 764         dt_dprintf("add global enumerator %s = %d\n", name, value);
 765 
 766         idp = dt_idhash_insert(dtp->dt_globals, name, DT_IDENT_ENUM,
 767             DT_IDFLG_INLINE | DT_IDFLG_REF, 0, _dtrace_defattr, 0,
 768             &dt_idops_inline, NULL, dtp->dt_gen);
 769 
 770         if (idp == NULL)
 771                 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
 772 
 773         yyintprefix = 0;
 774         yyintsuffix[0] = '\0';
 775         yyintdecimal = 0;
 776 
 777         dnp = dt_node_int(value);
 778         dt_node_type_assign(dnp, dsp->ds_ctfp, dsp->ds_type);
 779 
 780         if ((inp = malloc(sizeof (dt_idnode_t))) == NULL)
 781                 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
 782 
 783         /*
 784          * Remove the INT node from the node allocation list and store it in
 785          * din_list and din_root so it persists with and is freed by the ident.
 786          */
 787         assert(yypcb->pcb_list == dnp);
 788         yypcb->pcb_list = dnp->dn_link;
 789         dnp->dn_link = NULL;
 790 
 791         bzero(inp, sizeof (dt_idnode_t));
 792         inp->din_list = dnp;
 793         inp->din_root = dnp;
 794 
 795         idp->di_iarg = inp;
 796         idp->di_ctfp = dsp->ds_ctfp;
 797         idp->di_type = dsp->ds_type;
 798 }


 800 /*
 801  * Look up the type corresponding to the specified decl stack.  The scoping of
 802  * the underlying type names is handled by dt_type_lookup().  We build up the
 803  * name from the specified string and prefixes and then lookup the type.  If
 804  * we fail, an errmsg is saved and the caller must abort with EDT_COMPILER.
 805  */
 806 int
 807 dt_decl_type(dt_decl_t *ddp, dtrace_typeinfo_t *tip)
 808 {
 809         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 810 
 811         dt_module_t *dmp;
 812         ctf_arinfo_t r;
 813         ctf_id_t type;
 814 
 815         char n[DT_TYPE_NAMELEN];
 816         uint_t flag;
 817         char *name;
 818         int rv;
 819 


 820         /*
 821          * Based on our current #include depth and decl stack depth, determine
 822          * which dynamic CTF module and scope to use when adding any new types.
 823          */
 824         dmp = yypcb->pcb_idepth ? dtp->dt_cdefs : dtp->dt_ddefs;
 825         flag = yypcb->pcb_dstack.ds_next ? CTF_ADD_NONROOT : CTF_ADD_ROOT;
 826 



 827         /*
 828          * If we have already cached a CTF type for this decl, then we just
 829          * return the type information for the cached type.
 830          */
 831         if (ddp->dd_ctfp != NULL &&
 832             (dmp = dt_module_lookup_by_ctf(dtp, ddp->dd_ctfp)) != NULL) {
 833                 tip->dtt_object = dmp->dm_name;
 834                 tip->dtt_ctfp = ddp->dd_ctfp;
 835                 tip->dtt_type = ddp->dd_type;
 836                 return (0);
 837         }
 838 
 839         /*
 840          * Currently CTF treats all function pointers identically.  We cache a
 841          * representative ID of kind CTF_K_FUNCTION and just return that type.
 842          * If we want to support full function declarations, dd_next refers to
 843          * the declaration of the function return type, and the parameter list
 844          * should be parsed and hung off a new pointer inside of this decl.
 845          */
 846         if (ddp->dd_kind == CTF_K_FUNCTION) {




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2013 by Delphix. All rights reserved.
  25  * Copyright (c) 2013 Joyent, Inc. All rights reserved.
  26  */
  27 
  28 #include <strings.h>
  29 #include <stdlib.h>
  30 #include <limits.h>
  31 #include <alloca.h>
  32 #include <assert.h>
  33 
  34 #include <dt_decl.h>
  35 #include <dt_parser.h>
  36 #include <dt_module.h>
  37 #include <dt_impl.h>
  38 
  39 static dt_decl_t *
  40 dt_decl_check(dt_decl_t *ddp)
  41 {
  42         if (ddp->dd_kind == CTF_K_UNKNOWN)
  43                 return (ddp); /* nothing to check if the type is not yet set */
  44 
  45         if (ddp->dd_name != NULL && strcmp(ddp->dd_name, "char") == 0 &&


 759                         xyerror(D_DECL_IDRED,
 760                             "identifier redeclared: %s\n", name);
 761                 } else
 762                         return;
 763         }
 764 
 765         dt_dprintf("add global enumerator %s = %d\n", name, value);
 766 
 767         idp = dt_idhash_insert(dtp->dt_globals, name, DT_IDENT_ENUM,
 768             DT_IDFLG_INLINE | DT_IDFLG_REF, 0, _dtrace_defattr, 0,
 769             &dt_idops_inline, NULL, dtp->dt_gen);
 770 
 771         if (idp == NULL)
 772                 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
 773 
 774         yyintprefix = 0;
 775         yyintsuffix[0] = '\0';
 776         yyintdecimal = 0;
 777 
 778         dnp = dt_node_int(value);
 779         dt_node_type_assign(dnp, dsp->ds_ctfp, dsp->ds_type, B_FALSE);
 780 
 781         if ((inp = malloc(sizeof (dt_idnode_t))) == NULL)
 782                 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
 783 
 784         /*
 785          * Remove the INT node from the node allocation list and store it in
 786          * din_list and din_root so it persists with and is freed by the ident.
 787          */
 788         assert(yypcb->pcb_list == dnp);
 789         yypcb->pcb_list = dnp->dn_link;
 790         dnp->dn_link = NULL;
 791 
 792         bzero(inp, sizeof (dt_idnode_t));
 793         inp->din_list = dnp;
 794         inp->din_root = dnp;
 795 
 796         idp->di_iarg = inp;
 797         idp->di_ctfp = dsp->ds_ctfp;
 798         idp->di_type = dsp->ds_type;
 799 }


 801 /*
 802  * Look up the type corresponding to the specified decl stack.  The scoping of
 803  * the underlying type names is handled by dt_type_lookup().  We build up the
 804  * name from the specified string and prefixes and then lookup the type.  If
 805  * we fail, an errmsg is saved and the caller must abort with EDT_COMPILER.
 806  */
 807 int
 808 dt_decl_type(dt_decl_t *ddp, dtrace_typeinfo_t *tip)
 809 {
 810         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 811 
 812         dt_module_t *dmp;
 813         ctf_arinfo_t r;
 814         ctf_id_t type;
 815 
 816         char n[DT_TYPE_NAMELEN];
 817         uint_t flag;
 818         char *name;
 819         int rv;
 820 
 821         tip->dtt_flags = 0;
 822 
 823         /*
 824          * Based on our current #include depth and decl stack depth, determine
 825          * which dynamic CTF module and scope to use when adding any new types.
 826          */
 827         dmp = yypcb->pcb_idepth ? dtp->dt_cdefs : dtp->dt_ddefs;
 828         flag = yypcb->pcb_dstack.ds_next ? CTF_ADD_NONROOT : CTF_ADD_ROOT;
 829 
 830         if (ddp->dd_attr & DT_DA_USER)
 831                 tip->dtt_flags = DTT_FL_USER;
 832 
 833         /*
 834          * If we have already cached a CTF type for this decl, then we just
 835          * return the type information for the cached type.
 836          */
 837         if (ddp->dd_ctfp != NULL &&
 838             (dmp = dt_module_lookup_by_ctf(dtp, ddp->dd_ctfp)) != NULL) {
 839                 tip->dtt_object = dmp->dm_name;
 840                 tip->dtt_ctfp = ddp->dd_ctfp;
 841                 tip->dtt_type = ddp->dd_type;
 842                 return (0);
 843         }
 844 
 845         /*
 846          * Currently CTF treats all function pointers identically.  We cache a
 847          * representative ID of kind CTF_K_FUNCTION and just return that type.
 848          * If we want to support full function declarations, dd_next refers to
 849          * the declaration of the function return type, and the parameter list
 850          * should be parsed and hung off a new pointer inside of this decl.
 851          */
 852         if (ddp->dd_kind == CTF_K_FUNCTION) {