1 |
GDB loads debug files based on the file name given in the .gnu_debuglink |
2 |
section, prepended with /usr/lib/debug/${dirname}, where dirname is the |
3 |
absolute path to the parent directory of the binary being executed. |
4 |
|
5 |
For each unique inode as input, we need a link to the debug file with |
6 |
the GNU debuglink as its basename. A link to the debug file should exist |
7 |
for each directory in which the input inode exists. |
8 |
|
9 |
The debug link names should be based on the .gnu_debuglink value instead |
10 |
of the name of the file we are processing as input. |
11 |
|
12 |
The .gnu_debuglink value is based on the name of the first link |
13 |
processed for each inode. We save this value as a symlink, and then read |
14 |
it back as we process subsequent links. |
15 |
|
16 |
For example, given the following input: |
17 |
|
18 |
INODE PATH |
19 |
1 /usr/bin/git |
20 |
1 /usr/libexec/git-core/git-add |
21 |
2 /usr/bin/git-shell |
22 |
2 /usr/libexec/git-core/git-shell |
23 |
|
24 |
We generate the following inodes for the debug files: |
25 |
|
26 |
INODE DEBUGLINK |
27 |
3 git.debug |
28 |
4 git-shell.debug |
29 |
|
30 |
We should generate the following links: |
31 |
|
32 |
INODE PATH |
33 |
3 /usr/lib/debug/usr/bin/git.debug |
34 |
3 /usr/lib/debug/usr/libexec/git-core/git.debug |
35 |
4 /usr/bin/debug/usr/bin/git-shell.debug |
36 |
4 /usr/bin/debug/usr/libexec/git-core/git-shell.debug |
37 |
|
38 |
The previous code would have generated this broken output: |
39 |
|
40 |
INODE PATH |
41 |
3 /usr/lib/debug/usr/bin/git.debug |
42 |
3 /usr/lib/debug/usr/libexec/git-core/git-add.debug (*) |
43 |
4 /usr/bin/debug/usr/bin/git-shell.debug |
44 |
4 /usr/bin/debug/usr/libexec/git-core/git-shell.debug |
45 |
|
46 |
(*) This link has the wrong name. |
47 |
|
48 |
Bug: https://bugs.gentoo.org/820107 |
49 |
Signed-off-by: Mike Gilbert <floppym@g.o> |
50 |
--- |
51 |
bin/estrip | 31 ++++++++++++++++++++++--------- |
52 |
1 file changed, 22 insertions(+), 9 deletions(-) |
53 |
|
54 |
diff --git a/bin/estrip b/bin/estrip |
55 |
index abe523fff..8134020fd 100755 |
56 |
--- a/bin/estrip |
57 |
+++ b/bin/estrip |
58 |
@@ -201,17 +201,29 @@ save_elf_debug() { |
59 |
local x=$1 |
60 |
local inode_debug=$2 |
61 |
local splitdebug=$3 |
62 |
- local d_noslash=${D%/} |
63 |
- local y=${ED%/}/usr/lib/debug/${x:${#d_noslash}}.debug |
64 |
+ |
65 |
+ local x_basename=${x##*/} |
66 |
+ local x_dirname=${x%/*} |
67 |
+ local y_dirname=${ED%/}/usr/lib/debug/${x_dirname#${D%/}/} |
68 |
+ local y_basename y |
69 |
|
70 |
# dont save debug info twice |
71 |
[[ ${x} == *".debug" ]] && return 0 |
72 |
|
73 |
- mkdir -p "${y%/*}" |
74 |
+ mkdir -p "${y_dirname}" || die |
75 |
+ |
76 |
+ if [[ -L ${inode_debug} ]] ; then |
77 |
+ y_basename=$(readlink "${inode_debug}") || die |
78 |
+ y_basename=${y_basename##*/} |
79 |
+ y=${y_dirname}/${y_basename} |
80 |
|
81 |
- if [ -f "${inode_debug}" ] ; then |
82 |
- ln "${inode_debug}" "${y}" || die "ln failed unexpectedly" |
83 |
+ if [[ ! -e ${y} ]]; then |
84 |
+ ln -L "${inode_debug}" "${y}" || die |
85 |
+ fi |
86 |
else |
87 |
+ y_basename=${x_basename}.debug |
88 |
+ y=${y_dirname}/${y_basename} |
89 |
+ |
90 |
if [[ -n ${splitdebug} ]] ; then |
91 |
mv "${splitdebug}" "${y}" |
92 |
else |
93 |
@@ -222,11 +234,12 @@ save_elf_debug() { |
94 |
fi |
95 |
# Only do the following if the debug file was |
96 |
# successfully created (see bug #446774). |
97 |
- if [ $? -eq 0 ] ; then |
98 |
+ if [[ $? -eq 0 ]] ; then |
99 |
local args="a-x,o-w" |
100 |
[[ -g ${x} || -u ${x} ]] && args+=",go-r" |
101 |
chmod ${args} "${y}" |
102 |
- ln "${y}" "${inode_debug}" || die "ln failed unexpectedly" |
103 |
+ # symlink so we can read the name back. |
104 |
+ ln -s "${y}" "${inode_debug}" || die |
105 |
fi |
106 |
fi |
107 |
|
108 |
@@ -239,8 +252,8 @@ save_elf_debug() { |
109 |
local buildid_dir="${ED%/}/usr/lib/debug/.build-id/${buildid:0:2}" |
110 |
local buildid_file="${buildid_dir}/${buildid:2}" |
111 |
mkdir -p "${buildid_dir}" |
112 |
- [ -L "${buildid_file}".debug ] || ln -s "../../${x:$((${#d_noslash} + 1))}.debug" "${buildid_file}.debug" |
113 |
- [ -L "${buildid_file}" ] || ln -s "/${x:$((${#d_noslash} + 1))}" "${buildid_file}" |
114 |
+ [[ -L "${buildid_file}".debug ]] || ln -s "../../${x#${D%/}/}.debug" "${buildid_file}.debug" |
115 |
+ [[ -L "${buildid_file}" ]] || ln -s "../../../../../${x#${D%/}/}" "${buildid_file}" |
116 |
fi |
117 |
} |
118 |
|
119 |
-- |
120 |
2.33.1 |