Print this page
10823 should ignore DW_TAG_subprogram with DW_AT_declaration tags
10824 GCC7-derived CTF can double qualifiers on arrays
10825 ctfdump -c drops last type
10826 ctfdump -c goes off the rails with a missing parent
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Jason King <jason.king@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>


   8  *
   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.
  13  *
  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]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 #pragma ident   "%Z%%M% %I%     %E% SMI"


  29 
  30 #include <sys/sysmacros.h>
  31 #include <ctf_impl.h>
  32 
  33 /*
  34  * Compare the given input string and length against a table of known C storage
  35  * qualifier keywords.  We just ignore these in ctf_lookup_by_name, below.  To
  36  * do this quickly, we use a pre-computed Perfect Hash Function similar to the
  37  * technique originally described in the classic paper:
  38  *
  39  * R.J. Cichelli, "Minimal Perfect Hash Functions Made Simple",
  40  * Communications of the ACM, Volume 23, Issue 1, January 1980, pp. 17-19.
  41  *
  42  * For an input string S of length N, we use hash H = S[N - 1] + N - 105, which
  43  * for the current set of qualifiers yields a unique H in the range [0 .. 20].
  44  * The hash can be modified when the keyword set changes as necessary.  We also
  45  * store the length of each keyword and check it prior to the final strcmp().
  46  */
  47 static int
  48 isqualifier(const char *s, size_t len)


 294 int
 295 ctf_func_args(ctf_file_t *fp, ulong_t symidx, uint_t argc, ctf_id_t *argv)
 296 {
 297         const ushort_t *dp;
 298         ctf_funcinfo_t f;
 299 
 300         if (ctf_func_info(fp, symidx, &f) == CTF_ERR)
 301                 return (CTF_ERR); /* errno is set for us */
 302 
 303         /*
 304          * The argument data is two ushort_t's past the translation table
 305          * offset: one for the function info, and one for the return type.
 306          */
 307         dp = (ushort_t *)((uintptr_t)fp->ctf_buf + fp->ctf_sxlate[symidx]) + 2;
 308 
 309         for (argc = MIN(argc, f.ctc_argc); argc != 0; argc--)
 310                 *argv++ = *dp++;
 311 
 312         return (0);
 313 }

















































   8  *
   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.
  13  *
  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]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 /*
  29  * Copyright 2019, Joyent, Inc.
  30  */
  31 
  32 #include <sys/sysmacros.h>
  33 #include <ctf_impl.h>
  34 
  35 /*
  36  * Compare the given input string and length against a table of known C storage
  37  * qualifier keywords.  We just ignore these in ctf_lookup_by_name, below.  To
  38  * do this quickly, we use a pre-computed Perfect Hash Function similar to the
  39  * technique originally described in the classic paper:
  40  *
  41  * R.J. Cichelli, "Minimal Perfect Hash Functions Made Simple",
  42  * Communications of the ACM, Volume 23, Issue 1, January 1980, pp. 17-19.
  43  *
  44  * For an input string S of length N, we use hash H = S[N - 1] + N - 105, which
  45  * for the current set of qualifiers yields a unique H in the range [0 .. 20].
  46  * The hash can be modified when the keyword set changes as necessary.  We also
  47  * store the length of each keyword and check it prior to the final strcmp().
  48  */
  49 static int
  50 isqualifier(const char *s, size_t len)


 296 int
 297 ctf_func_args(ctf_file_t *fp, ulong_t symidx, uint_t argc, ctf_id_t *argv)
 298 {
 299         const ushort_t *dp;
 300         ctf_funcinfo_t f;
 301 
 302         if (ctf_func_info(fp, symidx, &f) == CTF_ERR)
 303                 return (CTF_ERR); /* errno is set for us */
 304 
 305         /*
 306          * The argument data is two ushort_t's past the translation table
 307          * offset: one for the function info, and one for the return type.
 308          */
 309         dp = (ushort_t *)((uintptr_t)fp->ctf_buf + fp->ctf_sxlate[symidx]) + 2;
 310 
 311         for (argc = MIN(argc, f.ctc_argc); argc != 0; argc--)
 312                 *argv++ = *dp++;
 313 
 314         return (0);
 315 }
 316 
 317 /*
 318  * Unlike the normal lookup routines, ctf_dyn_*() variants consult both the
 319  * processed CTF contents of a ctf_file_t as well as the dynamic types in the
 320  * dtdef list.
 321  */
 322 
 323 const ctf_type_t *
 324 ctf_dyn_lookup_by_id(ctf_file_t *fp, ctf_id_t id)
 325 {
 326         ctf_file_t **fpp = &fp;
 327         const ctf_type_t *t;
 328         ctf_dtdef_t *dtd;
 329 
 330         if ((t = ctf_lookup_by_id(fpp, id)) != NULL)
 331                 return (t);
 332 
 333         if ((dtd = ctf_dtd_lookup(fp, id)) == NULL)
 334                 return (NULL);
 335 
 336         return (&dtd->dtd_data);
 337 }
 338 
 339 int
 340 ctf_dyn_array_info(ctf_file_t *infp, ctf_id_t id, ctf_arinfo_t *arinfop)
 341 {
 342         ctf_file_t *fp = infp;
 343         const ctf_type_t *t;
 344         ctf_dtdef_t *dtd;
 345 
 346         if ((t = ctf_lookup_by_id(&fp, id)) != NULL) {
 347 
 348                 if (LCTF_INFO_KIND(fp, t->ctt_info) != CTF_K_ARRAY)
 349                         return (ctf_set_errno(infp, ECTF_NOTARRAY));
 350 
 351                 return (ctf_array_info(fp, id, arinfop));
 352         }
 353 
 354         if ((dtd = ctf_dtd_lookup(fp, id)) == NULL)
 355                 return (ctf_set_errno(infp, ENOENT));
 356 
 357         if (LCTF_INFO_KIND(fp, dtd->dtd_data.ctt_info) != CTF_K_ARRAY)
 358                 return (ctf_set_errno(infp, ECTF_NOTARRAY));
 359 
 360         bcopy(&dtd->dtd_u.dtu_arr, arinfop, sizeof (*arinfop));
 361         return (0);
 362 }