Dump the content of STRUCT, ENUM and the encoding, offset and bits for
authorMartin Pieuchot <mpi@openbsd.org>
Fri, 18 Mar 2016 21:28:45 +0000 (22:28 +0100)
committerMartin Pieuchot <mpi@openbsd.org>
Fri, 18 Mar 2016 21:30:32 +0000 (22:30 +0100)
INTEGER and FLOAT.

ctf.h
ctfdump.c

diff --git a/ctf.h b/ctf.h
index f07b1d49fa338f336a0075ddc0bbcb3906334e75..2807b45619929b628c3317aa8b1fd2cc23b4e5e2 100644 (file)
--- a/ctf.h
+++ b/ctf.h
@@ -75,7 +75,7 @@ struct ctf_member {
 struct ctf_lmember {
        struct ctf_member       _ctlm_member;
 #define ctlm_name _ctlm_member.ctm_name
-#define ctlm_type _ctlm_member.ctlm_type
+#define ctlm_type _ctlm_member.ctm_type
 #define ctlm_pad0 _ctlm_member.ctm_offset
        unsigned int            ctlm_offsethi;
        unsigned int            ctlm_offsetlo;
@@ -120,6 +120,37 @@ struct ctf_enum {
 #define  CTF_K_RESTRICT                13
 #define  CTF_K_MAX             31
 
+/*
+ * Integer/Float Encoding macro.
+ */
+#define _CTF_ENCODING(e)       (((e) & 0xff000000) >> 24)
+#define _CTF_OFFSET(e)         (((e) & 0x00ff0000) >> 16)
+#define _CTF_BITS(e)           (((e) & 0x0000ffff))
+
+#define CTF_INT_ENCODING(e)    _CTF_ENCODING(e)
+#define  CTF_INT_SIGNED                (1 << 0)
+#define  CTF_INT_CHAR          (1 << 1)
+#define  CTF_INT_BOOL          (1 << 2)
+#define  CTF_INT_VARARGS       (1 << 3)
+#define CTF_INT_OFFSET(e)      _CTF_OFFSET(e)
+#define CTF_INT_BITS(e)                _CTF_BITS(e)
+
+#define CTF_FP_ENCODING(e)     _CTF_ENCODING(e)
+#define  CTF_FP_SINGLE         1
+#define  CTF_FP_DOUBLE         2
+#define  CTF_FP_CPLX           3
+#define  CTF_FP_DCPLX          4
+#define  CTF_FP_LDCPLX         5
+#define  CTF_FP_LDOUBLE                6
+#define  CTF_FP_INTRVL         7
+#define  CTF_FP_DINTRVL                8
+#define  CTF_FP_LDINTRVL       9
+#define  CTF_FP_IMAGRY         10
+#define  CTF_FP_DIMAGRY                11
+#define  CTF_FP_LDIMAGRY       12
+#define CTF_FP_OFFSET(e)       _CTF_OFFSET(e)
+#define CTF_FP_BITS(e)         _CTF_BITS(e)
+
 /*
  * Name reference macro.
  */
@@ -133,3 +164,9 @@ struct ctf_enum {
 #define CTF_SIZE_TO_LSIZE_LO(s)        ((uint32_t)(s))
 #define CTF_TYPE_LSIZE(t)      \
        (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
+
+/*
+ * Member macro.
+ */
+#define CTF_LMEM_OFFSET(m) \
+       (((uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
index fcce75ed906d6326d884e33fe8d47700230ed133..2577900b04b69aa3f8183f11b61118a7c1a5f4f7 100644 (file)
--- a/ctfdump.c
+++ b/ctfdump.c
@@ -519,13 +519,13 @@ unsigned int
 ctf_dump_type(struct ctf_header *cth, const char *data, off_t dlen,
     unsigned int offset, unsigned int idx)
 {
-       const struct ctf_type   *ctt;
-       unsigned short           kind, vlen, root;
-       unsigned int             toff, tlen = 0;
+       const char              *p = data + cth->cth_typeoff + offset;
+       const struct ctf_type   *ctt = (struct ctf_type *)p;
+       unsigned short           i, kind, vlen, root;
+       unsigned int             eob, toff;
        uint64_t                 size;
        const char              *name, *kname;
 
-       ctt = (struct ctf_type *)(data + cth->cth_typeoff + offset);
        kind = CTF_INFO_KIND(ctt->ctt_info);
        vlen = CTF_INFO_VLEN(ctt->ctt_info);
        root = CTF_INFO_ISROOT(ctt->ctt_info);
@@ -552,30 +552,68 @@ ctf_dump_type(struct ctf_header *cth, const char *data, off_t dlen,
        case CTF_K_FORWARD:
                break;
        case CTF_K_INTEGER:
-               tlen = sizeof(unsigned int);
+               eob = *((unsigned int *)((char *)ctt + toff));
+               toff += sizeof(unsigned int);
+               printf(" encoding=0x%x offset=%u bits=%u",
+                   CTF_INT_ENCODING(eob), CTF_INT_OFFSET(eob),
+                   CTF_INT_BITS(eob));
                break;
        case CTF_K_FLOAT:
+               eob = *((unsigned int *)((char *)ctt + toff));
+               toff += sizeof(unsigned int);
+               printf(" encoding=0x%x offset=%u bits=%u",
+                   CTF_FP_ENCODING(eob), CTF_FP_OFFSET(eob), CTF_FP_BITS(eob));
                break;
        case CTF_K_ARRAY:
-               tlen = sizeof(struct ctf_array);
+               toff += sizeof(struct ctf_array);
                break;
        case CTF_K_FUNCTION:
-               tlen = (vlen + (vlen & 1)) * sizeof(unsigned short);
+               toff += (vlen + (vlen & 1)) * sizeof(unsigned short);
                break;
        case CTF_K_STRUCT:
        case CTF_K_UNION:
-               printf(" (%llu bytes)", size);
-               if (size < CTF_LSTRUCT_THRESH)
-                       tlen = vlen * sizeof(struct ctf_member);
-               else
-                       tlen = vlen * sizeof(struct ctf_lmember);
+               printf(" (%llu bytes)\n", size);
+
+               if (size < CTF_LSTRUCT_THRESH) {
+                       for (i = 0; i < vlen; i++) {
+                               struct ctf_member       *ctm;
+
+                               ctm = (struct ctf_member *)(p + toff);
+                               toff += sizeof(struct ctf_member);
+
+                               printf("\t%s type=%u off=%u\n",
+                                   ctf_off2name(cth, data, dlen,
+                                       ctm->ctm_name),
+                                   ctm->ctm_type, ctm->ctm_offset);
+                       }
+               } else {
+                       for (i = 0; i < vlen; i++) {
+                               struct ctf_lmember      *ctlm;
+
+                               ctlm = (struct ctf_lmember *)(p + toff);
+                               toff += sizeof(struct ctf_lmember);
+
+                               printf("\t%s type=%u off=%llu\n",
+                                   ctf_off2name(cth, data, dlen,
+                                       ctlm->ctlm_name),
+                                   ctlm->ctlm_type, CTF_LMEM_OFFSET(ctlm));
+                       }
+               }
                break;
        case CTF_K_ENUM:
-               tlen = vlen * sizeof(struct ctf_enum);
+               printf("\n");
+               for (i = 0; i < vlen; i++) {
+                       struct ctf_enum *cte;
+
+                       cte = (struct ctf_enum *)(p + toff);
+                       toff += sizeof(struct ctf_enum);
+
+                       printf("\t%s = %u\n",
+                           ctf_off2name(cth, data, dlen, cte->cte_name),
+                           cte->cte_value);
+               }
                break;
        case CTF_K_POINTER:
-               vlen = sizeof(unsigned int);
-               /* FALLTHROUGH */
        case CTF_K_TYPEDEF:
        case CTF_K_VOLATILE:
        case CTF_K_CONST:
@@ -588,7 +626,7 @@ ctf_dump_type(struct ctf_header *cth, const char *data, off_t dlen,
 
        printf("\n");
 
-       return toff + tlen;
+       return toff;
 }
 
 const char *