ronnie
2022-10-23 4bf14332546635f50a1bf7f3df4c0a8e29643280
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
#
# Script to make an offline archive for debugging with libdwfl-based tools.
#
#    make-debug-archive ARCHIVE {options}
#    make-debug-archive --kernel [--force] [RELEASE]
#
# Valid options are those listed under 'Input selection options'
# by running @UNSTRIP@ --help.
#
# The archive installed by --kernel be used automatically by -K.
# An offline archive can be used via -e in any tool that accepts those options.
#
 
UNSTRIP=${UNSTRIP:-@UNSTRIP@}
AR=${AR:-@AR@}
SUDO=${SUDO:-/usr/bin/sudo}
 
LS=/bin/ls
RM=/bin/rm
MV=/bin/mv
MKDIR=/bin/mkdir
XARGS=/usr/bin/xargs
 
outdir=${TMPDIR:-/tmp}/debugar$$
 
usage()
{
  echo "Usage: $0 ARCHIVE {options}"
  echo "   or: $0 --kernel [--sudo] [--force] [RELEASE]"
  echo
  echo "Valid options are listed under 'Input selection options'"
  echo "when running: $UNSTRIP --help"
  echo
  echo "The --kernel form updates the file used by -K if the"
  echo "kernel installation has changed, or always with --force."
  echo "With --sudo, touches the installed file via $SUDO."
}
 
fatal_usage()
{
  usage >&2
  exit 2
}
 
script_version()
{
  echo "`basename $0` (@PACKAGE_NAME@) @PACKAGE_VERSION@"
  echo "Copyright (C) 2007 Red Hat, Inc."
  echo "This is free software; see the source for copying conditions."
  echo "There is NO warranty; not even for MERCHANTABILITY or"
  echo "FITNESS FOR A PARTICULAR PURPOSE."
  echo "Written by Roland McGrath."
}
 
sudo=
kernel=no
force_kernel=no
while [ $# -gt 0 ]; do
  case "x$1" in
  x--help) usage; exit 0 ;;
  x--version) script_version; exit 0 ;;
  x--kernel) kernel=yes ;;
  x--force) force_kernel=yes ;;
  x--sudo) sudo=$SUDO ;;
  *) break ;;
  esac
  shift
done
 
if [ $kernel = no ] && [ $force_kernel = yes -o -n "$sudo" ]; then
  usage
fi
 
if [ $kernel = yes ]; then
  if [ $# -eq 0 ]; then
    release=`uname -r`
  elif [ $# -eq 1 ]; then
    release=$1
  else
    fatal_usage
  fi
 
  dir=/usr/lib/debug/lib/modules/$release
  archive=$dir/debug.a
  dep=/lib/modules/$release/modules.dep
 
  if [ ! -d $dir ]; then
    echo >&2 "$0: $dir not installed"
    exit 1
  fi
 
  # Without --force, bail if the kernel installation is not newer.
  # This file is normally touched by installing new kernels or modules.
  if [ $force_kernel = no -a "$archive" -nt "$dep" ]; then
    exit 0
  fi
 
  # We have to kill the old one first, because our own -K would use it.
  [ ! -e "$archive" ] || $sudo $RM -f "$archive" || exit
 
  set "$archive" "-K$release"
fi
 
if [ $# -lt 2 ]; then
  fatal_usage
fi
 
archive="$1"
shift
 
case "$archive" in
/*) ;;
*) archive="`/bin/pwd`/$archive" ;;
esac
 
if [ -z "$sudo" ]; then
  new_archive="$archive.new"
else
  new_archive="$outdir.a"
fi
 
$RM -f "$new_archive" || exit
 
trap '$RM -rf "$outdir" "$new_archive"' 0 1 2 15
 
$MKDIR "$outdir" &&
$UNSTRIP -d "$outdir" -m -a -R "$@" &&
(cd "$outdir" && $LS | $XARGS $AR cq "$new_archive") &&
$sudo $MV -f "$new_archive" "$archive"
 
exit