2021-02-18 04:20:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-03-10 20:43:44 +00:00
|
|
|
######################
|
|
|
|
# extractFunctionRadix.sh
|
|
|
|
#
|
|
|
|
# Written: Ross Thompson
|
|
|
|
# email: ross1728@gmail.com
|
|
|
|
# Created: March 1, 2021
|
|
|
|
# Modified: March 10, 2021
|
|
|
|
#
|
2021-03-12 21:29:02 +00:00
|
|
|
# Purpose: Processes all compiled object files into 2 types of files which assist in debuging applications.
|
|
|
|
# File 1: .addr: A sorted list of function starting addresses.
|
2021-03-10 20:43:44 +00:00
|
|
|
# When a the PCE is greater than or equal to the function's starting address, the label will be associated with this address.
|
2021-03-12 21:29:02 +00:00
|
|
|
# File 2: .lab: A sorted list of funciton labels. The names of functions. Modelsim will display these names rather than the function address.
|
2021-03-10 20:43:44 +00:00
|
|
|
#
|
|
|
|
# A component of the Wally configurable RISC-V project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
|
|
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
|
|
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
|
|
# is furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
|
|
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
######################
|
|
|
|
|
|
|
|
|
|
|
|
function processProgram {
|
|
|
|
local objDumpFile=$1
|
|
|
|
local numBits=$2
|
|
|
|
local size=$(($numBits/4))
|
|
|
|
local index=$3
|
|
|
|
|
|
|
|
# when size = 16 => 64 bit
|
|
|
|
# when size = 8 => 32 bit
|
|
|
|
local listOfAddr=`egrep -i "^[0-9]{$size} <[0-9a-zA-Z_]+>" $objDumpFile`
|
|
|
|
|
|
|
|
# skip if the wrong bit width.
|
|
|
|
if [ -z "$listOfAddr" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2021-02-18 04:20:28 +00:00
|
|
|
|
|
|
|
# parse out the addresses and the labels
|
2021-03-10 20:43:44 +00:00
|
|
|
local addresses=`echo "$listOfAddr" | awk '{print $1}'`
|
|
|
|
local labels=`echo "$listOfAddr" | awk '{print "\""$2"\"", "-color \"SpringGreen\","}' | tr -d '<>:'`
|
2021-03-11 23:12:21 +00:00
|
|
|
local labelsName=`echo "$listOfAddr" | awk '{print ""$2""}' | tr -d '<>:'`
|
2021-02-18 04:20:28 +00:00
|
|
|
|
2021-03-10 20:43:44 +00:00
|
|
|
# output per program function address list
|
2021-02-18 04:20:28 +00:00
|
|
|
echo "$addresses" > $objDumpFile.addr
|
2021-03-11 23:12:21 +00:00
|
|
|
echo "$labelsName" > $objDumpFile.lab
|
2021-02-18 04:20:28 +00:00
|
|
|
|
|
|
|
# need to add some formatting to each line
|
2021-03-10 20:43:44 +00:00
|
|
|
local numLines=`echo "$listOfAddr" | wc -l`
|
2021-03-10 17:00:51 +00:00
|
|
|
|
2021-03-10 20:43:44 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
index=0
|
|
|
|
|
|
|
|
for objDumpFile in "$@";
|
|
|
|
do
|
|
|
|
|
|
|
|
processProgram "$objDumpFile" 32 "$index"
|
|
|
|
processProgram "$objDumpFile" 64 "$index"
|
|
|
|
|
2021-02-27 01:43:40 +00:00
|
|
|
index=$(($index+1))
|
|
|
|
|
2021-02-18 04:20:28 +00:00
|
|
|
done
|
2021-03-10 17:00:51 +00:00
|
|
|
|
2021-03-10 20:43:44 +00:00
|
|
|
exit 0
|
|
|
|
|