]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.6-buildid-locate.patch
- up to 7.8; updated patches copied from Fedora (263b580)
[packages/gdb.git] / gdb-6.6-buildid-locate.patch
CommitLineData
f727df28 1Index: gdb-7.7.50.20140609/gdb/corelow.c
3a58abaf 2===================================================================
f727df28
KK
3--- gdb-7.7.50.20140609.orig/gdb/corelow.c 2014-06-13 20:09:37.369745221 +0200
4+++ gdb-7.7.50.20140609/gdb/corelow.c 2014-06-13 20:09:42.407750265 +0200
5@@ -49,6 +49,10 @@
a7de96f0 6 #include "gdb_bfd.h"
321e94d6
BS
7 #include "completer.h"
8 #include "filestuff.h"
3a58abaf
AM
9+#include "auxv.h"
10+#include "elf/common.h"
3a58abaf 11+#include "gdbcmd.h"
321e94d6 12+#include "build-id.h"
3a58abaf 13
3a58abaf 14 #ifndef O_LARGEFILE
f412e1b4 15 #define O_LARGEFILE 0
f727df28 16@@ -272,6 +276,53 @@ add_to_thread_list (bfd *abfd, asection
6ed6bacf 17 inferior_ptid = ptid; /* Yes, make it current. */
3a58abaf
AM
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;
03ffe914 26+ struct elf_build_id *build_id;
1dce4dc1 27+ char *execfilename, *debug_filename;
3a58abaf 28+ char *build_id_filename;
7566401a 29+ struct cleanup *back_to;
3a58abaf 30+
7566401a 31+ if (exec_bfd != NULL || symfile_objfile != NULL)
3a58abaf
AM
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;
03ffe914 40+ back_to = make_cleanup (xfree, build_id);
3a58abaf 41+
7566401a
ER
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+
321e94d6 48+ execfilename = build_id_to_filename (build_id, &build_id_filename);
03ffe914 49+ make_cleanup (xfree, build_id_filename);
3a58abaf 50+
1dce4dc1 51+ if (execfilename != NULL)
3a58abaf 52+ {
1dce4dc1
KK
53+ make_cleanup (xfree, execfilename);
54+ exec_file_attach (execfilename, from_tty);
55+ symbol_file_add_main (execfilename, from_tty);
7566401a
ER
56+ if (symfile_objfile != NULL)
57+ symfile_objfile->flags |= OBJF_BUILD_ID_CORE_LOADED;
3a58abaf
AM
58+ }
59+ else
7566401a 60+ debug_print_missing (_("the main executable file"), build_id_filename);
3a58abaf 61+
7566401a 62+ do_cleanups (back_to);
3a58abaf
AM
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
f727df28 70@@ -410,6 +461,14 @@ core_open (char *filename, int from_tty)
a7de96f0
PS
71 switch_to_thread (thread->ptid);
72 }
3a58abaf
AM
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
a7de96f0
PS
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. */
3a58abaf
AM
79+ if (build_id_core_loads != 0)
80+ build_id_locate_exec (from_tty);
81+
a7de96f0
PS
82 post_create_inferior (&core_ops, from_tty);
83
84 /* Now go through the target stack looking for threads since there
f727df28 85@@ -1029,4 +1088,11 @@ _initialize_corelow (void)
3a58abaf
AM
86 init_core_ops ();
87
321e94d6 88 add_target_with_completer (&core_ops, filename_completer);
3a58abaf
AM
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."), _("\
a7de96f0 93+Show whether CORE-FILE loads the build-id associated files automatically."),
3a58abaf
AM
94+ NULL, NULL, NULL,
95+ &setlist, &showlist);
96 }
f727df28 97Index: gdb-7.7.50.20140609/gdb/doc/gdb.texinfo
3a58abaf 98===================================================================
f727df28
KK
99--- gdb-7.7.50.20140609.orig/gdb/doc/gdb.texinfo 2014-06-13 20:09:37.380745232 +0200
100+++ gdb-7.7.50.20140609/gdb/doc/gdb.texinfo 2014-06-13 20:09:42.417750275 +0200
101@@ -17547,6 +17547,27 @@ information files.
3a58abaf
AM
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
f727df28 129Index: gdb-7.7.50.20140609/gdb/solib-svr4.c
3a58abaf 130===================================================================
f727df28
KK
131--- gdb-7.7.50.20140609.orig/gdb/solib-svr4.c 2014-06-13 20:09:37.382745234 +0200
132+++ gdb-7.7.50.20140609/gdb/solib-svr4.c 2014-06-13 20:09:42.418750276 +0200
133@@ -48,6 +48,7 @@
321e94d6
BS
134 #include "exceptions.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@@ -1369,9 +1370,52 @@ svr4_read_so_list (CORE_ADDR lm, CORE_AD
f412e1b4
PS
142 continue;
143 }
144
145- strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
146- new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
147- strcpy (new->so_original_name, new->so_name);
148+ {
03ffe914 149+ struct elf_build_id *build_id;
f412e1b4
PS
150+
151+ strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
152+ new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
153+ /* May get overwritten below. */
154+ strcpy (new->so_name, new->so_original_name);
155+
156+ build_id = build_id_addr_get (new->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. */
321e94d6 163+ name = build_id_to_filename (build_id, &build_id_filename);
f412e1b4
PS
164+ if (name != NULL)
165+ {
166+ strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
167+ new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
168+ xfree (name);
169+ }
170+ else
171+ {
172+ debug_print_missing (new->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+ new->so_name[0] = 0;
187+ }
188+
189+ xfree (build_id_filename);
190+ xfree (build_id);
191+ }
192+ }
193+
194 xfree (buffer);
3a58abaf 195
f412e1b4 196 /* If this entry has no name, or its name matches the name
f727df28 197Index: gdb-7.7.50.20140609/gdb/elfread.c
3a58abaf 198===================================================================
f727df28
KK
199--- gdb-7.7.50.20140609.orig/gdb/elfread.c 2014-06-13 20:09:37.383745235 +0200
200+++ gdb-7.7.50.20140609/gdb/elfread.c 2014-06-13 20:09:42.418750276 +0200
201@@ -1335,9 +1335,10 @@ elf_symfile_read (struct objfile *objfil
321e94d6
BS
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);
f727df28 214@@ -1351,6 +1352,12 @@ elf_symfile_read (struct objfile *objfil
321e94d6
BS
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
f727df28 227Index: gdb-7.7.50.20140609/gdb/symfile.h
321e94d6 228===================================================================
f727df28
KK
229--- gdb-7.7.50.20140609.orig/gdb/symfile.h 2014-06-13 20:09:42.419750277 +0200
230+++ gdb-7.7.50.20140609/gdb/symfile.h 2014-06-13 20:10:04.478772510 +0200
231@@ -570,6 +570,10 @@ void expand_symtabs_matching (expand_sym
232 void map_symbol_filenames (symbol_filename_ftype *fun, void *data,
233 int need_fullname);
321e94d6
BS
234
235+/* build-id support. */
236+extern struct elf_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
f727df28 242Index: gdb-7.7.50.20140609/gdb/testsuite/lib/gdb.exp
321e94d6 243===================================================================
f727df28
KK
244--- gdb-7.7.50.20140609.orig/gdb/testsuite/lib/gdb.exp 2014-06-13 20:09:37.384745236 +0200
245+++ gdb-7.7.50.20140609/gdb/testsuite/lib/gdb.exp 2014-06-13 20:09:42.420750278 +0200
246@@ -1492,6 +1492,16 @@ proc default_gdb_start { } {
321e94d6
BS
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
f727df28 263Index: gdb-7.7.50.20140609/gdb/testsuite/lib/mi-support.exp
321e94d6 264===================================================================
f727df28
KK
265--- gdb-7.7.50.20140609.orig/gdb/testsuite/lib/mi-support.exp 2014-06-13 20:09:37.385745237 +0200
266+++ gdb-7.7.50.20140609/gdb/testsuite/lib/mi-support.exp 2014-06-13 20:09:42.421750279 +0200
321e94d6
BS
267@@ -212,6 +212,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 } {
f727df28 284Index: gdb-7.7.50.20140609/gdb/objfiles.h
321e94d6 285===================================================================
f727df28
KK
286--- gdb-7.7.50.20140609.orig/gdb/objfiles.h 2014-06-13 20:09:37.385745237 +0200
287+++ gdb-7.7.50.20140609/gdb/objfiles.h 2014-06-13 20:09:42.421750279 +0200
288@@ -464,6 +464,10 @@ struct objfile
321e94d6
BS
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);
f727df28 299Index: gdb-7.7.50.20140609/gdb/testsuite/gdb.base/corefile.exp
321e94d6 300===================================================================
f727df28
KK
301--- gdb-7.7.50.20140609.orig/gdb/testsuite/gdb.base/corefile.exp 2014-06-13 20:09:37.385745237 +0200
302+++ gdb-7.7.50.20140609/gdb/testsuite/gdb.base/corefile.exp 2014-06-13 20:09:42.421750279 +0200
303@@ -293,3 +293,33 @@ gdb_test_multiple "core-file $corefile"
321e94d6
BS
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+}
f727df28 337Index: gdb-7.7.50.20140609/gdb/build-id.c
321e94d6 338===================================================================
f727df28
KK
339--- gdb-7.7.50.20140609.orig/gdb/build-id.c 2014-06-13 20:09:37.386745238 +0200
340+++ gdb-7.7.50.20140609/gdb/build-id.c 2014-06-13 20:09:42.422750280 +0200
321e94d6
BS
341@@ -27,11 +27,65 @@
342 #include "symfile.h"
343 #include "objfiles.h"
344 #include "filenames.h"
3a58abaf 345+#include "libbfd.h"
51a5ef0f
PS
346+#include "gdbcore.h"
347+#include "gdbcmd.h"
348+#include "observer.h"
6ed6bacf 349+#include <sys/stat.h>
321e94d6 350+
3a58abaf
AM
351+#define BUILD_ID_VERBOSE_NONE 0
352+#define BUILD_ID_VERBOSE_FILENAMES 1
353+#define BUILD_ID_VERBOSE_BINARY_PARSE 2
354+static int build_id_verbose = BUILD_ID_VERBOSE_FILENAMES;
355+static void
356+show_build_id_verbose (struct ui_file *file, int from_tty,
357+ struct cmd_list_element *c, const char *value)
358+{
359+ fprintf_filtered (file, _("Verbosity level of the build-id locator is %s.\n"),
360+ value);
361+}
362+
6ed6bacf
AM
363+/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
364+ FIXME: NOTE decoding should be unified with the BFD core notes decoding. */
321e94d6
BS
365
366-/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */
03ffe914 367+static struct elf_build_id *
3a58abaf
AM
368+build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
369+{
370+ bfd_byte *p;
371+
372+ p = buf;
373+ while (p < buf + size)
374+ {
375+ /* FIXME: bad alignment assumption. */
376+ Elf_External_Note *xnp = (Elf_External_Note *) p;
377+ size_t namesz = H_GET_32 (templ, xnp->namesz);
378+ size_t descsz = H_GET_32 (templ, xnp->descsz);
321e94d6 379+ bfd_byte *descdata = (gdb_byte *) xnp->name + BFD_ALIGN (namesz, 4);
3a58abaf
AM
380+
381+ if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
382+ && namesz == sizeof "GNU"
383+ && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
384+ {
385+ size_t size = descsz;
386+ gdb_byte *data = (void *) descdata;
03ffe914 387+ struct elf_build_id *retval;
3a58abaf
AM
388+
389+ retval = xmalloc (sizeof *retval - 1 + size);
390+ retval->size = size;
391+ memcpy (retval->data, data, size);
392+
393+ return retval;
394+ }
395+ p = descdata + BFD_ALIGN (descsz, 4);
396+ }
397+ return NULL;
398+}
321e94d6 399
3a58abaf
AM
400+/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
401+ Locate NT_GNU_BUILD_ID from ABFD and return its content. */
321e94d6 402+
03ffe914
JR
403 static const struct elf_build_id *
404-build_id_bfd_get (bfd *abfd)
3a58abaf
AM
405+build_id_bfd_shdr_get (bfd *abfd)
406 {
03ffe914
JR
407 if (!bfd_check_format (abfd, bfd_object)
408 || bfd_get_flavour (abfd) != bfd_target_elf_flavour
321e94d6 409@@ -45,6 +99,348 @@ build_id_bfd_get (bfd *abfd)
03ffe914 410 return elf_tdata (abfd)->build_id;
3a58abaf
AM
411 }
412
413+/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
414+ bfd_elf_bfd_from_remote_memory () has too much overhead by
415+ allocating/reading all the available ELF PT_LOADs. */
416+
03ffe914 417+static struct elf_build_id *
3a58abaf
AM
418+build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
419+ Elf_Internal_Phdr *i_phdr)
420+{
421+ int i;
03ffe914 422+ struct elf_build_id *retval = NULL;
3a58abaf
AM
423+
424+ for (i = 0; i < e_phnum; i++)
425+ if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
426+ {
427+ Elf_Internal_Phdr *hdr = &i_phdr[i];
428+ gdb_byte *buf;
429+ int err;
430+
431+ buf = xmalloc (hdr->p_filesz);
432+ err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
433+ hdr->p_filesz);
434+ if (err == 0)
435+ retval = build_id_buf_get (templ, buf, hdr->p_filesz);
436+ else
437+ retval = NULL;
438+ xfree (buf);
439+ if (retval != NULL)
440+ break;
441+ }
442+ return retval;
443+}
444+
445+/* First we validate the file by reading in the ELF header and checking
446+ the magic number. */
447+
448+static inline bfd_boolean
449+elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
450+{
451+ gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
452+ gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
453+ == offsetof (Elf32_External_Ehdr, e_ident));
454+ gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
455+ == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
456+
457+ return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
458+ && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
459+ && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
460+ && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
461+}
462+
463+/* Translate an ELF file header in external format into an ELF file header in
464+ internal format. */
465+
466+#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr)) \
467+ : H_GET_32 (bfd, (ptr)))
468+#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr)) \
469+ : H_GET_S32 (bfd, (ptr)))
470+
471+static void
472+elf_swap_ehdr_in (bfd *abfd,
473+ const Elf64_External_Ehdr *src64,
474+ Elf_Internal_Ehdr *dst)
475+{
476+ int is64 = bfd_get_arch_size (abfd) == 64;
477+#define SRC(field) (is64 ? src64->field \
478+ : ((const Elf32_External_Ehdr *) src64)->field)
479+
480+ int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
481+ memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
482+ dst->e_type = H_GET_16 (abfd, SRC (e_type));
483+ dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
484+ dst->e_version = H_GET_32 (abfd, SRC (e_version));
485+ if (signed_vma)
486+ dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
487+ else
488+ dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
489+ dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
490+ dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
491+ dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
492+ dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
493+ dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
494+ dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
495+ dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
496+ dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
497+ dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
498+
499+#undef SRC
500+}
501+
502+/* Translate an ELF program header table entry in external format into an
503+ ELF program header table entry in internal format. */
504+
a7de96f0 505+static void
3a58abaf
AM
506+elf_swap_phdr_in (bfd *abfd,
507+ const Elf64_External_Phdr *src64,
508+ Elf_Internal_Phdr *dst)
509+{
510+ int is64 = bfd_get_arch_size (abfd) == 64;
511+#define SRC(field) (is64 ? src64->field \
512+ : ((const Elf32_External_Phdr *) src64)->field)
513+
514+ int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
515+
516+ dst->p_type = H_GET_32 (abfd, SRC (p_type));
517+ dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
518+ dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
519+ if (signed_vma)
520+ {
521+ dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
522+ dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
523+ }
524+ else
525+ {
526+ dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
527+ dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
528+ }
529+ dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
530+ dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
531+ dst->p_align = H_GET_WORD (abfd, SRC (p_align));
532+
533+#undef SRC
534+}
535+
536+#undef H_GET_SIGNED_WORD
537+#undef H_GET_WORD
538+
539+static Elf_Internal_Phdr *
540+elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
541+ bfd_vma *loadbase_pointer)
542+{
543+ /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr) */
544+ Elf64_External_Ehdr x_ehdr64; /* Elf file header, external form */
545+ Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
546+ bfd_size_type x_phdrs_size;
547+ gdb_byte *x_phdrs_ptr;
548+ Elf_Internal_Phdr *i_phdrs;
549+ int err;
550+ unsigned int i;
551+ bfd_vma loadbase;
552+ int loadbase_set;
553+
554+ gdb_assert (templ != NULL);
555+ gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
556+
557+ /* Read in the ELF header in external format. */
558+ err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
559+ if (err)
560+ {
561+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
562+ warning (_("build-id: Error reading ELF header at address 0x%lx"),
563+ (unsigned long) ehdr_vma);
564+ return NULL;
565+ }
566+
567+ /* Now check to see if we have a valid ELF file, and one that BFD can
568+ make use of. The magic number must match, the address size ('class')
569+ and byte-swapping must match our XVEC entry. */
570+
571+ if (! elf_file_p (&x_ehdr64)
572+ || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
573+ || !((bfd_get_arch_size (templ) == 64
574+ && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
575+ || (bfd_get_arch_size (templ) == 32
576+ && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
577+ {
578+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
579+ warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
580+ (unsigned long) ehdr_vma);
581+ return NULL;
582+ }
583+
584+ /* Check that file's byte order matches xvec's */
585+ switch (x_ehdr64.e_ident[EI_DATA])
586+ {
587+ case ELFDATA2MSB: /* Big-endian */
588+ if (! bfd_header_big_endian (templ))
589+ {
590+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
591+ warning (_("build-id: Unrecognized "
592+ "big-endian ELF header at address 0x%lx"),
593+ (unsigned long) ehdr_vma);
594+ return NULL;
595+ }
596+ break;
597+ case ELFDATA2LSB: /* Little-endian */
598+ if (! bfd_header_little_endian (templ))
599+ {
600+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
601+ warning (_("build-id: Unrecognized "
602+ "little-endian ELF header at address 0x%lx"),
603+ (unsigned long) ehdr_vma);
604+ return NULL;
605+ }
606+ break;
607+ case ELFDATANONE: /* No data encoding specified */
608+ default: /* Unknown data encoding specified */
609+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
610+ warning (_("build-id: Unrecognized "
611+ "ELF header endianity at address 0x%lx"),
612+ (unsigned long) ehdr_vma);
613+ return NULL;
614+ }
615+
616+ elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
617+
618+ /* The file header tells where to find the program headers.
619+ These are what we use to actually choose what to read. */
620+
621+ if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
622+ ? sizeof (Elf64_External_Phdr)
623+ : sizeof (Elf32_External_Phdr))
624+ || i_ehdr.e_phnum == 0)
625+ {
626+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
627+ warning (_("build-id: Invalid ELF program headers from the ELF header "
628+ "at address 0x%lx"), (unsigned long) ehdr_vma);
629+ return NULL;
630+ }
631+
632+ x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
633+ : sizeof (Elf32_External_Phdr));
634+
635+ i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
636+ x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
637+ err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
638+ i_ehdr.e_phnum * x_phdrs_size);
639+ if (err)
640+ {
641+ free (i_phdrs);
642+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
643+ warning (_("build-id: Error reading "
644+ "ELF program headers at address 0x%lx"),
645+ (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
646+ return NULL;
647+ }
648+
649+ loadbase = ehdr_vma;
650+ loadbase_set = 0;
651+ for (i = 0; i < i_ehdr.e_phnum; ++i)
652+ {
653+ elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
654+ (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
655+ /* IA-64 vDSO may have two mappings for one segment, where one mapping
656+ is executable only, and one is read only. We must not use the
657+ executable one (PF_R is the first one, PF_X the second one). */
658+ if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
659+ {
660+ /* Only the first PT_LOAD segment indicates the file bias.
661+ Next segments may have P_VADDR arbitrarily higher.
662+ If the first segment has P_VADDR zero any next segment must not
663+ confuse us, the first one sets LOADBASE certainly enough. */
664+ if (!loadbase_set && i_phdrs[i].p_offset == 0)
665+ {
666+ loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
667+ loadbase_set = 1;
668+ }
669+ }
670+ }
671+
672+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
673+ warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
674+ (unsigned long) ehdr_vma, (unsigned long) loadbase);
675+
676+ *e_phnum_pointer = i_ehdr.e_phnum;
677+ *loadbase_pointer = loadbase;
678+ return i_phdrs;
679+}
680+
681+/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
682+ Find the first section before ADDR containing an ELF header.
683+ We rely on the fact the sections from multiple files do not mix.
684+ FIXME: We should check ADDR is contained _inside_ the section with possibly
685+ missing content (P_FILESZ < P_MEMSZ). These omitted sections are currently
686+ hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR. */
687+
688+static CORE_ADDR build_id_addr;
689+struct build_id_addr_sect
690+ {
691+ struct build_id_addr_sect *next;
692+ asection *sect;
693+ };
694+static struct build_id_addr_sect *build_id_addr_sect;
695+
696+static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
697+{
698+ if (build_id_addr >= bfd_section_vma (abfd, sect))
699+ {
700+ struct build_id_addr_sect *candidate;
701+
702+ candidate = xmalloc (sizeof *candidate);
703+ candidate->next = build_id_addr_sect;
704+ build_id_addr_sect = candidate;
705+ candidate->sect = sect;
706+ }
707+}
708+
03ffe914 709+struct elf_build_id *
3a58abaf
AM
710+build_id_addr_get (CORE_ADDR addr)
711+{
712+ struct build_id_addr_sect *candidate;
03ffe914 713+ struct elf_build_id *retval = NULL;
3a58abaf
AM
714+ Elf_Internal_Phdr *i_phdr = NULL;
715+ bfd_vma loadbase = 0;
716+ unsigned e_phnum = 0;
717+
718+ if (core_bfd == NULL)
719+ return NULL;
720+
721+ build_id_addr = addr;
722+ gdb_assert (build_id_addr_sect == NULL);
723+ bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
724+
725+ /* Sections are sorted in the high-to-low VMAs order.
726+ Stop the search on the first ELF header we find.
727+ Do not continue the search even if it does not contain NT_GNU_BUILD_ID. */
728+
729+ for (candidate = build_id_addr_sect; candidate != NULL;
730+ candidate = candidate->next)
731+ {
732+ i_phdr = elf_get_phdr (core_bfd,
733+ bfd_section_vma (core_bfd, candidate->sect),
734+ &e_phnum, &loadbase);
735+ if (i_phdr != NULL)
736+ break;
737+ }
738+
739+ if (i_phdr != NULL)
740+ {
741+ retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
742+ xfree (i_phdr);
743+ }
744+
745+ while (build_id_addr_sect != NULL)
746+ {
747+ candidate = build_id_addr_sect;
748+ build_id_addr_sect = candidate->next;
749+ xfree (candidate);
750+ }
751+
752+ return retval;
753+}
754+
321e94d6 755 /* See build-id.h. */
3a58abaf 756
321e94d6
BS
757 int
758@@ -53,7 +449,7 @@ build_id_verify (bfd *abfd, size_t check
759 const struct elf_build_id *found;
760 int retval = 0;
3a58abaf
AM
761
762- found = build_id_bfd_get (abfd);
763+ found = build_id_bfd_shdr_get (abfd);
764
765 if (found == NULL)
321e94d6
BS
766 warning (_("File \"%s\" has no build-id, file skipped"),
767@@ -68,20 +464,56 @@ build_id_verify (bfd *abfd, size_t check
768 return retval;
3a58abaf
AM
769 }
770
321e94d6 771+static char *
03ffe914
JR
772+link_resolve (const char *symlink, int level)
773+{
774+ char buf[PATH_MAX + 1], *target, *retval;
775+ ssize_t got;
776+
777+ if (level > 10)
778+ return xstrdup (symlink);
779+
780+ got = readlink (symlink, buf, sizeof (buf));
781+ if (got < 0 || got >= sizeof (buf))
782+ return xstrdup (symlink);
783+ buf[got] = '\0';
784+
785+ if (IS_ABSOLUTE_PATH (buf))
786+ target = xstrdup (buf);
787+ else
788+ {
789+ char *dir = ldirname (symlink);
790+
791+ if (dir == NULL)
792+ return xstrdup (symlink);
793+ target = xstrprintf ("%s"
794+#ifndef HAVE_DOS_BASED_FILE_SYSTEM
795+ "/"
796+#else /* HAVE_DOS_BASED_FILE_SYSTEM */
797+ "\\"
798+#endif /* HAVE_DOS_BASED_FILE_SYSTEM */
799+ "%s", dir, buf);
800+ }
801+
802+ retval = link_resolve (target, level + 1);
803+ xfree (target);
804+ return retval;
805+}
806+
321e94d6
BS
807 /* See build-id.h. */
808
809 bfd *
810-build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
811+build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id,
812+ char **link_return, int add_debug_suffix)
3a58abaf 813 {
321e94d6
BS
814- char *link, *debugdir;
815+ char *link, *debugdir, *link_all = NULL;
a7de96f0
PS
816 VEC (char_ptr) *debugdir_vec;
817 struct cleanup *back_to;
818 int ix;
321e94d6 819 bfd *abfd = NULL;
3a58abaf
AM
820
821 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
ab050a48 822- link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
321e94d6
BS
823- + 2 * build_id_len + (sizeof ".debug" - 1) + 1);
824+ link = xmalloc (strlen (debug_file_directory) + 2 * build_id_len + 50);
ab050a48
BZ
825
826 /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
827 cause "/.build-id/..." lookups. */
321e94d6 828@@ -94,8 +526,11 @@ build_id_to_debug_bfd (size_t build_id_l
a7de96f0 829 size_t debugdir_len = strlen (debugdir);
321e94d6
BS
830 const gdb_byte *data = build_id;
831 size_t size = build_id_len;
03ffe914 832- char *s;
321e94d6 833 char *filename = NULL;
6ed6bacf
AM
834+ unsigned seqno;
835+ struct stat statbuf_trash;
03ffe914
JR
836+ /* Initialize it just to avoid a GCC false warning. */
837+ char *s, *link0 = NULL, *link0_resolved;
6ed6bacf 838
a7de96f0 839 memcpy (link, debugdir, debugdir_len);
03ffe914 840 s = &link[debugdir_len];
321e94d6 841@@ -109,44 +544,282 @@ build_id_to_debug_bfd (size_t build_id_l
ab050a48
BZ
842 *s++ = '/';
843 while (size-- > 0)
844 s += sprintf (s, "%02x", (unsigned) *data++);
845- strcpy (s, ".debug");
6ed6bacf 846+ for (seqno = 0;; seqno++)
a7de96f0 847+ {
6ed6bacf 848+ char *s2;
321e94d6
BS
849
850- /* lrealpath() is expensive even for the usually non-existent files. */
851- if (access (link, F_OK) == 0)
852- filename = lrealpath (link);
6ed6bacf
AM
853+ if (seqno)
854+ {
855+ /* There can be multiple build-id symlinks pointing to real files
856+ with the same build-id (such as hard links). Some of the real
857+ files may not be installed. */
858+
859+ s2 = s + sprintf (s, ".%u", seqno);
860+ }
861+ else
862+ s2 = s;
863+
864+ if (add_debug_suffix)
865+ strcpy (s2, ".debug");
866+ else
867+ *s2 = 0;
03ffe914
JR
868+
869+ if (!seqno)
870+ {
871+ /* If none of the real files is found report as missing file
872+ always the non-.%u-suffixed file. */
873+ link0 = xstrdup (link);
874+ }
875+
6ed6bacf
AM
876+ /* `access' automatically dereferences LINK. */
877+ if (lstat (link, &statbuf_trash) != 0)
878+ {
879+ /* Stop increasing SEQNO. */
880+ break;
881+ }
882+
321e94d6
BS
883+ filename = lrealpath (link);
884+ if (filename == NULL)
885+ continue;
6ed6bacf 886+
321e94d6
BS
887+ /* We expect to be silent on the non-existing files. */
888+ abfd = gdb_bfd_open_maybe_remote (filename);
889+ if (abfd == NULL)
6ed6bacf 890+ {
321e94d6
BS
891+ xfree (filename);
892+ continue;
6ed6bacf 893+ }
321e94d6
BS
894
895- if (filename == NULL)
896- continue;
897+ if (build_id_verify (abfd, build_id_len, build_id))
6ed6bacf 898+ break;
321e94d6
BS
899
900- /* We expect to be silent on the non-existing files. */
901- abfd = gdb_bfd_open_maybe_remote (filename);
902- if (abfd == NULL)
903- continue;
904+ gdb_bfd_unref (abfd);
905+ abfd = NULL;
906
907- if (build_id_verify (abfd, build_id_len, build_id))
908- break;
909+ xfree (filename);
910+ filename = NULL;
ab050a48
BZ
911+ }
912+
321e94d6 913+ if (filename != NULL)
03ffe914 914+ {
321e94d6 915+ /* LINK_ALL is not used below in this non-NULL FILENAME case. */
03ffe914 916+ xfree (link0);
a7de96f0 917+ break;
03ffe914
JR
918+ }
919+
920+ /* If the symlink has target request to install the target.
921+ BASE-debuginfo.rpm contains the symlink but BASE.rpm may be missing.
922+ https://bugzilla.redhat.com/show_bug.cgi?id=981154 */
923+ link0_resolved = link_resolve (link0, 0);
924+ xfree (link0);
321e94d6 925+
03ffe914 926+ if (link_all == NULL)
321e94d6 927+ link_all = link0_resolved;
03ffe914 928+ else
321e94d6 929+ {
03ffe914 930+ size_t len_orig = strlen (link_all);
ab050a48 931+
03ffe914
JR
932+ link_all = xrealloc (link_all,
933+ len_orig + 1 + strlen (link0_resolved) + 1);
ab050a48 934+
03ffe914
JR
935+ /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
936+ its possible use as an argument for installation command. */
937+ link_all[len_orig] = ' ';
321e94d6
BS
938
939- gdb_bfd_unref (abfd);
940- abfd = NULL;
03ffe914 941+ strcpy (&link_all[len_orig + 1], link0_resolved);
321e94d6
BS
942+ xfree (link0_resolved);
943+ }
a7de96f0 944+ }
321e94d6 945+
3a58abaf 946+ if (link_return != NULL)
ab050a48 947+ {
321e94d6 948+ if (abfd != NULL)
03ffe914
JR
949+ {
950+ *link_return = link;
951+ link = NULL;
952+ }
ab050a48 953+ else
03ffe914
JR
954+ {
955+ *link_return = link_all;
956+ link_all = NULL;
957+ }
a7de96f0 958 }
ab050a48
BZ
959+ xfree (link);
960+ xfree (link_all);
a7de96f0
PS
961
962 do_cleanups (back_to);
321e94d6 963 return abfd;
a7de96f0
PS
964 }
965
321e94d6
BS
966+char *
967+build_id_to_filename (const struct elf_build_id *build_id, char **link_return)
968+{
969+ bfd *abfd;
970+ char *result;
971+
972+ abfd = build_id_to_debug_bfd (build_id->size, build_id->data, link_return, 0);
973+ if (abfd == NULL)
974+ return NULL;
975+
976+ result = xstrdup (bfd_get_filename (abfd));
977+ gdb_bfd_unref (abfd);
978+ return result;
979+}
980+
3a58abaf
AM
981+/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
982+ Try to install the hash file ...
983+ avoidance. */
984+
985+struct missing_filepair
986+ {
987+ char *binary;
988+ char *debug;
989+ char data[1];
990+ };
991+
992+static struct htab *missing_filepair_hash;
993+static struct obstack missing_filepair_obstack;
994+
995+static void *
996+missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
997+{
998+ void *retval;
999+ size_t size = nmemb * nmemb_size;
1000+
1001+ retval = obstack_alloc (&missing_filepair_obstack, size);
1002+ memset (retval, 0, size);
a7de96f0
PS
1003+ return retval;
1004+}
1005+
3a58abaf
AM
1006+static hashval_t
1007+missing_filepair_hash_func (const struct missing_filepair *elem)
1008+{
1009+ hashval_t retval = 0;
1010+
1011+ retval ^= htab_hash_string (elem->binary);
1012+ if (elem->debug != NULL)
1013+ retval ^= htab_hash_string (elem->debug);
1014+
1015+ return retval;
1016+}
1017+
1018+static int
1019+missing_filepair_eq (const struct missing_filepair *elem1,
1020+ const struct missing_filepair *elem2)
1021+{
1022+ return strcmp (elem1->binary, elem2->binary) == 0
7566401a
ER
1023+ && ((elem1->debug == NULL) == (elem2->debug == NULL))
1024+ && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
3a58abaf
AM
1025+}
1026+
1027+static void
1028+missing_filepair_change (void)
1029+{
1030+ if (missing_filepair_hash != NULL)
1031+ {
1032+ obstack_free (&missing_filepair_obstack, NULL);
1033+ /* All their memory came just from missing_filepair_OBSTACK. */
1034+ missing_filepair_hash = NULL;
1035+ }
1036+}
1037+
1038+static void
1039+debug_print_executable_changed (void)
1040+{
1041+ missing_filepair_change ();
1042+}
1043+
1044+/* Notify user the file BINARY with (possibly NULL) associated separate debug
1045+ information file DEBUG is missing. DEBUG may or may not be the build-id
1046+ file such as would be:
1047+ /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
1048+ */
1049+
1050+void
1051+debug_print_missing (const char *binary, const char *debug)
1052+{
1053+ size_t binary_len0 = strlen (binary) + 1;
1054+ size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
7566401a 1055+ struct missing_filepair missing_filepair_find;
3a58abaf
AM
1056+ struct missing_filepair *missing_filepair;
1057+ struct missing_filepair **slot;
1058+
1059+ if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
1060+ return;
1061+
1062+ if (missing_filepair_hash == NULL)
1063+ {
1064+ obstack_init (&missing_filepair_obstack);
1065+ missing_filepair_hash = htab_create_alloc (64,
1066+ (hashval_t (*) (const void *)) missing_filepair_hash_func,
1067+ (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
1068+ missing_filepair_xcalloc, NULL);
1069+ }
1070+
7566401a
ER
1071+ /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
1072+ obstack_free in the case of a (rare) match. The problem is ALLOC_F for
1073+ MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
1074+ structures for MISSING_FILEPAIR_HASH. Calling obstack_free would possibly
1075+ not to free only MISSING_FILEPAIR but also some such structures (allocated
1076+ during the htab_find_slot call). */
1077+
1078+ missing_filepair_find.binary = (char *) binary;
1079+ missing_filepair_find.debug = (char *) debug;
1080+ slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
1081+ &missing_filepair_find,
1082+ INSERT);
1083+
1084+ /* While it may be still printed duplicitely with the missing debuginfo file
1085+ * it is due to once printing about the binary file build-id link and once
1086+ * about the .debug file build-id link as both the build-id symlinks are
1087+ * located in the debuginfo package. */
1088+
1089+ if (*slot != NULL)
1090+ return;
1091+
3a58abaf
AM
1092+ missing_filepair = obstack_alloc (&missing_filepair_obstack,
1093+ sizeof (*missing_filepair) - 1
1094+ + binary_len0 + debug_len0);
1095+ missing_filepair->binary = missing_filepair->data;
1096+ memcpy (missing_filepair->binary, binary, binary_len0);
1097+ if (debug != NULL)
1098+ {
1099+ missing_filepair->debug = missing_filepair->binary + binary_len0;
1100+ memcpy (missing_filepair->debug, debug, debug_len0);
1101+ }
1102+ else
1103+ missing_filepair->debug = NULL;
1104+
3a58abaf
AM
1105+ *slot = missing_filepair;
1106+
1107+ /* We do not collect and flush these messages as each such message
1108+ already requires its own separate lines. */
1109+
1110+ fprintf_unfiltered (gdb_stdlog,
1111+ _("Missing separate debuginfo for %s\n"), binary);
1112+ if (debug != NULL)
1113+ fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
1114+ debug);
1115+}
1116+
321e94d6
BS
1117 /* See build-id.h. */
1118
1119 char *
51a5ef0f
PS
1120-find_separate_debug_file_by_buildid (struct objfile *objfile)
1121+find_separate_debug_file_by_buildid (struct objfile *objfile,
1122+ char **build_id_filename_return)
3a58abaf 1123 {
03ffe914 1124 const struct elf_build_id *build_id;
3a58abaf
AM
1125
1126- build_id = build_id_bfd_get (objfile->obfd);
51a5ef0f
PS
1127+ if (build_id_filename_return)
1128+ *build_id_filename_return = NULL;
1129+
3a58abaf
AM
1130+ build_id = build_id_bfd_shdr_get (objfile->obfd);
1131 if (build_id != NULL)
1132 {
321e94d6 1133 bfd *abfd;
3a58abaf 1134
321e94d6
BS
1135- abfd = build_id_to_debug_bfd (build_id->size, build_id->data);
1136+ abfd = build_id_to_debug_bfd (build_id->size, build_id->data,
1137+ build_id_filename_return, 1);
3a58abaf 1138 /* Prevent looping on a stripped .debug file. */
321e94d6
BS
1139 if (abfd != NULL
1140 && filename_cmp (bfd_get_filename (abfd),
1141@@ -166,3 +839,21 @@ find_separate_debug_file_by_buildid (str
51a5ef0f
PS
1142 }
1143 return NULL;
1144 }
51a5ef0f 1145+
321e94d6 1146+extern void _initialize_build_id (void);
51a5ef0f 1147+
321e94d6
BS
1148+void
1149+_initialize_build_id (void)
1150+{
51a5ef0f
PS
1151+ add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
1152+ _("\
1153+Set debugging level of the build-id locator."), _("\
1154+Show debugging level of the build-id locator."), _("\
1155+Level 1 (default) enables printing the missing debug filenames,\n\
1156+level 2 also prints the parsing of binaries to find the identificators."),
1157+ NULL,
1158+ show_build_id_verbose,
1159+ &setlist, &showlist);
1160+
1161+ observer_attach_executable_changed (debug_print_executable_changed);
321e94d6 1162+}
f727df28 1163Index: gdb-7.7.50.20140609/gdb/build-id.h
3a58abaf 1164===================================================================
f727df28
KK
1165--- gdb-7.7.50.20140609.orig/gdb/build-id.h 2014-06-13 20:09:37.386745238 +0200
1166+++ gdb-7.7.50.20140609/gdb/build-id.h 2014-06-13 20:09:42.422750280 +0200
321e94d6
BS
1167@@ -32,13 +32,18 @@ extern int build_id_verify (bfd *abfd,
1168 the caller. */
3a58abaf 1169
321e94d6
BS
1170 extern bfd *build_id_to_debug_bfd (size_t build_id_len,
1171- const bfd_byte *build_id);
1172+ const bfd_byte *build_id, char **link_return,
1173+ int add_debug_suffix);
3a58abaf 1174+
321e94d6
BS
1175+extern char *build_id_to_filename (const struct elf_build_id *build_id,
1176+ char **link_return);
3a58abaf 1177
321e94d6
BS
1178 /* Find the separate debug file for OBJFILE, by using the build-id
1179 associated with OBJFILE's BFD. If successful, returns a malloc'd
1180 file name for the separate debug file. The caller must free this.
1181 Otherwise, returns NULL. */
1182
1183-extern char *find_separate_debug_file_by_buildid (struct objfile *objfile);
1184+extern char *find_separate_debug_file_by_buildid (struct objfile *objfile,
1185+ char **build_id_filename_return);
3a58abaf 1186
321e94d6 1187 #endif /* BUILD_ID_H */
f727df28 1188Index: gdb-7.7.50.20140609/gdb/dwarf2read.c
7566401a 1189===================================================================
f727df28
KK
1190--- gdb-7.7.50.20140609.orig/gdb/dwarf2read.c 2014-06-13 20:09:37.389745241 +0200
1191+++ gdb-7.7.50.20140609/gdb/dwarf2read.c 2014-06-13 20:09:42.425750283 +0200
1192@@ -2446,7 +2446,7 @@ dwarf2_get_dwz_file (void)
d566d21e 1193 }
7566401a 1194
321e94d6
BS
1195 if (dwz_bfd == NULL)
1196- dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid);
1197+ dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid, NULL, 1);
a7de96f0 1198
321e94d6
BS
1199 if (dwz_bfd == NULL)
1200 error (_("could not find '.gnu_debugaltlink' file for %s"),
This page took 5.786069 seconds and 4 git commands to generate.