1 Index: gdb-6.8.50.20090302/gdb/corelow.c
2 ===================================================================
3 --- gdb-6.8.50.20090302.orig/gdb/corelow.c 2009-02-23 01:03:48.000000000 +0100
4 +++ gdb-6.8.50.20090302/gdb/corelow.c 2009-03-07 17:04:57.000000000 +0100
6 #include "exceptions.h"
10 +#include "elf/common.h"
11 +#include "objfiles.h"
16 @@ -267,6 +271,56 @@ add_to_thread_list (bfd *abfd, asection
17 inferior_ptid = ptid; /* Yes, make it current */
20 +static int build_id_core_loads = 1;
23 +build_id_locate_exec (int from_tty)
26 + struct build_id *build_id;
27 + char *exec_filename, *debug_filename;
28 + char *build_id_filename;
30 + if (exec_bfd != 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 + exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
41 + if (exec_filename != NULL)
42 + exec_file_attach (exec_filename, from_tty);
44 + debug_print_missing (_("the main executable file"), build_id_filename);
45 + xfree (build_id_filename);
47 + /* `.note.gnu.build-id' section exists even for files without a separate
49 + debug_filename = build_id_to_filename (build_id, &build_id_filename, 1);
50 + if (debug_filename != NULL)
52 + symbol_file_add_main (debug_filename, from_tty);
53 + xfree (debug_filename);
57 + if (exec_filename != NULL)
58 + symbol_file_add_main (exec_filename, from_tty);
59 + /* For EXEC_FILENAME NULL we were already complaining above. */
60 + if (symfile_objfile == NULL && exec_filename != NULL)
61 + debug_print_missing (exec_filename, build_id_filename);
63 + xfree (build_id_filename);
65 + xfree (exec_filename);
67 + /* No automatic SOLIB_ADD as the libraries would get read twice. */
70 /* This routine opens and sets up the core file bfd. */
73 @@ -363,6 +417,12 @@ core_open (char *filename, int from_tty)
74 push_target (&core_ops);
75 discard_cleanups (old_chain);
77 + /* Find the build_id identifiers. If it gets executed after
78 + POST_CREATE_INFERIOR we would clash with asking to discard the already
79 + loaded VDSO symbols. */
80 + if (build_id_core_loads != 0)
81 + build_id_locate_exec (from_tty);
83 add_inferior_silent (corelow_pid);
85 /* Do this before acknowledging the inferior, so if
86 @@ -751,4 +811,11 @@ _initialize_corelow (void)
89 add_target (&core_ops);
91 + add_setshow_boolean_cmd ("build-id-core-loads", class_files,
92 + &build_id_core_loads, _("\
93 +Set whether CORE-FILE loads the build-id associated files automatically."), _("\
94 +Show whether CORE-FILE loads the build-id associated files automatically.."),
96 + &setlist, &showlist);
98 Index: gdb-6.8.50.20090302/gdb/doc/gdb.texinfo
99 ===================================================================
100 --- gdb-6.8.50.20090302.orig/gdb/doc/gdb.texinfo 2009-03-07 17:04:56.000000000 +0100
101 +++ gdb-6.8.50.20090302/gdb/doc/gdb.texinfo 2009-03-07 17:04:57.000000000 +0100
102 @@ -13294,6 +13294,27 @@ information files.
106 +You can also adjust the current verbosity of the @dfn{build id} locating.
110 +@kindex set build-id-verbose
111 +@item set build-id-verbose 0
112 +No additional messages are printed.
114 +@item set build-id-verbose 1
115 +Missing separate debug filenames are printed.
117 +@item set build-id-verbose 2
118 +Missing separate debug filenames are printed and also all the parsing of the
119 +binaries to find their @dfn{build id} content is printed.
121 +@kindex show build-id-verbose
122 +@item show build-id-verbose
123 +Show the current verbosity value for the @dfn{build id} content locating.
127 @cindex @code{.gnu_debuglink} sections
128 @cindex debug link sections
129 A debug link is a special section of the executable file named
130 Index: gdb-6.8.50.20090302/gdb/solib-svr4.c
131 ===================================================================
132 --- gdb-6.8.50.20090302.orig/gdb/solib-svr4.c 2009-03-07 17:04:52.000000000 +0100
133 +++ gdb-6.8.50.20090302/gdb/solib-svr4.c 2009-03-07 17:04:57.000000000 +0100
134 @@ -1000,9 +1000,33 @@ svr4_current_sos (void)
135 safe_strerror (errcode));
138 - strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
139 - new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
140 - strcpy (new->so_original_name, new->so_name);
141 + struct build_id *build_id;
143 + strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
144 + new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
145 + /* May get overwritten below. */
146 + strcpy (new->so_name, new->so_original_name);
148 + build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
149 + if (build_id != NULL)
151 + char *name, *build_id_filename;
153 + /* Missing the build-id matching separate debug info file
154 + would be handled while SO_NAME gets loaded. */
155 + name = build_id_to_filename (build_id, &build_id_filename, 0);
158 + strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
159 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
163 + debug_print_missing (new->so_name, build_id_filename);
165 + xfree (build_id_filename);
171 Index: gdb-6.8.50.20090302/gdb/symfile.c
172 ===================================================================
173 --- gdb-6.8.50.20090302.orig/gdb/symfile.c 2009-03-07 17:04:53.000000000 +0100
174 +++ gdb-6.8.50.20090302/gdb/symfile.c 2009-03-07 17:22:21.000000000 +0100
181 #include <sys/types.h>
183 @@ -1185,16 +1186,65 @@ symbol_file_clear (int from_tty)
184 printf_unfiltered (_("No symbol file now.\n"));
187 +/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
188 + FIXME: NOTE decoding should be unified with the BFD core notes decoding. */
190 +#define BUILD_ID_VERBOSE_NONE 0
191 +#define BUILD_ID_VERBOSE_FILENAMES 1
192 +#define BUILD_ID_VERBOSE_BINARY_PARSE 2
193 +static int build_id_verbose = BUILD_ID_VERBOSE_FILENAMES;
195 +show_build_id_verbose (struct ui_file *file, int from_tty,
196 + struct cmd_list_element *c, const char *value)
198 + fprintf_filtered (file, _("Verbosity level of the build-id locator is %s.\n"),
208 -/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */
210 +build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
215 + while (p < buf + size)
217 + /* FIXME: bad alignment assumption. */
218 + Elf_External_Note *xnp = (Elf_External_Note *) p;
219 + size_t namesz = H_GET_32 (templ, xnp->namesz);
220 + size_t descsz = H_GET_32 (templ, xnp->descsz);
221 + bfd_byte *descdata = xnp->name + BFD_ALIGN (namesz, 4);
223 + if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
224 + && namesz == sizeof "GNU"
225 + && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
227 + size_t size = descsz;
228 + gdb_byte *data = (void *) descdata;
229 + struct build_id *retval;
231 + retval = xmalloc (sizeof *retval - 1 + size);
232 + retval->size = size;
233 + memcpy (retval->data, data, size);
237 + p = descdata + BFD_ALIGN (descsz, 4);
242 +/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
243 + Locate NT_GNU_BUILD_ID from ABFD and return its content. */
245 static struct build_id *
246 -build_id_bfd_get (bfd *abfd)
247 +build_id_bfd_shdr_get (bfd *abfd)
249 struct build_id *retval;
251 @@ -1210,6 +1260,348 @@ build_id_bfd_get (bfd *abfd)
255 +/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
256 + bfd_elf_bfd_from_remote_memory () has too much overhead by
257 + allocating/reading all the available ELF PT_LOADs. */
259 +static struct build_id *
260 +build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
261 + Elf_Internal_Phdr *i_phdr)
264 + struct build_id *retval = NULL;
266 + for (i = 0; i < e_phnum; i++)
267 + if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
269 + Elf_Internal_Phdr *hdr = &i_phdr[i];
273 + buf = xmalloc (hdr->p_filesz);
274 + err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
277 + retval = build_id_buf_get (templ, buf, hdr->p_filesz);
281 + if (retval != NULL)
287 +/* First we validate the file by reading in the ELF header and checking
288 + the magic number. */
290 +static inline bfd_boolean
291 +elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
293 + gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
294 + gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
295 + == offsetof (Elf32_External_Ehdr, e_ident));
296 + gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
297 + == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
299 + return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
300 + && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
301 + && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
302 + && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
305 +/* Translate an ELF file header in external format into an ELF file header in
306 + internal format. */
308 +#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr)) \
309 + : H_GET_32 (bfd, (ptr)))
310 +#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr)) \
311 + : H_GET_S32 (bfd, (ptr)))
314 +elf_swap_ehdr_in (bfd *abfd,
315 + const Elf64_External_Ehdr *src64,
316 + Elf_Internal_Ehdr *dst)
318 + int is64 = bfd_get_arch_size (abfd) == 64;
319 +#define SRC(field) (is64 ? src64->field \
320 + : ((const Elf32_External_Ehdr *) src64)->field)
322 + int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
323 + memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
324 + dst->e_type = H_GET_16 (abfd, SRC (e_type));
325 + dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
326 + dst->e_version = H_GET_32 (abfd, SRC (e_version));
328 + dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
330 + dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
331 + dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
332 + dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
333 + dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
334 + dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
335 + dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
336 + dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
337 + dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
338 + dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
339 + dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
344 +/* Translate an ELF program header table entry in external format into an
345 + ELF program header table entry in internal format. */
348 +elf_swap_phdr_in (bfd *abfd,
349 + const Elf64_External_Phdr *src64,
350 + Elf_Internal_Phdr *dst)
352 + int is64 = bfd_get_arch_size (abfd) == 64;
353 +#define SRC(field) (is64 ? src64->field \
354 + : ((const Elf32_External_Phdr *) src64)->field)
356 + int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
358 + dst->p_type = H_GET_32 (abfd, SRC (p_type));
359 + dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
360 + dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
363 + dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
364 + dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
368 + dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
369 + dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
371 + dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
372 + dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
373 + dst->p_align = H_GET_WORD (abfd, SRC (p_align));
378 +#undef H_GET_SIGNED_WORD
381 +static Elf_Internal_Phdr *
382 +elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
383 + bfd_vma *loadbase_pointer)
385 + /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr) */
386 + Elf64_External_Ehdr x_ehdr64; /* Elf file header, external form */
387 + Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
388 + bfd_size_type x_phdrs_size;
389 + gdb_byte *x_phdrs_ptr;
390 + Elf_Internal_Phdr *i_phdrs;
396 + gdb_assert (templ != NULL);
397 + gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
399 + /* Read in the ELF header in external format. */
400 + err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
403 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
404 + warning (_("build-id: Error reading ELF header at address 0x%lx"),
405 + (unsigned long) ehdr_vma);
409 + /* Now check to see if we have a valid ELF file, and one that BFD can
410 + make use of. The magic number must match, the address size ('class')
411 + and byte-swapping must match our XVEC entry. */
413 + if (! elf_file_p (&x_ehdr64)
414 + || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
415 + || !((bfd_get_arch_size (templ) == 64
416 + && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
417 + || (bfd_get_arch_size (templ) == 32
418 + && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
420 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
421 + warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
422 + (unsigned long) ehdr_vma);
426 + /* Check that file's byte order matches xvec's */
427 + switch (x_ehdr64.e_ident[EI_DATA])
429 + case ELFDATA2MSB: /* Big-endian */
430 + if (! bfd_header_big_endian (templ))
432 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
433 + warning (_("build-id: Unrecognized "
434 + "big-endian ELF header at address 0x%lx"),
435 + (unsigned long) ehdr_vma);
439 + case ELFDATA2LSB: /* Little-endian */
440 + if (! bfd_header_little_endian (templ))
442 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
443 + warning (_("build-id: Unrecognized "
444 + "little-endian ELF header at address 0x%lx"),
445 + (unsigned long) ehdr_vma);
449 + case ELFDATANONE: /* No data encoding specified */
450 + default: /* Unknown data encoding specified */
451 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
452 + warning (_("build-id: Unrecognized "
453 + "ELF header endianity at address 0x%lx"),
454 + (unsigned long) ehdr_vma);
458 + elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
460 + /* The file header tells where to find the program headers.
461 + These are what we use to actually choose what to read. */
463 + if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
464 + ? sizeof (Elf64_External_Phdr)
465 + : sizeof (Elf32_External_Phdr))
466 + || i_ehdr.e_phnum == 0)
468 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
469 + warning (_("build-id: Invalid ELF program headers from the ELF header "
470 + "at address 0x%lx"), (unsigned long) ehdr_vma);
474 + x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
475 + : sizeof (Elf32_External_Phdr));
477 + i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
478 + x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
479 + err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
480 + i_ehdr.e_phnum * x_phdrs_size);
484 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
485 + warning (_("build-id: Error reading "
486 + "ELF program headers at address 0x%lx"),
487 + (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
491 + loadbase = ehdr_vma;
493 + for (i = 0; i < i_ehdr.e_phnum; ++i)
495 + elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
496 + (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
497 + /* IA-64 vDSO may have two mappings for one segment, where one mapping
498 + is executable only, and one is read only. We must not use the
499 + executable one (PF_R is the first one, PF_X the second one). */
500 + if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
502 + /* Only the first PT_LOAD segment indicates the file bias.
503 + Next segments may have P_VADDR arbitrarily higher.
504 + If the first segment has P_VADDR zero any next segment must not
505 + confuse us, the first one sets LOADBASE certainly enough. */
506 + if (!loadbase_set && i_phdrs[i].p_offset == 0)
508 + loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
514 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
515 + warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
516 + (unsigned long) ehdr_vma, (unsigned long) loadbase);
518 + *e_phnum_pointer = i_ehdr.e_phnum;
519 + *loadbase_pointer = loadbase;
523 +/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
524 + Find the first section before ADDR containing an ELF header.
525 + We rely on the fact the sections from multiple files do not mix.
526 + FIXME: We should check ADDR is contained _inside_ the section with possibly
527 + missing content (P_FILESZ < P_MEMSZ). These omitted sections are currently
528 + hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR. */
530 +static CORE_ADDR build_id_addr;
531 +struct build_id_addr_sect
533 + struct build_id_addr_sect *next;
536 +static struct build_id_addr_sect *build_id_addr_sect;
538 +static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
540 + if (build_id_addr >= bfd_section_vma (abfd, sect))
542 + struct build_id_addr_sect *candidate;
544 + candidate = xmalloc (sizeof *candidate);
545 + candidate->next = build_id_addr_sect;
546 + build_id_addr_sect = candidate;
547 + candidate->sect = sect;
552 +build_id_addr_get (CORE_ADDR addr)
554 + struct build_id_addr_sect *candidate;
555 + struct build_id *retval = NULL;
556 + Elf_Internal_Phdr *i_phdr = NULL;
557 + bfd_vma loadbase = 0;
558 + unsigned e_phnum = 0;
560 + if (core_bfd == NULL)
563 + build_id_addr = addr;
564 + gdb_assert (build_id_addr_sect == NULL);
565 + bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
567 + /* Sections are sorted in the high-to-low VMAs order.
568 + Stop the search on the first ELF header we find.
569 + Do not continue the search even if it does not contain NT_GNU_BUILD_ID. */
571 + for (candidate = build_id_addr_sect; candidate != NULL;
572 + candidate = candidate->next)
574 + i_phdr = elf_get_phdr (core_bfd,
575 + bfd_section_vma (core_bfd, candidate->sect),
576 + &e_phnum, &loadbase);
577 + if (i_phdr != NULL)
581 + if (i_phdr != NULL)
583 + retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
587 + while (build_id_addr_sect != NULL)
589 + candidate = build_id_addr_sect;
590 + build_id_addr_sect = candidate->next;
597 /* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */
600 @@ -1227,7 +1619,7 @@ build_id_verify (const char *filename, s
604 - found = build_id_bfd_get (abfd);
605 + found = build_id_bfd_shdr_get (abfd);
608 warning (_("File \"%s\" has no build-id, file skipped"), filename);
609 @@ -1246,8 +1638,9 @@ build_id_verify (const char *filename, s
614 -build_id_to_debug_filename (struct build_id *build_id)
616 +build_id_to_filename (struct build_id *build_id, char **link_return,
617 + int add_debug_suffix)
619 char *link, *s, *retval = NULL;
620 gdb_byte *data = build_id->data;
621 @@ -1255,7 +1648,9 @@ build_id_to_debug_filename (struct build
623 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
624 link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
625 - + 2 * size + (sizeof ".debug" - 1) + 1);
627 + + (add_debug_suffix ? sizeof ".debug" - 1 : 0)
629 s = link + sprintf (link, "%s/.build-id/", debug_file_directory);
632 @@ -1266,12 +1661,14 @@ build_id_to_debug_filename (struct build
635 s += sprintf (s, "%02x", (unsigned) *data++);
636 - strcpy (s, ".debug");
637 + if (add_debug_suffix)
638 + strcpy (s, ".debug");
642 /* lrealpath() is expensive even for the usually non-existent files. */
643 if (access (link, F_OK) == 0)
644 retval = lrealpath (link);
647 if (retval != NULL && !build_id_verify (retval, build_id))
649 @@ -1279,9 +1676,142 @@ build_id_to_debug_filename (struct build
653 + if (link_return != NULL)
654 + *link_return = link;
661 +/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
662 + Try to install the hash file ...
665 +struct missing_filepair
672 +static struct htab *missing_filepair_hash;
673 +static struct obstack missing_filepair_obstack;
676 +missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
679 + size_t size = nmemb * nmemb_size;
681 + retval = obstack_alloc (&missing_filepair_obstack, size);
682 + memset (retval, 0, size);
687 +missing_filepair_hash_func (const struct missing_filepair *elem)
689 + hashval_t retval = 0;
691 + retval ^= htab_hash_string (elem->binary);
692 + if (elem->debug != NULL)
693 + retval ^= htab_hash_string (elem->debug);
699 +missing_filepair_eq (const struct missing_filepair *elem1,
700 + const struct missing_filepair *elem2)
702 + return strcmp (elem1->binary, elem2->binary) == 0
703 + && ((elem1->debug == NULL && elem2->debug == NULL)
704 + || strcmp (elem1->debug, elem2->debug) == 0);
708 +missing_filepair_change (void)
710 + if (missing_filepair_hash != NULL)
712 + obstack_free (&missing_filepair_obstack, NULL);
713 + /* All their memory came just from missing_filepair_OBSTACK. */
714 + missing_filepair_hash = NULL;
719 +debug_print_executable_changed (void)
721 + missing_filepair_change ();
724 +/* Notify user the file BINARY with (possibly NULL) associated separate debug
725 + information file DEBUG is missing. DEBUG may or may not be the build-id
726 + file such as would be:
727 + /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
731 +debug_print_missing (const char *binary, const char *debug)
733 + size_t binary_len0 = strlen (binary) + 1;
734 + size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
735 + struct missing_filepair *missing_filepair;
736 + struct missing_filepair **slot;
738 + if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
741 + if (missing_filepair_hash == NULL)
743 + obstack_init (&missing_filepair_obstack);
744 + missing_filepair_hash = htab_create_alloc (64,
745 + (hashval_t (*) (const void *)) missing_filepair_hash_func,
746 + (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
747 + missing_filepair_xcalloc, NULL);
750 + missing_filepair = obstack_alloc (&missing_filepair_obstack,
751 + sizeof (*missing_filepair) - 1
752 + + binary_len0 + debug_len0);
753 + missing_filepair->binary = missing_filepair->data;
754 + memcpy (missing_filepair->binary, binary, binary_len0);
757 + missing_filepair->debug = missing_filepair->binary + binary_len0;
758 + memcpy (missing_filepair->debug, debug, debug_len0);
761 + missing_filepair->debug = NULL;
763 + slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
767 + /* While it may be still printed duplicitely with the missing debuginfo file
768 + * it is due to once printing about the binary file build-id link and once
769 + * about the .debug file build-id link as both the build-id symlinks are
770 + * located in the debuginfo package. */
774 + obstack_free (&missing_filepair_obstack, missing_filepair);
777 + *slot = missing_filepair;
779 + /* We do not collect and flush these messages as each such message
780 + already requires its own separate lines. */
782 + fprintf_unfiltered (gdb_stdlog,
783 + _("Missing separate debuginfo for %s\n"), binary);
785 + fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
790 get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
792 @@ -1364,32 +1894,36 @@ static char *
793 find_separate_debug_file (struct objfile *objfile)
799 + char *basename = NULL;
801 + char *debugfile = NULL;
804 + char *canon_name = NULL;
805 bfd_size_type debuglink_size;
808 struct build_id *build_id;
809 + char *build_id_filename = NULL;
811 - build_id = build_id_bfd_get (objfile->obfd);
812 + build_id = build_id_bfd_shdr_get (objfile->obfd);
813 if (build_id != NULL)
817 - build_id_name = build_id_to_debug_filename (build_id);
818 + build_id_name = build_id_to_filename (build_id, &build_id_filename, 1);
820 /* Prevent looping on a stripped .debug file. */
821 if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
823 - warning (_("\"%s\": separate debug info file has no debug info"),
824 + warning (_("\"%s\": The separate debug info file has no debug info"),
826 xfree (build_id_name);
828 else if (build_id_name != NULL)
829 - return build_id_name;
831 + xfree (build_id_filename);
832 + return build_id_name;
836 basename = get_debug_link_info (objfile, &crc32);
837 @@ -1397,7 +1931,7 @@ find_separate_debug_file (struct objfile
838 if (basename == NULL)
839 /* There's no separate debug info, hence there's no way we could
840 load it => no warning. */
842 + goto cleanup_return_debugfile;
844 dir = xstrdup (objfile->name);
846 @@ -1413,23 +1947,19 @@ find_separate_debug_file (struct objfile
847 gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i]));
850 - debugfile = alloca (strlen (debug_file_directory) + 1
852 - + strlen (DEBUG_SUBDIRECTORY)
854 - + strlen (basename)
856 + debugfile = xmalloc (strlen (debug_file_directory) + 1
858 + + strlen (DEBUG_SUBDIRECTORY)
860 + + strlen (basename)
863 /* First try in the same directory as the original file. */
864 strcpy (debugfile, dir);
865 strcat (debugfile, basename);
867 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
871 - return xstrdup (debugfile);
873 + goto cleanup_return_debugfile;
875 /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */
876 strcpy (debugfile, dir);
877 @@ -1438,11 +1968,7 @@ find_separate_debug_file (struct objfile
878 strcat (debugfile, basename);
880 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
884 - return xstrdup (debugfile);
886 + goto cleanup_return_debugfile;
888 /* Then try in the global debugfile directory. */
889 strcpy (debugfile, debug_file_directory);
890 @@ -1451,11 +1977,7 @@ find_separate_debug_file (struct objfile
891 strcat (debugfile, basename);
893 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
897 - return xstrdup (debugfile);
899 + goto cleanup_return_debugfile;
901 /* If the file is in the sysroot, try using its base path in the
902 global debugfile directory. */
903 @@ -1470,20 +1992,18 @@ find_separate_debug_file (struct objfile
904 strcat (debugfile, basename);
906 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
908 - xfree (canon_name);
911 - return xstrdup (debugfile);
913 + goto cleanup_return_debugfile;
917 - xfree (canon_name);
920 + debug_print_missing (objfile->name, build_id_filename);
922 +cleanup_return_debugfile:
923 + xfree (build_id_filename);
924 + xfree (canon_name);
932 @@ -4216,4 +4736,16 @@ Show printing of symbol loading messages
935 &setprintlist, &showprintlist);
937 + add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
939 +Set debugging level of the build-id locator."), _("\
940 +Show debugging level of the build-id locator."), _("\
941 +Level 1 (default) enables printing the missing debug filenames,\n\
942 +level 2 also prints the parsing of binaries to find the identificators."),
944 + show_build_id_verbose,
945 + &setlist, &showlist);
947 + observer_attach_executable_changed (debug_print_executable_changed);
949 Index: gdb-6.8.50.20090302/gdb/symfile.h
950 ===================================================================
951 --- gdb-6.8.50.20090302.orig/gdb/symfile.h 2009-03-07 17:04:52.000000000 +0100
952 +++ gdb-6.8.50.20090302/gdb/symfile.h 2009-03-07 17:13:33.000000000 +0100
953 @@ -372,6 +372,13 @@ extern int symfile_map_offsets_to_segmen
954 struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
955 void free_symfile_segment_data (struct symfile_segment_data *data);
957 +/* build-id support. */
959 +extern struct build_id *build_id_addr_get (CORE_ADDR addr);
960 +extern char *build_id_to_filename (struct build_id *build_id,
961 + char **link_return, int add_debug_suffix);
962 +extern void debug_print_missing (const char *binary, const char *debug);
964 /* From dwarf2read.c */
966 extern int dwarf2_has_info (struct objfile *);
967 Index: gdb-6.8.50.20090302/gdb/testsuite/lib/gdb.exp
968 ===================================================================
969 --- gdb-6.8.50.20090302.orig/gdb/testsuite/lib/gdb.exp 2009-03-07 17:04:52.000000000 +0100
970 +++ gdb-6.8.50.20090302/gdb/testsuite/lib/gdb.exp 2009-03-07 17:13:33.000000000 +0100
971 @@ -1230,6 +1230,16 @@ proc default_gdb_start { } {
972 warning "Couldn't set the width to 0."
975 + # Turn off the missing warnings as the testsuite does not expect it.
976 + send_gdb "set build-id-verbose 0\n"
978 + -re "$gdb_prompt $" {
979 + verbose "Disabled the missing debug infos warnings." 2
982 + warning "Could not disable the missing debug infos warnings.."
988 --- ./gdb/testsuite/lib/mi-support.exp 2009-03-21 21:09:09.000000000 +0100
989 +++ ./gdb/testsuite/lib/mi-support.exp 2009-03-22 16:37:58.000000000 +0100
990 @@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
994 + # Turn off the missing warnings as the testsuite does not expect it.
995 + send_gdb "190-gdb-set build-id-verbose 0\n"
997 + -re ".*190-gdb-set build-id-verbose 0\r\n190\\\^done\r\n$mi_gdb_prompt$" {
998 + verbose "Disabled the missing debug infos warnings." 2
1001 + warning "Could not disable the missing debug infos warnings.."