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