Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/cddl/osnet/dist/tools/ctf/cvt sync with freebsd



details:   https://anonhg.NetBSD.org/src/rev/caf70c1c3dbe
branches:  trunk
changeset: 327492:caf70c1c3dbe
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 09 17:04:00 2014 +0000

description:
sync with freebsd

diffstat:

 external/cddl/osnet/dist/tools/ctf/cvt/ctf.c      |  131 ++++++++-
 external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c |   23 +-
 external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.h |    7 +-
 external/cddl/osnet/dist/tools/ctf/cvt/ctftools.h |    7 +-
 external/cddl/osnet/dist/tools/ctf/cvt/dwarf.c    |  305 +++++++++++++++------
 external/cddl/osnet/dist/tools/ctf/cvt/input.c    |    7 +-
 external/cddl/osnet/dist/tools/ctf/cvt/output.c   |   33 +-
 external/cddl/osnet/dist/tools/ctf/cvt/st_parse.c |   40 +-
 external/cddl/osnet/dist/tools/ctf/cvt/stabs.c    |    2 +
 external/cddl/osnet/dist/tools/ctf/cvt/traverse.c |    8 +-
 external/cddl/osnet/dist/tools/ctf/cvt/util.c     |    4 +-
 11 files changed, 415 insertions(+), 152 deletions(-)

diffs (truncated from 1299 to 300 lines):

diff -r e28e6f0d2043 -r caf70c1c3dbe external/cddl/osnet/dist/tools/ctf/cvt/ctf.c
--- a/external/cddl/osnet/dist/tools/ctf/cvt/ctf.c      Sun Mar 09 16:58:03 2014 +0000
+++ b/external/cddl/osnet/dist/tools/ctf/cvt/ctf.c      Sun Mar 09 17:04:00 2014 +0000
@@ -51,15 +51,13 @@
  *
  * The value is only valid during a call to ctf_load.
  */
-char *curfile;
-
-
-/* The number of types. */
-static int ntypes=0;
+static char *curfile;
 
 #define        CTF_BUF_CHUNK_SIZE      (64 * 1024)
 #define        RES_BUF_CHUNK_SIZE      (64 * 1024)
 
+static int ntypes = 0;         /* The number of types. */
+
 struct ctf_buf {
        strtab_t ctb_strtab;    /* string table */
        caddr_t ctb_base;       /* pointer to base of buffer */
@@ -70,6 +68,18 @@
        int ntholes;            /* number of type holes */
 };
 
+/*
+ * Macros to reverse byte order
+ */
+#define        BSWAP_8(x)      ((x) & 0xff)
+#define        BSWAP_16(x)     ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
+#define        BSWAP_32(x)     ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
+
+#define        SWAP_16(x)      (x) = BSWAP_16(x)
+#define        SWAP_32(x)      (x) = BSWAP_32(x)
+
+static int target_requires_swap;
+
 /*PRINTFLIKE1*/
 static void
 parseterminate(const char *fmt, ...)
@@ -148,6 +158,11 @@
        ctl.ctl_label = strtab_insert(&b->ctb_strtab, le->le_name);
        ctl.ctl_typeidx = le->le_idx;
 
+       if (target_requires_swap) {
+               SWAP_32(ctl.ctl_label);
+               SWAP_32(ctl.ctl_typeidx);
+       }
+
        ctf_buf_write(b, &ctl, sizeof (ctl));
 
        return (1);
@@ -160,6 +175,10 @@
 
        ctf_buf_write(b, &id, sizeof (id));
 
+       if (target_requires_swap) {
+               SWAP_16(id);
+       }
+
        debug(3, "Wrote object %s (%d)\n", (idp ? idp->ii_name : "(null)"), id);
 }
 
@@ -188,10 +207,21 @@
 
        fdata[0] = CTF_TYPE_INFO(CTF_K_FUNCTION, 1, nargs);
        fdata[1] = idp->ii_dtype->t_id;
+
+       if (target_requires_swap) {
+               SWAP_16(fdata[0]);
+               SWAP_16(fdata[1]);
+       }
+
        ctf_buf_write(b, fdata, sizeof (fdata));
 
        for (i = 0; i < idp->ii_nargs; i++) {
                id = idp->ii_args[i]->t_id;
+
+               if (target_requires_swap) {
+                       SWAP_16(id);
+               }
+
                ctf_buf_write(b, &id, sizeof (id));
        }
 
