1 http://sourceware.org/gdb/wiki/ProjectArcher
2 http://sourceware.org/gdb/wiki/ArcherBranchManagement
4 archer-jankratochvil-pie-fedora12
6 commit 2ae60b5156d43aabfe5757940eaf7b4370fb05d2
9 diff --git a/gdb/auxv.c b/gdb/auxv.c
10 index 7b4ecbe..7df8eb5 100644
16 #include "gdb_assert.h"
20 #include "elf/common.h"
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. */
32 -procfs_xfer_auxv (struct target_ops *ops,
33 - enum target_object object,
37 +procfs_xfer_auxv (gdb_byte *readbuf,
38 const gdb_byte *writebuf,
41 @@ -50,9 +47,6 @@ procfs_xfer_auxv (struct target_ops *ops,
45 - gdb_assert (object == TARGET_OBJECT_AUXV);
46 - gdb_assert (readbuf || writebuf);
48 pathname = xstrprintf ("/proc/%d/auxv", PIDGET (inferior_ptid));
49 fd = open (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY);
51 @@ -72,6 +66,152 @@ procfs_xfer_auxv (struct target_ops *ops,
55 +/* This function handles access via ld.so's symbol `_dl_auxv'. */
58 +ld_so_xfer_auxv (gdb_byte *readbuf,
59 + const gdb_byte *writebuf,
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);
72 + msym = lookup_minimal_symbol ("_dl_auxv", NULL, NULL);
76 + if (MSYMBOL_SIZE (msym) != ptr_size)
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. */
83 + pointer_address = SYMBOL_VALUE_ADDRESS (msym);
85 + data_address = read_memory_typed_address (pointer_address, ptr_type);
87 + /* Possibly still not initialized such as during an inferior startup. */
88 + if (data_address == 0)
91 + data_address += offset;
93 + if (writebuf != NULL)
95 + if (target_write_memory (data_address, writebuf, len) == 0)
101 + /* Stop if trying to read past the existing AUXV block. The final AT_NULL
102 + was already returned before. */
104 + if (offset >= auxv_pair_size)
106 + if (target_read_memory (data_address - auxv_pair_size, ptr_buf,
110 + if (extract_typed_address (ptr_buf, ptr_type) == AT_NULL)
116 + gdb_assert (block % auxv_pair_size == 0);
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). */
127 + block &= -auxv_pair_size;
131 + if (target_read_memory (data_address, readbuf, block) != 0)
133 + if (block <= auxv_pair_size)
136 + block = auxv_pair_size;
140 + data_address += block;
143 + /* Check terminal AT_NULL. This function is being called indefinitely
144 + being extended its READBUF until it returns EOF (0). */
146 + while (block >= auxv_pair_size)
148 + retval += auxv_pair_size;
150 + if (extract_typed_address (readbuf, ptr_type) == AT_NULL)
153 + readbuf += auxv_pair_size;
154 + block -= auxv_pair_size;
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. */
165 +memory_xfer_auxv (struct target_ops *ops,
166 + enum target_object object,
169 + const gdb_byte *writebuf,
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));
182 + gdb_assert (object == TARGET_OBJECT_AUXV);
183 + gdb_assert (readbuf || writebuf);
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. */
189 + if (inf == NULL || inf->attach_flag != 0)
193 + retval = ld_so_xfer_auxv (readbuf, writebuf, offset, len);
198 + return procfs_xfer_auxv (readbuf, writebuf, offset, len);
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
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);
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. */
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,
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
234 && PC_SOLIB (loc->address)
235 diff --git a/gdb/defs.h b/gdb/defs.h
236 index 94674dc..57aaae2 100644
240 /* A byte from the program being debugged. */
241 typedef bfd_byte gdb_byte;
243 -/* An address in the program being debugged. Host byte order. */
244 +/* An address in the program being debugged. Host byte order.
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).
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. */
258 typedef bfd_vma CORE_ADDR;
260 /* The largest CORE_ADDR value. */
261 diff --git a/gdb/exec.c b/gdb/exec.c
262 index 455151e..67f40d9 100644
265 @@ -656,8 +656,33 @@ print_section_info (struct target_section_table *t, bfd *abfd)
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)));
272 + bfd_vma displacement = 0;
274 + for (p = t->sections; p < t->sections_end; p++)
276 + asection *asect = p->the_bfd_section;
278 + if ((bfd_get_section_flags (abfd, asect) & (SEC_ALLOC | SEC_LOAD))
279 + != (SEC_ALLOC | SEC_LOAD))
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))
286 + displacement = p->addr - bfd_get_section_vma (abfd, asect);
290 + if (p == t->sections_end)
291 + warning (_("Cannot find section for the entry point of %s.\n"),
292 + bfd_get_filename (abfd));
294 + printf_filtered (_("\tEntry point: %s\n"),
295 + paddress (gdbarch, bfd_get_start_address (abfd)
298 for (p = t->sections; p < t->sections_end; p++)
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
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 ());
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))
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. */
319 - SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
321 - solib_add (NULL, from_tty, target, auto_solib_add);
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));
332 - solib_create_inferior_hook ();
333 + solib_create_inferior_hook (from_tty);
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))
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. */
349 + SOLIB_ADD (NULL, 0, target, auto_solib_add);
351 + solib_add (NULL, 0, target, auto_solib_add);
355 diff --git a/gdb/infrun.c b/gdb/infrun.c
356 index 9d29b15..ed451d5 100644
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));
363 - solib_create_inferior_hook ();
364 + solib_create_inferior_hook (0);
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,
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,
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
386 along with this program. If not, see <http://www.gnu.org/licenses/>. */
389 -#include "gdbcore.h"
390 #include "gdbtypes.h"
391 #include "linux-tdep.h"
392 -#include "observer.h"
394 -#include "elf-bfd.h"
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)
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. */
408 -check_is_pie_binary (void)
410 - Elf_Internal_Ehdr *elf_hdr;
414 - else if (bfd_get_flavour (exec_bfd) != bfd_target_elf_flavour)
417 - if (elf_tdata (exec_bfd)->elf_header->e_type == ET_DYN)
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"));
425 -_initialize_linux_tdep (void)
427 - observer_attach_executable_changed (check_is_pie_binary);
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)
437 - solib_create_inferior_hook ();
438 + solib_create_inferior_hook (0);
442 @@ -1212,7 +1212,7 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file,
445 || (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
446 - solib_create_inferior_hook ();
447 + solib_create_inferior_hook (0);
451 diff --git a/gdb/objfiles.c b/gdb/objfiles.c
452 index e5442ca..fb0cea9 100644
455 @@ -544,9 +544,10 @@ free_all_objfiles (void)
458 /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
459 - entries in new_offsets. */
461 -objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
462 + entries in new_offsets. SEPARATE_DEBUG_OBJFILE is not touched here. */
465 +objfile_relocate1 (struct objfile *objfile, struct section_offsets *new_offsets)
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)
473 + if (objfile->psymtabs_addrmap)
474 + addrmap_relocate (objfile->psymtabs_addrmap,
475 + ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
478 struct partial_symtab *p;
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));
486 +/* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
487 + entries in new_offsets. Process also OBJFILE's SEPARATE_DEBUG_OBJFILE.
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
496 +objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
498 + objfile_relocate1 (objfile, new_offsets);
500 + if (objfile->separate_debug_objfile != NULL)
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;
508 + objfile_addrs = build_section_addr_info_from_objfile (objfile);
509 + my_cleanups = make_cleanup (xfree, objfile_addrs);
511 + /* Here OBJFILE_ADDRS contain the correct absolute addresses, the
512 + relative ones must be already created according to debug_objfile. */
514 + addr_info_make_relative (objfile_addrs, debug_objfile->obfd);
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,
523 + do_cleanups (my_cleanups);
525 + objfile_relocate1 (debug_objfile, new_debug_offsets);
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
534 @@ -4376,7 +4376,7 @@ procfs_xfer_partial (struct target_ops *ops, enum target_object object,
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,
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)
549 /* Shared library startup support. See documentation in solib-svr4.c */
551 -darwin_solib_create_inferior_hook (void)
552 +darwin_solib_create_inferior_hook (int from_tty)
554 struct minimal_symbol *msymbol;
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)
564 -frv_solib_create_inferior_hook (void)
565 +frv_solib_create_inferior_hook (int from_tty)
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)
577 - void solib_create_inferior_hook ()
578 + void solib_create_inferior_hook (int from_tty)
582 @@ -431,7 +431,7 @@ enable_break (void)
586 -irix_solib_create_inferior_hook (void)
587 +irix_solib_create_inferior_hook (int from_tty)
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)
599 -null_solib_create_inferior_hook (void)
600 +null_solib_create_inferior_hook (int from_tty)
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. */
612 -osf_solib_create_inferior_hook (void)
613 +osf_solib_create_inferior_hook (int from_tty)
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. */
625 -pa64_solib_create_inferior_hook (void)
626 +pa64_solib_create_inferior_hook (int from_tty)
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. */
638 -som_solib_create_inferior_hook (void)
639 +som_solib_create_inferior_hook (int from_tty)
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
649 spu_relocate_main_executable (int spufs_fd)
651 - struct objfile *objfile;
652 - struct cleanup *old_chain;
653 struct section_offsets *new_offsets;
656 - for (objfile = symfile_objfile;
658 - objfile = objfile->separate_debug_objfile)
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)
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));
671 - objfile_relocate (objfile, new_offsets);
672 - do_cleanups (old_chain);
674 + for (i = 0; i < symfile_objfile->num_sections; i++)
675 + new_offsets->offsets[i] = SPUADDR (spufs_fd, 0);
677 + objfile_relocate (symfile_objfile, new_offsets);
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)
683 /* Create inferior hook. */
685 -spu_solib_create_inferior_hook (void)
686 +spu_solib_create_inferior_hook (int from_tty)
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)
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);
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)
707 -sunos_solib_create_inferior_hook (void)
708 +sunos_solib_create_inferior_hook (int from_tty)
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
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);
722 /* Link map info to include in an allocated so_list entry */
724 @@ -599,11 +600,12 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
726 int arch_size, step, sect_size;
728 - CORE_ADDR dyn_ptr, dyn_addr;
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;
738 @@ -619,7 +621,13 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
739 sect = bfd_get_section_by_name (abfd, ".dynamic");
742 - dyn_addr = bfd_section_vma (abfd, sect);
744 + for (target_section = target_get_section_table (&exec_ops)->sections;
745 + target_section < target_get_section_table (&exec_ops)->sections_end;
747 + if (sect == target_section->the_bfd_section)
749 + gdb_assert (target_section < target_get_section_table (&exec_ops)->sections_end);
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)
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);
762 @@ -1258,7 +1266,7 @@ exec_entry_point (struct bfd *abfd, struct target_ops *targ)
766 -enable_break (struct svr4_info *info)
767 +enable_break (struct svr4_info *info, int from_tty)
769 struct minimal_symbol *msymbol;
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. */
775 - solib_add (NULL, 0, ¤t_target, auto_solib_add);
776 + solib_add (NULL, from_tty, ¤t_target, auto_solib_add);
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)
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;
787 + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
788 + mask = ((CORE_ADDR) 1 << addr_bit) - 1;
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);
800 /* Record the relocated start and end address of the dynamic linker
801 @@ -1414,16 +1427,20 @@ enable_break (struct svr4_info *info)
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;
810 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
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;
821 /* Now try to set a breakpoint in the dynamic linker. */
822 @@ -1448,7 +1465,7 @@ enable_break (struct svr4_info *info)
826 - create_solib_event_breakpoint (target_gdbarch, load_addr + sym_addr);
827 + create_solib_event_breakpoint (target_gdbarch, (load_addr + sym_addr) & mask);
831 @@ -1517,113 +1534,131 @@ enable_break (struct svr4_info *info)
833 svr4_special_symbol_handling (void)
835 + svr4_relocate_main_executable ();
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.
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().
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
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. ]
881 -svr4_relocate_main_executable (void)
883 +svr4_static_exec_displacement (void)
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);
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.
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().
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
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. ]
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);
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:
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.
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. */
955 +svr4_exec_displacement (void)
958 + CORE_ADDR entry_point;
960 + if (exec_bfd == NULL)
963 + if (target_auxv_search (¤t_target, AT_ENTRY, &entry_point) == 1)
964 + return entry_point - exec_entry_point (exec_bfd, ¤t_target);
966 + return svr4_static_exec_displacement ();
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. */
975 +svr4_relocate_main_executable (void)
977 + CORE_ADDR displacement = svr4_exec_displacement ();
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. */
983 + if (symfile_objfile)
985 - struct cleanup *old_chain;
986 struct section_offsets *new_offsets;
988 - CORE_ADDR displacement;
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.
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:
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.
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. */
1015 - displacement = pc - exec_entry_point (exec_bfd, &exec_ops);
1018 - new_offsets = xcalloc (symfile_objfile->num_sections,
1019 - sizeof (struct section_offsets));
1020 - old_chain = make_cleanup (xfree, new_offsets);
1023 + new_offsets = alloca (symfile_objfile->num_sections
1024 + * sizeof (*new_offsets));
1026 for (i = 0; i < symfile_objfile->num_sections; i++)
1028 - if (displacement != ANOFFSET (symfile_objfile->section_offsets, i))
1030 - new_offsets->offsets[i] = displacement;
1032 + new_offsets->offsets[i] = displacement;
1035 - objfile_relocate (symfile_objfile, new_offsets);
1036 + objfile_relocate (symfile_objfile, new_offsets);
1038 + else if (exec_bfd)
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)
1050 @@ -1635,7 +1670,7 @@ svr4_relocate_main_executable (void)
1054 - void svr4_solib_create_inferior_hook ()
1055 + void svr4_solib_create_inferior_hook (int from_tty)
1059 @@ -1680,7 +1715,7 @@ svr4_relocate_main_executable (void)
1063 -svr4_solib_create_inferior_hook (void)
1064 +svr4_solib_create_inferior_hook (int from_tty)
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));
1071 /* Relocate the main executable if necessary. */
1072 - svr4_relocate_main_executable ();
1073 + if (current_inferior ()->attach_flag == 0)
1074 + svr4_relocate_main_executable ();
1076 if (!svr4_have_link_map_offsets ())
1079 - if (!enable_break (info))
1080 + if (!enable_break (info, from_tty))
1083 #if defined(_SCO_DS)
1084 @@ -1910,8 +1946,19 @@ elf_lookup_lib_symbol (const struct objfile *objfile,
1086 const domain_enum domain)
1088 - if (objfile->obfd == NULL
1089 - || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
1092 + if (objfile == symfile_objfile)
1096 + /* OBJFILE should have been passed as the non-debug one. */
1097 + gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
1099 + abfd = objfile->obfd;
1102 + if (abfd == NULL || scan_dyntag (DT_SYMBOLIC, abfd, NULL) != 1)
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)
1114 -solib_target_solib_create_inferior_hook (void)
1115 +solib_target_solib_create_inferior_hook (int from_tty)
1117 /* Nothing needed. */
1119 diff --git a/gdb/solib.c b/gdb/solib.c
1120 index 3574e62..7ea3663 100644
1123 @@ -998,7 +998,7 @@ clear_solib (void)
1127 - void solib_create_inferior_hook ()
1128 + void solib_create_inferior_hook (int from_tty)
1132 @@ -1008,10 +1008,10 @@ clear_solib (void)
1133 SOLIB_CREATE_INFERIOR_HOOK. */
1136 -solib_create_inferior_hook (void)
1137 +solib_create_inferior_hook (int from_tty)
1139 struct target_so_ops *ops = solib_ops (target_gdbarch);
1140 - ops->solib_create_inferior_hook();
1141 + ops->solib_create_inferior_hook (from_tty);
1145 @@ -1087,7 +1087,6 @@ reload_shared_libraries (char *ignored, int from_tty,
1146 struct cmd_list_element *e)
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));
1157 - solib_create_inferior_hook ();
1158 + solib_create_inferior_hook (from_tty);
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. */
1169 + solib_add (NULL, 0, NULL, auto_solib_add);
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
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. */
1182 -extern void solib_create_inferior_hook (void);
1183 +extern void solib_create_inferior_hook (int from_tty);
1185 /* If ADDR lies in a shared library, return its name. */
1187 diff --git a/gdb/solist.h b/gdb/solist.h
1188 index 005e8f7..9724fe7 100644
1191 @@ -87,7 +87,7 @@ struct target_so_ops
1192 void (*clear_solib) (void);
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);
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
1204 @@ -536,40 +536,151 @@ place_section (bfd *abfd, asection *sect, void *obj)
1205 arg->lowest = start_addr + bfd_get_section_size (sect);
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. */
1216 +struct section_addr_info *
1217 +build_section_addr_info_from_objfile (struct objfile *objfile)
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;
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);
1231 + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
1232 + mask = ((CORE_ADDR) 1 << addr_bit) - 1;
1234 + for (p = sections; p < sections_end; p++)
1236 + CORE_ADDR baseaddr;
1238 + gdb_assert (p->the_bfd_section->index < objfile->num_sections);
1239 + baseaddr = ANOFFSET (objfile->section_offsets,
1240 + p->the_bfd_section->index);
1242 + p->addr = (p->addr + baseaddr) & mask;
1243 + p->endaddr = (p->endaddr + baseaddr) & mask;
1246 + retval = build_section_addr_info_from_section_table (sections, sections_end);
1248 + do_cleanups (my_cleanups);
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
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,
1262 + struct section_addr_info *addrs)
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));
1274 - /* Now calculate offsets for section that were specified by the
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++)
1279 - struct other_sections *osp ;
1280 + struct other_sections *osp;
1282 - osp = &addrs->other[i] ;
1283 + osp = &addrs->other[i];
1287 /* Record all sections in offsets */
1288 /* The section_offsets in the objfile are here filled in using
1290 - (objfile->section_offsets)->offsets[osp->sectindex] = osp->addr;
1291 + section_offsets->offsets[osp->sectindex] = osp->addr;
1295 +/* Relativize absolute addresses in ADDRS into offsets based on ABFD. Fill-in
1296 + also SECTINDEXes there. */
1299 +addr_info_make_relative (struct section_addr_info *addrs, bfd *abfd)
1301 + asection *lower_sect;
1303 + CORE_ADDR lower_offset;
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)
1314 + warning (_("no loadable sections found in added symbol-file %s"),
1315 + bfd_get_filename (abfd));
1319 + lower_offset = bfd_section_vma (bfd_get_filename (abfd), lower_sect);
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!!!
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 */
1331 + for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
1333 + if (addrs->other[i].addr != 0)
1335 + sect = bfd_get_section_by_name (abfd, addrs->other[i].name);
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;
1345 + warning (_("section %s not found in %s"), addrs->other[i].name,
1346 + bfd_get_filename (abfd));
1347 + addrs->other[i].addr = 0;
1351 + addrs->other[i].addr = lower_offset;
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. */
1362 +default_symfile_offsets (struct objfile *objfile,
1363 + struct section_addr_info *addrs)
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);
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,
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)
1380 - asection *lower_sect;
1382 - CORE_ADDR lower_offset;
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,
1392 - if (lower_sect == NULL)
1394 - warning (_("no loadable sections found in added symbol-file %s"),
1399 - lower_offset = bfd_section_vma (objfile->obfd, lower_sect);
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!!!
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 */
1411 - for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
1413 - if (addrs->other[i].addr != 0)
1415 - sect = bfd_get_section_by_name (objfile->obfd,
1416 - addrs->other[i].name);
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 ;
1427 - warning (_("section %s not found in %s"),
1428 - addrs->other[i].name,
1430 - addrs->other[i].addr = 0;
1434 - addrs->other[i].addr = lower_offset;
1437 + if (addrs && addrs->other[0].name)
1438 + addr_info_make_relative (addrs, objfile->obfd);
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);
1456 - orig_addrs = copy_section_addr_info (addrs);
1457 - make_cleanup_free_section_addr_info (orig_addrs);
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);
1470 - if (addrs != NULL)
1472 - objfile->separate_debug_objfile
1473 - = symbol_file_add (debugfile, add_flags, orig_addrs, flags);
1477 - objfile->separate_debug_objfile
1478 - = symbol_file_add (debugfile, add_flags, NULL, flags);
1480 + struct section_addr_info *objfile_addrs;
1482 + objfile_addrs = build_section_addr_info_from_objfile (objfile);
1483 + make_cleanup (xfree, objfile_addrs);
1485 + objfile->separate_debug_objfile = symbol_file_add (debugfile, add_flags,
1486 + objfile_addrs, flags);
1488 objfile->separate_debug_objfile->separate_debug_objfile_backlink
1491 diff --git a/gdb/symfile.h b/gdb/symfile.h
1492 index bf9d9e7..bff6bd8 100644
1495 @@ -181,6 +181,16 @@ struct sym_fns
1499 +extern struct section_addr_info *
1500 + build_section_addr_info_from_objfile (struct objfile *objfile);
1502 +extern void relative_addr_info_to_section_offsets
1503 + (struct section_offsets *section_offsets, int num_sections,
1504 + struct section_addr_info *addrs);
1506 +extern void addr_info_make_relative (struct section_addr_info *addrs,
1509 /* The default version of sym_fns.sym_offsets for readers that don't
1510 do anything special. */
1512 diff --git a/gdb/symtab.c b/gdb/symtab.c
1513 index 82e0163..01117e3 100644
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))
1522 + if (obj->separate_debug_objfile_backlink)
1523 + obj = obj->separate_debug_objfile_backlink;
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
1534 +++ b/gdb/testsuite/gdb.base/break-interp-lib.c
1536 +/* This testcase is part of GDB, the GNU debugger.
1538 + Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
1553 +#include <signal.h>
1554 +#include <unistd.h>
1555 +#include <assert.h>
1559 +libfunc (const char *action)
1561 + assert (action != NULL);
1563 + if (strcmp (action, "segv") == 0)
1566 + if (strcmp (action, "sleep") == 0)
1568 + puts ("sleeping");
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
1580 +++ b/gdb/testsuite/gdb.base/break-interp-main.c
1582 +/* This testcase is part of GDB, the GNU debugger.
1584 + Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
1599 +#include <assert.h>
1601 +extern void libfunc (const char *action);
1604 +main (int argc, char **argv)
1606 + assert (argc == 2);
1608 + libfunc (argv[1]);
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
1616 +++ b/gdb/testsuite/gdb.base/break-interp.exp
1618 +# Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>.
1633 +# This test only works on GNU/Linux.
1634 +if { ![isnative] || [is_remote host] || ![istarget *-linux*] || [skip_shlib_tests]} {
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"
1647 +if [get_compiler_info ${binfile_lib}] {
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.
1654 +if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug additional_flags=-Wl,-soname,${test}.so]] != ""} {
1658 +if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} {
1662 +# Return the interpreter filename string.
1663 +# Return "" if no interpreter was found.
1664 +proc section_get {exec section} {
1667 + set tmp "${objdir}/${subdir}/break-interp.interp"
1668 + set objcopy_program [transform objcopy]
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} {
1678 + set fi [open $tmp]
1679 + fconfigure $fi -translation binary
1680 + set data [read $fi]
1683 + # .interp has size $len + 1 but .gnu_debuglink contains garbage after \000.
1684 + set len [string first \000 $data]
1686 + verbose -log "section $section not found"
1689 + set retval [string range $data 0 [expr $len - 1]]
1690 + verbose -log "section $section is <$retval>"
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} {
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]
1703 + # isfile returns 1 even for symlinks to files.
1704 + set retval $debug_root/$exec_build_id_debug
1705 + if [file isfile $retval] {
1708 + set retval $exec_dir/$debug_base
1709 + if [file isfile $retval] {
1712 + set retval $exec_dir/.debug/$debug_base
1713 + if [file isfile $retval] {
1716 + set retval $debug_root/$exec_dir/$debug_base
1717 + if [file isfile $retval] {
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)
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"
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]
1746 +proc prelinkNO {arg {name {}}} {
1747 + if {$name == ""} {
1748 + set name [file tail $arg]
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]
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]} {
1770 +proc prelinkYES {arg {name ""}} {
1771 + if {$name == ""} {
1772 + set name [file tail $arg]
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 == ""} {
1789 +# Resolve symlinks.
1790 +proc symlink_resolve {file} {
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
1799 + verbose -log "Resolved symlink $file targetting $target as $src2"
1802 + set loop [expr $loop + 1]
1804 + fail "Looping symlink resolution for $file"
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] {
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] {
1840 +# `runto' does not check we stopped really at the function we specified.
1841 +proc reach {func command} {
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 $" {
1850 + -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in $func \\(\\)( from .*)?\r\n$gdb_prompt $" {
1857 +proc test_core {file} {
1858 + global srcdir subdir gdb_prompt
1860 + set corefile [core_find $file {} "segv"]
1861 + if {$corefile == ""} {
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
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"
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"
1879 +proc test_attach {file} {
1884 + set test "sleep function started"
1886 + set command "${file} sleep"
1887 + set res [remote_spawn host $command];
1888 + if { $res < 0 || $res == "" } {
1889 + perror "Spawning $command failed."
1893 + set pid [exp_pid -i $res]
1895 + -re "sleeping\r\n" {
1899 + fail "$test (eof)"
1903 + fail "$test (timeout)"
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"
1915 + remote_exec host "kill -9 $pid"
1918 +proc test_ld {file ifmain trynosym} {
1919 + global srcdir subdir gdb_prompt
1921 + # First test normal `file'-command loaded $FILE with symbols.
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
1930 + reach "dl_main" "run segv"
1932 + gdb_test "bt" "#0 +\[^\r\n\]*\\mdl_main\\M.*" "dl bt"
1935 + reach "main" continue
1937 + reach "libfunc" continue
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"
1952 + set old_ldprefix $pf_prefix
1953 + lappend pf_prefix "symbol-less:"
1955 + # Test also `exec-file'-command loaded $FILE - therefore without symbols.
1956 + # SYMBOL_OBJFILE is not available and only EXEC_BFD must be used.
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
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"
1969 + reach "dl_main" run
1971 + set test "info files"
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)
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"
1984 + # There is no symbol to break at ld.so. Moreover it can exit with an
1986 + gdb_test "run" "Program exited (normally|with code \[0-9\]+)\\." "ld.so exit"
1989 + set pf_prefix $old_ldprefix
1992 +# Create separate binaries for each testcase - to make the possible reported
1993 +# problem reproducible after the whole test run finishes.
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"} {
2004 + set ldname "LDprelink${ldprelink}debug${ldsepdebug}"
2005 + set interp $binprefix-$ldname
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.
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
2020 + set pf_prefix $old_ldprefix
2021 + lappend pf_prefix "$ldname:"
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] {
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"]} {
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] {
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] {
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"
2062 + if {$ldsepdebug == "SEP"} {
2063 + if ![prelinkNO "${interp}.debug"] {
2067 + file delete "${interp}.debug"
2070 + if ![prelink$ldprelink $interp] {
2073 + test_ld $interp 0 [expr {$ldsepdebug == "NO"}]
2075 + if ![copy $interp $interp_saved] {
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"} {
2088 + set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}"
2089 + set exec $binprefix-$binname
2092 + set pf_prefix $old_binprefix
2093 + lappend pf_prefix "$binname:"
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}
2100 + if {$binpie == "YES"} {
2101 + lappend opts {additional_flags=-fPIE -pie}
2103 + if {[build_executable ${test}.exp [file tail $exec] $srcfile $opts] == -1} {
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"
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
2121 + file delete -force $dir
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 == ""} {
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} {
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
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"}]
2159 + file delete $interp_saved
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}] {
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.
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.
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.
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"
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"
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"
2217 +set corefile [core_find $binfile {coremmap.data}]
2218 +if {$corefile == ""} {
2222 -# Try to clean up after ourselves.
2223 -remote_file build delete [file join $coredir coremmap.data]
2224 -remote_exec build "rmdir $coredir"
2226 -if { $found == 0 } {
2227 - warning "can't generate a core file - core tests suppressed - check ulimit -c"
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 } {
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"
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"
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)"
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]"
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)"
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)"
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" }
2272 @@ -147,22 +94,22 @@ expect {
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"
2281 -eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$objdir/$subdir/corefile";
2282 +eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile";
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]"
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)"
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)"
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" }
2300 set timeout $oldtimeout
2301 @@ -178,7 +125,7 @@ gdb_load ${binfile}
2303 # Test basic corefile recognition via core-file command.
2305 -send_gdb "core-file $objdir/$subdir/corefile\n"
2306 +send_gdb "core-file $corefile\n"
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
2316 -/* This testcase is part of GDB, the GNU debugger.
2318 - Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>.
2340 - printf ("a = %d\n", a);
2344 -main (int argc, char *argv[])
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
2356 -# Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>.
2371 -set testfile pie-support
2372 -set srcfile ${testfile}.c
2373 -set objfile ${objdir}/${subdir}/${testfile}.o
2374 -set binfile ${objdir}/${subdir}/${testfile}
2376 -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {quiet debug additional_flags=-fpie}] != "" } {
2377 - untested "Couldn't compile test PIE object file."
2380 -if { [gdb_compile "${objfile}" "${binfile}" executable {quiet debug additional_flags=-pie}] != "" } {
2381 - untested "Couldn't compile test PIE binary."
2385 -# Get things started.
2389 -gdb_reinitialize_dir $srcdir/$subdir
2391 -if [is_remote host] {
2392 - set binfile [remote_download host $binfile]
2393 - if { $binfile == "" } {
2394 - untested "Couldn't download remote test binary."
2399 -# The file command used to kill the remote target. For the benefit
2400 -# of the testsuite, preserve this behavior.
2403 - -re "Kill the program being debugged. .y or n. $" {
2405 - verbose "\t\tKilling previous program being debugged"
2408 - -re "$gdb_prompt $" {
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
2418 +++ b/gdb/testsuite/gdb.base/valgrind-db-attach.c
2420 +/* This testcase is part of GDB, the GNU debugger.
2422 + Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
2437 +#include <stdlib.h>
2447 + free (p); /* double-free */
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
2454 +++ b/gdb/testsuite/gdb.base/valgrind-db-attach.exp
2456 +# Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>.
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} {
2481 +# remote_spawn breaks the command on each whitespace despite possible quoting.
2482 +# Use backslash-escaped whitespace there instead:
2484 +set db_command "--db-command=$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts] %f %p"
2485 +regsub -all " " $db_command "\\ " db_command
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."
2497 +# Declare GDB now as running.
2498 +set gdb_spawn_id -1
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" {
2506 + -re "valgrind: failed to start tool 'memcheck' for platform '.*': No such file or directory" {
2513 +set double_free [gdb_get_line_number "double-free"]
2515 +gdb_test_multiple "" $test {
2516 + -re "Invalid free\\(\\) / delete / delete\\\[\\\]\r\n.*: main \\(${srcfile}:$double_free\\)\r\n.*---- Attach to debugger \\? --- \[^\r\n\]* ---- " {
2519 + -re "---- Attach to debugger \\? --- \[^\r\n\]* ---- " {
2525 +# Initialization from default_gdb_start.
2526 +gdb_test "set height 0"
2527 +gdb_test "set width 0"
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
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.
2545 # Line 39 of "../.././gdb/testsuite/gdb.dwarf2/dw2-ranges.S" starts at address 0x4 and ends at 0x8.
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 } {
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
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 } {
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
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]
2582 +proc core_find {binfile {deletefiles {}} {arg ""}} {
2583 + global objdir subdir
2585 + set destcore "$binfile.core"
2586 + file delete $destcore
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.
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.
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.
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"
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"
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"
2636 + # Try to clean up after ourselves.
2637 + foreach deletefile $deletefiles {
2638 + remote_file build delete [file join $coredir $deletefile]
2640 + remote_exec build "rmdir $coredir"
2642 + if { $found == 0 } {
2643 + warning "can't generate a core file - core tests suppressed - check ulimit -c"