2 https://bugzilla.redhat.com/show_bug.cgi?id=623749
4 https://bugzilla.redhat.com/show_bug.cgi?id=636937
6 http://sourceware.org/ml/gdb-patches/2010-09/msg00395.html
7 Subject: Re: [patch] Fix gcore writer for -Wl,-z,relro (PR corefiles/11804)
10 2010-09-22 Jan Kratochvil <jan.kratochvil@redhat.com>
12 Fix gcore writer for -Wl,-z,relro.
13 * gdb.base/gcore-relro.exp: New file.
14 * gdb.base/gcore-relro-main.c: New file.
15 * gdb.base/gcore-relro-lib.c: New file.
17 --- ./gdb/gcore.c 2010-09-23 20:14:56.000000000 +0200
18 +++ ./gdb/gcore.c 2010-09-23 20:37:56.000000000 +0200
19 @@ -401,6 +401,7 @@ gcore_create_callback (CORE_ADDR vaddr,
21 if (write == 0 && !solib_keep_data_in_core (vaddr, size))
23 +#if 0 /* https://bugzilla.redhat.com/show_bug.cgi?id=636937 */
24 /* See if this region of memory lies inside a known file on disk.
25 If so, we can avoid copying its contents by clearing SEC_LOAD. */
26 struct objfile *objfile;
27 @@ -433,6 +434,7 @@ gcore_create_callback (CORE_ADDR vaddr,
32 flags |= SEC_READONLY;
36 +++ b/gdb/testsuite/gdb.base/gcore-relro-lib.c
38 +/* Copyright 2010 Free Software Foundation, Inc.
40 + This file is part of GDB.
42 + This program is free software; you can redistribute it and/or modify
43 + it under the terms of the GNU General Public License as published by
44 + the Free Software Foundation; either version 3 of the License, or
45 + (at your option) any later version.
47 + This program is distributed in the hope that it will be useful,
48 + but WITHOUT ANY WARRANTY; without even the implied warranty of
49 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 + GNU General Public License for more details.
52 + You should have received a copy of the GNU General Public License
53 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
60 +++ b/gdb/testsuite/gdb.base/gcore-relro-main.c
62 +/* Copyright 2010 Free Software Foundation, Inc.
64 + This file is part of GDB.
66 + This program is free software; you can redistribute it and/or modify
67 + it under the terms of the GNU General Public License as published by
68 + the Free Software Foundation; either version 3 of the License, or
69 + (at your option) any later version.
71 + This program is distributed in the hope that it will be useful,
72 + but WITHOUT ANY WARRANTY; without even the implied warranty of
73 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74 + GNU General Public License for more details.
76 + You should have received a copy of the GNU General Public License
77 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
79 +extern void lib (void);
88 +++ b/gdb/testsuite/gdb.base/gcore-relro.exp
90 +# Copyright 2010 Free Software Foundation, Inc.
92 +# This program is free software; you can redistribute it and/or modify
93 +# it under the terms of the GNU General Public License as published by
94 +# the Free Software Foundation; either version 3 of the License, or
95 +# (at your option) any later version.
97 +# This program is distributed in the hope that it will be useful,
98 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
99 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100 +# GNU General Public License for more details.
102 +# You should have received a copy of the GNU General Public License
103 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
105 +if {[skip_shlib_tests]} {
109 +set testfile "gcore-relro"
110 +set srcmainfile ${testfile}-main.c
111 +set srclibfile ${testfile}-lib.c
112 +set libfile ${objdir}/${subdir}/${testfile}-lib.so
113 +set objfile ${objdir}/${subdir}/${testfile}-main.o
114 +set executable ${testfile}-main
115 +set binfile ${objdir}/${subdir}/${executable}
116 +set gcorefile ${objdir}/${subdir}/${executable}.gcore
118 +if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} {debug}] != ""
119 + || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
120 + untested ${testfile}.exp
123 +set opts [list debug shlib=${libfile} additional_flags=-Wl,-z,relro]
124 +if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
125 + unsupported "-Wl,-z,relro compilation failed"
129 +clean_restart $executable
130 +gdb_load_shlibs $libfile
132 +# Does this gdb support gcore?
133 +set test "help gcore"
134 +gdb_test_multiple $test $test {
135 + -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
136 + # gcore command not supported -- nothing to test here.
137 + unsupported "gdb does not support gcore on this target"
140 + -re "Save a core file .*\r\n$gdb_prompt $" {
145 +if { ![runto lib] } then {
149 +set escapedfilename [string_to_regexp ${gcorefile}]
151 +set test "save a corefile"
152 +gdb_test_multiple "gcore ${gcorefile}" $test {
153 + -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
156 + -re "Can't create a corefile\r\n$gdb_prompt $" {
162 +# Now restart gdb and load the corefile.
164 +clean_restart $executable
165 +gdb_load_shlibs $libfile
167 +gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
169 +gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"