]>
Commit | Line | Data |
---|---|---|
ab050a48 BZ |
1 | http://sourceware.org/gdb/wiki/ProjectArcher |
2 | http://sourceware.org/gdb/wiki/ArcherBranchManagement | |
3 | ||
4 | archer-jankratochvil-pie-fedora12 | |
5 | GIT snapshot: | |
6 | commit 2ae60b5156d43aabfe5757940eaf7b4370fb05d2 | |
7 | ||
8 | ||
9 | diff --git a/gdb/auxv.c b/gdb/auxv.c | |
10 | index 7b4ecbe..7df8eb5 100644 | |
11 | --- a/gdb/auxv.c | |
12 | +++ b/gdb/auxv.c | |
13 | @@ -25,6 +25,7 @@ | |
14 | #include "inferior.h" | |
15 | #include "valprint.h" | |
16 | #include "gdb_assert.h" | |
17 | +#include "gdbcore.h" | |
18 | ||
19 | #include "auxv.h" | |
20 | #include "elf/common.h" | |
21 | @@ -33,15 +34,11 @@ | |
22 | #include <fcntl.h> | |
23 | ||
24 | ||
25 | -/* This function is called like a to_xfer_partial hook, but must be | |
26 | - called with TARGET_OBJECT_AUXV. It handles access via | |
27 | - /proc/PID/auxv, which is a common method for native targets. */ | |
28 | +/* This function handles access via /proc/PID/auxv, which is a common method | |
29 | + for native targets. */ | |
30 | ||
31 | -LONGEST | |
32 | -procfs_xfer_auxv (struct target_ops *ops, | |
33 | - enum target_object object, | |
34 | - const char *annex, | |
35 | - gdb_byte *readbuf, | |
36 | +static LONGEST | |
37 | +procfs_xfer_auxv (gdb_byte *readbuf, | |
38 | const gdb_byte *writebuf, | |
39 | ULONGEST offset, | |
40 | LONGEST len) | |
41 | @@ -50,9 +47,6 @@ procfs_xfer_auxv (struct target_ops *ops, | |
42 | int fd; | |
43 | LONGEST n; | |
44 | ||
45 | - gdb_assert (object == TARGET_OBJECT_AUXV); | |
46 | - gdb_assert (readbuf || writebuf); | |
47 | - | |
48 | pathname = xstrprintf ("/proc/%d/auxv", PIDGET (inferior_ptid)); | |
49 | fd = open (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY); | |
50 | xfree (pathname); | |
51 | @@ -72,6 +66,152 @@ procfs_xfer_auxv (struct target_ops *ops, | |
52 | return n; | |
53 | } | |
54 | ||
55 | +/* This function handles access via ld.so's symbol `_dl_auxv'. */ | |
56 | + | |
57 | +static LONGEST | |
58 | +ld_so_xfer_auxv (gdb_byte *readbuf, | |
59 | + const gdb_byte *writebuf, | |
60 | + ULONGEST offset, | |
61 | + LONGEST len) | |
62 | +{ | |
63 | + struct minimal_symbol *msym; | |
64 | + CORE_ADDR data_address, pointer_address; | |
65 | + struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr; | |
66 | + size_t ptr_size = TYPE_LENGTH (ptr_type); | |
67 | + size_t auxv_pair_size = 2 * ptr_size; | |
68 | + gdb_byte *ptr_buf = alloca (ptr_size); | |
69 | + LONGEST retval; | |
70 | + size_t block; | |
71 | + | |
72 | + msym = lookup_minimal_symbol ("_dl_auxv", NULL, NULL); | |
73 | + if (msym == NULL) | |
74 | + return -1; | |
75 | + | |
76 | + if (MSYMBOL_SIZE (msym) != ptr_size) | |
77 | + return -1; | |
78 | + | |
79 | + /* POINTER_ADDRESS is a location where the `_dl_auxv' variable resides. | |
80 | + DATA_ADDRESS is the inferior value present in `_dl_auxv', therefore the | |
81 | + real inferior AUXV address. */ | |
82 | + | |
83 | + pointer_address = SYMBOL_VALUE_ADDRESS (msym); | |
84 | + | |
85 | + data_address = read_memory_typed_address (pointer_address, ptr_type); | |
86 | + | |
87 | + /* Possibly still not initialized such as during an inferior startup. */ | |
88 | + if (data_address == 0) | |
89 | + return -1; | |
90 | + | |
91 | + data_address += offset; | |
92 | + | |
93 | + if (writebuf != NULL) | |
94 | + { | |
95 | + if (target_write_memory (data_address, writebuf, len) == 0) | |
96 | + return len; | |
97 | + else | |
98 | + return -1; | |
99 | + } | |
100 | + | |
101 | + /* Stop if trying to read past the existing AUXV block. The final AT_NULL | |
102 | + was already returned before. */ | |
103 | + | |
104 | + if (offset >= auxv_pair_size) | |
105 | + { | |
106 | + if (target_read_memory (data_address - auxv_pair_size, ptr_buf, | |
107 | + ptr_size) != 0) | |
108 | + return -1; | |
109 | + | |
110 | + if (extract_typed_address (ptr_buf, ptr_type) == AT_NULL) | |
111 | + return 0; | |
112 | + } | |
113 | + | |
114 | + retval = 0; | |
115 | + block = 0x400; | |
116 | + gdb_assert (block % auxv_pair_size == 0); | |
117 | + | |
118 | + while (len > 0) | |
119 | + { | |
120 | + if (block > len) | |
121 | + block = len; | |
122 | + | |
123 | + /* Reading sizes smaller than AUXV_PAIR_SIZE is not supported. Tails | |
124 | + unaligned to AUXV_PAIR_SIZE will not be read during a call (they | |
125 | + should be completed during next read with new/extended buffer). */ | |
126 | + | |
127 | + block &= -auxv_pair_size; | |
128 | + if (block == 0) | |
129 | + return retval; | |
130 | + | |
131 | + if (target_read_memory (data_address, readbuf, block) != 0) | |
132 | + { | |
133 | + if (block <= auxv_pair_size) | |
134 | + return retval; | |
135 | + | |
136 | + block = auxv_pair_size; | |
137 | + continue; | |
138 | + } | |
139 | + | |
140 | + data_address += block; | |
141 | + len -= block; | |
142 | + | |
143 | + /* Check terminal AT_NULL. This function is being called indefinitely | |
144 | + being extended its READBUF until it returns EOF (0). */ | |
145 | + | |
146 | + while (block >= auxv_pair_size) | |
147 | + { | |
148 | + retval += auxv_pair_size; | |
149 | + | |
150 | + if (extract_typed_address (readbuf, ptr_type) == AT_NULL) | |
151 | + return retval; | |
152 | + | |
153 | + readbuf += auxv_pair_size; | |
154 | + block -= auxv_pair_size; | |
155 | + } | |
156 | + } | |
157 | + | |
158 | + return retval; | |
159 | +} | |
160 | + | |
161 | +/* This function is called like a to_xfer_partial hook, but must be | |
162 | + called with TARGET_OBJECT_AUXV. It handles access to AUXV. */ | |
163 | + | |
164 | +LONGEST | |
165 | +memory_xfer_auxv (struct target_ops *ops, | |
166 | + enum target_object object, | |
167 | + const char *annex, | |
168 | + gdb_byte *readbuf, | |
169 | + const gdb_byte *writebuf, | |
170 | + ULONGEST offset, | |
171 | + LONGEST len) | |
172 | +{ | |
173 | + /* Workaround gdb-7.0 bug where linux_nat_xfer_partial() does | |
174 | + inferior_ptid = pid_to_ptid (GET_LWP (inferior_ptid)); | |
175 | + and current_inferior() assertion fails not finding the LWP->PID. | |
176 | + It got fixed post-gdb-7.0 by: | |
177 | + Add base multi-executable/process support to GDB. | |
178 | + 40ff0a289e6165aa930af284df5c52162cb0cd5f | |
179 | + by introducing `current_inferior_'. */ | |
180 | + struct inferior *inf = find_inferior_pid (ptid_get_pid (inferior_ptid)); | |
181 | + | |
182 | + gdb_assert (object == TARGET_OBJECT_AUXV); | |
183 | + gdb_assert (readbuf || writebuf); | |
184 | + | |
185 | + /* ld_so_xfer_auxv is the only function safe for virtual executables being | |
186 | + executed by valgrind's memcheck. As using ld_so_xfer_auxv is problematic | |
187 | + during inferior startup GDB does call it only for attached processes. */ | |
188 | + | |
189 | + if (inf == NULL || inf->attach_flag != 0) | |
190 | + { | |
191 | + LONGEST retval; | |
192 | + | |
193 | + retval = ld_so_xfer_auxv (readbuf, writebuf, offset, len); | |
194 | + if (retval != -1) | |
195 | + return retval; | |
196 | + } | |
197 | + | |
198 | + return procfs_xfer_auxv (readbuf, writebuf, offset, len); | |
199 | +} | |
200 | + | |
201 | /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR. | |
202 | Return 0 if *READPTR is already at the end of the buffer. | |
203 | Return -1 if there is insufficient buffer for a whole entry. | |
204 | diff --git a/gdb/auxv.h b/gdb/auxv.h | |
205 | index 71e6562..87c24ae 100644 | |
206 | --- a/gdb/auxv.h | |
207 | +++ b/gdb/auxv.h | |
208 | @@ -43,11 +43,7 @@ extern int target_auxv_search (struct target_ops *ops, | |
209 | /* Print the contents of the target's AUXV on the specified file. */ | |
210 | extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops); | |
211 | ||
212 | -/* This function is called like a to_xfer_partial hook, but must be | |
213 | - called with TARGET_OBJECT_AUXV. It handles access via | |
214 | - /proc/PID/auxv, which is a common method for native targets. */ | |
215 | - | |
216 | -extern LONGEST procfs_xfer_auxv (struct target_ops *ops, | |
217 | +extern LONGEST memory_xfer_auxv (struct target_ops *ops, | |
218 | enum target_object object, | |
219 | const char *annex, | |
220 | gdb_byte *readbuf, | |
221 | diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c | |
222 | index 0f35101..bffc5a6 100644 | |
223 | --- a/gdb/breakpoint.c | |
224 | +++ b/gdb/breakpoint.c | |
225 | @@ -4805,7 +4805,8 @@ disable_breakpoints_in_shlibs (void) | |
226 | to insert those breakpoints and fail. */ | |
227 | if (((b->type == bp_breakpoint) | |
228 | || (b->type == bp_hardware_breakpoint) | |
229 | - || (b->type == bp_tracepoint)) | |
230 | + || (b->type == bp_tracepoint) | |
231 | + || b->type == bp_shlib_event) | |
232 | && !loc->shlib_disabled | |
233 | #ifdef PC_SOLIB | |
234 | && PC_SOLIB (loc->address) | |
235 | diff --git a/gdb/defs.h b/gdb/defs.h | |
236 | index 94674dc..57aaae2 100644 | |
237 | --- a/gdb/defs.h | |
238 | +++ b/gdb/defs.h | |
239 | @@ -98,7 +98,20 @@ | |
240 | /* A byte from the program being debugged. */ | |
241 | typedef bfd_byte gdb_byte; | |
242 | ||
243 | -/* An address in the program being debugged. Host byte order. */ | |
244 | +/* An address in the program being debugged. Host byte order. | |
245 | + | |
246 | + Its width is the maximum width of all the supported targets. That means | |
247 | + 32-bit target will run on such GDB using 64-bit CORE_ADDR cluttering the | |
248 | + bits 32...63 with random data from internal GDB calculations. GDB currently | |
249 | + in general truncates the address width only when it is being presented/used | |
250 | + externally (such as by the paddress function). | |
251 | + | |
252 | + FIXME: This is still not right as any GDB internal comparisons (such as >=) | |
253 | + of CORE_ADDR do not use the properly truncated width. As converting all the | |
254 | + CORE_ADDR operations to width-aware functions is not feasible the way out | |
255 | + could be a width-aware C++ class CORE_ADDR referencing gdbarch as its | |
256 | + constructor parameter. */ | |
257 | + | |
258 | typedef bfd_vma CORE_ADDR; | |
259 | ||
260 | /* The largest CORE_ADDR value. */ | |
261 | diff --git a/gdb/exec.c b/gdb/exec.c | |
262 | index 455151e..67f40d9 100644 | |
263 | --- a/gdb/exec.c | |
264 | +++ b/gdb/exec.c | |
265 | @@ -656,8 +656,33 @@ print_section_info (struct target_section_table *t, bfd *abfd) | |
266 | wrap_here (" "); | |
267 | printf_filtered (_("file type %s.\n"), bfd_get_target (abfd)); | |
268 | if (abfd == exec_bfd) | |
269 | - printf_filtered (_("\tEntry point: %s\n"), | |
270 | - paddress (gdbarch, bfd_get_start_address (abfd))); | |
271 | + { | |
272 | + bfd_vma displacement = 0; | |
273 | + | |
274 | + for (p = t->sections; p < t->sections_end; p++) | |
275 | + { | |
276 | + asection *asect = p->the_bfd_section; | |
277 | + | |
278 | + if ((bfd_get_section_flags (abfd, asect) & (SEC_ALLOC | SEC_LOAD)) | |
279 | + != (SEC_ALLOC | SEC_LOAD)) | |
280 | + continue; | |
281 | + | |
282 | + if (bfd_get_section_vma (abfd, asect) <= abfd->start_address | |
283 | + && abfd->start_address < bfd_get_section_vma (abfd, asect) | |
284 | + + bfd_get_section_size (asect)) | |
285 | + { | |
286 | + displacement = p->addr - bfd_get_section_vma (abfd, asect); | |
287 | + break; | |
288 | + } | |
289 | + } | |
290 | + if (p == t->sections_end) | |
291 | + warning (_("Cannot find section for the entry point of %s.\n"), | |
292 | + bfd_get_filename (abfd)); | |
293 | + | |
294 | + printf_filtered (_("\tEntry point: %s\n"), | |
295 | + paddress (gdbarch, bfd_get_start_address (abfd) | |
296 | + + displacement)); | |
297 | + } | |
298 | for (p = t->sections; p < t->sections_end; p++) | |
299 | { | |
300 | printf_filtered ("\t%s", hex_string_custom (p->addr, wid)); | |
301 | diff --git a/gdb/infcmd.c b/gdb/infcmd.c | |
302 | index fab1892..fc0f05d 100644 | |
303 | --- a/gdb/infcmd.c | |
304 | +++ b/gdb/infcmd.c | |
305 | @@ -395,22 +395,6 @@ post_create_inferior (struct target_ops *target, int from_tty) | |
306 | /* Now that we know the register layout, retrieve current PC. */ | |
307 | stop_pc = regcache_read_pc (get_current_regcache ()); | |
308 | ||
309 | - /* If the solist is global across processes, there's no need to | |
310 | - refetch it here. */ | |
311 | - if (exec_bfd && !gdbarch_has_global_solist (target_gdbarch)) | |
312 | - { | |
313 | - /* Sometimes the platform-specific hook loads initial shared | |
314 | - libraries, and sometimes it doesn't. Try to do so first, so | |
315 | - that we can add them with the correct value for FROM_TTY. | |
316 | - If we made all the inferior hook methods consistent, | |
317 | - this call could be removed. */ | |
318 | -#ifdef SOLIB_ADD | |
319 | - SOLIB_ADD (NULL, from_tty, target, auto_solib_add); | |
320 | -#else | |
321 | - solib_add (NULL, from_tty, target, auto_solib_add); | |
322 | -#endif | |
323 | - } | |
324 | - | |
325 | if (exec_bfd) | |
326 | { | |
327 | /* Create the hooks to handle shared library load and unload | |
328 | @@ -418,7 +402,25 @@ post_create_inferior (struct target_ops *target, int from_tty) | |
329 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
330 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); | |
331 | #else | |
332 | - solib_create_inferior_hook (); | |
333 | + solib_create_inferior_hook (from_tty); | |
334 | +#endif | |
335 | + } | |
336 | + | |
337 | + /* If the solist is global across processes, there's no need to | |
338 | + refetch it here. */ | |
339 | + if (exec_bfd && !gdbarch_has_global_solist (target_gdbarch)) | |
340 | + { | |
341 | + /* Sometimes the platform-specific hook loads initial shared | |
342 | + libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be | |
343 | + incorrectly 0 but such solib targets should be fixed anyway. If we | |
344 | + made all the inferior hook methods consistent, this call could be | |
345 | + removed. Call it only after the solib target has been initialized by | |
346 | + solib_create_inferior_hook. */ | |
347 | + | |
348 | +#ifdef SOLIB_ADD | |
349 | + SOLIB_ADD (NULL, 0, target, auto_solib_add); | |
350 | +#else | |
351 | + solib_add (NULL, 0, target, auto_solib_add); | |
352 | #endif | |
353 | } | |
354 | ||
355 | diff --git a/gdb/infrun.c b/gdb/infrun.c | |
356 | index 9d29b15..ed451d5 100644 | |
357 | --- a/gdb/infrun.c | |
358 | +++ b/gdb/infrun.c | |
359 | @@ -544,7 +544,7 @@ follow_exec (ptid_t pid, char *execd_pathname) | |
360 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
361 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); | |
362 | #else | |
363 | - solib_create_inferior_hook (); | |
364 | + solib_create_inferior_hook (0); | |
365 | #endif | |
366 | ||
367 | jit_inferior_created_hook (); | |
368 | diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c | |
369 | index 0907f03..1c18782 100644 | |
370 | --- a/gdb/linux-nat.c | |
371 | +++ b/gdb/linux-nat.c | |
372 | @@ -4674,7 +4674,7 @@ linux_xfer_partial (struct target_ops *ops, enum target_object object, | |
373 | LONGEST xfer; | |
374 | ||
375 | if (object == TARGET_OBJECT_AUXV) | |
376 | - return procfs_xfer_auxv (ops, object, annex, readbuf, writebuf, | |
377 | + return memory_xfer_auxv (ops, object, annex, readbuf, writebuf, | |
378 | offset, len); | |
379 | ||
380 | if (object == TARGET_OBJECT_OSDATA) | |
381 | diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c | |
382 | index 6634703..37770f5 100644 | |
383 | --- a/gdb/linux-tdep.c | |
384 | +++ b/gdb/linux-tdep.c | |
385 | @@ -18,12 +18,8 @@ | |
386 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
387 | ||
388 | #include "defs.h" | |
389 | -#include "gdbcore.h" | |
390 | #include "gdbtypes.h" | |
391 | #include "linux-tdep.h" | |
392 | -#include "observer.h" | |
393 | - | |
394 | -#include "elf-bfd.h" | |
395 | ||
396 | /* This function is suitable for architectures that don't | |
397 | extend/override the standard siginfo structure. */ | |
398 | @@ -138,30 +134,3 @@ linux_get_siginfo_type (struct gdbarch *gdbarch) | |
399 | ||
400 | return siginfo_type; | |
401 | } | |
402 | - | |
403 | -/* Observer for the executable_changed event, to check whether the new | |
404 | - exec binary is a PIE (Position Independent Executable) specimen, which | |
405 | - is currently unsupported. */ | |
406 | - | |
407 | -static void | |
408 | -check_is_pie_binary (void) | |
409 | -{ | |
410 | - Elf_Internal_Ehdr *elf_hdr; | |
411 | - | |
412 | - if (!exec_bfd) | |
413 | - return; | |
414 | - else if (bfd_get_flavour (exec_bfd) != bfd_target_elf_flavour) | |
415 | - return; | |
416 | - | |
417 | - if (elf_tdata (exec_bfd)->elf_header->e_type == ET_DYN) | |
418 | - warning (_("\ | |
419 | -The current binary is a PIE (Position Independent Executable), which\n\ | |
420 | -GDB does NOT currently support. Most debugger features will fail if used\n\ | |
421 | -in this session.\n")); | |
422 | -} | |
423 | - | |
424 | -void | |
425 | -_initialize_linux_tdep (void) | |
426 | -{ | |
427 | - observer_attach_executable_changed (check_is_pie_binary); | |
428 | -} | |
429 | diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c | |
430 | index 0adb045..ea89331 100644 | |
431 | --- a/gdb/nto-procfs.c | |
432 | +++ b/gdb/nto-procfs.c | |
433 | @@ -652,7 +652,7 @@ static void | |
434 | procfs_post_attach (pid_t pid) | |
435 | { | |
436 | if (exec_bfd) | |
437 | - solib_create_inferior_hook (); | |
438 | + solib_create_inferior_hook (0); | |
439 | } | |
440 | ||
441 | static ptid_t | |
442 | @@ -1212,7 +1212,7 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file, | |
443 | ||
444 | if (exec_bfd != NULL | |
445 | || (symfile_objfile != NULL && symfile_objfile->obfd != NULL)) | |
446 | - solib_create_inferior_hook (); | |
447 | + solib_create_inferior_hook (0); | |
448 | } | |
449 | ||
450 | static void | |
451 | diff --git a/gdb/objfiles.c b/gdb/objfiles.c | |
452 | index e5442ca..fb0cea9 100644 | |
453 | --- a/gdb/objfiles.c | |
454 | +++ b/gdb/objfiles.c | |
455 | @@ -544,9 +544,10 @@ free_all_objfiles (void) | |
456 | } | |
457 | \f | |
458 | /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS | |
459 | - entries in new_offsets. */ | |
460 | -void | |
461 | -objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets) | |
462 | + entries in new_offsets. SEPARATE_DEBUG_OBJFILE is not touched here. */ | |
463 | + | |
464 | +static void | |
465 | +objfile_relocate1 (struct objfile *objfile, struct section_offsets *new_offsets) | |
466 | { | |
467 | struct obj_section *s; | |
468 | struct section_offsets *delta = | |
469 | @@ -624,6 +625,10 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets) | |
470 | } | |
471 | } | |
472 | ||
473 | + if (objfile->psymtabs_addrmap) | |
474 | + addrmap_relocate (objfile->psymtabs_addrmap, | |
475 | + ANOFFSET (delta, SECT_OFF_TEXT (objfile))); | |
476 | + | |
477 | { | |
478 | struct partial_symtab *p; | |
479 | ||
480 | @@ -701,6 +706,49 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets) | |
481 | exec_set_section_address (bfd_get_filename (objfile->obfd), idx, | |
482 | obj_section_addr (s)); | |
483 | } | |
484 | +} | |
485 | + | |
486 | +/* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS | |
487 | + entries in new_offsets. Process also OBJFILE's SEPARATE_DEBUG_OBJFILE. | |
488 | + | |
489 | + The number and ordering of sections does differ between the two objfiles. | |
490 | + Only their names match. Also the file offsets will differ (objfile being | |
491 | + possibly prelinked but separate_debug_objfile is probably not prelinked) but | |
492 | + the in-memory absolute address as specified by NEW_OFFSETS must match both | |
493 | + files. */ | |
494 | + | |
495 | +void | |
496 | +objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets) | |
497 | +{ | |
498 | + objfile_relocate1 (objfile, new_offsets); | |
499 | + | |
500 | + if (objfile->separate_debug_objfile != NULL) | |
501 | + { | |
502 | + struct objfile *debug_objfile = objfile->separate_debug_objfile; | |
503 | + struct section_addr_info *objfile_addrs; | |
504 | + struct section_offsets *new_debug_offsets; | |
505 | + int new_debug_num_sections; | |
506 | + struct cleanup *my_cleanups; | |
507 | + | |
508 | + objfile_addrs = build_section_addr_info_from_objfile (objfile); | |
509 | + my_cleanups = make_cleanup (xfree, objfile_addrs); | |
510 | + | |
511 | + /* Here OBJFILE_ADDRS contain the correct absolute addresses, the | |
512 | + relative ones must be already created according to debug_objfile. */ | |
513 | + | |
514 | + addr_info_make_relative (objfile_addrs, debug_objfile->obfd); | |
515 | + | |
516 | + gdb_assert (debug_objfile->num_sections | |
517 | + == bfd_count_sections (debug_objfile->obfd)); | |
518 | + new_debug_offsets = alloca (SIZEOF_N_SECTION_OFFSETS | |
519 | + (debug_objfile->num_sections)); | |
520 | + relative_addr_info_to_section_offsets (new_debug_offsets, | |
521 | + debug_objfile->num_sections, | |
522 | + objfile_addrs); | |
523 | + do_cleanups (my_cleanups); | |
524 | + | |
525 | + objfile_relocate1 (debug_objfile, new_debug_offsets); | |
526 | + } | |
527 | ||
528 | /* Relocate breakpoints as necessary, after things are relocated. */ | |
529 | breakpoint_re_set (); | |
530 | diff --git a/gdb/procfs.c b/gdb/procfs.c | |
531 | index b569bac..15829c2 100644 | |
532 | --- a/gdb/procfs.c | |
533 | +++ b/gdb/procfs.c | |
534 | @@ -4376,7 +4376,7 @@ procfs_xfer_partial (struct target_ops *ops, enum target_object object, | |
535 | ||
536 | #ifdef NEW_PROC_API | |
537 | case TARGET_OBJECT_AUXV: | |
538 | - return procfs_xfer_auxv (ops, object, annex, readbuf, writebuf, | |
539 | + return memory_xfer_auxv (ops, object, annex, readbuf, writebuf, | |
540 | offset, len); | |
541 | #endif | |
542 | ||
543 | diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c | |
544 | index 9428d92..3591168 100644 | |
545 | --- a/gdb/solib-darwin.c | |
546 | +++ b/gdb/solib-darwin.c | |
547 | @@ -277,7 +277,7 @@ darwin_special_symbol_handling (void) | |
548 | ||
549 | /* Shared library startup support. See documentation in solib-svr4.c */ | |
550 | static void | |
551 | -darwin_solib_create_inferior_hook (void) | |
552 | +darwin_solib_create_inferior_hook (int from_tty) | |
553 | { | |
554 | struct minimal_symbol *msymbol; | |
555 | char **bkpt_namep; | |
556 | diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c | |
557 | index b8d5528..002c589 100644 | |
558 | --- a/gdb/solib-frv.c | |
559 | +++ b/gdb/solib-frv.c | |
560 | @@ -971,7 +971,7 @@ frv_relocate_main_executable (void) | |
561 | */ | |
562 | ||
563 | static void | |
564 | -frv_solib_create_inferior_hook (void) | |
565 | +frv_solib_create_inferior_hook (int from_tty) | |
566 | { | |
567 | /* Relocate main executable. */ | |
568 | frv_relocate_main_executable (); | |
569 | diff --git a/gdb/solib-irix.c b/gdb/solib-irix.c | |
570 | index a0c1cd2..f94f7dc 100644 | |
571 | --- a/gdb/solib-irix.c | |
572 | +++ b/gdb/solib-irix.c | |
573 | @@ -386,7 +386,7 @@ enable_break (void) | |
574 | ||
575 | SYNOPSIS | |
576 | ||
577 | - void solib_create_inferior_hook () | |
578 | + void solib_create_inferior_hook (int from_tty) | |
579 | ||
580 | DESCRIPTION | |
581 | ||
582 | @@ -431,7 +431,7 @@ enable_break (void) | |
583 | */ | |
584 | ||
585 | static void | |
586 | -irix_solib_create_inferior_hook (void) | |
587 | +irix_solib_create_inferior_hook (int from_tty) | |
588 | { | |
589 | struct inferior *inf; | |
590 | struct thread_info *tp; | |
591 | diff --git a/gdb/solib-null.c b/gdb/solib-null.c | |
592 | index b39ccdb..87f7848 100644 | |
593 | --- a/gdb/solib-null.c | |
594 | +++ b/gdb/solib-null.c | |
595 | @@ -32,7 +32,7 @@ null_special_symbol_handling (void) | |
596 | } | |
597 | ||
598 | static void | |
599 | -null_solib_create_inferior_hook (void) | |
600 | +null_solib_create_inferior_hook (int from_tty) | |
601 | { | |
602 | } | |
603 | ||
604 | diff --git a/gdb/solib-osf.c b/gdb/solib-osf.c | |
605 | index c295335..0acc7fb 100644 | |
606 | --- a/gdb/solib-osf.c | |
607 | +++ b/gdb/solib-osf.c | |
608 | @@ -306,7 +306,7 @@ osf_clear_solib (void) | |
609 | Also, what if child has exit()ed? Must exit loop somehow. */ | |
610 | ||
611 | static void | |
612 | -osf_solib_create_inferior_hook (void) | |
613 | +osf_solib_create_inferior_hook (int from_tty) | |
614 | { | |
615 | struct inferior *inf; | |
616 | struct thread_info *tp; | |
617 | diff --git a/gdb/solib-pa64.c b/gdb/solib-pa64.c | |
618 | index 637fc1a..16d4010 100644 | |
619 | --- a/gdb/solib-pa64.c | |
620 | +++ b/gdb/solib-pa64.c | |
621 | @@ -329,7 +329,7 @@ bfd_lookup_symbol (bfd *abfd, char *symname) | |
622 | with shared libraries mapped shareable. */ | |
623 | ||
624 | static void | |
625 | -pa64_solib_create_inferior_hook (void) | |
626 | +pa64_solib_create_inferior_hook (int from_tty) | |
627 | { | |
628 | struct minimal_symbol *msymbol; | |
629 | unsigned int dld_flags, status; | |
630 | diff --git a/gdb/solib-som.c b/gdb/solib-som.c | |
631 | index 16f00a3..37ac8cd 100644 | |
632 | --- a/gdb/solib-som.c | |
633 | +++ b/gdb/solib-som.c | |
634 | @@ -182,7 +182,7 @@ struct { | |
635 | means running until the "_start" is called. */ | |
636 | ||
637 | static void | |
638 | -som_solib_create_inferior_hook (void) | |
639 | +som_solib_create_inferior_hook (int from_tty) | |
640 | { | |
641 | enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); | |
642 | struct minimal_symbol *msymbol; | |
643 | diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c | |
644 | index 9f06fa9..45e7e69 100644 | |
645 | --- a/gdb/solib-spu.c | |
646 | +++ b/gdb/solib-spu.c | |
647 | @@ -52,25 +52,19 @@ | |
648 | static void | |
649 | spu_relocate_main_executable (int spufs_fd) | |
650 | { | |
651 | - struct objfile *objfile; | |
652 | - struct cleanup *old_chain; | |
653 | struct section_offsets *new_offsets; | |
654 | int i; | |
655 | ||
656 | - for (objfile = symfile_objfile; | |
657 | - objfile; | |
658 | - objfile = objfile->separate_debug_objfile) | |
659 | - { | |
660 | - new_offsets = xcalloc (objfile->num_sections, | |
661 | - sizeof (struct section_offsets)); | |
662 | - old_chain = make_cleanup (xfree, new_offsets); | |
663 | + if (symfile_objfile == NULL) | |
664 | + return; | |
665 | ||
666 | - for (i = 0; i < objfile->num_sections; i++) | |
667 | - new_offsets->offsets[i] = SPUADDR (spufs_fd, 0); | |
668 | + new_offsets = alloca (symfile_objfile->num_sections | |
669 | + * sizeof (struct section_offsets)); | |
670 | ||
671 | - objfile_relocate (objfile, new_offsets); | |
672 | - do_cleanups (old_chain); | |
673 | - } | |
674 | + for (i = 0; i < symfile_objfile->num_sections; i++) | |
675 | + new_offsets->offsets[i] = SPUADDR (spufs_fd, 0); | |
676 | + | |
677 | + objfile_relocate (symfile_objfile, new_offsets); | |
678 | } | |
679 | ||
680 | /* When running a stand-alone SPE executable, we may need to skip one more | |
681 | @@ -370,7 +364,7 @@ spu_enable_break (struct objfile *objfile) | |
682 | ||
683 | /* Create inferior hook. */ | |
684 | static void | |
685 | -spu_solib_create_inferior_hook (void) | |
686 | +spu_solib_create_inferior_hook (int from_tty) | |
687 | { | |
688 | /* Remove all previously installed solib breakpoints. Both the SVR4 | |
689 | code and us will re-install all required breakpoints. */ | |
690 | @@ -401,7 +395,7 @@ spu_solib_create_inferior_hook (void) | |
691 | } | |
692 | ||
693 | /* Call SVR4 hook -- this will re-insert the SVR4 solib breakpoints. */ | |
694 | - svr4_so_ops.solib_create_inferior_hook (); | |
695 | + svr4_so_ops.solib_create_inferior_hook (from_tty); | |
696 | ||
697 | /* If the inferior is statically linked against libspe, we need to install | |
698 | our own solib breakpoint right now. Otherwise, it will be installed by | |
699 | diff --git a/gdb/solib-sunos.c b/gdb/solib-sunos.c | |
700 | index 9b2a470..b2a147d 100644 | |
701 | --- a/gdb/solib-sunos.c | |
702 | +++ b/gdb/solib-sunos.c | |
703 | @@ -740,7 +740,7 @@ sunos_special_symbol_handling (void) | |
704 | */ | |
705 | ||
706 | static void | |
707 | -sunos_solib_create_inferior_hook (void) | |
708 | +sunos_solib_create_inferior_hook (int from_tty) | |
709 | { | |
710 | struct thread_info *tp; | |
711 | struct inferior *inf; | |
712 | diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c | |
713 | index 68aadc0..efbe717 100644 | |
714 | --- a/gdb/solib-svr4.c | |
715 | +++ b/gdb/solib-svr4.c | |
716 | @@ -50,6 +50,7 @@ | |
717 | ||
718 | static struct link_map_offsets *svr4_fetch_link_map_offsets (void); | |
719 | static int svr4_have_link_map_offsets (void); | |
720 | +static void svr4_relocate_main_executable (void); | |
721 | ||
722 | /* Link map info to include in an allocated so_list entry */ | |
723 | ||
724 | @@ -599,11 +600,12 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr) | |
725 | { | |
726 | int arch_size, step, sect_size; | |
727 | long dyn_tag; | |
728 | - CORE_ADDR dyn_ptr, dyn_addr; | |
729 | + CORE_ADDR dyn_ptr; | |
730 | gdb_byte *bufend, *bufstart, *buf; | |
731 | Elf32_External_Dyn *x_dynp_32; | |
732 | Elf64_External_Dyn *x_dynp_64; | |
733 | struct bfd_section *sect; | |
734 | + struct target_section *target_section; | |
735 | ||
736 | if (abfd == NULL) | |
737 | return 0; | |
738 | @@ -619,7 +621,13 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr) | |
739 | sect = bfd_get_section_by_name (abfd, ".dynamic"); | |
740 | if (sect == NULL) | |
741 | return 0; | |
742 | - dyn_addr = bfd_section_vma (abfd, sect); | |
743 | + | |
744 | + for (target_section = target_get_section_table (&exec_ops)->sections; | |
745 | + target_section < target_get_section_table (&exec_ops)->sections_end; | |
746 | + target_section++) | |
747 | + if (sect == target_section->the_bfd_section) | |
748 | + break; | |
749 | + gdb_assert (target_section < target_get_section_table (&exec_ops)->sections_end); | |
750 | ||
751 | /* Read in .dynamic from the BFD. We will get the actual value | |
752 | from memory later. */ | |
753 | @@ -661,7 +669,7 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr) | |
754 | CORE_ADDR ptr_addr; | |
755 | ||
756 | ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr; | |
757 | - ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8; | |
758 | + ptr_addr = target_section->addr + (buf - bufstart) + arch_size / 8; | |
759 | if (target_read_memory (ptr_addr, ptr_buf, arch_size / 8) == 0) | |
760 | dyn_ptr = extract_typed_address (ptr_buf, ptr_type); | |
761 | *ptr = dyn_ptr; | |
762 | @@ -1258,7 +1266,7 @@ exec_entry_point (struct bfd *abfd, struct target_ops *targ) | |
763 | */ | |
764 | ||
765 | static int | |
766 | -enable_break (struct svr4_info *info) | |
767 | +enable_break (struct svr4_info *info, int from_tty) | |
768 | { | |
769 | struct minimal_symbol *msymbol; | |
770 | char **bkpt_namep; | |
771 | @@ -1279,7 +1287,7 @@ enable_break (struct svr4_info *info) | |
772 | mean r_brk has already been relocated. Assume the dynamic linker | |
773 | is the object containing r_brk. */ | |
774 | ||
775 | - solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
776 | + solib_add (NULL, from_tty, ¤t_target, auto_solib_add); | |
777 | sym_addr = 0; | |
778 | if (info->debug_base && solib_svr4_r_map (info) != 0) | |
779 | sym_addr = solib_svr4_r_brk (info); | |
780 | @@ -1339,6 +1347,11 @@ enable_break (struct svr4_info *info) | |
781 | bfd *tmp_bfd = NULL; | |
782 | struct target_ops *tmp_bfd_target; | |
783 | volatile struct gdb_exception ex; | |
784 | + int addr_bit = gdbarch_addr_bit (target_gdbarch); | |
785 | + CORE_ADDR mask = CORE_ADDR_MAX; | |
786 | + | |
787 | + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) | |
788 | + mask = ((CORE_ADDR) 1 << addr_bit) - 1; | |
789 | ||
790 | sym_addr = 0; | |
791 | ||
792 | @@ -1404,7 +1417,7 @@ enable_break (struct svr4_info *info) | |
793 | info->debug_loader_name = xstrdup (interp_name); | |
794 | info->debug_loader_offset_p = 1; | |
795 | info->debug_loader_offset = load_addr; | |
796 | - solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
797 | + solib_add (NULL, from_tty, ¤t_target, auto_solib_add); | |
798 | } | |
799 | ||
800 | /* Record the relocated start and end address of the dynamic linker | |
801 | @@ -1414,16 +1427,20 @@ enable_break (struct svr4_info *info) | |
802 | { | |
803 | interp_text_sect_low = | |
804 | bfd_section_vma (tmp_bfd, interp_sect) + load_addr; | |
805 | + interp_text_sect_low &= mask; | |
806 | interp_text_sect_high = | |
807 | interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect); | |
808 | + interp_text_sect_high &= mask; | |
809 | } | |
810 | interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt"); | |
811 | if (interp_sect) | |
812 | { | |
813 | interp_plt_sect_low = | |
814 | bfd_section_vma (tmp_bfd, interp_sect) + load_addr; | |
815 | + interp_text_sect_low &= mask; | |
816 | interp_plt_sect_high = | |
817 | interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect); | |
818 | + interp_text_sect_high &= mask; | |
819 | } | |
820 | ||
821 | /* Now try to set a breakpoint in the dynamic linker. */ | |
822 | @@ -1448,7 +1465,7 @@ enable_break (struct svr4_info *info) | |
823 | ||
824 | if (sym_addr != 0) | |
825 | { | |
826 | - create_solib_event_breakpoint (target_gdbarch, load_addr + sym_addr); | |
827 | + create_solib_event_breakpoint (target_gdbarch, (load_addr + sym_addr) & mask); | |
828 | xfree (interp_name); | |
829 | return 1; | |
830 | } | |
831 | @@ -1517,113 +1534,131 @@ enable_break (struct svr4_info *info) | |
832 | static void | |
833 | svr4_special_symbol_handling (void) | |
834 | { | |
835 | + svr4_relocate_main_executable (); | |
836 | } | |
837 | ||
838 | -/* Relocate the main executable. This function should be called upon | |
839 | - stopping the inferior process at the entry point to the program. | |
840 | - The entry point from BFD is compared to the PC and if they are | |
841 | - different, the main executable is relocated by the proper amount. | |
842 | +/* Decide if the objfile needs to be relocated. As indicated above, | |
843 | + we will only be here when execution is stopped at the beginning | |
844 | + of the program. Relocation is necessary if the address at which | |
845 | + we are presently stopped differs from the start address stored in | |
846 | + the executable AND there's no interpreter section. The condition | |
847 | + regarding the interpreter section is very important because if | |
848 | + there *is* an interpreter section, execution will begin there | |
849 | + instead. When there is an interpreter section, the start address | |
850 | + is (presumably) used by the interpreter at some point to start | |
851 | + execution of the program. | |
852 | + | |
853 | + If there is an interpreter, it is normal for it to be set to an | |
854 | + arbitrary address at the outset. The job of finding it is | |
855 | + handled in enable_break(). | |
856 | + | |
857 | + So, to summarize, relocations are necessary when there is no | |
858 | + interpreter section and the start address obtained from the | |
859 | + executable is different from the address at which GDB is | |
860 | + currently stopped. | |
861 | ||
862 | - As written it will only attempt to relocate executables which | |
863 | - lack interpreter sections. It seems likely that only dynamic | |
864 | - linker executables will get relocated, though it should work | |
865 | - properly for a position-independent static executable as well. */ | |
866 | + [ The astute reader will note that we also test to make sure that | |
867 | + the executable in question has the DYNAMIC flag set. It is my | |
868 | + opinion that this test is unnecessary (undesirable even). It | |
869 | + was added to avoid inadvertent relocation of an executable | |
870 | + whose e_type member in the ELF header is not ET_DYN. There may | |
871 | + be a time in the future when it is desirable to do relocations | |
872 | + on other types of files as well in which case this condition | |
873 | + should either be removed or modified to accomodate the new file | |
874 | + type. (E.g, an ET_EXEC executable which has been built to be | |
875 | + position-independent could safely be relocated by the OS if | |
876 | + desired. It is true that this violates the ABI, but the ABI | |
877 | + has been known to be bent from time to time.) - Kevin, Nov 2000. ] | |
878 | + */ | |
879 | ||
880 | -static void | |
881 | -svr4_relocate_main_executable (void) | |
882 | +static CORE_ADDR | |
883 | +svr4_static_exec_displacement (void) | |
884 | { | |
885 | asection *interp_sect; | |
886 | struct regcache *regcache | |
887 | = get_thread_arch_regcache (inferior_ptid, target_gdbarch); | |
888 | CORE_ADDR pc = regcache_read_pc (regcache); | |
889 | ||
890 | - /* Decide if the objfile needs to be relocated. As indicated above, | |
891 | - we will only be here when execution is stopped at the beginning | |
892 | - of the program. Relocation is necessary if the address at which | |
893 | - we are presently stopped differs from the start address stored in | |
894 | - the executable AND there's no interpreter section. The condition | |
895 | - regarding the interpreter section is very important because if | |
896 | - there *is* an interpreter section, execution will begin there | |
897 | - instead. When there is an interpreter section, the start address | |
898 | - is (presumably) used by the interpreter at some point to start | |
899 | - execution of the program. | |
900 | - | |
901 | - If there is an interpreter, it is normal for it to be set to an | |
902 | - arbitrary address at the outset. The job of finding it is | |
903 | - handled in enable_break(). | |
904 | - | |
905 | - So, to summarize, relocations are necessary when there is no | |
906 | - interpreter section and the start address obtained from the | |
907 | - executable is different from the address at which GDB is | |
908 | - currently stopped. | |
909 | - | |
910 | - [ The astute reader will note that we also test to make sure that | |
911 | - the executable in question has the DYNAMIC flag set. It is my | |
912 | - opinion that this test is unnecessary (undesirable even). It | |
913 | - was added to avoid inadvertent relocation of an executable | |
914 | - whose e_type member in the ELF header is not ET_DYN. There may | |
915 | - be a time in the future when it is desirable to do relocations | |
916 | - on other types of files as well in which case this condition | |
917 | - should either be removed or modified to accomodate the new file | |
918 | - type. (E.g, an ET_EXEC executable which has been built to be | |
919 | - position-independent could safely be relocated by the OS if | |
920 | - desired. It is true that this violates the ABI, but the ABI | |
921 | - has been known to be bent from time to time.) - Kevin, Nov 2000. ] | |
922 | - */ | |
923 | - | |
924 | interp_sect = bfd_get_section_by_name (exec_bfd, ".interp"); | |
925 | if (interp_sect == NULL | |
926 | && (bfd_get_file_flags (exec_bfd) & DYNAMIC) != 0 | |
927 | && (exec_entry_point (exec_bfd, &exec_ops) != pc)) | |
928 | + return pc - exec_entry_point (exec_bfd, &exec_ops); | |
929 | + | |
930 | + return 0; | |
931 | +} | |
932 | + | |
933 | +/* We relocate all of the sections by the same amount. This | |
934 | + behavior is mandated by recent editions of the System V ABI. | |
935 | + According to the System V Application Binary Interface, | |
936 | + Edition 4.1, page 5-5: | |
937 | + | |
938 | + ... Though the system chooses virtual addresses for | |
939 | + individual processes, it maintains the segments' relative | |
940 | + positions. Because position-independent code uses relative | |
941 | + addressesing between segments, the difference between | |
942 | + virtual addresses in memory must match the difference | |
943 | + between virtual addresses in the file. The difference | |
944 | + between the virtual address of any segment in memory and | |
945 | + the corresponding virtual address in the file is thus a | |
946 | + single constant value for any one executable or shared | |
947 | + object in a given process. This difference is the base | |
948 | + address. One use of the base address is to relocate the | |
949 | + memory image of the program during dynamic linking. | |
950 | + | |
951 | + The same language also appears in Edition 4.0 of the System V | |
952 | + ABI and is left unspecified in some of the earlier editions. */ | |
953 | + | |
954 | +static CORE_ADDR | |
955 | +svr4_exec_displacement (void) | |
956 | +{ | |
957 | + int found; | |
958 | + CORE_ADDR entry_point; | |
959 | + | |
960 | + if (exec_bfd == NULL) | |
961 | + return 0; | |
962 | + | |
963 | + if (target_auxv_search (¤t_target, AT_ENTRY, &entry_point) == 1) | |
964 | + return entry_point - exec_entry_point (exec_bfd, ¤t_target); | |
965 | + | |
966 | + return svr4_static_exec_displacement (); | |
967 | +} | |
968 | + | |
969 | +/* Relocate the main executable. This function should be called upon | |
970 | + stopping the inferior process at the entry point to the program. | |
971 | + The entry point from BFD is compared to the AT_ENTRY of AUXV and if they are | |
972 | + different, the main executable is relocated by the proper amount. */ | |
973 | + | |
974 | +static void | |
975 | +svr4_relocate_main_executable (void) | |
976 | +{ | |
977 | + CORE_ADDR displacement = svr4_exec_displacement (); | |
978 | + | |
979 | + /* Even if DISPLACEMENT is 0 still try to relocate it as this is a new | |
980 | + difference of in-memory vs. in-file addresses and we could already | |
981 | + relocate the executable at this function to improper address before. */ | |
982 | + | |
983 | + if (symfile_objfile) | |
984 | { | |
985 | - struct cleanup *old_chain; | |
986 | struct section_offsets *new_offsets; | |
987 | - int i, changed; | |
988 | - CORE_ADDR displacement; | |
989 | - | |
990 | - /* It is necessary to relocate the objfile. The amount to | |
991 | - relocate by is simply the address at which we are stopped | |
992 | - minus the starting address from the executable. | |
993 | - | |
994 | - We relocate all of the sections by the same amount. This | |
995 | - behavior is mandated by recent editions of the System V ABI. | |
996 | - According to the System V Application Binary Interface, | |
997 | - Edition 4.1, page 5-5: | |
998 | - | |
999 | - ... Though the system chooses virtual addresses for | |
1000 | - individual processes, it maintains the segments' relative | |
1001 | - positions. Because position-independent code uses relative | |
1002 | - addressesing between segments, the difference between | |
1003 | - virtual addresses in memory must match the difference | |
1004 | - between virtual addresses in the file. The difference | |
1005 | - between the virtual address of any segment in memory and | |
1006 | - the corresponding virtual address in the file is thus a | |
1007 | - single constant value for any one executable or shared | |
1008 | - object in a given process. This difference is the base | |
1009 | - address. One use of the base address is to relocate the | |
1010 | - memory image of the program during dynamic linking. | |
1011 | - | |
1012 | - The same language also appears in Edition 4.0 of the System V | |
1013 | - ABI and is left unspecified in some of the earlier editions. */ | |
1014 | - | |
1015 | - displacement = pc - exec_entry_point (exec_bfd, &exec_ops); | |
1016 | - changed = 0; | |
1017 | - | |
1018 | - new_offsets = xcalloc (symfile_objfile->num_sections, | |
1019 | - sizeof (struct section_offsets)); | |
1020 | - old_chain = make_cleanup (xfree, new_offsets); | |
1021 | + int i; | |
1022 | + | |
1023 | + new_offsets = alloca (symfile_objfile->num_sections | |
1024 | + * sizeof (*new_offsets)); | |
1025 | ||
1026 | for (i = 0; i < symfile_objfile->num_sections; i++) | |
1027 | - { | |
1028 | - if (displacement != ANOFFSET (symfile_objfile->section_offsets, i)) | |
1029 | - changed = 1; | |
1030 | - new_offsets->offsets[i] = displacement; | |
1031 | - } | |
1032 | + new_offsets->offsets[i] = displacement; | |
1033 | ||
1034 | - if (changed) | |
1035 | - objfile_relocate (symfile_objfile, new_offsets); | |
1036 | + objfile_relocate (symfile_objfile, new_offsets); | |
1037 | + } | |
1038 | + else if (exec_bfd) | |
1039 | + { | |
1040 | + asection *asect; | |
1041 | ||
1042 | - do_cleanups (old_chain); | |
1043 | + for (asect = exec_bfd->sections; asect != NULL; asect = asect->next) | |
1044 | + exec_set_section_address (bfd_get_filename (exec_bfd), asect->index, | |
1045 | + bfd_section_vma (exec_bfd, asect) | |
1046 | + + displacement); | |
1047 | } | |
1048 | } | |
1049 | ||
1050 | @@ -1635,7 +1670,7 @@ svr4_relocate_main_executable (void) | |
1051 | ||
1052 | SYNOPSIS | |
1053 | ||
1054 | - void svr4_solib_create_inferior_hook () | |
1055 | + void svr4_solib_create_inferior_hook (int from_tty) | |
1056 | ||
1057 | DESCRIPTION | |
1058 | ||
1059 | @@ -1680,7 +1715,7 @@ svr4_relocate_main_executable (void) | |
1060 | */ | |
1061 | ||
1062 | static void | |
1063 | -svr4_solib_create_inferior_hook (void) | |
1064 | +svr4_solib_create_inferior_hook (int from_tty) | |
1065 | { | |
1066 | struct inferior *inf; | |
1067 | struct thread_info *tp; | |
1068 | @@ -1689,12 +1724,13 @@ svr4_solib_create_inferior_hook (void) | |
1069 | info = get_svr4_info (PIDGET (inferior_ptid)); | |
1070 | ||
1071 | /* Relocate the main executable if necessary. */ | |
1072 | - svr4_relocate_main_executable (); | |
1073 | + if (current_inferior ()->attach_flag == 0) | |
1074 | + svr4_relocate_main_executable (); | |
1075 | ||
1076 | if (!svr4_have_link_map_offsets ()) | |
1077 | return; | |
1078 | ||
1079 | - if (!enable_break (info)) | |
1080 | + if (!enable_break (info, from_tty)) | |
1081 | return; | |
1082 | ||
1083 | #if defined(_SCO_DS) | |
1084 | @@ -1910,8 +1946,19 @@ elf_lookup_lib_symbol (const struct objfile *objfile, | |
1085 | const char *name, | |
1086 | const domain_enum domain) | |
1087 | { | |
1088 | - if (objfile->obfd == NULL | |
1089 | - || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1) | |
1090 | + bfd *abfd; | |
1091 | + | |
1092 | + if (objfile == symfile_objfile) | |
1093 | + abfd = exec_bfd; | |
1094 | + else | |
1095 | + { | |
1096 | + /* OBJFILE should have been passed as the non-debug one. */ | |
1097 | + gdb_assert (objfile->separate_debug_objfile_backlink == NULL); | |
1098 | + | |
1099 | + abfd = objfile->obfd; | |
1100 | + } | |
1101 | + | |
1102 | + if (abfd == NULL || scan_dyntag (DT_SYMBOLIC, abfd, NULL) != 1) | |
1103 | return NULL; | |
1104 | ||
1105 | return lookup_global_symbol_from_objfile (objfile, name, domain); | |
1106 | diff --git a/gdb/solib-target.c b/gdb/solib-target.c | |
1107 | index 07415e4..d160a70 100644 | |
1108 | --- a/gdb/solib-target.c | |
1109 | +++ b/gdb/solib-target.c | |
1110 | @@ -306,7 +306,7 @@ solib_target_special_symbol_handling (void) | |
1111 | } | |
1112 | ||
1113 | static void | |
1114 | -solib_target_solib_create_inferior_hook (void) | |
1115 | +solib_target_solib_create_inferior_hook (int from_tty) | |
1116 | { | |
1117 | /* Nothing needed. */ | |
1118 | } | |
1119 | diff --git a/gdb/solib.c b/gdb/solib.c | |
1120 | index 3574e62..7ea3663 100644 | |
1121 | --- a/gdb/solib.c | |
1122 | +++ b/gdb/solib.c | |
1123 | @@ -998,7 +998,7 @@ clear_solib (void) | |
1124 | ||
1125 | SYNOPSIS | |
1126 | ||
1127 | - void solib_create_inferior_hook () | |
1128 | + void solib_create_inferior_hook (int from_tty) | |
1129 | ||
1130 | DESCRIPTION | |
1131 | ||
1132 | @@ -1008,10 +1008,10 @@ clear_solib (void) | |
1133 | SOLIB_CREATE_INFERIOR_HOOK. */ | |
1134 | ||
1135 | void | |
1136 | -solib_create_inferior_hook (void) | |
1137 | +solib_create_inferior_hook (int from_tty) | |
1138 | { | |
1139 | struct target_so_ops *ops = solib_ops (target_gdbarch); | |
1140 | - ops->solib_create_inferior_hook(); | |
1141 | + ops->solib_create_inferior_hook (from_tty); | |
1142 | } | |
1143 | ||
1144 | /* GLOBAL FUNCTION | |
1145 | @@ -1087,7 +1087,6 @@ reload_shared_libraries (char *ignored, int from_tty, | |
1146 | struct cmd_list_element *e) | |
1147 | { | |
1148 | no_shared_libraries (NULL, from_tty); | |
1149 | - solib_add (NULL, from_tty, NULL, auto_solib_add); | |
1150 | /* Creating inferior hooks here has two purposes. First, if we reload | |
1151 | shared libraries then the address of solib breakpoint we've computed | |
1152 | previously might be no longer valid. For example, if we forgot to set | |
1153 | @@ -1102,9 +1101,19 @@ reload_shared_libraries (char *ignored, int from_tty, | |
1154 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
1155 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); | |
1156 | #else | |
1157 | - solib_create_inferior_hook (); | |
1158 | + solib_create_inferior_hook (from_tty); | |
1159 | #endif | |
1160 | } | |
1161 | + | |
1162 | + /* Sometimes the platform-specific hook loads initial shared | |
1163 | + libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be | |
1164 | + incorrectly 0 but such solib targets should be fixed anyway. If we | |
1165 | + made all the inferior hook methods consistent, this call could be | |
1166 | + removed. Call it only after the solib target has been initialized by | |
1167 | + solib_create_inferior_hook. */ | |
1168 | + | |
1169 | + solib_add (NULL, 0, NULL, auto_solib_add); | |
1170 | + | |
1171 | /* We have unloaded and then reloaded debug info for all shared libraries. | |
1172 | However, frames may still reference them, for example a frame's | |
1173 | unwinder might still point of DWARF FDE structures that are now freed. | |
1174 | diff --git a/gdb/solib.h b/gdb/solib.h | |
1175 | index ccc5b63..abe5e19 100644 | |
1176 | --- a/gdb/solib.h | |
1177 | +++ b/gdb/solib.h | |
1178 | @@ -41,7 +41,7 @@ extern int solib_read_symbols (struct so_list *, int); | |
1179 | addresses to which they are linked, and sufficient information to | |
1180 | read in their symbols at a later time. */ | |
1181 | ||
1182 | -extern void solib_create_inferior_hook (void); | |
1183 | +extern void solib_create_inferior_hook (int from_tty); | |
1184 | ||
1185 | /* If ADDR lies in a shared library, return its name. */ | |
1186 | ||
1187 | diff --git a/gdb/solist.h b/gdb/solist.h | |
1188 | index 005e8f7..9724fe7 100644 | |
1189 | --- a/gdb/solist.h | |
1190 | +++ b/gdb/solist.h | |
1191 | @@ -87,7 +87,7 @@ struct target_so_ops | |
1192 | void (*clear_solib) (void); | |
1193 | ||
1194 | /* Target dependent code to run after child process fork. */ | |
1195 | - void (*solib_create_inferior_hook) (void); | |
1196 | + void (*solib_create_inferior_hook) (int from_tty); | |
1197 | ||
1198 | /* Do additional symbol handling, lookup, etc. after symbols | |
1199 | for a shared object have been loaded. */ | |
1200 | diff --git a/gdb/symfile.c b/gdb/symfile.c | |
1201 | index c31b72a..6d7fa10 100644 | |
1202 | --- a/gdb/symfile.c | |
1203 | +++ b/gdb/symfile.c | |
1204 | @@ -536,40 +536,151 @@ place_section (bfd *abfd, asection *sect, void *obj) | |
1205 | arg->lowest = start_addr + bfd_get_section_size (sect); | |
1206 | } | |
1207 | ||
1208 | -/* Parse the user's idea of an offset for dynamic linking, into our idea | |
1209 | - of how to represent it for fast symbol reading. This is the default | |
1210 | - version of the sym_fns.sym_offsets function for symbol readers that | |
1211 | - don't need to do anything special. It allocates a section_offsets table | |
1212 | - for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */ | |
1213 | +/* Build (allocate and populate) struct section_addr_info with absolute | |
1214 | + addresses from OBJFILE->OBFD and OBJFILE->SECTION_OFFSETS. */ | |
1215 | + | |
1216 | +struct section_addr_info * | |
1217 | +build_section_addr_info_from_objfile (struct objfile *objfile) | |
1218 | +{ | |
1219 | + struct target_section *sections = NULL, *sections_end; | |
1220 | + struct target_section *p; | |
1221 | + int addr_bit = gdbarch_addr_bit (objfile->gdbarch); | |
1222 | + CORE_ADDR mask = CORE_ADDR_MAX; | |
1223 | + struct section_addr_info *retval; | |
1224 | + struct cleanup *my_cleanups; | |
1225 | + | |
1226 | + if (build_section_table (objfile->obfd, §ions, §ions_end)) | |
1227 | + error (_("Can't find the file sections in `%s': %s"), | |
1228 | + bfd_get_filename (objfile->obfd), bfd_errmsg (bfd_get_error ())); | |
1229 | + my_cleanups = make_cleanup (xfree, sections); | |
1230 | + | |
1231 | + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) | |
1232 | + mask = ((CORE_ADDR) 1 << addr_bit) - 1; | |
1233 | + | |
1234 | + for (p = sections; p < sections_end; p++) | |
1235 | + { | |
1236 | + CORE_ADDR baseaddr; | |
1237 | + | |
1238 | + gdb_assert (p->the_bfd_section->index < objfile->num_sections); | |
1239 | + baseaddr = ANOFFSET (objfile->section_offsets, | |
1240 | + p->the_bfd_section->index); | |
1241 | + | |
1242 | + p->addr = (p->addr + baseaddr) & mask; | |
1243 | + p->endaddr = (p->endaddr + baseaddr) & mask; | |
1244 | + } | |
1245 | + | |
1246 | + retval = build_section_addr_info_from_section_table (sections, sections_end); | |
1247 | + | |
1248 | + do_cleanups (my_cleanups); | |
1249 | + | |
1250 | + return retval; | |
1251 | +} | |
1252 | + | |
1253 | +/* Store struct section_addr_info as prepared (made relative and with SECTINDEX | |
1254 | + filled-in) by addr_info_make_relative into SECTION_OFFSETS of NUM_SECTIONS | |
1255 | + entries. */ | |
1256 | ||
1257 | void | |
1258 | -default_symfile_offsets (struct objfile *objfile, | |
1259 | - struct section_addr_info *addrs) | |
1260 | +relative_addr_info_to_section_offsets (struct section_offsets *section_offsets, | |
1261 | + int num_sections, | |
1262 | + struct section_addr_info *addrs) | |
1263 | { | |
1264 | int i; | |
1265 | ||
1266 | - objfile->num_sections = bfd_count_sections (objfile->obfd); | |
1267 | - objfile->section_offsets = (struct section_offsets *) | |
1268 | - obstack_alloc (&objfile->objfile_obstack, | |
1269 | - SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); | |
1270 | - memset (objfile->section_offsets, 0, | |
1271 | - SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); | |
1272 | + memset (section_offsets, 0, SIZEOF_N_SECTION_OFFSETS (num_sections)); | |
1273 | ||
1274 | - /* Now calculate offsets for section that were specified by the | |
1275 | - caller. */ | |
1276 | + /* Now calculate offsets for section that were specified by the caller. */ | |
1277 | for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++) | |
1278 | { | |
1279 | - struct other_sections *osp ; | |
1280 | + struct other_sections *osp; | |
1281 | ||
1282 | - osp = &addrs->other[i] ; | |
1283 | + osp = &addrs->other[i]; | |
1284 | if (osp->addr == 0) | |
1285 | continue; | |
1286 | ||
1287 | /* Record all sections in offsets */ | |
1288 | /* The section_offsets in the objfile are here filled in using | |
1289 | the BFD index. */ | |
1290 | - (objfile->section_offsets)->offsets[osp->sectindex] = osp->addr; | |
1291 | + section_offsets->offsets[osp->sectindex] = osp->addr; | |
1292 | + } | |
1293 | +} | |
1294 | + | |
1295 | +/* Relativize absolute addresses in ADDRS into offsets based on ABFD. Fill-in | |
1296 | + also SECTINDEXes there. */ | |
1297 | + | |
1298 | +void | |
1299 | +addr_info_make_relative (struct section_addr_info *addrs, bfd *abfd) | |
1300 | +{ | |
1301 | + asection *lower_sect; | |
1302 | + asection *sect; | |
1303 | + CORE_ADDR lower_offset; | |
1304 | + int i; | |
1305 | + | |
1306 | + /* Find lowest loadable section to be used as starting point for | |
1307 | + continguous sections. FIXME!! won't work without call to find | |
1308 | + .text first, but this assumes text is lowest section. */ | |
1309 | + lower_sect = bfd_get_section_by_name (abfd, ".text"); | |
1310 | + if (lower_sect == NULL) | |
1311 | + bfd_map_over_sections (abfd, find_lowest_section, &lower_sect); | |
1312 | + if (lower_sect == NULL) | |
1313 | + { | |
1314 | + warning (_("no loadable sections found in added symbol-file %s"), | |
1315 | + bfd_get_filename (abfd)); | |
1316 | + lower_offset = 0; | |
1317 | + } | |
1318 | + else | |
1319 | + lower_offset = bfd_section_vma (bfd_get_filename (abfd), lower_sect); | |
1320 | + | |
1321 | + /* Calculate offsets for the loadable sections. | |
1322 | + FIXME! Sections must be in order of increasing loadable section | |
1323 | + so that contiguous sections can use the lower-offset!!! | |
1324 | + | |
1325 | + Adjust offsets if the segments are not contiguous. | |
1326 | + If the section is contiguous, its offset should be set to | |
1327 | + the offset of the highest loadable section lower than it | |
1328 | + (the loadable section directly below it in memory). | |
1329 | + this_offset = lower_offset = lower_addr - lower_orig_addr */ | |
1330 | + | |
1331 | + for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++) | |
1332 | + { | |
1333 | + if (addrs->other[i].addr != 0) | |
1334 | + { | |
1335 | + sect = bfd_get_section_by_name (abfd, addrs->other[i].name); | |
1336 | + if (sect) | |
1337 | + { | |
1338 | + addrs->other[i].addr -= bfd_section_vma (abfd, sect); | |
1339 | + lower_offset = addrs->other[i].addr; | |
1340 | + /* This is the index used by BFD. */ | |
1341 | + addrs->other[i].sectindex = sect->index; | |
1342 | + } | |
1343 | + else | |
1344 | + { | |
1345 | + warning (_("section %s not found in %s"), addrs->other[i].name, | |
1346 | + bfd_get_filename (abfd)); | |
1347 | + addrs->other[i].addr = 0; | |
1348 | + } | |
1349 | + } | |
1350 | + else | |
1351 | + addrs->other[i].addr = lower_offset; | |
1352 | } | |
1353 | +} | |
1354 | + | |
1355 | +/* Parse the user's idea of an offset for dynamic linking, into our idea | |
1356 | + of how to represent it for fast symbol reading. This is the default | |
1357 | + version of the sym_fns.sym_offsets function for symbol readers that | |
1358 | + don't need to do anything special. It allocates a section_offsets table | |
1359 | + for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */ | |
1360 | + | |
1361 | +void | |
1362 | +default_symfile_offsets (struct objfile *objfile, | |
1363 | + struct section_addr_info *addrs) | |
1364 | +{ | |
1365 | + objfile->num_sections = bfd_count_sections (objfile->obfd); | |
1366 | + objfile->section_offsets = (struct section_offsets *) | |
1367 | + obstack_alloc (&objfile->objfile_obstack, | |
1368 | + SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); | |
1369 | + relative_addr_info_to_section_offsets (objfile->section_offsets, | |
1370 | + objfile->num_sections, addrs); | |
1371 | ||
1372 | /* For relocatable files, all loadable sections will start at zero. | |
1373 | The zero is meaningless, so try to pick arbitrary addresses such | |
1374 | @@ -803,65 +914,8 @@ syms_from_objfile (struct objfile *objfile, | |
1375 | ||
1376 | We no longer warn if the lowest section is not a text segment (as | |
1377 | happens for the PA64 port. */ | |
1378 | - if (!mainline && addrs && addrs->other[0].name) | |
1379 | - { | |
1380 | - asection *lower_sect; | |
1381 | - asection *sect; | |
1382 | - CORE_ADDR lower_offset; | |
1383 | - int i; | |
1384 | - | |
1385 | - /* Find lowest loadable section to be used as starting point for | |
1386 | - continguous sections. FIXME!! won't work without call to find | |
1387 | - .text first, but this assumes text is lowest section. */ | |
1388 | - lower_sect = bfd_get_section_by_name (objfile->obfd, ".text"); | |
1389 | - if (lower_sect == NULL) | |
1390 | - bfd_map_over_sections (objfile->obfd, find_lowest_section, | |
1391 | - &lower_sect); | |
1392 | - if (lower_sect == NULL) | |
1393 | - { | |
1394 | - warning (_("no loadable sections found in added symbol-file %s"), | |
1395 | - objfile->name); | |
1396 | - lower_offset = 0; | |
1397 | - } | |
1398 | - else | |
1399 | - lower_offset = bfd_section_vma (objfile->obfd, lower_sect); | |
1400 | - | |
1401 | - /* Calculate offsets for the loadable sections. | |
1402 | - FIXME! Sections must be in order of increasing loadable section | |
1403 | - so that contiguous sections can use the lower-offset!!! | |
1404 | - | |
1405 | - Adjust offsets if the segments are not contiguous. | |
1406 | - If the section is contiguous, its offset should be set to | |
1407 | - the offset of the highest loadable section lower than it | |
1408 | - (the loadable section directly below it in memory). | |
1409 | - this_offset = lower_offset = lower_addr - lower_orig_addr */ | |
1410 | - | |
1411 | - for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++) | |
1412 | - { | |
1413 | - if (addrs->other[i].addr != 0) | |
1414 | - { | |
1415 | - sect = bfd_get_section_by_name (objfile->obfd, | |
1416 | - addrs->other[i].name); | |
1417 | - if (sect) | |
1418 | - { | |
1419 | - addrs->other[i].addr | |
1420 | - -= bfd_section_vma (objfile->obfd, sect); | |
1421 | - lower_offset = addrs->other[i].addr; | |
1422 | - /* This is the index used by BFD. */ | |
1423 | - addrs->other[i].sectindex = sect->index ; | |
1424 | - } | |
1425 | - else | |
1426 | - { | |
1427 | - warning (_("section %s not found in %s"), | |
1428 | - addrs->other[i].name, | |
1429 | - objfile->name); | |
1430 | - addrs->other[i].addr = 0; | |
1431 | - } | |
1432 | - } | |
1433 | - else | |
1434 | - addrs->other[i].addr = lower_offset; | |
1435 | - } | |
1436 | - } | |
1437 | + if (addrs && addrs->other[0].name) | |
1438 | + addr_info_make_relative (addrs, objfile->obfd); | |
1439 | ||
1440 | /* Initialize symbol reading routines for this objfile, allow complaints to | |
1441 | appear for this new file, and record how verbose to be, then do the | |
1442 | @@ -959,7 +1013,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd, | |
1443 | struct objfile *objfile; | |
1444 | struct partial_symtab *psymtab; | |
1445 | char *debugfile = NULL; | |
1446 | - struct section_addr_info *orig_addrs = NULL; | |
1447 | struct cleanup *my_cleanups; | |
1448 | const char *name = bfd_get_filename (abfd); | |
1449 | const int from_tty = add_flags & SYMFILE_VERBOSE; | |
1450 | @@ -981,12 +1034,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd, | |
1451 | objfile->flags |= OBJF_MAIN; | |
1452 | discard_cleanups (my_cleanups); | |
1453 | ||
1454 | - if (addrs) | |
1455 | - { | |
1456 | - orig_addrs = copy_section_addr_info (addrs); | |
1457 | - make_cleanup_free_section_addr_info (orig_addrs); | |
1458 | - } | |
1459 | - | |
1460 | /* We either created a new mapped symbol table, mapped an existing | |
1461 | symbol table file which has not had initial symbol reading | |
1462 | performed, or need to read an unmapped symbol table. */ | |
1463 | @@ -1033,18 +1080,17 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd, | |
1464 | `.gnu_debuglink' may no longer be present with `.note.gnu.build-id'. */ | |
1465 | if (!has_any_debug_symbols (objfile)) | |
1466 | debugfile = find_separate_debug_file (objfile); | |
1467 | + | |
1468 | if (debugfile) | |
1469 | { | |
1470 | - if (addrs != NULL) | |
1471 | - { | |
1472 | - objfile->separate_debug_objfile | |
1473 | - = symbol_file_add (debugfile, add_flags, orig_addrs, flags); | |
1474 | - } | |
1475 | - else | |
1476 | - { | |
1477 | - objfile->separate_debug_objfile | |
1478 | - = symbol_file_add (debugfile, add_flags, NULL, flags); | |
1479 | - } | |
1480 | + struct section_addr_info *objfile_addrs; | |
1481 | + | |
1482 | + objfile_addrs = build_section_addr_info_from_objfile (objfile); | |
1483 | + make_cleanup (xfree, objfile_addrs); | |
1484 | + | |
1485 | + objfile->separate_debug_objfile = symbol_file_add (debugfile, add_flags, | |
1486 | + objfile_addrs, flags); | |
1487 | + | |
1488 | objfile->separate_debug_objfile->separate_debug_objfile_backlink | |
1489 | = objfile; | |
1490 | ||
1491 | diff --git a/gdb/symfile.h b/gdb/symfile.h | |
1492 | index bf9d9e7..bff6bd8 100644 | |
1493 | --- a/gdb/symfile.h | |
1494 | +++ b/gdb/symfile.h | |
1495 | @@ -181,6 +181,16 @@ struct sym_fns | |
1496 | ||
1497 | }; | |
1498 | ||
1499 | +extern struct section_addr_info * | |
1500 | + build_section_addr_info_from_objfile (struct objfile *objfile); | |
1501 | + | |
1502 | +extern void relative_addr_info_to_section_offsets | |
1503 | + (struct section_offsets *section_offsets, int num_sections, | |
1504 | + struct section_addr_info *addrs); | |
1505 | + | |
1506 | +extern void addr_info_make_relative (struct section_addr_info *addrs, | |
1507 | + bfd *abfd); | |
1508 | + | |
1509 | /* The default version of sym_fns.sym_offsets for readers that don't | |
1510 | do anything special. */ | |
1511 | ||
1512 | diff --git a/gdb/symtab.c b/gdb/symtab.c | |
1513 | index 82e0163..01117e3 100644 | |
1514 | --- a/gdb/symtab.c | |
1515 | +++ b/gdb/symtab.c | |
1516 | @@ -1449,7 +1449,12 @@ lookup_objfile_from_block (const struct block *block) | |
1517 | /* Go through SYMTABS. */ | |
1518 | ALL_SYMTABS (obj, s) | |
1519 | if (block == BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK)) | |
1520 | - return obj; | |
1521 | + { | |
1522 | + if (obj->separate_debug_objfile_backlink) | |
1523 | + obj = obj->separate_debug_objfile_backlink; | |
1524 | + | |
1525 | + return obj; | |
1526 | + } | |
1527 | ||
1528 | return NULL; | |
1529 | } | |
1530 | diff --git a/gdb/testsuite/gdb.base/break-interp-lib.c b/gdb/testsuite/gdb.base/break-interp-lib.c | |
1531 | new file mode 100644 | |
1532 | index 0000000..9ca943e | |
1533 | --- /dev/null | |
1534 | +++ b/gdb/testsuite/gdb.base/break-interp-lib.c | |
1535 | @@ -0,0 +1,40 @@ | |
1536 | +/* This testcase is part of GDB, the GNU debugger. | |
1537 | + | |
1538 | + Copyright 2009 Free Software Foundation, Inc. | |
1539 | + | |
1540 | + This program is free software; you can redistribute it and/or modify | |
1541 | + it under the terms of the GNU General Public License as published by | |
1542 | + the Free Software Foundation; either version 3 of the License, or | |
1543 | + (at your option) any later version. | |
1544 | + | |
1545 | + This program is distributed in the hope that it will be useful, | |
1546 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1547 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1548 | + GNU General Public License for more details. | |
1549 | + | |
1550 | + You should have received a copy of the GNU General Public License | |
1551 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
1552 | + | |
1553 | +#include <signal.h> | |
1554 | +#include <unistd.h> | |
1555 | +#include <assert.h> | |
1556 | +#include <stdio.h> | |
1557 | + | |
1558 | +void | |
1559 | +libfunc (const char *action) | |
1560 | +{ | |
1561 | + assert (action != NULL); | |
1562 | + | |
1563 | + if (strcmp (action, "segv") == 0) | |
1564 | + raise (SIGSEGV); | |
1565 | + | |
1566 | + if (strcmp (action, "sleep") == 0) | |
1567 | + { | |
1568 | + puts ("sleeping"); | |
1569 | + fflush (stdout); | |
1570 | + | |
1571 | + sleep (60); | |
1572 | + } | |
1573 | + | |
1574 | + assert (0); | |
1575 | +} | |
1576 | diff --git a/gdb/testsuite/gdb.base/break-interp-main.c b/gdb/testsuite/gdb.base/break-interp-main.c | |
1577 | new file mode 100644 | |
1578 | index 0000000..e12ec2b | |
1579 | --- /dev/null | |
1580 | +++ b/gdb/testsuite/gdb.base/break-interp-main.c | |
1581 | @@ -0,0 +1,30 @@ | |
1582 | +/* This testcase is part of GDB, the GNU debugger. | |
1583 | + | |
1584 | + Copyright 2009 Free Software Foundation, Inc. | |
1585 | + | |
1586 | + This program is free software; you can redistribute it and/or modify | |
1587 | + it under the terms of the GNU General Public License as published by | |
1588 | + the Free Software Foundation; either version 3 of the License, or | |
1589 | + (at your option) any later version. | |
1590 | + | |
1591 | + This program is distributed in the hope that it will be useful, | |
1592 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1593 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1594 | + GNU General Public License for more details. | |
1595 | + | |
1596 | + You should have received a copy of the GNU General Public License | |
1597 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
1598 | + | |
1599 | +#include <assert.h> | |
1600 | + | |
1601 | +extern void libfunc (const char *action); | |
1602 | + | |
1603 | +int | |
1604 | +main (int argc, char **argv) | |
1605 | +{ | |
1606 | + assert (argc == 2); | |
1607 | + | |
1608 | + libfunc (argv[1]); | |
1609 | + | |
1610 | + return 0; | |
1611 | +} | |
1612 | diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp | |
1613 | new file mode 100644 | |
1614 | index 0000000..52f460c | |
1615 | --- /dev/null | |
1616 | +++ b/gdb/testsuite/gdb.base/break-interp.exp | |
1617 | @@ -0,0 +1,545 @@ | |
1618 | +# Copyright 2009 Free Software Foundation, Inc. | |
1619 | + | |
1620 | +# This program is free software; you can redistribute it and/or modify | |
1621 | +# it under the terms of the GNU General Public License as published by | |
1622 | +# the Free Software Foundation; either version 3 of the License, or | |
1623 | +# (at your option) any later version. | |
1624 | +# | |
1625 | +# This program is distributed in the hope that it will be useful, | |
1626 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1627 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1628 | +# GNU General Public License for more details. | |
1629 | +# | |
1630 | +# You should have received a copy of the GNU General Public License | |
1631 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1632 | + | |
1633 | +# This test only works on GNU/Linux. | |
1634 | +if { ![isnative] || [is_remote host] || ![istarget *-linux*] || [skip_shlib_tests]} { | |
1635 | + continue | |
1636 | +} | |
1637 | + | |
1638 | +set test "break-interp" | |
1639 | +set binprefix ${objdir}/${subdir}/${test} | |
1640 | +# Only to get the $interp_system name. | |
1641 | +set srcfile_test "start.c" | |
1642 | +set binfile_test ${test}-test | |
1643 | +set binfile_lib ${objdir}/${subdir}/${test}.so | |
1644 | +set srcfile "${test}-main.c" | |
1645 | +set srcfile_lib "${test}-lib.c" | |
1646 | + | |
1647 | +if [get_compiler_info ${binfile_lib}] { | |
1648 | + return -1 | |
1649 | +} | |
1650 | + | |
1651 | +# Use -soname so that it is listed with " => " by ldd and this testcase makes | |
1652 | +# a copy of ${binfile_lib} for each prelink variant. | |
1653 | + | |
1654 | +if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug additional_flags=-Wl,-soname,${test}.so]] != ""} { | |
1655 | + return -1 | |
1656 | +} | |
1657 | + | |
1658 | +if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} { | |
1659 | + return -1 | |
1660 | +} | |
1661 | + | |
1662 | +# Return the interpreter filename string. | |
1663 | +# Return "" if no interpreter was found. | |
1664 | +proc section_get {exec section} { | |
1665 | + global objdir | |
1666 | + global subdir | |
1667 | + set tmp "${objdir}/${subdir}/break-interp.interp" | |
1668 | + set objcopy_program [transform objcopy] | |
1669 | + | |
1670 | + set command "exec $objcopy_program -O binary --set-section-flags $section=A --change-section-address $section=0 -j $section $exec $tmp" | |
1671 | + verbose -log "command is $command" | |
1672 | + set result [catch $command output] | |
1673 | + verbose -log "result is $result" | |
1674 | + verbose -log "output is $output" | |
1675 | + if {$result == 1} { | |
1676 | + return "" | |
1677 | + } | |
1678 | + set fi [open $tmp] | |
1679 | + fconfigure $fi -translation binary | |
1680 | + set data [read $fi] | |
1681 | + close $fi | |
1682 | + #file delete $tmp | |
1683 | + # .interp has size $len + 1 but .gnu_debuglink contains garbage after \000. | |
1684 | + set len [string first \000 $data] | |
1685 | + if {$len < 0} { | |
1686 | + verbose -log "section $section not found" | |
1687 | + return "" | |
1688 | + } | |
1689 | + set retval [string range $data 0 [expr $len - 1]] | |
1690 | + verbose -log "section $section is <$retval>" | |
1691 | + return $retval | |
1692 | +} | |
1693 | + | |
1694 | +# Note: The separate debug info file content build-id/crc32 are not verified | |
1695 | +# contrary to the GDB search algorithm skipping non-matching ones. | |
1696 | +proc system_debug_get {exec} { | |
1697 | + global debug_root | |
1698 | + | |
1699 | + set exec_build_id_debug [build_id_debug_filename_get $exec] | |
1700 | + set debug_base "[file tail $exec].debug" | |
1701 | + set exec_dir [file dirname $exec] | |
1702 | + | |
1703 | + # isfile returns 1 even for symlinks to files. | |
1704 | + set retval $debug_root/$exec_build_id_debug | |
1705 | + if [file isfile $retval] { | |
1706 | + return $retval | |
1707 | + } | |
1708 | + set retval $exec_dir/$debug_base | |
1709 | + if [file isfile $retval] { | |
1710 | + return $retval | |
1711 | + } | |
1712 | + set retval $exec_dir/.debug/$debug_base | |
1713 | + if [file isfile $retval] { | |
1714 | + return $retval | |
1715 | + } | |
1716 | + set retval $debug_root/$exec_dir/$debug_base | |
1717 | + if [file isfile $retval] { | |
1718 | + return $retval | |
1719 | + } | |
1720 | + return "" | |
1721 | +} | |
1722 | + | |
1723 | +gdb_exit | |
1724 | +gdb_start | |
1725 | +set debug_root "" | |
1726 | +set test "show debug-file-directory" | |
1727 | +gdb_test_multiple $test $test { | |
1728 | + -re "The directory where separate debug symbols are searched for is \"(.*)\".\r\n$gdb_prompt $" { | |
1729 | + set debug_root $expect_out(1,string) | |
1730 | + } | |
1731 | +} | |
1732 | + | |
1733 | +set interp_system [section_get ${objdir}/${subdir}/$binfile_test .interp] | |
1734 | +set interp_system_debug [system_debug_get $interp_system] | |
1735 | +verbose -log "$interp_system has debug $interp_system_debug" | |
1736 | + | |
1737 | +proc prelinkNO_run {arg} { | |
1738 | + set command "exec /usr/sbin/prelink -uN $arg" | |
1739 | + verbose -log "command is $command" | |
1740 | + set result [catch $command output] | |
1741 | + verbose -log "result is $result" | |
1742 | + verbose -log "output is $output" | |
1743 | + return [list $result $output] | |
1744 | +} | |
1745 | + | |
1746 | +proc prelinkNO {arg {name {}}} { | |
1747 | + if {$name == ""} { | |
1748 | + set name [file tail $arg] | |
1749 | + } | |
1750 | + set test "unprelink $name" | |
1751 | + set run [prelinkNO_run $arg] | |
1752 | + set result [lindex $run 0] | |
1753 | + set output [lindex $run 1] | |
1754 | + if {$result == 0 && $output == ""} { | |
1755 | + verbose -log "$name has been now unprelinked" | |
1756 | + set run [prelinkNO_run $arg] | |
1757 | + set result [lindex $run 0] | |
1758 | + set output [lindex $run 1] | |
1759 | + } | |
1760 | + # Last line does miss the trailing \n. | |
1761 | + if {$result == 1 && [regexp {^(/usr/sbin/prelink: [^ ]* does not have .gnu.prelink_undo section\n?)*$} $output]} { | |
1762 | + pass $test | |
1763 | + return 1 | |
1764 | + } else { | |
1765 | + fail $test | |
1766 | + return 0 | |
1767 | + } | |
1768 | +} | |
1769 | + | |
1770 | +proc prelinkYES {arg {name ""}} { | |
1771 | + if {$name == ""} { | |
1772 | + set name [file tail $arg] | |
1773 | + } | |
1774 | + set test "prelink $name" | |
1775 | + set command "exec /usr/sbin/prelink -qNR --no-exec-shield $arg" | |
1776 | + verbose -log "command is $command" | |
1777 | + set result [catch $command output] | |
1778 | + verbose -log "result is $result" | |
1779 | + verbose -log "output is $output" | |
1780 | + if {$result == 0 && $output == ""} { | |
1781 | + pass $test | |
1782 | + return 1 | |
1783 | + } else { | |
1784 | + fail $test | |
1785 | + return 0 | |
1786 | + } | |
1787 | +} | |
1788 | + | |
1789 | +# Resolve symlinks. | |
1790 | +proc symlink_resolve {file} { | |
1791 | + set loop 0 | |
1792 | + while {[file type $file] == "link"} { | |
1793 | + set target [file readlink $file] | |
1794 | + if {[file pathtype $target] == "relative"} { | |
1795 | + set src2 [file dirname $file]/$target | |
1796 | + } else { | |
1797 | + set src2 $target | |
1798 | + } | |
1799 | + verbose -log "Resolved symlink $file targetting $target as $src2" | |
1800 | + set file $src2 | |
1801 | + | |
1802 | + set loop [expr $loop + 1] | |
1803 | + if {$loop > 30} { | |
1804 | + fail "Looping symlink resolution for $file" | |
1805 | + return "" | |
1806 | + } | |
1807 | + } | |
1808 | + return $file | |
1809 | +} | |
1810 | + | |
1811 | +proc copy {src dest} { | |
1812 | + set src [symlink_resolve $src] | |
1813 | + # Test name would contain build-id hash for symlink-unresolved $src. | |
1814 | + set test "copy [file tail $src] to [file tail $dest]" | |
1815 | + set command "file copy -force $src $dest" | |
1816 | + verbose -log "command is $command" | |
1817 | + if [catch $command] { | |
1818 | + fail $test | |
1819 | + return 0 | |
1820 | + } else { | |
1821 | + pass $test | |
1822 | + return 1 | |
1823 | + } | |
1824 | +} | |
1825 | + | |
1826 | +proc strip_debug {dest} { | |
1827 | + set test "strip [file tail $dest]" | |
1828 | + set strip_program [transform strip] | |
1829 | + set command "exec $strip_program --strip-debug $dest" | |
1830 | + verbose -log "command is $command" | |
1831 | + if [catch $command] { | |
1832 | + fail $test | |
1833 | + return 0 | |
1834 | + } else { | |
1835 | + pass $test | |
1836 | + return 1 | |
1837 | + } | |
1838 | +} | |
1839 | + | |
1840 | +# `runto' does not check we stopped really at the function we specified. | |
1841 | +proc reach {func command} { | |
1842 | + global gdb_prompt | |
1843 | + | |
1844 | + if [gdb_breakpoint $func allow-pending] { | |
1845 | + set test "reach $func" | |
1846 | + gdb_test_multiple $command $test { | |
1847 | + -re "Breakpoint \[0-9\]+, $func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" { | |
1848 | + pass $test | |
1849 | + } | |
1850 | + -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in $func \\(\\)( from .*)?\r\n$gdb_prompt $" { | |
1851 | + pass $test | |
1852 | + } | |
1853 | + } | |
1854 | + } | |
1855 | +} | |
1856 | + | |
1857 | +proc test_core {file} { | |
1858 | + global srcdir subdir gdb_prompt | |
1859 | + | |
1860 | + set corefile [core_find $file {} "segv"] | |
1861 | + if {$corefile == ""} { | |
1862 | + return | |
1863 | + } | |
1864 | + | |
1865 | + gdb_exit | |
1866 | + gdb_start | |
1867 | + # Clear it to never find any separate debug infos in $debug_root. | |
1868 | + gdb_test "set debug-file-directory" "" "set debug-file-directory for core" | |
1869 | + gdb_reinitialize_dir $srcdir/$subdir | |
1870 | + gdb_load $file | |
1871 | + | |
1872 | + # Do not check the binary filename as it may be truncated. | |
1873 | + gdb_test "core-file $corefile" "Core was generated by .*\r\n#0 .*" "core loaded" | |
1874 | + | |
1875 | + # Check there is no "argc=can't compute CFA for this frame". | |
1876 | + gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain \\((argc=2,.*)?\\).*" "core main bt" | |
1877 | +} | |
1878 | + | |
1879 | +proc test_attach {file} { | |
1880 | + global board_info | |
1881 | + | |
1882 | + gdb_exit | |
1883 | + | |
1884 | + set test "sleep function started" | |
1885 | + | |
1886 | + set command "${file} sleep" | |
1887 | + set res [remote_spawn host $command]; | |
1888 | + if { $res < 0 || $res == "" } { | |
1889 | + perror "Spawning $command failed." | |
1890 | + fail $test | |
1891 | + return | |
1892 | + } | |
1893 | + set pid [exp_pid -i $res] | |
1894 | + gdb_expect { | |
1895 | + -re "sleeping\r\n" { | |
1896 | + pass $test | |
1897 | + } | |
1898 | + eof { | |
1899 | + fail "$test (eof)" | |
1900 | + return | |
1901 | + } | |
1902 | + timeout { | |
1903 | + fail "$test (timeout)" | |
1904 | + return | |
1905 | + } | |
1906 | + } | |
1907 | + | |
1908 | + gdb_exit | |
1909 | + gdb_start | |
1910 | + gdb_test "attach $pid" "Attaching to process $pid\r\n.*" "attach" | |
1911 | + # Check there is no "argc=can't compute CFA for this frame". | |
1912 | + gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain \\((argc=2,.*)?\\).*" "attach main bt" | |
1913 | + gdb_exit | |
1914 | + | |
1915 | + remote_exec host "kill -9 $pid" | |
1916 | +} | |
1917 | + | |
1918 | +proc test_ld {file ifmain trynosym} { | |
1919 | + global srcdir subdir gdb_prompt | |
1920 | + | |
1921 | + # First test normal `file'-command loaded $FILE with symbols. | |
1922 | + | |
1923 | + gdb_exit | |
1924 | + gdb_start | |
1925 | + # Clear it to never find any separate debug infos in $debug_root. | |
1926 | + gdb_test "set debug-file-directory" | |
1927 | + gdb_reinitialize_dir $srcdir/$subdir | |
1928 | + gdb_load $file | |
1929 | + | |
1930 | + reach "dl_main" "run segv" | |
1931 | + | |
1932 | + gdb_test "bt" "#0 +\[^\r\n\]*\\mdl_main\\M.*" "dl bt" | |
1933 | + | |
1934 | + if $ifmain { | |
1935 | + reach "main" continue | |
1936 | + | |
1937 | + reach "libfunc" continue | |
1938 | + | |
1939 | + # Check there is no "argc=can't compute CFA for this frame". | |
1940 | + gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain \\((argc=2,.*)?\\).*" "main bt" | |
1941 | + | |
1942 | + test_core $file | |
1943 | + | |
1944 | + test_attach $file | |
1945 | + } | |
1946 | + | |
1947 | + if !$trynosym { | |
1948 | + return | |
1949 | + } | |
1950 | + | |
1951 | + global pf_prefix | |
1952 | + set old_ldprefix $pf_prefix | |
1953 | + lappend pf_prefix "symbol-less:" | |
1954 | + | |
1955 | + # Test also `exec-file'-command loaded $FILE - therefore without symbols. | |
1956 | + # SYMBOL_OBJFILE is not available and only EXEC_BFD must be used. | |
1957 | + | |
1958 | + gdb_exit | |
1959 | + gdb_start | |
1960 | + # Clear it to never find any separate debug infos in $debug_root. | |
1961 | + gdb_test "set debug-file-directory" | |
1962 | + gdb_reinitialize_dir $srcdir/$subdir | |
1963 | + | |
1964 | + # Test no (error) message has been printed by `exec-file'. | |
1965 | + set escapedfile [string_to_regexp $file] | |
1966 | + gdb_test "exec-file $file" "exec-file $escapedfile" "load" | |
1967 | + | |
1968 | + if $ifmain { | |
1969 | + reach "dl_main" run | |
1970 | + | |
1971 | + set test "info files" | |
1972 | + set entrynohex "" | |
1973 | + gdb_test_multiple $test $test { | |
1974 | + -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n.*$gdb_prompt $" { | |
1975 | + set entrynohex $expect_out(1,string) | |
1976 | + pass $test | |
1977 | + } | |
1978 | + } | |
1979 | + if {$entrynohex != ""} { | |
1980 | + gdb_test "break *0x$entrynohex" "" "break at entry point" | |
1981 | + gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached" | |
1982 | + } | |
1983 | + } else { | |
1984 | + # There is no symbol to break at ld.so. Moreover it can exit with an | |
1985 | + # error code. | |
1986 | + gdb_test "run" "Program exited (normally|with code \[0-9\]+)\\." "ld.so exit" | |
1987 | + } | |
1988 | + | |
1989 | + set pf_prefix $old_ldprefix | |
1990 | +} | |
1991 | + | |
1992 | +# Create separate binaries for each testcase - to make the possible reported | |
1993 | +# problem reproducible after the whole test run finishes. | |
1994 | + | |
1995 | +set old_ldprefix $pf_prefix | |
1996 | +foreach ldprelink {NO YES} { | |
1997 | + foreach ldsepdebug {NO IN SEP} { | |
1998 | + # Skip running the ldsepdebug test if we do not have system separate | |
1999 | + # debug info available. | |
2000 | + if {$interp_system_debug == "" && $ldsepdebug == "SEP"} { | |
2001 | + continue | |
2002 | + } | |
2003 | + | |
2004 | + set ldname "LDprelink${ldprelink}debug${ldsepdebug}" | |
2005 | + set interp $binprefix-$ldname | |
2006 | + | |
2007 | + # prelink needs to always prelink all the dependencies to do any file | |
2008 | + # modifications of its files. ld.so also needs all the dependencies to | |
2009 | + # be prelinked to omit the relocation process. In-memory file offsets | |
2010 | + # are not dependent whether ld.so went the prelink way or through the | |
2011 | + # relocation process. | |
2012 | + # | |
2013 | + # For GDB we are not interested whether prelink succeeds as it is | |
2014 | + # transparent to GDB. GDB is being tested for differences of file | |
2015 | + # offsets vs. in-memory offsets. So we have to prelink even ld.so for | |
2016 | + # the BIN modification to happen but we need to restore the original | |
2017 | + # possibly unprelinked ld.so to test all the combinations for GDB. | |
2018 | + set interp_saved ${interp}-saved | |
2019 | + | |
2020 | + set pf_prefix $old_ldprefix | |
2021 | + lappend pf_prefix "$ldname:" | |
2022 | + | |
2023 | + if {$ldsepdebug == "NO"} { | |
2024 | + copy $interp_system $interp | |
2025 | + # Never call strip-debug before unprelink: | |
2026 | + # prelink: ...: Section .note.gnu.build-id created after prelinking | |
2027 | + if ![prelinkNO $interp] { | |
2028 | + continue | |
2029 | + } | |
2030 | + strip_debug $interp | |
2031 | + } elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} { | |
2032 | + copy $interp_system $interp | |
2033 | + } elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} { | |
2034 | + copy $interp_system $interp | |
2035 | + copy $interp_system_debug "${interp}.debug" | |
2036 | + # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
2037 | + if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} { | |
2038 | + continue | |
2039 | + } | |
2040 | + set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]" | |
2041 | + set command "exec eu-unstrip -o $interp $interp ${interp}.debug" | |
2042 | + verbose -log "command is $command" | |
2043 | + if [catch $command] { | |
2044 | + setup_xfail *-*-* | |
2045 | + fail $test | |
2046 | + continue | |
2047 | + } else { | |
2048 | + pass $test | |
2049 | + } | |
2050 | + } elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} { | |
2051 | + copy $interp_system $interp | |
2052 | + # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
2053 | + if ![prelinkNO $interp] { | |
2054 | + continue | |
2055 | + } | |
2056 | + gdb_gnu_strip_debug $interp | |
2057 | + } elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} { | |
2058 | + copy $interp_system $interp | |
2059 | + copy $interp_system_debug "${interp}.debug" | |
2060 | + } | |
2061 | + | |
2062 | + if {$ldsepdebug == "SEP"} { | |
2063 | + if ![prelinkNO "${interp}.debug"] { | |
2064 | + continue | |
2065 | + } | |
2066 | + } else { | |
2067 | + file delete "${interp}.debug" | |
2068 | + } | |
2069 | + | |
2070 | + if ![prelink$ldprelink $interp] { | |
2071 | + continue | |
2072 | + } | |
2073 | + test_ld $interp 0 [expr {$ldsepdebug == "NO"}] | |
2074 | + | |
2075 | + if ![copy $interp $interp_saved] { | |
2076 | + continue | |
2077 | + } | |
2078 | + set old_binprefix $pf_prefix | |
2079 | + foreach binprelink {NO YES} { | |
2080 | + foreach binsepdebug {NO IN SEP} { | |
2081 | + foreach binpie {NO YES} { | |
2082 | + # This combination is not possible, non-PIE (fixed address) | |
2083 | + # binary cannot be prelinked to any (other) address. | |
2084 | + if {$binprelink == "YES" && $binpie == "NO"} { | |
2085 | + continue | |
2086 | + } | |
2087 | + | |
2088 | + set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}" | |
2089 | + set exec $binprefix-$binname | |
2090 | + set dir ${exec}.d | |
2091 | + | |
2092 | + set pf_prefix $old_binprefix | |
2093 | + lappend pf_prefix "$binname:" | |
2094 | + | |
2095 | + set opts "additional_flags=-Wl,--dynamic-linker,$interp,-rpath,$dir" | |
2096 | + lappend opts "additional_flags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]" | |
2097 | + if {$binsepdebug != "NO"} { | |
2098 | + lappend opts {debug} | |
2099 | + } | |
2100 | + if {$binpie == "YES"} { | |
2101 | + lappend opts {additional_flags=-fPIE -pie} | |
2102 | + } | |
2103 | + if {[build_executable ${test}.exp [file tail $exec] $srcfile $opts] == -1} { | |
2104 | + continue; | |
2105 | + } | |
2106 | + if {$binsepdebug == "SEP"} { | |
2107 | + gdb_gnu_strip_debug $exec | |
2108 | + # Just a sanity check. As gdb_gnu_strip_debug uses the | |
2109 | + # "[file dirname $exec]/.debug/[file tail $exec].debug" | |
2110 | + # variant delete the higher-priority exec.debug file. | |
2111 | + file delete "$exec.debug" | |
2112 | + } | |
2113 | + | |
2114 | + # Supply a self-sufficent directory $dir with the required | |
2115 | + # libraries. To make an executable properly prelinked all | |
2116 | + # its dependencies on libraries must be also prelinked. If | |
2117 | + # some of the system libraries is currently not prelinked | |
2118 | + # we have no right to prelink (modify it) at its current | |
2119 | + # system place. | |
2120 | + | |
2121 | + file delete -force $dir | |
2122 | + file mkdir $dir | |
2123 | + | |
2124 | + set command "ldd $exec" | |
2125 | + set result [catch "exec $command" output] | |
2126 | + verbose -log "result of $command is $result" | |
2127 | + verbose -log "output of $command is $output" | |
2128 | + if {$result != 0 || $output == ""} { | |
2129 | + fail $command | |
2130 | + } else { | |
2131 | + pass $command | |
2132 | + } | |
2133 | + | |
2134 | + # gdb testsuite will put there also needless -lm. | |
2135 | + set test "$command output contains libc" | |
2136 | + set libc [regexp -all -inline -line {^.* => (/[^ ]+).*$} $output] | |
2137 | + if {[llength $libc] == 0} { | |
2138 | + fail $test | |
2139 | + } else { | |
2140 | + pass $test | |
2141 | + } | |
2142 | + | |
2143 | + set dests {} | |
2144 | + for {set i 1} {$i < [llength $libc]} {incr i 2} { | |
2145 | + set abspath [lindex $libc $i] | |
2146 | + set dest "$dir/[file tail $abspath]" | |
2147 | + copy $abspath $dest | |
2148 | + lappend dests $dest | |
2149 | + } | |
2150 | + | |
2151 | + if {[prelink$binprelink "--dynamic-linker=$interp --ld-library-path=$dir $exec $interp [concat $dests]" $exec] | |
2152 | + && [copy $interp_saved $interp]} { | |
2153 | + test_ld $exec 1 [expr {$binsepdebug == "NO"}] | |
2154 | + } | |
2155 | + } | |
2156 | + } | |
2157 | + } | |
2158 | + | |
2159 | + file delete $interp_saved | |
2160 | + } | |
2161 | +} | |
2162 | +set pf_prefix $old_ldprefix | |
2163 | diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp | |
2164 | index a1003e1..547a898 100644 | |
2165 | --- a/gdb/testsuite/gdb.base/corefile.exp | |
2166 | +++ b/gdb/testsuite/gdb.base/corefile.exp | |
2167 | @@ -42,65 +42,12 @@ if [get_compiler_info ${binfile}] { | |
2168 | return -1; | |
2169 | } | |
2170 | ||
2171 | -# Create a core file named "corefile" rather than just "core", to | |
2172 | -# avoid problems with sys admin types that like to regularly prune all | |
2173 | -# files named "core" from the system. | |
2174 | -# | |
2175 | -# Arbitrarily try setting the core size limit to "unlimited" since | |
2176 | -# this does not hurt on systems where the command does not work and | |
2177 | -# allows us to generate a core on systems where it does. | |
2178 | -# | |
2179 | -# Some systems append "core" to the name of the program; others append | |
2180 | -# the name of the program to "core"; still others (like Linux, as of | |
2181 | -# May 2003) create cores named "core.PID". In the latter case, we | |
2182 | -# could have many core files lying around, and it may be difficult to | |
2183 | -# tell which one is ours, so let's run the program in a subdirectory. | |
2184 | -set found 0 | |
2185 | -set coredir "${objdir}/${subdir}/coredir.[getpid]" | |
2186 | -file mkdir $coredir | |
2187 | -catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\"" | |
2188 | -# remote_exec host "${binfile}" | |
2189 | -foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" { | |
2190 | - if [remote_file build exists $i] { | |
2191 | - remote_exec build "mv $i ${objdir}/${subdir}/corefile" | |
2192 | - set found 1 | |
2193 | - } | |
2194 | -} | |
2195 | -# Check for "core.PID". | |
2196 | -if { $found == 0 } { | |
2197 | - set names [glob -nocomplain -directory $coredir core.*] | |
2198 | - if {[llength $names] == 1} { | |
2199 | - set corefile [file join $coredir [lindex $names 0]] | |
2200 | - remote_exec build "mv $corefile ${objdir}/${subdir}/corefile" | |
2201 | - set found 1 | |
2202 | - } | |
2203 | -} | |
2204 | -if { $found == 0 } { | |
2205 | - # The braindamaged HPUX shell quits after the ulimit -c above | |
2206 | - # without executing ${binfile}. So we try again without the | |
2207 | - # ulimit here if we didn't find a core file above. | |
2208 | - # Oh, I should mention that any "braindamaged" non-Unix system has | |
2209 | - # the same problem. I like the cd bit too, it's really neat'n stuff. | |
2210 | - catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\"" | |
2211 | - foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" { | |
2212 | - if [remote_file build exists $i] { | |
2213 | - remote_exec build "mv $i ${objdir}/${subdir}/corefile" | |
2214 | - set found 1 | |
2215 | - } | |
2216 | - } | |
2217 | +set corefile [core_find $binfile {coremmap.data}] | |
2218 | +if {$corefile == ""} { | |
2219 | + return 0; | |
2220 | } | |
2221 | ||
2222 | -# Try to clean up after ourselves. | |
2223 | -remote_file build delete [file join $coredir coremmap.data] | |
2224 | -remote_exec build "rmdir $coredir" | |
2225 | - | |
2226 | -if { $found == 0 } { | |
2227 | - warning "can't generate a core file - core tests suppressed - check ulimit -c" | |
2228 | - return 0 | |
2229 | -} | |
2230 | - | |
2231 | -# | |
2232 | -# Test that we can simply startup with a "-core=corefile" command line arg | |
2233 | +# Test that we can simply startup with a "-core=$corefile" command line arg | |
2234 | # and recognize that the core file is a valid, usable core file. | |
2235 | # To do this, we must shutdown the currently running gdb and restart | |
2236 | # with the -core args. We can't use gdb_start because it looks for | |
2237 | @@ -114,27 +61,27 @@ if { $found == 0 } { | |
2238 | ||
2239 | gdb_exit | |
2240 | if $verbose>1 then { | |
2241 | - send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$objdir/$subdir/corefile\n" | |
2242 | + send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n" | |
2243 | } | |
2244 | ||
2245 | set oldtimeout $timeout | |
2246 | set timeout [expr "$timeout + 60"] | |
2247 | verbose "Timeout is now $timeout seconds" 2 | |
2248 | -eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$objdir/$subdir/corefile" | |
2249 | +eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile" | |
2250 | expect { | |
2251 | -re "Couldn't find .* registers in core file.*$gdb_prompt $" { | |
2252 | - fail "args: -core=corefile (couldn't find regs)" | |
2253 | + fail "args: -core=[file tail $corefile] (couldn't find regs)" | |
2254 | } | |
2255 | -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { | |
2256 | - pass "args: -core=corefile" | |
2257 | + pass "args: -core=[file tail $corefile]" | |
2258 | } | |
2259 | -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { | |
2260 | - pass "args: -core=corefile (with bad program name)" | |
2261 | + pass "args: -core=[file tail $corefile] (with bad program name)" | |
2262 | } | |
2263 | -re ".*registers from core file: File in wrong format.* $" { | |
2264 | - fail "args: -core=corefile (could not read registers from core file)" | |
2265 | + fail "args: -core=[file tail $corefile] (could not read registers from core file)" | |
2266 | } | |
2267 | - -re ".*$gdb_prompt $" { fail "args: -core=corefile" } | |
2268 | + -re ".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" } | |
2269 | timeout { fail "(timeout) starting with -core" } | |
2270 | } | |
2271 | ||
2272 | @@ -147,22 +94,22 @@ expect { | |
2273 | close; | |
2274 | ||
2275 | if $verbose>1 then { | |
2276 | - send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile\n" | |
2277 | + send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n" | |
2278 | } | |
2279 | ||
2280 | ||
2281 | -eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile"; | |
2282 | +eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile"; | |
2283 | expect { | |
2284 | -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { | |
2285 | - pass "args: execfile -core=corefile" | |
2286 | + pass "args: execfile -core=[file tail $corefile]" | |
2287 | } | |
2288 | -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" { | |
2289 | - pass "args: execfile -core=corefile (with bad program name)" | |
2290 | + pass "args: execfile -core=[file tail $corefile] (with bad program name)" | |
2291 | } | |
2292 | -re ".*registers from core file: File in wrong format.* $" { | |
2293 | - fail "args: execfile -core=corefile (could not read registers from core file)" | |
2294 | + fail "args: execfile -core=[file tail $corefile] (could not read registers from core file)" | |
2295 | } | |
2296 | - -re ".*$gdb_prompt $" { fail "args: execfile -core=corefile" } | |
2297 | + -re ".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" } | |
2298 | timeout { fail "(timeout) starting with -core" } | |
2299 | } | |
2300 | set timeout $oldtimeout | |
2301 | @@ -178,7 +125,7 @@ gdb_load ${binfile} | |
2302 | ||
2303 | # Test basic corefile recognition via core-file command. | |
2304 | ||
2305 | -send_gdb "core-file $objdir/$subdir/corefile\n" | |
2306 | +send_gdb "core-file $corefile\n" | |
2307 | gdb_expect { | |
2308 | -re ".* program is being debugged already.*y or n. $" { | |
2309 | # gdb_load may connect us to a gdbserver. | |
2310 | diff --git a/gdb/testsuite/gdb.base/pie-support.c b/gdb/testsuite/gdb.base/pie-support.c | |
2311 | deleted file mode 100644 | |
2312 | index 63768b9..0000000 | |
2313 | --- a/gdb/testsuite/gdb.base/pie-support.c | |
2314 | +++ /dev/null | |
2315 | @@ -1,34 +0,0 @@ | |
2316 | -/* This testcase is part of GDB, the GNU debugger. | |
2317 | - | |
2318 | - Copyright 2009 Free Software Foundation, Inc. | |
2319 | - | |
2320 | - This program is free software; you can redistribute it and/or modify | |
2321 | - it under the terms of the GNU General Public License as published by | |
2322 | - the Free Software Foundation; either version 3 of the License, or | |
2323 | - (at your option) any later version. | |
2324 | - | |
2325 | - This program is distributed in the hope that it will be useful, | |
2326 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2327 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2328 | - GNU General Public License for more details. | |
2329 | - | |
2330 | - You should have received a copy of the GNU General Public License | |
2331 | - along with this program. If not, see <http://www.gnu.org/licenses/>. | |
2332 | - | |
2333 | -*/ | |
2334 | - | |
2335 | -#include <stdio.h> | |
2336 | - | |
2337 | -void | |
2338 | -f1 (int a) | |
2339 | -{ | |
2340 | - printf ("a = %d\n", a); | |
2341 | -} | |
2342 | - | |
2343 | -int | |
2344 | -main (int argc, char *argv[]) | |
2345 | -{ | |
2346 | - f1 (1); | |
2347 | - | |
2348 | - return 0; | |
2349 | -} | |
2350 | diff --git a/gdb/testsuite/gdb.base/pie-support.exp b/gdb/testsuite/gdb.base/pie-support.exp | |
2351 | deleted file mode 100644 | |
2352 | index 7d118c0..0000000 | |
2353 | --- a/gdb/testsuite/gdb.base/pie-support.exp | |
2354 | +++ /dev/null | |
2355 | @@ -1,58 +0,0 @@ | |
2356 | -# Copyright 2009 Free Software Foundation, Inc. | |
2357 | - | |
2358 | -# This program is free software; you can redistribute it and/or modify | |
2359 | -# it under the terms of the GNU General Public License as published by | |
2360 | -# the Free Software Foundation; either version 3 of the License, or | |
2361 | -# (at your option) any later version. | |
2362 | -# | |
2363 | -# This program is distributed in the hope that it will be useful, | |
2364 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2365 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2366 | -# GNU General Public License for more details. | |
2367 | -# | |
2368 | -# You should have received a copy of the GNU General Public License | |
2369 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
2370 | - | |
2371 | -set testfile pie-support | |
2372 | -set srcfile ${testfile}.c | |
2373 | -set objfile ${objdir}/${subdir}/${testfile}.o | |
2374 | -set binfile ${objdir}/${subdir}/${testfile} | |
2375 | - | |
2376 | -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {quiet debug additional_flags=-fpie}] != "" } { | |
2377 | - untested "Couldn't compile test PIE object file." | |
2378 | - return -1 | |
2379 | -} | |
2380 | -if { [gdb_compile "${objfile}" "${binfile}" executable {quiet debug additional_flags=-pie}] != "" } { | |
2381 | - untested "Couldn't compile test PIE binary." | |
2382 | - return -1 | |
2383 | -} | |
2384 | - | |
2385 | -# Get things started. | |
2386 | - | |
2387 | -gdb_exit | |
2388 | -gdb_start | |
2389 | -gdb_reinitialize_dir $srcdir/$subdir | |
2390 | - | |
2391 | -if [is_remote host] { | |
2392 | - set binfile [remote_download host $binfile] | |
2393 | - if { $binfile == "" } { | |
2394 | - untested "Couldn't download remote test binary." | |
2395 | - return -1 | |
2396 | - } | |
2397 | -} | |
2398 | - | |
2399 | -# The file command used to kill the remote target. For the benefit | |
2400 | -# of the testsuite, preserve this behavior. | |
2401 | -send_gdb "kill\n" | |
2402 | -gdb_expect 120 { | |
2403 | - -re "Kill the program being debugged. .y or n. $" { | |
2404 | - send_gdb "y\n" | |
2405 | - verbose "\t\tKilling previous program being debugged" | |
2406 | - exp_continue | |
2407 | - } | |
2408 | - -re "$gdb_prompt $" { | |
2409 | - # OK. | |
2410 | - } | |
2411 | -} | |
2412 | - | |
2413 | -gdb_test "file $binfile" "current binary is a PIE.*" "correctly detected PIE binary" | |
2414 | diff --git a/gdb/testsuite/gdb.base/valgrind-db-attach.c b/gdb/testsuite/gdb.base/valgrind-db-attach.c | |
2415 | new file mode 100644 | |
2416 | index 0000000..5faaaac | |
2417 | --- /dev/null | |
2418 | +++ b/gdb/testsuite/gdb.base/valgrind-db-attach.c | |
2419 | @@ -0,0 +1,30 @@ | |
2420 | +/* This testcase is part of GDB, the GNU debugger. | |
2421 | + | |
2422 | + Copyright 2009 Free Software Foundation, Inc. | |
2423 | + | |
2424 | + This program is free software; you can redistribute it and/or modify | |
2425 | + it under the terms of the GNU General Public License as published by | |
2426 | + the Free Software Foundation; either version 3 of the License, or | |
2427 | + (at your option) any later version. | |
2428 | + | |
2429 | + This program is distributed in the hope that it will be useful, | |
2430 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2431 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2432 | + GNU General Public License for more details. | |
2433 | + | |
2434 | + You should have received a copy of the GNU General Public License | |
2435 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
2436 | + | |
2437 | +#include <stdlib.h> | |
2438 | + | |
2439 | +int main() | |
2440 | +{ | |
2441 | + void *p; | |
2442 | + | |
2443 | + p = malloc (1); | |
2444 | + if (p == NULL) | |
2445 | + return 1; | |
2446 | + free (p); | |
2447 | + free (p); /* double-free */ | |
2448 | + return 0; | |
2449 | +} | |
2450 | diff --git a/gdb/testsuite/gdb.base/valgrind-db-attach.exp b/gdb/testsuite/gdb.base/valgrind-db-attach.exp | |
2451 | new file mode 100644 | |
2452 | index 0000000..ac06fd3 | |
2453 | --- /dev/null | |
2454 | +++ b/gdb/testsuite/gdb.base/valgrind-db-attach.exp | |
2455 | @@ -0,0 +1,74 @@ | |
2456 | +# Copyright 2009 Free Software Foundation, Inc. | |
2457 | + | |
2458 | +# This program is free software; you can redistribute it and/or modify | |
2459 | +# it under the terms of the GNU General Public License as published by | |
2460 | +# the Free Software Foundation; either version 3 of the License, or | |
2461 | +# (at your option) any later version. | |
2462 | +# | |
2463 | +# This program is distributed in the hope that it will be useful, | |
2464 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2465 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2466 | +# GNU General Public License for more details. | |
2467 | +# | |
2468 | +# You should have received a copy of the GNU General Public License | |
2469 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
2470 | + | |
2471 | +set test valgrind-db-attach | |
2472 | +set srcfile $test.c | |
2473 | +set executable $test | |
2474 | +set binfile ${objdir}/${subdir}/${executable} | |
2475 | +if {[build_executable $test.exp $executable $srcfile {debug}] == -1} { | |
2476 | + return -1 | |
2477 | +} | |
2478 | + | |
2479 | +gdb_exit | |
2480 | + | |
2481 | +# remote_spawn breaks the command on each whitespace despite possible quoting. | |
2482 | +# Use backslash-escaped whitespace there instead: | |
2483 | + | |
2484 | +set db_command "--db-command=$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts] %f %p" | |
2485 | +regsub -all " " $db_command "\\ " db_command | |
2486 | + | |
2487 | +set test "spawn valgrind" | |
2488 | +set cmd "valgrind --db-attach=yes $db_command $binfile" | |
2489 | +set res [remote_spawn host $cmd]; | |
2490 | +if { $res < 0 || $res == "" } { | |
2491 | + verbose -log "Spawning $cmd failed." | |
2492 | + setup_xfail *-*-* | |
2493 | + fail $test | |
2494 | + return -1 | |
2495 | +} | |
2496 | +pass $test | |
2497 | +# Declare GDB now as running. | |
2498 | +set gdb_spawn_id -1 | |
2499 | + | |
2500 | +set test "valgrind started" | |
2501 | +# The trailing '.' differs for different memcheck versions. | |
2502 | +gdb_test_multiple "" $test { | |
2503 | + -re "Memcheck, a memory error detector\\.?\r\n" { | |
2504 | + pass $test | |
2505 | + } | |
2506 | + -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" { | |
2507 | + setup_xfail *-*-* | |
2508 | + fail $test | |
2509 | + return -1 | |
2510 | + } | |
2511 | +} | |
2512 | + | |
2513 | +set double_free [gdb_get_line_number "double-free"] | |
2514 | + | |
2515 | +gdb_test_multiple "" $test { | |
2516 | + -re "Invalid free\\(\\) / delete / delete\\\[\\\]\r\n.*: main \\(${srcfile}:$double_free\\)\r\n.*---- Attach to debugger \\? --- \[^\r\n\]* ---- " { | |
2517 | + send_gdb "y\r" | |
2518 | + } | |
2519 | + -re "---- Attach to debugger \\? --- \[^\r\n\]* ---- " { | |
2520 | + send_gdb "n\r" | |
2521 | + exp_continue | |
2522 | + } | |
2523 | +} | |
2524 | + | |
2525 | +# Initialization from default_gdb_start. | |
2526 | +gdb_test "set height 0" | |
2527 | +gdb_test "set width 0" | |
2528 | + | |
2529 | +gdb_test "bt" "in main \\(.*\\) at .*${srcfile}:$double_free" | |
2530 | diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges.exp | |
2531 | index 61e1fe4..9109030 100644 | |
2532 | --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges.exp | |
2533 | +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges.exp | |
2534 | @@ -55,6 +55,12 @@ gdb_start | |
2535 | gdb_reinitialize_dir $srcdir/$subdir | |
2536 | gdb_load ${binfile} | |
2537 | ||
2538 | +# Test also objfile->psymtabs_addrmap relocations for -fPIE -pie builds below. | |
2539 | +# On some targets it may possibly fail but the program is being started only | |
2540 | +# for the PIE build so try it anyway. | |
2541 | + | |
2542 | +runto_main | |
2543 | + | |
2544 | # Correct output: | |
2545 | # Line 39 of "../.././gdb/testsuite/gdb.dwarf2/dw2-ranges.S" starts at address 0x4 and ends at 0x8. | |
2546 | # Wrong output: | |
2547 | diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp | |
2548 | index d0c3493..fbf9124 100644 | |
2549 | --- a/gdb/testsuite/lib/gdb.exp | |
2550 | +++ b/gdb/testsuite/lib/gdb.exp | |
2551 | @@ -2778,6 +2778,11 @@ proc gdb_gnu_strip_debug { dest args } { | |
2552 | return 1 | |
2553 | } | |
2554 | ||
2555 | + # Workaround PR binutils/10802: | |
2556 | + # Preserve the 'x' bit also for PIEs (Position Independent Executables). | |
2557 | + set perm [file attributes ${dest} -permissions] | |
2558 | + file attributes ${stripped_file} -permissions $perm | |
2559 | + | |
2560 | # Get rid of everything but the debug info, and store result in debug_file | |
2561 | # This will be in the .debug subdirectory, see above. | |
2562 | set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output] | |
2563 | @@ -2814,7 +2819,12 @@ proc gdb_gnu_strip_debug { dest args } { | |
2564 | return 1 | |
2565 | } | |
2566 | ||
2567 | - return 0 | |
2568 | + # Workaround PR binutils/10802: | |
2569 | + # Preserve the 'x' bit also for PIEs (Position Independent Executables). | |
2570 | + set perm [file attributes ${stripped_file} -permissions] | |
2571 | + file attributes ${dest} -permissions $perm | |
2572 | + | |
2573 | + return 0 | |
2574 | } | |
2575 | ||
2576 | # Test the output of GDB_COMMAND matches the pattern obtained | |
2577 | @@ -3043,3 +3053,70 @@ if {[info exists TRANSCRIPT]} { | |
2578 | return [uplevel real_send_gdb $args] | |
2579 | } | |
2580 | } | |
2581 | + | |
2582 | +proc core_find {binfile {deletefiles {}} {arg ""}} { | |
2583 | + global objdir subdir | |
2584 | + | |
2585 | + set destcore "$binfile.core" | |
2586 | + file delete $destcore | |
2587 | + | |
2588 | + # Create a core file named "$destcore" rather than just "core", to | |
2589 | + # avoid problems with sys admin types that like to regularly prune all | |
2590 | + # files named "core" from the system. | |
2591 | + # | |
2592 | + # Arbitrarily try setting the core size limit to "unlimited" since | |
2593 | + # this does not hurt on systems where the command does not work and | |
2594 | + # allows us to generate a core on systems where it does. | |
2595 | + # | |
2596 | + # Some systems append "core" to the name of the program; others append | |
2597 | + # the name of the program to "core"; still others (like Linux, as of | |
2598 | + # May 2003) create cores named "core.PID". In the latter case, we | |
2599 | + # could have many core files lying around, and it may be difficult to | |
2600 | + # tell which one is ours, so let's run the program in a subdirectory. | |
2601 | + set found 0 | |
2602 | + set coredir "${objdir}/${subdir}/coredir.[getpid]" | |
2603 | + file mkdir $coredir | |
2604 | + catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\"" | |
2605 | + # remote_exec host "${binfile}" | |
2606 | + foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" { | |
2607 | + if [remote_file build exists $i] { | |
2608 | + remote_exec build "mv $i $destcore" | |
2609 | + set found 1 | |
2610 | + } | |
2611 | + } | |
2612 | + # Check for "core.PID". | |
2613 | + if { $found == 0 } { | |
2614 | + set names [glob -nocomplain -directory $coredir core.*] | |
2615 | + if {[llength $names] == 1} { | |
2616 | + set corefile [file join $coredir [lindex $names 0]] | |
2617 | + remote_exec build "mv $corefile $destcore" | |
2618 | + set found 1 | |
2619 | + } | |
2620 | + } | |
2621 | + if { $found == 0 } { | |
2622 | + # The braindamaged HPUX shell quits after the ulimit -c above | |
2623 | + # without executing ${binfile}. So we try again without the | |
2624 | + # ulimit here if we didn't find a core file above. | |
2625 | + # Oh, I should mention that any "braindamaged" non-Unix system has | |
2626 | + # the same problem. I like the cd bit too, it's really neat'n stuff. | |
2627 | + catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\"" | |
2628 | + foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" { | |
2629 | + if [remote_file build exists $i] { | |
2630 | + remote_exec build "mv $i $destcore" | |
2631 | + set found 1 | |
2632 | + } | |
2633 | + } | |
2634 | + } | |
2635 | + | |
2636 | + # Try to clean up after ourselves. | |
2637 | + foreach deletefile $deletefiles { | |
2638 | + remote_file build delete [file join $coredir $deletefile] | |
2639 | + } | |
2640 | + remote_exec build "rmdir $coredir" | |
2641 | + | |
2642 | + if { $found == 0 } { | |
2643 | + warning "can't generate a core file - core tests suppressed - check ulimit -c" | |
2644 | + return "" | |
2645 | + } | |
2646 | + return $destcore | |
2647 | +} |