X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Fsysdump.c;h=0b0d49524ffd14b695ac0e7c205b7d237d733dc4;hb=c2274b2767dba3175e585bd17f9f4a93b56cdc63;hp=aa656240e0eacab8c6aa09bd0a73423056bf4ced;hpb=7bf6856e9c9fcb0cf9522e4104363acaef773202;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/sysdump.c b/binutils/sysdump.c index aa656240e0..0b0d49524f 100644 --- a/binutils/sysdump.c +++ b/binutils/sysdump.c @@ -1,49 +1,67 @@ /* Sysroff object format dumper. - Copyright (C) 1994 Free Software Foundation, Inc. + Copyright 1994, 1995, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. -This file is part of GNU Binutils. + This file is part of GNU Binutils. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ /* Written by Steve Chamberlain . - This program reads a SYSROFF object file and prints it in an - almost human readable form to stdout. */ + This program reads a SYSROFF object file and prints it in an + almost human readable form to stdout. */ + +#include "bfd.h" +#include "bucomm.h" +#include "safe-ctype.h" #include #include #include #include "sysroff.h" -#include - -#define PROGRAM_VERSION "1.0" static int dump = 1; static int segmented_p; static int code; +static int addrsize = 4; static FILE *file; -static char *xcalloc(a,b) -int a; -int b; -{ - char *r = xmalloc(a,b); - memset (r, 0, a * b); - return r; -} +static void dh PARAMS ((unsigned char *, int)); +static void itheader PARAMS ((char *, int)); +static void p PARAMS ((void)); +static void tabout PARAMS ((void)); +static void pbarray PARAMS ((barray *)); +static int getone PARAMS ((int)); +static int opt PARAMS ((int)); +static void must PARAMS ((int)); +static void tab PARAMS ((int, char *)); +static void dump_symbol_info PARAMS ((void)); +static void derived_type PARAMS ((void)); +static void module PARAMS ((void)); +static void show_usage PARAMS ((FILE *, int)); +static void show_help PARAMS ((void)); + +extern char *getCHARS PARAMS ((unsigned char *, int *, int, int)); +extern int fillup PARAMS ((char *)); +extern barray getBARRAY PARAMS ((unsigned char *, int *, int, int)); +extern int getINT PARAMS ((unsigned char *, int *, int, int)); +extern int getBITS PARAMS ((char *, int *, int, int)); +extern void sysroff_swap_tr_in PARAMS ((void)); +extern void sysroff_print_tr_out PARAMS ((void)); +extern int main PARAMS ((int, char **)); char * getCHARS (ptr, idx, size, max) @@ -68,11 +86,12 @@ getCHARS (ptr, idx, size, max) } *idx += b * 8; - r = calloc (b + 1, 1); + r = xcalloc (b + 1, 1); memcpy (r, ptr + oc, b); r[b] = 0; return r; } + static void dh (ptr, size) unsigned char *ptr; @@ -80,33 +99,32 @@ dh (ptr, size) { int i; int j; - int span = 20; + int span = 16; printf ("\n************************************************************\n"); for (i = 0; i < size; i += span) { - for (j = 0; j < span && j + i < size; j++) + for (j = 0; j < span; j++) { - printf ("%02x ", ptr[i + j]); + if (j + i < size) + printf ("%02x ", ptr[i + j]); + else + printf (" "); } - printf ("\n"); - } - for (i = 0; i < size; i += span) - { for (j = 0; j < span && j + i < size; j++) { int c = ptr[i + j]; if (c < 32 || c > 127) c = '.'; - printf (" %c ", c); + printf ("%c", c); } printf ("\n"); } } -int +int fillup (ptr) char *ptr; { @@ -127,23 +145,23 @@ fillup (ptr) } if (dump) dh (ptr, size); - return size; -} + return size - 1; +} -barray +barray getBARRAY (ptr, idx, dsize, max) unsigned char *ptr; int *idx; - int dsize; - int max; + int dsize ATTRIBUTE_UNUSED; + int max ATTRIBUTE_UNUSED; { barray res; int i; int byte = *idx / 8; int size = ptr[byte++]; res.len = size; - res.data = (unsigned char *)xmalloc (size); + res.data = (unsigned char *) xmalloc (size); for (i = 0; i < size; i++) { res.data[i] = ptr[byte++]; @@ -151,9 +169,7 @@ getBARRAY (ptr, idx, dsize, max) return res; } - - -int +int getINT (ptr, idx, size, max) unsigned char *ptr; int *idx; @@ -168,7 +184,7 @@ getINT (ptr, idx, size, max) return 0; } if (size == -2) - size = 4; + size = addrsize; if (size == -1) size = 0; switch (size) @@ -192,20 +208,22 @@ getINT (ptr, idx, size, max) } int -getBITS (ptr, idx, size) +getBITS (ptr, idx, size, max) char *ptr; int *idx; - int size; + int size, max; { int byte = *idx / 8; int bit = *idx % 8; + if (byte >= max) + return 0; + *idx += size; return (ptr[byte] >> (8 - bit - size)) & ((1 << size) - 1); } - static void itheader (name, code) char *name; @@ -213,6 +231,7 @@ itheader (name, code) { printf ("\n%s 0x%02x\n", name, code); } + static int indent; static void p () @@ -225,7 +244,7 @@ p () printf ("> "); } -static void +static void tabout () { p (); @@ -239,7 +258,8 @@ pbarray (y) printf ("%d (", y->len); for (x = 0; x < y->len; x++) { - printf ("(%02x %c)", y->data[x], isprint (y->data[x]) ? y->data[x] : '.'); + printf ("(%02x %c)", y->data[x], + ISPRINT (y->data[x]) ? y->data[x] : '.'); } printf (")\n"); } @@ -249,6 +269,28 @@ pbarray (y) #include "sysroff.c" +/* + * FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't + * hack the special case of the tr block, which has no contents. So we + * implement our own functions for reading in and printing out the tr + * block. + */ + +#define IT_tr_CODE 0x7f +void +sysroff_swap_tr_in() +{ + char raw[255]; + + memset(raw, 0, 255); + fillup(raw); +} + +void +sysroff_print_tr_out() +{ + itheader("tr", IT_tr_CODE); +} static int getone (type) @@ -283,6 +325,7 @@ getone (type) { struct IT_hd dummy; sysroff_swap_hd_in (&dummy); + addrsize = dummy.afl; sysroff_print_hd_out (&dummy); } break; @@ -419,14 +462,14 @@ getone (type) sysroff_swap_dss_in (&dummy); sysroff_print_dss_out (&dummy); } + break; case IT_hs_CODE: { struct IT_hs dummy; sysroff_swap_hs_in (&dummy); sysroff_print_hs_out (&dummy); } - - + break; case IT_dps_CODE: { struct IT_dps dummy; @@ -434,13 +477,10 @@ getone (type) sysroff_print_dps_out (&dummy); } break; - - case IT_tr_CODE: { - struct IT_tr dummy; - sysroff_swap_tr_in (&dummy); - sysroff_print_tr_out (&dummy); + sysroff_swap_tr_in (); + sysroff_print_tr_out (); } break; case IT_dds_CODE: @@ -450,14 +490,12 @@ getone (type) sysroff_print_dds_out (&dummy); } break; - break; default: printf ("GOT A %x\n", c); return 0; break; } return 1; - } static int @@ -467,37 +505,49 @@ opt (x) return getone (x); } -static void +#if 0 + +/* This is no longer used. */ + +static void unit_info_list () { - if (opt (IT_un_CODE)) + while (opt (IT_un_CODE)) { + getone (IT_us_CODE); + while (getone (IT_sc_CODE)) - { - getone (IT_ss_CODE); - } + getone (IT_ss_CODE); while (getone (IT_er_CODE)) - { - } + ; while (getone (IT_ed_CODE)) - { - } + ; } } +#endif + +#if 0 + +/* This is no longer used. */ + static void object_body_list () { - getone (IT_sh_CODE); - while (getone (IT_ob_CODE)) - ; - while (getone (IT_rl_CODE)) - ; + while (getone (IT_sh_CODE)) + { + while (getone (IT_ob_CODE)) + ; + while (getone (IT_rl_CODE)) + ; + } } -static void +#endif + +static void must (x) int x; { @@ -507,7 +557,7 @@ must (x) } } -static void +static void tab (i, s) int i; char *s; @@ -520,10 +570,9 @@ tab (i, s) printf ("\n"); } } -static void derived_type (); static void -symbol_info () +dump_symbol_info () { tab (1, "SYMBOL INFO"); while (opt (IT_dsy_CODE)) @@ -546,27 +595,27 @@ derived_type () { if (opt (IT_dpp_CODE)) { - symbol_info (); + dump_symbol_info (); must (IT_dpp_CODE); } else if (opt (IT_dfp_CODE)) { - symbol_info (); + dump_symbol_info (); must (IT_dfp_CODE); } else if (opt (IT_den_CODE)) { - symbol_info (); + dump_symbol_info (); must (IT_den_CODE); } else if (opt (IT_den_CODE)) { - symbol_info (); + dump_symbol_info (); must (IT_den_CODE); } else if (opt (IT_dds_CODE)) { - symbol_info (); + dump_symbol_info (); must (IT_dds_CODE); } else if (opt (IT_dar_CODE)) @@ -591,55 +640,73 @@ derived_type () tab (-1, ""); } +#if 0 + +/* This is no longer used. */ + static void program_structure () { tab (1, "PROGRAM STRUCTURE"); while (opt (IT_dps_CODE)) { - opt (IT_dso_CODE); + must (IT_dso_CODE); opt (IT_dss_CODE); - symbol_info (); + dump_symbol_info (); + must (IT_dps_CODE); } tab (-1, ""); } + +#endif + +#if 0 + +/* This is no longer used. */ + static void debug_list () { tab (1, "DEBUG LIST"); - getone (IT_du_CODE); - while (getone (IT_dus_CODE)) - ; - while (opt (IT_dfl_CODE)) - ; - while (getone (IT_dus_CODE)) - ; + must (IT_du_CODE); + opt (IT_dus_CODE); program_structure (); + must (IT_dln_CODE); - getone (IT_dln_CODE); tab (-1, ""); } +#endif + static void module () { int c = 0; int l = 0; - - tab (1, "MODULE***\n"); - getone (IT_cs_CODE); - getone (IT_hd_CODE); - getone (IT_hs_CODE); + tab (1, "MODULE***\n"); - while (!opt (IT_tr_CODE) && c < 10) + do { - unit_info_list (); - object_body_list (); - debug_list (); -c++; + c = getc (file); + ungetc (c, file); + + c &= 0x7f; } + while (getone (c) && c != IT_tr_CODE); + +#if 0 + must (IT_cs_CODE); + must (IT_hd_CODE); + opt (IT_hs_CODE); + + unit_info_list (); + object_body_list (); + debug_list (); + + must (IT_tr_CODE); +#endif tab (-1, ""); c = getc (file); @@ -656,28 +723,26 @@ c++; } } - -char * program_name; +char *program_name; static void show_usage (file, status) FILE *file; int status; { - fprintf (file, "Usage: %s [-hV] in-file\n", program_name); + fprintf (file, _("Usage: %s [-hV] in-file\n"), program_name); exit (status); } static void show_help () { - printf ("%s: Print a human readable interpretation of a SYSROFF object file\n", + printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"), program_name); show_usage (stdout, 0); } - -int +int main (ac, av) int ac; char **av; @@ -685,18 +750,25 @@ main (ac, av) char *input_file = NULL; int opt; static struct option long_options[] = - { - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'V' }, - { NULL, no_argument, 0, 0 } - }; + { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {NULL, no_argument, 0, 0} + }; + +#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) + setlocale (LC_MESSAGES, ""); +#endif +#if defined (HAVE_SETLOCALE) + setlocale (LC_CTYPE, ""); +#endif + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); program_name = av[0]; xmalloc_set_program_name (program_name); - while ((opt = getopt_long (ac, av, "hV", long_options, - (int *) NULL)) - != EOF) + while ((opt = getopt_long (ac, av, "hV", long_options, (int *) NULL)) != EOF) { switch (opt) { @@ -704,7 +776,7 @@ main (ac, av) show_help (); /*NOTREACHED*/ case 'V': - printf ("GNU %s version %s\n", program_name, PROGRAM_VERSION); + print_version ("sysdump"); exit (0); /*NOTREACHED*/ case 0: @@ -724,20 +796,15 @@ main (ac, av) if (!input_file) { - fprintf (stderr,"%s: no input file specified\n", - program_name); - exit(1); + fatal (_("no input file specified")); } - file = fopen (input_file, "r"); + file = fopen (input_file, FOPEN_RB); if (!file) { - fprintf (stderr,"%s: cannot open input file %s\n", - program_name, input_file); - exit(1); + fatal (_("cannot open input file %s"), input_file); } - module (); return 0; }