1 2007-11-02 Jan Kratochvil <jan.kratochvil@redhat.com>
5 2007-11-02 Jan Kratochvil <jan.kratochvil@redhat.com>
7 Port to post-GDB-6.7.1 multi-PC breakpoints.
9 2007-11-09 Jan Kratochvil <jan.kratochvil@redhat.com>
11 * solib-svr4.c (svr4_current_sos): Fix segfault on NULL EXEC_BFD.
13 2008-02-24 Jan Kratochvil <jan.kratochvil@redhat.com>
17 2008-02-27 Jan Kratochvil <jan.kratochvil@redhat.com>
19 Port to gdb-6.7.50.20080227.
21 2008-06-01 Jan Kratochvil <jan.kratochvil@redhat.com>
23 Fix crash on a watchpoint update on an inferior stop.
25 2008-09-01 Jan Kratochvil <jan.kratochvil@redhat.com>
27 Fix scan_dyntag() for binaries provided by valgrind (BZ 460319).
29 Index: gdb-6.8.91.20090925/gdb/amd64-tdep.c
30 ===================================================================
31 --- gdb-6.8.91.20090925.orig/gdb/amd64-tdep.c 2009-09-25 10:25:39.000000000 +0200
32 +++ gdb-6.8.91.20090925/gdb/amd64-tdep.c 2009-09-25 10:25:45.000000000 +0200
37 +#include "exceptions.h"
39 #include "gdb_assert.h"
41 @@ -1591,18 +1592,31 @@ amd64_analyze_stack_align (CORE_ADDR pc,
42 Any function that doesn't start with this sequence will be assumed
43 to have no prologue and thus no valid frame pointer in %rbp. */
46 -amd64_analyze_prologue (struct gdbarch *gdbarch,
47 - CORE_ADDR pc, CORE_ADDR current_pc,
48 - struct amd64_frame_cache *cache)
49 +struct amd64_analyze_prologue_data
51 + struct gdbarch *gdbarch;
52 + CORE_ADDR pc, current_pc;
53 + struct amd64_frame_cache *cache;
58 +amd64_analyze_prologue_1 (void *data_pointer)
60 + struct amd64_analyze_prologue_data *data = data_pointer;
61 + struct gdbarch *gdbarch = data->gdbarch;
62 + CORE_ADDR pc = data->pc, current_pc = data->current_pc;
63 + struct amd64_frame_cache *cache = data->cache;
64 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
65 static gdb_byte proto[3] = { 0x48, 0x89, 0xe5 }; /* movq %rsp, %rbp */
72 + data->retval = current_pc;
76 pc = amd64_analyze_stack_align (pc, current_pc, cache);
78 @@ -1617,18 +1631,59 @@ amd64_analyze_prologue (struct gdbarch *
80 /* If that's all, return now. */
81 if (current_pc <= pc + 1)
84 + data->retval = current_pc;
88 /* Check for `movq %rsp, %rbp'. */
89 read_memory (pc + 1, buf, 3);
90 if (memcmp (buf, proto, 3) != 0)
93 + data->retval = pc + 1;
97 /* OK, we actually have a frame. */
98 cache->frameless_p = 0;
100 + data->retval = pc + 4;
108 +/* Catch memory read errors and return just PC in such case.
109 + It occurs very early on enable_break->new_symfile_objfile->
110 + ->breakpoint_re_set->decode_line_1->decode_variable_1->
111 + ->find_function_start_sal */
114 +amd64_analyze_prologue (struct gdbarch *gdbarch,
115 + CORE_ADDR pc, CORE_ADDR current_pc,
116 + struct amd64_frame_cache *cache)
119 + struct amd64_analyze_prologue_data data;
120 + struct ui_file *saved_gdb_stderr;
122 + /* Suppress error messages. */
123 + saved_gdb_stderr = gdb_stderr;
124 + gdb_stderr = ui_file_new ();
126 + data.gdbarch = gdbarch;
128 + data.current_pc = current_pc;
129 + data.cache = cache;
130 + status = catch_errors (amd64_analyze_prologue_1, &data, "", RETURN_MASK_ALL);
132 + /* Stop suppressing error messages. */
133 + ui_file_delete (gdb_stderr);
134 + gdb_stderr = saved_gdb_stderr;
137 + return data.retval;
141 Index: gdb-6.8.91.20090925/gdb/auxv.c
142 ===================================================================
143 --- gdb-6.8.91.20090925.orig/gdb/auxv.c 2009-07-02 19:25:52.000000000 +0200
144 +++ gdb-6.8.91.20090925/gdb/auxv.c 2009-09-25 10:25:45.000000000 +0200
145 @@ -78,7 +78,7 @@ procfs_xfer_auxv (struct target_ops *ops
146 Return 1 if an entry was read into *TYPEP and *VALP. */
148 default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
149 - gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
150 + gdb_byte *endptr, ULONGEST *typep, CORE_ADDR *valp)
152 const int sizeof_auxv_field = gdbarch_ptr_bit (target_gdbarch)
154 @@ -106,7 +106,7 @@ default_auxv_parse (struct target_ops *o
155 Return 1 if an entry was read into *TYPEP and *VALP. */
157 target_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
158 - gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
159 + gdb_byte *endptr, ULONGEST *typep, CORE_ADDR *valp)
161 struct target_ops *t;
162 for (t = ops; t != NULL; t = t->beneath)
163 @@ -121,9 +121,10 @@ target_auxv_parse (struct target_ops *op
164 an error getting the information. On success, return 1 after
165 storing the entry's value field in *VALP. */
167 -target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
168 +target_auxv_search (struct target_ops *ops, ULONGEST match, CORE_ADDR *valp)
170 - CORE_ADDR type, val;
174 LONGEST n = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL, &data);
175 gdb_byte *ptr = data;
176 @@ -133,10 +134,10 @@ target_auxv_search (struct target_ops *o
180 - switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
181 + switch (target_auxv_parse (ops, &ptr, data + n, &at_type, &val))
183 case 1: /* Here's an entry, check it. */
185 + if (at_type == match)
189 @@ -159,7 +160,8 @@ target_auxv_search (struct target_ops *o
191 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
193 - CORE_ADDR type, val;
197 LONGEST len = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL,
199 @@ -169,13 +171,13 @@ fprint_target_auxv (struct ui_file *file
203 - while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
204 + while (target_auxv_parse (ops, &ptr, data + len, &at_type, &val) > 0)
206 const char *name = "???";
207 const char *description = "";
208 enum { dec, hex, str } flavor = hex;
213 #define TAG(tag, text, kind) \
214 case tag: name = #tag; description = text; flavor = kind; break
215 @@ -231,7 +233,7 @@ fprint_target_auxv (struct ui_file *file
218 fprintf_filtered (file, "%-4s %-20s %-30s ",
219 - plongest (type), name, description);
220 + plongest (at_type), name, description);
224 @@ -253,7 +255,7 @@ fprint_target_auxv (struct ui_file *file
228 - if (type == AT_NULL)
229 + if (at_type == AT_NULL)
233 Index: gdb-6.8.91.20090925/gdb/auxv.h
234 ===================================================================
235 --- gdb-6.8.91.20090925.orig/gdb/auxv.h 2009-06-07 21:07:08.000000000 +0200
236 +++ gdb-6.8.91.20090925/gdb/auxv.h 2009-09-25 10:25:45.000000000 +0200
238 Return 1 if an entry was read into *TYPEP and *VALP. */
239 extern int target_auxv_parse (struct target_ops *ops,
240 gdb_byte **readptr, gdb_byte *endptr,
241 - CORE_ADDR *typep, CORE_ADDR *valp);
242 + ULONGEST *typep, CORE_ADDR *valp);
244 /* Extract the auxiliary vector entry with a_type matching MATCH.
245 Return zero if no such entry was found, or -1 if there was
246 an error getting the information. On success, return 1 after
247 storing the entry's value field in *VALP. */
248 extern int target_auxv_search (struct target_ops *ops,
249 - CORE_ADDR match, CORE_ADDR *valp);
250 + ULONGEST match, CORE_ADDR *valp);
252 /* Print the contents of the target's AUXV on the specified file. */
253 extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops);
254 Index: gdb-6.8.91.20090925/gdb/dwarf2read.c
255 ===================================================================
256 --- gdb-6.8.91.20090925.orig/gdb/dwarf2read.c 2009-09-25 10:25:39.000000000 +0200
257 +++ gdb-6.8.91.20090925/gdb/dwarf2read.c 2009-09-25 10:25:45.000000000 +0200
258 @@ -1717,7 +1717,7 @@ dwarf2_build_psymtabs (struct objfile *o
259 dwarf2_read_section (objfile, &dwarf2_per_objfile->eh_frame);
260 dwarf2_read_section (objfile, &dwarf2_per_objfile->frame);
263 + if ((mainline == 1)
264 || (objfile->global_psymbols.size == 0
265 && objfile->static_psymbols.size == 0))
267 Index: gdb-6.8.91.20090925/gdb/elfread.c
268 ===================================================================
269 --- gdb-6.8.91.20090925.orig/gdb/elfread.c 2009-09-25 10:25:38.000000000 +0200
270 +++ gdb-6.8.91.20090925/gdb/elfread.c 2009-09-25 10:25:45.000000000 +0200
271 @@ -681,7 +681,7 @@ elf_symfile_read (struct objfile *objfil
272 /* If we are reinitializing, or if we have never loaded syms yet,
273 set table to empty. MAINLINE is cleared so that *_read_psymtab
274 functions do not all also re-initialize the psymbol table. */
278 init_psymbol_list (objfile, 0);
280 Index: gdb-6.8.91.20090925/gdb/infrun.c
281 ===================================================================
282 --- gdb-6.8.91.20090925.orig/gdb/infrun.c 2009-09-25 10:25:39.000000000 +0200
283 +++ gdb-6.8.91.20090925/gdb/infrun.c 2009-09-25 10:25:45.000000000 +0200
284 @@ -3659,6 +3659,10 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (
286 target_terminal_inferior ();
288 + /* For PIE executables, we dont really know where the
289 + breakpoints are going to be until we start up the inferior. */
290 + enable_breakpoints_after_startup ();
292 /* If requested, stop when the dynamic linker notifies
293 gdb of events. This allows the user to get control
294 and place breakpoints in initializer routines for
295 Index: gdb-6.8.91.20090925/gdb/objfiles.c
296 ===================================================================
297 --- gdb-6.8.91.20090925.orig/gdb/objfiles.c 2009-09-25 10:25:38.000000000 +0200
298 +++ gdb-6.8.91.20090925/gdb/objfiles.c 2009-09-25 10:25:45.000000000 +0200
300 #include "observer.h"
301 #include "complaints.h"
304 +#include "elf/common.h"
306 /* Prototypes for local functions */
308 static void objfile_alloc_data (struct objfile *objfile);
309 @@ -280,9 +283,17 @@ init_entry_point_info (struct objfile *o
311 entry_point_address (void)
315 struct gdbarch *gdbarch;
316 CORE_ADDR entry_point;
318 + /* Find the address of the entry point of the program from the
320 + ret = target_auxv_search (¤t_target, AT_ENTRY, &entry_point);
322 + return entry_point;
324 if (symfile_objfile == NULL)
327 Index: gdb-6.8.91.20090925/gdb/solib-svr4.c
328 ===================================================================
329 --- gdb-6.8.91.20090925.orig/gdb/solib-svr4.c 2009-09-25 10:25:39.000000000 +0200
330 +++ gdb-6.8.91.20090925/gdb/solib-svr4.c 2009-09-25 10:28:07.000000000 +0200
334 #include "exceptions.h"
335 +#include "command.h"
337 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
338 static int svr4_have_link_map_offsets (void);
339 @@ -359,7 +360,9 @@ solib_svr4_inferior_exit (int pid)
341 /* Local function prototypes */
344 static int match_main (char *);
347 static CORE_ADDR bfd_lookup_symbol (bfd *, char *);
349 @@ -600,10 +603,12 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
350 int arch_size, step, sect_size;
352 CORE_ADDR dyn_ptr, dyn_addr;
353 + CORE_ADDR reloc_addr = 0;
354 gdb_byte *bufend, *bufstart, *buf;
355 Elf32_External_Dyn *x_dynp_32;
356 Elf64_External_Dyn *x_dynp_64;
357 struct bfd_section *sect;
362 @@ -615,19 +620,81 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
366 + /* The auxv vector based relocatable files reading is limited to the main
368 + gdb_assert (abfd == exec_bfd || ptr == NULL);
372 + CORE_ADDR entry_addr;
374 + /* Find the address of the entry point of the program from the
376 + ret = target_auxv_search (¤t_target, AT_ENTRY, &entry_addr);
378 + if (ret == 0 || ret == -1)
380 + /* No auxv info, maybe an older kernel. Fake our way through. */
381 + entry_addr = bfd_get_start_address (exec_bfd);
384 + fprintf_unfiltered (gdb_stdlog,
385 + "elf_locate_base: program entry address not found. Using bfd's %s for %s\n",
386 + paddress (target_gdbarch, entry_addr), exec_bfd->filename);
391 + fprintf_unfiltered (gdb_stdlog,
392 + "elf_locate_base: found program entry address %s for %s\n",
393 + paddress (target_gdbarch, entry_addr), exec_bfd->filename);
395 + reloc_addr = entry_addr - bfd_get_start_address (exec_bfd);
397 + fprintf_unfiltered (gdb_stdlog,
398 + "elf_locate_base: expected relocation offset %s for %s\n",
399 + paddress (target_gdbarch, reloc_addr), exec_bfd->filename);
402 /* Find the start address of the .dynamic section. */
403 sect = bfd_get_section_by_name (abfd, ".dynamic");
408 + fprintf_unfiltered (gdb_stdlog,
409 + "elf_locate_base: .dynamic section not found in %s -- return now\n",
410 + exec_bfd->filename);
416 + fprintf_unfiltered (gdb_stdlog,
417 + "elf_locate_base: .dynamic section found in %s\n",
418 + exec_bfd->filename);
421 dyn_addr = bfd_section_vma (abfd, sect);
423 + fprintf_unfiltered (gdb_stdlog,
424 + "elf_locate_base: .dynamic addr %s\n",
425 + paddress (target_gdbarch, dyn_addr));
427 /* Read in .dynamic from the BFD. We will get the actual value
428 from memory later. */
429 sect_size = bfd_section_size (abfd, sect);
430 buf = bufstart = alloca (sect_size);
432 + fprintf_unfiltered (gdb_stdlog,
433 + "elf_locate_base: read in .dynamic section\n");
434 if (!bfd_get_section_contents (abfd, sect,
439 + fprintf_unfiltered (gdb_stdlog,
440 + "elf_locate_base: couldn't read .dynamic section -- return now\n");
444 /* Iterate over BUF and scan for DYNTAG. If found, set PTR and return. */
445 step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)
446 @@ -648,26 +715,105 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
447 dyn_tag = bfd_h_get_64 (abfd, (bfd_byte *) x_dynp_64->d_tag);
448 dyn_ptr = bfd_h_get_64 (abfd, (bfd_byte *) x_dynp_64->d_un.d_ptr);
450 - if (dyn_tag == DT_NULL)
452 + /* Verify RELOC_ADDR makes sense - it does not have to for valgrind which
453 + supplies us a specially crafted executable in /proc/PID/fd/X while
454 + /proc/PID/auxv corresponds to a different executable (.../memcheck). */
457 + gdb_byte tag_buf[8];
458 + CORE_ADDR tag_addr;
460 + tag_addr = dyn_addr + (buf - bufstart) + reloc_addr;
461 + if (target_read_memory (tag_addr, tag_buf, arch_size / 8) == 0)
463 + if (memcmp (tag_buf, buf, arch_size / 8) != 0)
466 + fprintf_unfiltered (gdb_stdlog,
467 + "elf_locate_base: tag at offset 0x%lx does not match,"
468 + " dropping relocation offset %s\n",
469 + (unsigned long) (buf - bufstart), paddress (target_gdbarch, reloc_addr));
476 + fprintf_unfiltered (gdb_stdlog,
477 + "elf_locate_base: tag at offset 0x%lx is not readable,"
478 + " dropping relocation offset %s\n",
479 + (unsigned long) (buf - bufstart), paddress (target_gdbarch, reloc_addr));
484 + if (dyn_tag == DT_NULL)
486 - if (dyn_tag == dyntag)
488 - /* If requested, try to read the runtime value of this .dynamic
492 - struct type *ptr_type;
493 - gdb_byte ptr_buf[8];
494 - CORE_ADDR ptr_addr;
496 - ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
497 - ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8;
498 - if (target_read_memory (ptr_addr, ptr_buf, arch_size / 8) == 0)
499 - dyn_ptr = extract_typed_address (ptr_buf, ptr_type);
504 + if (dyn_tag == dyntag)
506 + /* If requested, try to read the runtime value of this .dynamic
510 + gdb_byte ptr_buf[8];
511 + CORE_ADDR ptr_addr;
514 + ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8;
518 + fprintf_unfiltered (gdb_stdlog,
519 + "elf_locate_base: unrelocated ptr addr %s\n",
520 + paddress (target_gdbarch, ptr_addr));
521 + ptr_addr += reloc_addr;
523 + fprintf_unfiltered (gdb_stdlog,
524 + "elf_locate_base: relocated ptr addr %s"
525 + " (relocation offset %s) for %s\n",
526 + paddress (target_gdbarch, ptr_addr), paddress (target_gdbarch, reloc_addr),
527 + exec_bfd->filename);
529 + got = target_read_memory (ptr_addr, ptr_buf, arch_size / 8);
530 + if (got != 0 && reloc_addr)
532 + ptr_addr -= reloc_addr;
534 + fprintf_unfiltered (gdb_stdlog,
535 + "elf_locate_base: unrelocated back to ptr addr %s"
536 + " as the memory was unreable for %s\n",
537 + paddress (target_gdbarch, ptr_addr), exec_bfd->filename);
538 + got = target_read_memory (ptr_addr, ptr_buf, arch_size / 8);
543 + struct type *ptr_type;
545 + ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
546 + dyn_ptr = extract_typed_address (ptr_buf, ptr_type);
550 + fprintf_unfiltered (gdb_stdlog,
551 + "elf_locate_base: Tag entry has value %s -- return now\n",
552 + paddress (target_gdbarch, dyn_ptr));
560 + fprintf_unfiltered (gdb_stdlog,
561 + "elf_locate_base: Couldn't read tag entry value -- return now\n");
571 @@ -1040,6 +1186,11 @@ svr4_current_sos (void)
572 CORE_ADDR ldsomap = 0;
573 struct inferior *inf;
574 struct svr4_info *info;
575 + const char *filename = exec_bfd ? exec_bfd->filename : "<none>";
578 + fprintf_unfiltered (gdb_stdlog,
579 + "svr4_current_sos: exec_bfd %s\n", filename);
581 if (ptid_equal (inferior_ptid, null_ptid))
583 @@ -1054,7 +1205,13 @@ svr4_current_sos (void)
584 /* If we can't find the dynamic linker's base structure, this
585 must not be a dynamically linked executable. Hmm. */
586 if (! info->debug_base)
587 - return svr4_default_sos ();
590 + fprintf_unfiltered (gdb_stdlog,
591 + "svr4_current_sos: no DT_DEBUG found in %s -- return now\n",
593 + return svr4_default_sos ();
596 /* Walk the inferior's link map list, and build our list of
597 `struct so_list' nodes. */
598 @@ -1074,26 +1231,104 @@ svr4_current_sos (void)
599 new->lm_info->lm = xzalloc (lmo->link_map_size);
600 make_cleanup (xfree, new->lm_info->lm);
603 + fprintf_unfiltered (gdb_stdlog,
604 + "svr4_current_sos: read lm at %s\n", paddress (target_gdbarch, lm));
605 read_memory (lm, new->lm_info->lm, lmo->link_map_size);
610 + fprintf_unfiltered (gdb_stdlog,
611 + "svr4_current_sos: is first link entry? %d\n",
612 + IGNORE_FIRST_LINK_MAP_ENTRY (new));
614 /* For SVR4 versions, the first entry in the link map is for the
615 inferior executable, so we must ignore it. For some versions of
616 SVR4, it has no name. For others (Solaris 2.3 for example), it
617 does have a name, so we can no longer use a missing name to
618 decide when to ignore it. */
619 - if (IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
620 + if (exec_bfd != NULL && IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
622 - info->main_lm_addr = new->lm_info->lm_addr;
625 + /* It is the first link map entry, i.e. it is the main executable. */
627 + if (bfd_get_start_address (exec_bfd) == entry_point_address ())
629 + /* Non-pie case, main executable has not been relocated. */
630 + info->main_lm_addr = new->lm_info->lm_addr;
635 + /* Pie case, main executable has been relocated. */
636 + struct so_list *gdb_solib;
639 + fprintf_unfiltered (gdb_stdlog,
640 + "svr4_current_sos: Processing first link map entry\n");
641 + strncpy (new->so_name, exec_bfd->filename,
642 + SO_NAME_MAX_PATH_SIZE - 1);
643 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
644 + strcpy (new->so_original_name, new->so_name);
646 + new->main_relocated = 0;
650 + fprintf_unfiltered (gdb_stdlog,
651 + "svr4_current_sos: Processing nameless DSO\n");
652 + fprintf_unfiltered (gdb_stdlog,
653 + "svr4_current_sos: adding name %s\n",
657 + for (gdb_solib = master_so_list ();
659 + gdb_solib = gdb_solib->next)
662 + fprintf_unfiltered (gdb_stdlog,
663 + "svr4_current_sos: compare gdb %s and new %s\n",
664 + gdb_solib->so_name, new->so_name);
665 + if (strcmp (gdb_solib->so_name, new->so_name) == 0)
666 + if (gdb_solib->main_relocated)
669 + fprintf_unfiltered (gdb_stdlog,
670 + "svr4_current_sos: found main relocated\n");
675 + if ((gdb_solib && !gdb_solib->main_relocated) || (!gdb_solib))
677 + add_to_target_sections (0 /*from_tty*/, ¤t_target, new);
681 + /* We need this in the list of shared libs we return because
682 + solib_add_stub will loop through it and add the symbol file. */
685 + link_ptr = &new->next;
687 + } /* End of IGNORE_FIRST_LINK_MAP_ENTRY */
690 + /* This is not the first link map entry, i.e. is not the main
691 + executable. Note however that it could be the DSO supplied on
692 + certain systems (i.e. Linux 2.6) containing information about
693 + the vsyscall page. We must ignore such entry. This entry is
694 + nameless (just like the one for the main executable, sigh). */
699 /* Extract this shared object's name. */
701 + fprintf_unfiltered (gdb_stdlog,
702 + "svr4_current_sos: read LM_NAME\n");
704 target_read_string (LM_NAME (new), &buffer,
705 SO_NAME_MAX_PATH_SIZE - 1, &errcode);
707 @@ -1101,63 +1336,76 @@ svr4_current_sos (void)
708 safe_strerror (errcode));
711 - struct build_id *build_id;
713 - strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
714 - new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
715 - /* May get overwritten below. */
716 - strcpy (new->so_name, new->so_original_name);
718 - build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
719 - if (build_id != NULL)
721 + fprintf_unfiltered (gdb_stdlog,
722 + "svr4_current_sos: LM_NAME is <%s>\n",
724 + /* The name could be empty, in which case it is the
725 + system supplied DSO. */
726 + if (strcmp (buffer, "") == 0)
730 - char *name, *build_id_filename;
731 + struct build_id *build_id;
733 + strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
734 + new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
735 + /* May get overwritten below. */
736 + strcpy (new->so_name, new->so_original_name);
738 - /* Missing the build-id matching separate debug info file
739 - would be handled while SO_NAME gets loaded. */
740 - name = build_id_to_filename (build_id, &build_id_filename, 0);
742 + build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
743 + if (build_id != NULL)
745 - strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
746 - new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
748 + char *name, *build_id_filename;
750 + /* Missing the build-id matching separate debug info file
751 + would be handled while SO_NAME gets loaded. */
752 + name = build_id_to_filename (build_id, &build_id_filename, 0);
755 + strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
756 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
761 + debug_print_missing (new->so_name, build_id_filename);
763 + /* In the case the main executable was found according to
764 + its build-id (from a core file) prevent loading
765 + a different build of a library with accidentally the
768 + It suppresses bogus backtraces (and prints "??" there
769 + instead) if the on-disk files no longer match the
770 + running program version. */
772 + if (symfile_objfile != NULL
773 + && (symfile_objfile->flags
774 + & OBJF_BUILD_ID_CORE_LOADED) != 0)
775 + new->so_name[0] = 0;
778 + xfree (build_id_filename);
783 - debug_print_missing (new->so_name, build_id_filename);
785 - /* In the case the main executable was found according to
786 - its build-id (from a core file) prevent loading
787 - a different build of a library with accidentally the
790 - It suppresses bogus backtraces (and prints "??" there
791 - instead) if the on-disk files no longer match the
792 - running program version. */
794 - if (symfile_objfile != NULL
795 - && (symfile_objfile->flags
796 - & OBJF_BUILD_ID_CORE_LOADED) != 0)
797 - new->so_name[0] = 0;
800 + fprintf_unfiltered (gdb_stdlog,
801 + "svr4_current_sos: Processing DSO: %s\n",
803 + fprintf_unfiltered (gdb_stdlog,
804 + "svr4_current_sos: first link entry %d\n",
805 + IGNORE_FIRST_LINK_MAP_ENTRY (new));
808 - xfree (build_id_filename);
812 + link_ptr = &new->next;
817 - /* If this entry has no name, or its name matches the name
818 - for the main executable, don't include it in the list. */
819 - if (! new->so_name[0]
820 - || match_main (new->so_name))
826 - link_ptr = &new->next;
831 /* On Solaris, the dynamic linker is not in the normal list of
832 @@ -1173,6 +1421,9 @@ svr4_current_sos (void)
834 return svr4_default_sos ();
837 + fprintf_unfiltered (gdb_stdlog, "svr4_current_sos: ENDS %s\n", filename);
842 @@ -1205,7 +1456,7 @@ svr4_fetch_objfile_link_map (struct objf
843 /* On some systems, the only way to recognize the link map entry for
844 the main executable file is by looking at its name. Return
845 non-zero iff SONAME matches one of the known main executable names. */
849 match_main (char *soname)
851 @@ -1219,6 +1470,7 @@ match_main (char *soname)
857 /* Return 1 if PC lies in the dynamic symbol resolution code of the
858 SVR4 run time loader. */
859 @@ -1370,15 +1622,29 @@ enable_break (struct svr4_info *info)
860 /* Find the program interpreter; if not found, warn the user and drop
861 into the old breakpoint at symbol code. */
862 interp_name = find_program_interpreter ();
865 + fprintf_unfiltered (gdb_stdlog,
866 + "enable_break: search for .interp in %s\n",
867 + exec_bfd->filename);
870 CORE_ADDR load_addr = 0;
871 + CORE_ADDR load_addr_mask = -1L;
872 int load_addr_found = 0;
873 int loader_found_in_list = 0;
876 struct target_ops *tmp_bfd_target;
877 volatile struct gdb_exception ex;
880 + /* For 32bit inferiors with 64bit GDB we may get LOAD_ADDR at 0xff......
881 + and thus overflowing its addition to the address while CORE_ADDR is
882 + 64bit producing 0x1........ address invalid across GDB. */
883 + arch_size = bfd_get_arch_size (exec_bfd);
884 + if (arch_size > 0 && arch_size < sizeof (1UL) * 8)
885 + load_addr_mask = (1UL << arch_size) - 1;
889 @@ -1395,6 +1661,9 @@ enable_break (struct svr4_info *info)
891 tmp_bfd = solib_bfd_open (interp_name);
894 + fprintf_unfiltered (gdb_stdlog,
895 + "enable_break: opening %s\n", interp_name);
899 @@ -1452,16 +1721,16 @@ enable_break (struct svr4_info *info)
900 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
903 - interp_text_sect_low =
904 - bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
905 + interp_text_sect_low = (bfd_section_vma (tmp_bfd, interp_sect)
906 + + load_addr) & load_addr_mask;
907 interp_text_sect_high =
908 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
910 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
913 - interp_plt_sect_low =
914 - bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
915 + interp_plt_sect_low = (bfd_section_vma (tmp_bfd, interp_sect)
916 + + load_addr) & load_addr_mask;
917 interp_plt_sect_high =
918 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
920 @@ -1496,7 +1765,7 @@ enable_break (struct svr4_info *info)
924 - create_solib_event_breakpoint (target_gdbarch, load_addr + sym_addr);
925 + create_solib_event_breakpoint (target_gdbarch, (load_addr + sym_addr) & load_addr_mask);
929 @@ -1769,6 +2038,9 @@ svr4_solib_create_inferior_hook (void)
930 while (tp->stop_signal != TARGET_SIGNAL_TRAP);
931 inf->stop_soon = NO_STOP_QUIETLY;
932 #endif /* defined(_SCO_DS) */
934 + if (bfd_get_start_address (exec_bfd) != entry_point_address ())
935 + disable_breakpoints_before_startup ();
939 @@ -1945,6 +2217,76 @@ svr4_lp64_fetch_link_map_offsets (void)
944 +info_linkmap_command (char *cmd, int from_tty)
947 + struct svr4_info *info = get_svr4_info (PIDGET (inferior_ptid));
949 + /* Make sure we've looked up the inferior's dynamic linker's base
951 + if (! info->debug_base)
953 + info->debug_base = locate_base (info);
955 + /* If we can't find the dynamic linker's base structure, this
956 + must not be a dynamically linked executable. Hmm. */
957 + if (! info->debug_base)
960 + fprintf_unfiltered (gdb_stdlog,
961 + "svr4_print_linkmap: no DT_DEBUG found in %s -- return now\n",
962 + exec_bfd->filename);
967 + /* Walk the inferior's link map list, and print the info. */
969 + lm = solib_svr4_r_map (info);
974 + CORE_ADDR load_addr;
976 + struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
977 + struct so_list *new
978 + = (struct so_list *) xmalloc (sizeof (struct so_list));
979 + struct cleanup *old_chain = make_cleanup (xfree, new);
981 + memset (new, 0, sizeof (*new));
983 + new->lm_info = xmalloc (sizeof (struct lm_info));
984 + make_cleanup (xfree, new->lm_info);
986 + new->lm_info->lm = xmalloc (lmo->link_map_size);
987 + make_cleanup (xfree, new->lm_info->lm);
988 + memset (new->lm_info->lm, 0, lmo->link_map_size);
991 + fprintf_unfiltered (gdb_stdlog,
992 + "svr4_print_linkmap: read lm at %s\n", paddress (target_gdbarch, lm));
993 + read_memory (lm, new->lm_info->lm, lmo->link_map_size);
995 + lm = LM_NEXT (new);
997 + /* Load address. */
998 + load_addr = LM_ADDR_CHECK (new, NULL);
999 + /* Shared object's name. */
1000 + target_read_string (LM_NAME (new), &buffer,
1001 + SO_NAME_MAX_PATH_SIZE - 1, &errcode);
1002 + make_cleanup (xfree, buffer);
1005 + warning ("svr4_print_linkmap: Can't read pathname for load map: %s\n",
1006 + safe_strerror (errcode));
1008 + fprintf_filtered (gdb_stdout, "%-8s %-30s\n", paddress (target_gdbarch, load_addr), buffer);
1009 + do_cleanups (old_chain);
1015 struct target_so_ops svr4_so_ops;
1016 @@ -1985,4 +2327,7 @@ _initialize_svr4_solib (void)
1017 svr4_so_ops.same = svr4_same;
1019 observer_attach_inferior_exit (solib_svr4_inferior_exit);
1021 + add_info ("linkmap", info_linkmap_command,
1022 + "Display the inferior's linkmap.");
1024 Index: gdb-6.8.91.20090925/gdb/solib.c
1025 ===================================================================
1026 --- gdb-6.8.91.20090925.orig/gdb/solib.c 2009-09-25 10:25:38.000000000 +0200
1027 +++ gdb-6.8.91.20090925/gdb/solib.c 2009-09-25 10:25:45.000000000 +0200
1028 @@ -82,6 +82,8 @@ set_solib_ops (struct gdbarch *gdbarch,
1030 /* external data declarations */
1034 /* FIXME: gdbarch needs to control this variable, or else every
1035 configuration needs to call set_solib_ops. */
1036 struct target_so_ops *current_target_so_ops;
1037 @@ -105,6 +107,8 @@ The search path for loading non-absolute
1041 +void add_to_target_sections (int, struct target_ops *, struct so_list *);
1046 @@ -449,14 +453,38 @@ symbol_add_stub (struct so_list *so, int
1047 /* Have we already loaded this shared object? */
1048 ALL_OBJFILES (so->objfile)
1050 - if (strcmp (so->objfile->name, so->so_name) == 0)
1051 + /* Found an already loaded shared library. */
1052 + if (strcmp (so->objfile->name, so->so_name) == 0
1055 + /* Found an already loaded main executable. This could happen in
1056 + two circumstances.
1057 + First case: the main file has already been read in
1058 + as the first thing that gdb does at startup, and the file
1059 + hasn't been relocated properly yet. Therefor we need to read
1060 + it in with the proper section info.
1061 + Second case: it has been read in with the correct relocation,
1062 + and therefore we need to skip it. */
1063 + if (strcmp (so->objfile->name, so->so_name) == 0
1065 + && so->main_relocated)
1069 sap = build_section_addr_info_from_section_table (so->sections,
1072 - so->objfile = symbol_file_add_from_bfd (so->abfd, flags, sap, OBJF_SHARED);
1076 + fprintf_unfiltered (gdb_stdlog,
1077 + "symbol_add_stub: adding symbols for main\n");
1078 + so->objfile = symbol_file_add_from_bfd (so->abfd, (flags & ~SYMFILE_VERBOSE) | SYMFILE_MAINLINE, sap, 0);
1079 + so->main_relocated = 1;
1082 + so->objfile = symbol_file_add_from_bfd (so->abfd, flags, sap, OBJF_SHARED);
1084 free_section_addr_info (sap);
1087 @@ -596,6 +624,10 @@ update_solib_list (int from_tty, struct
1092 + fprintf_unfiltered (gdb_stdlog,
1093 + "update_solib_list: compare gdb:%s and inferior:%s\n",
1094 + gdb->so_original_name, i->so_original_name);
1095 if (! strcmp (gdb->so_original_name, i->so_original_name))
1098 @@ -650,18 +682,7 @@ update_solib_list (int from_tty, struct
1099 /* Fill in the rest of each of the `struct so_list' nodes. */
1100 for (i = inferior; i; i = i->next)
1102 - i->from_tty = from_tty;
1104 - /* Fill in the rest of the `struct so_list' node. */
1105 - catch_errors (solib_map_sections, i,
1106 - "Error while mapping shared library sections:\n",
1109 - /* Add the shared object's sections to the current set of
1110 - file section tables. Do this immediately after mapping
1111 - the object so that later nodes in the list can query this
1112 - object, as is needed in solib-osf.c. */
1113 - add_target_sections (i->sections, i->sections_end);
1114 + add_to_target_sections (from_tty, target, i);
1116 /* Notify any observer that the shared object has been
1117 loaded now that we've added it to GDB's tables. */
1118 @@ -771,6 +792,32 @@ solib_add (char *pattern, int from_tty,
1123 +add_to_target_sections (int from_tty, struct target_ops *target, struct so_list *solib)
1125 + /* If this is set, then the sections have been already added to the
1130 + solib->from_tty = from_tty;
1132 + /* Fill in the rest of the `struct so_list' node. */
1133 + catch_errors (solib_map_sections, solib,
1134 + "Error while mapping shared library sections:\n",
1138 + fprintf_unfiltered (gdb_stdlog,
1139 + "add_to_target_sections: add %s to to_sections\n",
1140 + solib->so_original_name);
1142 + /* Add the shared object's sections to the current set of
1143 + file section tables. Do this immediately after mapping
1144 + the object so that later nodes in the list can query this
1145 + object, as is needed in solib-osf.c. */
1146 + add_target_sections (solib->sections, solib->sections_end);
1151 @@ -1189,4 +1236,12 @@ This takes precedence over the environme
1152 reload_shared_libraries,
1153 show_solib_search_path,
1154 &setlist, &showlist);
1156 + add_setshow_boolean_cmd ("solib", no_class, &debug_solib,
1158 +Set debugging of GNU/Linux shlib module.\n"), _("\
1159 +Show debugging status of GNU/Linux shlib module.\n"), _("\
1160 +Enables printf debugging output of GNU/Linux shlib module.\n"),
1162 + &setdebuglist, &showdebuglist);
1164 Index: gdb-6.8.91.20090925/gdb/solist.h
1165 ===================================================================
1166 --- gdb-6.8.91.20090925.orig/gdb/solist.h 2009-09-25 10:25:38.000000000 +0200
1167 +++ gdb-6.8.91.20090925/gdb/solist.h 2009-09-25 10:25:45.000000000 +0200
1168 @@ -61,6 +61,8 @@ struct so_list
1170 char symbols_loaded; /* flag: symbols read in yet? */
1171 char from_tty; /* flag: print msgs? */
1172 + char main; /* flag: is this the main executable? */
1173 + char main_relocated; /* flag: has it been relocated yet? */
1174 struct objfile *objfile; /* objfile for loaded lib */
1175 struct target_section *sections;
1176 struct target_section *sections_end;
1177 @@ -147,4 +149,10 @@ struct symbol *solib_global_lookup (cons
1179 const domain_enum domain);
1181 +/* Add the list of sections in so_list to the target to_sections. */
1182 +extern void add_to_target_sections (int, struct target_ops *, struct so_list *);
1184 +/* Controls the printing of debugging output. */
1185 +extern int debug_solib;
1188 Index: gdb-6.8.91.20090925/gdb/symfile-mem.c
1189 ===================================================================
1190 --- gdb-6.8.91.20090925.orig/gdb/symfile-mem.c 2009-09-25 10:25:38.000000000 +0200
1191 +++ gdb-6.8.91.20090925/gdb/symfile-mem.c 2009-09-25 10:25:45.000000000 +0200
1192 @@ -115,7 +115,7 @@ symbol_file_add_from_memory (struct bfd
1196 - objf = symbol_file_add_from_bfd (nbfd, from_tty ? SYMFILE_VERBOSE : 0,
1197 + objf = symbol_file_add_from_bfd (nbfd, (from_tty ? SYMFILE_VERBOSE : 0) | SYMFILE_MAINLINE2_BOTH,
1200 /* This might change our ideas about frames already looked at. */
1201 Index: gdb-6.8.91.20090925/gdb/symfile.c
1202 ===================================================================
1203 --- gdb-6.8.91.20090925.orig/gdb/symfile.c 2009-09-25 10:25:39.000000000 +0200
1204 +++ gdb-6.8.91.20090925/gdb/symfile.c 2009-09-25 10:25:45.000000000 +0200
1206 #include "readline/readline.h"
1207 #include "gdb_assert.h"
1209 +#include "varobj.h"
1210 #include "observer.h"
1212 #include "parser-defs.h"
1213 @@ -779,7 +780,7 @@ syms_from_objfile (struct objfile *objfi
1215 /* Now either addrs or offsets is non-zero. */
1218 + if ((add_flags & SYMFILE_MAINLINE) && !(add_flags & SYMFILE_MAINLINE2_ONLY))
1220 /* We will modify the main symbol table, make sure that all its users
1221 will be cleaned up if an error occurs during symbol reading. */
1222 @@ -807,7 +808,7 @@ syms_from_objfile (struct objfile *objfi
1224 We no longer warn if the lowest section is not a text segment (as
1225 happens for the PA64 port. */
1226 - if (!mainline && addrs && addrs->other[0].name)
1227 + if (/*!mainline &&*/ addrs && addrs->other[0].name)
1229 asection *lower_sect;
1231 @@ -890,7 +891,7 @@ syms_from_objfile (struct objfile *objfi
1232 init_objfile_sect_indices (objfile);
1235 - (*objfile->sf->sym_read) (objfile, mainline);
1236 + (*objfile->sf->sym_read) (objfile, add_flags & SYMFILE_MAINLINE2_ONLY ? 2 : (add_flags & SYMFILE_MAINLINE ? 1 : 0));
1238 /* Discard cleanups as symbol reading was successful. */
1240 @@ -909,17 +910,22 @@ new_symfile_objfile (struct objfile *obj
1241 /* If this is the main symbol file we have to clean up all users of the
1242 old main symbol file. Otherwise it is sufficient to fixup all the
1243 breakpoints that may have been redefined by this symbol file. */
1244 - if (add_flags & SYMFILE_MAINLINE)
1245 + if (add_flags & SYMFILE_MAINLINE && !(add_flags & SYMFILE_MAINLINE2_ONLY))
1247 /* OK, make it the "real" symbol file. */
1248 symfile_objfile = objfile;
1250 clear_symtab_users ();
1252 - else if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
1253 + else if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0
1254 + && (add_flags & SYMFILE_MAINLINE2_BOTH) == 0)
1256 breakpoint_re_set ();
1260 + /* Don't reset breakpoints or it will screw up PIE. */
1263 /* We're done reading the symbol file; finish off complaints. */
1264 clear_complaints (&symfile_complaints, 0, add_flags & SYMFILE_VERBOSE);
1265 @@ -973,7 +979,7 @@ symbol_file_add_with_addrs_or_offsets (b
1266 /* Give user a chance to burp if we'd be
1267 interactively wiping out any existing symbols. */
1269 - if ((add_flags & SYMFILE_MAINLINE)
1270 + if ((add_flags & SYMFILE_MAINLINE) && !(add_flags & SYMFILE_MAINLINE2_ONLY)
1271 && (have_full_symbols () || have_partial_symbols ())
1273 && (have_full_symbols () || have_partial_symbols ())
1274 @@ -1163,6 +1169,9 @@ symbol_file_clear (int from_tty)
1275 symfile_objfile->name)
1276 : !query (_("Discard symbol table? "))))
1277 error (_("Not confirmed."));
1282 free_all_objfiles ();
1284 @@ -3367,6 +3376,8 @@ reread_symbols (void)
1285 /* Discard cleanups as symbol reading was successful. */
1286 discard_cleanups (old_cleanups);
1288 + init_entry_point_info (objfile);
1290 /* If the mtime has changed between the time we set new_modtime
1291 and now, we *want* this to be out of date, so don't call stat
1293 Index: gdb-6.8.91.20090925/gdb/target.h
1294 ===================================================================
1295 --- gdb-6.8.91.20090925.orig/gdb/target.h 2009-09-25 10:25:38.000000000 +0200
1296 +++ gdb-6.8.91.20090925/gdb/target.h 2009-09-25 10:25:45.000000000 +0200
1297 @@ -545,7 +545,7 @@ struct target_ops
1298 Return -1 if there is insufficient buffer for a whole entry.
1299 Return 1 if an entry was read into *TYPEP and *VALP. */
1300 int (*to_auxv_parse) (struct target_ops *ops, gdb_byte **readptr,
1301 - gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
1302 + gdb_byte *endptr, ULONGEST *typep, CORE_ADDR *valp);
1304 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
1305 sequence of bytes in PATTERN with length PATTERN_LEN.
1306 Index: gdb-6.8.91.20090925/gdb/symfile.h
1307 ===================================================================
1308 --- gdb-6.8.91.20090925.orig/gdb/symfile.h 2009-09-25 10:25:39.000000000 +0200
1309 +++ gdb-6.8.91.20090925/gdb/symfile.h 2009-09-25 10:25:45.000000000 +0200
1310 @@ -229,7 +229,13 @@ enum symfile_add_flags
1311 SYMFILE_MAINLINE = 1 << 2,
1313 /* Do not call breakpoint_re_set when adding this symbol file. */
1314 - SYMFILE_DEFER_BP_RESET = 1 << 3
1315 + SYMFILE_DEFER_BP_RESET = 1 << 3,
1317 + /* Red Hat PIE patch: Like SYMFILE_MAINLINE but for mainline == 2.
1318 + Former code was checking `if (mainline)' being satisfied both by
1319 + standard 1 and rare 2, simulate it here. */
1320 + SYMFILE_MAINLINE2_ONLY = 1 << 4,
1321 + SYMFILE_MAINLINE2_BOTH = SYMFILE_MAINLINE2_ONLY | SYMFILE_MAINLINE
1324 extern void syms_from_objfile (struct objfile *,
1325 Index: gdb-6.8.91.20090925/gdb/infcmd.c
1326 ===================================================================
1327 --- gdb-6.8.91.20090925.orig/gdb/infcmd.c 2009-09-25 10:25:39.000000000 +0200
1328 +++ gdb-6.8.91.20090925/gdb/infcmd.c 2009-09-25 10:25:45.000000000 +0200
1329 @@ -2308,6 +2308,9 @@ attach_command_post_wait (char *args, in
1331 post_create_inferior (¤t_target, from_tty);
1333 + /* Undo the disable from post_create_inferior. */
1334 + enable_breakpoints_after_startup ();
1336 /* Install inferior's terminal modes. */
1337 target_terminal_inferior ();
1339 Index: gdb-6.8.91.20090925/gdb/linux-tdep.c
1340 ===================================================================
1341 --- gdb-6.8.91.20090925.orig/gdb/linux-tdep.c 2009-08-04 22:41:13.000000000 +0200
1342 +++ gdb-6.8.91.20090925/gdb/linux-tdep.c 2009-09-25 10:25:45.000000000 +0200
1343 @@ -163,5 +163,7 @@ in this session.\n"));
1345 _initialize_linux_tdep (void)
1347 +#if 0 /* gdb-6.3-pie-20050110.patch */
1348 observer_attach_executable_changed (check_is_pie_binary);