summaryrefslogtreecommitdiffstats
path: root/userspace/cuda/570.144/scripts/disasm.sh
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/cuda/570.144/scripts/disasm.sh')
-rwxr-xr-xuserspace/cuda/570.144/scripts/disasm.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/userspace/cuda/570.144/scripts/disasm.sh b/userspace/cuda/570.144/scripts/disasm.sh
new file mode 100755
index 0000000..01fea69
--- /dev/null
+++ b/userspace/cuda/570.144/scripts/disasm.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# disasm.sh - objdump helpers for a library under analysis.
+#
+# Usage:
+# scripts/disasm.sh <file> <hex-vaddr> [before] [after]
+# disassemble [vaddr-before, vaddr+after] (default 0x40 each side)
+# scripts/disasm.sh --bytes <file> <hex-start> <hex-end>
+# raw bytes in the range
+# scripts/disasm.sh --symbol <file> <name>
+# exported symbol address/size (readelf dyn-syms)
+# scripts/disasm.sh --nearest <file> <hex-vaddr>
+# nearest preceding exported symbol (FUNC) and the offset into it
+set -e
+
+cmd="${1:?usage: disasm.sh [--bytes|--symbol|--nearest] <file> ...}"
+case "$cmd" in
+--bytes)
+ file="$2"; start="$3"; end="$4"
+ objdump -s --start-address="$start" --stop-address="$end" "$file"
+ ;;
+--symbol)
+ file="$2"; name="$3"
+ readelf -sW --dyn-syms "$file" | awk -v n="$name" '$8 == n {print}'
+ ;;
+--nearest)
+ file="$2"; target="$3"
+ python3 - "$file" "$target" <<'PY'
+import subprocess, sys
+path, t = sys.argv[1], int(sys.argv[2], 16)
+out = subprocess.check_output(["readelf", "-sW", "--dyn-syms", path], text=True)
+syms = []
+for line in out.splitlines():
+ p = line.split()
+ if len(p) >= 8 and p[3] == "FUNC":
+ try:
+ syms.append((int(p[1], 16), int(p[2]), p[7]))
+ except ValueError:
+ pass
+syms.sort()
+prev = None
+for a, s, n in syms:
+ if a <= t:
+ prev = (a, s, n)
+ else:
+ break
+if prev:
+ print("nearest exported: %s at 0x%x size 0x%x (+0x%x)" %
+ (prev[2], prev[0], prev[1], t - prev[0]))
+else:
+ print("no exported symbol before 0x%x" % t)
+PY
+ ;;
+*)
+ file="$1"; vaddr="$2"
+ before="${3:-0x40}"; after="${4:-0x40}"
+ start=$(printf '0x%x' $(( vaddr - before )) 2>/dev/null || echo "$vaddr")
+ end=$(printf '0x%x' $(( vaddr + after )) 2>/dev/null || echo "$vaddr")
+ # allow hex arithmetic with shell
+ start=$(python3 -c "print(hex(int('$vaddr',16)-int('$before',16)))")
+ end=$(python3 -c "print(hex(int('$vaddr',16)+int('$after',16)))")
+ objdump -d -Mintel --start-address="$start" --stop-address="$end" "$file"
+ ;;
+esac