]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.6-buildid-locate.patch
- up to 7.11.1
[packages/gdb.git] / gdb-6.6-buildid-locate.patch
CommitLineData
28b292e9 1Index: gdb-7.10.90.20160211/gdb/corelow.c
3a58abaf 2===================================================================
28b292e9
AM
3--- gdb-7.10.90.20160211.orig/gdb/corelow.c 2016-02-15 23:25:00.859346221 +0100
4+++ gdb-7.10.90.20160211/gdb/corelow.c 2016-02-15 23:26:46.516096395 +0100
b1b25d28 5@@ -45,6 +45,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
28b292e9 16@@ -266,6 +270,53 @@
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;
324d13e1 26+ struct bfd_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
28b292e9 70@@ -404,6 +455,14 @@
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
28b292e9 85@@ -1068,4 +1127,11 @@
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 }
28b292e9 97Index: gdb-7.10.90.20160211/gdb/doc/gdb.texinfo
3a58abaf 98===================================================================
28b292e9
AM
99--- gdb-7.10.90.20160211.orig/gdb/doc/gdb.texinfo 2016-02-15 23:25:36.455598958 +0100
100+++ gdb-7.10.90.20160211/gdb/doc/gdb.texinfo 2016-02-15 23:26:06.362811302 +0100
101@@ -18684,6 +18684,27 @@
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
28b292e9 129Index: gdb-7.10.90.20160211/gdb/solib-svr4.c
3a58abaf 130===================================================================
28b292e9
AM
131--- gdb-7.10.90.20160211.orig/gdb/solib-svr4.c 2016-02-15 23:25:00.859346221 +0100
132+++ gdb-7.10.90.20160211/gdb/solib-svr4.c 2016-02-15 23:26:46.613097083 +0100
b1b25d28
JR
133@@ -45,6 +45,7 @@
134 #include "auxv.h"
321e94d6
BS
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);
28b292e9 141@@ -1416,9 +1417,52 @@
f412e1b4
PS
142 continue;
143 }
144
324d13e1
JR
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);
f412e1b4 148+ {
324d13e1 149+ struct bfd_build_id *build_id;
f412e1b4 150+
324d13e1
JR
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';
f412e1b4 153+ /* May get overwritten below. */
324d13e1 154+ strcpy (newobj->so_name, newobj->so_original_name);
f412e1b4 155+
324d13e1 156+ build_id = build_id_addr_get (newobj->lm_info->l_ld);
f412e1b4
PS
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+ {
324d13e1
JR
166+ strncpy (newobj->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
167+ newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
f412e1b4
PS
168+ xfree (name);
169+ }
170+ else
171+ {
324d13e1 172+ debug_print_missing (newobj->so_name, build_id_filename);
f412e1b4
PS
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)
324d13e1 186+ newobj->so_name[0] = 0;
f412e1b4
PS
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
28b292e9 197Index: gdb-7.10.90.20160211/gdb/elfread.c
3a58abaf 198===================================================================
28b292e9
AM
199--- gdb-7.10.90.20160211.orig/gdb/elfread.c 2016-02-15 23:25:00.859346221 +0100
200+++ gdb-7.10.90.20160211/gdb/elfread.c 2016-02-15 23:26:06.364811316 +0100
201@@ -1259,9 +1259,10 @@
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);
28b292e9 214@@ -1275,6 +1276,12 @@
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
28b292e9 227Index: gdb-7.10.90.20160211/gdb/symfile.h
321e94d6 228===================================================================
28b292e9
AM
229--- gdb-7.10.90.20160211.orig/gdb/symfile.h 2016-02-15 23:25:00.859346221 +0100
230+++ gdb-7.10.90.20160211/gdb/symfile.h 2016-02-15 23:26:46.516096395 +0100
231@@ -584,6 +584,10 @@
f727df28
KK
232 void map_symbol_filenames (symbol_filename_ftype *fun, void *data,
233 int need_fullname);
321e94d6
BS
234
235+/* build-id support. */
324d13e1 236+extern struct bfd_build_id *build_id_addr_get (CORE_ADDR addr);
321e94d6
BS
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
28b292e9 242Index: gdb-7.10.90.20160211/gdb/testsuite/lib/gdb.exp
321e94d6 243===================================================================
28b292e9
AM
244--- gdb-7.10.90.20160211.orig/gdb/testsuite/lib/gdb.exp 2016-02-15 23:25:00.859346221 +0100
245+++ gdb-7.10.90.20160211/gdb/testsuite/lib/gdb.exp 2016-02-15 23:26:46.516096395 +0100
246@@ -1640,6 +1640,16 @@
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
28b292e9 263Index: gdb-7.10.90.20160211/gdb/testsuite/lib/mi-support.exp
321e94d6 264===================================================================
28b292e9
AM
265--- gdb-7.10.90.20160211.orig/gdb/testsuite/lib/mi-support.exp 2016-02-15 23:25:00.859346221 +0100
266+++ gdb-7.10.90.20160211/gdb/testsuite/lib/mi-support.exp 2016-02-15 23:26:46.516096395 +0100
267@@ -204,6 +204,16 @@
321e94d6
BS
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+ }
28b292e9
AM
281
282 # Create the new PTY for the inferior process.
321e94d6 283 if { $separate_inferior_pty } {
28b292e9 284Index: gdb-7.10.90.20160211/gdb/objfiles.h
321e94d6 285===================================================================
28b292e9
AM
286--- gdb-7.10.90.20160211.orig/gdb/objfiles.h 2016-02-15 23:25:00.859346221 +0100
287+++ gdb-7.10.90.20160211/gdb/objfiles.h 2016-02-15 23:26:06.366811330 +0100
288@@ -489,6 +489,10 @@
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);
28b292e9 299Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.base/corefile.exp
321e94d6 300===================================================================
28b292e9
AM
301--- gdb-7.10.90.20160211.orig/gdb/testsuite/gdb.base/corefile.exp 2016-02-15 23:25:00.859346221 +0100
302+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.base/corefile.exp 2016-02-15 23:26:55.178157896 +0100
303@@ -293,3 +293,33 @@
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
28b292e9 319+ set debugdir [standard_output_file ${testfile}-debugdir]
321e94d6
BS
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+}
28b292e9 337Index: gdb-7.10.90.20160211/gdb/build-id.c
321e94d6 338===================================================================
28b292e9
AM
339--- gdb-7.10.90.20160211.orig/gdb/build-id.c 2016-02-15 23:25:00.859346221 +0100
340+++ gdb-7.10.90.20160211/gdb/build-id.c 2016-02-15 23:26:46.516096395 +0100
324d13e1 341@@ -26,11 +26,67 @@
321e94d6
BS
342 #include "objfiles.h"
343 #include "filenames.h"
324d13e1 344 #include "gdbcore.h"
3a58abaf 345+#include "libbfd.h"
51a5ef0f
PS
346+#include "gdbcore.h"
347+#include "gdbcmd.h"
348+#include "observer.h"
324d13e1
JR
349+#include "elf/external.h"
350+#include "elf/internal.h"
351+#include "elf/common.h"
352+#include "elf-bfd.h"
6ed6bacf 353+#include <sys/stat.h>
321e94d6 354+
3a58abaf
AM
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+}
6ed6bacf
AM
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. */
b1b25d28 368+
324d13e1 369+static struct bfd_build_id *
3a58abaf
AM
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);
321e94d6 381+ bfd_byte *descdata = (gdb_byte *) xnp->name + BFD_ALIGN (namesz, 4);
3a58abaf
AM
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;
324d13e1 389+ struct bfd_build_id *retval;
3a58abaf
AM
390+
391+ retval = xmalloc (sizeof *retval - 1 + size);
392+ retval->size = size;
393+ memcpy (retval->data, data, size);
324d13e1 394+
3a58abaf
AM
395+ return retval;
396+ }
397+ p = descdata + BFD_ALIGN (descsz, 4);
398+ }
399+ return NULL;
400+}
324d13e1
JR
401
402 /* See build-id.h. */
403
404 const struct bfd_build_id *
03ffe914 405-build_id_bfd_get (bfd *abfd)
3a58abaf
AM
406+build_id_bfd_shdr_get (bfd *abfd)
407 {
324d13e1
JR
408 if (!bfd_check_format (abfd, bfd_object))
409 return NULL;
28b292e9 410@@ -42,6 +98,348 @@
324d13e1 411 return NULL;
3a58abaf
AM
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+
324d13e1 418+static struct bfd_build_id *
3a58abaf
AM
419+build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
420+ Elf_Internal_Phdr *i_phdr)
421+{
422+ int i;
324d13e1 423+ struct bfd_build_id *retval = NULL;
3a58abaf
AM
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+
a7de96f0 506+static void
3a58abaf
AM
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+
324d13e1 710+struct bfd_build_id *
3a58abaf
AM
711+build_id_addr_get (CORE_ADDR addr)
712+{
713+ struct build_id_addr_sect *candidate;
324d13e1 714+ struct bfd_build_id *retval = NULL;
3a58abaf
AM
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+
321e94d6 756 /* See build-id.h. */
3a58abaf 757
321e94d6 758 int
28b292e9 759@@ -50,7 +448,7 @@
324d13e1 760 const struct bfd_build_id *found;
321e94d6 761 int retval = 0;
3a58abaf
AM
762
763- found = build_id_bfd_get (abfd);
764+ found = build_id_bfd_shdr_get (abfd);
765
766 if (found == NULL)
321e94d6 767 warning (_("File \"%s\" has no build-id, file skipped"),
28b292e9 768@@ -65,23 +463,56 @@
321e94d6 769 return retval;
3a58abaf
AM
770 }
771
321e94d6 772+static char *
03ffe914
JR
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+
321e94d6
BS
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)
3a58abaf 814 {
321e94d6
BS
815- char *link, *debugdir;
816+ char *link, *debugdir, *link_all = NULL;
a7de96f0
PS
817 VEC (char_ptr) *debugdir_vec;
818 struct cleanup *back_to;
819 int ix;
321e94d6 820 bfd *abfd = NULL;
28b292e9 821- int alloc_len;
3a58abaf
AM
822
823 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
28b292e9
AM
824- alloc_len = (strlen (debug_file_directory)
825- + (sizeof "/.build-id/" - 1) + 1
826- + 2 * build_id_len + (sizeof ".debug" - 1) + 1);
827- link = (char *) alloca (alloc_len);
321e94d6 828+ link = xmalloc (strlen (debug_file_directory) + 2 * build_id_len + 50);
ab050a48
BZ
829
830 /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
831 cause "/.build-id/..." lookups. */
28b292e9 832@@ -94,9 +525,12 @@
a7de96f0 833 size_t debugdir_len = strlen (debugdir);
321e94d6
BS
834 const gdb_byte *data = build_id;
835 size_t size = build_id_len;
03ffe914 836- char *s;
321e94d6 837 char *filename = NULL;
324d13e1 838 struct cleanup *inner;
6ed6bacf
AM
839+ unsigned seqno;
840+ struct stat statbuf_trash;
03ffe914
JR
841+ /* Initialize it just to avoid a GCC false warning. */
842+ char *s, *link0 = NULL, *link0_resolved;
6ed6bacf 843
a7de96f0 844 memcpy (link, debugdir, debugdir_len);
03ffe914 845 s = &link[debugdir_len];
28b292e9 846@@ -110,47 +544,281 @@
ab050a48
BZ
847 *s++ = '/';
848 while (size-- > 0)
849 s += sprintf (s, "%02x", (unsigned) *data++);
850- strcpy (s, ".debug");
6ed6bacf 851+ for (seqno = 0;; seqno++)
a7de96f0 852+ {
6ed6bacf 853+ char *s2;
321e94d6
BS
854
855- /* lrealpath() is expensive even for the usually non-existent files. */
856- if (access (link, F_OK) == 0)
857- filename = lrealpath (link);
6ed6bacf
AM
858+ if (seqno)
859+ {
860+ /* There can be multiple build-id symlinks pointing to real files
861+ with the same build-id (such as hard links). Some of the real
862+ files may not be installed. */
863+
864+ s2 = s + sprintf (s, ".%u", seqno);
865+ }
866+ else
867+ s2 = s;
868+
869+ if (add_debug_suffix)
870+ strcpy (s2, ".debug");
871+ else
872+ *s2 = 0;
03ffe914
JR
873+
874+ if (!seqno)
875+ {
876+ /* If none of the real files is found report as missing file
877+ always the non-.%u-suffixed file. */
878+ link0 = xstrdup (link);
879+ }
880+
6ed6bacf
AM
881+ /* `access' automatically dereferences LINK. */
882+ if (lstat (link, &statbuf_trash) != 0)
883+ {
884+ /* Stop increasing SEQNO. */
885+ break;
886+ }
887+
321e94d6
BS
888+ filename = lrealpath (link);
889+ if (filename == NULL)
890+ continue;
6ed6bacf 891+
321e94d6 892+ /* We expect to be silent on the non-existing files. */
324d13e1
JR
893+ inner = make_cleanup (xfree, filename);
894+ abfd = gdb_bfd_open (filename, gnutarget, -1);
895+ do_cleanups (inner);
321e94d6
BS
896
897- if (filename == NULL)
898- continue;
324d13e1
JR
899+ if (abfd == NULL)
900+ continue;
901
902- /* We expect to be silent on the non-existing files. */
903- inner = make_cleanup (xfree, filename);
904- abfd = gdb_bfd_open (filename, gnutarget, -1);
905- do_cleanups (inner);
321e94d6 906+ if (build_id_verify (abfd, build_id_len, build_id))
6ed6bacf 907+ break;
321e94d6 908
321e94d6
BS
909- if (abfd == NULL)
910- continue;
911+ gdb_bfd_unref (abfd);
912+ abfd = NULL;
913
914- if (build_id_verify (abfd, build_id_len, build_id))
915- break;
321e94d6 916+ filename = NULL;
ab050a48 917+ }
b1b25d28
JR
918
919- gdb_bfd_unref (abfd);
920- abfd = NULL;
321e94d6 921+ if (filename != NULL)
03ffe914 922+ {
321e94d6 923+ /* LINK_ALL is not used below in this non-NULL FILENAME case. */
03ffe914 924+ xfree (link0);
a7de96f0 925+ break;
03ffe914
JR
926+ }
927+
928+ /* If the symlink has target request to install the target.
929+ BASE-debuginfo.rpm contains the symlink but BASE.rpm may be missing.
930+ https://bugzilla.redhat.com/show_bug.cgi?id=981154 */
931+ link0_resolved = link_resolve (link0, 0);
932+ xfree (link0);
321e94d6 933+
03ffe914 934+ if (link_all == NULL)
321e94d6 935+ link_all = link0_resolved;
03ffe914 936+ else
321e94d6 937+ {
03ffe914 938+ size_t len_orig = strlen (link_all);
ab050a48 939+
03ffe914
JR
940+ link_all = xrealloc (link_all,
941+ len_orig + 1 + strlen (link0_resolved) + 1);
ab050a48 942+
03ffe914
JR
943+ /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
944+ its possible use as an argument for installation command. */
945+ link_all[len_orig] = ' ';
b1b25d28 946+
03ffe914 947+ strcpy (&link_all[len_orig + 1], link0_resolved);
321e94d6
BS
948+ xfree (link0_resolved);
949+ }
a7de96f0 950+ }
321e94d6 951+
3a58abaf 952+ if (link_return != NULL)
ab050a48 953+ {
321e94d6 954+ if (abfd != NULL)
03ffe914
JR
955+ {
956+ *link_return = link;
957+ link = NULL;
958+ }
ab050a48 959+ else
03ffe914
JR
960+ {
961+ *link_return = link_all;
962+ link_all = NULL;
963+ }
a7de96f0 964 }
ab050a48
BZ
965+ xfree (link);
966+ xfree (link_all);
a7de96f0
PS
967
968 do_cleanups (back_to);
321e94d6 969 return abfd;
a7de96f0
PS
970 }
971
321e94d6 972+char *
324d13e1 973+build_id_to_filename (const struct bfd_build_id *build_id, char **link_return)
321e94d6
BS
974+{
975+ bfd *abfd;
976+ char *result;
977+
978+ abfd = build_id_to_debug_bfd (build_id->size, build_id->data, link_return, 0);
979+ if (abfd == NULL)
980+ return NULL;
981+
982+ result = xstrdup (bfd_get_filename (abfd));
983+ gdb_bfd_unref (abfd);
984+ return result;
985+}
986+
3a58abaf
AM
987+/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
988+ Try to install the hash file ...
989+ avoidance. */
990+
991+struct missing_filepair
992+ {
993+ char *binary;
994+ char *debug;
995+ char data[1];
996+ };
997+
998+static struct htab *missing_filepair_hash;
999+static struct obstack missing_filepair_obstack;
1000+
1001+static void *
1002+missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
1003+{
1004+ void *retval;
1005+ size_t size = nmemb * nmemb_size;
1006+
1007+ retval = obstack_alloc (&missing_filepair_obstack, size);
1008+ memset (retval, 0, size);
a7de96f0
PS
1009+ return retval;
1010+}
1011+
3a58abaf
AM
1012+static hashval_t
1013+missing_filepair_hash_func (const struct missing_filepair *elem)
1014+{
1015+ hashval_t retval = 0;
1016+
1017+ retval ^= htab_hash_string (elem->binary);
1018+ if (elem->debug != NULL)
1019+ retval ^= htab_hash_string (elem->debug);
1020+
1021+ return retval;
1022+}
1023+
1024+static int
1025+missing_filepair_eq (const struct missing_filepair *elem1,
1026+ const struct missing_filepair *elem2)
1027+{
1028+ return strcmp (elem1->binary, elem2->binary) == 0
7566401a
ER
1029+ && ((elem1->debug == NULL) == (elem2->debug == NULL))
1030+ && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
3a58abaf
AM
1031+}
1032+
1033+static void
1034+missing_filepair_change (void)
1035+{
1036+ if (missing_filepair_hash != NULL)
1037+ {
1038+ obstack_free (&missing_filepair_obstack, NULL);
1039+ /* All their memory came just from missing_filepair_OBSTACK. */
1040+ missing_filepair_hash = NULL;
1041+ }
1042+}
1043+
1044+static void
1045+debug_print_executable_changed (void)
1046+{
1047+ missing_filepair_change ();
1048+}
1049+
1050+/* Notify user the file BINARY with (possibly NULL) associated separate debug
1051+ information file DEBUG is missing. DEBUG may or may not be the build-id
1052+ file such as would be:
1053+ /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
1054+ */
1055+
1056+void
1057+debug_print_missing (const char *binary, const char *debug)
1058+{
1059+ size_t binary_len0 = strlen (binary) + 1;
1060+ size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
7566401a 1061+ struct missing_filepair missing_filepair_find;
3a58abaf
AM
1062+ struct missing_filepair *missing_filepair;
1063+ struct missing_filepair **slot;
1064+
1065+ if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
1066+ return;
1067+
1068+ if (missing_filepair_hash == NULL)
1069+ {
1070+ obstack_init (&missing_filepair_obstack);
1071+ missing_filepair_hash = htab_create_alloc (64,
1072+ (hashval_t (*) (const void *)) missing_filepair_hash_func,
1073+ (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
1074+ missing_filepair_xcalloc, NULL);
1075+ }
1076+
7566401a
ER
1077+ /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
1078+ obstack_free in the case of a (rare) match. The problem is ALLOC_F for
1079+ MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
1080+ structures for MISSING_FILEPAIR_HASH. Calling obstack_free would possibly
1081+ not to free only MISSING_FILEPAIR but also some such structures (allocated
1082+ during the htab_find_slot call). */
1083+
1084+ missing_filepair_find.binary = (char *) binary;
1085+ missing_filepair_find.debug = (char *) debug;
1086+ slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
1087+ &missing_filepair_find,
1088+ INSERT);
1089+
1090+ /* While it may be still printed duplicitely with the missing debuginfo file
1091+ * it is due to once printing about the binary file build-id link and once
1092+ * about the .debug file build-id link as both the build-id symlinks are
1093+ * located in the debuginfo package. */
1094+
1095+ if (*slot != NULL)
1096+ return;
1097+
3a58abaf
AM
1098+ missing_filepair = obstack_alloc (&missing_filepair_obstack,
1099+ sizeof (*missing_filepair) - 1
1100+ + binary_len0 + debug_len0);
1101+ missing_filepair->binary = missing_filepair->data;
1102+ memcpy (missing_filepair->binary, binary, binary_len0);
1103+ if (debug != NULL)
1104+ {
1105+ missing_filepair->debug = missing_filepair->binary + binary_len0;
1106+ memcpy (missing_filepair->debug, debug, debug_len0);
1107+ }
1108+ else
1109+ missing_filepair->debug = NULL;
1110+
3a58abaf
AM
1111+ *slot = missing_filepair;
1112+
1113+ /* We do not collect and flush these messages as each such message
1114+ already requires its own separate lines. */
1115+
1116+ fprintf_unfiltered (gdb_stdlog,
1117+ _("Missing separate debuginfo for %s\n"), binary);
1118+ if (debug != NULL)
1119+ fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
1120+ debug);
1121+}
1122+
321e94d6
BS
1123 /* See build-id.h. */
1124
1125 char *
51a5ef0f
PS
1126-find_separate_debug_file_by_buildid (struct objfile *objfile)
1127+find_separate_debug_file_by_buildid (struct objfile *objfile,
1128+ char **build_id_filename_return)
3a58abaf 1129 {
324d13e1 1130 const struct bfd_build_id *build_id;
3a58abaf
AM
1131
1132- build_id = build_id_bfd_get (objfile->obfd);
51a5ef0f
PS
1133+ if (build_id_filename_return)
1134+ *build_id_filename_return = NULL;
1135+
3a58abaf
AM
1136+ build_id = build_id_bfd_shdr_get (objfile->obfd);
1137 if (build_id != NULL)
1138 {
321e94d6 1139 bfd *abfd;
3a58abaf 1140
321e94d6
BS
1141- abfd = build_id_to_debug_bfd (build_id->size, build_id->data);
1142+ abfd = build_id_to_debug_bfd (build_id->size, build_id->data,
1143+ build_id_filename_return, 1);
3a58abaf 1144 /* Prevent looping on a stripped .debug file. */
321e94d6
BS
1145 if (abfd != NULL
1146 && filename_cmp (bfd_get_filename (abfd),
28b292e9 1147@@ -170,3 +838,21 @@
51a5ef0f
PS
1148 }
1149 return NULL;
1150 }
51a5ef0f 1151+
321e94d6 1152+extern void _initialize_build_id (void);
51a5ef0f 1153+
321e94d6
BS
1154+void
1155+_initialize_build_id (void)
1156+{
51a5ef0f
PS
1157+ add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
1158+ _("\
1159+Set debugging level of the build-id locator."), _("\
1160+Show debugging level of the build-id locator."), _("\
1161+Level 1 (default) enables printing the missing debug filenames,\n\
1162+level 2 also prints the parsing of binaries to find the identificators."),
1163+ NULL,
1164+ show_build_id_verbose,
1165+ &setlist, &showlist);
1166+
1167+ observer_attach_executable_changed (debug_print_executable_changed);
321e94d6 1168+}
28b292e9 1169Index: gdb-7.10.90.20160211/gdb/build-id.h
3a58abaf 1170===================================================================
28b292e9
AM
1171--- gdb-7.10.90.20160211.orig/gdb/build-id.h 2016-02-15 23:25:00.859346221 +0100
1172+++ gdb-7.10.90.20160211/gdb/build-id.h 2016-02-15 23:26:06.368811345 +0100
b1b25d28
JR
1173@@ -20,9 +20,10 @@
1174 #ifndef BUILD_ID_H
1175 #define BUILD_ID_H
1176
1177-/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */
1178+/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
1179+ Locate NT_GNU_BUILD_ID from ABFD and return its content. */
1180
324d13e1
JR
1181-extern const struct bfd_build_id *build_id_bfd_get (bfd *abfd);
1182+extern const struct bfd_build_id *build_id_bfd_shdr_get (bfd *abfd);
b1b25d28
JR
1183
1184 /* Return true if ABFD has NT_GNU_BUILD_ID matching the CHECK value.
1185 Otherwise, issue a warning and return false. */
28b292e9 1186@@ -36,13 +37,18 @@
321e94d6 1187 the caller. */
3a58abaf 1188
321e94d6
BS
1189 extern bfd *build_id_to_debug_bfd (size_t build_id_len,
1190- const bfd_byte *build_id);
1191+ const bfd_byte *build_id, char **link_return,
1192+ int add_debug_suffix);
3a58abaf 1193+
324d13e1 1194+extern char *build_id_to_filename (const struct bfd_build_id *build_id,
321e94d6 1195+ char **link_return);
3a58abaf 1196
321e94d6
BS
1197 /* Find the separate debug file for OBJFILE, by using the build-id
1198 associated with OBJFILE's BFD. If successful, returns a malloc'd
1199 file name for the separate debug file. The caller must free this.
1200 Otherwise, returns NULL. */
1201
1202-extern char *find_separate_debug_file_by_buildid (struct objfile *objfile);
1203+extern char *find_separate_debug_file_by_buildid (struct objfile *objfile,
1204+ char **build_id_filename_return);
3a58abaf 1205
321e94d6 1206 #endif /* BUILD_ID_H */
28b292e9 1207Index: gdb-7.10.90.20160211/gdb/dwarf2read.c
7566401a 1208===================================================================
28b292e9
AM
1209--- gdb-7.10.90.20160211.orig/gdb/dwarf2read.c 2016-02-15 23:25:36.461599001 +0100
1210+++ gdb-7.10.90.20160211/gdb/dwarf2read.c 2016-02-15 23:26:06.373811380 +0100
1211@@ -2516,7 +2516,7 @@
d566d21e 1212 }
7566401a 1213
321e94d6
BS
1214 if (dwz_bfd == NULL)
1215- dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid);
1216+ dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid, NULL, 1);
a7de96f0 1217
321e94d6
BS
1218 if (dwz_bfd == NULL)
1219 error (_("could not find '.gnu_debugaltlink' file for %s"),
28b292e9 1220Index: gdb-7.10.90.20160211/gdb/python/py-objfile.c
b1b25d28 1221===================================================================
28b292e9
AM
1222--- gdb-7.10.90.20160211.orig/gdb/python/py-objfile.c 2016-02-15 23:25:00.859346221 +0100
1223+++ gdb-7.10.90.20160211/gdb/python/py-objfile.c 2016-02-15 23:26:06.373811380 +0100
1224@@ -139,7 +139,7 @@
b1b25d28 1225
324d13e1 1226 TRY
b1b25d28
JR
1227 {
1228- build_id = build_id_bfd_get (objfile->obfd);
1229+ build_id = build_id_bfd_shdr_get (objfile->obfd);
1230 }
324d13e1
JR
1231 CATCH (except, RETURN_MASK_ALL)
1232 {
28b292e9 1233@@ -548,7 +548,7 @@
b1b25d28
JR
1234 /* Don't return separate debug files. */
1235 if (objfile->separate_debug_objfile_backlink != NULL)
1236 continue;
1237- obfd_build_id = build_id_bfd_get (objfile->obfd);
1238+ obfd_build_id = build_id_bfd_shdr_get (objfile->obfd);
1239 if (obfd_build_id == NULL)
1240 continue;
1241 if (objfpy_build_id_matches (obfd_build_id, build_id))
28b292e9 1242Index: gdb-7.10.90.20160211/gdb/coffread.c
324d13e1 1243===================================================================
28b292e9
AM
1244--- gdb-7.10.90.20160211.orig/gdb/coffread.c 2016-02-15 23:25:00.859346221 +0100
1245+++ gdb-7.10.90.20160211/gdb/coffread.c 2016-02-15 23:26:06.374811387 +0100
1246@@ -739,7 +739,7 @@
324d13e1
JR
1247 {
1248 char *debugfile;
1249
1250- debugfile = find_separate_debug_file_by_buildid (objfile);
1251+ debugfile = find_separate_debug_file_by_buildid (objfile, NULL);
1252
1253 if (debugfile == NULL)
1254 debugfile = find_separate_debug_file_by_debuglink (objfile);
This page took 0.250944 seconds and 4 git commands to generate.