Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: gdb/machoread.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/m88kbsd-nat.c ('k') | gdb/macrocmd.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Darwin support for GDB, the GNU debugger. 1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 2008-2012 Free Software Foundation, Inc. 2 Copyright (C) 2008-2013 Free Software Foundation, Inc.
3 3
4 Contributed by AdaCore. 4 Contributed by AdaCore.
5 5
6 This file is part of GDB. 6 This file is part of GDB.
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or 10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 */
21 20
22 #include "defs.h" 21 #include "defs.h"
23 #include "symtab.h" 22 #include "symtab.h"
24 #include "gdbtypes.h" 23 #include "gdbtypes.h"
25 #include "bfd.h" 24 #include "bfd.h"
26 #include "symfile.h" 25 #include "symfile.h"
27 #include "objfiles.h" 26 #include "objfiles.h"
28 #include "buildsym.h" 27 #include "buildsym.h"
29 #include "gdbcmd.h" 28 #include "gdbcmd.h"
30 #include "gdbcore.h" 29 #include "gdbcore.h"
31 #include "mach-o.h" 30 #include "mach-o.h"
32 #include "gdb_assert.h" 31 #include "gdb_assert.h"
33 #include "aout/stab_gnu.h" 32 #include "aout/stab_gnu.h"
34 #include "vec.h" 33 #include "vec.h"
35 #include "psympriv.h" 34 #include "psympriv.h"
36 #include "complaints.h" 35 #include "complaints.h"
36 #include "gdb_bfd.h"
37 37
38 #include <string.h> 38 #include <string.h>
39 39
40 /* If non-zero displays debugging message. */ 40 /* If non-zero displays debugging message. */
41 static int mach_o_debug_level = 0; 41 static unsigned int mach_o_debug_level = 0;
42 42
43 /* Dwarf debugging information are never in the final executable. They stay 43 /* Dwarf debugging information are never in the final executable. They stay
44 in object files and the executable contains the list of object files read 44 in object files and the executable contains the list of object files read
45 during the link. 45 during the link.
46 Each time an oso (other source) is found in the executable, the reader 46 Each time an oso (other source) is found in the executable, the reader
47 creates such a structure. They are read after the processing of the 47 creates such a structure. They are read after the processing of the
48 executable. */ 48 executable. */
49 49
50 typedef struct oso_el 50 typedef struct oso_el
51 { 51 {
52 /* Object file name. Can also be a member name. */ 52 /* Object file name. Can also be a member name. */
53 const char *name; 53 const char *name;
54 54
55 /* Associated time stamp. */ 55 /* Associated time stamp. */
56 unsigned long mtime; 56 unsigned long mtime;
57 57
58 /* Stab symbols range for this OSO. */ 58 /* Stab symbols range for this OSO. */
59 asymbol **oso_sym; 59 asymbol **oso_sym;
60 asymbol **end_sym; 60 asymbol **end_sym;
61 61
62 /* Number of interesting stabs in the range. */ 62 /* Number of interesting stabs in the range. */
63 unsigned int nbr_syms; 63 unsigned int nbr_syms;
64 } 64 }
65 oso_el; 65 oso_el;
66 66
67 /* Vector of object files to be read after the executable. This is one 67 /* Vector of object files to be read after the executable. */
68 global variable but it's life-time is the one of macho_symfile_read. */
69 DEF_VEC_O (oso_el); 68 DEF_VEC_O (oso_el);
70 static VEC (oso_el) *oso_vector;
71 69
72 static void 70 static void
73 macho_new_init (struct objfile *objfile) 71 macho_new_init (struct objfile *objfile)
74 { 72 {
75 } 73 }
76 74
77 static void 75 static void
78 macho_symfile_init (struct objfile *objfile) 76 macho_symfile_init (struct objfile *objfile)
79 { 77 {
80 objfile->flags |= OBJF_REORDERED; 78 objfile->flags |= OBJF_REORDERED;
81 init_entry_point_info (objfile);
82 } 79 }
83 80
84 /* Add a new OSO to the vector of OSO to load. */ 81 /* Add a new OSO to the vector of OSO to load. */
85 82
86 static void 83 static void
87 macho_register_oso (struct objfile *objfile, 84 macho_register_oso (VEC (oso_el) **oso_vector_ptr,
85 » » struct objfile *objfile,
88 asymbol **oso_sym, asymbol **end_sym, 86 asymbol **oso_sym, asymbol **end_sym,
89 unsigned int nbr_syms) 87 unsigned int nbr_syms)
90 { 88 {
91 oso_el el; 89 oso_el el;
92 90
93 el.name = (*oso_sym)->name; 91 el.name = (*oso_sym)->name;
94 el.mtime = (*oso_sym)->value; 92 el.mtime = (*oso_sym)->value;
95 el.oso_sym = oso_sym; 93 el.oso_sym = oso_sym;
96 el.end_sym = end_sym; 94 el.end_sym = end_sym;
97 el.nbr_syms = nbr_syms; 95 el.nbr_syms = nbr_syms;
98 VEC_safe_push (oso_el, oso_vector, &el); 96 VEC_safe_push (oso_el, *oso_vector_ptr, &el);
99 } 97 }
100 98
101 /* Add symbol SYM to the minimal symbol table of OBJFILE. */ 99 /* Add symbol SYM to the minimal symbol table of OBJFILE. */
102 100
103 static void 101 static void
104 macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym) 102 macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
105 { 103 {
106 if (sym->name == NULL || *sym->name == '\0') 104 if (sym->name == NULL || *sym->name == '\0')
107 { 105 {
108 /* Skip names that don't exist (shouldn't happen), or names 106 /* Skip names that don't exist (shouldn't happen), or names
109 that are null strings (may happen). */ 107 that are null strings (may happen). */
110 return; 108 return;
111 } 109 }
112 110
113 if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK)) 111 if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
114 { 112 {
115 CORE_ADDR symaddr; 113 CORE_ADDR symaddr;
116 CORE_ADDR offset; 114 CORE_ADDR offset;
117 enum minimal_symbol_type ms_type; 115 enum minimal_symbol_type ms_type;
118 116
119 offset = ANOFFSET (objfile->section_offsets, sym->section->index); 117 offset = ANOFFSET (objfile->section_offsets,
118 » » » gdb_bfd_section_index (objfile->obfd, sym->section));
120 119
121 /* Bfd symbols are section relative. */ 120 /* Bfd symbols are section relative. */
122 symaddr = sym->value + sym->section->vma; 121 symaddr = sym->value + sym->section->vma;
123 122
124 /* Select global/local/weak symbols. Note that bfd puts abs 123 /* Select global/local/weak symbols. Note that bfd puts abs
125 symbols in their own section, so all symbols we are 124 symbols in their own section, so all symbols we are
126 interested in will have a section. */ 125 interested in will have a section. */
127 /* Relocate all non-absolute and non-TLS symbols by the 126 /* Relocate all non-absolute and non-TLS symbols by the
128 section offset. */ 127 section offset. */
129 if (sym->section != bfd_abs_section_ptr 128 if (sym->section != bfd_abs_section_ptr
(...skipping 27 matching lines...) Expand all
157 else 156 else
158 ms_type = mst_file_bss; 157 ms_type = mst_file_bss;
159 } 158 }
160 else 159 else
161 ms_type = mst_unknown; 160 ms_type = mst_unknown;
162 } 161 }
163 else 162 else
164 return; /* Skip this symbol. */ 163 return; /* Skip this symbol. */
165 164
166 prim_record_minimal_symbol_and_info 165 prim_record_minimal_symbol_and_info
167 (sym->name, symaddr, ms_type, sym->section->index, 166 (sym->name, symaddr, ms_type,
168 sym->section, objfile); 167 » gdb_bfd_section_index (objfile->obfd, sym->section),
168 » objfile);
169 } 169 }
170 } 170 }
171 171
172 /* Build the minimal symbol table from SYMBOL_TABLE of length 172 /* Build the minimal symbol table from SYMBOL_TABLE of length
173 NUMBER_OF_SYMBOLS for OBJFILE. Registers OSO filenames found. */ 173 NUMBER_OF_SYMBOLS for OBJFILE. Registers OSO filenames found. */
174 174
175 static void 175 static void
176 macho_symtab_read (struct objfile *objfile, 176 macho_symtab_read (struct objfile *objfile,
177 » » long number_of_symbols, asymbol **symbol_table) 177 » » long number_of_symbols, asymbol **symbol_table,
178 » » VEC (oso_el) **oso_vector_ptr)
178 { 179 {
179 long i; 180 long i;
180 const asymbol *dir_so = NULL; 181 const asymbol *dir_so = NULL;
181 const asymbol *file_so = NULL; 182 const asymbol *file_so = NULL;
182 asymbol **oso_file = NULL; 183 asymbol **oso_file = NULL;
183 unsigned int nbr_syms = 0; 184 unsigned int nbr_syms = 0;
184 185
185 /* Current state while reading stabs. */ 186 /* Current state while reading stabs. */
186 enum 187 enum
187 { 188 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 { 232 {
232 if (mach_o_sym->n_type == N_OPT) 233 if (mach_o_sym->n_type == N_OPT)
233 { 234 {
234 /* No complaint for OPT. */ 235 /* No complaint for OPT. */
235 break; 236 break;
236 } 237 }
237 238
238 /* Debugging symbols are not expected here. */ 239 /* Debugging symbols are not expected here. */
239 complaint (&symfile_complaints, 240 complaint (&symfile_complaints,
240 _("%s: Unexpected debug stab outside SO markers"), 241 _("%s: Unexpected debug stab outside SO markers"),
241 objfile->name); 242 objfile_name (objfile));
242 } 243 }
243 else 244 else
244 { 245 {
245 /* Non-debugging symbols go to the minimal symbol table. */ 246 /* Non-debugging symbols go to the minimal symbol table. */
246 macho_symtab_add_minsym (objfile, sym); 247 macho_symtab_add_minsym (objfile, sym);
247 } 248 }
248 break; 249 break;
249 250
250 case S_FIRST_SO: 251 case S_FIRST_SO:
251 case S_SECOND_SO: 252 case S_SECOND_SO:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 break; 292 break;
292 293
293 case S_STAB_FILE: 294 case S_STAB_FILE:
294 case S_DWARF_FILE: 295 case S_DWARF_FILE:
295 if (mach_o_sym->n_type == N_SO) 296 if (mach_o_sym->n_type == N_SO)
296 { 297 {
297 if (sym->name == NULL || sym->name[0] == 0) 298 if (sym->name == NULL || sym->name[0] == 0)
298 { 299 {
299 /* End of file. */ 300 /* End of file. */
300 if (state == S_DWARF_FILE) 301 if (state == S_DWARF_FILE)
301 macho_register_oso (objfile, oso_file, symbol_table + i, 302 macho_register_oso (oso_vector_ptr, objfile,
303 » » » » » oso_file, symbol_table + i,
302 nbr_syms); 304 nbr_syms);
303 state = S_NO_SO; 305 state = S_NO_SO;
304 } 306 }
305 else 307 else
306 { 308 {
307 complaint (&symfile_complaints, _("Missing nul SO")); 309 complaint (&symfile_complaints, _("Missing nul SO"));
308 file_so = sym; 310 file_so = sym;
309 dir_so = NULL; 311 dir_so = NULL;
310 state = S_FIRST_SO; 312 state = S_FIRST_SO;
311 } 313 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 warning (_("can't find symbol '%s' in minsymtab"), name); 440 warning (_("can't find symbol '%s' in minsymtab"), name);
439 return 0; 441 return 0;
440 } 442 }
441 else 443 else
442 return SYMBOL_VALUE_ADDRESS (msym); 444 return SYMBOL_VALUE_ADDRESS (msym);
443 } 445 }
444 446
445 /* Add oso file OSO/ABFD as a symbol file. */ 447 /* Add oso file OSO/ABFD as a symbol file. */
446 448
447 static void 449 static void
448 macho_add_oso_symfile (oso_el *oso, bfd *abfd, 450 macho_add_oso_symfile (oso_el *oso, bfd *abfd, const char *name,
449 struct objfile *main_objfile, int symfile_flags) 451 struct objfile *main_objfile, int symfile_flags)
450 { 452 {
451 int storage; 453 int storage;
452 int i; 454 int i;
453 asymbol **symbol_table; 455 asymbol **symbol_table;
454 asymbol **symp; 456 asymbol **symp;
455 struct bfd_hash_table table; 457 struct bfd_hash_table table;
456 int nbr_sections; 458 int nbr_sections;
459 struct cleanup *cleanup;
457 460
458 /* Per section flag to mark which section have been rebased. */ 461 /* Per section flag to mark which section have been rebased. */
459 unsigned char *sections_rebased; 462 unsigned char *sections_rebased;
460 463
461 if (mach_o_debug_level > 0) 464 if (mach_o_debug_level > 0)
462 printf_unfiltered 465 printf_unfiltered
463 (_("Loading debugging symbols from oso: %s\n"), oso->name); 466 (_("Loading debugging symbols from oso: %s\n"), oso->name);
464 467
465 if (!bfd_check_format (abfd, bfd_object)) 468 if (!bfd_check_format (abfd, bfd_object))
466 { 469 {
467 warning (_("`%s': can't read symbols: %s."), oso->name, 470 warning (_("`%s': can't read symbols: %s."), oso->name,
468 bfd_errmsg (bfd_get_error ())); 471 bfd_errmsg (bfd_get_error ()));
469 bfd_close (abfd); 472 gdb_bfd_unref (abfd);
470 return; 473 return;
471 } 474 }
472 475
473 if (abfd->my_archive == NULL && oso->mtime != bfd_get_mtime (abfd)) 476 if (abfd->my_archive == NULL && oso->mtime != bfd_get_mtime (abfd))
474 { 477 {
475 warning (_("`%s': file time stamp mismatch."), oso->name); 478 warning (_("`%s': file time stamp mismatch."), oso->name);
476 bfd_close (abfd); 479 gdb_bfd_unref (abfd);
477 return; 480 return;
478 } 481 }
479 482
480 if (!bfd_hash_table_init_n (&table, macho_sym_hash_newfunc, 483 if (!bfd_hash_table_init_n (&table, macho_sym_hash_newfunc,
481 sizeof (struct macho_sym_hash_entry), 484 sizeof (struct macho_sym_hash_entry),
482 oso->nbr_syms)) 485 oso->nbr_syms))
483 { 486 {
484 warning (_("`%s': can't create hash table"), oso->name); 487 warning (_("`%s': can't create hash table"), oso->name);
485 bfd_close (abfd); 488 gdb_bfd_unref (abfd);
486 return; 489 return;
487 } 490 }
488 491
489 bfd_set_cacheable (abfd, 1); 492 bfd_set_cacheable (abfd, 1);
490 493
491 /* Read symbols table. */ 494 /* Read symbols table. */
492 storage = bfd_get_symtab_upper_bound (abfd); 495 storage = bfd_get_symtab_upper_bound (abfd);
493 symbol_table = (asymbol **) xmalloc (storage); 496 symbol_table = (asymbol **) xmalloc (storage);
494 bfd_canonicalize_symtab (abfd, symbol_table); 497 bfd_canonicalize_symtab (abfd, symbol_table);
495 498
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 else 625 else
623 { 626 {
624 /* Mark the section as never rebased. */ 627 /* Mark the section as never rebased. */
625 sections_rebased[sec->index] = 2; 628 sections_rebased[sec->index] = 2;
626 } 629 }
627 } 630 }
628 } 631 }
629 632
630 bfd_hash_table_free (&table); 633 bfd_hash_table_free (&table);
631 634
632 /* Make sure that the filename was malloc'ed. The current filename comes
633 either from an OSO symbol name or from an archive name. Memory for both
634 is not managed by gdb. */
635 abfd->filename = xstrdup (abfd->filename);
636
637 /* We need to clear SYMFILE_MAINLINE to avoid interractive question 635 /* We need to clear SYMFILE_MAINLINE to avoid interractive question
638 from symfile.c:symbol_file_add_with_addrs_or_offsets. */ 636 from symfile.c:symbol_file_add_with_addrs_or_offsets. */
637 cleanup = make_cleanup_bfd_unref (abfd);
639 symbol_file_add_from_bfd 638 symbol_file_add_from_bfd
640 (abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL, 639 (abfd, name, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
641 main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED 640 main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
642 | OBJF_READNOW | OBJF_USERLOADED), 641 | OBJF_READNOW | OBJF_USERLOADED),
643 main_objfile); 642 main_objfile);
643 do_cleanups (cleanup);
644 } 644 }
645 645
646 /* Read symbols from the vector of oso files. */ 646 /* Read symbols from the vector of oso files.
647
648 Note that this function sorts OSO_VECTOR_PTR. */
647 649
648 static void 650 static void
649 macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags) 651 macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
652 » » » struct objfile *main_objfile,
653 » » » int symfile_flags)
650 { 654 {
651 int ix; 655 int ix;
652 VEC (oso_el) *vec; 656 VEC (oso_el) *vec = *oso_vector_ptr;
653 oso_el *oso; 657 oso_el *oso;
654 658 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
655 vec = oso_vector;
656 oso_vector = NULL;
657 659
658 /* Sort oso by name so that files from libraries are gathered. */ 660 /* Sort oso by name so that files from libraries are gathered. */
659 qsort (VEC_address (oso_el, vec), VEC_length (oso_el, vec), 661 qsort (VEC_address (oso_el, vec), VEC_length (oso_el, vec),
660 sizeof (oso_el), oso_el_compare_name); 662 sizeof (oso_el), oso_el_compare_name);
661 663
662 for (ix = 0; VEC_iterate (oso_el, vec, ix, oso);) 664 for (ix = 0; VEC_iterate (oso_el, vec, ix, oso);)
663 { 665 {
664 int pfx_len; 666 int pfx_len;
665 667
666 /* Check if this is a library name. */ 668 /* Check if this is a library name. */
667 pfx_len = get_archive_prefix_len (oso->name); 669 pfx_len = get_archive_prefix_len (oso->name);
668 if (pfx_len > 0) 670 if (pfx_len > 0)
669 { 671 {
670 bfd *archive_bfd; 672 bfd *archive_bfd;
671 bfd *member_bfd; 673 bfd *member_bfd;
672 char *archive_name = XNEWVEC (char, pfx_len + 1); 674 char *archive_name = XNEWVEC (char, pfx_len + 1);
673 int last_ix; 675 int last_ix;
674 oso_el *oso2; 676 oso_el *oso2;
675 int ix2; 677 int ix2;
676 678
677 memcpy (archive_name, oso->name, pfx_len); 679 memcpy (archive_name, oso->name, pfx_len);
678 archive_name[pfx_len] = '\0'; 680 archive_name[pfx_len] = '\0';
679 681
682 make_cleanup (xfree, archive_name);
683
680 /* Compute number of oso for this archive. */ 684 /* Compute number of oso for this archive. */
681 for (last_ix = ix; 685 for (last_ix = ix;
682 VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++) 686 VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++)
683 { 687 {
684 if (strncmp (oso2->name, archive_name, pfx_len) != 0) 688 if (strncmp (oso2->name, archive_name, pfx_len) != 0)
685 break; 689 break;
686 } 690 }
687 691
688 /* Open the archive and check the format. */ 692 /* Open the archive and check the format. */
689 » archive_bfd = bfd_openr (archive_name, gnutarget); 693 » archive_bfd = gdb_bfd_open (archive_name, gnutarget, -1);
690 if (archive_bfd == NULL) 694 if (archive_bfd == NULL)
691 { 695 {
692 warning (_("Could not open OSO archive file \"%s\""), 696 warning (_("Could not open OSO archive file \"%s\""),
693 archive_name); 697 archive_name);
694 ix = last_ix; 698 ix = last_ix;
695 continue; 699 continue;
696 } 700 }
697 if (!bfd_check_format (archive_bfd, bfd_archive)) 701 if (!bfd_check_format (archive_bfd, bfd_archive))
698 { 702 {
699 warning (_("OSO archive file \"%s\" not an archive."), 703 warning (_("OSO archive file \"%s\" not an archive."),
700 archive_name); 704 archive_name);
701 » bfd_close (archive_bfd); 705 » gdb_bfd_unref (archive_bfd);
702 ix = last_ix; 706 ix = last_ix;
703 continue; 707 continue;
704 } 708 }
705 » member_bfd = bfd_openr_next_archived_file (archive_bfd, NULL); 709
710 » member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd, NULL);
706 711
707 if (member_bfd == NULL) 712 if (member_bfd == NULL)
708 { 713 {
709 warning (_("Could not read archive members out of " 714 warning (_("Could not read archive members out of "
710 "OSO archive \"%s\""), archive_name); 715 "OSO archive \"%s\""), archive_name);
711 » bfd_close (archive_bfd); 716 » gdb_bfd_unref (archive_bfd);
712 ix = last_ix; 717 ix = last_ix;
713 continue; 718 continue;
714 } 719 }
715 720
716 /* Load all oso in this library. */ 721 /* Load all oso in this library. */
717 while (member_bfd != NULL) 722 while (member_bfd != NULL)
718 { 723 {
719 bfd *prev; 724 bfd *prev;
720 const char *member_name = member_bfd->filename; 725 const char *member_name = member_bfd->filename;
721 int member_len = strlen (member_name); 726 int member_len = strlen (member_name);
722 727
723 /* If this member is referenced, add it as a symfile. */ 728 /* If this member is referenced, add it as a symfile. */
724 for (ix2 = ix; ix2 < last_ix; ix2++) 729 for (ix2 = ix; ix2 < last_ix; ix2++)
725 { 730 {
726 oso2 = VEC_index (oso_el, vec, ix2); 731 oso2 = VEC_index (oso_el, vec, ix2);
727 732
728 if (oso2->name 733 if (oso2->name
729 && strlen (oso2->name) == pfx_len + member_len + 2 734 && strlen (oso2->name) == pfx_len + member_len + 2
730 && !memcmp (member_name, oso2->name + pfx_len + 1, 735 && !memcmp (member_name, oso2->name + pfx_len + 1,
731 member_len)) 736 member_len))
732 { 737 {
733 macho_add_oso_symfile (oso2, member_bfd, 738 macho_add_oso_symfile (oso2, member_bfd,
739 bfd_get_filename (member_bfd),
734 main_objfile, symfile_flags); 740 main_objfile, symfile_flags);
735 oso2->name = NULL; 741 oso2->name = NULL;
736 break; 742 break;
737 } 743 }
738 } 744 }
739 745
740 prev = member_bfd; 746 prev = member_bfd;
741 » member_bfd = bfd_openr_next_archived_file 747 » member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd,
742 » » (archive_bfd, member_bfd); 748 » » » » » » » member_bfd);
743 749
744 /* Free previous member if not referenced by an oso. */ 750 /* Free previous member if not referenced by an oso. */
745 if (ix2 >= last_ix) 751 if (ix2 >= last_ix)
746 bfd_close (prev); 752 gdb_bfd_unref (prev);
747 } 753 }
748 for (ix2 = ix; ix2 < last_ix; ix2++) 754 for (ix2 = ix; ix2 < last_ix; ix2++)
749 { 755 {
750 oso_el *oso2 = VEC_index (oso_el, vec, ix2); 756 oso_el *oso2 = VEC_index (oso_el, vec, ix2);
751 757
752 if (oso2->name != NULL) 758 if (oso2->name != NULL)
753 warning (_("Could not find specified archive member " 759 warning (_("Could not find specified archive member "
754 "for OSO name \"%s\""), oso->name); 760 "for OSO name \"%s\""), oso->name);
755 } 761 }
756 ix = last_ix; 762 ix = last_ix;
757 } 763 }
758 else 764 else
759 { 765 {
760 bfd *abfd; 766 bfd *abfd;
761 767
762 » abfd = bfd_openr (oso->name, gnutarget); 768 » abfd = gdb_bfd_open (oso->name, gnutarget, -1);
763 if (!abfd) 769 if (!abfd)
764 warning (_("`%s': can't open to read symbols: %s."), oso->name, 770 warning (_("`%s': can't open to read symbols: %s."), oso->name,
765 bfd_errmsg (bfd_get_error ())); 771 bfd_errmsg (bfd_get_error ()));
766 else 772 else
767 macho_add_oso_symfile (oso, abfd, main_objfile, symfile_flags); 773 macho_add_oso_symfile (oso, abfd, oso->name, main_objfile,
774 » » » » symfile_flags);
768 775
769 ix++; 776 ix++;
770 } 777 }
771 } 778 }
772 779
773 VEC_free (oso_el, vec); 780 do_cleanups (cleanup);
774 } 781 }
775 782
776 /* DSYM (debug symbols) files contain the debug info of an executable. 783 /* DSYM (debug symbols) files contain the debug info of an executable.
777 This is a separate file created by dsymutil(1) and is similar to debug 784 This is a separate file created by dsymutil(1) and is similar to debug
778 link feature on ELF. 785 link feature on ELF.
779 DSYM files are located in a subdirectory. Append DSYM_SUFFIX to the 786 DSYM files are located in a subdirectory. Append DSYM_SUFFIX to the
780 executable name and the executable base name to get the DSYM file name. */ 787 executable name and the executable base name to get the DSYM file name. */
781 #define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/" 788 #define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/"
782 789
783 /* Check if a dsym file exists for OBJFILE. If so, returns a bfd for it. 790 /* Check if a dsym file exists for OBJFILE. If so, returns a bfd for it
784 Return NULL if no valid dsym file is found. */ 791 and return *FILENAMEP with its original xmalloc-ated filename.
792 Return NULL if no valid dsym file is found (FILENAMEP is not used in
793 such case). */
785 794
786 static bfd * 795 static bfd *
787 macho_check_dsym (struct objfile *objfile) 796 macho_check_dsym (struct objfile *objfile, char **filenamep)
788 { 797 {
789 size_t name_len = strlen (objfile->name); 798 size_t name_len = strlen (objfile_name (objfile));
790 size_t dsym_len = strlen (DSYM_SUFFIX); 799 size_t dsym_len = strlen (DSYM_SUFFIX);
791 const char *base_name = lbasename (objfile->name); 800 const char *base_name = lbasename (objfile_name (objfile));
792 size_t base_len = strlen (base_name); 801 size_t base_len = strlen (base_name);
793 char *dsym_filename = alloca (name_len + dsym_len + base_len + 1); 802 char *dsym_filename = alloca (name_len + dsym_len + base_len + 1);
794 bfd *dsym_bfd; 803 bfd *dsym_bfd;
795 bfd_mach_o_load_command *main_uuid; 804 bfd_mach_o_load_command *main_uuid;
796 bfd_mach_o_load_command *dsym_uuid; 805 bfd_mach_o_load_command *dsym_uuid;
797 806
798 strcpy (dsym_filename, objfile->name); 807 strcpy (dsym_filename, objfile_name (objfile));
799 strcpy (dsym_filename + name_len, DSYM_SUFFIX); 808 strcpy (dsym_filename + name_len, DSYM_SUFFIX);
800 strcpy (dsym_filename + name_len + dsym_len, base_name); 809 strcpy (dsym_filename + name_len + dsym_len, base_name);
801 810
802 if (access (dsym_filename, R_OK) != 0) 811 if (access (dsym_filename, R_OK) != 0)
803 return NULL; 812 return NULL;
804 813
805 if (bfd_mach_o_lookup_command (objfile->obfd, 814 if (bfd_mach_o_lookup_command (objfile->obfd,
806 BFD_MACH_O_LC_UUID, &main_uuid) == 0) 815 BFD_MACH_O_LC_UUID, &main_uuid) == 0)
807 { 816 {
808 warning (_("can't find UUID in %s"), objfile->name); 817 warning (_("can't find UUID in %s"), objfile_name (objfile));
809 return NULL; 818 return NULL;
810 } 819 }
811 dsym_filename = xstrdup (dsym_filename); 820 dsym_bfd = gdb_bfd_openr (dsym_filename, gnutarget);
812 dsym_bfd = bfd_openr (dsym_filename, gnutarget);
813 if (dsym_bfd == NULL) 821 if (dsym_bfd == NULL)
814 { 822 {
815 warning (_("can't open dsym file %s"), dsym_filename); 823 warning (_("can't open dsym file %s"), dsym_filename);
816 xfree (dsym_filename);
817 return NULL; 824 return NULL;
818 } 825 }
819 826
820 if (!bfd_check_format (dsym_bfd, bfd_object)) 827 if (!bfd_check_format (dsym_bfd, bfd_object))
821 { 828 {
822 bfd_close (dsym_bfd); 829 gdb_bfd_unref (dsym_bfd);
823 warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ())); 830 warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
824 xfree (dsym_filename);
825 return NULL; 831 return NULL;
826 } 832 }
827 833
828 if (bfd_mach_o_lookup_command (dsym_bfd, 834 if (bfd_mach_o_lookup_command (dsym_bfd,
829 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0) 835 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
830 { 836 {
831 warning (_("can't find UUID in %s"), dsym_filename); 837 warning (_("can't find UUID in %s"), dsym_filename);
832 bfd_close (dsym_bfd); 838 gdb_bfd_unref (dsym_bfd);
833 xfree (dsym_filename);
834 return NULL; 839 return NULL;
835 } 840 }
836 if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid, 841 if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
837 sizeof (main_uuid->command.uuid.uuid))) 842 sizeof (main_uuid->command.uuid.uuid)))
838 { 843 {
839 warning (_("dsym file UUID doesn't match the one in %s"), objfile->name); 844 warning (_("dsym file UUID doesn't match the one in %s"),
840 bfd_close (dsym_bfd); 845 » objfile_name (objfile));
841 xfree (dsym_filename); 846 gdb_bfd_unref (dsym_bfd);
842 return NULL; 847 return NULL;
843 } 848 }
849 *filenamep = xstrdup (dsym_filename);
844 return dsym_bfd; 850 return dsym_bfd;
845 } 851 }
846 852
847 static void 853 static void
848 macho_symfile_read (struct objfile *objfile, int symfile_flags) 854 macho_symfile_read (struct objfile *objfile, int symfile_flags)
849 { 855 {
850 bfd *abfd = objfile->obfd; 856 bfd *abfd = objfile->obfd;
851 CORE_ADDR offset; 857 CORE_ADDR offset;
852 long storage_needed; 858 long storage_needed;
853 bfd *dsym_bfd; 859 bfd *dsym_bfd;
860 VEC (oso_el) *oso_vector = NULL;
861 struct cleanup *old_chain = make_cleanup (VEC_cleanup (oso_el), &oso_vector);
854 862
855 /* Get symbols from the symbol table only if the file is an executable. 863 /* Get symbols from the symbol table only if the file is an executable.
856 The symbol table of object files is not relocated and is expected to 864 The symbol table of object files is not relocated and is expected to
857 be in the executable. */ 865 be in the executable. */
858 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) 866 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
859 { 867 {
868 char *dsym_filename;
869
860 /* Process the normal symbol table first. */ 870 /* Process the normal symbol table first. */
861 storage_needed = bfd_get_symtab_upper_bound (objfile->obfd); 871 storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
862 if (storage_needed < 0) 872 if (storage_needed < 0)
863 error (_("Can't read symbols from %s: %s"), 873 error (_("Can't read symbols from %s: %s"),
864 bfd_get_filename (objfile->obfd), 874 bfd_get_filename (objfile->obfd),
865 bfd_errmsg (bfd_get_error ())); 875 bfd_errmsg (bfd_get_error ()));
866 876
867 if (storage_needed > 0) 877 if (storage_needed > 0)
868 { 878 {
869 asymbol **symbol_table; 879 asymbol **symbol_table;
870 long symcount; 880 long symcount;
871 struct cleanup *back_to;
872 881
873 symbol_table = (asymbol **) xmalloc (storage_needed); 882 symbol_table = (asymbol **) xmalloc (storage_needed);
874 make_cleanup (xfree, symbol_table); 883 make_cleanup (xfree, symbol_table);
875 884
876 init_minimal_symbol_collection (); 885 init_minimal_symbol_collection ();
877 back_to = make_cleanup_discard_minimal_symbols (); 886 make_cleanup_discard_minimal_symbols ();
878 887
879 symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table); 888 symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
880 889
881 if (symcount < 0) 890 if (symcount < 0)
882 error (_("Can't read symbols from %s: %s"), 891 error (_("Can't read symbols from %s: %s"),
883 bfd_get_filename (objfile->obfd), 892 bfd_get_filename (objfile->obfd),
884 bfd_errmsg (bfd_get_error ())); 893 bfd_errmsg (bfd_get_error ()));
885 894
886 » macho_symtab_read (objfile, symcount, symbol_table); 895 » macho_symtab_read (objfile, symcount, symbol_table, &oso_vector);
887 896
888 install_minimal_symbols (objfile); 897 install_minimal_symbols (objfile);
889 do_cleanups (back_to);
890 } 898 }
891 899
892 /* Try to read .eh_frame / .debug_frame. */ 900 /* Try to read .eh_frame / .debug_frame. */
893 /* First, locate these sections. We ignore the result status 901 /* First, locate these sections. We ignore the result status
894 as it only checks for debug info. */ 902 as it only checks for debug info. */
895 dwarf2_has_info (objfile, NULL); 903 dwarf2_has_info (objfile, NULL);
896 dwarf2_build_frame_info (objfile); 904 dwarf2_build_frame_info (objfile);
897 905
898 /* Check for DSYM file. */ 906 /* Check for DSYM file. */
899 dsym_bfd = macho_check_dsym (objfile); 907 dsym_bfd = macho_check_dsym (objfile, &dsym_filename);
900 if (dsym_bfd != NULL) 908 if (dsym_bfd != NULL)
901 { 909 {
902 int ix; 910 int ix;
903 oso_el *oso; 911 oso_el *oso;
904 struct bfd_section *asect, *dsect; 912 struct bfd_section *asect, *dsect;
905 913
914 make_cleanup (xfree, dsym_filename);
915
906 if (mach_o_debug_level > 0) 916 if (mach_o_debug_level > 0)
907 printf_unfiltered (_("dsym file found\n")); 917 printf_unfiltered (_("dsym file found\n"));
908 918
909 /* Remove oso. They won't be used. */
910 VEC_free (oso_el, oso_vector);
911 oso_vector = NULL;
912
913 /* Set dsym section size. */ 919 /* Set dsym section size. */
914 for (asect = objfile->obfd->sections, dsect = dsym_bfd->sections; 920 for (asect = objfile->obfd->sections, dsect = dsym_bfd->sections;
915 asect && dsect; 921 asect && dsect;
916 asect = asect->next, dsect = dsect->next) 922 asect = asect->next, dsect = dsect->next)
917 { 923 {
918 if (strcmp (asect->name, dsect->name) != 0) 924 if (strcmp (asect->name, dsect->name) != 0)
919 break; 925 break;
920 bfd_set_section_size (dsym_bfd, dsect, 926 bfd_set_section_size (dsym_bfd, dsect,
921 bfd_get_section_size (asect)); 927 bfd_get_section_size (asect));
922 } 928 }
923 929
924 /* Add the dsym file as a separate file. */ 930 /* Add the dsym file as a separate file. */
925 symbol_file_add_separate (dsym_bfd, symfile_flags, objfile); 931 » make_cleanup_bfd_unref (dsym_bfd);
932 symbol_file_add_separate (dsym_bfd, dsym_filename, symfile_flags,
933 » » » » objfile);
926 934
927 /* Don't try to read dwarf2 from main file or shared libraries. */ 935 /* Don't try to read dwarf2 from main file or shared libraries. */
936 do_cleanups (old_chain);
928 return; 937 return;
929 } 938 }
930 } 939 }
931 940
932 if (dwarf2_has_info (objfile, NULL)) 941 if (dwarf2_has_info (objfile, NULL))
933 { 942 {
934 /* DWARF 2 sections */ 943 /* DWARF 2 sections */
935 dwarf2_build_psymtabs (objfile); 944 dwarf2_build_psymtabs (objfile);
936 } 945 }
937 946
938 /* Then the oso. */ 947 /* Then the oso. */
939 if (oso_vector != NULL) 948 if (oso_vector != NULL)
940 macho_symfile_read_all_oso (objfile, symfile_flags); 949 macho_symfile_read_all_oso (&oso_vector, objfile, symfile_flags);
950
951 do_cleanups (old_chain);
941 } 952 }
942 953
943 static bfd_byte * 954 static bfd_byte *
944 macho_symfile_relocate (struct objfile *objfile, asection *sectp, 955 macho_symfile_relocate (struct objfile *objfile, asection *sectp,
945 bfd_byte *buf) 956 bfd_byte *buf)
946 { 957 {
947 bfd *abfd = objfile->obfd; 958 bfd *abfd = objfile->obfd;
948 959
949 /* We're only interested in sections with relocation 960 /* We're only interested in sections with relocation
950 information. */ 961 information. */
951 if ((sectp->flags & SEC_RELOC) == 0) 962 if ((sectp->flags & SEC_RELOC) == 0)
952 return NULL; 963 return NULL;
953 964
954 if (mach_o_debug_level > 0) 965 if (mach_o_debug_level > 0)
955 printf_unfiltered (_("Relocate section '%s' of %s\n"), 966 printf_unfiltered (_("Relocate section '%s' of %s\n"),
956 sectp->name, objfile->name); 967 sectp->name, objfile_name (objfile));
957 968
958 return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL); 969 return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
959 } 970 }
960 971
961 static void 972 static void
962 macho_symfile_finish (struct objfile *objfile) 973 macho_symfile_finish (struct objfile *objfile)
963 { 974 {
964 } 975 }
965 976
966 static void 977 static void
967 macho_symfile_offsets (struct objfile *objfile, 978 macho_symfile_offsets (struct objfile *objfile,
968 struct section_addr_info *addrs) 979 const struct section_addr_info *addrs)
969 { 980 {
970 unsigned int i; 981 unsigned int i;
971 unsigned int num_sections; 982 unsigned int num_sections;
972 struct obj_section *osect; 983 struct obj_section *osect;
973 984
974 /* Allocate section_offsets. */ 985 /* Allocate section_offsets. */
975 objfile->num_sections = bfd_count_sections (objfile->obfd); 986 objfile->num_sections = bfd_count_sections (objfile->obfd);
976 objfile->section_offsets = (struct section_offsets *) 987 objfile->section_offsets = (struct section_offsets *)
977 obstack_alloc (&objfile->objfile_obstack, 988 obstack_alloc (&objfile->objfile_obstack,
978 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); 989 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
979 memset (objfile->section_offsets, 0, 990 memset (objfile->section_offsets, 0,
980 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); 991 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
981 992
982 /* This code is run when we first add the objfile with 993 /* This code is run when we first add the objfile with
983 symfile_add_with_addrs_or_offsets, when "addrs" not "offsets" are 994 symfile_add_with_addrs_or_offsets, when "addrs" not "offsets" are
984 passed in. The place in symfile.c where the addrs are applied 995 passed in. The place in symfile.c where the addrs are applied
985 depends on the addrs having section names. But in the dyld code 996 depends on the addrs having section names. But in the dyld code
986 we build an anonymous array of addrs, so that code is a no-op. 997 we build an anonymous array of addrs, so that code is a no-op.
987 Because of that, we have to apply the addrs to the sections here. 998 Because of that, we have to apply the addrs to the sections here.
988 N.B. if an objfile slides after we've already created it, then it 999 N.B. if an objfile slides after we've already created it, then it
989 goes through objfile_relocate. */ 1000 goes through objfile_relocate. */
990 1001
991 for (i = 0; i < addrs->num_sections; i++) 1002 for (i = 0; i < addrs->num_sections; i++)
992 { 1003 {
993 if (addrs->other[i].name == NULL)
994 continue;
995
996 ALL_OBJFILE_OSECTIONS (objfile, osect) 1004 ALL_OBJFILE_OSECTIONS (objfile, osect)
997 { 1005 {
998 const char *bfd_sect_name = osect->the_bfd_section->name; 1006 const char *bfd_sect_name = osect->the_bfd_section->name;
999 1007
1000 if (strcmp (bfd_sect_name, addrs->other[i].name) == 0) 1008 if (strcmp (bfd_sect_name, addrs->other[i].name) == 0)
1001 { 1009 {
1002 obj_section_offset (osect) = addrs->other[i].addr; 1010 obj_section_offset (osect) = addrs->other[i].addr;
1003 break; 1011 break;
1004 } 1012 }
1005 } 1013 }
1006 } 1014 }
1007 1015
1008 objfile->sect_index_text = 0; 1016 objfile->sect_index_text = 0;
1009 1017
1010 ALL_OBJFILE_OSECTIONS (objfile, osect) 1018 ALL_OBJFILE_OSECTIONS (objfile, osect)
1011 { 1019 {
1012 const char *bfd_sect_name = osect->the_bfd_section->name; 1020 const char *bfd_sect_name = osect->the_bfd_section->name;
1013 int sect_index = osect->the_bfd_section->index; 1021 int sect_index = osect - objfile->sections;;
1014 1022
1015 if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0) 1023 if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
1016 bfd_sect_name += 11; 1024 bfd_sect_name += 11;
1017 if (strcmp (bfd_sect_name, "__TEXT") == 0 1025 if (strcmp (bfd_sect_name, "__TEXT") == 0
1018 || strcmp (bfd_sect_name, "__TEXT.__text") == 0) 1026 || strcmp (bfd_sect_name, "__TEXT.__text") == 0)
1019 objfile->sect_index_text = sect_index; 1027 objfile->sect_index_text = sect_index;
1020 } 1028 }
1021 } 1029 }
1022 1030
1023 static const struct sym_fns macho_sym_fns = { 1031 static const struct sym_fns macho_sym_fns = {
1024 bfd_target_mach_o_flavour,
1025
1026 macho_new_init, /* init anything gbl to entire symtab */ 1032 macho_new_init, /* init anything gbl to entire symtab */
1027 macho_symfile_init, /* read initial info, setup for sym_read() */ 1033 macho_symfile_init, /* read initial info, setup for sym_read() */
1028 macho_symfile_read, /* read a symbol file into symtab */ 1034 macho_symfile_read, /* read a symbol file into symtab */
1029 NULL, /* sym_read_psymbols */ 1035 NULL, /* sym_read_psymbols */
1030 macho_symfile_finish, /* finished with file, cleanup */ 1036 macho_symfile_finish, /* finished with file, cleanup */
1031 macho_symfile_offsets, /* xlate external to internal form */ 1037 macho_symfile_offsets, /* xlate external to internal form */
1032 default_symfile_segments, /* Get segment information from a file. */ 1038 default_symfile_segments, /* Get segment information from a file. */
1033 NULL, 1039 NULL,
1034 macho_symfile_relocate, /* Relocate a debug section. */ 1040 macho_symfile_relocate, /* Relocate a debug section. */
1035 NULL, /* sym_get_probes */ 1041 NULL, /* sym_get_probes */
1036 &psym_functions 1042 &psym_functions
1037 }; 1043 };
1038 1044
1039 /* -Wmissing-prototypes */ 1045 /* -Wmissing-prototypes */
1040 extern initialize_file_ftype _initialize_machoread; 1046 extern initialize_file_ftype _initialize_machoread;
1041 1047
1042 void 1048 void
1043 _initialize_machoread () 1049 _initialize_machoread (void)
1044 { 1050 {
1045 add_symtab_fns (&macho_sym_fns); 1051 add_symtab_fns (bfd_target_mach_o_flavour, &macho_sym_fns);
1046 1052
1047 add_setshow_zinteger_cmd ("mach-o", class_obscure, 1053 add_setshow_zuinteger_cmd ("mach-o", class_obscure,
1048 » » » &mach_o_debug_level, 1054 » » » &mach_o_debug_level,
1049 » » » _("Set if printing Mach-O symbols processing."), 1055 » » » _("Set if printing Mach-O symbols processing."),
1050 » » » _("Show if printing Mach-O symbols processing."), 1056 » » » _("Show if printing Mach-O symbols processing."),
1051 » » » NULL, NULL, NULL, 1057 » » » NULL, NULL, NULL,
1052 » » » &setdebuglist, &showdebuglist); 1058 » » » &setdebuglist, &showdebuglist);
1053 } 1059 }
OLDNEW
« no previous file with comments | « gdb/m88kbsd-nat.c ('k') | gdb/macrocmd.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698