]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.6-buildid-locate.patch
- update to gdb-7.0-7.fc12.src.rpm; but leave cactus patches as these seem newer
[packages/gdb.git] / gdb-6.6-buildid-locate.patch
CommitLineData
ab050a48 1Index: gdb-7.0/gdb/corelow.c
3a58abaf 2===================================================================
ab050a48
BZ
3--- gdb-7.0.orig/gdb/corelow.c 2009-07-31 17:25:21.000000000 +0200
4+++ gdb-7.0/gdb/corelow.c 2009-10-23 00:17:29.000000000 +0200
3a58abaf
AM
5@@ -45,6 +45,10 @@
6 #include "exceptions.h"
7 #include "solib.h"
8 #include "filenames.h"
9+#include "auxv.h"
10+#include "elf/common.h"
11+#include "objfiles.h"
12+#include "gdbcmd.h"
13
14
15 #ifndef O_LARGEFILE
7566401a 16@@ -273,6 +277,52 @@ add_to_thread_list (bfd *abfd, asection
3a58abaf
AM
17 inferior_ptid = ptid; /* Yes, make it current */
18 }
19
20+static int build_id_core_loads = 1;
21+
22+static void
23+build_id_locate_exec (int from_tty)
24+{
25+ CORE_ADDR at_entry;
26+ struct build_id *build_id;
27+ char *exec_filename, *debug_filename;
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;
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);
7566401a 48+ back_to = 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
7566401a 69@@ -371,6 +421,12 @@ core_open (char *filename, int from_tty)
3a58abaf
AM
70 push_target (&core_ops);
71 discard_cleanups (old_chain);
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
75+ loaded VDSO symbols. */
76+ if (build_id_core_loads != 0)
77+ build_id_locate_exec (from_tty);
78+
79 add_inferior_silent (corelow_pid);
80
81 /* Do this before acknowledging the inferior, so if
7566401a 82@@ -878,4 +934,11 @@ _initialize_corelow (void)
3a58abaf
AM
83 init_core_ops ();
84
85 add_target (&core_ops);
86+
87+ add_setshow_boolean_cmd ("build-id-core-loads", class_files,
88+ &build_id_core_loads, _("\
89+Set whether CORE-FILE loads the build-id associated files automatically."), _("\
90+Show whether CORE-FILE loads the build-id associated files automatically.."),
91+ NULL, NULL, NULL,
92+ &setlist, &showlist);
93 }
ab050a48 94Index: gdb-7.0/gdb/doc/gdb.texinfo
3a58abaf 95===================================================================
ab050a48
BZ
96--- gdb-7.0.orig/gdb/doc/gdb.texinfo 2009-10-23 00:12:39.000000000 +0200
97+++ gdb-7.0/gdb/doc/gdb.texinfo 2009-10-23 00:17:29.000000000 +0200
98@@ -13896,6 +13896,27 @@ information files.
3a58abaf
AM
99
100 @end table
101
102+You can also adjust the current verbosity of the @dfn{build id} locating.
103+
104+@table @code
105+
106+@kindex set build-id-verbose
107+@item set build-id-verbose 0
108+No additional messages are printed.
109+
110+@item set build-id-verbose 1
111+Missing separate debug filenames are printed.
112+
113+@item set build-id-verbose 2
114+Missing separate debug filenames are printed and also all the parsing of the
115+binaries to find their @dfn{build id} content is printed.
116+
117+@kindex show build-id-verbose
118+@item show build-id-verbose
119+Show the current verbosity value for the @dfn{build id} content locating.
120+
121+@end table
122+
123 @cindex @code{.gnu_debuglink} sections
124 @cindex debug link sections
125 A debug link is a special section of the executable file named
ab050a48 126Index: gdb-7.0/gdb/solib-svr4.c
3a58abaf 127===================================================================
ab050a48
BZ
128--- gdb-7.0.orig/gdb/solib-svr4.c 2009-10-23 00:12:38.000000000 +0200
129+++ gdb-7.0/gdb/solib-svr4.c 2009-10-23 00:17:29.000000000 +0200
7566401a 130@@ -1101,9 +1101,49 @@ svr4_current_sos (void)
3a58abaf
AM
131 safe_strerror (errcode));
132 else
133 {
134- strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
135- new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
136- strcpy (new->so_original_name, new->so_name);
137+ struct build_id *build_id;
138+
139+ strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
140+ new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
141+ /* May get overwritten below. */
142+ strcpy (new->so_name, new->so_original_name);
143+
144+ build_id = build_id_addr_get (LM_DYNAMIC_FROM_LINK_MAP (new));
145+ if (build_id != NULL)
146+ {
147+ char *name, *build_id_filename;
148+
149+ /* Missing the build-id matching separate debug info file
150+ would be handled while SO_NAME gets loaded. */
151+ name = build_id_to_filename (build_id, &build_id_filename, 0);
152+ if (name != NULL)
153+ {
154+ strncpy (new->so_name, name, SO_NAME_MAX_PATH_SIZE - 1);
155+ new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
156+ xfree (name);
157+ }
158+ else
7566401a
ER
159+ {
160+ debug_print_missing (new->so_name, build_id_filename);
161+
162+ /* In the case the main executable was found according to
163+ its build-id (from a core file) prevent loading
164+ a different build of a library with accidentally the
165+ same SO_NAME.
166+
167+ It suppresses bogus backtraces (and prints "??" there
168+ instead) if the on-disk files no longer match the
169+ running program version. */
170+
171+ if (symfile_objfile != NULL
172+ && (symfile_objfile->flags
173+ & OBJF_BUILD_ID_CORE_LOADED) != 0)
174+ new->so_name[0] = 0;
175+ }
3a58abaf
AM
176+
177+ xfree (build_id_filename);
178+ xfree (build_id);
179+ }
180 }
181 xfree (buffer);
182
ab050a48 183Index: gdb-7.0/gdb/symfile.c
3a58abaf 184===================================================================
ab050a48
BZ
185--- gdb-7.0.orig/gdb/symfile.c 2009-10-23 00:12:38.000000000 +0200
186+++ gdb-7.0/gdb/symfile.c 2009-10-23 00:43:28.000000000 +0200
7566401a 187@@ -56,6 +56,7 @@
3a58abaf
AM
188 #include "elf-bfd.h"
189 #include "solib.h"
190 #include "remote.h"
191+#include "libbfd.h"
192
193 #include <sys/types.h>
194 #include <fcntl.h>
7566401a
ER
195@@ -1173,16 +1174,65 @@ symbol_file_clear (int from_tty)
196 printf_unfiltered (_("No symbol file now.\n"));
3a58abaf
AM
197 }
198
199+/* Locate NT_GNU_BUILD_ID and return its matching debug filename.
200+ FIXME: NOTE decoding should be unified with the BFD core notes decoding. */
201+
202+#define BUILD_ID_VERBOSE_NONE 0
203+#define BUILD_ID_VERBOSE_FILENAMES 1
204+#define BUILD_ID_VERBOSE_BINARY_PARSE 2
205+static int build_id_verbose = BUILD_ID_VERBOSE_FILENAMES;
206+static void
207+show_build_id_verbose (struct ui_file *file, int from_tty,
208+ struct cmd_list_element *c, const char *value)
209+{
210+ fprintf_filtered (file, _("Verbosity level of the build-id locator is %s.\n"),
211+ value);
212+}
213+
214 struct build_id
215 {
216 size_t size;
217 gdb_byte data[1];
218 };
219
220-/* Locate NT_GNU_BUILD_ID from ABFD and return its content. */
221+struct build_id *
222+build_id_buf_get (bfd *templ, gdb_byte *buf, bfd_size_type size)
223+{
224+ bfd_byte *p;
225+
226+ p = buf;
227+ while (p < buf + size)
228+ {
229+ /* FIXME: bad alignment assumption. */
230+ Elf_External_Note *xnp = (Elf_External_Note *) p;
231+ size_t namesz = H_GET_32 (templ, xnp->namesz);
232+ size_t descsz = H_GET_32 (templ, xnp->descsz);
233+ bfd_byte *descdata = xnp->name + BFD_ALIGN (namesz, 4);
234+
235+ if (H_GET_32 (templ, xnp->type) == NT_GNU_BUILD_ID
236+ && namesz == sizeof "GNU"
237+ && memcmp (xnp->name, "GNU", sizeof "GNU") == 0)
238+ {
239+ size_t size = descsz;
240+ gdb_byte *data = (void *) descdata;
241+ struct build_id *retval;
242+
243+ retval = xmalloc (sizeof *retval - 1 + size);
244+ retval->size = size;
245+ memcpy (retval->data, data, size);
246+
247+ return retval;
248+ }
249+ p = descdata + BFD_ALIGN (descsz, 4);
250+ }
251+ return NULL;
252+}
253+
254+/* Separate debuginfo files have corrupted PHDR but SHDR is correct there.
255+ Locate NT_GNU_BUILD_ID from ABFD and return its content. */
256
257 static struct build_id *
258-build_id_bfd_get (bfd *abfd)
259+build_id_bfd_shdr_get (bfd *abfd)
260 {
261 struct build_id *retval;
262
7566401a 263@@ -1198,6 +1248,348 @@ build_id_bfd_get (bfd *abfd)
3a58abaf
AM
264 return retval;
265 }
266
267+/* Core files may have missing (corrupt) SHDR but PDHR is correct there.
268+ bfd_elf_bfd_from_remote_memory () has too much overhead by
269+ allocating/reading all the available ELF PT_LOADs. */
270+
271+static struct build_id *
272+build_id_phdr_get (bfd *templ, bfd_vma loadbase, unsigned e_phnum,
273+ Elf_Internal_Phdr *i_phdr)
274+{
275+ int i;
276+ struct build_id *retval = NULL;
277+
278+ for (i = 0; i < e_phnum; i++)
279+ if (i_phdr[i].p_type == PT_NOTE && i_phdr[i].p_filesz > 0)
280+ {
281+ Elf_Internal_Phdr *hdr = &i_phdr[i];
282+ gdb_byte *buf;
283+ int err;
284+
285+ buf = xmalloc (hdr->p_filesz);
286+ err = target_read_memory (loadbase + i_phdr[i].p_vaddr, buf,
287+ hdr->p_filesz);
288+ if (err == 0)
289+ retval = build_id_buf_get (templ, buf, hdr->p_filesz);
290+ else
291+ retval = NULL;
292+ xfree (buf);
293+ if (retval != NULL)
294+ break;
295+ }
296+ return retval;
297+}
298+
299+/* First we validate the file by reading in the ELF header and checking
300+ the magic number. */
301+
302+static inline bfd_boolean
303+elf_file_p (Elf64_External_Ehdr *x_ehdrp64)
304+{
305+ gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
306+ gdb_assert (offsetof (Elf64_External_Ehdr, e_ident)
307+ == offsetof (Elf32_External_Ehdr, e_ident));
308+ gdb_assert (sizeof (((Elf64_External_Ehdr *) 0)->e_ident)
309+ == sizeof (((Elf32_External_Ehdr *) 0)->e_ident));
310+
311+ return ((x_ehdrp64->e_ident[EI_MAG0] == ELFMAG0)
312+ && (x_ehdrp64->e_ident[EI_MAG1] == ELFMAG1)
313+ && (x_ehdrp64->e_ident[EI_MAG2] == ELFMAG2)
314+ && (x_ehdrp64->e_ident[EI_MAG3] == ELFMAG3));
315+}
316+
317+/* Translate an ELF file header in external format into an ELF file header in
318+ internal format. */
319+
320+#define H_GET_WORD(bfd, ptr) (is64 ? H_GET_64 (bfd, (ptr)) \
321+ : H_GET_32 (bfd, (ptr)))
322+#define H_GET_SIGNED_WORD(bfd, ptr) (is64 ? H_GET_S64 (bfd, (ptr)) \
323+ : H_GET_S32 (bfd, (ptr)))
324+
325+static void
326+elf_swap_ehdr_in (bfd *abfd,
327+ const Elf64_External_Ehdr *src64,
328+ Elf_Internal_Ehdr *dst)
329+{
330+ int is64 = bfd_get_arch_size (abfd) == 64;
331+#define SRC(field) (is64 ? src64->field \
332+ : ((const Elf32_External_Ehdr *) src64)->field)
333+
334+ int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
335+ memcpy (dst->e_ident, SRC (e_ident), EI_NIDENT);
336+ dst->e_type = H_GET_16 (abfd, SRC (e_type));
337+ dst->e_machine = H_GET_16 (abfd, SRC (e_machine));
338+ dst->e_version = H_GET_32 (abfd, SRC (e_version));
339+ if (signed_vma)
340+ dst->e_entry = H_GET_SIGNED_WORD (abfd, SRC (e_entry));
341+ else
342+ dst->e_entry = H_GET_WORD (abfd, SRC (e_entry));
343+ dst->e_phoff = H_GET_WORD (abfd, SRC (e_phoff));
344+ dst->e_shoff = H_GET_WORD (abfd, SRC (e_shoff));
345+ dst->e_flags = H_GET_32 (abfd, SRC (e_flags));
346+ dst->e_ehsize = H_GET_16 (abfd, SRC (e_ehsize));
347+ dst->e_phentsize = H_GET_16 (abfd, SRC (e_phentsize));
348+ dst->e_phnum = H_GET_16 (abfd, SRC (e_phnum));
349+ dst->e_shentsize = H_GET_16 (abfd, SRC (e_shentsize));
350+ dst->e_shnum = H_GET_16 (abfd, SRC (e_shnum));
351+ dst->e_shstrndx = H_GET_16 (abfd, SRC (e_shstrndx));
352+
353+#undef SRC
354+}
355+
356+/* Translate an ELF program header table entry in external format into an
357+ ELF program header table entry in internal format. */
358+
359+void
360+elf_swap_phdr_in (bfd *abfd,
361+ const Elf64_External_Phdr *src64,
362+ Elf_Internal_Phdr *dst)
363+{
364+ int is64 = bfd_get_arch_size (abfd) == 64;
365+#define SRC(field) (is64 ? src64->field \
366+ : ((const Elf32_External_Phdr *) src64)->field)
367+
368+ int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
369+
370+ dst->p_type = H_GET_32 (abfd, SRC (p_type));
371+ dst->p_flags = H_GET_32 (abfd, SRC (p_flags));
372+ dst->p_offset = H_GET_WORD (abfd, SRC (p_offset));
373+ if (signed_vma)
374+ {
375+ dst->p_vaddr = H_GET_SIGNED_WORD (abfd, SRC (p_vaddr));
376+ dst->p_paddr = H_GET_SIGNED_WORD (abfd, SRC (p_paddr));
377+ }
378+ else
379+ {
380+ dst->p_vaddr = H_GET_WORD (abfd, SRC (p_vaddr));
381+ dst->p_paddr = H_GET_WORD (abfd, SRC (p_paddr));
382+ }
383+ dst->p_filesz = H_GET_WORD (abfd, SRC (p_filesz));
384+ dst->p_memsz = H_GET_WORD (abfd, SRC (p_memsz));
385+ dst->p_align = H_GET_WORD (abfd, SRC (p_align));
386+
387+#undef SRC
388+}
389+
390+#undef H_GET_SIGNED_WORD
391+#undef H_GET_WORD
392+
393+static Elf_Internal_Phdr *
394+elf_get_phdr (bfd *templ, bfd_vma ehdr_vma, unsigned *e_phnum_pointer,
395+ bfd_vma *loadbase_pointer)
396+{
397+ /* sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr) */
398+ Elf64_External_Ehdr x_ehdr64; /* Elf file header, external form */
399+ Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
400+ bfd_size_type x_phdrs_size;
401+ gdb_byte *x_phdrs_ptr;
402+ Elf_Internal_Phdr *i_phdrs;
403+ int err;
404+ unsigned int i;
405+ bfd_vma loadbase;
406+ int loadbase_set;
407+
408+ gdb_assert (templ != NULL);
409+ gdb_assert (sizeof (Elf64_External_Ehdr) >= sizeof (Elf32_External_Ehdr));
410+
411+ /* Read in the ELF header in external format. */
412+ err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr64, sizeof x_ehdr64);
413+ if (err)
414+ {
415+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
416+ warning (_("build-id: Error reading ELF header at address 0x%lx"),
417+ (unsigned long) ehdr_vma);
418+ return NULL;
419+ }
420+
421+ /* Now check to see if we have a valid ELF file, and one that BFD can
422+ make use of. The magic number must match, the address size ('class')
423+ and byte-swapping must match our XVEC entry. */
424+
425+ if (! elf_file_p (&x_ehdr64)
426+ || x_ehdr64.e_ident[EI_VERSION] != EV_CURRENT
427+ || !((bfd_get_arch_size (templ) == 64
428+ && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS64)
429+ || (bfd_get_arch_size (templ) == 32
430+ && x_ehdr64.e_ident[EI_CLASS] == ELFCLASS32)))
431+ {
432+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
433+ warning (_("build-id: Unrecognized ELF header at address 0x%lx"),
434+ (unsigned long) ehdr_vma);
435+ return NULL;
436+ }
437+
438+ /* Check that file's byte order matches xvec's */
439+ switch (x_ehdr64.e_ident[EI_DATA])
440+ {
441+ case ELFDATA2MSB: /* Big-endian */
442+ if (! bfd_header_big_endian (templ))
443+ {
444+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
445+ warning (_("build-id: Unrecognized "
446+ "big-endian ELF header at address 0x%lx"),
447+ (unsigned long) ehdr_vma);
448+ return NULL;
449+ }
450+ break;
451+ case ELFDATA2LSB: /* Little-endian */
452+ if (! bfd_header_little_endian (templ))
453+ {
454+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
455+ warning (_("build-id: Unrecognized "
456+ "little-endian ELF header at address 0x%lx"),
457+ (unsigned long) ehdr_vma);
458+ return NULL;
459+ }
460+ break;
461+ case ELFDATANONE: /* No data encoding specified */
462+ default: /* Unknown data encoding specified */
463+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
464+ warning (_("build-id: Unrecognized "
465+ "ELF header endianity at address 0x%lx"),
466+ (unsigned long) ehdr_vma);
467+ return NULL;
468+ }
469+
470+ elf_swap_ehdr_in (templ, &x_ehdr64, &i_ehdr);
471+
472+ /* The file header tells where to find the program headers.
473+ These are what we use to actually choose what to read. */
474+
475+ if (i_ehdr.e_phentsize != (bfd_get_arch_size (templ) == 64
476+ ? sizeof (Elf64_External_Phdr)
477+ : sizeof (Elf32_External_Phdr))
478+ || i_ehdr.e_phnum == 0)
479+ {
480+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
481+ warning (_("build-id: Invalid ELF program headers from the ELF header "
482+ "at address 0x%lx"), (unsigned long) ehdr_vma);
483+ return NULL;
484+ }
485+
486+ x_phdrs_size = (bfd_get_arch_size (templ) == 64 ? sizeof (Elf64_External_Phdr)
487+ : sizeof (Elf32_External_Phdr));
488+
489+ i_phdrs = xmalloc (i_ehdr.e_phnum * (sizeof *i_phdrs + x_phdrs_size));
490+ x_phdrs_ptr = (void *) &i_phdrs[i_ehdr.e_phnum];
491+ err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs_ptr,
492+ i_ehdr.e_phnum * x_phdrs_size);
493+ if (err)
494+ {
495+ free (i_phdrs);
496+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
497+ warning (_("build-id: Error reading "
498+ "ELF program headers at address 0x%lx"),
499+ (unsigned long) (ehdr_vma + i_ehdr.e_phoff));
500+ return NULL;
501+ }
502+
503+ loadbase = ehdr_vma;
504+ loadbase_set = 0;
505+ for (i = 0; i < i_ehdr.e_phnum; ++i)
506+ {
507+ elf_swap_phdr_in (templ, (Elf64_External_Phdr *)
508+ (x_phdrs_ptr + i * x_phdrs_size), &i_phdrs[i]);
509+ /* IA-64 vDSO may have two mappings for one segment, where one mapping
510+ is executable only, and one is read only. We must not use the
511+ executable one (PF_R is the first one, PF_X the second one). */
512+ if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R))
513+ {
514+ /* Only the first PT_LOAD segment indicates the file bias.
515+ Next segments may have P_VADDR arbitrarily higher.
516+ If the first segment has P_VADDR zero any next segment must not
517+ confuse us, the first one sets LOADBASE certainly enough. */
518+ if (!loadbase_set && i_phdrs[i].p_offset == 0)
519+ {
520+ loadbase = ehdr_vma - i_phdrs[i].p_vaddr;
521+ loadbase_set = 1;
522+ }
523+ }
524+ }
525+
526+ if (build_id_verbose >= BUILD_ID_VERBOSE_BINARY_PARSE)
527+ warning (_("build-id: Found ELF header at address 0x%lx, loadbase 0x%lx"),
528+ (unsigned long) ehdr_vma, (unsigned long) loadbase);
529+
530+ *e_phnum_pointer = i_ehdr.e_phnum;
531+ *loadbase_pointer = loadbase;
532+ return i_phdrs;
533+}
534+
535+/* BUILD_ID_ADDR_GET gets ADDR located somewhere in the object.
536+ Find the first section before ADDR containing an ELF header.
537+ We rely on the fact the sections from multiple files do not mix.
538+ FIXME: We should check ADDR is contained _inside_ the section with possibly
539+ missing content (P_FILESZ < P_MEMSZ). These omitted sections are currently
540+ hidden by _BFD_ELF_MAKE_SECTION_FROM_PHDR. */
541+
542+static CORE_ADDR build_id_addr;
543+struct build_id_addr_sect
544+ {
545+ struct build_id_addr_sect *next;
546+ asection *sect;
547+ };
548+static struct build_id_addr_sect *build_id_addr_sect;
549+
550+static void build_id_addr_candidate (bfd *abfd, asection *sect, void *obj)
551+{
552+ if (build_id_addr >= bfd_section_vma (abfd, sect))
553+ {
554+ struct build_id_addr_sect *candidate;
555+
556+ candidate = xmalloc (sizeof *candidate);
557+ candidate->next = build_id_addr_sect;
558+ build_id_addr_sect = candidate;
559+ candidate->sect = sect;
560+ }
561+}
562+
563+struct build_id *
564+build_id_addr_get (CORE_ADDR addr)
565+{
566+ struct build_id_addr_sect *candidate;
567+ struct build_id *retval = NULL;
568+ Elf_Internal_Phdr *i_phdr = NULL;
569+ bfd_vma loadbase = 0;
570+ unsigned e_phnum = 0;
571+
572+ if (core_bfd == NULL)
573+ return NULL;
574+
575+ build_id_addr = addr;
576+ gdb_assert (build_id_addr_sect == NULL);
577+ bfd_map_over_sections (core_bfd, build_id_addr_candidate, NULL);
578+
579+ /* Sections are sorted in the high-to-low VMAs order.
580+ Stop the search on the first ELF header we find.
581+ Do not continue the search even if it does not contain NT_GNU_BUILD_ID. */
582+
583+ for (candidate = build_id_addr_sect; candidate != NULL;
584+ candidate = candidate->next)
585+ {
586+ i_phdr = elf_get_phdr (core_bfd,
587+ bfd_section_vma (core_bfd, candidate->sect),
588+ &e_phnum, &loadbase);
589+ if (i_phdr != NULL)
590+ break;
591+ }
592+
593+ if (i_phdr != NULL)
594+ {
595+ retval = build_id_phdr_get (core_bfd, loadbase, e_phnum, i_phdr);
596+ xfree (i_phdr);
597+ }
598+
599+ while (build_id_addr_sect != NULL)
600+ {
601+ candidate = build_id_addr_sect;
602+ build_id_addr_sect = candidate->next;
603+ xfree (candidate);
604+ }
605+
606+ return retval;
607+}
608+
609 /* Return if FILENAME has NT_GNU_BUILD_ID matching the CHECK value. */
610
611 static int
7566401a 612@@ -1215,7 +1607,7 @@ build_id_verify (const char *filename, s
3a58abaf
AM
613 if (abfd == NULL)
614 return 0;
615
616- found = build_id_bfd_get (abfd);
617+ found = build_id_bfd_shdr_get (abfd);
618
619 if (found == NULL)
620 warning (_("File \"%s\" has no build-id, file skipped"), filename);
ab050a48 621@@ -1234,14 +1626,16 @@ build_id_verify (const char *filename, s
3a58abaf
AM
622 return retval;
623 }
624
625-static char *
626-build_id_to_debug_filename (struct build_id *build_id)
627+char *
628+build_id_to_filename (struct build_id *build_id, char **link_return,
629+ int add_debug_suffix)
630 {
ab050a48
BZ
631 char *link, *debugdir, *retval = NULL;
632+ char *link_all = NULL;
3a58abaf
AM
633
634 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
ab050a48
BZ
635- link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
636- + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
637+ link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
638+ + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
639
640 /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
641 cause "/.build-id/..." lookups. */
642@@ -1272,7 +1666,10 @@ build_id_to_debug_filename (struct build
643 *s++ = '/';
644 while (size-- > 0)
645 s += sprintf (s, "%02x", (unsigned) *data++);
646- strcpy (s, ".debug");
647+ if (add_debug_suffix)
648+ strcpy (s, ".debug");
649+ else
650+ *s = 0;
651
652 /* lrealpath() is expensive even for the usually non-existent files. */
653 if (access (link, F_OK) == 0)
654@@ -1285,15 +1682,185 @@ build_id_to_debug_filename (struct build
655 }
3a58abaf 656
ab050a48
BZ
657 if (retval != NULL)
658- break;
659+ {
660+ /* LINK_ALL is not used below in this non-NULL RETVAL case. */
661+ break;
662+ }
663+
664+ if (link_all == NULL)
665+ link_all = xstrdup (link);
666+ else
667+ {
668+ size_t len_orig = strlen (link_all);
669+
670+ link_all = xrealloc (link_all, len_orig + 1 + strlen (link) + 1);
671+
672+ /* Use whitespace instead of DIRNAME_SEPARATOR to be compatible with
673+ its possible use as an argument for installation command. */
674+ link_all[len_orig] = ' ';
675+
676+ strcpy (&link_all[len_orig + 1], link);
677+ }
3a58abaf 678
ab050a48 679 debugdir = debugdir_end;
3a58abaf 680 }
ab050a48 681 while (*debugdir != 0);
3a58abaf
AM
682
683+ if (link_return != NULL)
ab050a48
BZ
684+ {
685+ if (retval != NULL)
686+ {
687+ *link_return = link;
688+ link = NULL;
689+ }
690+ else
691+ {
692+ *link_return = link_all;
693+ link_all = NULL;
694+ }
695+ }
696+ xfree (link);
697+ xfree (link_all);
698+
699+ return retval;
700+}
3a58abaf 701+
3a58abaf
AM
702+/* This MISSING_FILEPAIR_HASH tracker is used only for the duplicite messages
703+ Try to install the hash file ...
704+ avoidance. */
705+
706+struct missing_filepair
707+ {
708+ char *binary;
709+ char *debug;
710+ char data[1];
711+ };
712+
713+static struct htab *missing_filepair_hash;
714+static struct obstack missing_filepair_obstack;
715+
716+static void *
717+missing_filepair_xcalloc (size_t nmemb, size_t nmemb_size)
718+{
719+ void *retval;
720+ size_t size = nmemb * nmemb_size;
721+
722+ retval = obstack_alloc (&missing_filepair_obstack, size);
723+ memset (retval, 0, size);
ab050a48
BZ
724 return retval;
725 }
726
3a58abaf
AM
727+static hashval_t
728+missing_filepair_hash_func (const struct missing_filepair *elem)
729+{
730+ hashval_t retval = 0;
731+
732+ retval ^= htab_hash_string (elem->binary);
733+ if (elem->debug != NULL)
734+ retval ^= htab_hash_string (elem->debug);
735+
736+ return retval;
737+}
738+
739+static int
740+missing_filepair_eq (const struct missing_filepair *elem1,
741+ const struct missing_filepair *elem2)
742+{
743+ return strcmp (elem1->binary, elem2->binary) == 0
7566401a
ER
744+ && ((elem1->debug == NULL) == (elem2->debug == NULL))
745+ && (elem1->debug == NULL || strcmp (elem1->debug, elem2->debug) == 0);
3a58abaf
AM
746+}
747+
748+static void
749+missing_filepair_change (void)
750+{
751+ if (missing_filepair_hash != NULL)
752+ {
753+ obstack_free (&missing_filepair_obstack, NULL);
754+ /* All their memory came just from missing_filepair_OBSTACK. */
755+ missing_filepair_hash = NULL;
756+ }
757+}
758+
759+static void
760+debug_print_executable_changed (void)
761+{
762+ missing_filepair_change ();
763+}
764+
765+/* Notify user the file BINARY with (possibly NULL) associated separate debug
766+ information file DEBUG is missing. DEBUG may or may not be the build-id
767+ file such as would be:
768+ /usr/lib/debug/.build-id/dd/b1d2ce632721c47bb9e8679f369e2295ce71be.debug
769+ */
770+
771+void
772+debug_print_missing (const char *binary, const char *debug)
773+{
774+ size_t binary_len0 = strlen (binary) + 1;
775+ size_t debug_len0 = debug ? strlen (debug) + 1 : 0;
7566401a 776+ struct missing_filepair missing_filepair_find;
3a58abaf
AM
777+ struct missing_filepair *missing_filepair;
778+ struct missing_filepair **slot;
779+
780+ if (build_id_verbose < BUILD_ID_VERBOSE_FILENAMES)
781+ return;
782+
783+ if (missing_filepair_hash == NULL)
784+ {
785+ obstack_init (&missing_filepair_obstack);
786+ missing_filepair_hash = htab_create_alloc (64,
787+ (hashval_t (*) (const void *)) missing_filepair_hash_func,
788+ (int (*) (const void *, const void *)) missing_filepair_eq, NULL,
789+ missing_filepair_xcalloc, NULL);
790+ }
791+
7566401a
ER
792+ /* Use MISSING_FILEPAIR_FIND first instead of calling obstack_alloc with
793+ obstack_free in the case of a (rare) match. The problem is ALLOC_F for
794+ MISSING_FILEPAIR_HASH allocates from MISSING_FILEPAIR_OBSTACK maintenance
795+ structures for MISSING_FILEPAIR_HASH. Calling obstack_free would possibly
796+ not to free only MISSING_FILEPAIR but also some such structures (allocated
797+ during the htab_find_slot call). */
798+
799+ missing_filepair_find.binary = (char *) binary;
800+ missing_filepair_find.debug = (char *) debug;
801+ slot = (struct missing_filepair **) htab_find_slot (missing_filepair_hash,
802+ &missing_filepair_find,
803+ INSERT);
804+
805+ /* While it may be still printed duplicitely with the missing debuginfo file
806+ * it is due to once printing about the binary file build-id link and once
807+ * about the .debug file build-id link as both the build-id symlinks are
808+ * located in the debuginfo package. */
809+
810+ if (*slot != NULL)
811+ return;
812+
3a58abaf
AM
813+ missing_filepair = obstack_alloc (&missing_filepair_obstack,
814+ sizeof (*missing_filepair) - 1
815+ + binary_len0 + debug_len0);
816+ missing_filepair->binary = missing_filepair->data;
817+ memcpy (missing_filepair->binary, binary, binary_len0);
818+ if (debug != NULL)
819+ {
820+ missing_filepair->debug = missing_filepair->binary + binary_len0;
821+ memcpy (missing_filepair->debug, debug, debug_len0);
822+ }
823+ else
824+ missing_filepair->debug = NULL;
825+
3a58abaf
AM
826+ *slot = missing_filepair;
827+
828+ /* We do not collect and flush these messages as each such message
829+ already requires its own separate lines. */
830+
831+ fprintf_unfiltered (gdb_stdlog,
832+ _("Missing separate debuginfo for %s\n"), binary);
833+ if (debug != NULL)
834+ fprintf_unfiltered (gdb_stdlog, _("Try to install the hash file %s\n"),
835+ debug);
836+}
837+
838 static char *
839 get_debug_link_info (struct objfile *objfile, unsigned long *crc32_out)
840 {
ab050a48 841@@ -1384,13 +1951,14 @@ find_separate_debug_file (struct objfile
3a58abaf
AM
842 unsigned long crc32;
843 int i;
844 struct build_id *build_id;
845+ char *build_id_filename = NULL;
846
847- build_id = build_id_bfd_get (objfile->obfd);
848+ build_id = build_id_bfd_shdr_get (objfile->obfd);
849 if (build_id != NULL)
850 {
851 char *build_id_name;
852
853- build_id_name = build_id_to_debug_filename (build_id);
854+ build_id_name = build_id_to_filename (build_id, &build_id_filename, 1);
855 xfree (build_id);
856 /* Prevent looping on a stripped .debug file. */
857 if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
ab050a48 858@@ -1400,7 +1968,10 @@ find_separate_debug_file (struct objfile
3a58abaf
AM
859 xfree (build_id_name);
860 }
861 else if (build_id_name != NULL)
862- return build_id_name;
ab050a48 863+ {
3a58abaf
AM
864+ xfree (build_id_filename);
865+ return build_id_name;
866+ }
867 }
868
869 basename = get_debug_link_info (objfile, &crc32);
ab050a48 870@@ -1501,8 +2072,10 @@ find_separate_debug_file (struct objfile
7566401a 871
ab050a48
BZ
872 xfree (debugfile);
873 debugfile = NULL;
3a58abaf 874+ debug_print_missing (objfile->name, build_id_filename);
7566401a 875
ab050a48 876 cleanup_return_debugfile:
3a58abaf 877+ xfree (build_id_filename);
ab050a48 878 xfree (canon_name);
3a58abaf
AM
879 xfree (basename);
880 xfree (dir);
ab050a48 881@@ -4256,4 +4829,16 @@ each global debug-file-directory compone
7566401a
ER
882 NULL,
883 show_debug_file_directory,
884 &setlist, &showlist);
ab050a48 885+
7566401a
ER
886+ add_setshow_zinteger_cmd ("build-id-verbose", no_class, &build_id_verbose,
887+ _("\
888+ Set debugging level of the build-id locator."), _("\
889+ Show debugging level of the build-id locator."), _("\
890+ Level 1 (default) enables printing the missing debug filenames,\n\
891+ level 2 also prints the parsing of binaries to find the identificators."),
892+ NULL,
893+ show_build_id_verbose,
894+ &setlist, &showlist);
ab050a48 895+
7566401a 896+ observer_attach_executable_changed (debug_print_executable_changed);
3a58abaf 897 }
ab050a48 898Index: gdb-7.0/gdb/symfile.h
3a58abaf 899===================================================================
ab050a48
BZ
900--- gdb-7.0.orig/gdb/symfile.h 2009-10-23 00:12:38.000000000 +0200
901+++ gdb-7.0/gdb/symfile.h 2009-10-23 00:17:29.000000000 +0200
7566401a 902@@ -381,6 +381,13 @@ extern int symfile_map_offsets_to_segmen
3a58abaf
AM
903 struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
904 void free_symfile_segment_data (struct symfile_segment_data *data);
905
906+/* build-id support. */
907+struct build_id;
908+extern struct build_id *build_id_addr_get (CORE_ADDR addr);
909+extern char *build_id_to_filename (struct build_id *build_id,
910+ char **link_return, int add_debug_suffix);
911+extern void debug_print_missing (const char *binary, const char *debug);
912+
913 /* From dwarf2read.c */
914
915 extern int dwarf2_has_info (struct objfile *);
ab050a48 916Index: gdb-7.0/gdb/testsuite/lib/gdb.exp
3a58abaf 917===================================================================
ab050a48
BZ
918--- gdb-7.0.orig/gdb/testsuite/lib/gdb.exp 2009-10-23 00:12:38.000000000 +0200
919+++ gdb-7.0/gdb/testsuite/lib/gdb.exp 2009-10-23 00:17:29.000000000 +0200
7566401a 920@@ -1248,6 +1248,16 @@ proc default_gdb_start { } {
3a58abaf
AM
921 warning "Couldn't set the width to 0."
922 }
923 }
924+ # Turn off the missing warnings as the testsuite does not expect it.
925+ send_gdb "set build-id-verbose 0\n"
926+ gdb_expect 10 {
927+ -re "$gdb_prompt $" {
928+ verbose "Disabled the missing debug infos warnings." 2
929+ }
930+ timeout {
931+ warning "Could not disable the missing debug infos warnings.."
932+ }
933+ }
934 return 0;
935 }
936
ab050a48 937Index: gdb-7.0/gdb/testsuite/lib/mi-support.exp
7566401a 938===================================================================
ab050a48
BZ
939--- gdb-7.0.orig/gdb/testsuite/lib/mi-support.exp 2009-09-15 20:51:26.000000000 +0200
940+++ gdb-7.0/gdb/testsuite/lib/mi-support.exp 2009-10-23 00:17:29.000000000 +0200
d566d21e 941@@ -221,6 +221,16 @@ proc default_mi_gdb_start { args } {
942 }
943 }
944 }
945+ # Turn off the missing warnings as the testsuite does not expect it.
946+ send_gdb "190-gdb-set build-id-verbose 0\n"
947+ gdb_expect 10 {
948+ -re ".*190-gdb-set build-id-verbose 0\r\n190\\\^done\r\n$mi_gdb_prompt$" {
949+ verbose "Disabled the missing debug infos warnings." 2
950+ }
951+ timeout {
952+ warning "Could not disable the missing debug infos warnings.."
953+ }
954+ }
955
956 detect_async
957
ab050a48 958Index: gdb-7.0/gdb/objfiles.h
7566401a 959===================================================================
ab050a48
BZ
960--- gdb-7.0.orig/gdb/objfiles.h 2009-10-23 00:12:38.000000000 +0200
961+++ gdb-7.0/gdb/objfiles.h 2009-10-23 00:17:29.000000000 +0200
7566401a
ER
962@@ -428,6 +428,10 @@ struct objfile
963
964 #define OBJF_MAIN (1 << 7)
965
966+/* This file was loaded according to the BUILD_ID_CORE_LOADS rules. */
967+
968+#define OBJF_BUILD_ID_CORE_LOADED (1 << 12)
969+
970 /* The object file that the main symbol table was loaded from (e.g. the
971 argument to the "symbol-file" or "file" command). */
972
This page took 0.195586 seconds and 4 git commands to generate.