lib_dumpbuffer: Now prints a large on-stack buffer first to avoid problems when the syslog output is prefixed with time.
This commit is contained in:
parent
79c8bb7ddf
commit
d4f3954b35
@ -70,10 +70,11 @@
|
||||
* any failure to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef CONFIG_LIB_BOARDCTL
|
||||
int board_app_initialize(uintptr_t arg)
|
||||
{
|
||||
lib_dumpbuffer("stdin", stdin, sizeof(FILE));
|
||||
#ifndef CONFIG_BOARD_INITIALIZE
|
||||
sim_bringup();
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/misc/lib_dumpbuffer.c
|
||||
*
|
||||
* Copyright (C) 2009, 2011, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2011, 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -47,6 +47,33 @@
|
||||
* Pre-processor definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define _NITEMS 32 /* 32 bytes displayed per line */
|
||||
#define _LINESIZE (3 * _NITEMS + 4) /* 2 hex chars, ASCII char, 3 spaces, NUL */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lib_nibble
|
||||
*
|
||||
* Description:
|
||||
* Convert a binary nibble to a hexadecimal character.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static char lib_nibble(unsigned char nibble)
|
||||
{
|
||||
if (nibble < 10)
|
||||
{
|
||||
return '0' + nibble;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'a' + nibble - 10;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -55,63 +82,76 @@
|
||||
* Name: lib_dumpbuffer
|
||||
*
|
||||
* Description:
|
||||
* Do a pretty buffer dump
|
||||
* Do a pretty buffer dump.
|
||||
*
|
||||
* A fairly large on-stack buffer is used for the case where timestamps are
|
||||
* applied to each line.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer,
|
||||
unsigned int buflen)
|
||||
{
|
||||
char buf[_LINESIZE];
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int k;
|
||||
|
||||
syslog(LOG_INFO, "%s (%p):\n", msg, buffer);
|
||||
for (i = 0; i < buflen; i += 32)
|
||||
for (i = 0; i < buflen; i += _NITEMS)
|
||||
{
|
||||
syslog(LOG_INFO, "%04x: ", i);
|
||||
for (j = 0; j < 32; j++)
|
||||
FAR char *ptr = buf;
|
||||
|
||||
/* General hex values. 2 * _NITEMS + 1 bytes */
|
||||
|
||||
for (j = 0; j < _NITEMS; j++)
|
||||
{
|
||||
k = i + j;
|
||||
|
||||
if (j == 16)
|
||||
if (j == (_NITEMS / 2))
|
||||
{
|
||||
syslog(LOG_INFO, " ");
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
|
||||
if (k < buflen)
|
||||
{
|
||||
syslog(LOG_INFO, "%02x", buffer[k]);
|
||||
*ptr++ = lib_nibble((buffer[k] >> 4) & 0xf);
|
||||
*ptr++ = lib_nibble(buffer[k] & 0xf);
|
||||
}
|
||||
else
|
||||
{
|
||||
syslog(LOG_INFO, " ");
|
||||
*ptr++ = ' ';
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
syslog(LOG_INFO, " ");
|
||||
for (j = 0; j < 32; j++)
|
||||
*ptr++= ' ';
|
||||
|
||||
/* General hex values. 1 * _NITEMS + 1 bytes */
|
||||
|
||||
for (j = 0; j < _NITEMS; j++)
|
||||
{
|
||||
k = i + j;
|
||||
|
||||
if (j == 16)
|
||||
if (j == (_NITEMS / 2))
|
||||
{
|
||||
syslog(LOG_INFO, " ");
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
|
||||
if (k < buflen)
|
||||
{
|
||||
if (buffer[k] >= 0x20 && buffer[k] < 0x7f)
|
||||
{
|
||||
syslog(LOG_INFO, "%c", buffer[k]);
|
||||
*ptr++ = buffer[k];
|
||||
}
|
||||
else
|
||||
{
|
||||
syslog(LOG_INFO, ".");
|
||||
*ptr++ = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syslog(LOG_INFO, "\n");
|
||||
*ptr = '\0';
|
||||
syslog(LOG_INFO, "%04x: %s\n", i, buf);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user