1 Index: gdb-7.2.90.20110429/gdb/corelow.c
2 ===================================================================
3 --- gdb-7.2.90.20110429.orig/gdb/corelow.c 2011-02-26 03:07:07.000000000 +0100
4 +++ gdb-7.2.90.20110429/gdb/corelow.c 2011-05-03 05:14:57.000000000 +0200
10 +#include "elf/common.h"
15 @@ -278,6 +281,52 @@ add_to_thread_list (bfd *abfd, asection
16 inferior_ptid = ptid; /* Yes, make it current. */
19 +static int build_id_core_loads = 1;
22 +build_id_locate_exec (int from_tty)
25 + struct build_id *build_id;
26 + char *exec_filename, *debug_filename;
27 + char *build_id_filename;
28 + struct cleanup *back_to;
30 + if (exec_bfd != NULL || symfile_objfile != NULL)
33 + if (target_auxv_search (¤t_target, AT_ENTRY, &at_entry) <= 0)
36 + build_id = build_id_addr_get (at_entry);
37 + if (build_id == NULL)
40 + /* SYMFILE_OBJFILE should refer to the main executable (not only to its
41 + separate debug info file). gcc44+ keeps .eh_frame only in the main
42 + executable without its duplicate .debug_frame in the separate debug info
43 + file - such .eh_frame would not be found if SYMFILE_OBJFILE would refer
44 + directly to the separate debug info file. */
46 + exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
47 + back_to = make_cleanup (xfree, build_id_filename);
49 + if (exec_filename != NULL)
51 + make_cleanup (xfree, exec_filename);
52 + exec_file_attach (exec_filename, from_tty);
53 + symbol_file_add_main (exec_filename, from_tty);
54 + if (symfile_objfile != NULL)
55 + symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
58 + debug_print_missing (_("the main executable file"), build_id_filename);
60 + do_cleanups (back_to);
62 + /* No automatic SOLIB_ADD as the libraries would get read twice. */
65 /* This routine opens and sets up the core file bfd. */
68 @@ -379,6 +428,12 @@ core_open (char *filename, int from_tty)
69 push_target (&core_ops);
70 discard_cleanups (old_chain);
72 + /* Find the build_id identifiers. If it gets executed after
73 + POST_CREATE_INFERIOR we would clash with asking to discard the already
74 + loaded VDSO symbols. */
75 + if (build_id_core_loads != 0)
76 + build_id_locate_exec (from_tty);
78 /* Do this before acknowledging the inferior, so if
79 post_create_inferior throws (can happen easilly if you're loading
80 a core file with the wrong exec), we aren't left with threads
81 @@ -932,4 +987,11 @@ _initialize_corelow (void)
84 add_target (&core_ops);
86 + add_setshow_boolean_cmd ("build-id-core-loads", class_files,
87 + &build_id_core_loads, _("\
88 +Set whether CORE-FILE loads the build-id associated files automatically."), _("\
89 +Show whether CORE-FILE loads the build-id associated files automatically.."),
91 + &setlist, &showlist);
93 Index: gdb-7.2.90.20110429/gdb/doc/gdb.texinfo
94 ===================================================================
95 --- gdb-7.2.90.20110429.orig/gdb/doc/gdb.texinfo 2011-05-03 05:14:56.000000000 +0200
96 +++ gdb-7.2.90.20110429/gdb/doc/gdb.texinfo 2011-05-03 05:14:57.000000000 +0200
97 @@ -15356,6 +15356,27 @@ information files.
101 +You can also adjust the current verbosity of the @dfn{build id} locating.
105 +@kindex set build-id-verbose
106 +@item set build-id-verbose 0
107 +No additional messages are printed.
109 +@item set build-id-verbose 1
110 +Missing separate debug filenames are printed.
112 +@item set build-id-verbose 2
113 +Missing separate debug filenames are printed and also all the parsing of the
114 +binaries to find their @dfn{build id} content is printed.
116 +@kindex show build-id-verbose
117 +@item show build-id-verbose
118 +Show the current verbosity value for the @dfn{build id} content locating.
122 @cindex @code{.gnu_debuglink} sections
123 @cindex debug link sections
124 A debug link is a special section of the executable file named
125 Index: gdb-7.2.90.20110429/gdb/solib-svr4.c
126 ===================================================================
127 --- gdb-7.2.90.20110429.orig/gdb/solib-svr4.c 2011-05-03 05:14:56.000000000 +0200
128 +++ gdb-7.2.90.20110429/gdb/solib-svr4.c 2011-05-03 05:14:57.000000000 +0200
129 @@ -1179,9 +1179,49 @@ svr4_current_sos (void)
130 safe_strerror (errcode));
133 - strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
134 - new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
135 - strcpy (new->so_original_name, new->so_name);
136 + struct build_id *build_id;
138 + strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
139 + new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
140 + /* May get overwritten below. */
141 + strcpy (new->so_name, new->so_original_name);
143 + build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
144 + if (build_id != NULL)
146 + char *name, *build_id_filename;
148 + /* Missing the build-id matching separate debug info file
149 + would be handled while SO_NAME gets loaded. */
150 + name = build_id_to_filename (build_id, &build_id_filename, 0);
153 + strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
154 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
159 + debug_print_missing (new->so_name, build_id_filename);
161 + /* In the case the main executable was found according to
162 + its build-id (from a core file) prevent loading
163 + a different build of a library with accidentally the
166 + It suppresses bogus backtraces (and prints "??" there
167 + instead) if the on-disk files no longer match the
168 + running program version. */
170 + if (symfile_objfile != NULL
171 + && (symfile_objfile->flags
172 + & OBJF_BUILD_ID_CORE_LOADED) != 0)
173 + new->so_name[0] = 0;
176 + xfree (build_id_filename);
182 Index: gdb-7.2.90.20110429/gdb/elfread.c
183 ===================================================================
184 --- gdb-7.2.90.20110429.orig/gdb/elfread.c 2011-05-03 05:14:56.000000000 +0200
185 +++ gdb-7.2.90.20110429/gdb/elfread.c 2011-05-03 05:19:27.000000000 +0200
188 #include "gdbthread.h"
189 #include "regcache.h"
191 +#include "gdbcore.h"
193 +#include "observer.h"
194 +#include <sys/stat.h>
196 extern void _initialize_elfread (void);
198 @@ -1077,16 +1082,65 @@ elf_gnu_ifunc_resolver_return_stop (stru
199 update_breakpoint_locations (b, sals, sals_end);
202 +#define BUILD_ID_VERBOSE_NONE 0
203 +#define BUILD_ID_VERBOSE_FILENAMES 1
204 +#define BUILD_ID_VERBOSE_BINARY_PARSE 2
205 +static int build_id_verbose = BUILD_ID_VERBOSE_FILENAMES;
207 +show_build_id_verbose (struct ui_file *file, int from_tty,
208 + struct cmd_list_element *c, const char *value)
210 + fprintf_filtered (file, _("Verbosity level of the build-id locator is %s.\n"),
220 -/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */
221 +/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
222 + FIXME: NOTE decoding should be unified with the BFD core notes decoding. */
225 +build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
230 + while (p < buf + size)
232 + /* FIXME: bad alignment assumption. */
233 + Elf_External_Note *xnp = (Elf_External_Note *) p;
234 + size_t namesz = H_GET_32 (templ, xnp->namesz);
235 + size_t descsz = H_GET_32 (templ, xnp->descsz);
236 + bfd_byte *descdata = xnp->name + BFD_ALIGN (namesz, 4);
238 + if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
239 + && namesz == sizeof "GNU"
240 + && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
242 + size_t size = descsz;
243 + gdb_byte *data = (void *) descdata;
244 + struct build_id *retval;
246 + retval = xmalloc (sizeof *retval - 1 + size);
247 + retval->size = size;
248 + memcpy (retval->data, data, size);
252 + p = descdata + BFD_ALIGN (descsz, 4);
257 +/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
258 + Locate NT_GNU_BUILD_ID from ABFD and return its content. */
260 static struct build_id *
261 -build_id_bfd_get (bfd *abfd)
262 +build_id_bfd_shdr_get (bfd *abfd)
264 struct build_id *retval;
266 @@ -1102,6 +1156,348 @@ build_id_bfd_get (bfd *abfd)
270 +/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
271 + bfd_elf_bfd_from_remote_memory () has too much overhead by
272 + allocating/reading all the available ELF PT_LOADs. */
274 +static struct build_id *
275 +build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
276 + Elf_Internal_Phdr *i_phdr)
279 + struct build_id *retval = NULL;
281 + for (i = 0; i < e_phnum; i++)
282 + if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
284 + Elf_Internal_Phdr *hdr = &i_phdr[i];
288 + buf = xmalloc (hdr->p_filesz);
289 + err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
292 + retval = build_id_buf_get (templ, buf, hdr->p_filesz);
296 + if (retval != NULL)
302 +/* First we validate the file by reading in the ELF header and checking
303 + the magic number. */
305 +static inline bfd_boolean
306 +elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
308 + gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
309 + gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
310 + == offsetof (Elf32_External_Ehdr, e_ident));
311 + gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
312 + == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
314 + return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
315 + && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
316 + && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
317 + && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
320 +/* Translate an ELF file header in external format into an ELF file header in
321 + internal format. */
323 +#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr)) \
324 + : H_GET_32 (bfd, (ptr)))
325 +#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr)) \
326 + : H_GET_S32 (bfd, (ptr)))
329 +elf_swap_ehdr_in (bfd *abfd,
330 + const Elf64_External_Ehdr *src64,
331 + Elf_Internal_Ehdr *dst)
333 + int is64 = bfd_get_arch_size (abfd) == 64;
334 +#define SRC(field) (is64 ? src64->field \
335 + : ((const Elf32_External_Ehdr *) src64)->field)
337 + int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
338 + memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
339 + dst->e_type = H_GET_16 (abfd, SRC (e_type));
340 + dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
341 + dst->e_version = H_GET_32 (abfd, SRC (e_version));
343 + dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
345 + dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
346 + dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
347 + dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
348 + dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
349 + dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
350 + dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
351 + dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
352 + dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
353 + dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
354 + dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
359 +/* Translate an ELF program header table entry in external format into an
360 + ELF program header table entry in internal format. */
363 +elf_swap_phdr_in (bfd *abfd,
364 + const Elf64_External_Phdr *src64,
365 + Elf_Internal_Phdr *dst)
367 + int is64 = bfd_get_arch_size (abfd) == 64;
368 +#define SRC(field) (is64 ? src64->field \
369 + : ((const Elf32_External_Phdr *) src64)->field)
371 + int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
373 + dst->p_type = H_GET_32 (abfd, SRC (p_type));
374 + dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
375 + dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
378 + dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
379 + dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
383 + dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
384 + dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
386 + dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
387 + dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
388 + dst->p_align = H_GET_WORD (abfd, SRC (p_align));
393 +#undef H_GET_SIGNED_WORD
396 +static Elf_Internal_Phdr *
397 +elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
398 + bfd_vma *loadbase_pointer)
400 + /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr) */
401 + Elf64_External_Ehdr x_ehdr64; /* Elf file header, external form */
402 + Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
403 + bfd_size_type x_phdrs_size;
404 + gdb_byte *x_phdrs_ptr;
405 + Elf_Internal_Phdr *i_phdrs;
411 + gdb_assert (templ != NULL);
412 + gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
414 + /* Read in the ELF header in external format. */
415 + err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
418 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
419 + warning (_("build-id: Error reading ELF header at address 0x%lx"),
420 + (unsigned long) ehdr_vma);
424 + /* Now check to see if we have a valid ELF file, and one that BFD can
425 + make use of. The magic number must match, the address size ('class')
426 + and byte-swapping must match our XVEC entry. */
428 + if (! elf_file_p (&x_ehdr64)
429 + || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
430 + || !((bfd_get_arch_size (templ) == 64
431 + && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
432 + || (bfd_get_arch_size (templ) == 32
433 + && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
435 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
436 + warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
437 + (unsigned long) ehdr_vma);
441 + /* Check that file's byte order matches xvec's */
442 + switch (x_ehdr64.e_ident[EI_DATA])
444 + case ELFDATA2MSB: /* Big-endian */
445 + if (! bfd_header_big_endian (templ))
447 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
448 + warning (_("build-id: Unrecognized "
449 + "big-endian ELF header at address 0x%lx"),
450 + (unsigned long) ehdr_vma);
454 + case ELFDATA2LSB: /* Little-endian */
455 + if (! bfd_header_little_endian (templ))
457 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
458 + warning (_("build-id: Unrecognized "
459 + "little-endian ELF header at address 0x%lx"),
460 + (unsigned long) ehdr_vma);
464 + case ELFDATANONE: /* No data encoding specified */
465 + default: /* Unknown data encoding specified */
466 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
467 + warning (_("build-id: Unrecognized "
468 + "ELF header endianity at address 0x%lx"),
469 + (unsigned long) ehdr_vma);
473 + elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
475 + /* The file header tells where to find the program headers.
476 + These are what we use to actually choose what to read. */
478 + if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
479 + ? sizeof (Elf64_External_Phdr)
480 + : sizeof (Elf32_External_Phdr))
481 + || i_ehdr.e_phnum == 0)
483 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
484 + warning (_("build-id: Invalid ELF program headers from the ELF header "
485 + "at address 0x%lx"), (unsigned long) ehdr_vma);
489 + x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
490 + : sizeof (Elf32_External_Phdr));
492 + i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
493 + x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
494 + err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
495 + i_ehdr.e_phnum * x_phdrs_size);
499 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
500 + warning (_("build-id: Error reading "
501 + "ELF program headers at address 0x%lx"),
502 + (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
506 + loadbase = ehdr_vma;
508 + for (i = 0; i < i_ehdr.e_phnum; ++i)
510 + elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
511 + (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
512 + /* IA-64 vDSO may have two mappings for one segment, where one mapping
513 + is executable only, and one is read only. We must not use the
514 + executable one (PF_R is the first one, PF_X the second one). */
515 + if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
517 + /* Only the first PT_LOAD segment indicates the file bias.
518 + Next segments may have P_VADDR arbitrarily higher.
519 + If the first segment has P_VADDR zero any next segment must not
520 + confuse us, the first one sets LOADBASE certainly enough. */
521 + if (!loadbase_set && i_phdrs[i].p_offset == 0)
523 + loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
529 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
530 + warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
531 + (unsigned long) ehdr_vma, (unsigned long) loadbase);
533 + *e_phnum_pointer = i_ehdr.e_phnum;
534 + *loadbase_pointer = loadbase;
538 +/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
539 + Find the first section before ADDR containing an ELF header.
540 + We rely on the fact the sections from multiple files do not mix.
541 + FIXME: We should check ADDR is contained _inside_ the section with possibly
542 + missing content (P_FILESZ < P_MEMSZ). These omitted sections are currently
543 + hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR. */
545 +static CORE_ADDR build_id_addr;
546 +struct build_id_addr_sect
548 + struct build_id_addr_sect *next;
551 +static struct build_id_addr_sect *build_id_addr_sect;
553 +static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
555 + if (build_id_addr >= bfd_section_vma (abfd, sect))
557 + struct build_id_addr_sect *candidate;
559 + candidate = xmalloc (sizeof *candidate);
560 + candidate->next = build_id_addr_sect;
561 + build_id_addr_sect = candidate;
562 + candidate->sect = sect;
567 +build_id_addr_get (CORE_ADDR addr)
569 + struct build_id_addr_sect *candidate;
570 + struct build_id *retval = NULL;
571 + Elf_Internal_Phdr *i_phdr = NULL;
572 + bfd_vma loadbase = 0;
573 + unsigned e_phnum = 0;
575 + if (core_bfd == NULL)
578 + build_id_addr = addr;
579 + gdb_assert (build_id_addr_sect == NULL);
580 + bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
582 + /* Sections are sorted in the high-to-low VMAs order.
583 + Stop the search on the first ELF header we find.
584 + Do not continue the search even if it does not contain NT_GNU_BUILD_ID. */
586 + for (candidate = build_id_addr_sect; candidate != NULL;
587 + candidate = candidate->next)
589 + i_phdr = elf_get_phdr (core_bfd,
590 + bfd_section_vma (core_bfd, candidate->sect),
591 + &e_phnum, &loadbase);
592 + if (i_phdr != NULL)
596 + if (i_phdr != NULL)
598 + retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
602 + while (build_id_addr_sect != NULL)
604 + candidate = build_id_addr_sect;
605 + build_id_addr_sect = candidate->next;
612 /* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */
615 @@ -1116,7 +1512,7 @@ build_id_verify (const char *filename, s
619 - found = build_id_bfd_get (abfd);
620 + found = build_id_bfd_shdr_get (abfd);
623 warning (_("File \"%s\" has no build-id, file skipped"), filename);
624 @@ -1134,14 +1530,15 @@ build_id_verify (const char *filename, s
629 -build_id_to_debug_filename (struct build_id *build_id)
631 +build_id_to_filename (struct build_id *build_id, char **link_return,
632 + int add_debug_suffix)
634 char *link, *debugdir, *retval = NULL;
635 + char *link_all = NULL;
637 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
638 - link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
639 - + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
640 + link = xmalloc (strlen (debug_file_directory) + 2 * build_id->size + 50);
642 /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
643 cause "/.build-id/..." lookups. */
644 @@ -1152,6 +1549,8 @@ build_id_to_debug_filename (struct build
645 char *s, *debugdir_end;
646 gdb_byte *data = build_id->data;
647 size_t size = build_id->size;
649 + struct stat statbuf_trash;
651 while (*debugdir == DIRNAME_SEPARATOR)
653 @@ -1172,39 +1571,242 @@ build_id_to_debug_filename (struct build
656 s += sprintf (s, "%02x", (unsigned) *data++);
657 - strcpy (s, ".debug");
659 - /* lrealpath() is expensive even for the usually non-existent files. */
660 - if (access (link, F_OK) == 0)
661 - retval = lrealpath (link);
663 - if (retval != NULL && !build_id_verify (retval, build_id))
664 + for (seqno = 0;; seqno++)
672 + /* There can be multiple build-id symlinks pointing to real files
673 + with the same build-id (such as hard links). Some of the real
674 + files may not be installed. */
676 + s2 = s + sprintf (s, ".%u", seqno);
681 + if (add_debug_suffix)
682 + strcpy (s2, ".debug");
686 + /* `access' automatically dereferences LINK. */
687 + if (lstat (link, &statbuf_trash) != 0)
689 + /* Stop increasing SEQNO. */
693 + retval = lrealpath (link);
695 + if (retval != NULL && !build_id_verify (retval, build_id))
708 + /* LINK_ALL is not used below in this non-NULL RETVAL case. */
712 + if (link_all == NULL)
713 + link_all = xstrdup (link);
716 + size_t len_orig = strlen (link_all);
718 + link_all = xrealloc (link_all, len_orig + 1 + strlen (link) + 1);
720 + /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
721 + its possible use as an argument for installation command. */
722 + link_all[len_orig] = ' ';
724 + strcpy (&link_all[len_orig + 1], link);
727 debugdir = debugdir_end;
729 while (*debugdir != 0);
731 + if (link_return != NULL)
733 + if (retval != NULL)
735 + *link_return = link;
740 + *link_return = link_all;
750 +/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
751 + Try to install the hash file ...
754 +struct missing_filepair
761 +static struct htab *missing_filepair_hash;
762 +static struct obstack missing_filepair_obstack;
765 +missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
768 + size_t size = nmemb * nmemb_size;
770 + retval = obstack_alloc (&missing_filepair_obstack, size);
771 + memset (retval, 0, size);
776 +missing_filepair_hash_func (const struct missing_filepair *elem)
778 + hashval_t retval = 0;
780 + retval ^= htab_hash_string (elem->binary);
781 + if (elem->debug != NULL)
782 + retval ^= htab_hash_string (elem->debug);
788 +missing_filepair_eq (const struct missing_filepair *elem1,
789 + const struct missing_filepair *elem2)
791 + return strcmp (elem1->binary, elem2->binary) == 0
792 + && ((elem1->debug == NULL) == (elem2->debug == NULL))
793 + && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
797 +missing_filepair_change (void)
799 + if (missing_filepair_hash != NULL)
801 + obstack_free (&missing_filepair_obstack, NULL);
802 + /* All their memory came just from missing_filepair_OBSTACK. */
803 + missing_filepair_hash = NULL;
808 +debug_print_executable_changed (void)
810 + missing_filepair_change ();
813 +/* Notify user the file BINARY with (possibly NULL) associated separate debug
814 + information file DEBUG is missing. DEBUG may or may not be the build-id
815 + file such as would be:
816 + /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
820 +debug_print_missing (const char *binary, const char *debug)
822 + size_t binary_len0 = strlen (binary) + 1;
823 + size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
824 + struct missing_filepair missing_filepair_find;
825 + struct missing_filepair *missing_filepair;
826 + struct missing_filepair **slot;
828 + if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
831 + if (missing_filepair_hash == NULL)
833 + obstack_init (&missing_filepair_obstack);
834 + missing_filepair_hash = htab_create_alloc (64,
835 + (hashval_t (*) (const void *)) missing_filepair_hash_func,
836 + (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
837 + missing_filepair_xcalloc, NULL);
840 + /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
841 + obstack_free in the case of a (rare) match. The problem is ALLOC_F for
842 + MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
843 + structures for MISSING_FILEPAIR_HASH. Calling obstack_free would possibly
844 + not to free only MISSING_FILEPAIR but also some such structures (allocated
845 + during the htab_find_slot call). */
847 + missing_filepair_find.binary = (char *) binary;
848 + missing_filepair_find.debug = (char *) debug;
849 + slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
850 + &missing_filepair_find,
853 + /* While it may be still printed duplicitely with the missing debuginfo file
854 + * it is due to once printing about the binary file build-id link and once
855 + * about the .debug file build-id link as both the build-id symlinks are
856 + * located in the debuginfo package. */
861 + missing_filepair = obstack_alloc (&missing_filepair_obstack,
862 + sizeof (*missing_filepair) - 1
863 + + binary_len0 + debug_len0);
864 + missing_filepair->binary = missing_filepair->data;
865 + memcpy (missing_filepair->binary, binary, binary_len0);
868 + missing_filepair->debug = missing_filepair->binary + binary_len0;
869 + memcpy (missing_filepair->debug, debug, debug_len0);
872 + missing_filepair->debug = NULL;
874 + *slot = missing_filepair;
876 + /* We do not collect and flush these messages as each such message
877 + already requires its own separate lines. */
879 + fprintf_unfiltered (gdb_stdlog,
880 + _("Missing separate debuginfo for %s\n"), binary);
882 + fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
887 -find_separate_debug_file_by_buildid (struct objfile *objfile)
888 +find_separate_debug_file_by_buildid (struct objfile *objfile,
889 + char **build_id_filename_return)
891 struct build_id *build_id;
893 - build_id = build_id_bfd_get (objfile->obfd);
894 + if (build_id_filename_return)
895 + *build_id_filename_return = NULL;
897 + build_id = build_id_bfd_shdr_get (objfile->obfd);
898 if (build_id != NULL)
902 - build_id_name = build_id_to_debug_filename (build_id);
903 + build_id_name = build_id_to_filename (build_id, build_id_filename_return,
906 /* Prevent looping on a stripped .debug file. */
907 if (build_id_name != NULL
908 @@ -1215,7 +1817,7 @@ find_separate_debug_file_by_buildid (str
909 xfree (build_id_name);
911 else if (build_id_name != NULL)
912 - return build_id_name;
913 + return build_id_name;
917 @@ -1418,9 +2020,10 @@ elf_symfile_read (struct objfile *objfil
918 `.note.gnu.build-id'. */
919 else if (!objfile_has_partial_symbols (objfile))
922 + char *debugfile, *build_id_filename;
924 - debugfile = find_separate_debug_file_by_buildid (objfile);
925 + debugfile = find_separate_debug_file_by_buildid (objfile,
926 + &build_id_filename);
928 if (debugfile == NULL)
929 debugfile = find_separate_debug_file_by_debuglink (objfile);
930 @@ -1432,6 +2035,12 @@ elf_symfile_read (struct objfile *objfil
931 symbol_file_add_separate (abfd, symfile_flags, objfile);
934 + /* Check if any separate debug info has been extracted out. */
935 + else if (bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink")
937 + debug_print_missing (objfile->name, build_id_filename);
939 + xfree (build_id_filename);
943 @@ -1911,4 +2520,16 @@ _initialize_elfread (void)
945 elf_objfile_gnu_ifunc_cache_data = register_objfile_data ();
946 gnu_ifunc_fns_p = &elf_gnu_ifunc_fns;
948 + add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
950 +Set debugging level of the build-id locator."), _("\
951 +Show debugging level of the build-id locator."), _("\
952 +Level 1 (default) enables printing the missing debug filenames,\n\
953 +level 2 also prints the parsing of binaries to find the identificators."),
955 + show_build_id_verbose,
956 + &setlist, &showlist);
958 + observer_attach_executable_changed (debug_print_executable_changed);
960 Index: gdb-7.2.90.20110429/gdb/symfile.h
961 ===================================================================
962 --- gdb-7.2.90.20110429.orig/gdb/symfile.h 2011-05-03 05:14:56.000000000 +0200
963 +++ gdb-7.2.90.20110429/gdb/symfile.h 2011-05-03 05:14:57.000000000 +0200
964 @@ -605,6 +605,13 @@ void free_symfile_segment_data (struct s
966 extern struct cleanup *increment_reading_symtab (void);
968 +/* build-id support. */
970 +extern struct build_id *build_id_addr_get (CORE_ADDR addr);
971 +extern char *build_id_to_filename (struct build_id *build_id,
972 + char **link_return, int add_debug_suffix);
973 +extern void debug_print_missing (const char *binary, const char *debug);
975 /* From dwarf2read.c */
977 extern int dwarf2_has_info (struct objfile *);
978 Index: gdb-7.2.90.20110429/gdb/testsuite/lib/gdb.exp
979 ===================================================================
980 --- gdb-7.2.90.20110429.orig/gdb/testsuite/lib/gdb.exp 2011-05-03 05:14:56.000000000 +0200
981 +++ gdb-7.2.90.20110429/gdb/testsuite/lib/gdb.exp 2011-05-03 05:14:57.000000000 +0200
982 @@ -1381,6 +1381,16 @@ proc default_gdb_start { } {
983 warning "Couldn't set the width to 0."
986 + # Turn off the missing warnings as the testsuite does not expect it.
987 + send_gdb "set build-id-verbose 0\n"
989 + -re "$gdb_prompt $" {
990 + verbose "Disabled the missing debug infos warnings." 2
993 + warning "Could not disable the missing debug infos warnings.."
999 Index: gdb-7.2.90.20110429/gdb/testsuite/lib/mi-support.exp
1000 ===================================================================
1001 --- gdb-7.2.90.20110429.orig/gdb/testsuite/lib/mi-support.exp 2011-03-07 17:03:04.000000000 +0100
1002 +++ gdb-7.2.90.20110429/gdb/testsuite/lib/mi-support.exp 2011-05-03 05:14:57.000000000 +0200
1003 @@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
1007 + # Turn off the missing warnings as the testsuite does not expect it.
1008 + send_gdb "190-gdb-set build-id-verbose 0\n"
1010 + -re ".*190-gdb-set build-id-verbose 0\r\n190\\\^done\r\n$mi_gdb_prompt$" {
1011 + verbose "Disabled the missing debug infos warnings." 2
1014 + warning "Could not disable the missing debug infos warnings.."
1020 Index: gdb-7.2.90.20110429/gdb/objfiles.h
1021 ===================================================================
1022 --- gdb-7.2.90.20110429.orig/gdb/objfiles.h 2011-03-07 17:17:29.000000000 +0100
1023 +++ gdb-7.2.90.20110429/gdb/objfiles.h 2011-05-03 05:14:57.000000000 +0200
1024 @@ -441,6 +441,10 @@ struct objfile
1026 #define OBJF_PSYMTABS_READ (1 << 4)
1028 +/* This file was loaded according to the BUILD_ID_CORE_LOADS rules. */
1030 +#define OBJF_BUILD_ID_CORE_LOADED (1 << 12)
1032 /* The object file that contains the runtime common minimal symbols
1033 for SunOS4. Note that this objfile has no associated BFD. */