]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.6-buildid-locate.patch
- updated to 7.10 and patches from fedora
[packages/gdb.git] / gdb-6.6-buildid-locate.patch
1 Index: gdb-7.9.90.20150709/gdb/corelow.c
2 ===================================================================
3 --- gdb-7.9.90.20150709.orig/gdb/corelow.c      2015-07-09 22:05:20.988044312 +0200
4 +++ gdb-7.9.90.20150709/gdb/corelow.c   2015-07-09 22:05:42.057222722 +0200
5 @@ -45,6 +45,10 @@
6  #include "gdb_bfd.h"
7  #include "completer.h"
8  #include "filestuff.h"
9 +#include "auxv.h"
10 +#include "elf/common.h"
11 +#include "gdbcmd.h"
12 +#include "build-id.h"
13  
14  #ifndef O_LARGEFILE
15  #define O_LARGEFILE 0
16 @@ -266,6 +270,53 @@ add_to_thread_list (bfd *abfd, asection
17      inferior_ptid = ptid;                      /* Yes, make it current.  */
18  }
19  
20 +static int build_id_core_loads = 1;
21 +
22 +static void
23 +build_id_locate_exec (int from_tty)
24 +{
25 +  CORE_ADDR at_entry;
26 +  struct bfd_build_id *build_id;
27 +  char *execfilename, *debug_filename;
28 +  char *build_id_filename;
29 +  struct cleanup *back_to;
30 +
31 +  if (exec_bfd != NULL || symfile_objfile != NULL)
32 +    return;
33 +
34 +  if (target_auxv_search (&current_target, AT_ENTRY, &at_entry) <= 0)
35 +    return;
36 +
37 +  build_id = build_id_addr_get (at_entry);
38 +  if (build_id == NULL)
39 +    return;
40 +  back_to = make_cleanup (xfree, build_id);
41 +
42 +  /* SYMFILE_OBJFILE should refer to the main executable (not only to its
43 +     separate debug info file).  gcc44+ keeps .eh_frame only in the main
44 +     executable without its duplicate .debug_frame in the separate debug info
45 +     file - such .eh_frame would not be found if SYMFILE_OBJFILE would refer
46 +     directly to the separate debug info file.  */
47 +
48 +  execfilename = build_id_to_filename (build_id, &build_id_filename);
49 +  make_cleanup (xfree, build_id_filename);
50 +
51 +  if (execfilename != NULL)
52 +    {
53 +      make_cleanup (xfree, execfilename);
54 +      exec_file_attach (execfilename, from_tty);
55 +      symbol_file_add_main (execfilename, from_tty);
56 +      if (symfile_objfile != NULL)
57 +        symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
58 +    }
59 +  else
60 +    debug_print_missing (_("the main executable file"), build_id_filename);
61 +
62 +  do_cleanups (back_to);
63 +
64 +  /* No automatic SOLIB_ADD as the libraries would get read twice.  */
65 +}
66 +
67  /* This routine opens and sets up the core file bfd.  */
68  
69  static void
70 @@ -404,6 +455,14 @@ core_open (const char *arg, int from_tty
71         switch_to_thread (thread->ptid);
72      }
73  
74 +  /* Find the build_id identifiers.  If it gets executed after
75 +     POST_CREATE_INFERIOR we would clash with asking to discard the already
76 +     loaded VDSO symbols.  If it gets executed before bfd_map_over_sections
77 +     INFERIOR_PTID is still not set and libthread_db initialization crashes on
78 +     PID == 0 in ps_pglobal_lookup.  */
79 +  if (build_id_core_loads != 0)
80 +    build_id_locate_exec (from_tty);
81 +
82    post_create_inferior (&core_ops, from_tty);
83  
84    /* Now go through the target stack looking for threads since there
85 @@ -1058,4 +1117,11 @@ _initialize_corelow (void)
86    init_core_ops ();
87  
88    add_target_with_completer (&core_ops, filename_completer);
89 +
90 +  add_setshow_boolean_cmd ("build-id-core-loads", class_files,
91 +                          &build_id_core_loads, _("\
92 +Set whether CORE-FILE loads the build-id associated files automatically."), _("\
93 +Show whether CORE-FILE loads the build-id associated files automatically."),
94 +                          NULL, NULL, NULL,
95 +                          &setlist, &showlist);
96  }
97 Index: gdb-7.9.90.20150709/gdb/doc/gdb.texinfo
98 ===================================================================
99 --- gdb-7.9.90.20150709.orig/gdb/doc/gdb.texinfo        2015-07-09 22:05:20.988044312 +0200
100 +++ gdb-7.9.90.20150709/gdb/doc/gdb.texinfo     2015-07-09 22:05:42.067222806 +0200
101 @@ -18304,6 +18304,27 @@ information files.
102  
103  @end table
104  
105 +You can also adjust the current verbosity of the @dfn{build id} locating.
106 +
107 +@table @code
108 +
109 +@kindex set build-id-verbose
110 +@item set build-id-verbose 0
111 +No additional messages are printed.
112 +
113 +@item set build-id-verbose 1
114 +Missing separate debug filenames are printed.
115 +
116 +@item set build-id-verbose 2
117 +Missing separate debug filenames are printed and also all the parsing of the
118 +binaries to find their @dfn{build id} content is printed.
119 +
120 +@kindex show build-id-verbose
121 +@item show build-id-verbose
122 +Show the current verbosity value for the @dfn{build id} content locating.
123 +
124 +@end table
125 +
126  @cindex @code{.gnu_debuglink} sections
127  @cindex debug link sections
128  A debug link is a special section of the executable file named
129 Index: gdb-7.9.90.20150709/gdb/solib-svr4.c
130 ===================================================================
131 --- gdb-7.9.90.20150709.orig/gdb/solib-svr4.c   2015-07-09 22:05:20.988044312 +0200
132 +++ gdb-7.9.90.20150709/gdb/solib-svr4.c        2015-07-09 22:05:42.068222815 +0200
133 @@ -45,6 +45,7 @@
134  #include "auxv.h"
135  #include "gdb_bfd.h"
136  #include "probe.h"
137 +#include "build-id.h"
138  
139  static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
140  static int svr4_have_link_map_offsets (void);
141 @@ -1379,9 +1380,52 @@ svr4_read_so_list (CORE_ADDR lm, CORE_AD
142           continue;
143         }
144  
145 -      strncpy (newobj->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
146 -      newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
147 -      strcpy (newobj->so_original_name, newobj->so_name);
148 +      {
149 +       struct bfd_build_id *build_id;
150 +
151 +       strncpy (newobj->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
152 +       newobj->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
153 +       /* May get overwritten below.  */
154 +       strcpy (newobj->so_name, newobj->so_original_name);
155 +
156 +       build_id = build_id_addr_get (newobj->lm_info->l_ld);
157 +       if (build_id != NULL)
158 +         {
159 +           char *name, *build_id_filename;
160 +
161 +           /* Missing the build-id matching separate debug info file
162 +              would be handled while SO_NAME gets loaded.  */
163 +           name = build_id_to_filename (build_id, &build_id_filename);
164 +           if (name != NULL)
165 +             {
166 +               strncpy (newobj->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
167 +               newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
168 +               xfree (name);
169 +             }
170 +           else
171 +             {
172 +               debug_print_missing (newobj->so_name, build_id_filename);
173 +
174 +               /* In the case the main executable was found according to
175 +                  its build-id (from a core file) prevent loading
176 +                  a different build of a library with accidentally the
177 +                  same SO_NAME.
178 +
179 +                  It suppresses bogus backtraces (and prints "??" there
180 +                  instead) if the on-disk files no longer match the
181 +                  running program version.  */
182 +
183 +               if (symfile_objfile != NULL
184 +                   && (symfile_objfile->flags
185 +                       & OBJF_BUILD_ID_CORE_LOADED) != 0)
186 +                 newobj->so_name[0] = 0;
187 +             }
188 +
189 +           xfree (build_id_filename);
190 +           xfree (build_id);
191 +         }
192 +      }
193 +
194        xfree (buffer);
195  
196        /* If this entry has no name, or its name matches the name
197 Index: gdb-7.9.90.20150709/gdb/elfread.c
198 ===================================================================
199 --- gdb-7.9.90.20150709.orig/gdb/elfread.c      2015-07-09 22:05:20.988044312 +0200
200 +++ gdb-7.9.90.20150709/gdb/elfread.c   2015-07-09 22:05:42.068222815 +0200
201 @@ -1250,9 +1250,10 @@ elf_symfile_read (struct objfile *objfil
202            && objfile->separate_debug_objfile == NULL
203            && objfile->separate_debug_objfile_backlink == NULL)
204      {
205 -      char *debugfile;
206 +      char *debugfile, *build_id_filename;
207  
208 -      debugfile = find_separate_debug_file_by_buildid (objfile);
209 +      debugfile = find_separate_debug_file_by_buildid (objfile,
210 +                                                      &build_id_filename);
211  
212        if (debugfile == NULL)
213         debugfile = find_separate_debug_file_by_debuglink (objfile);
214 @@ -1266,6 +1267,12 @@ elf_symfile_read (struct objfile *objfil
215           symbol_file_add_separate (abfd, debugfile, symfile_flags, objfile);
216           do_cleanups (cleanup);
217         }
218 +      /* Check if any separate debug info has been extracted out.  */
219 +      else if (bfd_get_section_by_name (objfile->obfd, ".gnu_debuglink")
220 +              != NULL)
221 +       debug_print_missing (objfile_name (objfile), build_id_filename);
222 +
223 +      xfree (build_id_filename);
224      }
225  }
226  
227 Index: gdb-7.9.90.20150709/gdb/symfile.h
228 ===================================================================
229 --- gdb-7.9.90.20150709.orig/gdb/symfile.h      2015-07-09 22:05:20.988044312 +0200
230 +++ gdb-7.9.90.20150709/gdb/symfile.h   2015-07-09 22:05:42.068222815 +0200
231 @@ -584,6 +584,10 @@ void expand_symtabs_matching (expand_sym
232  void map_symbol_filenames (symbol_filename_ftype *fun, void *data,
233                            int need_fullname);
234  
235 +/* build-id support.  */
236 +extern struct bfd_build_id *build_id_addr_get (CORE_ADDR addr);
237 +extern void debug_print_missing (const char *binary, const char *debug);
238 +
239  /* From dwarf2read.c */
240  
241  /* Names for a dwarf2 debugging section.  The field NORMAL is the normal
242 Index: gdb-7.9.90.20150709/gdb/testsuite/lib/gdb.exp
243 ===================================================================
244 --- gdb-7.9.90.20150709.orig/gdb/testsuite/lib/gdb.exp  2015-07-09 22:05:20.988044312 +0200
245 +++ gdb-7.9.90.20150709/gdb/testsuite/lib/gdb.exp       2015-07-09 22:05:42.070222832 +0200
246 @@ -1573,6 +1573,16 @@ proc default_gdb_start { } {
247             warning "Couldn't set the width to 0."
248         }
249      }
250 +    # Turn off the missing warnings as the testsuite does not expect it.
251 +    send_gdb "set build-id-verbose 0\n"
252 +    gdb_expect 10 {
253 +       -re "$gdb_prompt $" {
254 +           verbose "Disabled the missing debug infos warnings." 2
255 +       }
256 +       timeout {
257 +           warning "Could not disable the missing debug infos warnings.."
258 +       }
259 +    }
260      return 0
261  }
262  
263 Index: gdb-7.9.90.20150709/gdb/testsuite/lib/mi-support.exp
264 ===================================================================
265 --- gdb-7.9.90.20150709.orig/gdb/testsuite/lib/mi-support.exp   2015-07-09 22:05:20.988044312 +0200
266 +++ gdb-7.9.90.20150709/gdb/testsuite/lib/mi-support.exp        2015-07-09 22:05:42.070222832 +0200
267 @@ -214,6 +214,16 @@ proc default_mi_gdb_start { args } {
268             warning "Couldn't set the width to 0."
269         }
270      }
271 +    # Turn off the missing warnings as the testsuite does not expect it.
272 +    send_gdb "190-gdb-set build-id-verbose 0\n"
273 +    gdb_expect 10 {
274 +       -re ".*190-gdb-set build-id-verbose 0\r\n190\\\^done\r\n$mi_gdb_prompt$" {
275 +           verbose "Disabled the missing debug infos warnings." 2
276 +       }
277 +       timeout {
278 +           warning "Could not disable the missing debug infos warnings.."
279 +       }
280 +    }
281      # If allowing the inferior to have its own PTY then assign the inferior
282      # its own terminal device here.
283      if { $separate_inferior_pty } {
284 Index: gdb-7.9.90.20150709/gdb/objfiles.h
285 ===================================================================
286 --- gdb-7.9.90.20150709.orig/gdb/objfiles.h     2015-07-09 22:05:20.988044312 +0200
287 +++ gdb-7.9.90.20150709/gdb/objfiles.h  2015-07-09 22:05:42.071222840 +0200
288 @@ -459,6 +459,10 @@ struct objfile
289  
290  #define OBJF_NOT_FILENAME (1 << 6)
291  
292 +/* This file was loaded according to the BUILD_ID_CORE_LOADS rules.  */
293 +
294 +#define OBJF_BUILD_ID_CORE_LOADED (1 << 12)
295 +
296  /* Declarations for functions defined in objfiles.c */
297  
298  extern struct objfile *allocate_objfile (bfd *, const char *name, int);
299 Index: gdb-7.9.90.20150709/gdb/testsuite/gdb.base/corefile.exp
300 ===================================================================
301 --- gdb-7.9.90.20150709.orig/gdb/testsuite/gdb.base/corefile.exp        2015-07-09 22:05:20.988044312 +0200
302 +++ gdb-7.9.90.20150709/gdb/testsuite/gdb.base/corefile.exp     2015-07-09 22:05:42.071222840 +0200
303 @@ -293,3 +293,33 @@ gdb_test_multiple "core-file $corefile"
304         pass $test
305      }
306  }
307 +
308 +
309 +# Test auto-loading of binary files through build-id from the core file.
310 +set buildid [build_id_debug_filename_get $binfile]
311 +set wholetest "binfile found by build-id"
312 +if {$buildid == ""} {
313 +    untested "$wholetest (binary has no build-id)"
314 +} else {
315 +    gdb_exit
316 +    gdb_start
317 +
318 +    regsub {\.debug$} $buildid {} buildid
319 +    set debugdir ${objdir}/${subdir}/${testfile}-debugdir
320 +    file delete -force -- $debugdir
321 +    file mkdir $debugdir/[file dirname $buildid]
322 +    file copy $binfile $debugdir/$buildid
323 +
324 +    set test "show debug-file-directory"
325 +    gdb_test_multiple $test $test {
326 +       -re "The directory where separate debug symbols are searched for is \"(.*)\"\\.\r\n$gdb_prompt $" {
327 +           set debugdir_orig $expect_out(1,string)
328 +           pass $test
329 +       }
330 +    }
331 +    gdb_test_no_output "set debug-file-directory $debugdir:$debugdir_orig" "set debug-file-directory"
332 +    gdb_test "show build-id-core-loads" {Whether CORE-FILE loads the build-id associated files automatically is on\.}
333 +    gdb_test "core-file $corefile" "\r\nProgram terminated with .*" "core-file without executable"
334 +    gdb_test "info files" "Local exec file:\r\n\[ \t\]*`[string_to_regexp $debugdir/$buildid]', file type .*"
335 +    pass $wholetest
336 +}
337 Index: gdb-7.9.90.20150709/gdb/build-id.c
338 ===================================================================
339 --- gdb-7.9.90.20150709.orig/gdb/build-id.c     2015-07-09 22:05:20.988044312 +0200
340 +++ gdb-7.9.90.20150709/gdb/build-id.c  2015-07-09 22:19:35.022957009 +0200
341 @@ -26,11 +26,67 @@
342  #include "objfiles.h"
343  #include "filenames.h"
344  #include "gdbcore.h"
345 +#include "libbfd.h"
346 +#include "gdbcore.h"
347 +#include "gdbcmd.h"
348 +#include "observer.h"
349 +#include "elf/external.h"
350 +#include "elf/internal.h"
351 +#include "elf/common.h"
352 +#include "elf-bfd.h"
353 +#include <sys/stat.h>
354 +
355 +#define BUILD_ID_VERBOSE_NONE 0
356 +#define BUILD_ID_VERBOSE_FILENAMES 1
357 +#define BUILD_ID_VERBOSE_BINARY_PARSE 2
358 +static int build_id_verbose = BUILD_ID_VERBOSE_FILENAMES;
359 +static void
360 +show_build_id_verbose (struct ui_file *file, int from_tty,
361 +                      struct cmd_list_element *c, const char *value)
362 +{
363 +  fprintf_filtered (file, _("Verbosity level of the build-id locator is %s.\n"),
364 +                   value);
365 +}
366 +/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
367 +   FIXME: NOTE decoding should be unified with the BFD core notes decoding.  */
368 +
369 +static struct bfd_build_id *
370 +build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
371 +{
372 +  bfd_byte *p;
373 +
374 +  p = buf;
375 +  while (p < buf + size)
376 +    {
377 +      /* FIXME: bad alignment assumption.  */
378 +      Elf_External_Note *xnp = (Elf_External_Note *) p;
379 +      size_t namesz = H_GET_32 (templ, xnp->namesz);
380 +      size_t descsz = H_GET_32 (templ, xnp->descsz);
381 +      bfd_byte *descdata = (gdb_byte *) xnp->name + BFD_ALIGN (namesz, 4);
382 +
383 +      if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
384 +         && namesz == sizeof "GNU"
385 +         && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
386 +       {
387 +         size_t size = descsz;
388 +         gdb_byte *data = (void *) descdata;
389 +         struct bfd_build_id *retval;
390 +
391 +         retval = xmalloc (sizeof *retval - 1 + size);
392 +         retval->size = size;
393 +         memcpy (retval->data, data, size);
394 +
395 +         return retval;
396 +       }
397 +      p = descdata + BFD_ALIGN (descsz, 4);
398 +    }
399 +  return NULL;
400 +}
401  
402  /* See build-id.h.  */
403  
404  const struct bfd_build_id *
405 -build_id_bfd_get (bfd *abfd)
406 +build_id_bfd_shdr_get (bfd *abfd)
407  {
408    if (!bfd_check_format (abfd, bfd_object))
409      return NULL;
410 @@ -42,6 +98,348 @@ build_id_bfd_get (bfd *abfd)
411    return NULL;
412  }
413  
414 +/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
415 +   bfd_elf_bfd_from_remote_memory () has too much overhead by
416 +   allocating/reading all the available ELF PT_LOADs.  */
417 +
418 +static struct bfd_build_id *
419 +build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
420 +                  Elf_Internal_Phdr *i_phdr)
421 +{
422 +  int i;
423 +  struct bfd_build_id *retval = NULL;
424 +
425 +  for (i = 0; i < e_phnum; i++)
426 +    if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
427 +      {
428 +       Elf_Internal_Phdr *hdr = &i_phdr[i];
429 +       gdb_byte *buf;
430 +       int err;
431 +
432 +       buf = xmalloc (hdr->p_filesz);
433 +       err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
434 +                                 hdr->p_filesz);
435 +       if (err == 0)
436 +         retval = build_id_buf_get (templ, buf, hdr->p_filesz);
437 +       else
438 +         retval = NULL;
439 +       xfree (buf);
440 +       if (retval != NULL)
441 +         break;
442 +      }
443 +  return retval;
444 +}
445 +
446 +/* First we validate the file by reading in the ELF header and checking
447 +   the magic number.  */
448 +
449 +static inline bfd_boolean
450 +elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
451 +{
452 +  gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
453 +  gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
454 +             == offsetof (Elf32_External_Ehdr, e_ident));
455 +  gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
456 +             == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
457 +
458 +  return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
459 +         && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
460 +         && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
461 +         && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
462 +}
463 +
464 +/* Translate an ELF file header in external format into an ELF file header in
465 +   internal format.  */
466 +
467 +#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr))             \
468 +                                  : H_GET_32 (bfd, (ptr)))
469 +#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr))     \
470 +                                         : H_GET_S32 (bfd, (ptr)))
471 +
472 +static void
473 +elf_swap_ehdr_in (bfd *abfd,
474 +                 const Elf64_External_Ehdr *src64,
475 +                 Elf_Internal_Ehdr *dst)
476 +{
477 +  int is64 = bfd_get_arch_size (abfd) == 64;
478 +#define SRC(field) (is64 ? src64->field \
479 +                        : ((const Elf32_External_Ehdr *) src64)->field)
480 +
481 +  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
482 +  memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
483 +  dst->e_type = H_GET_16 (abfd, SRC (e_type));
484 +  dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
485 +  dst->e_version = H_GET_32 (abfd, SRC (e_version));
486 +  if (signed_vma)
487 +    dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
488 +  else
489 +    dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
490 +  dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
491 +  dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
492 +  dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
493 +  dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
494 +  dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
495 +  dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
496 +  dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
497 +  dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
498 +  dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
499 +
500 +#undef SRC
501 +}
502 +
503 +/* Translate an ELF program header table entry in external format into an
504 +   ELF program header table entry in internal format.  */
505 +
506 +static void
507 +elf_swap_phdr_in (bfd *abfd,
508 +                 const Elf64_External_Phdr *src64,
509 +                 Elf_Internal_Phdr *dst)
510 +{
511 +  int is64 = bfd_get_arch_size (abfd) == 64;
512 +#define SRC(field) (is64 ? src64->field                                        \
513 +                        : ((const Elf32_External_Phdr *) src64)->field)
514 +
515 +  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
516 +
517 +  dst->p_type = H_GET_32 (abfd, SRC (p_type));
518 +  dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
519 +  dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
520 +  if (signed_vma)
521 +    {
522 +      dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
523 +      dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
524 +    }
525 +  else
526 +    {
527 +      dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
528 +      dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
529 +    }
530 +  dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
531 +  dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
532 +  dst->p_align = H_GET_WORD (abfd, SRC (p_align));
533 +
534 +#undef SRC
535 +}
536 +
537 +#undef H_GET_SIGNED_WORD
538 +#undef H_GET_WORD
539 +
540 +static Elf_Internal_Phdr *
541 +elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
542 +              bfd_vma *loadbase_pointer)
543 +{
544 +  /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr)  */
545 +  Elf64_External_Ehdr x_ehdr64;        /* Elf file header, external form */
546 +  Elf_Internal_Ehdr i_ehdr;    /* Elf file header, internal form */
547 +  bfd_size_type x_phdrs_size;
548 +  gdb_byte *x_phdrs_ptr;
549 +  Elf_Internal_Phdr *i_phdrs;
550 +  int err;
551 +  unsigned int i;
552 +  bfd_vma loadbase;
553 +  int loadbase_set;
554 +
555 +  gdb_assert (templ != NULL);
556 +  gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
557 +
558 +  /* Read in the ELF header in external format.  */
559 +  err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
560 +  if (err)
561 +    {
562 +      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
563 +        warning (_("build-id: Error reading ELF header at address 0x%lx"),
564 +                (unsigned long) ehdr_vma);
565 +      return NULL;
566 +    }
567 +
568 +  /* Now check to see if we have a valid ELF file, and one that BFD can
569 +     make use of.  The magic number must match, the address size ('class')
570 +     and byte-swapping must match our XVEC entry.  */
571 +
572 +  if (! elf_file_p (&x_ehdr64)
573 +      || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
574 +      || !((bfd_get_arch_size (templ) == 64
575 +            && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
576 +           || (bfd_get_arch_size (templ) == 32
577 +              && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
578 +    {
579 +      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
580 +        warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
581 +                (unsigned long) ehdr_vma);
582 +      return NULL;
583 +    }
584 +
585 +  /* Check that file's byte order matches xvec's */
586 +  switch (x_ehdr64.e_ident[EI_DATA])
587 +    {
588 +    case ELFDATA2MSB:          /* Big-endian */
589 +      if (! bfd_header_big_endian (templ))
590 +       {
591 +         if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
592 +           warning (_("build-id: Unrecognized "
593 +                      "big-endian ELF header at address 0x%lx"),
594 +                    (unsigned long) ehdr_vma);
595 +         return NULL;
596 +       }
597 +      break;
598 +    case ELFDATA2LSB:          /* Little-endian */
599 +      if (! bfd_header_little_endian (templ))
600 +       {
601 +         if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
602 +           warning (_("build-id: Unrecognized "
603 +                      "little-endian ELF header at address 0x%lx"),
604 +                    (unsigned long) ehdr_vma);
605 +         return NULL;
606 +       }
607 +      break;
608 +    case ELFDATANONE:          /* No data encoding specified */
609 +    default:                   /* Unknown data encoding specified */
610 +      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
611 +       warning (_("build-id: Unrecognized "
612 +                  "ELF header endianity at address 0x%lx"),
613 +                (unsigned long) ehdr_vma);
614 +      return NULL;
615 +    }
616 +
617 +  elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
618 +
619 +  /* The file header tells where to find the program headers.
620 +     These are what we use to actually choose what to read.  */
621 +
622 +  if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
623 +                             ? sizeof (Elf64_External_Phdr)
624 +                            : sizeof (Elf32_External_Phdr))
625 +      || i_ehdr.e_phnum == 0)
626 +    {
627 +      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
628 +       warning (_("build-id: Invalid ELF program headers from the ELF header "
629 +                  "at address 0x%lx"), (unsigned long) ehdr_vma);
630 +      return NULL;
631 +    }
632 +
633 +  x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
634 +                                               : sizeof (Elf32_External_Phdr));
635 +
636 +  i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
637 +  x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
638 +  err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
639 +                           i_ehdr.e_phnum * x_phdrs_size);
640 +  if (err)
641 +    {
642 +      free (i_phdrs);
643 +      if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
644 +        warning (_("build-id: Error reading "
645 +                  "ELF program headers at address 0x%lx"),
646 +                (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
647 +      return NULL;
648 +    }
649 +
650 +  loadbase = ehdr_vma;
651 +  loadbase_set = 0;
652 +  for (i = 0; i < i_ehdr.e_phnum; ++i)
653 +    {
654 +      elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
655 +                              (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
656 +      /* IA-64 vDSO may have two mappings for one segment, where one mapping
657 +        is executable only, and one is read only.  We must not use the
658 +        executable one (PF_R is the first one, PF_X the second one).  */
659 +      if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
660 +       {
661 +         /* Only the first PT_LOAD segment indicates the file bias.
662 +            Next segments may have P_VADDR arbitrarily higher.
663 +            If the first segment has P_VADDR zero any next segment must not
664 +            confuse us, the first one sets LOADBASE certainly enough.  */
665 +         if (!loadbase_set && i_phdrs[i].p_offset == 0)
666 +           {
667 +             loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
668 +             loadbase_set = 1;
669 +           }
670 +       }
671 +    }
672 +
673 +  if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
674 +    warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
675 +            (unsigned long) ehdr_vma, (unsigned long) loadbase);
676 +
677 +  *e_phnum_pointer = i_ehdr.e_phnum;
678 +  *loadbase_pointer = loadbase;
679 +  return i_phdrs;
680 +}
681 +
682 +/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
683 +   Find the first section before ADDR containing an ELF header.
684 +   We rely on the fact the sections from multiple files do not mix.
685 +   FIXME: We should check ADDR is contained _inside_ the section with possibly
686 +   missing content (P_FILESZ < P_MEMSZ).  These omitted sections are currently
687 +   hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR.  */
688 +
689 +static CORE_ADDR build_id_addr;
690 +struct build_id_addr_sect
691 +  {
692 +    struct build_id_addr_sect *next;
693 +    asection *sect;
694 +  };
695 +static struct build_id_addr_sect *build_id_addr_sect;
696 +
697 +static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
698 +{
699 +  if (build_id_addr >= bfd_section_vma (abfd, sect))
700 +    {
701 +      struct build_id_addr_sect *candidate;
702 +
703 +      candidate = xmalloc (sizeof *candidate);
704 +      candidate->next = build_id_addr_sect;
705 +      build_id_addr_sect = candidate;
706 +      candidate->sect = sect;
707 +    }
708 +}
709 +
710 +struct bfd_build_id *
711 +build_id_addr_get (CORE_ADDR addr)
712 +{
713 +  struct build_id_addr_sect *candidate;
714 +  struct bfd_build_id *retval = NULL;
715 +  Elf_Internal_Phdr *i_phdr = NULL;
716 +  bfd_vma loadbase = 0;
717 +  unsigned e_phnum = 0;
718 +
719 +  if (core_bfd == NULL)
720 +    return NULL;
721 +
722 +  build_id_addr = addr;
723 +  gdb_assert (build_id_addr_sect == NULL);
724 +  bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
725 +
726 +  /* Sections are sorted in the high-to-low VMAs order.
727 +     Stop the search on the first ELF header we find.
728 +     Do not continue the search even if it does not contain NT_GNU_BUILD_ID.  */
729 +
730 +  for (candidate = build_id_addr_sect; candidate != NULL;
731 +       candidate = candidate->next)
732 +    {
733 +      i_phdr = elf_get_phdr (core_bfd,
734 +                            bfd_section_vma (core_bfd, candidate->sect),
735 +                            &e_phnum, &loadbase);
736 +      if (i_phdr != NULL)
737 +       break;
738 +    }
739 +
740 +  if (i_phdr != NULL)
741 +    {
742 +      retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
743 +      xfree (i_phdr);
744 +    }
745 +
746 +  while (build_id_addr_sect != NULL)
747 +    {
748 +      candidate = build_id_addr_sect;
749 +      build_id_addr_sect = candidate->next;
750 +      xfree (candidate);
751 +    }
752 +
753 +  return retval;
754 +}
755 +
756  /* See build-id.h.  */
757  
758  int
759 @@ -50,7 +448,7 @@ build_id_verify (bfd *abfd, size_t check
760    const struct bfd_build_id *found;
761    int retval = 0;
762  
763 -  found = build_id_bfd_get (abfd);
764 +  found = build_id_bfd_shdr_get (abfd);
765  
766    if (found == NULL)
767      warning (_("File \"%s\" has no build-id, file skipped"),
768 @@ -65,20 +463,56 @@ build_id_verify (bfd *abfd, size_t check
769    return retval;
770  }
771  
772 +static char *
773 +link_resolve (const char *symlink, int level)
774 +{
775 +  char buf[PATH_MAX + 1], *target, *retval;
776 +  ssize_t got;
777 +
778 +  if (level > 10)
779 +    return xstrdup (symlink);
780 +
781 +  got = readlink (symlink, buf, sizeof (buf));
782 +  if (got < 0 || got >= sizeof (buf))
783 +    return xstrdup (symlink);
784 +  buf[got] = '\0';
785 +
786 +  if (IS_ABSOLUTE_PATH (buf))
787 +    target = xstrdup (buf);
788 +  else
789 +    {
790 +      char *dir = ldirname (symlink);
791 +
792 +      if (dir == NULL)
793 +       return xstrdup (symlink);
794 +      target = xstrprintf ("%s"
795 +#ifndef HAVE_DOS_BASED_FILE_SYSTEM
796 +                          "/"
797 +#else /* HAVE_DOS_BASED_FILE_SYSTEM */
798 +                          "\\"
799 +#endif /* HAVE_DOS_BASED_FILE_SYSTEM */
800 +                          "%s", dir, buf);
801 +    }
802 +
803 +  retval = link_resolve (target, level + 1);
804 +  xfree (target);
805 +  return retval;
806 +}
807 +
808  /* See build-id.h.  */
809  
810  bfd *
811 -build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
812 +build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id,
813 +                      char **link_return, int add_debug_suffix)
814  {
815 -  char *link, *debugdir;
816 +  char *link, *debugdir, *link_all = NULL;
817    VEC (char_ptr) *debugdir_vec;
818    struct cleanup *back_to;
819    int ix;
820    bfd *abfd = NULL;
821  
822    /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
823 -  link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
824 -                + 2 * build_id_len + (sizeof ".debug" - 1) + 1);
825 +  link = xmalloc (strlen (debug_file_directory) + 2 * build_id_len + 50);
826  
827    /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
828       cause "/.build-id/..." lookups.  */
829 @@ -91,9 +525,12 @@ build_id_to_debug_bfd (size_t build_id_l
830        size_t debugdir_len = strlen (debugdir);
831        const gdb_byte *data = build_id;
832        size_t size = build_id_len;
833 -      char *s;
834        char *filename = NULL;
835        struct cleanup *inner;
836 +      unsigned seqno;
837 +      struct stat statbuf_trash;
838 +      /* Initialize it just to avoid a GCC false warning.  */
839 +      char *s, *link0 = NULL, *link0_resolved;
840  
841        memcpy (link, debugdir, debugdir_len);
842        s = &link[debugdir_len];
843 @@ -107,47 +544,281 @@ build_id_to_debug_bfd (size_t build_id_l
844         *s++ = '/';
845        while (size-- > 0)
846         s += sprintf (s, "%02x", (unsigned) *data++);
847 -      strcpy (s, ".debug");
848 +      for (seqno = 0;; seqno++)
849 +       {
850 +         char *s2;
851  
852 -      /* lrealpath() is expensive even for the usually non-existent files.  */
853 -      if (access (link, F_OK) == 0)
854 -       filename = lrealpath (link);
855 +         if (seqno)
856 +           {
857 +             /* There can be multiple build-id symlinks pointing to real files
858 +                with the same build-id (such as hard links).  Some of the real
859 +                files may not be installed.  */
860 +
861 +             s2 = s + sprintf (s, ".%u", seqno);
862 +           }
863 +         else
864 +           s2 = s;
865 +
866 +         if (add_debug_suffix)
867 +           strcpy (s2, ".debug");
868 +         else
869 +           *s2 = 0;
870 +
871 +         if (!seqno)
872 +           {
873 +             /* If none of the real files is found report as missing file
874 +                always the non-.%u-suffixed file.  */
875 +             link0 = xstrdup (link);
876 +           }
877 +
878 +         /* `access' automatically dereferences LINK.  */
879 +         if (lstat (link, &statbuf_trash) != 0)
880 +           {
881 +             /* Stop increasing SEQNO.  */
882 +             break;
883 +           }
884 +
885 +         filename = lrealpath (link);
886 +         if (filename == NULL)
887 +           continue;
888 +
889 +         /* We expect to be silent on the non-existing files.  */
890 +         inner = make_cleanup (xfree, filename);
891 +         abfd = gdb_bfd_open (filename, gnutarget, -1);
892 +         do_cleanups (inner);
893  
894 -      if (filename == NULL)
895 -       continue;
896 +         if (abfd == NULL)
897 +           continue;
898  
899 -      /* We expect to be silent on the non-existing files.  */
900 -      inner = make_cleanup (xfree, filename);
901 -      abfd = gdb_bfd_open (filename, gnutarget, -1);
902 -      do_cleanups (inner);
903 +         if (build_id_verify (abfd, build_id_len, build_id))
904 +           break;
905  
906 -      if (abfd == NULL)
907 -       continue;
908 +         gdb_bfd_unref (abfd);
909 +         abfd = NULL;
910  
911 -      if (build_id_verify (abfd, build_id_len, build_id))
912 -       break;
913 +         filename = NULL;
914 +       }
915  
916 -      gdb_bfd_unref (abfd);
917 -      abfd = NULL;
918 +      if (filename != NULL)
919 +       {
920 +         /* LINK_ALL is not used below in this non-NULL FILENAME case.  */
921 +         xfree (link0);
922 +         break;
923 +       }
924 +
925 +      /* If the symlink has target request to install the target.
926 +         BASE-debuginfo.rpm contains the symlink but BASE.rpm may be missing.
927 +         https://bugzilla.redhat.com/show_bug.cgi?id=981154  */
928 +      link0_resolved = link_resolve (link0, 0);
929 +      xfree (link0);
930 +
931 +      if (link_all == NULL)
932 +       link_all = link0_resolved;
933 +      else
934 +       {
935 +         size_t len_orig = strlen (link_all);
936 +
937 +         link_all = xrealloc (link_all,
938 +                              len_orig + 1 + strlen (link0_resolved) + 1);
939 +
940 +         /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
941 +            its possible use as an argument for installation command.  */
942 +         link_all[len_orig] = ' ';
943 +
944 +         strcpy (&link_all[len_orig + 1], link0_resolved);
945 +         xfree (link0_resolved);
946 +       }
947 +    }
948 +
949 +  if (link_return != NULL)
950 +    {
951 +      if (abfd != NULL)
952 +       {
953 +         *link_return = link;
954 +         link = NULL;
955 +       }
956 +      else
957 +       {
958 +         *link_return = link_all;
959 +         link_all = NULL;
960 +       }
961      }
962 +  xfree (link);
963 +  xfree (link_all);
964  
965    do_cleanups (back_to);
966    return abfd;
967  }
968  
969 +char *
970 +build_id_to_filename (const struct bfd_build_id *build_id, char **link_return)
971 +{
972 +  bfd *abfd;
973 +  char *result;
974 +  
975 +  abfd = build_id_to_debug_bfd (build_id->size, build_id->data, link_return, 0);
976 +  if (abfd == NULL)
977 +    return NULL;
978 +
979 +  result = xstrdup (bfd_get_filename (abfd));
980 +  gdb_bfd_unref (abfd);
981 +  return result;
982 +}
983 +
984 +/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
985 +     Try to install the hash file ...
986 +   avoidance.  */
987 +
988 +struct missing_filepair
989 +  {
990 +    char *binary;
991 +    char *debug;
992 +    char data[1];
993 +  };
994 +
995 +static struct htab *missing_filepair_hash;
996 +static struct obstack missing_filepair_obstack;
997 +
998 +static void *
999 +missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
1000 +{
1001 +  void *retval;
1002 +  size_t size = nmemb * nmemb_size;
1003 +
1004 +  retval = obstack_alloc (&missing_filepair_obstack, size);
1005 +  memset (retval, 0, size);
1006 +  return retval;
1007 +}
1008 +
1009 +static hashval_t
1010 +missing_filepair_hash_func (const struct missing_filepair *elem)
1011 +{
1012 +  hashval_t retval = 0;
1013 +
1014 +  retval ^= htab_hash_string (elem->binary);
1015 +  if (elem->debug != NULL)
1016 +    retval ^= htab_hash_string (elem->debug);
1017 +
1018 +  return retval;
1019 +}
1020 +
1021 +static int
1022 +missing_filepair_eq (const struct missing_filepair *elem1,
1023 +                      const struct missing_filepair *elem2)
1024 +{
1025 +  return strcmp (elem1->binary, elem2->binary) == 0
1026 +         && ((elem1->debug == NULL) == (elem2->debug == NULL))
1027 +         && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
1028 +}
1029 +
1030 +static void
1031 +missing_filepair_change (void)
1032 +{
1033 +  if (missing_filepair_hash != NULL)
1034 +    {
1035 +      obstack_free (&missing_filepair_obstack, NULL);
1036 +      /* All their memory came just from missing_filepair_OBSTACK.  */
1037 +      missing_filepair_hash = NULL;
1038 +    }
1039 +}
1040 +
1041 +static void
1042 +debug_print_executable_changed (void)
1043 +{
1044 +  missing_filepair_change ();
1045 +}
1046 +
1047 +/* Notify user the file BINARY with (possibly NULL) associated separate debug
1048 +   information file DEBUG is missing.  DEBUG may or may not be the build-id
1049 +   file such as would be:
1050 +     /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
1051 +   */
1052 +
1053 +void
1054 +debug_print_missing (const char *binary, const char *debug)
1055 +{
1056 +  size_t binary_len0 = strlen (binary) + 1;
1057 +  size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
1058 +  struct missing_filepair missing_filepair_find;
1059 +  struct missing_filepair *missing_filepair;
1060 +  struct missing_filepair **slot;
1061 +
1062 +  if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
1063 +    return;
1064 +
1065 +  if (missing_filepair_hash == NULL)
1066 +    {
1067 +      obstack_init (&missing_filepair_obstack);
1068 +      missing_filepair_hash = htab_create_alloc (64,
1069 +       (hashval_t (*) (const void *)) missing_filepair_hash_func,
1070 +       (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
1071 +       missing_filepair_xcalloc, NULL);
1072 +    }
1073 +
1074 +  /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
1075 +     obstack_free in the case of a (rare) match.  The problem is ALLOC_F for
1076 +     MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
1077 +     structures for MISSING_FILEPAIR_HASH.  Calling obstack_free would possibly
1078 +     not to free only MISSING_FILEPAIR but also some such structures (allocated
1079 +     during the htab_find_slot call).  */
1080 +
1081 +  missing_filepair_find.binary = (char *) binary;
1082 +  missing_filepair_find.debug = (char *) debug;
1083 +  slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
1084 +                                                     &missing_filepair_find,
1085 +                                                     INSERT);
1086 +
1087 +  /* While it may be still printed duplicitely with the missing debuginfo file
1088 +   * it is due to once printing about the binary file build-id link and once
1089 +   * about the .debug file build-id link as both the build-id symlinks are
1090 +   * located in the debuginfo package.  */
1091 +
1092 +  if (*slot != NULL)
1093 +    return;
1094 +
1095 +  missing_filepair = obstack_alloc (&missing_filepair_obstack,
1096 +                                     sizeof (*missing_filepair) - 1
1097 +                                     + binary_len0 + debug_len0);
1098 +  missing_filepair->binary = missing_filepair->data;
1099 +  memcpy (missing_filepair->binary, binary, binary_len0);
1100 +  if (debug != NULL)
1101 +    {
1102 +      missing_filepair->debug = missing_filepair->binary + binary_len0;
1103 +      memcpy (missing_filepair->debug, debug, debug_len0);
1104 +    }
1105 +  else
1106 +    missing_filepair->debug = NULL;
1107 +
1108 +  *slot = missing_filepair;
1109 +
1110 +  /* We do not collect and flush these messages as each such message
1111 +     already requires its own separate lines.  */
1112 +
1113 +  fprintf_unfiltered (gdb_stdlog,
1114 +                     _("Missing separate debuginfo for %s\n"), binary);
1115 +  if (debug != NULL)
1116 +    fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
1117 +                       debug);
1118 +}
1119 +
1120  /* See build-id.h.  */
1121  
1122  char *
1123 -find_separate_debug_file_by_buildid (struct objfile *objfile)
1124 +find_separate_debug_file_by_buildid (struct objfile *objfile,
1125 +                                    char **build_id_filename_return)
1126  {
1127    const struct bfd_build_id *build_id;
1128  
1129 -  build_id = build_id_bfd_get (objfile->obfd);
1130 +  if (build_id_filename_return)
1131 +    *build_id_filename_return = NULL;
1132 +
1133 +  build_id = build_id_bfd_shdr_get (objfile->obfd);
1134    if (build_id != NULL)
1135      {
1136        bfd *abfd;
1137  
1138 -      abfd = build_id_to_debug_bfd (build_id->size, build_id->data);
1139 +      abfd = build_id_to_debug_bfd (build_id->size, build_id->data,
1140 +                                   build_id_filename_return, 1);
1141        /* Prevent looping on a stripped .debug file.  */
1142        if (abfd != NULL
1143           && filename_cmp (bfd_get_filename (abfd),
1144 @@ -167,3 +838,21 @@ find_separate_debug_file_by_buildid (str
1145      }
1146    return NULL;
1147  }
1148 +
1149 +extern void _initialize_build_id (void);
1150 +
1151 +void
1152 +_initialize_build_id (void)
1153 +{
1154 +  add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
1155 +                           _("\
1156 +Set debugging level of the build-id locator."), _("\
1157 +Show debugging level of the build-id locator."), _("\
1158 +Level 1 (default) enables printing the missing debug filenames,\n\
1159 +level 2 also prints the parsing of binaries to find the identificators."),
1160 +                           NULL,
1161 +                           show_build_id_verbose,
1162 +                           &setlist, &showlist);
1163 +
1164 +  observer_attach_executable_changed (debug_print_executable_changed);
1165 +}
1166 Index: gdb-7.9.90.20150709/gdb/build-id.h
1167 ===================================================================
1168 --- gdb-7.9.90.20150709.orig/gdb/build-id.h     2015-07-09 22:05:20.988044312 +0200
1169 +++ gdb-7.9.90.20150709/gdb/build-id.h  2015-07-09 22:05:42.072222849 +0200
1170 @@ -20,9 +20,10 @@
1171  #ifndef BUILD_ID_H
1172  #define BUILD_ID_H
1173  
1174 -/* Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
1175 +/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
1176 +   Locate NT_GNU_BUILD_ID from ABFD and return its content.  */
1177  
1178 -extern const struct bfd_build_id *build_id_bfd_get (bfd *abfd);
1179 +extern const struct bfd_build_id *build_id_bfd_shdr_get (bfd *abfd);
1180  
1181  /* Return true if ABFD has NT_GNU_BUILD_ID matching the CHECK value.
1182     Otherwise, issue a warning and return false.  */
1183 @@ -36,13 +37,18 @@ extern int build_id_verify (bfd *abfd,
1184     the caller.  */
1185  
1186  extern bfd *build_id_to_debug_bfd (size_t build_id_len,
1187 -                                  const bfd_byte *build_id);
1188 +                                  const bfd_byte *build_id, char **link_return,
1189 +                                  int add_debug_suffix);
1190 +
1191 +extern char *build_id_to_filename (const struct bfd_build_id *build_id,
1192 +                                  char **link_return);
1193  
1194  /* Find the separate debug file for OBJFILE, by using the build-id
1195     associated with OBJFILE's BFD.  If successful, returns a malloc'd
1196     file name for the separate debug file.  The caller must free this.
1197     Otherwise, returns NULL.  */
1198  
1199 -extern char *find_separate_debug_file_by_buildid (struct objfile *objfile);
1200 +extern char *find_separate_debug_file_by_buildid (struct objfile *objfile,
1201 +                                              char **build_id_filename_return);
1202  
1203  #endif /* BUILD_ID_H */
1204 Index: gdb-7.9.90.20150709/gdb/dwarf2read.c
1205 ===================================================================
1206 --- gdb-7.9.90.20150709.orig/gdb/dwarf2read.c   2015-07-09 22:05:20.988044312 +0200
1207 +++ gdb-7.9.90.20150709/gdb/dwarf2read.c        2015-07-09 22:05:42.077222891 +0200
1208 @@ -2507,7 +2507,7 @@ dwarf2_get_dwz_file (void)
1209      }
1210  
1211    if (dwz_bfd == NULL)
1212 -    dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid);
1213 +    dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid, NULL, 1);
1214  
1215    if (dwz_bfd == NULL)
1216      error (_("could not find '.gnu_debugaltlink' file for %s"),
1217 Index: gdb-7.9.90.20150709/gdb/python/py-objfile.c
1218 ===================================================================
1219 --- gdb-7.9.90.20150709.orig/gdb/python/py-objfile.c    2015-07-09 22:05:20.988044312 +0200
1220 +++ gdb-7.9.90.20150709/gdb/python/py-objfile.c 2015-07-09 22:05:42.077222891 +0200
1221 @@ -139,7 +139,7 @@ objfpy_get_build_id (PyObject *self, voi
1222  
1223    TRY
1224      {
1225 -      build_id = build_id_bfd_get (objfile->obfd);
1226 +      build_id = build_id_bfd_shdr_get (objfile->obfd);
1227      }
1228    CATCH (except, RETURN_MASK_ALL)
1229      {
1230 @@ -548,7 +548,7 @@ objfpy_lookup_objfile_by_build_id (const
1231        /* Don't return separate debug files.  */
1232        if (objfile->separate_debug_objfile_backlink != NULL)
1233         continue;
1234 -      obfd_build_id = build_id_bfd_get (objfile->obfd);
1235 +      obfd_build_id = build_id_bfd_shdr_get (objfile->obfd);
1236        if (obfd_build_id == NULL)
1237         continue;
1238        if (objfpy_build_id_matches (obfd_build_id, build_id))
1239 Index: gdb-7.9.90.20150709/gdb/coffread.c
1240 ===================================================================
1241 --- gdb-7.9.90.20150709.orig/gdb/coffread.c     2015-07-09 22:05:20.988044312 +0200
1242 +++ gdb-7.9.90.20150709/gdb/coffread.c  2015-07-09 22:05:42.078222899 +0200
1243 @@ -739,7 +739,7 @@ coff_symfile_read (struct objfile *objfi
1244      {
1245        char *debugfile;
1246  
1247 -      debugfile = find_separate_debug_file_by_buildid (objfile);
1248 +      debugfile = find_separate_debug_file_by_buildid (objfile, NULL);
1249  
1250        if (debugfile == NULL)
1251         debugfile = find_separate_debug_file_by_debuglink (objfile);
This page took 0.151631 seconds and 3 git commands to generate.