Skip to content

Commit

Permalink
./do.sh dump now helps the user when they don't have the right tools …
Browse files Browse the repository at this point in the history
…installed
  • Loading branch information
mvines committed Oct 14, 2020
1 parent 47ef251 commit 9501e40
Showing 1 changed file with 43 additions and 37 deletions.
80 changes: 43 additions & 37 deletions do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ readCargoVariable() {

while read -r name equals value _; do
if [[ $name = "$variable" && $equals = = ]]; then
echo "${value//\"/}"
return
echo "${value//\"/}"
return
fi
done < <(cat "$Cargo_toml")
echo "Unable to locate $variable in $Cargo_toml" 1>&2
Expand All @@ -50,20 +50,20 @@ perform_action() {
features=

crateName="$(readCargoVariable name "$projectDir/Cargo.toml")"
so_path="$targetDir/$profile"
so_name="${crateName//\-/_}"
so_name_unstripped="${so_name}_unstripped"

if [[ -f "$projectDir"/Xargo.toml ]]; then
features="--features=program"
features="--features=program"
fi
case "$1" in
build)
if [[ -f "$projectDir"/Xargo.toml ]]; then
echo "build $crateName ($projectDir)"
"$sdkDir"/rust/build.sh "$projectDir"

so_path="$targetDir/$profile"
so_name="${crateName//\-/_}"
cp "$so_path/${so_name}.so" "$so_path/${so_name}_debug.so"
"$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/$so_name.so"
echo "build $crateName ($projectDir)"
"$sdkDir"/rust/build.sh "$projectDir"
cp "$so_path/${so_name}.so" "$so_path/${so_name_unstripped}.so"
"$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/${so_name}.so"
else
echo "$projectDir does not contain a program, skipping"
fi
Expand Down Expand Up @@ -98,43 +98,49 @@ perform_action() {
# - readelf
# - rustfilt
if [[ -f "$projectDir"/Xargo.toml ]]; then
if ! which rustfilt > /dev/null; then
echo "Error: rustfilt not found. It can be installed by running: cargo install rustfilt"
exit 1
fi
if ! which readelf > /dev/null; then
if [[ $(uname) = Darwin ]]; then
echo "Error: readelf not found. It can be installed by running: brew install binutils"
else
echo "Error: readelf not found."
fi
exit 1
fi

(
cd "$CALLER_PWD"
"$0" build "$2"
)

echo "dump $crateName ($projectDir)"

"$0" build "$2"
so="$so_path/${so_name}.so"

so_path="$targetDir/$profile"
so_name="${crateName//\-/_}"
so="$so_path/${so_name}_debug.so"
if [[ ! -r "$so" ]]; then
echo "Error: No dump created, cannot read $so"
exit 1
fi
dump="$so_path/${so_name}_dump"

if [ -f "$so" ]; then
ls \
-la \
"$so" \
>"${dump}_mangled.txt"
readelf \
-aW \
"$so" \
>>"${dump}_mangled.txt"
(
set -x
ls -la "$so" > "${dump}_mangled.txt"
readelf -aW "$so" >>"${dump}_mangled.txt"
"$sdkDir/dependencies/llvm-native/bin/llvm-objdump" \
-print-imm-hex \
--source \
--disassemble \
"$so" \
>>"${dump}_mangled.txt"
sed \
s/://g \
<"${dump}_mangled.txt" |
rustfilt \
>"${dump}.txt"
if [ -f "$dump.txt" ]; then
echo "Dumped: $dump.txt"
else
echo "Error: No dump created"
exit 1
fi
>> "${dump}_mangled.txt"
sed s/://g <"${dump}_mangled.txt" | rustfilt >"${dump}.txt"
)
if [[ -f "$dump.txt" ]]; then
echo "Created $dump.txt"
else
echo "Error: No dump created, cannot find: $so"
echo "Error: No dump created"
exit 1
fi
else
Expand Down

0 comments on commit 9501e40

Please sign in to comment.