source: rtems/cpukit/libmisc/shell/main_mwdump.c @ 8916bdc7

4.104.115
Last change on this file since 8916bdc7 was caf0e53, checked in by Joel Sherrill <joel.sherrill@…>, on 10/01/08 at 20:02:34

2008-10-01 Gene Smith <gene.smith@…>

PR 1328/cpukit

  • libmisc/shell/main_mdump.c, libmisc/shell/main_mwdump.c: Fix printing of more than 256 bytes.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 *  MWDUMP Shell Command Implmentation
3 *
4 *  Author: Fernando RUIZ CASAS
5 *  Work: fernando.ruiz@ctv.es
6 *  Home: correo@fernando-ruiz.com
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <ctype.h>
20#include <stdio.h>
21#include <string.h>
22#include <inttypes.h>
23
24#include <rtems.h>
25#include <rtems/shell.h>
26#include "internal.h"
27
28int rtems_shell_main_mwdump(
29  int   argc,
30  char *argv[]
31)
32{
33  unsigned char  n, m;
34  int            max;
35  int            res;
36  uintptr_t      addr = 0;
37  unsigned char *pb;
38
39  if (argc>1)
40    addr = rtems_shell_str2int(argv[1]);
41
42  if (argc>2) {
43    max = rtems_shell_str2int(argv[2]);
44    if (max <= 0) {
45      max = 1;      /* print 1 item if 0 or neg. */
46      res = 0;
47    }
48    else {
49      max--;
50      res = max & 0xf;/* num bytes in last row */
51      max >>= 4;      /* div by 16 */
52      max++;          /* num of rows to print */
53      if (max > 20) { /* limit to 20 */
54        max = 20;
55        res = 0xf;    /* 16 bytes print in last row */
56      }
57    }
58  }
59  else {
60    max = 20;
61    res = 0xf;
62  }
63
64  for (m=0;m<max;m++) {
65    printf("0x%08" PRIXPTR " ",addr);
66    pb = (unsigned char *) addr;
67    for (n=0;n<=(m==(max-1)?res:0xf);n+=2)
68      printf("%04X%c",*((unsigned short*)(pb+n)),n==6?'-':' ');
69    for (;n<=0xf;n+=2)
70      printf("    %c", n==6?'-':' ');
71    for (n=0;n<=(m==(max-1)?res:0xf);n++) {
72      printf("%c", isprint(pb[n]) ? pb[n] : '.');
73    }
74    printf("\n");
75    addr += 16;
76  }
77  return 0;
78}
79
80rtems_shell_cmd_t rtems_shell_WDUMP_Command = {
81  "wdump",                                      /* name */
82  "wdump [address [length]]",                   /* usage */
83  "mem",                                        /* topic */
84  rtems_shell_main_mwdump,                      /* command */
85  NULL,                                         /* alias */
86  NULL                                          /* next */
87};
Note: See TracBrowser for help on using the repository browser.