Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Read dbx symbol tables and convert to internal format, for GDB. |
b9e58503 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 |
65ce5df4 | 3 | Free Software Foundation, Inc. |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
c3a21801 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
c3a21801 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
c3a21801 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
c3a21801 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
9404978d MT |
20 | |
21 | /* This module provides three functions: dbx_symfile_init, | |
22 | which initializes to read a symbol file; dbx_new_init, which | |
23 | discards existing cached information when all symbols are being | |
24 | discarded; and dbx_symfile_read, which reads a symbol table | |
25 | from a file. | |
26 | ||
27 | dbx_symfile_read only does the minimum work necessary for letting the | |
28 | user "name" things symbolically; it does not read the entire symtab. | |
29 | Instead, it reads the external and static symbols and puts them in partial | |
30 | symbol tables. When more extensive information is requested of a | |
31 | file, the corresponding partial symbol table is mutated into a full | |
32 | fledged symbol table by going back and reading the symbols | |
33 | for real. dbx_psymtab_to_symtab() is the function that does this */ | |
bd5635a1 | 34 | |
bd5635a1 | 35 | #include "defs.h" |
2b576293 | 36 | #include "gdb_string.h" |
bd5635a1 | 37 | |
9342ecb9 | 38 | #if defined(USG) || defined(__CYGNUSCLIB__) |
bd5635a1 RP |
39 | #include <sys/types.h> |
40 | #include <fcntl.h> | |
bd5635a1 RP |
41 | #endif |
42 | ||
afe4ca15 JG |
43 | #include <obstack.h> |
44 | #include <sys/param.h> | |
021959e2 | 45 | #ifndef NO_SYS_FILE |
afe4ca15 | 46 | #include <sys/file.h> |
021959e2 | 47 | #endif |
2b576293 | 48 | #include "gdb_stat.h" |
bd5635a1 | 49 | #include <ctype.h> |
afe4ca15 JG |
50 | #include "symtab.h" |
51 | #include "breakpoint.h" | |
52 | #include "command.h" | |
53 | #include "target.h" | |
54 | #include "gdbcore.h" /* for bfd stuff */ | |
55 | #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ | |
56 | #include "symfile.h" | |
3624c875 | 57 | #include "objfiles.h" |
c0302457 | 58 | #include "buildsym.h" |
3416d90b | 59 | #include "stabsread.h" |
2af231b8 | 60 | #include "gdb-stabs.h" |
3416d90b | 61 | #include "demangle.h" |
51b80b00 FF |
62 | #include "language.h" /* Needed inside partial-stab.h */ |
63 | #include "complaints.h" | |
afe4ca15 | 64 | |
7e258d18 PB |
65 | #include "aout/aout64.h" |
66 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */ | |
bd5635a1 | 67 | |
2c7ab4ca JK |
68 | #if !defined (SEEK_SET) |
69 | #define SEEK_SET 0 | |
70 | #define SEEK_CUR 1 | |
71 | #endif | |
989d9cba | 72 | \f |
2b576293 C |
73 | /* We put a pointer to this structure in the read_symtab_private field |
74 | of the psymtab. */ | |
4a35d6e9 | 75 | |
989d9cba | 76 | struct symloc { |
4a35d6e9 | 77 | |
989d9cba JK |
78 | /* Offset within the file symbol table of first local symbol for this |
79 | file. */ | |
4a35d6e9 | 80 | |
4a35d6e9 | 81 | int ldsymoff; |
989d9cba JK |
82 | |
83 | /* Length (in bytes) of the section of the symbol table devoted to | |
84 | this file's symbols (actually, the section bracketed may contain | |
85 | more than just this file's symbols). If ldsymlen is 0, the only | |
86 | reason for this thing's existence is the dependency list. Nothing | |
87 | else will happen when it is read in. */ | |
88 | ||
4a35d6e9 | 89 | int ldsymlen; |
989d9cba JK |
90 | |
91 | /* The size of each symbol in the symbol file (in external form). */ | |
92 | ||
9342ecb9 | 93 | int symbol_size; |
989d9cba JK |
94 | |
95 | /* Further information needed to locate the symbols if they are in | |
96 | an ELF file. */ | |
97 | ||
9342ecb9 JG |
98 | int symbol_offset; |
99 | int string_offset; | |
100 | int file_string_offset; | |
4a35d6e9 FF |
101 | }; |
102 | ||
989d9cba JK |
103 | #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) |
104 | #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen) | |
105 | #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private)) | |
106 | #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size) | |
107 | #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset) | |
108 | #define STRING_OFFSET(p) (SYMLOC(p)->string_offset) | |
109 | #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset) | |
110 | ||
111 | \f | |
bd5635a1 RP |
112 | /* Macro to determine which symbols to ignore when reading the first symbol |
113 | of a file. Some machines override this definition. */ | |
114 | #ifndef IGNORE_SYMBOL | |
115 | /* This code is used on Ultrix systems. Ignore it */ | |
116 | #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS) | |
117 | #endif | |
118 | ||
2e4964ad FF |
119 | /* Remember what we deduced to be the source language of this psymtab. */ |
120 | ||
121 | static enum language psymtab_language = language_unknown; | |
122 | ||
bd5635a1 RP |
123 | /* Nonzero means give verbose info on gdb action. From main.c. */ |
124 | extern int info_verbose; | |
125 | ||
7d9884b9 | 126 | /* The BFD for this file -- implicit parameter to next_symbol_text. */ |
bd5635a1 | 127 | |
c0302457 | 128 | static bfd *symfile_bfd; |
bd5635a1 | 129 | |
afe4ca15 JG |
130 | /* The size of each symbol in the symbol file (in external form). |
131 | This is set by dbx_symfile_read when building psymtabs, and by | |
132 | dbx_psymtab_to_symtab when building symtabs. */ | |
133 | ||
134 | static unsigned symbol_size; | |
135 | ||
9342ecb9 JG |
136 | /* This is the offset of the symbol table in the executable file */ |
137 | static unsigned symbol_table_offset; | |
138 | ||
139 | /* This is the offset of the string table in the executable file */ | |
140 | static unsigned string_table_offset; | |
141 | ||
142 | /* For elf+stab executables, the n_strx field is not a simple index | |
143 | into the string table. Instead, each .o file has a base offset | |
144 | in the string table, and the associated symbols contain offsets | |
145 | from this base. The following two variables contain the base | |
146 | offset for the current and next .o files. */ | |
147 | static unsigned int file_string_table_offset; | |
148 | static unsigned int next_file_string_table_offset; | |
a66e8382 SG |
149 | |
150 | /* .o and NLM files contain unrelocated addresses which are based at 0. When | |
151 | non-zero, this flag disables some of the special cases for Solaris elf+stab | |
152 | text addresses at location 0. */ | |
153 | ||
154 | static int symfile_relocatable = 0; | |
bfe2f12b JL |
155 | |
156 | /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are relative | |
157 | to the function start address. */ | |
158 | ||
159 | static int block_address_function_relative = 0; | |
9d2b8d50 | 160 | \f |
ab52cc44 JK |
161 | /* The lowest text address we have yet encountered. This is needed |
162 | because in an a.out file, there is no header field which tells us | |
163 | what address the program is actually going to be loaded at, so we | |
164 | need to make guesses based on the symbols (which *are* relocated to | |
165 | reflect the address it will be loaded at). */ | |
9d2b8d50 | 166 | static CORE_ADDR lowest_text_address; |
9342ecb9 | 167 | |
bd5635a1 RP |
168 | /* Complaints about the symbols we have encountered. */ |
169 | ||
bd5635a1 RP |
170 | struct complaint lbrac_complaint = |
171 | {"bad block start address patched", 0, 0}; | |
172 | ||
bd5635a1 RP |
173 | struct complaint string_table_offset_complaint = |
174 | {"bad string table offset in symbol %d", 0, 0}; | |
175 | ||
176 | struct complaint unknown_symtype_complaint = | |
0c4d2cc2 | 177 | {"unknown symbol type %s", 0, 0}; |
bd5635a1 | 178 | |
65ce5df4 | 179 | struct complaint unknown_symchar_complaint = |
b30c81b6 | 180 | {"unknown symbol descriptor `%c'", 0, 0}; |
65ce5df4 | 181 | |
bd5635a1 RP |
182 | struct complaint lbrac_rbrac_complaint = |
183 | {"block start larger than block end", 0, 0}; | |
7d9884b9 JG |
184 | |
185 | struct complaint lbrac_unmatched_complaint = | |
186 | {"unmatched N_LBRAC before symtab pos %d", 0, 0}; | |
187 | ||
188 | struct complaint lbrac_mismatch_complaint = | |
189 | {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0}; | |
9342ecb9 JG |
190 | |
191 | struct complaint repeated_header_complaint = | |
26a859ec | 192 | {"\"repeated\" header file %s not previously seen, at symtab pos %d", 0, 0}; |
bd5635a1 | 193 | \f |
bd5635a1 RP |
194 | /* During initial symbol readin, we need to have a structure to keep |
195 | track of which psymtabs have which bincls in them. This structure | |
196 | is used during readin to setup the list of dependencies within each | |
197 | partial symbol table. */ | |
198 | ||
199 | struct header_file_location | |
200 | { | |
201 | char *name; /* Name of header file */ | |
202 | int instance; /* See above */ | |
203 | struct partial_symtab *pst; /* Partial symtab that has the | |
204 | BINCL/EINCL defs for this file */ | |
205 | }; | |
206 | ||
207 | /* The actual list and controling variables */ | |
208 | static struct header_file_location *bincl_list, *next_bincl; | |
209 | static int bincls_allocated; | |
210 | ||
021959e2 JG |
211 | /* Local function prototypes */ |
212 | ||
213 | static void | |
80d68b1d FF |
214 | free_header_files PARAMS ((void)); |
215 | ||
216 | static void | |
217 | init_header_files PARAMS ((void)); | |
021959e2 | 218 | |
574dac8e JK |
219 | static void |
220 | read_ofile_symtab PARAMS ((struct partial_symtab *)); | |
021959e2 JG |
221 | |
222 | static void | |
223 | dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *)); | |
224 | ||
225 | static void | |
4c07f28d | 226 | dbx_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *)); |
021959e2 | 227 | |
5801f348 JK |
228 | static void |
229 | read_dbx_dynamic_symtab PARAMS ((struct section_offsets *, | |
230 | struct objfile *objfile)); | |
231 | ||
021959e2 | 232 | static void |
2af231b8 JG |
233 | read_dbx_symtab PARAMS ((struct section_offsets *, struct objfile *, |
234 | CORE_ADDR, int)); | |
021959e2 JG |
235 | |
236 | static void | |
237 | free_bincl_list PARAMS ((struct objfile *)); | |
238 | ||
239 | static struct partial_symtab * | |
240 | find_corresponding_bincl_psymtab PARAMS ((char *, int)); | |
241 | ||
242 | static void | |
243 | add_bincl_to_list PARAMS ((struct partial_symtab *, char *, int)); | |
244 | ||
245 | static void | |
246 | init_bincl_list PARAMS ((int, struct objfile *)); | |
247 | ||
021959e2 JG |
248 | static char * |
249 | dbx_next_symbol_text PARAMS ((void)); | |
250 | ||
251 | static void | |
252 | fill_symbuf PARAMS ((bfd *)); | |
253 | ||
254 | static void | |
80d68b1d FF |
255 | dbx_symfile_init PARAMS ((struct objfile *)); |
256 | ||
257 | static void | |
258 | dbx_new_init PARAMS ((struct objfile *)); | |
021959e2 JG |
259 | |
260 | static void | |
2af231b8 | 261 | dbx_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int)); |
021959e2 JG |
262 | |
263 | static void | |
80d68b1d | 264 | dbx_symfile_finish PARAMS ((struct objfile *)); |
021959e2 JG |
265 | |
266 | static void | |
267 | record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *)); | |
268 | ||
269 | static void | |
270 | add_new_header_file PARAMS ((char *, int)); | |
271 | ||
272 | static void | |
273 | add_old_header_file PARAMS ((char *, int)); | |
274 | ||
275 | static void | |
276 | add_this_object_header_file PARAMS ((int)); | |
277 | ||
80d68b1d | 278 | /* Free up old header file tables */ |
bd5635a1 | 279 | |
021959e2 | 280 | static void |
80d68b1d | 281 | free_header_files () |
bd5635a1 RP |
282 | { |
283 | register int i; | |
bd5635a1 | 284 | |
80d68b1d FF |
285 | if (header_files != NULL) |
286 | { | |
287 | for (i = 0; i < n_header_files; i++) | |
288 | { | |
289 | free (header_files[i].name); | |
290 | } | |
ac88ca20 | 291 | free ((PTR)header_files); |
80d68b1d FF |
292 | header_files = NULL; |
293 | n_header_files = 0; | |
294 | } | |
295 | if (this_object_header_files) | |
296 | { | |
ac88ca20 | 297 | free ((PTR)this_object_header_files); |
80d68b1d FF |
298 | this_object_header_files = NULL; |
299 | } | |
300 | n_allocated_header_files = 0; | |
301 | n_allocated_this_object_header_files = 0; | |
302 | } | |
303 | ||
304 | /* Allocate new header file tables */ | |
305 | ||
306 | static void | |
307 | init_header_files () | |
308 | { | |
bd5635a1 | 309 | n_header_files = 0; |
80d68b1d FF |
310 | n_allocated_header_files = 10; |
311 | header_files = (struct header_file *) | |
312 | xmalloc (10 * sizeof (struct header_file)); | |
bd5635a1 RP |
313 | |
314 | n_allocated_this_object_header_files = 10; | |
315 | this_object_header_files = (int *) xmalloc (10 * sizeof (int)); | |
316 | } | |
317 | ||
bd5635a1 RP |
318 | /* Add header file number I for this object file |
319 | at the next successive FILENUM. */ | |
320 | ||
321 | static void | |
322 | add_this_object_header_file (i) | |
323 | int i; | |
324 | { | |
325 | if (n_this_object_header_files == n_allocated_this_object_header_files) | |
326 | { | |
327 | n_allocated_this_object_header_files *= 2; | |
328 | this_object_header_files | |
021959e2 | 329 | = (int *) xrealloc ((char *) this_object_header_files, |
bd5635a1 RP |
330 | n_allocated_this_object_header_files * sizeof (int)); |
331 | } | |
332 | ||
333 | this_object_header_files[n_this_object_header_files++] = i; | |
334 | } | |
335 | ||
336 | /* Add to this file an "old" header file, one already seen in | |
337 | a previous object file. NAME is the header file's name. | |
338 | INSTANCE is its instance code, to select among multiple | |
339 | symbol tables for the same header file. */ | |
340 | ||
341 | static void | |
342 | add_old_header_file (name, instance) | |
343 | char *name; | |
344 | int instance; | |
345 | { | |
346 | register struct header_file *p = header_files; | |
347 | register int i; | |
348 | ||
349 | for (i = 0; i < n_header_files; i++) | |
2e4964ad | 350 | if (STREQ (p[i].name, name) && instance == p[i].instance) |
bd5635a1 RP |
351 | { |
352 | add_this_object_header_file (i); | |
353 | return; | |
354 | } | |
26a859ec | 355 | complain (&repeated_header_complaint, name, symnum); |
bd5635a1 RP |
356 | } |
357 | ||
358 | /* Add to this file a "new" header file: definitions for its types follow. | |
359 | NAME is the header file's name. | |
360 | Most often this happens only once for each distinct header file, | |
361 | but not necessarily. If it happens more than once, INSTANCE has | |
362 | a different value each time, and references to the header file | |
363 | use INSTANCE values to select among them. | |
364 | ||
365 | dbx output contains "begin" and "end" markers for each new header file, | |
366 | but at this level we just need to know which files there have been; | |
367 | so we record the file when its "begin" is seen and ignore the "end". */ | |
368 | ||
369 | static void | |
370 | add_new_header_file (name, instance) | |
371 | char *name; | |
372 | int instance; | |
373 | { | |
374 | register int i; | |
bd5635a1 RP |
375 | |
376 | /* Make sure there is room for one more header file. */ | |
377 | ||
378 | if (n_header_files == n_allocated_header_files) | |
379 | { | |
380 | n_allocated_header_files *= 2; | |
381 | header_files = (struct header_file *) | |
021959e2 JG |
382 | xrealloc ((char *) header_files, |
383 | (n_allocated_header_files * sizeof (struct header_file))); | |
bd5635a1 RP |
384 | } |
385 | ||
386 | /* Create an entry for this header file. */ | |
387 | ||
388 | i = n_header_files++; | |
389 | header_files[i].name = savestring (name, strlen(name)); | |
390 | header_files[i].instance = instance; | |
391 | header_files[i].length = 10; | |
392 | header_files[i].vector | |
393 | = (struct type **) xmalloc (10 * sizeof (struct type *)); | |
4ed3a9ea | 394 | memset (header_files[i].vector, 0, 10 * sizeof (struct type *)); |
bd5635a1 RP |
395 | |
396 | add_this_object_header_file (i); | |
397 | } | |
398 | ||
bd5635a1 RP |
399 | #if 0 |
400 | static struct type ** | |
401 | explicit_lookup_type (real_filenum, index) | |
402 | int real_filenum, index; | |
403 | { | |
404 | register struct header_file *f = &header_files[real_filenum]; | |
405 | ||
406 | if (index >= f->length) | |
407 | { | |
408 | f->length *= 2; | |
409 | f->vector = (struct type **) | |
410 | xrealloc (f->vector, f->length * sizeof (struct type *)); | |
4ed97c9a RP |
411 | memset (&f->vector[f->length / 2], |
412 | '\0', f->length * sizeof (struct type *) / 2); | |
bd5635a1 RP |
413 | } |
414 | return &f->vector[index]; | |
415 | } | |
416 | #endif | |
417 | \f | |
9bba3334 | 418 | static void |
021959e2 | 419 | record_minimal_symbol (name, address, type, objfile) |
bd5635a1 RP |
420 | char *name; |
421 | CORE_ADDR address; | |
422 | int type; | |
021959e2 | 423 | struct objfile *objfile; |
bd5635a1 | 424 | { |
021959e2 | 425 | enum minimal_symbol_type ms_type; |
a66e8382 | 426 | int section; |
0c4d2cc2 | 427 | |
b8ec9a79 JK |
428 | switch (type) |
429 | { | |
a66e8382 SG |
430 | case N_TEXT | N_EXT: |
431 | ms_type = mst_text; | |
432 | section = SECT_OFF_TEXT; | |
433 | break; | |
434 | case N_DATA | N_EXT: | |
435 | ms_type = mst_data; | |
436 | section = SECT_OFF_DATA; | |
437 | break; | |
438 | case N_BSS | N_EXT: | |
439 | ms_type = mst_bss; | |
440 | section = SECT_OFF_BSS; | |
441 | break; | |
442 | case N_ABS | N_EXT: | |
443 | ms_type = mst_abs; | |
444 | section = -1; | |
445 | break; | |
0c4d2cc2 | 446 | #ifdef N_SETV |
a66e8382 SG |
447 | case N_SETV | N_EXT: |
448 | ms_type = mst_data; | |
449 | section = SECT_OFF_DATA; | |
450 | break; | |
b8ec9a79 JK |
451 | case N_SETV: |
452 | /* I don't think this type actually exists; since a N_SETV is the result | |
453 | of going over many .o files, it doesn't make sense to have one | |
454 | file local. */ | |
455 | ms_type = mst_file_data; | |
a66e8382 | 456 | section = SECT_OFF_DATA; |
b8ec9a79 | 457 | break; |
0c4d2cc2 | 458 | #endif |
05c81f45 | 459 | case N_TEXT: |
b8ec9a79 JK |
460 | case N_NBTEXT: |
461 | case N_FN: | |
462 | case N_FN_SEQ: | |
b8ec9a79 | 463 | ms_type = mst_file_text; |
a66e8382 | 464 | section = SECT_OFF_TEXT; |
b8ec9a79 | 465 | break; |
b8ec9a79 JK |
466 | case N_DATA: |
467 | ms_type = mst_file_data; | |
468 | ||
469 | /* Check for __DYNAMIC, which is used by Sun shared libraries. | |
470 | Record it as global even if it's local, not global, so | |
05c81f45 SEF |
471 | lookup_minimal_symbol can find it. We don't check symbol_leading_char |
472 | because for SunOS4 it always is '_'. */ | |
b8ec9a79 JK |
473 | if (name[8] == 'C' && STREQ ("__DYNAMIC", name)) |
474 | ms_type = mst_data; | |
475 | ||
476 | /* Same with virtual function tables, both global and static. */ | |
477 | { | |
478 | char *tempstring = name; | |
479 | if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd)) | |
480 | ++tempstring; | |
481 | if (VTBL_PREFIX_P ((tempstring))) | |
482 | ms_type = mst_data; | |
483 | } | |
a66e8382 | 484 | section = SECT_OFF_DATA; |
b8ec9a79 | 485 | break; |
b8ec9a79 JK |
486 | case N_BSS: |
487 | ms_type = mst_file_bss; | |
a66e8382 SG |
488 | section = SECT_OFF_BSS; |
489 | break; | |
490 | default: | |
491 | ms_type = mst_unknown; | |
492 | section = -1; | |
b8ec9a79 | 493 | break; |
0c4d2cc2 | 494 | } |
bd5635a1 | 495 | |
bfe2f12b | 496 | if ((ms_type == mst_file_text || ms_type == mst_text) |
9d2b8d50 JK |
497 | && address < lowest_text_address) |
498 | lowest_text_address = address; | |
499 | ||
a66e8382 | 500 | prim_record_minimal_symbol_and_info |
b8ec9a79 JK |
501 | (obsavestring (name, strlen (name), &objfile -> symbol_obstack), |
502 | address, | |
6545c6a0 | 503 | ms_type, |
a66e8382 SG |
504 | NULL, |
505 | section, | |
6545c6a0 | 506 | objfile); |
bd5635a1 RP |
507 | } |
508 | \f | |
509 | /* Scan and build partial symbols for a symbol file. | |
510 | We have been initialized by a call to dbx_symfile_init, which | |
3624c875 FF |
511 | put all the relevant info into a "struct dbx_symfile_info", |
512 | hung off the objfile structure. | |
bd5635a1 | 513 | |
2af231b8 JG |
514 | SECTION_OFFSETS contains offsets relative to which the symbols in the |
515 | various sections are (depending where the sections were actually loaded). | |
bd5635a1 RP |
516 | MAINLINE is true if we are reading the main symbol |
517 | table (as opposed to a shared lib or dynamically loaded file). */ | |
518 | ||
9bba3334 | 519 | static void |
2af231b8 | 520 | dbx_symfile_read (objfile, section_offsets, mainline) |
80d68b1d | 521 | struct objfile *objfile; |
2af231b8 | 522 | struct section_offsets *section_offsets; |
bd5635a1 RP |
523 | int mainline; /* FIXME comments above */ |
524 | { | |
80d68b1d | 525 | bfd *sym_bfd; |
bd5635a1 | 526 | int val; |
0eb22669 | 527 | struct cleanup *back_to; |
bd5635a1 | 528 | |
a66e8382 SG |
529 | val = strlen (objfile->name); |
530 | ||
531 | /* .o and .nlm files are relocatables with text, data and bss segs based at | |
532 | 0. This flag disables special (Solaris stabs-in-elf only) fixups for | |
533 | symbols with a value of 0. XXX - This is a Krock. Solaris stabs-in-elf | |
534 | should be fixed to determine pst->textlow without using this text seg of | |
535 | 0 fixup crap. */ | |
536 | ||
537 | if (strcmp (&objfile->name[val-2], ".o") == 0 | |
538 | || strcmp (&objfile->name[val-4], ".nlm") == 0) | |
539 | symfile_relocatable = 1; | |
540 | ||
bfe2f12b JL |
541 | /* This is true for Solaris (and all other systems which put stabs |
542 | in sections, hopefully, since it would be silly to do things | |
543 | differently from Solaris), and false for SunOS4 and other a.out | |
544 | file formats. */ | |
545 | block_address_function_relative = | |
546 | ((0 == strncmp (bfd_get_target (objfile->obfd), "elf", 3)) | |
547 | || (0 == strncmp (bfd_get_target (objfile->obfd), "som", 3)) | |
548 | || (0 == strncmp (bfd_get_target (objfile->obfd), "coff", 4)) | |
549 | || (0 == strncmp (bfd_get_target (objfile->obfd), "nlm", 3))); | |
550 | ||
80d68b1d | 551 | sym_bfd = objfile->obfd; |
2c7ab4ca | 552 | val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET); |
bd5635a1 | 553 | if (val < 0) |
80d68b1d | 554 | perror_with_name (objfile->name); |
bd5635a1 | 555 | |
66eeea27 | 556 | /* If we are reinitializing, or if we have never loaded syms yet, init */ |
a367db89 JK |
557 | if (mainline |
558 | || objfile->global_psymbols.size == 0 | |
559 | || objfile->static_psymbols.size == 0) | |
560 | init_psymbol_list (objfile, DBX_SYMCOUNT (objfile)); | |
66eeea27 | 561 | |
9342ecb9 JG |
562 | symbol_size = DBX_SYMBOL_SIZE (objfile); |
563 | symbol_table_offset = DBX_SYMTAB_OFFSET (objfile); | |
afe4ca15 | 564 | |
bd5635a1 | 565 | pending_blocks = 0; |
0eb22669 | 566 | back_to = make_cleanup (really_free_pendings, 0); |
bd5635a1 | 567 | |
021959e2 JG |
568 | init_minimal_symbol_collection (); |
569 | make_cleanup (discard_minimal_symbols, 0); | |
bd5635a1 RP |
570 | |
571 | /* Now that the symbol table data of the executable file are all in core, | |
572 | process them and define symbols accordingly. */ | |
573 | ||
2af231b8 | 574 | read_dbx_symtab (section_offsets, objfile, |
2b576293 C |
575 | DBX_TEXT_ADDR (objfile), |
576 | DBX_TEXT_SIZE (objfile)); | |
bd5635a1 | 577 | |
26a859ec | 578 | /* Add the dynamic symbols. */ |
5801f348 | 579 | |
26a859ec | 580 | read_dbx_dynamic_symtab (section_offsets, objfile); |
5801f348 | 581 | |
021959e2 JG |
582 | /* Install any minimal symbols that have been collected as the current |
583 | minimal symbols for this objfile. */ | |
bd5635a1 | 584 | |
80d68b1d | 585 | install_minimal_symbols (objfile); |
bd5635a1 | 586 | |
0eb22669 | 587 | do_cleanups (back_to); |
bd5635a1 RP |
588 | } |
589 | ||
9404978d MT |
590 | /* Initialize anything that needs initializing when a completely new |
591 | symbol file is specified (not just adding some symbols from another | |
592 | file, e.g. a shared library). */ | |
bd5635a1 | 593 | |
9bba3334 | 594 | static void |
ac88ca20 JG |
595 | dbx_new_init (ignore) |
596 | struct objfile *ignore; | |
bd5635a1 | 597 | { |
3416d90b | 598 | stabsread_new_init (); |
c0302457 | 599 | buildsym_new_init (); |
80d68b1d | 600 | init_header_files (); |
bd5635a1 RP |
601 | } |
602 | ||
603 | ||
604 | /* dbx_symfile_init () | |
605 | is the dbx-specific initialization routine for reading symbols. | |
80d68b1d | 606 | It is passed a struct objfile which contains, among other things, |
bd5635a1 RP |
607 | the BFD for the file whose symbols are being read, and a slot for a pointer |
608 | to "private data" which we fill with goodies. | |
609 | ||
610 | We read the string table into malloc'd space and stash a pointer to it. | |
611 | ||
612 | Since BFD doesn't know how to read debug symbols in a format-independent | |
613 | way (and may never do so...), we have to do it ourselves. We will never | |
614 | be called unless this is an a.out (or very similar) file. | |
615 | FIXME, there should be a cleaner peephole into the BFD environment here. */ | |
616 | ||
69a272c4 FF |
617 | #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */ |
618 | ||
9bba3334 | 619 | static void |
80d68b1d FF |
620 | dbx_symfile_init (objfile) |
621 | struct objfile *objfile; | |
bd5635a1 RP |
622 | { |
623 | int val; | |
80d68b1d | 624 | bfd *sym_bfd = objfile->obfd; |
bd5635a1 | 625 | char *name = bfd_get_filename (sym_bfd); |
2b576293 | 626 | asection *text_sect; |
69a272c4 | 627 | unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE]; |
bd5635a1 RP |
628 | |
629 | /* Allocate struct to keep track of the symfile */ | |
965a5c32 | 630 | objfile->sym_stab_info = (PTR) |
3624c875 | 631 | xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info)); |
bd5635a1 RP |
632 | |
633 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
bd5635a1 RP |
634 | #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd)) |
635 | #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd)) | |
040b9597 | 636 | |
bd5635a1 RP |
637 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ |
638 | ||
784fd92b | 639 | DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL; |
2b576293 C |
640 | |
641 | text_sect = bfd_get_section_by_name (sym_bfd, ".text"); | |
642 | if (!text_sect) | |
9342ecb9 | 643 | error ("Can't find .text section in symbol file"); |
2b576293 C |
644 | DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); |
645 | DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); | |
9342ecb9 | 646 | |
bf18ac80 | 647 | DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd); |
7da1e27d | 648 | DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd); |
9342ecb9 | 649 | DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET; |
3624c875 FF |
650 | |
651 | /* Read the string table and stash it away in the psymbol_obstack. It is | |
652 | only needed as long as we need to expand psymbols into full symbols, | |
653 | so when we blow away the psymbol the string table goes away as well. | |
654 | Note that gdb used to use the results of attempting to malloc the | |
655 | string table, based on the size it read, as a form of sanity check | |
656 | for botched byte swapping, on the theory that a byte swapped string | |
657 | table size would be so totally bogus that the malloc would fail. Now | |
658 | that we put in on the psymbol_obstack, we can't do this since gdb gets | |
659 | a fatal error (out of virtual memory) if the size is bogus. We can | |
69a272c4 FF |
660 | however at least check to see if the size is less than the size of |
661 | the size field itself, or larger than the size of the entire file. | |
662 | Note that all valid string tables have a size greater than zero, since | |
663 | the bytes used to hold the size are included in the count. */ | |
3624c875 | 664 | |
69a272c4 FF |
665 | if (STRING_TABLE_OFFSET == 0) |
666 | { | |
65ce5df4 JG |
667 | /* It appears that with the existing bfd code, STRING_TABLE_OFFSET |
668 | will never be zero, even when there is no string table. This | |
669 | would appear to be a bug in bfd. */ | |
69a272c4 FF |
670 | DBX_STRINGTAB_SIZE (objfile) = 0; |
671 | DBX_STRINGTAB (objfile) = NULL; | |
672 | } | |
673 | else | |
674 | { | |
2c7ab4ca | 675 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET); |
69a272c4 FF |
676 | if (val < 0) |
677 | perror_with_name (name); | |
678 | ||
679 | memset ((PTR) size_temp, 0, sizeof (size_temp)); | |
680 | val = bfd_read ((PTR) size_temp, sizeof (size_temp), 1, sym_bfd); | |
681 | if (val < 0) | |
65ce5df4 JG |
682 | { |
683 | perror_with_name (name); | |
684 | } | |
685 | else if (val == 0) | |
686 | { | |
687 | /* With the existing bfd code, STRING_TABLE_OFFSET will be set to | |
688 | EOF if there is no string table, and attempting to read the size | |
689 | from EOF will read zero bytes. */ | |
690 | DBX_STRINGTAB_SIZE (objfile) = 0; | |
691 | DBX_STRINGTAB (objfile) = NULL; | |
692 | } | |
693 | else | |
694 | { | |
695 | /* Read some data that would appear to be the string table size. | |
696 | If there really is a string table, then it is probably the right | |
697 | size. Byteswap if necessary and validate the size. Note that | |
698 | the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some | |
699 | random data that happened to be at STRING_TABLE_OFFSET, because | |
700 | bfd can't tell us there is no string table, the sanity checks may | |
701 | or may not catch this. */ | |
702 | DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp); | |
703 | ||
704 | if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp) | |
705 | || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd)) | |
706 | error ("ridiculous string table size (%d bytes).", | |
707 | DBX_STRINGTAB_SIZE (objfile)); | |
708 | ||
709 | DBX_STRINGTAB (objfile) = | |
710 | (char *) obstack_alloc (&objfile -> psymbol_obstack, | |
711 | DBX_STRINGTAB_SIZE (objfile)); | |
712 | ||
713 | /* Now read in the string table in one big gulp. */ | |
714 | ||
2c7ab4ca | 715 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET); |
65ce5df4 JG |
716 | if (val < 0) |
717 | perror_with_name (name); | |
718 | val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1, | |
719 | sym_bfd); | |
720 | if (val != DBX_STRINGTAB_SIZE (objfile)) | |
721 | perror_with_name (name); | |
722 | } | |
69a272c4 | 723 | } |
bd5635a1 | 724 | } |
80d68b1d FF |
725 | |
726 | /* Perform any local cleanups required when we are done with a particular | |
727 | objfile. I.E, we are in the process of discarding all symbol information | |
728 | for an objfile, freeing up all memory held for it, and unlinking the | |
729 | objfile struct from the global list of known objfiles. */ | |
730 | ||
731 | static void | |
732 | dbx_symfile_finish (objfile) | |
733 | struct objfile *objfile; | |
734 | { | |
965a5c32 | 735 | if (objfile->sym_stab_info != NULL) |
80d68b1d | 736 | { |
965a5c32 | 737 | mfree (objfile -> md, objfile->sym_stab_info); |
80d68b1d FF |
738 | } |
739 | free_header_files (); | |
740 | } | |
741 | ||
bd5635a1 RP |
742 | \f |
743 | /* Buffer for reading the symbol table entries. */ | |
afe4ca15 | 744 | static struct internal_nlist symbuf[4096]; |
bd5635a1 RP |
745 | static int symbuf_idx; |
746 | static int symbuf_end; | |
747 | ||
9342ecb9 JG |
748 | /* Name of last function encountered. Used in Solaris to approximate |
749 | object file boundaries. */ | |
750 | static char *last_function_name; | |
751 | ||
bd5635a1 RP |
752 | /* The address in memory of the string table of the object file we are |
753 | reading (which might not be the "main" object file, but might be a | |
a367db89 JK |
754 | shared library or some other dynamically loaded thing). This is |
755 | set by read_dbx_symtab when building psymtabs, and by | |
756 | read_ofile_symtab when building symtabs, and is used only by | |
757 | next_symbol_text. FIXME: If that is true, we don't need it when | |
758 | building psymtabs, right? */ | |
bd5635a1 RP |
759 | static char *stringtab_global; |
760 | ||
2b576293 C |
761 | /* These variables are used to control fill_symbuf when the stabs |
762 | symbols are not contiguous (as may be the case when a COFF file is | |
763 | linked using --split-by-reloc). */ | |
764 | static struct stab_section_list *symbuf_sections; | |
765 | static unsigned int symbuf_left; | |
766 | static unsigned int symbuf_read; | |
767 | ||
bd5635a1 RP |
768 | /* Refill the symbol table input buffer |
769 | and set the variables that control fetching entries from it. | |
770 | Reports an error if no data available. | |
771 | This function can read past the end of the symbol table | |
772 | (into the string table) but this does no harm. */ | |
773 | ||
7d9884b9 JG |
774 | static void |
775 | fill_symbuf (sym_bfd) | |
776 | bfd *sym_bfd; | |
bd5635a1 | 777 | { |
2b576293 C |
778 | unsigned int count; |
779 | int nbytes; | |
780 | ||
781 | if (symbuf_sections == NULL) | |
782 | count = sizeof (symbuf); | |
783 | else | |
784 | { | |
785 | if (symbuf_left <= 0) | |
786 | { | |
787 | file_ptr filepos = symbuf_sections->section->filepos; | |
788 | if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0) | |
789 | perror_with_name (bfd_get_filename (sym_bfd)); | |
790 | symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section); | |
791 | symbol_table_offset = filepos - symbuf_read; | |
792 | symbuf_sections = symbuf_sections->next; | |
793 | } | |
794 | ||
795 | count = symbuf_left; | |
796 | if (count > sizeof (symbuf)) | |
797 | count = sizeof (symbuf); | |
798 | } | |
799 | ||
800 | nbytes = bfd_read ((PTR)symbuf, count, 1, sym_bfd); | |
bd5635a1 | 801 | if (nbytes < 0) |
7d9884b9 | 802 | perror_with_name (bfd_get_filename (sym_bfd)); |
bd5635a1 RP |
803 | else if (nbytes == 0) |
804 | error ("Premature end of file reading symbol table"); | |
afe4ca15 | 805 | symbuf_end = nbytes / symbol_size; |
bd5635a1 | 806 | symbuf_idx = 0; |
2b576293 C |
807 | symbuf_left -= nbytes; |
808 | symbuf_read += nbytes; | |
bd5635a1 RP |
809 | } |
810 | ||
7d9884b9 | 811 | #define SWAP_SYMBOL(symp, abfd) \ |
bd5635a1 | 812 | { \ |
7d9884b9 | 813 | (symp)->n_strx = bfd_h_get_32(abfd, \ |
afe4ca15 | 814 | (unsigned char *)&(symp)->n_strx); \ |
7d9884b9 | 815 | (symp)->n_desc = bfd_h_get_16 (abfd, \ |
bd5635a1 | 816 | (unsigned char *)&(symp)->n_desc); \ |
7d9884b9 | 817 | (symp)->n_value = bfd_h_get_32 (abfd, \ |
bd5635a1 RP |
818 | (unsigned char *)&(symp)->n_value); \ |
819 | } | |
820 | ||
821 | /* Invariant: The symbol pointed to by symbuf_idx is the first one | |
822 | that hasn't been swapped. Swap the symbol at the same time | |
823 | that symbuf_idx is incremented. */ | |
824 | ||
825 | /* dbx allows the text of a symbol name to be continued into the | |
826 | next symbol name! When such a continuation is encountered | |
827 | (a \ at the end of the text of a name) | |
828 | call this function to get the continuation. */ | |
829 | ||
021959e2 | 830 | static char * |
aab77d5f | 831 | dbx_next_symbol_text () |
bd5635a1 RP |
832 | { |
833 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 834 | fill_symbuf (symfile_bfd); |
bd5635a1 | 835 | symnum++; |
7d9884b9 | 836 | SWAP_SYMBOL(&symbuf[symbuf_idx], symfile_bfd); |
9342ecb9 JG |
837 | return symbuf[symbuf_idx++].n_strx + stringtab_global |
838 | + file_string_table_offset; | |
bd5635a1 RP |
839 | } |
840 | \f | |
bd5635a1 RP |
841 | /* Initialize the list of bincls to contain none and have some |
842 | allocated. */ | |
843 | ||
844 | static void | |
021959e2 | 845 | init_bincl_list (number, objfile) |
bd5635a1 | 846 | int number; |
021959e2 | 847 | struct objfile *objfile; |
bd5635a1 RP |
848 | { |
849 | bincls_allocated = number; | |
850 | next_bincl = bincl_list = (struct header_file_location *) | |
318bf84f | 851 | xmmalloc (objfile -> md, bincls_allocated * sizeof(struct header_file_location)); |
bd5635a1 RP |
852 | } |
853 | ||
854 | /* Add a bincl to the list. */ | |
855 | ||
856 | static void | |
857 | add_bincl_to_list (pst, name, instance) | |
858 | struct partial_symtab *pst; | |
859 | char *name; | |
860 | int instance; | |
861 | { | |
862 | if (next_bincl >= bincl_list + bincls_allocated) | |
863 | { | |
864 | int offset = next_bincl - bincl_list; | |
865 | bincls_allocated *= 2; | |
866 | bincl_list = (struct header_file_location *) | |
318bf84f | 867 | xmrealloc (pst->objfile->md, (char *)bincl_list, |
bd5635a1 RP |
868 | bincls_allocated * sizeof (struct header_file_location)); |
869 | next_bincl = bincl_list + offset; | |
870 | } | |
871 | next_bincl->pst = pst; | |
872 | next_bincl->instance = instance; | |
873 | next_bincl++->name = name; | |
874 | } | |
875 | ||
876 | /* Given a name, value pair, find the corresponding | |
877 | bincl in the list. Return the partial symtab associated | |
878 | with that header_file_location. */ | |
879 | ||
9bba3334 | 880 | static struct partial_symtab * |
bd5635a1 RP |
881 | find_corresponding_bincl_psymtab (name, instance) |
882 | char *name; | |
883 | int instance; | |
884 | { | |
885 | struct header_file_location *bincl; | |
886 | ||
887 | for (bincl = bincl_list; bincl < next_bincl; bincl++) | |
888 | if (bincl->instance == instance | |
2e4964ad | 889 | && STREQ (name, bincl->name)) |
bd5635a1 RP |
890 | return bincl->pst; |
891 | ||
26a859ec | 892 | complain (&repeated_header_complaint, name, symnum); |
bd5635a1 RP |
893 | return (struct partial_symtab *) 0; |
894 | } | |
895 | ||
896 | /* Free the storage allocated for the bincl list. */ | |
897 | ||
898 | static void | |
021959e2 JG |
899 | free_bincl_list (objfile) |
900 | struct objfile *objfile; | |
bd5635a1 | 901 | { |
ac88ca20 | 902 | mfree (objfile -> md, (PTR)bincl_list); |
bd5635a1 RP |
903 | bincls_allocated = 0; |
904 | } | |
905 | ||
5801f348 JK |
906 | /* Scan a SunOs dynamic symbol table for symbols of interest and |
907 | add them to the minimal symbol table. */ | |
908 | ||
909 | static void | |
910 | read_dbx_dynamic_symtab (section_offsets, objfile) | |
911 | struct section_offsets *section_offsets; | |
912 | struct objfile *objfile; | |
913 | { | |
914 | bfd *abfd = objfile->obfd; | |
192b64e7 | 915 | struct cleanup *back_to; |
5801f348 | 916 | int counter; |
192b64e7 ILT |
917 | long dynsym_size; |
918 | long dynsym_count; | |
919 | asymbol **dynsyms; | |
920 | asymbol **symptr; | |
921 | arelent **relptr; | |
922 | long dynrel_size; | |
923 | long dynrel_count; | |
924 | arelent **dynrels; | |
5801f348 | 925 | CORE_ADDR sym_value; |
f69ecb9c | 926 | char *name; |
5801f348 JK |
927 | |
928 | /* Check that the symbol file has dynamic symbols that we know about. | |
929 | bfd_arch_unknown can happen if we are reading a sun3 symbol file | |
930 | on a sun4 host (and vice versa) and bfd is not configured | |
931 | --with-target=all. This would trigger an assertion in bfd/sunos.c, | |
932 | so we ignore the dynamic symbols in this case. */ | |
933 | if (bfd_get_flavour (abfd) != bfd_target_aout_flavour | |
934 | || (bfd_get_file_flags (abfd) & DYNAMIC) == 0 | |
192b64e7 | 935 | || bfd_get_arch (abfd) == bfd_arch_unknown) |
5801f348 JK |
936 | return; |
937 | ||
192b64e7 ILT |
938 | dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd); |
939 | if (dynsym_size < 0) | |
5801f348 JK |
940 | return; |
941 | ||
192b64e7 ILT |
942 | dynsyms = (asymbol **) xmalloc (dynsym_size); |
943 | back_to = make_cleanup (free, dynsyms); | |
944 | ||
945 | dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms); | |
946 | if (dynsym_count < 0) | |
947 | { | |
948 | do_cleanups (back_to); | |
949 | return; | |
950 | } | |
951 | ||
5801f348 JK |
952 | /* Enter dynamic symbols into the minimal symbol table |
953 | if this is a stripped executable. */ | |
954 | if (bfd_get_symcount (abfd) <= 0) | |
955 | { | |
192b64e7 ILT |
956 | symptr = dynsyms; |
957 | for (counter = 0; counter < dynsym_count; counter++, symptr++) | |
5801f348 | 958 | { |
192b64e7 ILT |
959 | asymbol *sym = *symptr; |
960 | asection *sec; | |
961 | int type; | |
962 | ||
192b64e7 | 963 | sec = bfd_get_section (sym); |
be78eb1a PS |
964 | |
965 | /* BFD symbols are section relative. */ | |
0683ac4b PS |
966 | sym_value = sym->value + sec->vma; |
967 | ||
192b64e7 | 968 | if (bfd_get_section_flags (abfd, sec) & SEC_CODE) |
5801f348 | 969 | { |
192b64e7 ILT |
970 | sym_value += ANOFFSET (section_offsets, SECT_OFF_TEXT); |
971 | type = N_TEXT; | |
5801f348 | 972 | } |
192b64e7 ILT |
973 | else if (bfd_get_section_flags (abfd, sec) & SEC_DATA) |
974 | { | |
975 | sym_value += ANOFFSET (section_offsets, SECT_OFF_DATA); | |
976 | type = N_DATA; | |
977 | } | |
978 | else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
5801f348 | 979 | { |
192b64e7 ILT |
980 | sym_value += ANOFFSET (section_offsets, SECT_OFF_BSS); |
981 | type = N_BSS; | |
5801f348 JK |
982 | } |
983 | else | |
192b64e7 ILT |
984 | continue; |
985 | ||
986 | if (sym->flags & BSF_GLOBAL) | |
987 | type |= N_EXT; | |
988 | ||
b9e58503 PS |
989 | record_minimal_symbol ((char *) bfd_asymbol_name (sym), sym_value, |
990 | type, objfile); | |
5801f348 JK |
991 | } |
992 | } | |
993 | ||
994 | /* Symbols from shared libraries have a dynamic relocation entry | |
995 | that points to the associated slot in the procedure linkage table. | |
996 | We make a mininal symbol table entry with type mst_solib_trampoline | |
997 | at the address in the procedure linkage table. */ | |
192b64e7 ILT |
998 | dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd); |
999 | if (dynrel_size < 0) | |
1000 | { | |
1001 | do_cleanups (back_to); | |
1002 | return; | |
1003 | } | |
1004 | ||
1005 | dynrels = (arelent **) xmalloc (dynrel_size); | |
1006 | make_cleanup (free, dynrels); | |
5801f348 | 1007 | |
192b64e7 ILT |
1008 | dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms); |
1009 | if (dynrel_count < 0) | |
1010 | { | |
1011 | do_cleanups (back_to); | |
1012 | return; | |
1013 | } | |
5801f348 | 1014 | |
192b64e7 | 1015 | for (counter = 0, relptr = dynrels; |
5801f348 | 1016 | counter < dynrel_count; |
192b64e7 | 1017 | counter++, relptr++) |
5801f348 | 1018 | { |
0683ac4b | 1019 | arelent *rel = *relptr; |
26a859ec PS |
1020 | CORE_ADDR address = |
1021 | rel->address + ANOFFSET (section_offsets, SECT_OFF_DATA); | |
5801f348 | 1022 | |
0683ac4b PS |
1023 | switch (bfd_get_arch (abfd)) |
1024 | { | |
1025 | case bfd_arch_sparc: | |
1026 | if (rel->howto->type != RELOC_JMP_SLOT) | |
1027 | continue; | |
1028 | break; | |
1029 | case bfd_arch_m68k: | |
1030 | /* `16' is the type BFD produces for a jump table relocation. */ | |
1031 | if (rel->howto->type != 16) | |
1032 | continue; | |
5801f348 | 1033 | |
0683ac4b PS |
1034 | /* Adjust address in the jump table to point to |
1035 | the start of the bsr instruction. */ | |
1036 | address -= 2; | |
1037 | break; | |
1038 | default: | |
1039 | continue; | |
1040 | } | |
5801f348 | 1041 | |
b9e58503 | 1042 | name = (char *) bfd_asymbol_name (*rel->sym_ptr_ptr); |
f69ecb9c JK |
1043 | prim_record_minimal_symbol |
1044 | (obsavestring (name, strlen (name), &objfile -> symbol_obstack), | |
1045 | address, | |
1046 | mst_solib_trampoline, | |
1047 | objfile); | |
5801f348 | 1048 | } |
192b64e7 ILT |
1049 | |
1050 | do_cleanups (back_to); | |
5801f348 JK |
1051 | } |
1052 | ||
bd5635a1 RP |
1053 | /* Given pointers to an a.out symbol table in core containing dbx |
1054 | style data, setup partial_symtab's describing each source file for | |
3624c875 FF |
1055 | which debugging information is available. |
1056 | SYMFILE_NAME is the name of the file we are reading from | |
2af231b8 JG |
1057 | and SECTION_OFFSETS is the set of offsets for the various sections |
1058 | of the file (a set of zeros if the mainline program). */ | |
bd5635a1 RP |
1059 | |
1060 | static void | |
2af231b8 JG |
1061 | read_dbx_symtab (section_offsets, objfile, text_addr, text_size) |
1062 | struct section_offsets *section_offsets; | |
7d9884b9 | 1063 | struct objfile *objfile; |
bd5635a1 RP |
1064 | CORE_ADDR text_addr; |
1065 | int text_size; | |
1066 | { | |
ac88ca20 | 1067 | register struct internal_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch */ |
bd5635a1 | 1068 | register char *namestring; |
bd5635a1 RP |
1069 | int nsl; |
1070 | int past_first_source_file = 0; | |
1071 | CORE_ADDR last_o_file_start = 0; | |
0eb22669 | 1072 | struct cleanup *back_to; |
7d9884b9 | 1073 | bfd *abfd; |
bd5635a1 | 1074 | |
bd5635a1 RP |
1075 | /* Current partial symtab */ |
1076 | struct partial_symtab *pst; | |
1077 | ||
1078 | /* List of current psymtab's include files */ | |
1079 | char **psymtab_include_list; | |
1080 | int includes_allocated; | |
1081 | int includes_used; | |
1082 | ||
1083 | /* Index within current psymtab dependency list */ | |
1084 | struct partial_symtab **dependency_list; | |
1085 | int dependencies_used, dependencies_allocated; | |
1086 | ||
9342ecb9 JG |
1087 | /* FIXME. We probably want to change stringtab_global rather than add this |
1088 | while processing every symbol entry. FIXME. */ | |
1089 | file_string_table_offset = 0; | |
1090 | next_file_string_table_offset = 0; | |
1091 | ||
3624c875 | 1092 | stringtab_global = DBX_STRINGTAB (objfile); |
bd5635a1 RP |
1093 | |
1094 | pst = (struct partial_symtab *) 0; | |
1095 | ||
1096 | includes_allocated = 30; | |
1097 | includes_used = 0; | |
1098 | psymtab_include_list = (char **) alloca (includes_allocated * | |
1099 | sizeof (char *)); | |
1100 | ||
1101 | dependencies_allocated = 30; | |
1102 | dependencies_used = 0; | |
1103 | dependency_list = | |
1104 | (struct partial_symtab **) alloca (dependencies_allocated * | |
1105 | sizeof (struct partial_symtab *)); | |
1106 | ||
bd5635a1 | 1107 | /* Init bincl list */ |
021959e2 | 1108 | init_bincl_list (20, objfile); |
0eb22669 | 1109 | back_to = make_cleanup (free_bincl_list, objfile); |
bd5635a1 | 1110 | |
3416d90b | 1111 | last_source_file = NULL; |
bd5635a1 | 1112 | |
9d2b8d50 | 1113 | lowest_text_address = (CORE_ADDR)-1; |
bd5635a1 | 1114 | |
7d9884b9 JG |
1115 | symfile_bfd = objfile->obfd; /* For next_text_symbol */ |
1116 | abfd = objfile->obfd; | |
bd5635a1 | 1117 | symbuf_end = symbuf_idx = 0; |
aab77d5f | 1118 | next_symbol_text_func = dbx_next_symbol_text; |
bd5635a1 | 1119 | |
3624c875 | 1120 | for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++) |
bd5635a1 RP |
1121 | { |
1122 | /* Get the symbol for this run and pull out some info */ | |
1123 | QUIT; /* allow this to be interruptable */ | |
1124 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 1125 | fill_symbuf (abfd); |
bd5635a1 RP |
1126 | bufp = &symbuf[symbuf_idx++]; |
1127 | ||
1128 | /* | |
1129 | * Special case to speed up readin. | |
1130 | */ | |
1131 | if (bufp->n_type == (unsigned char)N_SLINE) continue; | |
1132 | ||
7d9884b9 | 1133 | SWAP_SYMBOL (bufp, abfd); |
bd5635a1 RP |
1134 | |
1135 | /* Ok. There is a lot of code duplicated in the rest of this | |
1136 | switch statement (for efficiency reasons). Since I don't | |
1137 | like duplicating code, I will do my penance here, and | |
1138 | describe the code which is duplicated: | |
1139 | ||
1140 | *) The assignment to namestring. | |
1141 | *) The call to strchr. | |
1142 | *) The addition of a partial symbol the the two partial | |
1143 | symbol lists. This last is a large section of code, so | |
1144 | I've imbedded it in the following macro. | |
1145 | */ | |
1146 | ||
1147 | /* Set namestring based on bufp. If the string table index is invalid, | |
1148 | give a fake name, and print a single error message per symbol file read, | |
1149 | rather than abort the symbol reading or flood the user with messages. */ | |
9342ecb9 JG |
1150 | |
1151 | /*FIXME: Too many adds and indirections in here for the inner loop. */ | |
bd5635a1 | 1152 | #define SET_NAMESTRING()\ |
9342ecb9 JG |
1153 | if (((unsigned)bufp->n_strx + file_string_table_offset) >= \ |
1154 | DBX_STRINGTAB_SIZE (objfile)) { \ | |
51b80b00 | 1155 | complain (&string_table_offset_complaint, symnum); \ |
5801f348 | 1156 | namestring = "<bad string table offset>"; \ |
bd5635a1 | 1157 | } else \ |
9342ecb9 JG |
1158 | namestring = bufp->n_strx + file_string_table_offset + \ |
1159 | DBX_STRINGTAB (objfile) | |
bd5635a1 | 1160 | |
7e258d18 PB |
1161 | #define CUR_SYMBOL_TYPE bufp->n_type |
1162 | #define CUR_SYMBOL_VALUE bufp->n_value | |
1163 | #define DBXREAD_ONLY | |
2af231b8 JG |
1164 | #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\ |
1165 | start_psymtab(ofile, secoff, fname, low, symoff, global_syms, static_syms) | |
7e258d18 PB |
1166 | #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\ |
1167 | end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) | |
aab77d5f | 1168 | |
7e258d18 | 1169 | #include "partial-stab.h" |
bd5635a1 RP |
1170 | } |
1171 | ||
1172 | /* If there's stuff to be cleaned up, clean it up. */ | |
3624c875 | 1173 | if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */ |
9342ecb9 JG |
1174 | /*FIXME, does this have a bug at start address 0? */ |
1175 | && last_o_file_start | |
3624c875 FF |
1176 | && objfile -> ei.entry_point < bufp->n_value |
1177 | && objfile -> ei.entry_point >= last_o_file_start) | |
bd5635a1 | 1178 | { |
3624c875 FF |
1179 | objfile -> ei.entry_file_lowpc = last_o_file_start; |
1180 | objfile -> ei.entry_file_highpc = bufp->n_value; | |
bd5635a1 RP |
1181 | } |
1182 | ||
1183 | if (pst) | |
1184 | { | |
1185 | end_psymtab (pst, psymtab_include_list, includes_used, | |
9d2b8d50 JK |
1186 | symnum * symbol_size, |
1187 | (lowest_text_address == (CORE_ADDR)-1 | |
2fe3b329 PS |
1188 | ? (text_addr + section_offsets->offsets[SECT_OFF_TEXT]) |
1189 | : lowest_text_address) | |
9d2b8d50 | 1190 | + text_size, |
7e258d18 | 1191 | dependency_list, dependencies_used); |
bd5635a1 RP |
1192 | } |
1193 | ||
0eb22669 | 1194 | do_cleanups (back_to); |
bd5635a1 RP |
1195 | } |
1196 | ||
4a35d6e9 FF |
1197 | /* Allocate and partially fill a partial symtab. It will be |
1198 | completely filled at the end of the symbol list. | |
1199 | ||
1200 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
1201 | is the address relative to which its symbols are (incremental) or 0 | |
1202 | (normal). */ | |
1203 | ||
bd5635a1 | 1204 | |
7e258d18 | 1205 | struct partial_symtab * |
2af231b8 | 1206 | start_psymtab (objfile, section_offsets, |
bd5635a1 | 1207 | filename, textlow, ldsymoff, global_syms, static_syms) |
7d9884b9 | 1208 | struct objfile *objfile; |
2af231b8 | 1209 | struct section_offsets *section_offsets; |
bd5635a1 RP |
1210 | char *filename; |
1211 | CORE_ADDR textlow; | |
1212 | int ldsymoff; | |
1213 | struct partial_symbol *global_syms; | |
1214 | struct partial_symbol *static_syms; | |
1215 | { | |
1216 | struct partial_symtab *result = | |
2af231b8 | 1217 | start_psymtab_common(objfile, section_offsets, |
021959e2 | 1218 | filename, textlow, global_syms, static_syms); |
bd5635a1 | 1219 | |
021959e2 JG |
1220 | result->read_symtab_private = (char *) |
1221 | obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc)); | |
1222 | LDSYMOFF(result) = ldsymoff; | |
bd5635a1 | 1223 | result->read_symtab = dbx_psymtab_to_symtab; |
9342ecb9 JG |
1224 | SYMBOL_SIZE(result) = symbol_size; |
1225 | SYMBOL_OFFSET(result) = symbol_table_offset; | |
1226 | STRING_OFFSET(result) = string_table_offset; | |
1227 | FILE_STRING_OFFSET(result) = file_string_table_offset; | |
bd5635a1 | 1228 | |
2af231b8 JG |
1229 | /* If we're handling an ELF file, drag some section-relocation info |
1230 | for this source file out of the ELF symbol table, to compensate for | |
1231 | Sun brain death. This replaces the section_offsets in this psymtab, | |
1232 | if successful. */ | |
1233 | elfstab_offset_sections (objfile, result); | |
1234 | ||
2e4964ad FF |
1235 | /* Deduce the source language from the filename for this psymtab. */ |
1236 | psymtab_language = deduce_language_from_filename (filename); | |
1237 | ||
bd5635a1 RP |
1238 | return result; |
1239 | } | |
1240 | ||
cbba020f PS |
1241 | /* Close off the current usage of PST. |
1242 | Returns PST or NULL if the partial symtab was empty and thrown away. | |
bd5635a1 | 1243 | |
cbba020f | 1244 | FIXME: List variables and peculiarities of same. */ |
bd5635a1 | 1245 | |
cbba020f | 1246 | struct partial_symtab * |
bd5635a1 | 1247 | end_psymtab (pst, include_list, num_includes, capping_symbol_offset, |
7e258d18 | 1248 | capping_text, dependency_list, number_dependencies) |
bd5635a1 RP |
1249 | struct partial_symtab *pst; |
1250 | char **include_list; | |
1251 | int num_includes; | |
1252 | int capping_symbol_offset; | |
1253 | CORE_ADDR capping_text; | |
1254 | struct partial_symtab **dependency_list; | |
1255 | int number_dependencies; | |
bd5635a1 RP |
1256 | { |
1257 | int i; | |
021959e2 | 1258 | struct objfile *objfile = pst -> objfile; |
bd5635a1 | 1259 | |
7e258d18 PB |
1260 | if (capping_symbol_offset != -1) |
1261 | LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst); | |
bd5635a1 RP |
1262 | pst->texthigh = capping_text; |
1263 | ||
b9e58503 | 1264 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING |
9342ecb9 JG |
1265 | /* Under Solaris, the N_SO symbols always have a value of 0, |
1266 | instead of the usual address of the .o file. Therefore, | |
1267 | we have to do some tricks to fill in texthigh and textlow. | |
1268 | The first trick is in partial-stab.h: if we see a static | |
1269 | or global function, and the textlow for the current pst | |
1270 | is still 0, then we use that function's address for | |
b9e58503 | 1271 | the textlow of the pst. */ |
9342ecb9 | 1272 | |
b9e58503 | 1273 | /* Now, to fill in texthigh, we remember the last function seen |
9342ecb9 JG |
1274 | in the .o file (also in partial-stab.h). Also, there's a hack in |
1275 | bfd/elf.c and gdb/elfread.c to pass the ELF st_size field | |
1276 | to here via the misc_info field. Therefore, we can fill in | |
1277 | a reliable texthigh by taking the address plus size of the | |
b9e58503 | 1278 | last function in the file. */ |
9342ecb9 | 1279 | |
bcbf9559 | 1280 | if (pst->texthigh == 0 && last_function_name) { |
9342ecb9 JG |
1281 | char *p; |
1282 | int n; | |
1283 | struct minimal_symbol *minsym; | |
1284 | ||
1285 | p = strchr (last_function_name, ':'); | |
1286 | if (p == NULL) | |
1287 | p = last_function_name; | |
1288 | n = p - last_function_name; | |
1289 | p = alloca (n + 1); | |
1290 | strncpy (p, last_function_name, n); | |
1291 | p[n] = 0; | |
1292 | ||
b9e58503 | 1293 | minsym = lookup_minimal_symbol (p, pst->filename, objfile); |
9342ecb9 | 1294 | |
b9e58503 | 1295 | if (minsym) |
2e4964ad | 1296 | pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + |
5573d7d4 | 1297 | (long) MSYMBOL_INFO (minsym); |
b9e58503 | 1298 | |
9342ecb9 JG |
1299 | last_function_name = NULL; |
1300 | } | |
1301 | ||
1302 | /* this test will be true if the last .o file is only data */ | |
1303 | if (pst->textlow == 0) | |
6545c6a0 JK |
1304 | /* This loses if the text section really starts at address zero |
1305 | (generally true when we are debugging a .o file, for example). | |
b9e58503 | 1306 | That is why this whole thing is inside SOFUN_ADDRESS_MAYBE_MISSING. */ |
9342ecb9 JG |
1307 | pst->textlow = pst->texthigh; |
1308 | ||
bcbf9559 JG |
1309 | /* If we know our own starting text address, then walk through all other |
1310 | psymtabs for this objfile, and if any didn't know their ending text | |
1311 | address, set it to our starting address. Take care to not set our | |
1312 | own ending address to our starting address, nor to set addresses on | |
1313 | `dependency' files that have both textlow and texthigh zero. */ | |
9342ecb9 | 1314 | if (pst->textlow) { |
bfe2f12b JL |
1315 | struct partial_symtab *p1; |
1316 | ||
9342ecb9 | 1317 | ALL_OBJFILE_PSYMTABS (objfile, p1) { |
bcbf9559 | 1318 | if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) { |
9342ecb9 JG |
1319 | p1->texthigh = pst->textlow; |
1320 | /* if this file has only data, then make textlow match texthigh */ | |
1321 | if (p1->textlow == 0) | |
1322 | p1->textlow = p1->texthigh; | |
1323 | } | |
1324 | } | |
1325 | } | |
1326 | ||
1327 | /* End of kludge for patching Solaris textlow and texthigh. */ | |
b9e58503 | 1328 | #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */ |
9342ecb9 | 1329 | |
bd5635a1 | 1330 | pst->n_global_syms = |
021959e2 | 1331 | objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset); |
bd5635a1 | 1332 | pst->n_static_syms = |
021959e2 | 1333 | objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset); |
bd5635a1 RP |
1334 | |
1335 | pst->number_of_dependencies = number_dependencies; | |
1336 | if (number_dependencies) | |
1337 | { | |
1338 | pst->dependencies = (struct partial_symtab **) | |
021959e2 | 1339 | obstack_alloc (&objfile->psymbol_obstack, |
bd5635a1 | 1340 | number_dependencies * sizeof (struct partial_symtab *)); |
7e258d18 | 1341 | memcpy (pst->dependencies, dependency_list, |
bd5635a1 RP |
1342 | number_dependencies * sizeof (struct partial_symtab *)); |
1343 | } | |
1344 | else | |
1345 | pst->dependencies = 0; | |
1346 | ||
1347 | for (i = 0; i < num_includes; i++) | |
1348 | { | |
bd5635a1 | 1349 | struct partial_symtab *subpst = |
021959e2 | 1350 | allocate_psymtab (include_list[i], objfile); |
7d9884b9 | 1351 | |
2af231b8 | 1352 | subpst->section_offsets = pst->section_offsets; |
021959e2 JG |
1353 | subpst->read_symtab_private = |
1354 | (char *) obstack_alloc (&objfile->psymbol_obstack, | |
1355 | sizeof (struct symloc)); | |
4a35d6e9 FF |
1356 | LDSYMOFF(subpst) = |
1357 | LDSYMLEN(subpst) = | |
bd5635a1 RP |
1358 | subpst->textlow = |
1359 | subpst->texthigh = 0; | |
1360 | ||
3f83182d JG |
1361 | /* We could save slight bits of space by only making one of these, |
1362 | shared by the entire set of include files. FIXME-someday. */ | |
bd5635a1 | 1363 | subpst->dependencies = (struct partial_symtab **) |
021959e2 | 1364 | obstack_alloc (&objfile->psymbol_obstack, |
bd5635a1 RP |
1365 | sizeof (struct partial_symtab *)); |
1366 | subpst->dependencies[0] = pst; | |
1367 | subpst->number_of_dependencies = 1; | |
1368 | ||
1369 | subpst->globals_offset = | |
1370 | subpst->n_global_syms = | |
1371 | subpst->statics_offset = | |
1372 | subpst->n_static_syms = 0; | |
1373 | ||
1374 | subpst->readin = 0; | |
9a822037 | 1375 | subpst->symtab = 0; |
2707b48a | 1376 | subpst->read_symtab = pst->read_symtab; |
bd5635a1 RP |
1377 | } |
1378 | ||
021959e2 | 1379 | sort_pst_symbols (pst); |
bd5635a1 | 1380 | |
f9623881 JG |
1381 | /* If there is already a psymtab or symtab for a file of this name, remove it. |
1382 | (If there is a symtab, more drastic things also happen.) | |
1383 | This happens in VxWorks. */ | |
1384 | free_named_symtabs (pst->filename); | |
1385 | ||
7d9884b9 | 1386 | if (num_includes == 0 |
5801f348 JK |
1387 | && number_dependencies == 0 |
1388 | && pst->n_global_syms == 0 | |
1389 | && pst->n_static_syms == 0) | |
1390 | { | |
1391 | /* Throw away this psymtab, it's empty. We can't deallocate it, since | |
1392 | it is on the obstack, but we can forget to chain it on the list. */ | |
1393 | /* Empty psymtabs happen as a result of header files which don't have | |
1394 | any symbols in them. There can be a lot of them. But this check | |
1395 | is wrong, in that a psymtab with N_SLINE entries but nothing else | |
1396 | is not empty, but we don't realize that. Fixing that without slowing | |
1397 | things down might be tricky. */ | |
1398 | struct partial_symtab *prev_pst; | |
1399 | ||
1400 | /* First, snip it out of the psymtab chain */ | |
1401 | ||
1402 | if (pst->objfile->psymtabs == pst) | |
1403 | pst->objfile->psymtabs = pst->next; | |
1404 | else | |
1405 | for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next) | |
1406 | if (prev_pst->next == pst) | |
1407 | prev_pst->next = pst->next; | |
318bf84f | 1408 | |
5801f348 | 1409 | /* Next, put it on a free list for recycling */ |
318bf84f | 1410 | |
5801f348 JK |
1411 | pst->next = pst->objfile->free_psymtabs; |
1412 | pst->objfile->free_psymtabs = pst; | |
cbba020f | 1413 | |
5801f348 JK |
1414 | /* Indicate that psymtab was thrown away. */ |
1415 | pst = (struct partial_symtab *)NULL; | |
1416 | } | |
cbba020f | 1417 | return pst; |
bd5635a1 RP |
1418 | } |
1419 | \f | |
1420 | static void | |
4c07f28d | 1421 | dbx_psymtab_to_symtab_1 (pst) |
bd5635a1 | 1422 | struct partial_symtab *pst; |
bd5635a1 RP |
1423 | { |
1424 | struct cleanup *old_chain; | |
1425 | int i; | |
1426 | ||
1427 | if (!pst) | |
1428 | return; | |
1429 | ||
1430 | if (pst->readin) | |
1431 | { | |
199b2450 | 1432 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", |
bd5635a1 RP |
1433 | pst->filename); |
1434 | return; | |
1435 | } | |
1436 | ||
afe4ca15 | 1437 | /* Read in all partial symtabs on which this one is dependent */ |
bd5635a1 RP |
1438 | for (i = 0; i < pst->number_of_dependencies; i++) |
1439 | if (!pst->dependencies[i]->readin) | |
1440 | { | |
1441 | /* Inform about additional files that need to be read in. */ | |
1442 | if (info_verbose) | |
1443 | { | |
199b2450 | 1444 | fputs_filtered (" ", gdb_stdout); |
bd5635a1 | 1445 | wrap_here (""); |
199b2450 | 1446 | fputs_filtered ("and ", gdb_stdout); |
bd5635a1 RP |
1447 | wrap_here (""); |
1448 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
1449 | wrap_here (""); /* Flush output */ | |
199b2450 | 1450 | gdb_flush (gdb_stdout); |
bd5635a1 | 1451 | } |
4c07f28d | 1452 | dbx_psymtab_to_symtab_1 (pst->dependencies[i]); |
bd5635a1 RP |
1453 | } |
1454 | ||
4a35d6e9 | 1455 | if (LDSYMLEN(pst)) /* Otherwise it's a dummy */ |
bd5635a1 RP |
1456 | { |
1457 | /* Init stuff necessary for reading in symbols */ | |
3416d90b | 1458 | stabsread_init (); |
c0302457 | 1459 | buildsym_init (); |
bd5635a1 | 1460 | old_chain = make_cleanup (really_free_pendings, 0); |
9342ecb9 | 1461 | file_string_table_offset = FILE_STRING_OFFSET (pst); |
4c07f28d FF |
1462 | symbol_size = SYMBOL_SIZE (pst); |
1463 | ||
1464 | /* Read in this file's symbols */ | |
2c7ab4ca | 1465 | bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET); |
574dac8e | 1466 | read_ofile_symtab (pst); |
9404978d | 1467 | sort_symtab_syms (pst->symtab); |
bd5635a1 RP |
1468 | |
1469 | do_cleanups (old_chain); | |
1470 | } | |
1471 | ||
1472 | pst->readin = 1; | |
1473 | } | |
1474 | ||
ac88ca20 JG |
1475 | /* Read in all of the symbols for a given psymtab for real. |
1476 | Be verbose about it if the user wants that. */ | |
1477 | ||
bd5635a1 RP |
1478 | static void |
1479 | dbx_psymtab_to_symtab (pst) | |
1480 | struct partial_symtab *pst; | |
1481 | { | |
bd5635a1 | 1482 | bfd *sym_bfd; |
bd5635a1 RP |
1483 | |
1484 | if (!pst) | |
1485 | return; | |
1486 | ||
1487 | if (pst->readin) | |
1488 | { | |
199b2450 | 1489 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", |
bd5635a1 RP |
1490 | pst->filename); |
1491 | return; | |
1492 | } | |
1493 | ||
4a35d6e9 | 1494 | if (LDSYMLEN(pst) || pst->number_of_dependencies) |
bd5635a1 RP |
1495 | { |
1496 | /* Print the message now, before reading the string table, | |
1497 | to avoid disconcerting pauses. */ | |
1498 | if (info_verbose) | |
1499 | { | |
1500 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
199b2450 | 1501 | gdb_flush (gdb_stdout); |
bd5635a1 RP |
1502 | } |
1503 | ||
7d9884b9 | 1504 | sym_bfd = pst->objfile->obfd; |
bd5635a1 | 1505 | |
aab77d5f PB |
1506 | next_symbol_text_func = dbx_next_symbol_text; |
1507 | ||
4c07f28d | 1508 | dbx_psymtab_to_symtab_1 (pst); |
bd5635a1 RP |
1509 | |
1510 | /* Match with global symbols. This only needs to be done once, | |
1511 | after all of the symtabs and dependencies have been read in. */ | |
021959e2 | 1512 | scan_file_globals (pst->objfile); |
bd5635a1 | 1513 | |
bd5635a1 RP |
1514 | /* Finish up the debug error message. */ |
1515 | if (info_verbose) | |
1516 | printf_filtered ("done.\n"); | |
1517 | } | |
1518 | } | |
1519 | ||
574dac8e | 1520 | /* Read in a defined section of a specific object file's symbols. */ |
9342ecb9 | 1521 | |
574dac8e JK |
1522 | static void |
1523 | read_ofile_symtab (pst) | |
1524 | struct partial_symtab *pst; | |
bd5635a1 RP |
1525 | { |
1526 | register char *namestring; | |
7d9884b9 | 1527 | register struct internal_nlist *bufp; |
bd5635a1 | 1528 | unsigned char type; |
afe4ca15 | 1529 | unsigned max_symnum; |
7d9884b9 | 1530 | register bfd *abfd; |
574dac8e JK |
1531 | struct objfile *objfile; |
1532 | int sym_offset; /* Offset to start of symbols to read */ | |
1533 | int sym_size; /* Size of symbols to read */ | |
1534 | CORE_ADDR text_offset; /* Start of text segment for symbols */ | |
1535 | int text_size; /* Size of text segment for symbols */ | |
1536 | struct section_offsets *section_offsets; | |
1537 | ||
1538 | objfile = pst->objfile; | |
1539 | sym_offset = LDSYMOFF(pst); | |
1540 | sym_size = LDSYMLEN(pst); | |
1541 | text_offset = pst->textlow; | |
1542 | text_size = pst->texthigh - pst->textlow; | |
1543 | section_offsets = pst->section_offsets; | |
7d9884b9 | 1544 | |
021959e2 | 1545 | current_objfile = objfile; |
3416d90b | 1546 | subfile_stack = NULL; |
bd5635a1 | 1547 | |
3624c875 | 1548 | stringtab_global = DBX_STRINGTAB (objfile); |
3416d90b | 1549 | last_source_file = NULL; |
bd5635a1 | 1550 | |
7d9884b9 JG |
1551 | abfd = objfile->obfd; |
1552 | symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */ | |
bd5635a1 RP |
1553 | symbuf_end = symbuf_idx = 0; |
1554 | ||
1555 | /* It is necessary to actually read one symbol *before* the start | |
1556 | of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL | |
1557 | occurs before the N_SO symbol. | |
1558 | ||
1559 | Detecting this in read_dbx_symtab | |
1560 | would slow down initial readin, so we look for it here instead. */ | |
9342ecb9 | 1561 | if (!processing_acc_compilation && sym_offset >= (int)symbol_size) |
bd5635a1 | 1562 | { |
2c7ab4ca | 1563 | bfd_seek (symfile_bfd, sym_offset - symbol_size, SEEK_CUR); |
7d9884b9 | 1564 | fill_symbuf (abfd); |
bd5635a1 | 1565 | bufp = &symbuf[symbuf_idx++]; |
7d9884b9 | 1566 | SWAP_SYMBOL (bufp, abfd); |
bd5635a1 | 1567 | |
afe4ca15 | 1568 | SET_NAMESTRING (); |
bd5635a1 | 1569 | |
1aed6766 SG |
1570 | processing_gcc_compilation = 0; |
1571 | if (bufp->n_type == N_TEXT) | |
1572 | { | |
db2302cb PS |
1573 | const char *tempstring = namestring; |
1574 | ||
2e4964ad | 1575 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) |
1aed6766 | 1576 | processing_gcc_compilation = 1; |
2e4964ad | 1577 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) |
1aed6766 | 1578 | processing_gcc_compilation = 2; |
db2302cb PS |
1579 | if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd)) |
1580 | ++tempstring; | |
1581 | if (STREQN (tempstring, "__gnu_compiled", 14)) | |
1582 | processing_gcc_compilation = 2; | |
1aed6766 | 1583 | } |
3416d90b FF |
1584 | |
1585 | /* Try to select a C++ demangling based on the compilation unit | |
1586 | producer. */ | |
1587 | ||
1588 | if (processing_gcc_compilation) | |
1589 | { | |
1aed6766 | 1590 | if (AUTO_DEMANGLING) |
3416d90b FF |
1591 | { |
1592 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
1593 | } | |
3416d90b | 1594 | } |
bd5635a1 RP |
1595 | } |
1596 | else | |
1597 | { | |
1598 | /* The N_SO starting this symtab is the first symbol, so we | |
1599 | better not check the symbol before it. I'm not this can | |
1600 | happen, but it doesn't hurt to check for it. */ | |
2c7ab4ca | 1601 | bfd_seek (symfile_bfd, sym_offset, SEEK_CUR); |
bd5635a1 RP |
1602 | processing_gcc_compilation = 0; |
1603 | } | |
1604 | ||
1605 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 1606 | fill_symbuf (abfd); |
bd5635a1 RP |
1607 | bufp = &symbuf[symbuf_idx]; |
1608 | if (bufp->n_type != (unsigned char)N_SO) | |
1609 | error("First symbol in segment of executable not a source symbol"); | |
1610 | ||
afe4ca15 JG |
1611 | max_symnum = sym_size / symbol_size; |
1612 | ||
bd5635a1 | 1613 | for (symnum = 0; |
afe4ca15 | 1614 | symnum < max_symnum; |
bd5635a1 RP |
1615 | symnum++) |
1616 | { | |
1617 | QUIT; /* Allow this to be interruptable */ | |
1618 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 1619 | fill_symbuf(abfd); |
bd5635a1 | 1620 | bufp = &symbuf[symbuf_idx++]; |
7d9884b9 | 1621 | SWAP_SYMBOL (bufp, abfd); |
bd5635a1 | 1622 | |
c0302457 | 1623 | type = bufp->n_type; |
bd5635a1 | 1624 | |
afe4ca15 | 1625 | SET_NAMESTRING (); |
bd5635a1 | 1626 | |
7d9884b9 | 1627 | if (type & N_STAB) { |
c55e6167 | 1628 | process_one_symbol (type, bufp->n_desc, bufp->n_value, |
2af231b8 | 1629 | namestring, section_offsets, objfile); |
7d9884b9 | 1630 | } |
bd5635a1 RP |
1631 | /* We skip checking for a new .o or -l file; that should never |
1632 | happen in this routine. */ | |
1aed6766 | 1633 | else if (type == N_TEXT) |
3416d90b FF |
1634 | { |
1635 | /* I don't think this code will ever be executed, because | |
1636 | the GCC_COMPILED_FLAG_SYMBOL usually is right before | |
1637 | the N_SO symbol which starts this source file. | |
1638 | However, there is no reason not to accept | |
1639 | the GCC_COMPILED_FLAG_SYMBOL anywhere. */ | |
1aed6766 | 1640 | |
2e4964ad | 1641 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) |
1aed6766 | 1642 | processing_gcc_compilation = 1; |
2e4964ad | 1643 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) |
1aed6766 SG |
1644 | processing_gcc_compilation = 2; |
1645 | ||
1aed6766 | 1646 | if (AUTO_DEMANGLING) |
3416d90b FF |
1647 | { |
1648 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
1649 | } | |
3416d90b | 1650 | } |
bd5635a1 RP |
1651 | else if (type & N_EXT || type == (unsigned char)N_TEXT |
1652 | || type == (unsigned char)N_NBTEXT | |
0c4d2cc2 | 1653 | ) { |
bd5635a1 RP |
1654 | /* Global symbol: see if we came across a dbx defintion for |
1655 | a corresponding symbol. If so, store the value. Remove | |
1656 | syms from the chain when their values are stored, but | |
1657 | search the whole chain, as there may be several syms from | |
1658 | different files with the same name. */ | |
1659 | /* This is probably not true. Since the files will be read | |
1660 | in one at a time, each reference to a global symbol will | |
1661 | be satisfied in each file as it appears. So we skip this | |
1662 | section. */ | |
1663 | ; | |
0c4d2cc2 | 1664 | } |
bd5635a1 | 1665 | } |
9404978d | 1666 | |
021959e2 | 1667 | current_objfile = NULL; |
9342ecb9 JG |
1668 | |
1669 | /* In a Solaris elf file, this variable, which comes from the | |
1670 | value of the N_SO symbol, will still be 0. Luckily, text_offset, | |
1671 | which comes from pst->textlow is correct. */ | |
1672 | if (last_source_start_addr == 0) | |
1673 | last_source_start_addr = text_offset; | |
1674 | ||
574dac8e JK |
1675 | pst->symtab = end_symtab (text_offset + text_size, 0, 0, objfile, |
1676 | SECT_OFF_TEXT); | |
3416d90b | 1677 | end_stabs (); |
bd5635a1 | 1678 | } |
574dac8e | 1679 | |
bd5635a1 | 1680 | \f |
c55e6167 JG |
1681 | /* This handles a single symbol from the symbol-file, building symbols |
1682 | into a GDB symtab. It takes these arguments and an implicit argument. | |
1683 | ||
1684 | TYPE is the type field of the ".stab" symbol entry. | |
1685 | DESC is the desc field of the ".stab" entry. | |
1686 | VALU is the value field of the ".stab" entry. | |
1687 | NAME is the symbol name, in our address space. | |
2af231b8 JG |
1688 | SECTION_OFFSETS is a set of amounts by which the sections of this object |
1689 | file were relocated when it was loaded into memory. | |
1690 | All symbols that refer | |
1691 | to memory locations need to be offset by these amounts. | |
9342ecb9 | 1692 | OBJFILE is the object file from which we are reading symbols. |
c55e6167 JG |
1693 | It is used in end_symtab. */ |
1694 | ||
7e258d18 | 1695 | void |
2af231b8 | 1696 | process_one_symbol (type, desc, valu, name, section_offsets, objfile) |
bd5635a1 RP |
1697 | int type, desc; |
1698 | CORE_ADDR valu; | |
1699 | char *name; | |
2af231b8 | 1700 | struct section_offsets *section_offsets; |
9342ecb9 | 1701 | struct objfile *objfile; |
bd5635a1 | 1702 | { |
a5e6391b JK |
1703 | #ifdef SUN_FIXED_LBRAC_BUG |
1704 | /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need | |
1705 | to correct the address of N_LBRAC's. If it is not defined, then | |
1706 | we never need to correct the addresses. */ | |
1707 | ||
0cf9329b | 1708 | /* This records the last pc address we've seen. We depend on there being |
bd5635a1 RP |
1709 | an SLINE or FUN or SO before the first LBRAC, since the variable does |
1710 | not get reset in between reads of different symbol files. */ | |
1711 | static CORE_ADDR last_pc_address; | |
a5e6391b | 1712 | #endif |
8357834f | 1713 | |
bd5635a1 | 1714 | register struct context_stack *new; |
9342ecb9 JG |
1715 | /* This remembers the address of the start of a function. It is used |
1716 | because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are | |
1717 | relative to the current function's start address. On systems | |
2af231b8 JG |
1718 | other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is |
1719 | used to relocate these symbol types rather than SECTION_OFFSETS. */ | |
9342ecb9 | 1720 | static CORE_ADDR function_start_offset; |
bd5635a1 | 1721 | |
8357834f | 1722 | /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source |
b8ec9a79 | 1723 | file. Used to detect the SunPRO solaris compiler. */ |
4d57c599 | 1724 | static int n_opt_found; |
8357834f | 1725 | |
b8ec9a79 JK |
1726 | /* The stab type used for the definition of the last function. |
1727 | N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */ | |
1728 | static int function_stab_type = 0; | |
1729 | ||
574dac8e JK |
1730 | if (!block_address_function_relative) |
1731 | /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the | |
1732 | function start address, so just use the text offset. */ | |
1733 | function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
51b80b00 | 1734 | |
bd5635a1 RP |
1735 | /* Something is wrong if we see real data before |
1736 | seeing a source file name. */ | |
1737 | ||
3416d90b | 1738 | if (last_source_file == NULL && type != (unsigned char)N_SO) |
bd5635a1 | 1739 | { |
a5e6391b JK |
1740 | /* Ignore any symbols which appear before an N_SO symbol. Currently |
1741 | no one puts symbols there, but we should deal gracefully with the | |
1742 | case. A complain()t might be in order (if !IGNORE_SYMBOL (type)), | |
1743 | but this should not be an error (). */ | |
1744 | return; | |
bd5635a1 RP |
1745 | } |
1746 | ||
1747 | switch (type) | |
1748 | { | |
1749 | case N_FUN: | |
1750 | case N_FNAME: | |
2af231b8 JG |
1751 | /* Relocate for dynamic loading */ |
1752 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
b8ec9a79 | 1753 | goto define_a_symbol; |
bd5635a1 | 1754 | |
bd5635a1 RP |
1755 | case N_LBRAC: |
1756 | /* This "symbol" just indicates the start of an inner lexical | |
1757 | context within a function. */ | |
1758 | ||
b9e58503 PS |
1759 | /* Ignore extra outermost context from SunPRO cc and acc. */ |
1760 | if (n_opt_found && desc == 1) | |
1761 | break; | |
1762 | ||
574dac8e JK |
1763 | #if defined(BLOCK_ADDRESS_ABSOLUTE) |
1764 | /* Relocate for dynamic loading (?). */ | |
9342ecb9 | 1765 | valu += function_start_offset; |
c55e6167 | 1766 | #else |
574dac8e JK |
1767 | if (block_address_function_relative) |
1768 | /* Relocate for Sun ELF acc fn-relative syms. */ | |
1769 | valu += function_start_offset; | |
1770 | else | |
1771 | /* On most machines, the block addresses are relative to the | |
1772 | N_SO, the linker did not relocate them (sigh). */ | |
1773 | valu += last_source_start_addr; | |
bd5635a1 RP |
1774 | #endif |
1775 | ||
a5e6391b | 1776 | #ifdef SUN_FIXED_LBRAC_BUG |
8357834f | 1777 | if (!SUN_FIXED_LBRAC_BUG && valu < last_pc_address) { |
bd5635a1 | 1778 | /* Patch current LBRAC pc value to match last handy pc value */ |
51b80b00 | 1779 | complain (&lbrac_complaint); |
bd5635a1 RP |
1780 | valu = last_pc_address; |
1781 | } | |
a5e6391b | 1782 | #endif |
7d9884b9 | 1783 | new = push_context (desc, valu); |
bd5635a1 RP |
1784 | break; |
1785 | ||
1786 | case N_RBRAC: | |
1787 | /* This "symbol" just indicates the end of an inner lexical | |
1788 | context that was started with N_LBRAC. */ | |
1789 | ||
b9e58503 PS |
1790 | /* Ignore extra outermost context from SunPRO cc and acc. */ |
1791 | if (n_opt_found && desc == 1) | |
1792 | break; | |
1793 | ||
574dac8e JK |
1794 | #if defined(BLOCK_ADDRESS_ABSOLUTE) |
1795 | /* Relocate for dynamic loading (?). */ | |
9342ecb9 | 1796 | valu += function_start_offset; |
c55e6167 | 1797 | #else |
574dac8e JK |
1798 | if (block_address_function_relative) |
1799 | /* Relocate for Sun ELF acc fn-relative syms. */ | |
1800 | valu += function_start_offset; | |
1801 | else | |
1802 | /* On most machines, the block addresses are relative to the | |
1803 | N_SO, the linker did not relocate them (sigh). */ | |
1804 | valu += last_source_start_addr; | |
bd5635a1 RP |
1805 | #endif |
1806 | ||
7d9884b9 | 1807 | new = pop_context(); |
bd5635a1 | 1808 | if (desc != new->depth) |
51b80b00 | 1809 | complain (&lbrac_mismatch_complaint, symnum); |
bd5635a1 RP |
1810 | |
1811 | /* Some compilers put the variable decls inside of an | |
1812 | LBRAC/RBRAC block. This macro should be nonzero if this | |
1813 | is true. DESC is N_DESC from the N_RBRAC symbol. | |
0cf9329b PB |
1814 | GCC_P is true if we've detected the GCC_COMPILED_SYMBOL |
1815 | or the GCC2_COMPILED_SYMBOL. */ | |
bd5635a1 RP |
1816 | #if !defined (VARIABLES_INSIDE_BLOCK) |
1817 | #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0 | |
1818 | #endif | |
1819 | ||
1820 | /* Can only use new->locals as local symbols here if we're in | |
1821 | gcc or on a machine that puts them before the lbrack. */ | |
1822 | if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
1823 | local_symbols = new->locals; | |
1824 | ||
2f8c3639 JL |
1825 | if (context_stack_depth |
1826 | > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
bd5635a1 | 1827 | { |
2f8c3639 JL |
1828 | /* This is not the outermost LBRAC...RBRAC pair in the function, |
1829 | its local symbols preceded it, and are the ones just recovered | |
1830 | from the context stack. Define the block for them (but don't | |
1831 | bother if the block contains no symbols. Should we complain | |
1832 | on blocks without symbols? I can't think of any useful purpose | |
1833 | for them). */ | |
1834 | if (local_symbols != NULL) | |
bd5635a1 | 1835 | { |
2f8c3639 JL |
1836 | /* Muzzle a compiler bug that makes end < start. (which |
1837 | compilers? Is this ever harmful?). */ | |
1838 | if (new->start_addr > valu) | |
1839 | { | |
1840 | complain (&lbrac_rbrac_complaint); | |
1841 | new->start_addr = valu; | |
1842 | } | |
1843 | /* Make a block for the local symbols within. */ | |
1844 | finish_block (0, &local_symbols, new->old_blocks, | |
1845 | new->start_addr, valu, objfile); | |
bd5635a1 | 1846 | } |
bd5635a1 RP |
1847 | } |
1848 | else | |
1849 | { | |
2f8c3639 JL |
1850 | /* This is the outermost LBRAC...RBRAC pair. There is no |
1851 | need to do anything; leave the symbols that preceded it | |
1852 | to be attached to the function's own block. We need to | |
1853 | indicate that we just moved outside of the function. */ | |
bd5635a1 RP |
1854 | within_function = 0; |
1855 | } | |
2f8c3639 | 1856 | |
bd5635a1 RP |
1857 | if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) |
1858 | /* Now pop locals of block just finished. */ | |
1859 | local_symbols = new->locals; | |
1860 | break; | |
1861 | ||
9bb30452 | 1862 | case N_FN: |
6150cc73 | 1863 | case N_FN_SEQ: |
9bb30452 | 1864 | /* This kind of symbol indicates the start of an object file. */ |
2af231b8 JG |
1865 | /* Relocate for dynamic loading */ |
1866 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
bd5635a1 RP |
1867 | break; |
1868 | ||
1869 | case N_SO: | |
1870 | /* This type of symbol indicates the start of data | |
1871 | for one source file. | |
1872 | Finish the symbol table of the previous source file | |
1873 | (if any) and start accumulating a new symbol table. */ | |
2af231b8 JG |
1874 | /* Relocate for dynamic loading */ |
1875 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
c55e6167 | 1876 | |
8357834f JK |
1877 | n_opt_found = 0; |
1878 | ||
a5e6391b | 1879 | #ifdef SUN_FIXED_LBRAC_BUG |
bd5635a1 | 1880 | last_pc_address = valu; /* Save for SunOS bug circumcision */ |
a5e6391b | 1881 | #endif |
8357834f | 1882 | |
bd5635a1 RP |
1883 | #ifdef PCC_SOL_BROKEN |
1884 | /* pcc bug, occasionally puts out SO for SOL. */ | |
1885 | if (context_stack_depth > 0) | |
1886 | { | |
1887 | start_subfile (name, NULL); | |
1888 | break; | |
1889 | } | |
1890 | #endif | |
1891 | if (last_source_file) | |
7e258d18 PB |
1892 | { |
1893 | /* Check if previous symbol was also an N_SO (with some | |
1894 | sanity checks). If so, that one was actually the directory | |
1895 | name, and the current one is the real file name. | |
1896 | Patch things up. */ | |
6985bc54 | 1897 | if (previous_stab_code == (unsigned char) N_SO) |
7e258d18 | 1898 | { |
3416d90b | 1899 | patch_subfile_names (current_subfile, name); |
c72af089 | 1900 | break; /* Ignore repeated SOs */ |
7e258d18 | 1901 | } |
65ce5df4 | 1902 | end_symtab (valu, 0, 0, objfile, SECT_OFF_TEXT); |
3416d90b | 1903 | end_stabs (); |
7e258d18 | 1904 | } |
320f93f7 SG |
1905 | |
1906 | /* Null name means this just marks the end of text for this .o file. | |
1907 | Don't start a new symtab in this case. */ | |
1908 | if (*name == '\000') | |
1909 | break; | |
1910 | ||
3416d90b | 1911 | start_stabs (); |
bd5635a1 RP |
1912 | start_symtab (name, NULL, valu); |
1913 | break; | |
1914 | ||
1915 | case N_SOL: | |
1916 | /* This type of symbol indicates the start of data for | |
1917 | a sub-source-file, one whose contents were copied or | |
1918 | included in the compilation of the main source file | |
1919 | (whose name was given in the N_SO symbol.) */ | |
2af231b8 JG |
1920 | /* Relocate for dynamic loading */ |
1921 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
784fd92b | 1922 | start_subfile (name, current_subfile->dirname); |
bd5635a1 RP |
1923 | break; |
1924 | ||
1925 | case N_BINCL: | |
1926 | push_subfile (); | |
1927 | add_new_header_file (name, valu); | |
784fd92b | 1928 | start_subfile (name, current_subfile->dirname); |
bd5635a1 RP |
1929 | break; |
1930 | ||
1931 | case N_EINCL: | |
784fd92b | 1932 | start_subfile (pop_subfile (), current_subfile->dirname); |
bd5635a1 RP |
1933 | break; |
1934 | ||
1935 | case N_EXCL: | |
1936 | add_old_header_file (name, valu); | |
1937 | break; | |
1938 | ||
1939 | case N_SLINE: | |
1940 | /* This type of "symbol" really just records | |
1941 | one line-number -- core-address correspondence. | |
1942 | Enter it in the line list for this symbol table. */ | |
9342ecb9 JG |
1943 | /* Relocate for dynamic loading and for ELF acc fn-relative syms. */ |
1944 | valu += function_start_offset; | |
a5e6391b | 1945 | #ifdef SUN_FIXED_LBRAC_BUG |
bd5635a1 | 1946 | last_pc_address = valu; /* Save for SunOS bug circumcision */ |
a5e6391b | 1947 | #endif |
4137c5fc | 1948 | record_line (current_subfile, desc, valu); |
bd5635a1 RP |
1949 | break; |
1950 | ||
1951 | case N_BCOMM: | |
4d57c599 | 1952 | common_block_start (name, objfile); |
bd5635a1 RP |
1953 | break; |
1954 | ||
1955 | case N_ECOMM: | |
4d57c599 JK |
1956 | common_block_end (objfile); |
1957 | break; | |
bd5635a1 | 1958 | |
2af231b8 JG |
1959 | /* The following symbol types need to have the appropriate offset added |
1960 | to their value; then we process symbol definitions in the name. */ | |
1961 | ||
1962 | case N_STSYM: /* Static symbol in data seg */ | |
1963 | case N_LCSYM: /* Static symbol in BSS seg */ | |
1964 | case N_ROSYM: /* Static symbol in Read-only data seg */ | |
4d57c599 JK |
1965 | /* HORRID HACK DEPT. However, it's Sun's furgin' fault. |
1966 | Solaris2's stabs-in-elf makes *most* symbols relative | |
1967 | but leaves a few absolute (at least for Solaris 2.1 and version | |
1968 | 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence. | |
2af231b8 JG |
1969 | .stab "foo:S...",N_STSYM is absolute (ld relocates it) |
1970 | .stab "foo:V...",N_STSYM is relative (section base subtracted). | |
1971 | This leaves us no choice but to search for the 'S' or 'V'... | |
1972 | (or pass the whole section_offsets stuff down ONE MORE function | |
4d57c599 | 1973 | call level, which we really don't want to do). */ |
2af231b8 JG |
1974 | { |
1975 | char *p; | |
a66e8382 SG |
1976 | |
1977 | /* .o files and NLMs have non-zero text seg offsets, but don't need | |
1978 | their static syms offset in this fashion. XXX - This is really a | |
1979 | crock that should be fixed in the solib handling code so that I | |
1980 | don't have to work around it here. */ | |
1981 | ||
1982 | if (!symfile_relocatable) | |
2af231b8 | 1983 | { |
a66e8382 SG |
1984 | p = strchr (name, ':'); |
1985 | if (p != 0 && p[1] == 'S') | |
1986 | { | |
1987 | /* The linker relocated it. We don't want to add an | |
1988 | elfstab_offset_sections-type offset, but we *do* want | |
1989 | to add whatever solib.c passed to symbol_file_add as | |
1990 | addr (this is known to affect SunOS4, and I suspect ELF | |
1991 | too). Since elfstab_offset_sections currently does not | |
1992 | muck with the text offset (there is no Ttext.text | |
1993 | symbol), we can get addr from the text offset. If | |
1994 | elfstab_offset_sections ever starts dealing with the | |
1995 | text offset, and we still need to do this, we need to | |
1996 | invent a SECT_OFF_ADDR_KLUDGE or something. */ | |
1997 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
1998 | goto define_a_symbol; | |
1999 | } | |
2af231b8 JG |
2000 | } |
2001 | /* Since it's not the kludge case, re-dispatch to the right handler. */ | |
2002 | switch (type) { | |
2003 | case N_STSYM: goto case_N_STSYM; | |
2004 | case N_LCSYM: goto case_N_LCSYM; | |
2005 | case N_ROSYM: goto case_N_ROSYM; | |
2006 | default: abort(); | |
2007 | } | |
2008 | } | |
2009 | ||
2010 | case_N_STSYM: /* Static symbol in data seg */ | |
c55e6167 | 2011 | case N_DSLINE: /* Source line number, data seg */ |
2af231b8 JG |
2012 | valu += ANOFFSET (section_offsets, SECT_OFF_DATA); |
2013 | goto define_a_symbol; | |
2014 | ||
2015 | case_N_LCSYM: /* Static symbol in BSS seg */ | |
c55e6167 JG |
2016 | case N_BSLINE: /* Source line number, bss seg */ |
2017 | /* N_BROWS: overlaps with N_BSLINE */ | |
2af231b8 JG |
2018 | valu += ANOFFSET (section_offsets, SECT_OFF_BSS); |
2019 | goto define_a_symbol; | |
2020 | ||
2021 | case_N_ROSYM: /* Static symbol in Read-only data seg */ | |
2022 | valu += ANOFFSET (section_offsets, SECT_OFF_RODATA); | |
2023 | goto define_a_symbol; | |
2024 | ||
c55e6167 | 2025 | case N_ENTRY: /* Alternate entry point */ |
2af231b8 JG |
2026 | /* Relocate for dynamic loading */ |
2027 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
2028 | goto define_a_symbol; | |
c55e6167 | 2029 | |
4f470205 JK |
2030 | /* The following symbol types we don't know how to process. Handle |
2031 | them in a "default" way, but complain to people who care. */ | |
2032 | default: | |
2033 | case N_CATCH: /* Exception handler catcher */ | |
2034 | case N_EHDECL: /* Exception handler name */ | |
2035 | case N_PC: /* Global symbol in Pascal */ | |
2036 | case N_M2C: /* Modula-2 compilation unit */ | |
2037 | /* N_MOD2: overlaps with N_EHDECL */ | |
2038 | case N_SCOPE: /* Modula-2 scope information */ | |
2039 | case N_ECOML: /* End common (local name) */ | |
2040 | case N_NBTEXT: /* Gould Non-Base-Register symbols??? */ | |
2041 | case N_NBDATA: | |
2042 | case N_NBBSS: | |
2043 | case N_NBSTS: | |
2044 | case N_NBLCS: | |
9d2b8d50 | 2045 | complain (&unknown_symtype_complaint, local_hex_string (type)); |
4f470205 JK |
2046 | /* FALLTHROUGH */ |
2047 | ||
c55e6167 JG |
2048 | /* The following symbol types don't need the address field relocated, |
2049 | since it is either unused, or is absolute. */ | |
2af231b8 | 2050 | define_a_symbol: |
c55e6167 JG |
2051 | case N_GSYM: /* Global variable */ |
2052 | case N_NSYMS: /* Number of symbols (ultrix) */ | |
2053 | case N_NOMAP: /* No map? (ultrix) */ | |
2054 | case N_RSYM: /* Register variable */ | |
2055 | case N_DEFD: /* Modula-2 GNU module dependency */ | |
2056 | case N_SSYM: /* Struct or union element */ | |
2057 | case N_LSYM: /* Local symbol in stack */ | |
2058 | case N_PSYM: /* Parameter variable */ | |
2059 | case N_LENG: /* Length of preceding symbol type */ | |
2060 | if (name) | |
4f470205 | 2061 | { |
b8ec9a79 JK |
2062 | int deftype; |
2063 | char *colon_pos = strchr (name, ':'); | |
2064 | if (colon_pos == NULL) | |
2065 | deftype = '\0'; | |
2066 | else | |
2067 | deftype = colon_pos[1]; | |
2068 | ||
2069 | switch (deftype) | |
4f470205 | 2070 | { |
b8ec9a79 JK |
2071 | case 'f': |
2072 | case 'F': | |
2073 | function_stab_type = type; | |
2074 | ||
b9e58503 PS |
2075 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING |
2076 | /* Deal with the SunPRO 3.0 compiler which omits the address | |
2077 | from N_FUN symbols. */ | |
989d9cba JK |
2078 | if (type == N_FUN |
2079 | && valu == ANOFFSET (section_offsets, SECT_OFF_TEXT)) | |
b9e58503 PS |
2080 | { |
2081 | struct minimal_symbol *msym; | |
2082 | char *p; | |
2083 | int n; | |
2084 | ||
2085 | p = strchr (name, ':'); | |
2086 | if (p == NULL) | |
2087 | p = name; | |
2088 | n = p - name; | |
2089 | p = alloca (n + 1); | |
2090 | strncpy (p, name, n); | |
2091 | p[n] = 0; | |
2092 | ||
2093 | msym = lookup_minimal_symbol (p, last_source_file, | |
2094 | objfile); | |
2095 | if (msym) | |
2096 | valu = SYMBOL_VALUE_ADDRESS (msym); | |
2097 | } | |
2098 | #endif | |
2099 | ||
3ef0fc8c | 2100 | #ifdef SUN_FIXED_LBRAC_BUG |
b8ec9a79 JK |
2101 | /* The Sun acc compiler, under SunOS4, puts out |
2102 | functions with N_GSYM or N_STSYM. The problem is | |
2103 | that the address of the symbol is no good (for N_GSYM | |
2104 | it doesn't even attept an address; for N_STSYM it | |
2105 | puts out an address but then it gets relocated | |
2106 | relative to the data segment, not the text segment). | |
2107 | Currently we can't fix this up later as we do for | |
2108 | some types of symbol in scan_file_globals. | |
2109 | Fortunately we do have a way of finding the address - | |
2110 | we know that the value in last_pc_address is either | |
2111 | the one we want (if we're dealing with the first | |
2112 | function in an object file), or somewhere in the | |
2113 | previous function. This means that we can use the | |
2114 | minimal symbol table to get the address. */ | |
2115 | ||
b9e58503 PS |
2116 | /* Starting with release 3.0, the Sun acc compiler, |
2117 | under SunOS4, puts out functions with N_FUN and a value | |
2118 | of zero. This gets relocated to the start of the text | |
2119 | segment of the module, which is no good either. | |
2120 | Under SunOS4 we can deal with this as N_SLINE and N_SO | |
2121 | entries contain valid absolute addresses. | |
2122 | Release 3.0 acc also puts out N_OPT entries, which makes | |
2123 | it possible to discern acc from cc or gcc. */ | |
2124 | ||
2125 | if (type == N_GSYM || type == N_STSYM | |
2126 | || (type == N_FUN | |
2127 | && n_opt_found && !block_address_function_relative)) | |
b8ec9a79 JK |
2128 | { |
2129 | struct minimal_symbol *m; | |
2130 | int l = colon_pos - name; | |
2131 | ||
2132 | m = lookup_minimal_symbol_by_pc (last_pc_address); | |
2b576293 C |
2133 | if (m && STREQN (SYMBOL_NAME (m), name, l) |
2134 | && SYMBOL_NAME (m) [l] == '\0') | |
b8ec9a79 JK |
2135 | /* last_pc_address was in this function */ |
2136 | valu = SYMBOL_VALUE (m); | |
2b576293 C |
2137 | else if (m && STREQN (SYMBOL_NAME (m+1), name, l) |
2138 | && SYMBOL_NAME (m+1) [l] == '\0') | |
3c7d3064 JK |
2139 | /* last_pc_address was in last function */ |
2140 | valu = SYMBOL_VALUE (m+1); | |
b8ec9a79 | 2141 | else |
3c7d3064 JK |
2142 | /* Not found - use last_pc_address (for finish_block) */ |
2143 | valu = last_pc_address; | |
b8ec9a79 JK |
2144 | } |
2145 | ||
b8ec9a79 JK |
2146 | last_pc_address = valu; /* Save for SunOS bug circumcision */ |
2147 | #endif | |
2148 | ||
2149 | if (block_address_function_relative) | |
2150 | /* For Solaris 2.0 compilers, the block addresses and | |
2151 | N_SLINE's are relative to the start of the | |
2152 | function. On normal systems, and when using gcc on | |
2153 | Solaris 2.0, these addresses are just absolute, or | |
2154 | relative to the N_SO, depending on | |
2155 | BLOCK_ADDRESS_ABSOLUTE. */ | |
2156 | function_start_offset = valu; | |
2157 | ||
2158 | within_function = 1; | |
2159 | if (context_stack_depth > 0) | |
2160 | { | |
2161 | new = pop_context (); | |
2162 | /* Make a block for the local symbols within. */ | |
2163 | finish_block (new->name, &local_symbols, new->old_blocks, | |
2164 | new->start_addr, valu, objfile); | |
2165 | } | |
2166 | /* Stack must be empty now. */ | |
2167 | if (context_stack_depth != 0) | |
2168 | complain (&lbrac_unmatched_complaint, symnum); | |
2169 | ||
2170 | new = push_context (0, valu); | |
2171 | new->name = define_symbol (valu, name, desc, type, objfile); | |
2172 | break; | |
2173 | ||
2174 | default: | |
2175 | define_symbol (valu, name, desc, type, objfile); | |
2176 | break; | |
4f470205 JK |
2177 | } |
2178 | } | |
bd5635a1 RP |
2179 | break; |
2180 | ||
ec8ceca3 JG |
2181 | /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it |
2182 | for a bunch of other flags, too. Someday we may parse their | |
2183 | flags; for now we ignore theirs and hope they'll ignore ours. */ | |
2184 | case N_OPT: /* Solaris 2: Compiler options */ | |
2185 | if (name) | |
2186 | { | |
2e4964ad | 2187 | if (STREQ (name, GCC2_COMPILED_FLAG_SYMBOL)) |
3416d90b | 2188 | { |
1aed6766 | 2189 | processing_gcc_compilation = 2; |
3416d90b | 2190 | #if 1 /* Works, but is experimental. -fnf */ |
1aed6766 | 2191 | if (AUTO_DEMANGLING) |
3416d90b FF |
2192 | { |
2193 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
2194 | } | |
2195 | #endif | |
2196 | } | |
8357834f JK |
2197 | else |
2198 | n_opt_found = 1; | |
ec8ceca3 JG |
2199 | } |
2200 | break; | |
2201 | ||
bcbf9559 JG |
2202 | /* The following symbol types can be ignored. */ |
2203 | case N_OBJ: /* Solaris 2: Object file dir and name */ | |
bcbf9559 JG |
2204 | /* N_UNDF: Solaris 2: file separator mark */ |
2205 | /* N_UNDF: -- we will never encounter it, since we only process one | |
2206 | file's symbols at once. */ | |
4c7c6bab JG |
2207 | case N_ENDM: /* Solaris 2: End of module */ |
2208 | case N_MAIN: /* Name of main routine. */ | |
9342ecb9 | 2209 | break; |
bd5635a1 | 2210 | } |
7e258d18 PB |
2211 | |
2212 | previous_stab_code = type; | |
bd5635a1 RP |
2213 | } |
2214 | \f | |
2b576293 C |
2215 | /* FIXME: The only difference between this and elfstab_build_psymtabs |
2216 | is the call to install_minimal_symbols for elf, and the support for | |
2217 | split sections. If the differences are really that small, the code | |
2218 | should be shared. */ | |
965a5c32 | 2219 | |
b5b186a2 SS |
2220 | /* Scan and build partial symbols for an coff symbol file. |
2221 | The coff file has already been processed to get its minimal symbols. | |
2222 | ||
2223 | This routine is the equivalent of dbx_symfile_init and dbx_symfile_read | |
2224 | rolled into one. | |
2225 | ||
2226 | OBJFILE is the object file we are reading symbols from. | |
2227 | ADDR is the address relative to which the symbols are (e.g. | |
2228 | the base address of the text segment). | |
2229 | MAINLINE is true if we are reading the main symbol | |
2230 | table (as opposed to a shared lib or dynamically loaded file). | |
2b576293 C |
2231 | TEXTADDR is the address of the text section. |
2232 | TEXTSIZE is the size of the text section. | |
2233 | STABSECTS is the list of .stab sections in OBJFILE. | |
b5b186a2 SS |
2234 | STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the |
2235 | .stabstr section exists. | |
2236 | ||
2237 | This routine is mostly copied from dbx_symfile_init and dbx_symfile_read, | |
2238 | adjusted for coff details. */ | |
2239 | ||
2240 | void | |
2241 | coffstab_build_psymtabs (objfile, section_offsets, mainline, | |
2b576293 | 2242 | textaddr, textsize, stabsects, |
b5b186a2 SS |
2243 | stabstroffset, stabstrsize) |
2244 | struct objfile *objfile; | |
2245 | struct section_offsets *section_offsets; | |
2246 | int mainline; | |
2b576293 C |
2247 | CORE_ADDR textaddr; |
2248 | unsigned int textsize; | |
2249 | struct stab_section_list *stabsects; | |
b5b186a2 SS |
2250 | file_ptr stabstroffset; |
2251 | unsigned int stabstrsize; | |
2252 | { | |
2253 | int val; | |
2254 | bfd *sym_bfd = objfile->obfd; | |
2255 | char *name = bfd_get_filename (sym_bfd); | |
2256 | struct dbx_symfile_info *info; | |
2b576293 | 2257 | unsigned int stabsize; |
b5b186a2 SS |
2258 | |
2259 | /* There is already a dbx_symfile_info allocated by our caller. | |
2260 | It might even contain some info from the coff symtab to help us. */ | |
965a5c32 | 2261 | info = (struct dbx_symfile_info *) objfile->sym_stab_info; |
b5b186a2 | 2262 | |
2b576293 C |
2263 | DBX_TEXT_ADDR (objfile) = textaddr; |
2264 | DBX_TEXT_SIZE (objfile) = textsize; | |
b5b186a2 SS |
2265 | |
2266 | #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ | |
2267 | DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE; | |
b5b186a2 | 2268 | DBX_STRINGTAB_SIZE (objfile) = stabstrsize; |
b5b186a2 SS |
2269 | |
2270 | if (stabstrsize > bfd_get_size (sym_bfd)) | |
2271 | error ("ridiculous string table size: %d bytes", stabstrsize); | |
2272 | DBX_STRINGTAB (objfile) = (char *) | |
2273 | obstack_alloc (&objfile->psymbol_obstack, stabstrsize+1); | |
2274 | ||
2275 | /* Now read in the string table in one big gulp. */ | |
2276 | ||
2277 | val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET); | |
2278 | if (val < 0) | |
2279 | perror_with_name (name); | |
2280 | val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd); | |
2281 | if (val != stabstrsize) | |
2282 | perror_with_name (name); | |
2283 | ||
2284 | stabsread_new_init (); | |
2285 | buildsym_new_init (); | |
2286 | free_header_files (); | |
2287 | init_header_files (); | |
2288 | ||
2289 | processing_acc_compilation = 1; | |
2290 | ||
2291 | /* In a coff file, we've already installed the minimal symbols that came | |
2292 | from the coff (non-stab) symbol table, so always act like an | |
2293 | incremental load here. */ | |
2b576293 C |
2294 | if (stabsects->next == NULL) |
2295 | { | |
2296 | stabsize = bfd_section_size (sym_bfd, stabsects->section); | |
2297 | DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile); | |
2298 | DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos; | |
2299 | } | |
2300 | else | |
2301 | { | |
2302 | struct stab_section_list *stabsect; | |
2303 | ||
2304 | DBX_SYMCOUNT (objfile) = 0; | |
2305 | for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next) | |
2306 | { | |
2307 | stabsize = bfd_section_size (sym_bfd, stabsect->section); | |
2308 | DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile); | |
2309 | } | |
2310 | ||
2311 | DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos; | |
2312 | ||
2313 | symbuf_sections = stabsects->next; | |
2314 | symbuf_left = bfd_section_size (sym_bfd, stabsects->section); | |
2315 | symbuf_read = 0; | |
2316 | } | |
2317 | ||
b5b186a2 SS |
2318 | dbx_symfile_read (objfile, section_offsets, 0); |
2319 | } | |
2320 | \f | |
9342ecb9 JG |
2321 | /* Scan and build partial symbols for an ELF symbol file. |
2322 | This ELF file has already been processed to get its minimal symbols, | |
2323 | and any DWARF symbols that were in it. | |
2324 | ||
2325 | This routine is the equivalent of dbx_symfile_init and dbx_symfile_read | |
2326 | rolled into one. | |
2327 | ||
2328 | OBJFILE is the object file we are reading symbols from. | |
2329 | ADDR is the address relative to which the symbols are (e.g. | |
2330 | the base address of the text segment). | |
2331 | MAINLINE is true if we are reading the main symbol | |
2332 | table (as opposed to a shared lib or dynamically loaded file). | |
2333 | STABOFFSET and STABSIZE define the location in OBJFILE where the .stab | |
2334 | section exists. | |
2335 | STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the | |
2336 | .stabstr section exists. | |
2337 | ||
2338 | This routine is mostly copied from dbx_symfile_init and dbx_symfile_read, | |
2339 | adjusted for elf details. */ | |
2340 | ||
2341 | void | |
1aed6766 | 2342 | elfstab_build_psymtabs (objfile, section_offsets, mainline, |
9342ecb9 | 2343 | staboffset, stabsize, |
1aed6766 SG |
2344 | stabstroffset, stabstrsize) |
2345 | struct objfile *objfile; | |
2346 | struct section_offsets *section_offsets; | |
2347 | int mainline; | |
51b80b00 | 2348 | file_ptr staboffset; |
1aed6766 | 2349 | unsigned int stabsize; |
51b80b00 | 2350 | file_ptr stabstroffset; |
1aed6766 | 2351 | unsigned int stabstrsize; |
9342ecb9 JG |
2352 | { |
2353 | int val; | |
2354 | bfd *sym_bfd = objfile->obfd; | |
2355 | char *name = bfd_get_filename (sym_bfd); | |
2356 | struct dbx_symfile_info *info; | |
2b576293 | 2357 | asection *text_sect; |
9342ecb9 | 2358 | |
2af231b8 JG |
2359 | /* There is already a dbx_symfile_info allocated by our caller. |
2360 | It might even contain some info from the ELF symtab to help us. */ | |
965a5c32 | 2361 | info = (struct dbx_symfile_info *) objfile->sym_stab_info; |
9342ecb9 | 2362 | |
2b576293 C |
2363 | text_sect = bfd_get_section_by_name (sym_bfd, ".text"); |
2364 | if (!text_sect) | |
9342ecb9 | 2365 | error ("Can't find .text section in symbol file"); |
2b576293 C |
2366 | DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); |
2367 | DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); | |
9342ecb9 JG |
2368 | |
2369 | #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ | |
2370 | DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE; | |
2371 | DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile); | |
2372 | DBX_STRINGTAB_SIZE (objfile) = stabstrsize; | |
2373 | DBX_SYMTAB_OFFSET (objfile) = staboffset; | |
2374 | ||
996ccb30 | 2375 | if (stabstrsize > bfd_get_size (sym_bfd)) |
9342ecb9 JG |
2376 | error ("ridiculous string table size: %d bytes", stabstrsize); |
2377 | DBX_STRINGTAB (objfile) = (char *) | |
2378 | obstack_alloc (&objfile->psymbol_obstack, stabstrsize+1); | |
2379 | ||
2380 | /* Now read in the string table in one big gulp. */ | |
2381 | ||
2c7ab4ca | 2382 | val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET); |
9342ecb9 JG |
2383 | if (val < 0) |
2384 | perror_with_name (name); | |
2385 | val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd); | |
2386 | if (val != stabstrsize) | |
2387 | perror_with_name (name); | |
2388 | ||
3416d90b | 2389 | stabsread_new_init (); |
9342ecb9 JG |
2390 | buildsym_new_init (); |
2391 | free_header_files (); | |
2392 | init_header_files (); | |
2393 | install_minimal_symbols (objfile); | |
2394 | ||
2395 | processing_acc_compilation = 1; | |
2396 | ||
2397 | /* In an elf file, we've already installed the minimal symbols that came | |
2398 | from the elf (non-stab) symbol table, so always act like an | |
2399 | incremental load here. */ | |
2af231b8 JG |
2400 | dbx_symfile_read (objfile, section_offsets, 0); |
2401 | } | |
2402 | \f | |
a66e8382 SG |
2403 | /* Scan and build partial symbols for a file with special sections for stabs |
2404 | and stabstrings. The file has already been processed to get its minimal | |
2405 | symbols, and any other symbols that might be necessary to resolve GSYMs. | |
2406 | ||
2407 | This routine is the equivalent of dbx_symfile_init and dbx_symfile_read | |
2408 | rolled into one. | |
2409 | ||
2410 | OBJFILE is the object file we are reading symbols from. | |
2411 | ADDR is the address relative to which the symbols are (e.g. the base address | |
2412 | of the text segment). | |
2413 | MAINLINE is true if we are reading the main symbol table (as opposed to a | |
2414 | shared lib or dynamically loaded file). | |
2415 | STAB_NAME is the name of the section that contains the stabs. | |
2416 | STABSTR_NAME is the name of the section that contains the stab strings. | |
2417 | ||
2418 | This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */ | |
2419 | ||
2420 | void | |
2421 | stabsect_build_psymtabs (objfile, section_offsets, mainline, stab_name, | |
320f93f7 | 2422 | stabstr_name, text_name) |
a66e8382 SG |
2423 | struct objfile *objfile; |
2424 | struct section_offsets *section_offsets; | |
2425 | int mainline; | |
2426 | char *stab_name; | |
2427 | char *stabstr_name; | |
320f93f7 | 2428 | char *text_name; |
a66e8382 SG |
2429 | { |
2430 | int val; | |
2431 | bfd *sym_bfd = objfile->obfd; | |
2432 | char *name = bfd_get_filename (sym_bfd); | |
2433 | asection *stabsect; | |
2434 | asection *stabstrsect; | |
2b576293 | 2435 | asection *text_sect; |
a66e8382 SG |
2436 | |
2437 | stabsect = bfd_get_section_by_name (sym_bfd, stab_name); | |
2438 | stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name); | |
2439 | ||
2440 | if (!stabsect) | |
2441 | return; | |
2442 | ||
2443 | if (!stabstrsect) | |
2444 | error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)", | |
2445 | stab_name, stabstr_name); | |
2446 | ||
bfe2f12b | 2447 | objfile->sym_stab_info = (PTR) xmalloc (sizeof (struct dbx_symfile_info)); |
a66e8382 SG |
2448 | memset (DBX_SYMFILE_INFO (objfile), 0, sizeof (struct dbx_symfile_info)); |
2449 | ||
2b576293 C |
2450 | text_sect = bfd_get_section_by_name (sym_bfd, text_name); |
2451 | if (!text_sect) | |
320f93f7 | 2452 | error ("Can't find %s section in symbol file", text_name); |
2b576293 C |
2453 | DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); |
2454 | DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); | |
a66e8382 SG |
2455 | |
2456 | DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist); | |
2457 | DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect) | |
2458 | / DBX_SYMBOL_SIZE (objfile); | |
2459 | DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect); | |
2460 | DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */ | |
2461 | ||
2462 | if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd)) | |
2463 | error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile)); | |
2464 | DBX_STRINGTAB (objfile) = (char *) | |
2465 | obstack_alloc (&objfile->psymbol_obstack, DBX_STRINGTAB_SIZE (objfile) + 1); | |
2466 | ||
2467 | /* Now read in the string table in one big gulp. */ | |
2468 | ||
2469 | val = bfd_get_section_contents (sym_bfd, /* bfd */ | |
2470 | stabstrsect, /* bfd section */ | |
2471 | DBX_STRINGTAB (objfile), /* input buffer */ | |
2472 | 0, /* offset into section */ | |
2473 | DBX_STRINGTAB_SIZE (objfile)); /* amount to read */ | |
2474 | ||
2475 | if (!val) | |
2476 | perror_with_name (name); | |
2477 | ||
2478 | stabsread_new_init (); | |
2479 | buildsym_new_init (); | |
2480 | free_header_files (); | |
2481 | init_header_files (); | |
2482 | install_minimal_symbols (objfile); | |
2483 | ||
2484 | /* Now, do an incremental load */ | |
2485 | ||
2486 | processing_acc_compilation = 1; | |
2487 | dbx_symfile_read (objfile, section_offsets, 0); | |
2488 | } | |
2489 | \f | |
2af231b8 JG |
2490 | /* Parse the user's idea of an offset for dynamic linking, into our idea |
2491 | of how to represent it for fast symbol reading. */ | |
2492 | ||
040b9597 | 2493 | static struct section_offsets * |
2af231b8 JG |
2494 | dbx_symfile_offsets (objfile, addr) |
2495 | struct objfile *objfile; | |
2496 | CORE_ADDR addr; | |
2497 | { | |
2498 | struct section_offsets *section_offsets; | |
2499 | int i; | |
4d57c599 JK |
2500 | |
2501 | objfile->num_sections = SECT_OFF_MAX; | |
2af231b8 JG |
2502 | section_offsets = (struct section_offsets *) |
2503 | obstack_alloc (&objfile -> psymbol_obstack, | |
4d57c599 JK |
2504 | sizeof (struct section_offsets) |
2505 | + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1)); | |
2af231b8 JG |
2506 | |
2507 | for (i = 0; i < SECT_OFF_MAX; i++) | |
2508 | ANOFFSET (section_offsets, i) = addr; | |
2509 | ||
2510 | return section_offsets; | |
9342ecb9 JG |
2511 | } |
2512 | \f | |
80d68b1d FF |
2513 | static struct sym_fns aout_sym_fns = |
2514 | { | |
0eed42de | 2515 | bfd_target_aout_flavour, |
80d68b1d FF |
2516 | dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */ |
2517 | dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
2518 | dbx_symfile_read, /* sym_read: read a symbol file into symtab */ | |
2519 | dbx_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
2af231b8 | 2520 | dbx_symfile_offsets, /* sym_offsets: parse user's offsets to internal form */ |
80d68b1d FF |
2521 | NULL /* next: pointer to next struct sym_fns */ |
2522 | }; | |
bd5635a1 RP |
2523 | |
2524 | void | |
2525 | _initialize_dbxread () | |
2526 | { | |
bd5635a1 | 2527 | add_symtab_fns(&aout_sym_fns); |
bd5635a1 | 2528 | } |