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