@@ -216,11 +246,25 @@
                ctt->ctt_size = CTF_LSIZE_SENT;
                ctt->ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);
                ctt->ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size);
+               if (target_requires_swap) {
+                       SWAP_32(ctt->ctt_name);
+                       SWAP_16(ctt->ctt_info);
+                       SWAP_16(ctt->ctt_size);
+                       SWAP_32(ctt->ctt_lsizehi);
+                       SWAP_32(ctt->ctt_lsizelo);
+               }
                ctf_buf_write(b, ctt, sizeof (*ctt));
        } else {
                ctf_stype_t *cts = (ctf_stype_t *)ctt;
 
                cts->ctt_size = (ushort_t)size;
+
+               if (target_requires_swap) {
+                       SWAP_32(cts->ctt_name);
+                       SWAP_16(cts->ctt_info);
+                       SWAP_16(cts->ctt_size);
+               }
+
                ctf_buf_write(b, cts, sizeof (*cts));
        }
 }
@@ -230,6 +274,12 @@
 {
        ctf_stype_t *cts = (ctf_stype_t *)ctt;
 
+       if (target_requires_swap) {
+               SWAP_32(cts->ctt_name);
+               SWAP_16(cts->ctt_info);
+               SWAP_16(cts->ctt_size);
+       }
+
        ctf_buf_write(b, cts, sizeof (*cts));
 }
 
@@ -304,6 +354,9 @@
                        encoding = ip->intr_fformat;
 
                data = CTF_INT_DATA(encoding, ip->intr_offset, ip->intr_nbits);
+               if (target_requires_swap) {
+                       SWAP_32(data);
+               }
                ctf_buf_write(b, &data, sizeof (data));
                break;
 
@@ -320,6 +373,11 @@
                cta.cta_contents = tp->t_ardef->ad_contents->t_id;
                cta.cta_index = tp->t_ardef->ad_idxtype->t_id;
                cta.cta_nelems = tp->t_ardef->ad_nelems;
+               if (target_requires_swap) {
+                       SWAP_16(cta.cta_contents);
+                       SWAP_16(cta.cta_index);
+                       SWAP_32(cta.cta_nelems);
+               }
                ctf_buf_write(b, &cta, sizeof (cta));
                break;
 
@@ -349,6 +407,11 @@
                                    offset);
                                ctm.ctm_type = mp->ml_type->t_id;
                                ctm.ctm_offset = mp->ml_offset;
+                               if (target_requires_swap) {
+                                       SWAP_32(ctm.ctm_name);
+                                       SWAP_16(ctm.ctm_type);
+                                       SWAP_16(ctm.ctm_offset);
+                               }
                                ctf_buf_write(b, &ctm, sizeof (ctm));
                        }
                } else {
@@ -363,6 +426,14 @@
                                    CTF_OFFSET_TO_LMEMHI(mp->ml_offset);
                                ctlm.ctlm_offsetlo =
                                    CTF_OFFSET_TO_LMEMLO(mp->ml_offset);
+
+                               if (target_requires_swap) {
+                                       SWAP_32(ctlm.ctlm_name);
+                                       SWAP_16(ctlm.ctlm_type);
+                                       SWAP_32(ctlm.ctlm_offsethi);
+                                       SWAP_32(ctlm.ctlm_offsetlo);
+                               }
+
                                ctf_buf_write(b, &ctlm, sizeof (ctlm));
                        }
                }
