Lines Matching defs:cup
295 ctf_dwarf_error(ctf_cu_t *cup, ctf_file_t *cfp, int err, const char *fmt, ...)
300 ssize_t rem = cup->cu_errlen;
307 ret = snprintf(cup->cu_errbuf, rem, "die %s: ", cup->cu_name);
314 ret = vsnprintf(cup->cu_errbuf + off, rem, fmt, ap);
322 (void) snprintf(cup->cu_errbuf + off, rem,
329 cup->cu_errbuf[0] = '\0';
340 ctf_dwarf_void(ctf_cu_t *cup)
342 if (cup->cu_voidtid == CTF_ERR) {
344 cup->cu_voidtid = ctf_add_integer(cup->cu_ctfp, CTF_ADD_ROOT,
346 if (cup->cu_voidtid == CTF_ERR) {
347 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
349 ctf_errmsg(ctf_errno(cup->cu_ctfp)));
353 return (cup->cu_voidtid);
362 ctf_dwarf_long(ctf_cu_t *cup)
364 if (cup->cu_longtid == CTF_ERR) {
370 enc.cte_bits = cup->cu_ptrsz * 8;
371 cup->cu_longtid = ctf_add_integer(cup->cu_ctfp, CTF_ADD_NONROOT,
373 if (cup->cu_longtid == CTF_ERR) {
374 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
376 ctf_errmsg(ctf_errno(cup->cu_ctfp)));
381 return (cup->cu_longtid);
398 ctf_dwmap_add(ctf_cu_t *cup, ctf_id_t id, Dwarf_Die die, boolean_t fix)
407 if ((ret = ctf_dwarf_offset(cup, die, &off)) != 0)
419 VERIFY(avl_find(&cup->cu_map, dwmap, &index) == NULL);
420 avl_insert(&cup->cu_map, dwmap, index);
425 ctf_dwarf_attribute(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name,
437 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
444 ctf_dwarf_ref(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name, Dwarf_Off *refp)
450 if ((ret = ctf_dwarf_attribute(cup, die, name, &attr)) != 0)
454 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
458 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
465 ctf_dwarf_refdie(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name,
472 if ((ret = ctf_dwarf_ref(cup, die, name, &off)) != 0)
475 off += cup->cu_cuoff;
476 if ((ret = dwarf_offdie(cup->cu_dwarf, off, diep, &derr)) !=
478 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
488 ctf_dwarf_signed(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name,
495 if ((ret = ctf_dwarf_attribute(cup, die, name, &attr)) != 0)
499 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
503 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
510 ctf_dwarf_unsigned(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name,
517 if ((ret = ctf_dwarf_attribute(cup, die, name, &attr)) != 0)
521 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
525 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
532 ctf_dwarf_boolean(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name,
539 if ((ret = ctf_dwarf_attribute(cup, die, name, &attr)) != 0)
543 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
547 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
555 ctf_dwarf_string(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half name, char **strp)
563 if ((ret = ctf_dwarf_attribute(cup, die, name, &attr)) != 0)
571 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
575 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
582 ctf_dwarf_member_location(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Unsigned *valp)
590 if ((ret = ctf_dwarf_attribute(cup, die, DW_AT_data_member_location,
595 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
598 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
601 dwarf_dealloc(cup->cu_dwarf, attr, DW_DLA_ATTR);
604 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
606 dwarf_dealloc(cup->cu_dwarf, loc->ld_s, DW_DLA_LOC_BLOCK);
607 dwarf_dealloc(cup->cu_dwarf, loc, DW_DLA_LOCDESC);
613 dwarf_dealloc(cup->cu_dwarf, loc->ld_s, DW_DLA_LOC_BLOCK);
614 dwarf_dealloc(cup->cu_dwarf, loc, DW_DLA_LOCDESC);
620 ctf_dwarf_offset(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Off *offsetp)
627 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
645 ctf_dwarf_tag(ctf_cu_t *cup, Dwarf_Die die, Dwarf_Half *tagp)
652 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
659 ctf_dwarf_sib(ctf_cu_t *cup, Dwarf_Die base, Dwarf_Die *sibp)
665 ret = dwarf_siblingof(cup->cu_dwarf, base, sibp, &derr);
669 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
676 ctf_dwarf_child(ctf_cu_t *cup, Dwarf_Die base, Dwarf_Die *childp)
686 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
699 ctf_dwarf_isglobal(ctf_cu_t *cup, Dwarf_Die die, boolean_t *igp)
705 if ((ret = ctf_dwarf_signed(cup, die, DW_AT_visibility, &vis)) == 0) {
712 if ((ret = ctf_dwarf_boolean(cup, die, DW_AT_external, &ext)) != 0) {
724 ctf_dwarf_die_elfenc(Elf *elf, ctf_cu_t *cup, char *errbuf, size_t errlen)
735 cup->cu_mach = ehdr.e_machine;
738 cup->cu_ptrsz = 4;
739 VERIFY(ctf_setmodel(cup->cu_ctfp, CTF_MODEL_ILP32) == 0);
741 cup->cu_ptrsz = 8;
742 VERIFY(ctf_setmodel(cup->cu_ctfp, CTF_MODEL_LP64) == 0);
750 cup->cu_bigend = B_FALSE;
752 cup->cu_bigend = B_TRUE;
807 ctf_dwarf_float_base(ctf_cu_t *cup, Dwarf_Signed type, ctf_encoding_t *enc)
814 if (map->cdf_mach == cup->cu_mach)
819 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
820 "Unsupported machine type: %d\n", cup->cu_mach);
840 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
847 ctf_dwarf_dwarf_base(ctf_cu_t *cup, Dwarf_Die die, int *kindp,
853 if ((ret = ctf_dwarf_signed(cup, die, DW_AT_encoding, &type)) != 0)
884 if ((ret = ctf_dwarf_float_base(cup, type, enc)) != 0)
888 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
976 ctf_dwarf_create_base(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp, int isroot,
986 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0)
988 if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_byte_size, &sz)) != 0) {
1003 if ((ret = ctf_dwarf_dwarf_base(cup, die, &kind, &enc)) != 0)
1007 id = ctf_add_encoded(cup->cu_ctfp, isroot, name, &enc, kind);
1009 ret = ctf_errno(cup->cu_ctfp);
1012 ret = ctf_dwmap_add(cup, id, die, B_FALSE);
1038 ctf_dwarf_member_offset(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t mid,
1047 if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_data_bit_offset,
1055 if ((ret = ctf_dwarf_member_location(cup, die, &loc)) != 0)
1059 if ((ret = ctf_dwarf_signed(cup, die, DW_AT_bit_offset,
1068 if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_bit_size, &bitsz)) != 0)
1071 if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_byte_size,
1075 if ((tsz = ctf_type_size(cup->cu_ctfp, mid)) == CTF_ERR) {
1076 int e = ctf_errno(cup->cu_ctfp);
1077 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1085 if (cup->cu_bigend == B_TRUE) {
1108 ctf_dwarf_member_bitfield(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp)
1118 if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_bit_size, &bitsz)) != 0) {
1133 dtd = ctf_dtd_lookup(cup->cu_ctfp, base);
1138 dtd = ctf_dtd_lookup(cup->cu_ctfp, dtd->dtd_data.ctt_type);
1163 for (cdb = ctf_list_next(&cup->cu_bitfields); cdb != NULL;
1194 cdb->cdb_id = ctf_add_integer(cup->cu_ctfp, CTF_ADD_NONROOT,
1197 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1199 ctf_errmsg(ctf_errno(cup->cu_ctfp)));
1205 ctf_list_append(&cup->cu_bitfields, cdb);
1214 ctf_dwarf_fixup_sou(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t base, boolean_t add)
1221 kind = ctf_type_kind(cup->cu_ctfp, base);
1228 if ((ret = ctf_dwarf_child(cup, die, &child)) != 0)
1241 if ((ret = ctf_dwarf_tag(cup, memb, &tag)) != 0)
1247 if ((ret = ctf_dwarf_refdie(cup, memb, DW_AT_type, &tdie)) != 0)
1250 if ((ret = ctf_dwarf_convert_type(cup, tdie, &mid,
1259 if ((ret = ctf_dwarf_member_bitfield(cup, memb,
1265 if ((ret = ctf_dwarf_string(cup, memb, DW_AT_name,
1273 } else if ((ret = ctf_dwarf_member_offset(cup, memb, mid,
1280 if ((ret = ctf_dwarf_member_bitfield(cup, memb, &mid)) != 0)
1283 ret = ctf_add_member(cup->cu_ctfp, base, mname, mid, memboff);
1285 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1287 mname, ctf_errmsg(ctf_errno(cup->cu_ctfp)));
1297 if ((ret = ctf_dwarf_sib(cup, memb, &sib)) != 0)
1310 if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_byte_size, &size)) != 0)
1313 if ((ctf_set_size(cup->cu_ctfp, base, nsz)) == CTF_ERR) {
1314 int e = ctf_errno(cup->cu_ctfp);
1315 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1325 ctf_dwarf_create_sou(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp,
1338 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0 &&
1350 if ((ret = ctf_dwarf_boolean(cup, die, DW_AT_declaration,
1358 base = ctf_add_forward(cup->cu_ctfp, isroot, name, kind);
1360 base = ctf_add_struct(cup->cu_ctfp, isroot, name);
1362 base = ctf_add_union(cup->cu_ctfp, isroot, name);
1368 return (ctf_errno(cup->cu_ctfp));
1376 return (ctf_dwmap_add(cup, base, die, B_FALSE));
1377 if ((ret = ctf_dwmap_add(cup, base, die, B_TRUE)) != 0)
1383 if ((ret = ctf_dwarf_child(cup, die, &child)) != 0)
1392 ctf_dwarf_create_array_range(ctf_cu_t *cup, Dwarf_Die range, ctf_id_t *idp,
1403 if ((ret = ctf_dwarf_sib(cup, range, &sib)) != 0)
1407 if ((ret = ctf_dwarf_create_array_range(cup, sib, &id,
1415 if ((ar.ctr_index = ctf_dwarf_long(cup)) == CTF_ERR)
1416 return (ctf_errno(cup->cu_ctfp));
1429 if ((ret = ctf_dwarf_unsigned(cup, range, DW_AT_upper_bound,
1434 } else if ((ret = ctf_dwarf_signed(cup, range, DW_AT_upper_bound,
1443 if ((*idp = ctf_add_array(cup->cu_ctfp, isroot, &ar)) == CTF_ERR)
1444 return (ctf_errno(cup->cu_ctfp));
1455 ctf_dwarf_create_array(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp, int isroot)
1462 if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_type, &tdie)) != 0)
1464 if ((ret = ctf_dwarf_convert_type(cup, tdie, &tid,
1468 if ((ret = ctf_dwarf_child(cup, die, &rdie)) != 0)
1470 if ((ret = ctf_dwarf_tag(cup, rdie, &rtag)) != 0)
1473 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1484 if ((ret = ctf_dwarf_create_array_range(cup, rdie, idp, tid,
1488 return (ctf_dwmap_add(cup, *idp, die, B_FALSE));
1492 ctf_dwarf_create_reference(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp,
1501 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0 &&
1513 if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_type, &tdie)) != 0) {
1518 if ((id = ctf_dwarf_void(cup)) == CTF_ERR) {
1520 return (ctf_errno(cup->cu_ctfp));
1523 if ((ret = ctf_dwarf_convert_type(cup, tdie, &id,
1530 if ((*idp = ctf_add_reftype(cup->cu_ctfp, isroot, name, id, kind)) ==
1533 return (ctf_errno(cup->cu_ctfp));
1537 return (ctf_dwmap_add(cup, *idp, die, B_FALSE));
1541 ctf_dwarf_create_enum(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp, int isroot)
1548 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0 &&
1553 id = ctf_add_enum(cup->cu_ctfp, isroot, name);
1558 return (ctf_errno(cup->cu_ctfp));
1560 if ((ret = ctf_dwmap_add(cup, id, die, B_FALSE)) != 0)
1563 if ((ret = ctf_dwarf_child(cup, die, &child)) != 0) {
1576 if ((ret = ctf_dwarf_sib(cup, arg, &child)) != 0)
1579 if ((ret = ctf_dwarf_tag(cup, arg, &tag)) != 0)
1583 if ((ret = ctf_dwarf_convert_type(cup, arg, NULL,
1592 if ((ret = ctf_dwarf_string(cup, arg, DW_AT_name, &name)) != 0)
1601 if ((ret = ctf_dwarf_unsigned(cup, arg, DW_AT_const_value,
1604 } else if ((ret = ctf_dwarf_signed(cup, arg, DW_AT_const_value,
1613 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1618 ret = ctf_add_enumerator(cup->cu_ctfp, id, name, eval);
1620 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1624 return (ctf_errno(cup->cu_ctfp));
1637 ctf_dwarf_create_fptr(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp, int isroot)
1647 if ((ret = ctf_dwarf_boolean(cup, die, DW_AT_declaration, &b)) != 0) {
1658 if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_type, &retdie)) != 0) {
1661 if ((fi.ctc_return = ctf_dwarf_void(cup)) == CTF_ERR)
1662 return (ctf_errno(cup->cu_ctfp));
1664 if ((ret = ctf_dwarf_convert_type(cup, retdie, &fi.ctc_return,
1669 if ((ret = ctf_dwarf_function_count(cup, die, &fi, B_TRUE)) != 0) {
1678 if ((ret = ctf_dwarf_convert_fargs(cup, die, &fi, argv)) != 0) {
1684 if ((*idp = ctf_add_funcptr(cup->cu_ctfp, isroot, &fi, argv)) ==
1687 return (ctf_errno(cup->cu_ctfp));
1691 return (ctf_dwmap_add(cup, *idp, die, B_FALSE));
1695 ctf_dwarf_convert_type(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp,
1707 if ((ret = ctf_dwarf_offset(cup, die, &offset)) != 0)
1710 if (offset > cup->cu_maxoff) {
1711 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1713 offset, cup->cu_maxoff);
1721 if ((map = avl_find(&cup->cu_map, &lookup, NULL)) != NULL) {
1726 if ((ret = ctf_dwarf_tag(cup, die, &tag)) != 0)
1733 ret = ctf_dwarf_create_base(cup, die, idp, isroot, offset);
1737 ret = ctf_dwarf_create_array(cup, die, idp, isroot);
1741 ret = ctf_dwarf_create_enum(cup, die, idp, isroot);
1745 ret = ctf_dwarf_create_reference(cup, die, idp, CTF_K_POINTER,
1750 ret = ctf_dwarf_create_sou(cup, die, idp, CTF_K_STRUCT,
1755 ret = ctf_dwarf_create_fptr(cup, die, idp, isroot);
1759 ret = ctf_dwarf_create_reference(cup, die, idp, CTF_K_TYPEDEF,
1764 ret = ctf_dwarf_create_sou(cup, die, idp, CTF_K_UNION,
1769 ret = ctf_dwarf_create_reference(cup, die, idp, CTF_K_CONST,
1774 ret = ctf_dwarf_create_reference(cup, die, idp, CTF_K_VOLATILE,
1779 ret = ctf_dwarf_create_reference(cup, die, idp, CTF_K_RESTRICT,
1794 ctf_dwarf_walk_lexical(ctf_cu_t *cup, Dwarf_Die die)
1799 if ((ret = ctf_dwarf_child(cup, die, &child)) != 0)
1805 return (ctf_dwarf_convert_die(cup, die));
1809 ctf_dwarf_function_count(ctf_cu_t *cup, Dwarf_Die die, ctf_funcinfo_t *fip,
1815 if ((ret = ctf_dwarf_child(cup, die, &child)) != 0)
1822 if ((ret = ctf_dwarf_tag(cup, arg, &tag)) != 0)
1840 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name,
1854 if ((ret = ctf_dwarf_sib(cup, arg, &sib)) != 0)
1863 ctf_dwarf_convert_fargs(ctf_cu_t *cup, Dwarf_Die die, ctf_funcinfo_t *fip,
1870 if ((ret = ctf_dwarf_child(cup, die, &child)) != 0)
1877 if ((ret = ctf_dwarf_tag(cup, arg, &tag)) != 0)
1882 if ((ret = ctf_dwarf_refdie(cup, arg, DW_AT_type,
1886 if ((ret = ctf_dwarf_convert_type(cup, tdie, &argv[i],
1900 if ((ret = ctf_dwarf_sib(cup, arg, &sib)) != 0)
1909 ctf_dwarf_convert_function(ctf_cu_t *cup, Dwarf_Die die)
1922 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0) {
1936 if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_type, &tdie)) == 0) {
1937 if ((ret = ctf_dwarf_convert_type(cup, tdie,
1948 if ((cdf->cdf_fip.ctc_return = ctf_dwarf_void(cup)) ==
1952 return (ctf_errno(cup->cu_ctfp));
1966 if ((ret = ctf_dwarf_function_count(cup, die, &cdf->cdf_fip,
1982 if ((ret = ctf_dwarf_convert_fargs(cup, die,
1993 if ((ret = ctf_dwarf_isglobal(cup, die, &cdf->cdf_global)) != 0) {
2001 ctf_list_append(&cup->cu_funcs, cdf);
2009 ctf_dwarf_convert_variable(ctf_cu_t *cup, Dwarf_Die die)
2019 if ((ret = ctf_dwarf_boolean(cup, die, DW_AT_declaration, &b)) == 0) {
2033 if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_specification,
2036 if ((ret = ctf_dwarf_offset(cup, tdie, &offset)) != 0)
2045 if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0 &&
2051 if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_type, &tdie)) != 0) {
2056 if ((ret = ctf_dwarf_convert_type(cup, tdie, &id,
2068 if ((ret = ctf_dwarf_isglobal(cup, die, &cdv->cdv_global)) != 0) {
2074 ctf_list_append(&cup->cu_vars, cdv);
2082 ctf_dwarf_walk_toplevel(ctf_cu_t *cup, Dwarf_Die die)
2088 if ((ret = ctf_dwarf_offset(cup, die, &offset)) != 0)
2091 if (offset > cup->cu_maxoff) {
2092 (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
2094 offset, cup->cu_maxoff);
2098 if ((ret = ctf_dwarf_tag(cup, die, &tag)) != 0)
2105 ret = ctf_dwarf_convert_function(cup, die);
2109 ret = ctf_dwarf_convert_variable(cup, die);
2113 ret = ctf_dwarf_walk_lexical(cup, die);
2120 ret = ctf_dwarf_convert_type(cup, die, NULL, B_TRUE);
2135 ctf_dwarf_convert_die(ctf_cu_t *cup, Dwarf_Die die)
2141 if ((ret = ctf_dwarf_walk_toplevel(cup, die)) != 0)
2144 if ((ret = ctf_dwarf_sib(cup, die, &sib)) != 0)
2152 ctf_dwarf_fixup_die(ctf_cu_t *cup, boolean_t addpass)
2156 for (map = avl_first(&cup->cu_map); map != NULL;
2157 map = AVL_NEXT(&cup->cu_map, map)) {
2161 if ((ret = ctf_dwarf_fixup_sou(cup, map->cdm_die, map->cdm_id,
2170 ctf_dwarf_match_func(ctf_cu_t *cup, const char *file, const char *name,
2179 if (bind == STB_LOCAL && (file == NULL || cup->cu_name == NULL))
2182 for (cdf = ctf_list_next(&cup->cu_funcs); cdf != NULL;
2190 if (bind == STB_LOCAL && strcmp(file, cup->cu_name) != 0)
2198 ctf_dwarf_match_var(ctf_cu_t *cup, const char *file, const char *name,
2204 if (bind == STB_LOCAL && (file == NULL || cup->cu_name == NULL))
2208 for (cdv = ctf_list_next(&cup->cu_vars); cdv != NULL;
2216 if (bind == STB_LOCAL && strcmp(file, cup->cu_name) != 0)
2225 ctf_dwarf_symtab_iter(ctf_cu_t *cup, ctf_dwarf_symtab_f *func, void *arg)
2229 ctf_file_t *fp = cup->cu_ctfp;
2276 ret = func(cup, gsymp, i, file, name, arg);
2285 ctf_dwarf_conv_funcvars_cb(ctf_cu_t *cup, const GElf_Sym *symp, ulong_t idx,
2300 ctf_dwvar_t *cdv = ctf_dwarf_match_var(cup, file, name,
2305 ret = ctf_add_object(cup->cu_ctfp, idx, cdv->cdv_type);
2308 ctf_dwfunc_t *cdf = ctf_dwarf_match_func(cup, file, name,
2312 ret = ctf_add_function(cup->cu_ctfp, idx, &cdf->cdf_fip,
2317 return (ctf_errno(cup->cu_ctfp));
2324 ctf_dwarf_conv_funcvars(ctf_cu_t *cup)
2326 return (ctf_dwarf_symtab_iter(cup, ctf_dwarf_conv_funcvars_cb, NULL));
2375 ctf_dwarf_conv_check_weak(ctf_cu_t *cup, const GElf_Sym *symp,
2422 ctf_dwarf_duplicate_sym(ctf_cu_t *cup, ulong_t idx, ulong_t matchidx)
2424 ctf_id_t id = ctf_lookup_by_symbol(cup->cu_ctfp, matchidx);
2431 if (ctf_errno(cup->cu_ctfp) == ECTF_NOTYPEDAT)
2434 return (ctf_errno(cup->cu_ctfp));
2437 if (ctf_add_object(cup->cu_ctfp, idx, id) == CTF_ERR)
2438 return (ctf_errno(cup->cu_ctfp));
2444 ctf_dwarf_duplicate_func(ctf_cu_t *cup, ulong_t idx, ulong_t matchidx)
2450 if (ctf_func_info(cup->cu_ctfp, matchidx, &fip) == CTF_ERR) {
2451 if (ctf_errno(cup->cu_ctfp) == ECTF_NOFUNCDAT)
2454 return (ctf_errno(cup->cu_ctfp));
2462 if (ctf_func_args(cup->cu_ctfp, matchidx, fip.ctc_argc, args) ==
2465 return (ctf_errno(cup->cu_ctfp));
2469 ret = ctf_add_function(cup->cu_ctfp, idx, &fip, args);
2473 return (ctf_errno(cup->cu_ctfp));
2479 ctf_dwarf_conv_weaks_cb(ctf_cu_t *cup, const GElf_Sym *symp,
2506 ret = ctf_dwarf_symtab_iter(cup, ctf_dwarf_conv_check_weak, &cweak);
2522 ret = ctf_dwarf_duplicate_sym(cup, idx, cweak.cweak_idx);
2524 ret = ctf_dwarf_duplicate_func(cup, idx, cweak.cweak_idx);
2531 ctf_dwarf_conv_weaks(ctf_cu_t *cup)
2533 return (ctf_dwarf_symtab_iter(cup, ctf_dwarf_conv_weaks_cb, NULL));
2542 ctf_cu_t *cup = arg;
2544 ctf_dprintf("converting die: %s\n", cup->cu_name);
2545 ctf_dprintf("max offset: %x\n", cup->cu_maxoff);
2546 VERIFY(cup != NULL);
2548 ret = ctf_dwarf_convert_die(cup, cup->cu_cu);
2549 ctf_dprintf("ctf_dwarf_convert_die (%s) returned %d\n", cup->cu_name,
2554 if (ctf_update(cup->cu_ctfp) != 0) {
2555 return (ctf_dwarf_error(cup, cup->cu_ctfp, 0,
2559 ret = ctf_dwarf_fixup_die(cup, B_FALSE);
2560 ctf_dprintf("ctf_dwarf_fixup_die (%s) returned %d\n", cup->cu_name,
2565 if (ctf_update(cup->cu_ctfp) != 0) {
2566 return (ctf_dwarf_error(cup, cup->cu_ctfp, 0,
2570 ret = ctf_dwarf_fixup_die(cup, B_TRUE);
2571 ctf_dprintf("ctf_dwarf_fixup_die (%s) returned %d\n", cup->cu_name,
2576 if (ctf_update(cup->cu_ctfp) != 0) {
2577 return (ctf_dwarf_error(cup, cup->cu_ctfp, 0,
2582 if ((ret = ctf_dwarf_conv_funcvars(cup)) != 0) {
2583 return (ctf_dwarf_error(cup, NULL, ret,
2587 if (ctf_update(cup->cu_ctfp) != 0) {
2588 return (ctf_dwarf_error(cup, cup->cu_ctfp, 0,
2592 if (cup->cu_doweaks == B_TRUE) {
2593 if ((ret = ctf_dwarf_conv_weaks(cup)) != 0) {
2594 return (ctf_dwarf_error(cup, NULL, ret,
2598 if (ctf_update(cup->cu_ctfp) != 0) {
2599 return (ctf_dwarf_error(cup, cup->cu_ctfp, 0,
2604 ctf_phase_dump(cup->cu_ctfp, "pre-dedup");
2606 if ((ret = ctf_merge_add(cup->cu_cmh, cup->cu_ctfp)) != 0) {
2607 return (ctf_dwarf_error(cup, NULL, ret,
2612 if ((ret = ctf_merge_dedup(cup->cu_cmh, &dedup)) != 0) {
2613 return (ctf_dwarf_error(cup, NULL, ret,
2616 ctf_close(cup->cu_ctfp);
2617 cup->cu_ctfp = dedup;
2628 ctf_dwarf_free_die(ctf_cu_t *cup)
2637 ctf_dprintf("Beginning to free die: %p\n", cup);
2638 cup->cu_elf = NULL;
2639 ctf_dprintf("Trying to free name: %p\n", cup->cu_name);
2640 if (cup->cu_name != NULL)
2641 ctf_free(cup->cu_name, strlen(cup->cu_name) + 1);
2642 ctf_dprintf("Trying to free merge handle: %p\n", cup->cu_cmh);
2643 if (cup->cu_cmh != NULL) {
2644 ctf_merge_fini(cup->cu_cmh);
2645 cup->cu_cmh = NULL;
2649 for (cdf = ctf_list_next(&cup->cu_funcs); cdf != NULL; cdf = ndf) {
2660 for (cdv = ctf_list_next(&cup->cu_vars); cdv != NULL; cdv = ndv) {
2667 for (cdb = ctf_list_next(&cup->cu_bitfields); cdb != NULL; cdb = ndb) {
2672 ctf_dprintf("Trying to clean up dwarf_t: %p\n", cup->cu_dwarf);
2673 (void) dwarf_finish(cup->cu_dwarf, &derr);
2674 cup->cu_dwarf = NULL;
2675 ctf_close(cup->cu_ctfp);
2678 while ((map = avl_destroy_nodes(&cup->cu_map, &cookie)) != NULL) {
2681 avl_destroy(&cup->cu_map);
2682 cup->cu_errbuf = NULL;
2734 ctf_dwarf_init_die(int fd, Elf *elf, ctf_cu_t *cup, int ndie, char *errbuf,
2743 while ((ret = dwarf_next_cu_header(cup->cu_dwarf, &hdrlen, NULL,
2760 cup->cu_voidtid = CTF_ERR;
2761 cup->cu_longtid = CTF_ERR;
2762 cup->cu_elf = elf;
2763 cup->cu_maxoff = nexthdr - 1;
2764 cup->cu_ctfp = ctf_fdcreate(fd, &ret);
2765 if (cup->cu_ctfp == NULL) {
2766 ctf_free(cup, sizeof (ctf_cu_t));
2769 avl_create(&cup->cu_map, ctf_dwmap_comp, sizeof (ctf_dwmap_t),
2771 cup->cu_errbuf = errbuf;
2772 cup->cu_errlen = errlen;
2773 bzero(&cup->cu_vars, sizeof (ctf_list_t));
2774 bzero(&cup->cu_funcs, sizeof (ctf_list_t));
2775 bzero(&cup->cu_bitfields, sizeof (ctf_list_t));
2777 if ((ret = ctf_dwarf_die_elfenc(elf, cup, errbuf,
2779 avl_destroy(&cup->cu_map);
2780 ctf_free(cup, sizeof (ctf_cu_t));
2784 if ((ret = ctf_dwarf_sib(cup, NULL, &cu)) != 0) {
2785 avl_destroy(&cup->cu_map);
2786 ctf_free(cup, sizeof (ctf_cu_t));
2792 avl_destroy(&cup->cu_map);
2793 ctf_free(cup, sizeof (ctf_cu_t));
2797 if ((ret = ctf_dwarf_child(cup, cu, &child)) != 0) {
2798 avl_destroy(&cup->cu_map);
2799 ctf_free(cup, sizeof (ctf_cu_t));
2805 avl_destroy(&cup->cu_map);
2806 ctf_free(cup, sizeof (ctf_cu_t));
2810 cup->cu_cuoff = offset;
2811 cup->cu_cu = child;
2813 if ((cup->cu_cmh = ctf_merge_init(fd, &ret)) == NULL) {
2814 avl_destroy(&cup->cu_map);
2815 ctf_free(cup, sizeof (ctf_cu_t));
2819 if (ctf_dwarf_string(cup, cu, DW_AT_name, &name) == 0) {
2822 cup->cu_name = strdup(b);
2839 ctf_cu_t *cdies = NULL, *cup;
2890 cup = &cdies[i];
2892 &cup->cu_dwarf, &derr);
2907 cup->cu_doweaks = ndies > 1 ? B_FALSE : B_TRUE;
2926 cup = &cdies[i];
2927 ctf_dprintf("adding die %s: %p, %x %x\n", cup->cu_name,
2928 cup->cu_cu, cup->cu_cuoff, cup->cu_maxoff);
2929 if (workq_add(wqp, cup) == -1) {
2964 cup = &cdies[i];
2965 if ((ret = ctf_merge_add(cmp, cup->cu_ctfp)) != 0) {