File: strip_debug.sh

package info (click to toggle)
dxvk 2.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,224 kB
  • sloc: cpp: 123,108; ansic: 76,058; sh: 545; python: 174; makefile: 81
file content (80 lines) | stat: -rwxr-xr-x 2,727 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Kindly provided by Alexis Murzeau <amubtdx@gmail.com>
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=975475#22
# Adapted by Marc Dequènes (Duck) <Duck@DuckCorp.org>

set -e -o pipefail


PACKAGE=$1
DH_PKG_DIR=debian/.debhelper/${PACKAGE}/


get_buildid()
{
    local FILE=$1

    llvm-readobj --coff-debug-directory $FILE | awk '/PDBGUID:/ { $1=""; gsub(/[^0-9A-F]+/, ""); print; exit }'
}

strip_and_create_debug()
{
    local BINARY_FILE=$1
    local BUILDID=$2
    local DEBUG_FILE=${DH_PKG_DIR}/dbgsym-root/usr/lib/debug/.build-id/${BUILDID:0:2}/${BUILDID:2}.debug
    local DEBUG_FILE_DIR=$(dirname $DEBUG_FILE)
    local DEBUG_FILE_NAME=$(basename $DEBUG_FILE)
    local BINARY_FILE_DIR=$(dirname $BINARY_FILE)
    local BINARY_FILE_NAME=$(basename $BINARY_FILE)

    mkdir -p $DEBUG_FILE_DIR

    # Sequence made according to dh_strip but using binutils-mingw-w64-x86-64 tools
    # https://salsa.debian.org/debian/debhelper/-/blob/main/dh_strip

    if [ "${DEB_HOST_ARCH_BITS}" = "64" ]; then
        gnu_cpu=x86_64
    else
        gnu_cpu=i686
    fi

    # Note: --compress-debug-sections is not supported by winedbg and will cause a crash
    ${gnu_cpu}-w64-mingw32-objcopy --only-keep-debug "$BINARY_FILE" "$DEBUG_FILE"
    chmod 0644 "$DEBUG_FILE"
    ${gnu_cpu}-w64-mingw32-strip --remove-section=.comment --remove-section=.note --strip-unneeded "$BINARY_FILE"
    # It is not possible to specify a path that does not exist to set the debug link with objcopy.
    # Instead, using a filename without component directory will trigger a lookup in various locations
    # including /usr/lib/debug/
    cp "$DEBUG_FILE" "${BINARY_FILE_DIR}/${DEBUG_FILE_NAME}"
    pushd "${BINARY_FILE_DIR}"
    ${gnu_cpu}-w64-mingw32-objcopy --add-gnu-debuglink "$(basename $DEBUG_FILE_NAME)" "$BINARY_FILE_NAME"
    popd
    rm "${BINARY_FILE_DIR}/${DEBUG_FILE_NAME}"
}


mkdir -p ${DH_PKG_DIR}

for FILE in $(find debian/${PACKAGE}/usr/lib -name "*.dll.so"); do
    BUILDID=$(get_buildid $FILE)
    echo "Striping '${FILE}' with build-id '${BUILDID}'"
    strip_and_create_debug $FILE $BUILDID
    # list of build-ids, later used by dh_gencontrol to create the Build-Ids package header
    echo $BUILDID >>${DH_PKG_DIR}/dbgsym-build-ids.tmp
done

cat ${DH_PKG_DIR}/dbgsym-build-ids.tmp | sort | paste -sd ' ' > ${DH_PKG_DIR}/dbgsym-build-ids
rm ${DH_PKG_DIR}/dbgsym-build-ids.tmp


# To debug a program, you can do:
# $ winedbg --gdb --no-start --port 2345 program.exe
# [...]
#
# $ gdb program.exe
# [...]
# (gdb) target remote localhost:2345

# gdb must be used instead of ${gnu_cpu}-w64-mingw32-gdb (else winedbg will have this error:
# 0108:err:winedbg:packet_query Unhandled query "GetTIBAddr:110"