This is an automated email from Gerrit.

Kamal Dasu (kdasu.k...@gmail.com) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/1964

-- gerrit

commit b9d20d042683a3ebd874446e18b233bfc6b7b6b0
Author: Kamal Dasu <kdasu.k...@gmail.com>
Date:   Tue Dec 3 16:15:42 2013 -0500

    svf: Fix debug and error messages that print hex buffer
    
    Added SVF_BUF_LOG macro to properly print the hex buffer of parsed
    string for SIR, SDR, TDI, TDO and MASK. The original debug and error
    logs with respect to printing real values were misleading and also
    had endianess issues. All the bits are printed now instead of just
    u32 values.
    
    Change-Id: Ie89902403bdb61ff458418446c2ca1253ea2a63f
    Signed-off-by: Kamal Dasu <kdasu.k...@gmail.com>

diff --git a/src/svf/svf.c b/src/svf/svf.c
index 3e7bfbf..84ffb0d 100644
--- a/src/svf/svf.c
+++ b/src/svf/svf.c
@@ -241,6 +241,41 @@ static long svf_total_lines;
 static int svf_percentage;
 static int svf_last_printed_percentage = -1;
 
+/*
+ * macro is used to print the svf hex buffer at desired debug level
+ * DEBUG, INFO, ERROR, USER
+ */
+#define SVF_BUF_LOG(_lvl, _buf, _nbits, _desc)         \
+       svf_hexbuf_print(LOG_LVL_##_lvl ,  __FILE__, __LINE__, __func__, _buf, 
_nbits, _desc)
+
+static void svf_hexbuf_print(int dbg_lvl, const char *file, unsigned line,
+                            const char *function, uint8_t *buf, int bit_len, 
char *desc)
+{
+       int j, i = 1, len = 0;
+       int byte_len = (bit_len + 7) >> 3;
+       int msbits = bit_len%8;
+       char *prbuf = NULL;
+
+       /* allocate space for print buffer
+          add extra 32 bytes for formating passed description */
+       prbuf = malloc(sizeof(desc) + byte_len + 32);
+       if (!prbuf)
+               return;
+
+       if (desc)
+               len += sprintf(prbuf, "%8s = ", desc);
+
+       /* take care of most significant unaligned bit len */
+       len += sprintf(prbuf + len,
+                      (msbits > 4  || msbits == 0) ? "0x%02x" : "0x%01x", 
buf[byte_len - i++]);
+       for (j = byte_len - i; j >= 0; j--)
+               len += sprintf(prbuf + len, "%02x", buf[j]);
+
+       log_printf_lf(dbg_lvl, file, line, function, "%s", prbuf);
+
+       free(prbuf);
+}
+
 static void svf_free_xxd_para(struct svf_xxr_para *para)
 {
        if (NULL != para) {
@@ -263,20 +298,6 @@ static void svf_free_xxd_para(struct svf_xxr_para *para)
        }
 }
 
-static unsigned svf_get_mask_u32(int bitlen)
-{
-       uint32_t bitmask;
-
-       if (bitlen < 0)
-               bitmask = 0;
-       else if (bitlen >= 32)
-               bitmask = 0xFFFFFFFF;
-       else
-               bitmask = (1 << bitlen) - 1;
-
-       return bitmask;
-}
-
 int svf_add_statemove(tap_state_t state_to)
 {
        tap_state_t state_from = cmd_queue_cur_state;
@@ -829,19 +850,11 @@ static int svf_check_tdo(void)
                if ((svf_check_tdo_para[i].enabled)
                                && buf_cmp_mask(&svf_tdi_buffer[index_var], 
&svf_tdo_buffer[index_var],
                                &svf_mask_buffer[index_var], len)) {
-                       unsigned bitmask;
-                       unsigned received, expected, tapmask;
-                       bitmask = 
svf_get_mask_u32(svf_check_tdo_para[i].bit_len);
-
-                       memcpy(&received, svf_tdi_buffer + index_var, 
sizeof(unsigned));
-                       memcpy(&expected, svf_tdo_buffer + index_var, 
sizeof(unsigned));
-                       memcpy(&tapmask, svf_mask_buffer + index_var, 
sizeof(unsigned));
                        LOG_ERROR("tdo check error at line %d",
                                svf_check_tdo_para[i].line_num);
-                       LOG_ERROR("read = 0x%X, want = 0x%X, mask = 0x%X",
-                               received & bitmask,
-                               expected & bitmask,
-                               tapmask & bitmask);
+                       SVF_BUF_LOG(ERROR, &svf_tdi_buffer[index_var], len, 
"READ");
+                       SVF_BUF_LOG(ERROR, &svf_tdo_buffer[index_var], len, 
"WANT");
+                       SVF_BUF_LOG(ERROR, &svf_mask_buffer[index_var], len, 
"MASK");
                        return ERROR_FAIL;
                }
        }
@@ -1036,8 +1049,7 @@ XXR_common:
                                        LOG_ERROR("fail to parse hex value");
                                        return ERROR_FAIL;
                                }
-                               LOG_DEBUG("\t%s = 0x%X", argus[i],
-                                               (**(int **)pbuffer_tmp) & 
svf_get_mask_u32(xxr_para_tmp->len));
+                               SVF_BUF_LOG(DEBUG, *pbuffer_tmp, 
xxr_para_tmp->len, argus[i]);
                        }
                        /* If a command changes the length of the last scan of 
the same type and the
                         * MASK parameter is absent, */
@@ -1573,11 +1585,7 @@ XXR_common:
 
                        /* output debug info */
                        if ((SIR == command) || (SDR == command)) {
-                               int read_value;
-                               memcpy(&read_value, svf_tdi_buffer, 
sizeof(int));
-                               /* in debug mode, data is from index 0 */
-                               int read_mask = 
svf_get_mask_u32(svf_check_tdo_para[0].bit_len);
-                               LOG_DEBUG("\tTDO read = 0x%X", read_value & 
read_mask);
+                               SVF_BUF_LOG(DEBUG, svf_tdi_buffer, 
svf_check_tdo_para[0].bit_len, "TDO read");
                        }
                }
        } else {

-- 

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to