Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_dump32.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * Provides general purpose debug facilities
36  */
37 /*!
38 @defgroup debug Debug Support Functions
39 */
40 
41 #include "ocs.h"
42 
43 static int
44 _isprint(int c) {
45  return ((c > 32) && (c < 127));
46 }
47 
48 static uint32_t ocs_debug_mask = 0;
49 
50 static int _ocs_debug_is_enabled(uint32_t mask) {
51  return (ocs_debug_mask & mask) == mask;
52 }
53 
54 
55 /**
56  * @ingroup debug
57  * @brief Dump 32 bit hex/ascii data
58  *
59  * Dumps using ocs_log a buffer of data as 32 bit hex and ascii
60  *
61  * @param mask debug enable bits
62  * @param os os handle
63  * @param label text label for the display (may be NULL)
64  * @param buf pointer to data buffer
65  * @param buf_length length of data buffer
66  *
67  * @return none
68  *
69  */
70 
71 void
72 ocs_dump32(uint32_t mask, ocs_os_handle_t os, const char *label, void *buf, uint32_t buf_length)
73 {
74  uint32_t word_count = buf_length / sizeof(uint32_t);
75  uint32_t i;
76  uint32_t columns = 8;
77  uint32_t n;
78  uint32_t *wbuf;
79  char *cbuf;
80  uint32_t addr = 0;
81  char linebuf[200];
82  char *pbuf = linebuf;
83 
84  if (!_ocs_debug_is_enabled(mask)) {
85  return;
86  }
87 
88  if (label) {
89  ocs_log_info(os, "%s\n", label);
90  }
91 
92  wbuf = buf;
93  while (word_count > 0) {
94  pbuf = linebuf;
95  pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), "%08X: ", addr);
96 
97  n = word_count;
98  if (n > columns)
99  n = columns;
100 
101  for (i = 0; i < n; i ++)
102  pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), "%08X ", wbuf[i]);
103 
104  for (; i < columns; i ++)
105  pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), "%8s ", "");
106 
107  pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), " ");
108  cbuf = (char*)wbuf;
109  for (i = 0; i < n*sizeof(uint32_t); i ++)
110  pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), "%c", _isprint(cbuf[i]) ? cbuf[i] : '.');
111  pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), "\n");
112 
113  ocs_log_info(os, "%s", linebuf);
114 
115  wbuf += n;
116  word_count -= n;
117  addr += n*sizeof(uint32_t);
118  }
119 }
static int _ocs_debug_is_enabled(uint32_t mask)
Definition: ocs_dump32.c:50
static int _isprint(int c)
Definition: ocs_dump32.c:44
void ocs_dump32(uint32_t mask, ocs_os_handle_t os, const char *label, void *buf, uint32_t buf_length)
Dump 32 bit hex/ascii data.
Definition: ocs_dump32.c:72
static uint32_t ocs_debug_mask
Definition: ocs_dump32.c:48