#!@PERL@ # # $Id$ # eval "exec @PERL@ -S $0 $*" if $running_under_some_shell; # dump shared memory segment tony@divnc.com require 'sys/shm.ph'; require 'getopts.pl'; &Getopts("vhi:k:f:l:b:w"); # verbose, help, id, key, first, length, word, base if ($opt_h || ($opt_i && $opt_k)) { print STDERR < $length) { die "offset ($offset) and length ($print_length) go beyond end of segment ($length bytes)"; } printf("KEY: 0x%X (%d) ", $key, $key) if ($key); printf "ID: $id\n"; printf " %d bytes (0x%X), %d words, logical base is 0x%X\n", $length, $length, $length / 4, $base; if ($offset || ($print_length != $length)) { printf " printing %X (%d) bytes starting at offset 0x%X (%d)\n", $print_length, $print_length, $offset, $offset; } printf "\n"; if ( ! shmread($id, $shm_data, $offset, $print_length)) { die "could not attach and read from shmid $id: $!"; } # the dump code below derived from "Real Perl Programs" example "xdump" # from Camel book $base += $offset; $offset = 0; for ($len = $print_length; $len >= 16; ) { $data = substr($shm_data, $offset, 16); @array = unpack('N4', $data); $data =~ tr/\0-\37\177-\377/./; printf "%8.8lX %8.8lX %8.8lX %8.8lX %8.8lX |%s|\n", $base, @array, $data; $offset += 16; $base += 16; $len -= 16; } # Now finish up the end a byte at a time if ($len) { $data = substr($shm_data, $offset, $len); @array = unpack('C*', $data); for (@array) { $_ = sprintf('%2.2X', $_); } push(@array, ' ') while $len++ < 16; $data =~ tr/\0-\37\177-\377/./; $data =~ s/[^ -~]/./g; printf "%8.8lX ", $base; printf "%s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s |%-16s|\n", @array, $data; }