imgtools/romtools/maksym/hpsym.pl
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #
       
     2 # Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # munge maksym.log into form suitable for an HP logic analyser
       
    16 # History
       
    17 # 0.1	08/06/99	First release.
       
    18 # 0.2	09/06/99	Always include symbols from E32 and device drivers.
       
    19 # 0.3	15/06/99	Added rombase flag & argument.
       
    20 # 0.4	11/11/99	Remove c++filt step. Ensure symbols don't contain spaces.
       
    21 #
       
    22 
       
    23 # Globals
       
    24 my $rombase = 0x50000000;
       
    25 my @executables = ( 'euser' );
       
    26 
       
    27 my $maksym = 'maksym.log';
       
    28 my $gpa = 'symbols.gpa';
       
    29 my $arg;
       
    30 my $skip;
       
    31 
       
    32 # Standard e32toolp path scanning
       
    33 use FindBin;		# for FindBin::Bin
       
    34 
       
    35 my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
       
    36 
       
    37 BEGIN {
       
    38 # check user has a version of perl that will cope
       
    39 	require 5.005_03;
       
    40 # establish the path to the Perl libraries: currently the same directory as this script
       
    41 	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
       
    42 	$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
       
    43 	$PerlLibPath .= "\\";
       
    44 }
       
    45 
       
    46 use lib $PerlLibPath;
       
    47 use Modload;
       
    48 Load_SetModulePath($PerlLibPath);
       
    49 
       
    50 if (@ARGV)
       
    51   {
       
    52 	$maksym = shift;
       
    53 	if ($maksym =~ /^-[h\?]$/i)
       
    54 	  {
       
    55 		&help;
       
    56 	  }
       
    57 	elsif ($maksym =~ /^(-r)/i)
       
    58 	  {
       
    59 		if (@ARGV)
       
    60 		  {
       
    61 			$rombase=hex(shift);
       
    62 			if (@ARGV)
       
    63 			  {
       
    64 				$maksym = shift;
       
    65 			  }
       
    66 			else
       
    67 			  {
       
    68 				print "\nError: missing <infile> argument.\n";
       
    69 				&usage;
       
    70 				exit 1;
       
    71 			  }
       
    72 		  }
       
    73 		else
       
    74 		  {
       
    75 			print "\nError: rombase flag '-r' requires an argument.\n";
       
    76 			&usage;
       
    77 			exit 1;
       
    78 		  }
       
    79 	  }
       
    80 	elsif ($maksym =~ /^(-.*)/)
       
    81 	  {
       
    82 		print "\nError: invalid flag '$1'\n.";
       
    83 		&usage;
       
    84 		exit 1;
       
    85 	  }
       
    86 
       
    87 	if (@ARGV)
       
    88 	  {
       
    89 		my $file;
       
    90 
       
    91 		$gpa = shift;
       
    92 		
       
    93 		foreach $file (@ARGV)
       
    94 		  {
       
    95 			push @executables, quotemeta($file);
       
    96 		  }
       
    97 	  }
       
    98   }
       
    99 else
       
   100   {
       
   101 	&help;
       
   102   }
       
   103 		
       
   104 open (GPA, ">$gpa") or die "Can't write to '$gpa'";
       
   105 open (LOG, "$maksym") or die "Can't read '$maksym'";
       
   106 
       
   107 while (<LOG>)
       
   108   {
       
   109 	if (/^From\s+\S+\\(.+)\\.+\\(.+)$/)
       
   110 	  {
       
   111 		# Found a new file
       
   112 		$abi = $1;
       
   113 		$file = $2;
       
   114 
       
   115 		# Decode this file if it's kernel-side or matches the supplied regexp
       
   116 		if ($abi =~ /^(M|S)/i)
       
   117 		  {
       
   118 			$skip = 0;
       
   119 		  }
       
   120 		else
       
   121 		  {
       
   122 			$skip = 1;
       
   123 			foreach $re (@executables)
       
   124 			  {
       
   125 				$skip = 0 if ($file =~ /$re/i);
       
   126 			  }
       
   127 		  }
       
   128 		print "$file\n" if not $skip;
       
   129 	  }
       
   130 	elsif (!/^$/ && !$skip)
       
   131 	  {
       
   132 		/^(\S*)\s*(\S*)\s*(.*)$/;
       
   133 		$addr=hex($1) - $rombase;
       
   134 		$len=(hex($2)<0) ? 4 : hex($2);
       
   135 		$name = $3;
       
   136 		$name =~ s/\(.*//;		# remove arguments and any const qualifier
       
   137 
       
   138 		# remove spaces from symbol names
       
   139 		if ($name =~ 'global constructors keyed to (.*)')
       
   140 		  {
       
   141 			$name = $1.'_CTOR';
       
   142 		  }
       
   143 		elsif ($name =~ 'global destructors keyed to (.*)')
       
   144 		  {
       
   145 			$name = $1.'_DTOR';
       
   146 		  }
       
   147 		elsif ($name =~ '(.*) virtual table')
       
   148 		  {
       
   149 			$name = $1.'_VTBL';
       
   150 		  }
       
   151 		else
       
   152 		  {
       
   153 			$name =~ s/ /_/g;
       
   154 		  }
       
   155 		print GPA "$name\t", sprintf('%08x', $addr), '..',
       
   156 		  sprintf('%08x', $addr+$len-1), "\n";
       
   157 	  }
       
   158   }
       
   159 
       
   160 close LOG;
       
   161 close GPA;
       
   162 exit 0;
       
   163 
       
   164 
       
   165 sub help ()
       
   166   {
       
   167 	my $build;
       
   168 
       
   169 	&Load_ModuleL('E32TPVER');
       
   170 	print "\nhpsym - Produce symbolic info in \"HP GPA Symbol File Format\"" .
       
   171 	  " suitable for use\n        with a HP logic analyser (Build ",
       
   172 	  &E32tpver, ")\n";
       
   173 	&usage;
       
   174 	exit 0;
       
   175   }
       
   176 
       
   177 sub usage ()
       
   178   {
       
   179 	print <<EOF
       
   180 
       
   181 Usage:
       
   182   hpsym [-r <rombase>] <logfile> [<outfile> [<executables>]]
       
   183 
       
   184 Where:
       
   185   <rombase>     Offset in hex of logical address from physical address of ROM.
       
   186                 Defaults to 50000000. Use 0 for single-process builds.
       
   187   <logfile>     Log from maksym tool.
       
   188   <outfile>     Output filename. Default is 'symbols.gpa'. Use - for stdout.
       
   189   <executables> Names of additional executables to list the symbols of.
       
   190                 ASSP-specific executables and EUSER are always included.
       
   191 
       
   192 Example:
       
   193   hpsym maksym.log symbols.gpa efile efsrv .fsy
       
   194 
       
   195 EOF
       
   196   }