int mdb_ctf_type_iter(const char *object, mdb_ctf_type_f *cb, void *data) { ctf_file_t *fp; mdb_tgt_t *t = mdb.m_target; int ret; type_iter_t ti; if (object == MDB_CTF_SYNTHETIC_ITER) fp = mdb.m_synth; else fp = mdb_tgt_name_to_ctf(t, object); if (fp == NULL) return (-1); ti.ti_cb = cb; ti.ti_arg = data; ti.ti_fp = fp; if ((ret = ctf_type_iter(fp, type_iter_cb, &ti)) == CTF_ERR) return (set_errno(ctf_to_errno(ctf_errno(fp)))); return (ret); }
static void ctfdump_types(void) { ctfdump_title(CTFDUMP_TYPES, "Types"); if (ctf_type_iter(g_fp, B_TRUE, ctfdump_types_cb, NULL) == CTF_ERR) { ctfdump_warn("failed to dump labels: %s\n", ctf_errmsg(ctf_errno(g_fp))); g_exit = 1; } }
static void ctfdump_source(void) { ulong_t nr_syms = ctf_nr_syms(g_fp); ctf_id_t max_id = ctf_max_id(g_fp); size_t count = 0; (void) printf("/* Types */\n\n"); if ((idnames = calloc(max_id + 1, sizeof (idnames[0]))) == NULL) { ctfdump_fatal("failed to alloc idnames: %s\n", strerror(errno)); } if (ctf_type_iter(g_fp, B_FALSE, ctfsrc_collect_types_cb, idnames) == CTF_ERR) { warnx("failed to collect types: %s", ctf_errmsg(ctf_errno(g_fp))); g_exit = 1; } qsort(idnames, max_id, sizeof (ctf_idname_t), idname_compare); for (size_t i = 0; i < max_id; i++) { if (idnames[i].ci_id != 0) ctfsrc_type(idnames[i].ci_id, idnames[i].ci_name); } free(idnames); (void) printf("\n\n/* Data Objects */\n\n"); if ((idnames = calloc(nr_syms, sizeof (idnames[0]))) == NULL) { ctfdump_fatal("failed to alloc idnames: %s\n", strerror(errno)); } if (ctf_object_iter(g_fp, ctfsrc_collect_objects_cb, &count) == CTF_ERR) { warnx("failed to collect objects: %s", ctf_errmsg(ctf_errno(g_fp))); g_exit = 1; } qsort(idnames, count, sizeof (ctf_idname_t), idname_compare); for (size_t i = 0; i < count; i++) ctfsrc_object(idnames[i].ci_id, idnames[i].ci_name); free(idnames); (void) printf("\n\n/* Functions */\n\n"); if ((idnames = calloc(nr_syms, sizeof (idnames[0]))) == NULL) { ctfdump_fatal("failed to alloc idnames: %s\n", strerror(errno)); } count = 0; if (ctf_function_iter(g_fp, ctfsrc_collect_functions_cb, &count) == CTF_ERR) { warnx("failed to collect functions: %s", ctf_errmsg(ctf_errno(g_fp))); g_exit = 1; } qsort(idnames, count, sizeof (ctf_idname_t), idname_compare); for (size_t i = 0; i < count; i++) ctfsrc_function(&idnames[i]); free(idnames); }