X-Git-Url: https://repo.jachan.dev/binutils.git/blobdiff_plain/d7b1416ef2c46ee9b8bfe4e5ceb87b371d49504c..HEAD:/libctf/ctf-types.c diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index ed76eca846..220bbb528f 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -1,5 +1,5 @@ /* Type handling functions. - Copyright (C) 2019-2021 Free Software Foundation, Inc. + Copyright (C) 2019-2022 Free Software Foundation, Inc. This file is part of libctf. @@ -579,6 +579,8 @@ ctf_type_resolve (ctf_dict_t *fp, ctf_id_t type) prev = type; type = tp->ctt_type; break; + case CTF_K_UNKNOWN: + return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE)); default: return type; } @@ -808,6 +810,13 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type) case CTF_K_RESTRICT: ctf_decl_sprintf (&cd, "restrict"); break; + case CTF_K_UNKNOWN: + if (name[0] == '\0') + ctf_decl_sprintf (&cd, _("(nonrepresentable type)")); + else + ctf_decl_sprintf (&cd, _("(nonrepresentable type %s)"), + name); + break; } k = cdp->cd_kind; @@ -1157,7 +1166,7 @@ ctf_type_pointer (ctf_dict_t *fp, ctf_id_t type) return (ctf_set_errno (ofp, ECTF_NOTYPE)); } -/* Return the encoding for the specified INTEGER or FLOAT. */ +/* Return the encoding for the specified INTEGER, FLOAT, or ENUM. */ int ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) @@ -1194,6 +1203,12 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) ep->cte_offset = CTF_FP_OFFSET (data); ep->cte_bits = CTF_FP_BITS (data); break; + case CTF_K_ENUM: + /* v3 only: we must guess at the underlying integral format. */ + ep->cte_format = CTF_INT_SIGNED; + ep->cte_offset = 0; + ep->cte_bits = 0; + break; case CTF_K_SLICE: { const ctf_slice_t *slice; @@ -1626,20 +1641,27 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func, unsigned char *vlen; ssize_t size, increment, vbytes; uint32_t kind, n, i = 0; + int nonrepresentable = 0; int rc; - if ((type = ctf_type_resolve (fp, type)) == CTF_ERR) - return -1; /* errno is set for us. */ + if ((type = ctf_type_resolve (fp, type)) == CTF_ERR) { + if (ctf_errno (fp) != ECTF_NONREPRESENTABLE) + return -1; /* errno is set for us. */ + else + nonrepresentable = 1; + } - if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) - return -1; /* errno is set for us. */ + if (!nonrepresentable) + if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) + return -1; /* errno is set for us. */ if ((rc = func (name, otype, offset, depth, arg)) != 0) return rc; - kind = LCTF_INFO_KIND (fp, tp->ctt_info); + if (!nonrepresentable) + kind = LCTF_INFO_KIND (fp, tp->ctt_info); - if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) + if (nonrepresentable || (kind != CTF_K_STRUCT && kind != CTF_K_UNION)) return 0; ctf_get_ctt_size (fp, tp, &size, &increment);