]> git.pld-linux.org Git - packages/gdb.git/blame - 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
CommitLineData
4b0e5c1b
AM
1From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2From: Fedora GDB patches <invalid@email.com>
3Date: Fri, 27 Oct 2017 21:07:50 +0200
4Subject: gdb-6.6-buildid-locate-solib-missing-ids.patch
5
6FileName: 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
140f8057
JR
13gdb returns an incorrect back trace when applying a debuginfo
14https://bugzilla.redhat.com/show_bug.cgi?id=1339862
4b0e5c1b
AM
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
140f8057 24
4b0e5c1b
AM
25diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
26index 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,
a7de96f0
PS
30 }
31
32 {
324d13e1
JR
33- struct bfd_build_id *build_id;
34+ struct bfd_build_id *build_id = NULL;
a7de96f0 35
324d13e1
JR
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';
a7de96f0 38 /* May get overwritten below. */
324d13e1 39 strcpy (newobj->so_name, newobj->so_original_name);
a7de96f0 40
324d13e1 41- build_id = build_id_addr_get (newobj->lm_info->l_ld);
a7de96f0
PS
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)
4b0e5c1b 55+ build_id = build_id_addr_get (li->l_ld);
a7de96f0
PS
56 if (build_id != NULL)
57 {
58 char *name, *build_id_filename;
4b0e5c1b 59@@ -1409,23 +1422,7 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
a7de96f0
PS
60 xfree (name);
61 }
62 else
63- {
324d13e1 64- debug_print_missing (newobj->so_name, build_id_filename);
a7de96f0
PS
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)
324d13e1 78- newobj->so_name[0] = 0;
a7de96f0 79- }
324d13e1 80+ debug_print_missing (newobj->so_name, build_id_filename);
a7de96f0
PS
81
82 xfree (build_id_filename);
83 xfree (build_id);
4b0e5c1b
AM
84diff --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
85new file mode 100644
86index 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+}
111diff --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
112new file mode 100644
113index 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+}
142diff --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
143new file mode 100644
144index 0000000000..0c46489f31
145--- /dev/null
146+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
140f8057
JR
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"
4b0e5c1b
AM
253--
2542.14.3
255
This page took 0.164753 seconds and 4 git commands to generate.