Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions scripts/04-deploy-and-prep-gdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# 1. Best-effort kill of any local gdb holding the debug-endpoint TCP
# port (KGDB serial bridge and QEMU gdbstub each serve one client).
# 2. Upload module/<name>.ko, verify size matches.
# 3. Insmod in the background; poll /sys/module/<name>/sections/ for the
# runtime load addresses and emit an `add-symbol-file ...` line.
# 3. Insmod; poll /sys/module/<name>/sections/ for runtime addresses,
# stage a section-relocated copy of the .ko, and add-symbol-file it.
# 4. Emit .gdb/<target>-<method>.gdb (+ -attached variant) and the
# current-* symlinks the IDE launch configs point at.
#
Expand Down Expand Up @@ -171,12 +171,23 @@ load_and_discover_symbols() {
local text_addr
text_addr="$(awk '$1 == ".text" { print $2 }' "$tmp")"
if [[ -n "$text_addr" ]]; then
local cmd="add-symbol-file $artifact $text_addr"
# Pre-relocate the .ko: write each section's runtime
# address into its sh_addr so BFD bakes correct addresses into DWARF.
local relocated="$gdb_dir/$target-$debug_method-$module_name-relocated.ko"
local objcopy_args=()
local existing
existing="$(objdump -h "$artifact" | awk '$1 ~ /^[0-9]+$/ {print $2}')"
while read -r sec addr; do
[[ "$sec" != ".text" && -n "$addr" ]] && cmd+=" -s $sec $addr"
[[ -z "$addr" || -z "$sec" ]] && continue
grep -qxF "$sec" <<< "$existing" || continue
objcopy_args+=("--change-section-address" "$sec=$addr")
done < "$tmp"
rm -f "$relocated"
objcopy --no-change-warnings "${objcopy_args[@]}" \
"$artifact" "$relocated" \
|| die "objcopy failed to produce $relocated"
{
echo "$cmd"
printf 'add-symbol-file %s %s\n' "$relocated" "$text_addr"
printf 'echo loaded %s module symbols for %s\\n\n' "$module_name" "$target"
} > "$symbols_file"
rm -f "$tmp"
Expand Down
Loading