1 Index: gdb-7.0/gdb/corelow.c
2 ===================================================================
3 --- gdb-7.0.orig/gdb/corelow.c 2009-07-31 17:25:21.000000000 +0200
4 +++ gdb-7.0/gdb/corelow.c 2009-10-23 00:17:29.000000000 +0200
6 #include "exceptions.h"
10 +#include "elf/common.h"
11 +#include "objfiles.h"
16 @@ -273,6 +277,52 @@ 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;
29 + struct cleanup *back_to;
31 + if (exec_bfd != NULL || symfile_objfile != NULL)
34 + if (target_auxv_search (¤t_target, AT_ENTRY, &at_entry) <= 0)
37 + build_id = build_id_addr_get (at_entry);
38 + if (build_id == NULL)
41 + /* SYMFILE_OBJFILE should refer to the main executable (not only to its
42 + separate debug info file). gcc44+ keeps .eh_frame only in the main
43 + executable without its duplicate .debug_frame in the separate debug info
44 + file - such .eh_frame would not be found if SYMFILE_OBJFILE would refer
45 + directly to the separate debug info file. */
47 + exec_filename = build_id_to_filename (build_id, &build_id_filename, 0);
48 + back_to = make_cleanup (xfree, build_id_filename);
50 + if (exec_filename != NULL)
52 + make_cleanup (xfree, exec_filename);
53 + exec_file_attach (exec_filename, from_tty);
54 + symbol_file_add_main (exec_filename, from_tty);
55 + if (symfile_objfile != NULL)
56 + symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
59 + debug_print_missing (_("the main executable file"), build_id_filename);
61 + do_cleanups (back_to);
63 + /* No automatic SOLIB_ADD as the libraries would get read twice. */
66 /* This routine opens and sets up the core file bfd. */
69 @@ -371,6 +421,12 @@ core_open (char *filename, int from_tty)
70 push_target (&core_ops);
71 discard_cleanups (old_chain);
73 + /* Find the build_id identifiers. If it gets executed after
74 + POST_CREATE_INFERIOR we would clash with asking to discard the already
75 + loaded VDSO symbols. */
76 + if (build_id_core_loads != 0)
77 + build_id_locate_exec (from_tty);
79 add_inferior_silent (corelow_pid);
81 /* Do this before acknowledging the inferior, so if
82 @@ -878,4 +934,11 @@ _initialize_corelow (void)
85 add_target (&core_ops);
87 + add_setshow_boolean_cmd ("build-id-core-loads", class_files,
88 + &build_id_core_loads, _("\
89 +Set whether CORE-FILE loads the build-id associated files automatically."), _("\
90 +Show whether CORE-FILE loads the build-id associated files automatically.."),
92 + &setlist, &showlist);
94 Index: gdb-7.0/gdb/doc/gdb.texinfo
95 ===================================================================
96 --- gdb-7.0.orig/gdb/doc/gdb.texinfo 2009-10-23 00:12:39.000000000 +0200
97 +++ gdb-7.0/gdb/doc/gdb.texinfo 2009-10-23 00:17:29.000000000 +0200
98 @@ -13896,6 +13896,27 @@ information files.
102 +You can also adjust the current verbosity of the @dfn{build id} locating.
106 +@kindex set build-id-verbose
107 +@item set build-id-verbose 0
108 +No additional messages are printed.
110 +@item set build-id-verbose 1
111 +Missing separate debug filenames are printed.
113 +@item set build-id-verbose 2
114 +Missing separate debug filenames are printed and also all the parsing of the
115 +binaries to find their @dfn{build id} content is printed.
117 +@kindex show build-id-verbose
118 +@item show build-id-verbose
119 +Show the current verbosity value for the @dfn{build id} content locating.
123 @cindex @code{.gnu_debuglink} sections
124 @cindex debug link sections
125 A debug link is a special section of the executable file named
126 Index: gdb-7.0/gdb/solib-svr4.c
127 ===================================================================
128 --- gdb-7.0.orig/gdb/solib-svr4.c 2009-10-23 00:12:38.000000000 +0200
129 +++ gdb-7.0/gdb/solib-svr4.c 2009-10-23 00:17:29.000000000 +0200
130 @@ -1101,9 +1101,49 @@ svr4_current_sos (void)
131 safe_strerror (errcode));
134 - strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
135 - new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
136 - strcpy (new->so_original_name, new->so_name);
137 + struct build_id *build_id;
139 + strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
140 + new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
141 + /* May get overwritten below. */
142 + strcpy (new->so_name, new->so_original_name);
144 + build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
145 + if (build_id != NULL)
147 + char *name, *build_id_filename;
149 + /* Missing the build-id matching separate debug info file
150 + would be handled while SO_NAME gets loaded. */
151 + name = build_id_to_filename (build_id, &build_id_filename, 0);
154 + strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
155 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
160 + debug_print_missing (new->so_name, build_id_filename);
162 + /* In the case the main executable was found according to
163 + its build-id (from a core file) prevent loading
164 + a different build of a library with accidentally the
167 + It suppresses bogus backtraces (and prints "??" there
168 + instead) if the on-disk files no longer match the
169 + running program version. */
171 + if (symfile_objfile != NULL
172 + && (symfile_objfile->flags
173 + & OBJF_BUILD_ID_CORE_LOADED) != 0)
174 + new->so_name[0] = 0;
177 + xfree (build_id_filename);
183 Index: gdb-7.0/gdb/symfile.c
184 ===================================================================
185 --- gdb-7.0.orig/gdb/symfile.c 2009-10-23 00:12:38.000000000 +0200
186 +++ gdb-7.0/gdb/symfile.c 2009-10-23 00:43:28.000000000 +0200
193 #include <sys/types.h>
195 @@ -1173,16 +1174,65 @@ symbol_file_clear (int from_tty)
196 printf_unfiltered (_("No symbol file now.\n"));
199 +/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
200 + FIXME: NOTE decoding should be unified with the BFD core notes decoding. */
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. */
222 +build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
227 + while (p < buf + size)
229 + /* FIXME: bad alignment assumption. */
230 + Elf_External_Note *xnp = (Elf_External_Note *) p;
231 + size_t namesz = H_GET_32 (templ, xnp->namesz);
232 + size_t descsz = H_GET_32 (templ, xnp->descsz);
233 + bfd_byte *descdata = xnp->name + BFD_ALIGN (namesz, 4);
235 + if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
236 + && namesz == sizeof "GNU"
237 + && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
239 + size_t size = descsz;
240 + gdb_byte *data = (void *) descdata;
241 + struct build_id *retval;
243 + retval = xmalloc (sizeof *retval - 1 + size);
244 + retval->size = size;
245 + memcpy (retval->data, data, size);
249 + p = descdata + BFD_ALIGN (descsz, 4);
254 +/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
255 + Locate NT_GNU_BUILD_ID from ABFD and return its content. */
257 static struct build_id *
258 -build_id_bfd_get (bfd *abfd)
259 +build_id_bfd_shdr_get (bfd *abfd)
261 struct build_id *retval;
263 @@ -1198,6 +1248,348 @@ build_id_bfd_get (bfd *abfd)
267 +/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
268 + bfd_elf_bfd_from_remote_memory () has too much overhead by
269 + allocating/reading all the available ELF PT_LOADs. */
271 +static struct build_id *
272 +build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
273 + Elf_Internal_Phdr *i_phdr)
276 + struct build_id *retval = NULL;
278 + for (i = 0; i < e_phnum; i++)
279 + if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
281 + Elf_Internal_Phdr *hdr = &i_phdr[i];
285 + buf = xmalloc (hdr->p_filesz);
286 + err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
289 + retval = build_id_buf_get (templ, buf, hdr->p_filesz);
293 + if (retval != NULL)
299 +/* First we validate the file by reading in the ELF header and checking
300 + the magic number. */
302 +static inline bfd_boolean
303 +elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
305 + gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
306 + gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
307 + == offsetof (Elf32_External_Ehdr, e_ident));
308 + gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
309 + == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
311 + return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
312 + && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
313 + && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
314 + && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
317 +/* Translate an ELF file header in external format into an ELF file header in
318 + internal format. */
320 +#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr)) \
321 + : H_GET_32 (bfd, (ptr)))
322 +#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr)) \
323 + : H_GET_S32 (bfd, (ptr)))
326 +elf_swap_ehdr_in (bfd *abfd,
327 + const Elf64_External_Ehdr *src64,
328 + Elf_Internal_Ehdr *dst)
330 + int is64 = bfd_get_arch_size (abfd) == 64;
331 +#define SRC(field) (is64 ? src64->field \
332 + : ((const Elf32_External_Ehdr *) src64)->field)
334 + int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
335 + memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
336 + dst->e_type = H_GET_16 (abfd, SRC (e_type));
337 + dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
338 + dst->e_version = H_GET_32 (abfd, SRC (e_version));
340 + dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
342 + dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
343 + dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
344 + dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
345 + dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
346 + dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
347 + dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
348 + dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
349 + dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
350 + dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
351 + dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
356 +/* Translate an ELF program header table entry in external format into an
357 + ELF program header table entry in internal format. */
360 +elf_swap_phdr_in (bfd *abfd,
361 + const Elf64_External_Phdr *src64,
362 + Elf_Internal_Phdr *dst)
364 + int is64 = bfd_get_arch_size (abfd) == 64;
365 +#define SRC(field) (is64 ? src64->field \
366 + : ((const Elf32_External_Phdr *) src64)->field)
368 + int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
370 + dst->p_type = H_GET_32 (abfd, SRC (p_type));
371 + dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
372 + dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
375 + dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
376 + dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
380 + dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
381 + dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
383 + dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
384 + dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
385 + dst->p_align = H_GET_WORD (abfd, SRC (p_align));
390 +#undef H_GET_SIGNED_WORD
393 +static Elf_Internal_Phdr *
394 +elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
395 + bfd_vma *loadbase_pointer)
397 + /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr) */
398 + Elf64_External_Ehdr x_ehdr64; /* Elf file header, external form */
399 + Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
400 + bfd_size_type x_phdrs_size;
401 + gdb_byte *x_phdrs_ptr;
402 + Elf_Internal_Phdr *i_phdrs;
408 + gdb_assert (templ != NULL);
409 + gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
411 + /* Read in the ELF header in external format. */
412 + err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
415 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
416 + warning (_("build-id: Error reading ELF header at address 0x%lx"),
417 + (unsigned long) ehdr_vma);
421 + /* Now check to see if we have a valid ELF file, and one that BFD can
422 + make use of. The magic number must match, the address size ('class')
423 + and byte-swapping must match our XVEC entry. */
425 + if (! elf_file_p (&x_ehdr64)
426 + || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
427 + || !((bfd_get_arch_size (templ) == 64
428 + && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
429 + || (bfd_get_arch_size (templ) == 32
430 + && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
432 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
433 + warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
434 + (unsigned long) ehdr_vma);
438 + /* Check that file's byte order matches xvec's */
439 + switch (x_ehdr64.e_ident[EI_DATA])
441 + case ELFDATA2MSB: /* Big-endian */
442 + if (! bfd_header_big_endian (templ))
444 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
445 + warning (_("build-id: Unrecognized "
446 + "big-endian ELF header at address 0x%lx"),
447 + (unsigned long) ehdr_vma);
451 + case ELFDATA2LSB: /* Little-endian */
452 + if (! bfd_header_little_endian (templ))
454 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
455 + warning (_("build-id: Unrecognized "
456 + "little-endian ELF header at address 0x%lx"),
457 + (unsigned long) ehdr_vma);
461 + case ELFDATANONE: /* No data encoding specified */
462 + default: /* Unknown data encoding specified */
463 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
464 + warning (_("build-id: Unrecognized "
465 + "ELF header endianity at address 0x%lx"),
466 + (unsigned long) ehdr_vma);
470 + elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
472 + /* The file header tells where to find the program headers.
473 + These are what we use to actually choose what to read. */
475 + if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
476 + ? sizeof (Elf64_External_Phdr)
477 + : sizeof (Elf32_External_Phdr))
478 + || i_ehdr.e_phnum == 0)
480 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
481 + warning (_("build-id: Invalid ELF program headers from the ELF header "
482 + "at address 0x%lx"), (unsigned long) ehdr_vma);
486 + x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
487 + : sizeof (Elf32_External_Phdr));
489 + i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
490 + x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
491 + err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
492 + i_ehdr.e_phnum * x_phdrs_size);
496 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
497 + warning (_("build-id: Error reading "
498 + "ELF program headers at address 0x%lx"),
499 + (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
503 + loadbase = ehdr_vma;
505 + for (i = 0; i < i_ehdr.e_phnum; ++i)
507 + elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
508 + (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
509 + /* IA-64 vDSO may have two mappings for one segment, where one mapping
510 + is executable only, and one is read only. We must not use the
511 + executable one (PF_R is the first one, PF_X the second one). */
512 + if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
514 + /* Only the first PT_LOAD segment indicates the file bias.
515 + Next segments may have P_VADDR arbitrarily higher.
516 + If the first segment has P_VADDR zero any next segment must not
517 + confuse us, the first one sets LOADBASE certainly enough. */
518 + if (!loadbase_set && i_phdrs[i].p_offset == 0)
520 + loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
526 + if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
527 + warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
528 + (unsigned long) ehdr_vma, (unsigned long) loadbase);
530 + *e_phnum_pointer = i_ehdr.e_phnum;
531 + *loadbase_pointer = loadbase;
535 +/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
536 + Find the first section before ADDR containing an ELF header.
537 + We rely on the fact the sections from multiple files do not mix.
538 + FIXME: We should check ADDR is contained _inside_ the section with possibly
539 + missing content (P_FILESZ < P_MEMSZ). These omitted sections are currently
540 + hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR. */
542 +static CORE_ADDR build_id_addr;
543 +struct build_id_addr_sect
545 + struct build_id_addr_sect *next;
548 +static struct build_id_addr_sect *build_id_addr_sect;
550 +static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
552 + if (build_id_addr >= bfd_section_vma (abfd, sect))
554 + struct build_id_addr_sect *candidate;
556 + candidate = xmalloc (sizeof *candidate);
557 + candidate->next = build_id_addr_sect;
558 + build_id_addr_sect = candidate;
559 + candidate->sect = sect;
564 +build_id_addr_get (CORE_ADDR addr)
566 + struct build_id_addr_sect *candidate;
567 + struct build_id *retval = NULL;
568 + Elf_Internal_Phdr *i_phdr = NULL;
569 + bfd_vma loadbase = 0;
570 + unsigned e_phnum = 0;
572 + if (core_bfd == NULL)
575 + build_id_addr = addr;
576 + gdb_assert (build_id_addr_sect == NULL);
577 + bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
579 + /* Sections are sorted in the high-to-low VMAs order.
580 + Stop the search on the first ELF header we find.
581 + Do not continue the search even if it does not contain NT_GNU_BUILD_ID. */
583 + for (candidate = build_id_addr_sect; candidate != NULL;
584 + candidate = candidate->next)
586 + i_phdr = elf_get_phdr (core_bfd,
587 + bfd_section_vma (core_bfd, candidate->sect),
588 + &e_phnum, &loadbase);
589 + if (i_phdr != NULL)
593 + if (i_phdr != NULL)
595 + retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
599 + while (build_id_addr_sect != NULL)
601 + candidate = build_id_addr_sect;
602 + build_id_addr_sect = candidate->next;
609 /* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */
612 @@ -1215,7 +1607,7 @@ build_id_verify (const char *filename, s
616 - found = build_id_bfd_get (abfd);
617 + found = build_id_bfd_shdr_get (abfd);
620 warning (_("File \"%s\" has no build-id, file skipped"), filename);
621 @@ -1234,14 +1626,16 @@ build_id_verify (const char *filename, s
626 -build_id_to_debug_filename (struct build_id *build_id)
628 +build_id_to_filename (struct build_id *build_id, char **link_return,
629 + int add_debug_suffix)
631 char *link, *debugdir, *retval = NULL;
632 + char *link_all = NULL;
634 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
635 - link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
636 - + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
637 + link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
638 + + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
640 /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
641 cause "/.build-id/..." lookups. */
642 @@ -1272,7 +1666,10 @@ build_id_to_debug_filename (struct build
645 s += sprintf (s, "%02x", (unsigned) *data++);
646 - strcpy (s, ".debug");
647 + if (add_debug_suffix)
648 + strcpy (s, ".debug");
652 /* lrealpath() is expensive even for the usually non-existent files. */
653 if (access (link, F_OK) == 0)
654 @@ -1285,15 +1682,185 @@ build_id_to_debug_filename (struct build
660 + /* LINK_ALL is not used below in this non-NULL RETVAL case. */
664 + if (link_all == NULL)
665 + link_all = xstrdup (link);
668 + size_t len_orig = strlen (link_all);
670 + link_all = xrealloc (link_all, len_orig + 1 + strlen (link) + 1);
672 + /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
673 + its possible use as an argument for installation command. */
674 + link_all[len_orig] = ' ';
676 + strcpy (&link_all[len_orig + 1], link);
679 debugdir = debugdir_end;
681 while (*debugdir != 0);
683 + if (link_return != NULL)
685 + if (retval != NULL)
687 + *link_return = link;
692 + *link_return = link_all;
702 +/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
703 + Try to install the hash file ...
706 +struct missing_filepair
713 +static struct htab *missing_filepair_hash;
714 +static struct obstack missing_filepair_obstack;
717 +missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
720 + size_t size = nmemb * nmemb_size;
722 + retval = obstack_alloc (&missing_filepair_obstack, size);
723 + memset (retval, 0, size);
728 +missing_filepair_hash_func (const struct missing_filepair *elem)
730 + hashval_t retval = 0;
732 + retval ^= htab_hash_string (elem->binary);
733 + if (elem->debug != NULL)
734 + retval ^= htab_hash_string (elem->debug);
740 +missing_filepair_eq (const struct missing_filepair *elem1,
741 + const struct missing_filepair *elem2)
743 + return strcmp (elem1->binary, elem2->binary) == 0
744 + && ((elem1->debug == NULL) == (elem2->debug == NULL))
745 + && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
749 +missing_filepair_change (void)
751 + if (missing_filepair_hash != NULL)
753 + obstack_free (&missing_filepair_obstack, NULL);
754 + /* All their memory came just from missing_filepair_OBSTACK. */
755 + missing_filepair_hash = NULL;
760 +debug_print_executable_changed (void)
762 + missing_filepair_change ();
765 +/* Notify user the file BINARY with (possibly NULL) associated separate debug
766 + information file DEBUG is missing. DEBUG may or may not be the build-id
767 + file such as would be:
768 + /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
772 +debug_print_missing (const char *binary, const char *debug)
774 + size_t binary_len0 = strlen (binary) + 1;
775 + size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
776 + struct missing_filepair missing_filepair_find;
777 + struct missing_filepair *missing_filepair;
778 + struct missing_filepair **slot;
780 + if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
783 + if (missing_filepair_hash == NULL)
785 + obstack_init (&missing_filepair_obstack);
786 + missing_filepair_hash = htab_create_alloc (64,
787 + (hashval_t (*) (const void *)) missing_filepair_hash_func,
788 + (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
789 + missing_filepair_xcalloc, NULL);
792 + /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
793 + obstack_free in the case of a (rare) match. The problem is ALLOC_F for
794 + MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
795 + structures for MISSING_FILEPAIR_HASH. Calling obstack_free would possibly
796 + not to free only MISSING_FILEPAIR but also some such structures (allocated
797 + during the htab_find_slot call). */
799 + missing_filepair_find.binary = (char *) binary;
800 + missing_filepair_find.debug = (char *) debug;
801 + slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
802 + &missing_filepair_find,
805 + /* While it may be still printed duplicitely with the missing debuginfo file
806 + * it is due to once printing about the binary file build-id link and once
807 + * about the .debug file build-id link as both the build-id symlinks are
808 + * located in the debuginfo package. */
813 + missing_filepair = obstack_alloc (&missing_filepair_obstack,
814 + sizeof (*missing_filepair) - 1
815 + + binary_len0 + debug_len0);
816 + missing_filepair->binary = missing_filepair->data;
817 + memcpy (missing_filepair->binary, binary, binary_len0);
820 + missing_filepair->debug = missing_filepair->binary + binary_len0;
821 + memcpy (missing_filepair->debug, debug, debug_len0);
824 + missing_filepair->debug = NULL;
826 + *slot = missing_filepair;
828 + /* We do not collect and flush these messages as each such message
829 + already requires its own separate lines. */
831 + fprintf_unfiltered (gdb_stdlog,
832 + _("Missing separate debuginfo for %s\n"), binary);
834 + fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
839 get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
841 @@ -1384,13 +1951,14 @@ find_separate_debug_file (struct objfile
844 struct build_id *build_id;
845 + char *build_id_filename = NULL;
847 - build_id = build_id_bfd_get (objfile->obfd);
848 + build_id = build_id_bfd_shdr_get (objfile->obfd);
849 if (build_id != NULL)
853 - build_id_name = build_id_to_debug_filename (build_id);
854 + build_id_name = build_id_to_filename (build_id, &build_id_filename, 1);
856 /* Prevent looping on a stripped .debug file. */
857 if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
858 @@ -1400,7 +1968,10 @@ find_separate_debug_file (struct objfile
859 xfree (build_id_name);
861 else if (build_id_name != NULL)
862 - return build_id_name;
864 + xfree (build_id_filename);
865 + return build_id_name;
869 basename = get_debug_link_info (objfile, &crc32);
870 @@ -1501,8 +2072,10 @@ find_separate_debug_file (struct objfile
874 + debug_print_missing (objfile->name, build_id_filename);
876 cleanup_return_debugfile:
877 + xfree (build_id_filename);
881 @@ -4256,4 +4829,16 @@ each global debug-file-directory compone
883 show_debug_file_directory,
884 &setlist, &showlist);
886 + add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
888 + Set debugging level of the build-id locator."), _("\
889 + Show debugging level of the build-id locator."), _("\
890 + Level 1 (default) enables printing the missing debug filenames,\n\
891 + level 2 also prints the parsing of binaries to find the identificators."),
893 + show_build_id_verbose,
894 + &setlist, &showlist);
896 + observer_attach_executable_changed (debug_print_executable_changed);
898 Index: gdb-7.0/gdb/symfile.h
899 ===================================================================
900 --- gdb-7.0.orig/gdb/symfile.h 2009-10-23 00:12:38.000000000 +0200
901 +++ gdb-7.0/gdb/symfile.h 2009-10-23 00:17:29.000000000 +0200
902 @@ -381,6 +381,13 @@ extern int symfile_map_offsets_to_segmen
903 struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
904 void free_symfile_segment_data (struct symfile_segment_data *data);
906 +/* build-id support. */
908 +extern struct build_id *build_id_addr_get (CORE_ADDR addr);
909 +extern char *build_id_to_filename (struct build_id *build_id,
910 + char **link_return, int add_debug_suffix);
911 +extern void debug_print_missing (const char *binary, const char *debug);
913 /* From dwarf2read.c */
915 extern int dwarf2_has_info (struct objfile *);
916 Index: gdb-7.0/gdb/testsuite/lib/gdb.exp
917 ===================================================================
918 --- gdb-7.0.orig/gdb/testsuite/lib/gdb.exp 2009-10-23 00:12:38.000000000 +0200
919 +++ gdb-7.0/gdb/testsuite/lib/gdb.exp 2009-10-23 00:17:29.000000000 +0200
920 @@ -1248,6 +1248,16 @@ proc default_gdb_start { } {
921 warning "Couldn't set the width to 0."
924 + # Turn off the missing warnings as the testsuite does not expect it.
925 + send_gdb "set build-id-verbose 0\n"
927 + -re "$gdb_prompt $" {
928 + verbose "Disabled the missing debug infos warnings." 2
931 + warning "Could not disable the missing debug infos warnings.."
937 Index: gdb-7.0/gdb/testsuite/lib/mi-support.exp
938 ===================================================================
939 --- gdb-7.0.orig/gdb/testsuite/lib/mi-support.exp 2009-09-15 20:51:26.000000000 +0200
940 +++ gdb-7.0/gdb/testsuite/lib/mi-support.exp 2009-10-23 00:17:29.000000000 +0200
941 @@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
945 + # Turn off the missing warnings as the testsuite does not expect it.
946 + send_gdb "190-gdb-set build-id-verbose 0\n"
948 + -re ".*190-gdb-set build-id-verbose 0\r\n190\\\^done\r\n$mi_gdb_prompt$" {
949 + verbose "Disabled the missing debug infos warnings." 2
952 + warning "Could not disable the missing debug infos warnings.."
958 Index: gdb-7.0/gdb/objfiles.h
959 ===================================================================
960 --- gdb-7.0.orig/gdb/objfiles.h 2009-10-23 00:12:38.000000000 +0200
961 +++ gdb-7.0/gdb/objfiles.h 2009-10-23 00:17:29.000000000 +0200
962 @@ -428,6 +428,10 @@ struct objfile
964 #define OBJF_MAIN (1 << 7)
966 +/* This file was loaded according to the BUILD_ID_CORE_LOADS rules. */
968 +#define OBJF_BUILD_ID_CORE_LOADED (1 << 12)
970 /* The object file that the main symbol table was loaded from (e.g. the
971 argument to the "symbol-file" or "file" command). */