}
#endif
-void
-test_hexdump(const char *title, const void *buf, unsigned int len)
-{
- unsigned int i, out, ofs;
- const unsigned char *data = buf;
-#define LINE_LEN 80
- char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */
-
- printf("%s at [%p], len=%u\n", title, data, len);
- ofs = 0;
- while (ofs < len) {
- /* format 1 line in the buffer, then use printf to print them */
- out = rte_snprintf(line, LINE_LEN, "%08X", ofs);
- for (i = 0; ofs+i < len && i < 16; i++)
- out += rte_snprintf(line+out, LINE_LEN - out, " %02X",
- data[ofs+i]&0xff);
- for(; i <= 16; i++)
- out += rte_snprintf(line+out, LINE_LEN - out, " ");
- for(i = 0; ofs < len && i < 16; i++, ofs++) {
- unsigned char c = data[ofs];
- if (!isascii(c) || !isprint(c))
- c = '.';
- out += rte_snprintf(line+out, LINE_LEN - out, "%c", c);
- }
- printf("%s\n", line);
- }
-}
-
int
main(int argc, char **argv)
{
extern cmdline_parse_ctx_t main_ctx[];
-void test_hexdump(const char *title, const void *buf, unsigned int len);
-
int main(int argc, char **argv);
int test_pci(void);
#include <rte_random.h>
#include <rte_common.h>
#include <rte_errno.h>
+#include <rte_hexdump.h>
#include <cmdline_parse.h>
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
/* check data */
if (memcmp(src, dst, cur_dst - dst)) {
- test_hexdump("src", src, cur_src - src);
- test_hexdump("dst", dst, cur_dst - dst);
+ rte_hexdump("src", src, cur_src - src);
+ rte_hexdump("dst", dst, cur_dst - dst);
printf("data after dequeue is not the same\n");
goto fail;
}
INC += rte_rwlock.h rte_spinlock.h rte_tailq.h rte_interrupts.h rte_alarm.h
INC += rte_string_fns.h rte_cpuflags.h rte_version.h rte_tailq_elem.h
INC += rte_eal_memconfig.h rte_malloc_heap.h
+INC += rte_hexdump.h
ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y)
INC += rte_warnings.h
--- /dev/null
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdint.h>
+#include <rte_hexdump.h>
+#include <rte_string_fns.h>
+
+#define LINE_LEN 128
+
+/**************************************************************************//**
+*
+* rte_hexdump - Dump out memory in a special hex dump format.
+*
+* DESCRIPTION
+* Dump out the message buffer in a special hex dump output format with characters
+* printed for each line of 16 hex values.
+*
+* RETURNS: N/A
+*
+* SEE ALSO:
+*/
+
+void
+rte_hexdump(const char * title, const void * buf, unsigned int len)
+{
+ unsigned int i, out, ofs;
+ const unsigned char *data = buf;
+ char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */
+
+ printf("%s at [%p], len=%u\n", (title)? title : " Dump data", data, len);
+ ofs = 0;
+ while (ofs < len) {
+ /* format the line in the buffer, then use printf to output to screen */
+ out = rte_snprintf(line, LINE_LEN, "%08X:", ofs);
+ for (i = 0; ((ofs + i) < len) && (i < 16); i++)
+ out += rte_snprintf(line+out, LINE_LEN - out, " %02X", (data[ofs+i] & 0xff));
+ for(; i <= 16; i++)
+ out += rte_snprintf(line+out, LINE_LEN - out, " | ");
+ for(i = 0; (ofs < len) && (i < 16); i++, ofs++) {
+ unsigned char c = data[ofs];
+ if ( (c < ' ') || (c > '~'))
+ c = '.';
+ out += rte_snprintf(line+out, LINE_LEN - out, "%c", c);
+ }
+ printf("%s\n", line);
+ }
+ fflush(stdout);
+}
+
+/**************************************************************************//**
+*
+* rte_memdump - Dump out memory in hex bytes with colons.
+*
+* DESCRIPTION
+* Dump out the message buffer in hex bytes with colons xx:xx:xx:xx:...
+*
+* RETURNS: N/A
+*
+* SEE ALSO:
+*/
+
+void
+rte_memdump(const char * title, const void * buf, unsigned int len)
+{
+ unsigned int i, out;
+ const unsigned char *data = buf;
+ char line[LINE_LEN];
+
+ if ( title )
+ printf("%s: ", title);
+
+ line[0] = '\0';
+ for (i = 0, out = 0; i < len; i++) {
+ // Make sure we do not overrun the line buffer length.
+ if ( out >= (LINE_LEN - 4) ) {
+ printf("%s", line);
+ out = 0;
+ line[out] = '\0';
+ }
+ out += rte_snprintf(line+out, LINE_LEN - out, "%02x%s",
+ (data[i] & 0xff), ((i+1) < len)? ":" : "");
+ }
+ if ( out > 0 )
+ printf("%s", line);
+ printf("\n");
+
+ fflush(stdout);
+}
+
--- /dev/null
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _RTE_HEXDUMP_H_
+#define _RTE_HEXDUMP_H_
+
+/**
+ * @file
+ * Simple API to dump out memory in a special hex format.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* Dump out memory in a special hex dump format.
+*
+* @param title
+* If not NULL this string is printed as a header to the output.
+* @param buf
+* This is the buffer address to print out.
+* @param len
+* The number of bytes to dump out
+* @return
+* None.
+*/
+
+extern void
+rte_hexdump(const char * title, const void * buf, unsigned int len);
+
+/**
+* Dump out memory in a hex format with colons between bytes.
+*
+* @param title
+* If not NULL this string is printed as a header to the output.
+* @param buf
+* This is the buffer address to print out.
+* @param len
+* The number of bytes to dump out
+* @return
+* None.
+*/
+
+void
+rte_memdump(const char * title, const void * buf, unsigned int len);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_HEXDUMP_H_ */
SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c
SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c
SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_cpuflags.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c
CFLAGS_eal.o := -D_GNU_SOURCE
CFLAGS_eal_thread.o := -D_GNU_SOURCE
#include <rte_mempool.h>
#include <rte_mbuf.h>
#include <rte_string_fns.h>
+#include <rte_hexdump.h>
/*
* ctrlmbuf constructor, given as a callback function to
m->pkt.in_port = 0xff;
}
-static void
-rte_pktmbuf_hexdump(const void *buf, unsigned int len)
-{
- unsigned int i, out, ofs;
- const unsigned char *data = buf;
-#define LINE_LEN 80
- char line[LINE_LEN];
-
- printf(" dump data at 0x%p, len=%u\n", data, len);
- ofs = 0;
- while (ofs < len) {
- out = rte_snprintf(line, LINE_LEN, " %08X", ofs);
- for (i = 0; ofs+i < len && i < 16; i++)
- out += rte_snprintf(line+out, LINE_LEN - out, " %02X",
- data[ofs+i]&0xff);
- for (; i <= 16; i++)
- out += rte_snprintf(line+out, LINE_LEN - out, " ");
- for (i = 0; ofs < len && i < 16; i++, ofs++) {
- unsigned char c = data[ofs];
- if (!isascii(c) || !isprint(c))
- c = '.';
- out += rte_snprintf(line+out, LINE_LEN - out, "%c", c);
- }
- printf("%s\n", line);
- }
-}
-
/* do some sanity checks on a mbuf: panic if it fails */
void
rte_mbuf_sanity_check(const struct rte_mbuf *m, enum rte_mbuf_type t,
if (len > m->pkt.data_len)
len = m->pkt.data_len;
if (len != 0)
- rte_pktmbuf_hexdump(m->pkt.data, len);
+ rte_hexdump(NULL, m->pkt.data, len);
dump_len -= len;
m = m->pkt.next;
nb_segs --;