@@ -373,20 +444,26 @@
                        i++; /* count up enum members */
 
                if (i > CTF_MAX_VLEN) {
-                       printf("enum %s has too many values: %d > %d, truncating\n",
+                       warning("enum %s has too many values: %d > %d\n",
                            tdesc_name(tp), i, CTF_MAX_VLEN);
-
-                   i = CTF_MAX_VLEN;
+                       i = CTF_MAX_VLEN;
                }
 
                ctt.ctt_info = CTF_TYPE_INFO(CTF_K_ENUM, isroot, i);
                write_sized_type_rec(b, &ctt, tp->t_size);
 
-               for (ep = tp->t_emem; i && ep != NULL; ep = ep->el_next, i--) {
+               for (ep = tp->t_emem; ep != NULL && i > 0; ep = ep->el_next) {
                        offset = strtab_insert(&b->ctb_strtab, ep->el_name);
                        cte.cte_name = CTF_TYPE_NAME(CTF_STRTAB_0, offset);
                        cte.cte_value = ep->el_number;
+
+                       if (target_requires_swap) {
+                               SWAP_32(cte.cte_name);
+                               SWAP_32(cte.cte_value);
+                       }
+
                        ctf_buf_write(b, &cte, sizeof (cte));
+                       i--;
                }
                break;
 
@@ -428,6 +505,11 @@
 
                for (i = 0; i < (int) tp->t_fndef->fn_nargs; i++) {
                        id = tp->t_fndef->fn_args[i]->t_id;
+
+                       if (target_requires_swap) {
+                               SWAP_16(id);
+                       }
+
                        ctf_buf_write(b, &id, sizeof (id));
                }
 
@@ -621,6 +703,9 @@
 
        int i;
 
+       target_requires_swap = do_compress & CTF_SWAP_BYTES;
+       do_compress &= ~CTF_SWAP_BYTES;
+
        /*
         * Prepare the header, and create the CTF output buffers.  The data
         * object section and function section are both lists of 2-byte
@@ -657,6 +742,18 @@
        h.cth_stroff = ctf_buf_cur(buf);
        h.cth_strlen = strtab_size(&buf->ctb_strtab);
 
+       if (target_requires_swap) {
+               SWAP_16(h.cth_preamble.ctp_magic);
+               SWAP_32(h.cth_parlabel);
+               SWAP_32(h.cth_parname);
+               SWAP_32(h.cth_lbloff);
+               SWAP_32(h.cth_objtoff);
+               SWAP_32(h.cth_funcoff);
+               SWAP_32(h.cth_typeoff);
+               SWAP_32(h.cth_stroff);
+               SWAP_32(h.cth_strlen);
+       }
+
        /*
         * We only do compression for ctfmerge, as ctfconvert is only
         * supposed to be used on intermediary build objects. This is
@@ -824,7 +921,7 @@
                        debug(3, "Skipping null object\n");
                        continue;
                } else if (id >= tdsize) {
-                       parseterminate("(1) Reference to invalid type %d", id);
+                       parseterminate("Reference to invalid type %d", id);
                }
 
                ii = iidesc_new(symit_name(si));
@@ -875,7 +972,7 @@
                dptr += 2;
 
                if (retid >= tdsize)
-                       parseterminate("(2) Reference to invalid type %d", retid);
+                       parseterminate("Reference to invalid type %d", retid);
 
                ii = iidesc_new(symit_name(si));
                ii->ii_dtype = tdarr[retid];
@@ -893,8 +990,8 @@
                        v = (void *) dptr;
                        ushort_t id = *((ushort_t *)v);
                        if (id >= tdsize)
-                               parseterminate("(3) Reference to invalid type %d (tdsize %d) ii_nargs %d %s",
-                                   id, tdsize, ii->ii_nargs, ii->ii_name);
+                               parseterminate("Reference to invalid type %d",
+                                   id);
                        ii->ii_args[i] = tdarr[id];
                }
 
@@ -949,7 +1046,7 @@
                        break;
 
                if (tid >= tdsize)
-                       parseterminate("(4) Reference to invalid type %d", tid);
+                       parseterminate("Reference to invalid type %d", tid);
 
                void *v = (void *) dptr;
                ctt = v;
@@ -1053,7 +1150,8 @@
                                        (*mpp)->ml_offset = ctm->ctm_offset;
                                        (*mpp)->ml_size = 0;
                                        if (ctm->ctm_type > ntypes) {
-                                           parseterminate("Invalid member type ctm_type=%d", ctm->ctm_type);
+                                               parseterminate("Invalid member type ctm_type=%d",
+                                                   ctm->ctm_type);
                                        }
                                }
                        } else {
@@ -1072,7 +1170,8 @@
                                            (int)CTF_LMEM_OFFSET(ctlm);
                                        (*mpp)->ml_size = 0;
                                        if (ctlm->ctlm_type > ntypes) {
-                                           parseterminate("Invalid lmember type ctlm_type=%d", ctlm->ctlm_type);
+                                               parseterminate("Invalid lmember type ctlm_type=%d",



Home | Main Index | Thread Index | Old Index