]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.6-buildid-locate-solib-missing-ids.patch
- x32 patch no longer needed
[packages/gdb.git] / gdb-6.6-buildid-locate-solib-missing-ids.patch
1 From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2 From: Fedora GDB patches <invalid@email.com>
3 Date: Fri, 27 Oct 2017 21:07:50 +0200
4 Subject: gdb-6.6-buildid-locate-solib-missing-ids.patch
5
6 FileName: gdb-6.6-buildid-locate-solib-missing-ids.patch
7
8 ;; Fix loading of core files without build-ids but with build-ids in executables.
9 ;; Load strictly build-id-checked core files only if no executable is specified
10 ;; (Jan Kratochvil, RH BZ 1339862).
11 ;;=push+jan
12
13 gdb returns an incorrect back trace when applying a debuginfo
14 https://bugzilla.redhat.com/show_bug.cgi?id=1339862
15 ---
16  gdb/solib-svr4.c                                   |  35 ++++---
17  .../gcore-buildid-exec-but-not-solib-lib.c         |  21 +++++
18  .../gcore-buildid-exec-but-not-solib-main.c        |  25 +++++
19  .../gdb.base/gcore-buildid-exec-but-not-solib.exp  | 105 +++++++++++++++++++++
20  4 files changed, 167 insertions(+), 19 deletions(-)
21  create mode 100644 gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
22  create mode 100644 gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
23  create mode 100644 gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
24
25 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
26 index a3399ad8f7..d7eeb6350d 100644
27 --- a/gdb/solib-svr4.c
28 +++ b/gdb/solib-svr4.c
29 @@ -1387,14 +1387,27 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
30         }
31  
32        {
33 -       struct bfd_build_id *build_id;
34 +       struct bfd_build_id *build_id = NULL;
35  
36         strncpy (newobj->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
37         newobj->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
38         /* May get overwritten below.  */
39         strcpy (newobj->so_name, newobj->so_original_name);
40  
41 -       build_id = build_id_addr_get (newobj->lm_info->l_ld);
42 +       /* In the case the main executable was found according to its build-id
43 +          (from a core file) prevent loading a different build of a library
44 +          with accidentally the same SO_NAME.
45 +
46 +          It suppresses bogus backtraces (and prints "??" there instead) if
47 +          the on-disk files no longer match the running program version.
48 +
49 +          If the main executable was not loaded according to its build-id do
50 +          not do any build-id checking of the libraries.  There may be missing
51 +          build-ids dumped in the core file and we would map all the libraries
52 +          to the only existing file loaded that time - the executable.  */
53 +       if (symfile_objfile != NULL
54 +           && (symfile_objfile->flags & OBJF_BUILD_ID_CORE_LOADED) != 0)
55 +         build_id = build_id_addr_get (li->l_ld);
56         if (build_id != NULL)
57           {
58             char *name, *build_id_filename;
59 @@ -1409,23 +1422,7 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
60                 xfree (name);
61               }
62             else
63 -             {
64 -               debug_print_missing (newobj->so_name, build_id_filename);
65 -
66 -               /* In the case the main executable was found according to
67 -                  its build-id (from a core file) prevent loading
68 -                  a different build of a library with accidentally the
69 -                  same SO_NAME.
70 -
71 -                  It suppresses bogus backtraces (and prints "??" there
72 -                  instead) if the on-disk files no longer match the
73 -                  running program version.  */
74 -
75 -               if (symfile_objfile != NULL
76 -                   && (symfile_objfile->flags
77 -                       & OBJF_BUILD_ID_CORE_LOADED) != 0)
78 -                 newobj->so_name[0] = 0;
79 -             }
80 +             debug_print_missing (newobj->so_name, build_id_filename);
81  
82             xfree (build_id_filename);
83             xfree (build_id);
84 diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
85 new file mode 100644
86 index 0000000000..d74b690c73
87 --- /dev/null
88 +++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
89 @@ -0,0 +1,21 @@
90 +/* Copyright 2010 Free Software Foundation, Inc.
91 +
92 +   This file is part of GDB.
93 +
94 +   This program is free software; you can redistribute it and/or modify
95 +   it under the terms of the GNU General Public License as published by
96 +   the Free Software Foundation; either version 3 of the License, or
97 +   (at your option) any later version.
98 +
99 +   This program is distributed in the hope that it will be useful,
100 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
101 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
102 +   GNU General Public License for more details.
103 +
104 +   You should have received a copy of the GNU General Public License
105 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
106 +
107 +void
108 +lib (void)
109 +{
110 +}
111 diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
112 new file mode 100644
113 index 0000000000..46b9dfe161
114 --- /dev/null
115 +++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
116 @@ -0,0 +1,25 @@
117 +/* Copyright 2010 Free Software Foundation, Inc.
118 +
119 +   This file is part of GDB.
120 +
121 +   This program is free software; you can redistribute it and/or modify
122 +   it under the terms of the GNU General Public License as published by
123 +   the Free Software Foundation; either version 3 of the License, or
124 +   (at your option) any later version.
125 +
126 +   This program is distributed in the hope that it will be useful,
127 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
128 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
129 +   GNU General Public License for more details.
130 +
131 +   You should have received a copy of the GNU General Public License
132 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
133 +
134 +extern void lib (void);
135 +
136 +int
137 +main (void)
138 +{
139 +  lib ();
140 +  return 0;
141 +}
142 diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
143 new file mode 100644
144 index 0000000000..0c46489f31
145 --- /dev/null
146 +++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
147 @@ -0,0 +1,105 @@
148 +# Copyright 2016 Free Software Foundation, Inc.
149 +
150 +# This program is free software; you can redistribute it and/or modify
151 +# it under the terms of the GNU General Public License as published by
152 +# the Free Software Foundation; either version 3 of the License, or
153 +# (at your option) any later version.
154 +#
155 +# This program is distributed in the hope that it will be useful,
156 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
157 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
158 +# GNU General Public License for more details.
159 +#
160 +# You should have received a copy of the GNU General Public License
161 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
162 +
163 +if {[skip_shlib_tests]} {
164 +    return 0
165 +}
166 +
167 +set testfile "gcore-buildid-exec-but-not-solib"
168 +set srcmainfile ${testfile}-main.c
169 +set srclibfile ${testfile}-lib.c
170 +set libfile [standard_output_file ${testfile}-lib.so]
171 +set objfile [standard_output_file ${testfile}-main.o]
172 +set executable ${testfile}-main
173 +set binfile [standard_output_file ${executable}]
174 +set gcorefile [standard_output_file ${executable}.gcore]
175 +set outdir [file dirname $binfile]
176 +
177 +if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} "debug additional_flags=-Wl,--build-id"] != ""
178 +     || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
179 +     unsupported "-Wl,--build-id compilation failed"
180 +     return -1
181 +}
182 +set opts [list debug shlib=${libfile} "additional_flags=-Wl,--build-id"]
183 +if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
184 +     unsupported "-Wl,--build-id compilation failed"
185 +     return -1
186 +}
187 +
188 +clean_restart $executable
189 +gdb_load_shlib $libfile
190 +
191 +# Does this gdb support gcore?
192 +set test "help gcore"
193 +gdb_test_multiple $test $test {
194 +    -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
195 +       # gcore command not supported -- nothing to test here.
196 +       unsupported "gdb does not support gcore on this target"
197 +       return -1;
198 +    }
199 +    -re "Save a core file .*\r\n$gdb_prompt $" {
200 +       pass $test
201 +    }
202 +}
203 +
204 +if { ![runto lib] } then {
205 +    return -1
206 +}
207 +
208 +set escapedfilename [string_to_regexp ${gcorefile}]
209 +
210 +set test "save a corefile"
211 +gdb_test_multiple "gcore ${gcorefile}" $test {
212 +    -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
213 +       pass $test
214 +    }
215 +    -re "Can't create a corefile\r\n$gdb_prompt $" {
216 +       unsupported $test
217 +       return -1
218 +    }
219 +}
220 +
221 +# Now restart gdb and load the corefile.
222 +
223 +clean_restart $executable
224 +gdb_load_shlib $libfile
225 +
226 +set buildid [build_id_debug_filename_get $libfile]
227 +
228 +regsub {\.debug$} $buildid {} buildid
229 +
230 +set debugdir [standard_output_file ${testfile}-debugdir]
231 +file delete -force -- $debugdir
232 +
233 +file mkdir $debugdir/[file dirname $libfile]
234 +file copy $libfile $debugdir/${libfile}
235 +
236 +file mkdir $debugdir/[file dirname $buildid]
237 +file copy $libfile $debugdir/${buildid}
238 +
239 +remote_exec build "ln -s /lib       ${debugdir}/"
240 +remote_exec build "ln -s /lib64     ${debugdir}/"
241 +# /usr is not needed, all the libs are in /lib64: libm.so.6 libc.so.6 ld-linux-x86-64.so.2
242 +
243 +gdb_test "set solib-absolute-prefix $debugdir"
244 +
245 +gdb_test_no_output "set debug-file-directory $debugdir" "set debug-file-directory"
246 +
247 +gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
248 +
249 +gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
250 +
251 +gdb_test "bt"
252 +gdb_test "info shared"
253 -- 
254 2.14.3
255
This page took 0.045942 seconds and 3 git commands to generate.