source: rtems/c/src/lib/libbsp/unix/posix/tools/shmdump.in @ df25c998

4.104.114.84.95
Last change on this file since df25c998 was 11cfb6f7, checked in by Joel Sherrill <joel.sherrill@…>, on 10/14/98 at 20:19:30

Patch from Ralf Corsepius <corsepiu@…>:

  1. Rtems contains some perl scripts that use hard-coded paths to /usr/bin/perl or /usr/local/bin/perl I have already fixed these problems by adding some checks to configure.in. While doing this, I also cleaned up some more autoconf related problems for generating shell scripts. This patch might seem a bit scary to you, but I am quite confident it won't break something (I've been testing it for almost a week now, however it might introduce typos for a limited number configurations I don't have access to - But it shouldn't be a problem for you to test them :-).

I expect to get this finished tonight, hence you will very likely
have the patch when you get up tomorrow.

Changes:

  • Check for PERL and disable all PERL scripts if perl wasn't found.
  • Generate all KSHELL-scripts with autoconf instead of make-script
  • Automatic dependency handling for autoconf generated KSHELL or PERL scripts (make/rtems.cfg)

Notes:

  • this patch contains new files and deletes some other files.
  • The patch is relative to rtems-4.0.0-beta4 with my previous rtems-rc-981014-1.diff patch applied.

Testing:

I tested it with sh-rtems and posix under linux. Now all targets
which are touched by this patch and which are not used while building
for sh-rtems and posix still need to be tested. AFAIS, only the
sparc/erc32 BSP should be affected by this criterion. And if you
like to, you should also consider testing it on a Cygwin32 and a
Solaris host for one arbitrary BSP.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#!@PERL@
2#
3#  $Id$
4#
5eval "exec @PERL@ -S $0 $*"
6    if $running_under_some_shell;
7
8# dump shared memory segment   tony@divnc.com
9
10require 'sys/shm.ph';
11require 'getopts.pl';
12&Getopts("vhi:k:f:l:b:w");      # verbose, help, id, key, first, length, word, base
13
14if ($opt_h || ($opt_i && $opt_k))
15{
16    print STDERR <<NO_MORE_HELP;
17shmdump
18
19    Dump contents of specifed shared memory segment.
20
21Usage: $0  [options]
22
23    -h          -- help
24    -v          -- possibly more verbose
25    -i shmid    -- shm id
26    -k shmkey   -- shm key
27    -f first    -- start of partial dump
28    -l length   -- length of partial dump
29    -w          -- dump as 4byte words instead of bytes
30    -b base     -- use 'base' as base address for output
31
32    anything else == this help message
33NO_MORE_HELP
34    exit 1;
35}
36
37$verbose = $opt_v;
38$id = $opt_i;
39$key = $opt_k;
40$offset = $opt_f;
41$print_length = $opt_l;
42$base = $opt_b;
43$word_dump = $opt_w;
44
45if ($key)
46{
47    # ensure key is an integer
48    $key = oct($key) if $key =~ /^0/;
49    die "Could not convert key to id; $!" unless $id = shmget($key, 1, 0);
50}
51
52# ensure integerhood in case of leading '0x'
53$base = oct($base) if $base =~ /^0/;
54$offset = oct($offset) if $offset =~ /^0/;
55$print_length = oct($print_length) if $print_length =~ /^0/;
56
57if ( ! shmctl($id, &IPC_STAT, $shmid_ds))
58{
59    die "shmctl(2) for id $id failed -- (I was trying to get size): $!";
60}
61
62# Pick the length out.
63# It is at byte offset 0x30 on hpux9 and probably hpux10
64# Also get the key if we don't have it already.  Don't need it tho...
65$length = unpack("I", substr($shmid_ds, 0x30, 4));
66$key = unpack("I", substr($shmid_ds, 0x14, 4)) if ! $key;
67
68# poke around looking for length and key
69# print "I guess: length: $length,  key: $key\n";
70# print "****$shmid_ds****\n"; die "";
71
72# make sure offset and print length make sense
73$print_length = $length if ! $print_length;
74if (($offset + $print_length) > $length)
75{
76    die "offset ($offset) and length ($print_length) go beyond end of segment ($length bytes)";
77}
78
79printf("KEY: 0x%X (%d)  ", $key, $key) if ($key);
80printf "ID: $id\n";
81printf "   %d bytes (0x%X), %d words, logical base is 0x%X\n",
82       $length, $length, $length / 4, $base;
83if ($offset || ($print_length != $length))
84{
85    printf "   printing %X (%d) bytes starting at offset 0x%X (%d)\n",
86           $print_length, $print_length, $offset, $offset;
87}
88printf "\n";
89
90if ( ! shmread($id, $shm_data, $offset, $print_length))
91{
92    die "could not attach and read from shmid $id: $!";
93}
94
95# the dump code below derived from "Real Perl Programs" example "xdump"
96# from Camel book
97
98$base += $offset;
99$offset = 0;
100for ($len = $print_length; $len >= 16; )
101{
102    $data = substr($shm_data, $offset, 16);
103
104    @array = unpack('N4', $data);
105    $data =~ tr/\0-\37\177-\377/./;
106    printf "%8.8lX   %8.8lX %8.8lX %8.8lX %8.8lX   |%s|\n",
107            $base, @array, $data;
108
109    $offset += 16;
110    $base += 16;
111    $len -= 16;
112}
113
114# Now finish up the end a byte at a time
115
116if ($len)
117{
118    $data = substr($shm_data, $offset, $len);
119    @array = unpack('C*', $data);
120    for (@array)
121    {
122        $_ = sprintf('%2.2X', $_);
123    }
124
125    push(@array, '  ') while $len++ < 16;
126
127    $data =~ tr/\0-\37\177-\377/./;
128    $data =~ s/[^ -~]/./g;
129
130    printf "%8.8lX   ", $base;
131    printf "%s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   |%-16s|\n",
132           @array, $data;
133}
134
Note: See TracBrowser for help on using the repository browser.