diff options
| author | Arthur Hanson Rasmusson <arthur@vgpu.io> | 2026-09-23 07:05:45 -0400 |
|---|---|---|
| committer | Arthur Hanson Rasmusson <arthur@vgpu.io> | 2026-09-23 07:05:45 -0400 |
| commit | 2aafde5cc3679020d8b31277c03d70fd6908384c (patch) | |
| tree | a3d89236459b5586e5a4d0c3b2b1b574fbfb274b /userspace/cuda/570.144/scripts/disasm.sh | |
| parent | 7fdbe8713c8cf746cd1a15e93e0de39d333905c7 (diff) | |
| download | open-iov-2aafde5cc3679020d8b31277c03d70fd6908384c.tar.gz open-iov-2aafde5cc3679020d8b31277c03d70fd6908384c.zip | |
userspace/cuda: libcuda analysis tree (debug-focused), guest ioctl tracer
Analysis tooling for debugging CUDA execution in Open-IOV guests:
- userspace/cuda/570.144/: fetch a library from a running guest (nc),
objdump helpers, crash ip -> file vaddr + symbol mapping, and Ghidra
headless import/analysis/decompile scripts (project kept so single
functions decompile in seconds). The purpose is debugging correctness
and performance of CUDA in Open-IOV VMs (not a reimplementation);
extracted binaries and decompiled output are gitignored.
- tools/guest-diag/ioctl_trace.c: ptrace tracker for the NVIDIA driver
ioctls of a child (libcuda issues raw syscalls, so LD_PRELOAD sees
nothing). Decodes RM_ALLOC (class) and RM_CONTROL (cmd) arguments;
this is how the cuCtxCreate crash sequence was captured.
- tools/test/cuda_drv_test.c: unbuffered + per-call markers so a crash
identifies the CUDA call it happened in.
Diffstat (limited to 'userspace/cuda/570.144/scripts/disasm.sh')
| -rwxr-xr-x | userspace/cuda/570.144/scripts/disasm.sh | 65 |
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 |
