diff --git a/ChangeLog b/ChangeLog index 55b263e1f88..8f774358d7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -455,4 +455,5 @@ and mounted. * Corrected a critical bug that prevent recvfrom from receiving packets from any remote UDP port. + * NSH: Add hexadecimal dump command (xd) diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index 1b83454b93e..bedb624f84f 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -254,6 +254,12 @@ 2.30 Wait for Microseconds (usleep) + +
+ + 2.31 Hexadecimal Dump (xd) + + @@ -1411,6 +1417,33 @@ usleep <usec> Pause execution (sleep) of <usec> microseconds.

+ + + + +
+

2.31 Hexadecimal dump (xd)

+
+ +Command Syntax:

+ +

+ Synopsis. + Dump <byte-count> bytes of data from address <hex-address>. +

+

Example:

+ +
@@ -1800,6 +1833,7 @@ usleep <usec>
  • umount
  • unset
  • usleep
  • +
  • xd
  • diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index 4674077cc33..04704af51f2 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -8,7 +8,7 @@

    NuttX RTOS

    -

    Last Updated: September 6, 2008

    +

    Last Updated: September 7, 2008

    @@ -1082,6 +1082,7 @@ nuttx-0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> and mounted. * Corrected a critical bug that prevent recvfrom from receiving packets from any remote UDP port. + * NSH: Add hexadecimal dump command (xd) pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/examples/nsh/README.txt b/examples/nsh/README.txt index c202d7a8ea6..69187f1a344 100644 --- a/examples/nsh/README.txt +++ b/examples/nsh/README.txt @@ -552,6 +552,21 @@ o usleep Pause execution (sleep) of microseconds. +o xd + + Dump bytes of data from address + + Example: + ^^^^^^^^ + + nsh> xd 410e0 512 + Hex dump: + 0000: 00 00 00 00 9c 9d 03 00 00 00 00 01 11 01 10 06 ................ + 0010: 12 01 11 01 25 08 13 0b 03 08 1b 08 00 00 02 24 ....%..........$ + ... + 01f0: 08 3a 0b 3b 0b 49 13 00 00 04 13 01 01 13 03 08 .:.;.I.......... + nsh> + NSH Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -598,6 +613,7 @@ Command Dependencies on Configuration Settings umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT unset !CONFIG_DISABLE_ENVIRON usleep !CONFIG_DISABLE_SIGNALS + xd --- * NOTES: - Because of hardware padding, the actual required size may be larger. diff --git a/examples/nsh/nsh.h b/examples/nsh/nsh.h index c69aa2342d3..d8d18a72a68 100644 --- a/examples/nsh/nsh.h +++ b/examples/nsh/nsh.h @@ -259,6 +259,11 @@ extern char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl, const char *relpath); extern void nsh_freefullpath(char *relpath); #endif +/* Debug */ + +extern void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, + const char *buffer, ssize_t nbytes); + /* Shell command handlers */ extern int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); @@ -268,6 +273,7 @@ extern int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_mem(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +extern int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT extern int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); diff --git a/examples/nsh/nsh_dbgcmds.c b/examples/nsh/nsh_dbgcmds.c index 2f528a657dc..305727dc697 100644 --- a/examples/nsh/nsh_dbgcmds.c +++ b/examples/nsh/nsh_dbgcmds.c @@ -298,3 +298,71 @@ int cmd_mem(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) nsh_output(vtbl, " fordblks: %8x\n", mem.fordblks); return OK; } + +/**************************************************************************** + * Name: nsh_dumpbuffer + ****************************************************************************/ + +void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, + const char *buffer, ssize_t nbytes) +{ + char line[128]; + int ch; + int i; + int j; + + nsh_output(vtbl, "%s:\n", msg); + for (i = 0; i < nbytes; i += 16) + { + sprintf(line, "%04x: ", i); + + for ( j = 0; j < 16; j++) + { + if (i + j < nbytes) + { + sprintf(&line[strlen(line)], "%02x ", buffer[i+j] ); + } + else + { + strcpy(&line[strlen(line)], " "); + } + } + + for ( j = 0; j < 16; j++) + { + if (i + j < nbytes) + { + ch = buffer[i+j]; + sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.'); + } + } + nsh_output(vtbl, "%s\n", line); + } +} + +/**************************************************************************** + * Name: cmd_xd + ****************************************************************************/ + +int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + char *addr; + char *endptr; + int nbytes; + + addr = (char*)strtol(argv[1], &endptr, 16); + if (argv[0][0] == '\0' || *endptr != '\0') + { + return ERROR; + } + + nbytes = (int)strtol(argv[2], &endptr, 0); + if (argv[0][0] == '\0' || *endptr != '\0' || nbytes < 0) + { + return ERROR; + } + + nsh_dumpbuffer(vtbl, "Hex dump", addr, nbytes); + return OK; +} + diff --git a/examples/nsh/nsh_fscmds.c b/examples/nsh/nsh_fscmds.c index cd02ca576ee..f6049e67e04 100644 --- a/examples/nsh/nsh_fscmds.c +++ b/examples/nsh/nsh_fscmds.c @@ -60,6 +60,7 @@ #include #include #include +#include #include "nsh.h" @@ -851,6 +852,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) fmt = g_fmtcmdoutofmemory; goto errout_with_fmt; } + dbg("RAMDISK at %p\n", buffer); /* Then register the ramdisk */ diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index e58836fccee..68de8528510 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -210,7 +210,8 @@ static const struct cmdmap_s g_cmdmap[] = #ifndef CONFIG_DISABLE_SIGNALS { "usleep", cmd_usleep, 2, 2, "" }, #endif /* CONFIG_DISABLE_SIGNALS */ - { NULL, NULL, 1, 1, NULL } + { "xd", cmd_xd, 3, 3, " " }, + { NULL, NULL, 1, 1, NULL } }; /**************************************************************************** diff --git a/examples/nsh/nsh_telnetd.c b/examples/nsh/nsh_telnetd.c index d3cce997178..dd679cf3918 100644 --- a/examples/nsh/nsh_telnetd.c +++ b/examples/nsh/nsh_telnetd.c @@ -84,6 +84,12 @@ #define TELNET_DO 253 #define TELNET_DONT 254 +#ifdef CONFIG_EXAMPLES_NSH_TELNETD_DUMPBUFFER +# define nsh_telnetdump(vtbl,msg,buf,nb) nsh_dumpbuffer(vtbl,msg,buf,nb) +#else +# define nsh_telnetdump(vtbl,msg,buf,nb) +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -171,56 +177,6 @@ static void tio_semtake(struct telnetio_s *tio) #define tio_semgive(tio) ASSERT(sem_post(&tio->tio_sem) == 0) -/**************************************************************************** - * Name: nsh_dumpbuffer - * - * Description: - * Dump a buffer of data (debug only) - * - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_NSH_TELNETD_DUMPBUFFER -static void nsh_dumpbuffer(const char *msg, const char *buffer, ssize_t nbytes) -{ -#ifdef CONFIG_DEBUG - char line[128]; - int ch; - int i; - int j; - - dbg("%s:\n", msg); - for (i = 0; i < nbytes; i += 16) - { - sprintf(line, "%04x: ", i); - - for ( j = 0; j < 16; j++) - { - if (i + j < nbytes) - { - sprintf(&line[strlen(line)], "%02x ", buffer[i+j] ); - } - else - { - strcpy(&line[strlen(line)], " "); - } - } - - for ( j = 0; j < 16; j++) - { - if (i + j < nbytes) - { - ch = buffer[i+j]; - sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.'); - } - } - dbg("%s\n", line); - } -#endif -} -#else -# define nsh_dumpbuffer(msg,buffer,nbytes) -#endif - /**************************************************************************** * Name: nsh_allocstruct ****************************************************************************/ @@ -327,7 +283,8 @@ static void nsh_putchar(struct telnetd_s *pstate, uint8 ch) if (ch == ISO_nl || tio->tio_bufndx == (CONFIG_EXAMPLES_NSH_LINELEN - 1)) { pstate->tn_cmd[tio->tio_bufndx] = '\0'; - nsh_dumpbuffer("TELNET CMD", pstate->tn_cmd, strlen(pstate->tn_cmd)); + nsh_telnetdump(&pstate->tn_vtbl, "TELNET CMD", + pstate->tn_cmd, strlen(pstate->tn_cmd)); nsh_parse(&pstate->tn_vtbl, pstate->tn_cmd); tio->tio_bufndx = 0; } @@ -354,7 +311,7 @@ static void nsh_sendopt(struct telnetd_s *pstate, uint8 option, uint8 value) optbuf[2] = value; optbuf[3] = 0; - nsh_dumpbuffer("Send optbuf", optbuf, 4); + nsh_telnetdump(&pstate->tn_vtbl, "Send optbuf", optbuf, 4); tio_semtake(tio); /* Only one call to send at a time */ if (send(tio->tio_sockfd, optbuf, 4, 0) < 0) { @@ -377,7 +334,8 @@ static void nsh_flush(FAR struct telnetd_s *pstate) if (pstate->tn_sndlen > 0) { - nsh_dumpbuffer("Shell output", pstate->tn_outbuffer, pstate->tn_sndlen); + nsh_telnetdump(&pstate->tn_vtbl, "Shell output", + pstate->tn_outbuffer, pstate->tn_sndlen); tio_semtake(tio); /* Only one call to send at a time */ if (send(tio->tio_sockfd, pstate->tn_outbuffer, pstate->tn_sndlen, 0) < 0) { @@ -531,13 +489,15 @@ static void *nsh_connection(void *arg) /* Read a buffer of data from the TELNET client */ - ret = recv(tio->tio_sockfd, tio->tio_inbuffer, CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE, 0); + ret = recv(tio->tio_sockfd, tio->tio_inbuffer, + CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE, 0); if (ret > 0) { /* Process the received TELNET data */ - nsh_dumpbuffer("Received buffer", tio->tio_inbuffer, ret); + nsh_telnetdump(&pstate->tn_vtbl, "Received buffer", + tio->tio_inbuffer, ret); ret = nsh_receive(pstate, ret); } }