]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Read dbx symbol tables and convert to internal format, for GDB. |
c55e6167 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
c3a21801 | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
c3a21801 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
c3a21801 | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
c3a21801 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
9404978d MT |
19 | |
20 | /* This module provides three functions: dbx_symfile_init, | |
21 | which initializes to read a symbol file; dbx_new_init, which | |
22 | discards existing cached information when all symbols are being | |
23 | discarded; and dbx_symfile_read, which reads a symbol table | |
24 | from a file. | |
25 | ||
26 | dbx_symfile_read only does the minimum work necessary for letting the | |
27 | user "name" things symbolically; it does not read the entire symtab. | |
28 | Instead, it reads the external and static symbols and puts them in partial | |
29 | symbol tables. When more extensive information is requested of a | |
30 | file, the corresponding partial symbol table is mutated into a full | |
31 | fledged symbol table by going back and reading the symbols | |
32 | for real. dbx_psymtab_to_symtab() is the function that does this */ | |
bd5635a1 | 33 | |
bd5635a1 RP |
34 | #include <stdio.h> |
35 | #include <string.h> | |
36 | #include "defs.h" | |
bd5635a1 RP |
37 | |
38 | #ifdef USG | |
39 | #include <sys/types.h> | |
40 | #include <fcntl.h> | |
41 | #define L_SET 0 | |
42 | #define L_INCR 1 | |
43 | #endif | |
44 | ||
afe4ca15 JG |
45 | #include <obstack.h> |
46 | #include <sys/param.h> | |
47 | #include <sys/file.h> | |
48 | #include <sys/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" | |
c0302457 | 57 | #include "buildsym.h" |
afe4ca15 | 58 | |
7e258d18 PB |
59 | #include "aout/aout64.h" |
60 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */ | |
bd5635a1 | 61 | |
c0302457 JG |
62 | /* Information is passed among various dbxread routines for accessing |
63 | symbol files. A pointer to this structure is kept in the sym_private | |
64 | field of the struct sym_fns passed in by symfile.h. */ | |
65 | ||
bd5635a1 RP |
66 | struct dbx_symfile_info { |
67 | asection *text_sect; /* Text section accessor */ | |
68 | int symcount; /* How many symbols are there in the file */ | |
69 | char *stringtab; /* The actual string table */ | |
70 | int stringtab_size; /* Its size */ | |
71 | off_t symtab_offset; /* Offset in file to symbol table */ | |
bd5635a1 RP |
72 | }; |
73 | ||
c0302457 | 74 | |
4a35d6e9 FF |
75 | /* Each partial symbol table entry contains a pointer to private data for the |
76 | read_symtab() function to use when expanding a partial symbol table entry | |
77 | to a full symbol table entry. | |
78 | ||
79 | For dbxread this structure contains the offset within the file symbol table | |
80 | of first local symbol for this file, and length (in bytes) of the section | |
81 | of the symbol table devoted to this file's symbols (actually, the section | |
82 | bracketed may contain more than just this file's symbols). If ldsymlen is | |
83 | 0, the only reason for this thing's existence is the dependency list. | |
84 | Nothing else will happen when it is read in. */ | |
85 | ||
86 | #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) | |
87 | #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen) | |
88 | ||
89 | struct symloc { | |
90 | int ldsymoff; | |
91 | int ldsymlen; | |
92 | }; | |
93 | ||
bd5635a1 RP |
94 | extern void qsort (); |
95 | extern double atof (); | |
bd5635a1 RP |
96 | |
97 | /* Forward declarations */ | |
98 | ||
bd5635a1 RP |
99 | static void read_dbx_symtab (); |
100 | static void init_psymbol_list (); | |
7e258d18 | 101 | extern void process_one_symbol (); |
c0302457 JG |
102 | void start_subfile (); |
103 | int hashname (); | |
bd5635a1 | 104 | static struct pending *copy_pending (); |
9404978d | 105 | static struct symtab *read_ofile_symtab (); |
bd5635a1 RP |
106 | static void dbx_psymtab_to_symtab (); |
107 | ||
bd5635a1 RP |
108 | /* Macro to determine which symbols to ignore when reading the first symbol |
109 | of a file. Some machines override this definition. */ | |
110 | #ifndef IGNORE_SYMBOL | |
111 | /* This code is used on Ultrix systems. Ignore it */ | |
112 | #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS) | |
113 | #endif | |
114 | ||
115 | /* Macro for name of symbol to indicate a file compiled with gcc. */ | |
116 | #ifndef GCC_COMPILED_FLAG_SYMBOL | |
117 | #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled." | |
118 | #endif | |
119 | ||
0cf9329b PB |
120 | /* Macro for name of symbol to indicate a file compiled with gcc2. */ |
121 | #ifndef GCC2_COMPILED_FLAG_SYMBOL | |
122 | #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled." | |
123 | #endif | |
124 | ||
bd5635a1 RP |
125 | /* Define this as 1 if a pcc declaration of a char or short argument |
126 | gives the correct address. Otherwise assume pcc gives the | |
127 | address of the corresponding int, which is not the same on a | |
128 | big-endian machine. */ | |
129 | ||
130 | #ifndef BELIEVE_PCC_PROMOTION | |
131 | #define BELIEVE_PCC_PROMOTION 0 | |
132 | #endif | |
c0302457 | 133 | |
bd5635a1 RP |
134 | /* Nonzero means give verbose info on gdb action. From main.c. */ |
135 | extern int info_verbose; | |
136 | ||
7d9884b9 | 137 | /* The BFD for this file -- implicit parameter to next_symbol_text. */ |
bd5635a1 | 138 | |
c0302457 | 139 | static bfd *symfile_bfd; |
bd5635a1 | 140 | |
7d9884b9 JG |
141 | /* The objfile for this file -- only good in process_one_symbol(). */ |
142 | ||
143 | static struct objfile *our_objfile; | |
144 | ||
bd5635a1 RP |
145 | /* String table for the main symbol file. It is kept in memory |
146 | permanently, to speed up symbol reading. Other files' symbol tables | |
147 | are read in on demand. FIXME, this should be cleaner. */ | |
148 | ||
149 | static char *symfile_string_table; | |
150 | static int symfile_string_table_size; | |
151 | ||
afe4ca15 JG |
152 | /* The size of each symbol in the symbol file (in external form). |
153 | This is set by dbx_symfile_read when building psymtabs, and by | |
154 | dbx_psymtab_to_symtab when building symtabs. */ | |
155 | ||
156 | static unsigned symbol_size; | |
157 | ||
bd5635a1 RP |
158 | /* Complaints about the symbols we have encountered. */ |
159 | ||
bd5635a1 RP |
160 | struct complaint lbrac_complaint = |
161 | {"bad block start address patched", 0, 0}; | |
162 | ||
bd5635a1 RP |
163 | struct complaint string_table_offset_complaint = |
164 | {"bad string table offset in symbol %d", 0, 0}; | |
165 | ||
166 | struct complaint unknown_symtype_complaint = | |
0c4d2cc2 | 167 | {"unknown symbol type %s", 0, 0}; |
bd5635a1 RP |
168 | |
169 | struct complaint lbrac_rbrac_complaint = | |
170 | {"block start larger than block end", 0, 0}; | |
7d9884b9 JG |
171 | |
172 | struct complaint lbrac_unmatched_complaint = | |
173 | {"unmatched N_LBRAC before symtab pos %d", 0, 0}; | |
174 | ||
175 | struct complaint lbrac_mismatch_complaint = | |
176 | {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0}; | |
bd5635a1 | 177 | \f |
bd5635a1 RP |
178 | /* During initial symbol readin, we need to have a structure to keep |
179 | track of which psymtabs have which bincls in them. This structure | |
180 | is used during readin to setup the list of dependencies within each | |
181 | partial symbol table. */ | |
182 | ||
183 | struct header_file_location | |
184 | { | |
185 | char *name; /* Name of header file */ | |
186 | int instance; /* See above */ | |
187 | struct partial_symtab *pst; /* Partial symtab that has the | |
188 | BINCL/EINCL defs for this file */ | |
189 | }; | |
190 | ||
191 | /* The actual list and controling variables */ | |
192 | static struct header_file_location *bincl_list, *next_bincl; | |
193 | static int bincls_allocated; | |
194 | ||
bd5635a1 RP |
195 | /* Free up old header file tables, and allocate new ones. |
196 | We're reading a new symbol file now. */ | |
197 | ||
c0302457 | 198 | void |
bd5635a1 RP |
199 | free_and_init_header_files () |
200 | { | |
201 | register int i; | |
202 | for (i = 0; i < n_header_files; i++) | |
203 | free (header_files[i].name); | |
204 | if (header_files) /* First time null */ | |
205 | free (header_files); | |
206 | if (this_object_header_files) /* First time null */ | |
207 | free (this_object_header_files); | |
208 | ||
209 | n_allocated_header_files = 10; | |
210 | header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file)); | |
211 | n_header_files = 0; | |
212 | ||
213 | n_allocated_this_object_header_files = 10; | |
214 | this_object_header_files = (int *) xmalloc (10 * sizeof (int)); | |
215 | } | |
216 | ||
217 | /* Called at the start of each object file's symbols. | |
218 | Clear out the mapping of header file numbers to header files. */ | |
219 | ||
c0302457 | 220 | void |
bd5635a1 RP |
221 | new_object_header_files () |
222 | { | |
223 | /* Leave FILENUM of 0 free for builtin types and this file's types. */ | |
224 | n_this_object_header_files = 1; | |
225 | header_file_prev_index = -1; | |
226 | } | |
227 | ||
228 | /* Add header file number I for this object file | |
229 | at the next successive FILENUM. */ | |
230 | ||
231 | static void | |
232 | add_this_object_header_file (i) | |
233 | int i; | |
234 | { | |
235 | if (n_this_object_header_files == n_allocated_this_object_header_files) | |
236 | { | |
237 | n_allocated_this_object_header_files *= 2; | |
238 | this_object_header_files | |
239 | = (int *) xrealloc (this_object_header_files, | |
240 | n_allocated_this_object_header_files * sizeof (int)); | |
241 | } | |
242 | ||
243 | this_object_header_files[n_this_object_header_files++] = i; | |
244 | } | |
245 | ||
246 | /* Add to this file an "old" header file, one already seen in | |
247 | a previous object file. NAME is the header file's name. | |
248 | INSTANCE is its instance code, to select among multiple | |
249 | symbol tables for the same header file. */ | |
250 | ||
251 | static void | |
252 | add_old_header_file (name, instance) | |
253 | char *name; | |
254 | int instance; | |
255 | { | |
256 | register struct header_file *p = header_files; | |
257 | register int i; | |
258 | ||
259 | for (i = 0; i < n_header_files; i++) | |
260 | if (!strcmp (p[i].name, name) && instance == p[i].instance) | |
261 | { | |
262 | add_this_object_header_file (i); | |
263 | return; | |
264 | } | |
265 | error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.", | |
266 | symnum); | |
267 | } | |
268 | ||
269 | /* Add to this file a "new" header file: definitions for its types follow. | |
270 | NAME is the header file's name. | |
271 | Most often this happens only once for each distinct header file, | |
272 | but not necessarily. If it happens more than once, INSTANCE has | |
273 | a different value each time, and references to the header file | |
274 | use INSTANCE values to select among them. | |
275 | ||
276 | dbx output contains "begin" and "end" markers for each new header file, | |
277 | but at this level we just need to know which files there have been; | |
278 | so we record the file when its "begin" is seen and ignore the "end". */ | |
279 | ||
280 | static void | |
281 | add_new_header_file (name, instance) | |
282 | char *name; | |
283 | int instance; | |
284 | { | |
285 | register int i; | |
286 | header_file_prev_index = -1; | |
287 | ||
288 | /* Make sure there is room for one more header file. */ | |
289 | ||
290 | if (n_header_files == n_allocated_header_files) | |
291 | { | |
292 | n_allocated_header_files *= 2; | |
293 | header_files = (struct header_file *) | |
294 | xrealloc (header_files, | |
295 | (n_allocated_header_files | |
296 | * sizeof (struct header_file))); | |
297 | } | |
298 | ||
299 | /* Create an entry for this header file. */ | |
300 | ||
301 | i = n_header_files++; | |
302 | header_files[i].name = savestring (name, strlen(name)); | |
303 | header_files[i].instance = instance; | |
304 | header_files[i].length = 10; | |
305 | header_files[i].vector | |
306 | = (struct type **) xmalloc (10 * sizeof (struct type *)); | |
307 | bzero (header_files[i].vector, 10 * sizeof (struct type *)); | |
308 | ||
309 | add_this_object_header_file (i); | |
310 | } | |
311 | ||
bd5635a1 RP |
312 | #if 0 |
313 | static struct type ** | |
314 | explicit_lookup_type (real_filenum, index) | |
315 | int real_filenum, index; | |
316 | { | |
317 | register struct header_file *f = &header_files[real_filenum]; | |
318 | ||
319 | if (index >= f->length) | |
320 | { | |
321 | f->length *= 2; | |
322 | f->vector = (struct type **) | |
323 | xrealloc (f->vector, f->length * sizeof (struct type *)); | |
324 | bzero (&f->vector[f->length / 2], | |
325 | f->length * sizeof (struct type *) / 2); | |
326 | } | |
327 | return &f->vector[index]; | |
328 | } | |
329 | #endif | |
330 | \f | |
9bba3334 | 331 | static void |
bd5635a1 RP |
332 | record_misc_function (name, address, type) |
333 | char *name; | |
334 | CORE_ADDR address; | |
335 | int type; | |
336 | { | |
0c4d2cc2 JG |
337 | enum misc_function_type misc_type; |
338 | ||
339 | switch (type &~ N_EXT) { | |
340 | case N_TEXT: misc_type = mf_text; break; | |
341 | case N_DATA: misc_type = mf_data; break; | |
342 | case N_BSS: misc_type = mf_bss; break; | |
343 | case N_ABS: misc_type = mf_abs; break; | |
344 | #ifdef N_SETV | |
345 | case N_SETV: misc_type = mf_data; break; | |
346 | #endif | |
347 | default: misc_type = mf_unknown; break; | |
348 | } | |
bd5635a1 RP |
349 | |
350 | prim_record_misc_function (obsavestring (name, strlen (name)), | |
351 | address, misc_type); | |
352 | } | |
353 | \f | |
354 | /* Scan and build partial symbols for a symbol file. | |
355 | We have been initialized by a call to dbx_symfile_init, which | |
356 | put all the relevant info into a "struct dbx_symfile_info" | |
357 | hung off the struct sym_fns SF. | |
358 | ||
359 | ADDR is the address relative to which the symbols in it are (e.g. | |
360 | the base address of the text segment). | |
361 | MAINLINE is true if we are reading the main symbol | |
362 | table (as opposed to a shared lib or dynamically loaded file). */ | |
363 | ||
9bba3334 | 364 | static void |
bd5635a1 RP |
365 | dbx_symfile_read (sf, addr, mainline) |
366 | struct sym_fns *sf; | |
367 | CORE_ADDR addr; | |
368 | int mainline; /* FIXME comments above */ | |
369 | { | |
370 | struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private); | |
7d9884b9 | 371 | bfd *sym_bfd = sf->objfile->obfd; |
bd5635a1 | 372 | int val; |
bd5635a1 | 373 | |
7d9884b9 | 374 | val = bfd_seek (sf->objfile->obfd, info->symtab_offset, L_SET); |
bd5635a1 | 375 | if (val < 0) |
7d9884b9 | 376 | perror_with_name (sf->objfile->name); |
bd5635a1 RP |
377 | |
378 | /* If mainline, set global string table pointers, and reinitialize global | |
379 | partial symbol list. */ | |
380 | if (mainline) { | |
381 | symfile_string_table = info->stringtab; | |
382 | symfile_string_table_size = info->stringtab_size; | |
bd5635a1 RP |
383 | } |
384 | ||
66eeea27 JG |
385 | /* If we are reinitializing, or if we have never loaded syms yet, init */ |
386 | if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0) | |
387 | init_psymbol_list (info->symcount); | |
388 | ||
afe4ca15 JG |
389 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ |
390 | symbol_size = obj_symbol_entry_size (sym_bfd); | |
391 | ||
bd5635a1 RP |
392 | pending_blocks = 0; |
393 | make_cleanup (really_free_pendings, 0); | |
394 | ||
395 | init_misc_bunches (); | |
396 | make_cleanup (discard_misc_bunches, 0); | |
397 | ||
398 | /* Now that the symbol table data of the executable file are all in core, | |
399 | process them and define symbols accordingly. */ | |
400 | ||
7d9884b9 JG |
401 | read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/ |
402 | sf->objfile, info->stringtab, info->stringtab_size, | |
bd5635a1 RP |
403 | info->symcount, |
404 | bfd_section_vma (sym_bfd, info->text_sect), | |
405 | bfd_section_size (sym_bfd, info->text_sect)); | |
406 | ||
407 | /* Go over the misc symbol bunches and install them in vector. */ | |
408 | ||
409 | condense_misc_bunches (!mainline); | |
410 | ||
411 | /* Free up any memory we allocated for ourselves. */ | |
412 | ||
413 | if (!mainline) { | |
414 | free (info->stringtab); /* Stringtab is only saved for mainline */ | |
415 | } | |
416 | free (info); | |
417 | sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */ | |
418 | ||
9404978d MT |
419 | if (!partial_symtab_list) { |
420 | wrap_here (""); | |
421 | printf_filtered ("(no debugging symbols found)..."); | |
422 | wrap_here (""); | |
423 | } | |
bd5635a1 RP |
424 | } |
425 | ||
9404978d MT |
426 | /* Initialize anything that needs initializing when a completely new |
427 | symbol file is specified (not just adding some symbols from another | |
428 | file, e.g. a shared library). */ | |
bd5635a1 | 429 | |
9bba3334 | 430 | static void |
9404978d | 431 | dbx_new_init () |
bd5635a1 | 432 | { |
c0302457 | 433 | buildsym_new_init (); |
bd5635a1 | 434 | |
bd5635a1 | 435 | /* Don't put these on the cleanup chain; they need to stick around |
9404978d | 436 | until the next call to dbx_new_init. *Then* we'll free them. */ |
bd5635a1 RP |
437 | if (symfile_string_table) |
438 | { | |
439 | free (symfile_string_table); | |
440 | symfile_string_table = 0; | |
441 | symfile_string_table_size = 0; | |
442 | } | |
443 | free_and_init_header_files (); | |
444 | } | |
445 | ||
446 | ||
447 | /* dbx_symfile_init () | |
448 | is the dbx-specific initialization routine for reading symbols. | |
449 | It is passed a struct sym_fns which contains, among other things, | |
450 | the BFD for the file whose symbols are being read, and a slot for a pointer | |
451 | to "private data" which we fill with goodies. | |
452 | ||
453 | We read the string table into malloc'd space and stash a pointer to it. | |
454 | ||
455 | Since BFD doesn't know how to read debug symbols in a format-independent | |
456 | way (and may never do so...), we have to do it ourselves. We will never | |
457 | be called unless this is an a.out (or very similar) file. | |
458 | FIXME, there should be a cleaner peephole into the BFD environment here. */ | |
459 | ||
9bba3334 | 460 | static void |
bd5635a1 RP |
461 | dbx_symfile_init (sf) |
462 | struct sym_fns *sf; | |
463 | { | |
464 | int val; | |
7d9884b9 | 465 | bfd *sym_bfd = sf->objfile->obfd; |
bd5635a1 RP |
466 | char *name = bfd_get_filename (sym_bfd); |
467 | struct dbx_symfile_info *info; | |
468 | unsigned char size_temp[4]; | |
469 | ||
470 | /* Allocate struct to keep track of the symfile */ | |
c0302457 | 471 | sf->sym_private = xmalloc (sizeof (*info)); |
bd5635a1 RP |
472 | info = (struct dbx_symfile_info *)sf->sym_private; |
473 | ||
474 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
bd5635a1 RP |
475 | #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd)) |
476 | #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd)) | |
477 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
478 | ||
bd5635a1 RP |
479 | info->text_sect = bfd_get_section_by_name (sym_bfd, ".text"); |
480 | if (!info->text_sect) | |
481 | abort(); | |
63989338 | 482 | info->symcount = bfd_get_symcount (sym_bfd); |
bd5635a1 RP |
483 | |
484 | /* Read the string table size and check it for bogosity. */ | |
7d9884b9 | 485 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET); |
bd5635a1 RP |
486 | if (val < 0) |
487 | perror_with_name (name); | |
bd5635a1 | 488 | |
7d9884b9 | 489 | val = bfd_read (size_temp, sizeof (long), 1, sym_bfd); |
bd5635a1 RP |
490 | if (val < 0) |
491 | perror_with_name (name); | |
dcc35536 | 492 | info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp); |
bd5635a1 | 493 | |
7d9884b9 | 494 | if (info->stringtab_size >= 0) |
bd5635a1 RP |
495 | { |
496 | info->stringtab = (char *) xmalloc (info->stringtab_size); | |
497 | /* Caller is responsible for freeing the string table. No cleanup. */ | |
498 | } | |
499 | else | |
500 | info->stringtab = NULL; | |
501 | if (info->stringtab == NULL && info->stringtab_size != 0) | |
502 | error ("ridiculous string table size: %d bytes", info->stringtab_size); | |
503 | ||
504 | /* Now read in the string table in one big gulp. */ | |
505 | ||
7d9884b9 | 506 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET); |
bd5635a1 RP |
507 | if (val < 0) |
508 | perror_with_name (name); | |
7d9884b9 JG |
509 | val = bfd_read (info->stringtab, info->stringtab_size, 1, sym_bfd); |
510 | if (val != info->stringtab_size) | |
bd5635a1 RP |
511 | perror_with_name (name); |
512 | ||
513 | /* Record the position of the symbol table for later use. */ | |
514 | ||
515 | info->symtab_offset = SYMBOL_TABLE_OFFSET; | |
516 | } | |
517 | \f | |
518 | /* Buffer for reading the symbol table entries. */ | |
afe4ca15 | 519 | static struct internal_nlist symbuf[4096]; |
bd5635a1 RP |
520 | static int symbuf_idx; |
521 | static int symbuf_end; | |
522 | ||
bd5635a1 RP |
523 | /* The address in memory of the string table of the object file we are |
524 | reading (which might not be the "main" object file, but might be a | |
525 | shared library or some other dynamically loaded thing). This is set | |
526 | by read_dbx_symtab when building psymtabs, and by read_ofile_symtab | |
527 | when building symtabs, and is used only by next_symbol_text. */ | |
528 | static char *stringtab_global; | |
529 | ||
530 | /* Refill the symbol table input buffer | |
531 | and set the variables that control fetching entries from it. | |
532 | Reports an error if no data available. | |
533 | This function can read past the end of the symbol table | |
534 | (into the string table) but this does no harm. */ | |
535 | ||
7d9884b9 JG |
536 | static void |
537 | fill_symbuf (sym_bfd) | |
538 | bfd *sym_bfd; | |
bd5635a1 | 539 | { |
7d9884b9 | 540 | int nbytes = bfd_read (symbuf, sizeof (symbuf), 1, sym_bfd); |
bd5635a1 | 541 | if (nbytes < 0) |
7d9884b9 | 542 | perror_with_name (bfd_get_filename (sym_bfd)); |
bd5635a1 RP |
543 | else if (nbytes == 0) |
544 | error ("Premature end of file reading symbol table"); | |
afe4ca15 | 545 | symbuf_end = nbytes / symbol_size; |
bd5635a1 | 546 | symbuf_idx = 0; |
bd5635a1 RP |
547 | } |
548 | ||
7d9884b9 | 549 | #define SWAP_SYMBOL(symp, abfd) \ |
bd5635a1 | 550 | { \ |
7d9884b9 | 551 | (symp)->n_strx = bfd_h_get_32(abfd, \ |
afe4ca15 | 552 | (unsigned char *)&(symp)->n_strx); \ |
7d9884b9 | 553 | (symp)->n_desc = bfd_h_get_16 (abfd, \ |
bd5635a1 | 554 | (unsigned char *)&(symp)->n_desc); \ |
7d9884b9 | 555 | (symp)->n_value = bfd_h_get_32 (abfd, \ |
bd5635a1 RP |
556 | (unsigned char *)&(symp)->n_value); \ |
557 | } | |
558 | ||
559 | /* Invariant: The symbol pointed to by symbuf_idx is the first one | |
560 | that hasn't been swapped. Swap the symbol at the same time | |
561 | that symbuf_idx is incremented. */ | |
562 | ||
563 | /* dbx allows the text of a symbol name to be continued into the | |
564 | next symbol name! When such a continuation is encountered | |
565 | (a \ at the end of the text of a name) | |
566 | call this function to get the continuation. */ | |
567 | ||
c0302457 | 568 | char * |
aab77d5f | 569 | dbx_next_symbol_text () |
bd5635a1 RP |
570 | { |
571 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 572 | fill_symbuf (symfile_bfd); |
bd5635a1 | 573 | symnum++; |
7d9884b9 | 574 | SWAP_SYMBOL(&symbuf[symbuf_idx], symfile_bfd); |
afe4ca15 | 575 | return symbuf[symbuf_idx++].n_strx + stringtab_global; |
bd5635a1 RP |
576 | } |
577 | \f | |
578 | /* Initializes storage for all of the partial symbols that will be | |
579 | created by read_dbx_symtab and subsidiaries. */ | |
580 | ||
581 | static void | |
582 | init_psymbol_list (total_symbols) | |
583 | int total_symbols; | |
584 | { | |
585 | /* Free any previously allocated psymbol lists. */ | |
586 | if (global_psymbols.list) | |
587 | free (global_psymbols.list); | |
588 | if (static_psymbols.list) | |
589 | free (static_psymbols.list); | |
590 | ||
591 | /* Current best guess is that there are approximately a twentieth | |
592 | of the total symbols (in a debugging file) are global or static | |
593 | oriented symbols */ | |
594 | global_psymbols.size = total_symbols / 10; | |
595 | static_psymbols.size = total_symbols / 10; | |
596 | global_psymbols.next = global_psymbols.list = (struct partial_symbol *) | |
597 | xmalloc (global_psymbols.size * sizeof (struct partial_symbol)); | |
598 | static_psymbols.next = static_psymbols.list = (struct partial_symbol *) | |
599 | xmalloc (static_psymbols.size * sizeof (struct partial_symbol)); | |
600 | } | |
601 | ||
602 | /* Initialize the list of bincls to contain none and have some | |
603 | allocated. */ | |
604 | ||
605 | static void | |
606 | init_bincl_list (number) | |
607 | int number; | |
608 | { | |
609 | bincls_allocated = number; | |
610 | next_bincl = bincl_list = (struct header_file_location *) | |
611 | xmalloc (bincls_allocated * sizeof(struct header_file_location)); | |
612 | } | |
613 | ||
614 | /* Add a bincl to the list. */ | |
615 | ||
616 | static void | |
617 | add_bincl_to_list (pst, name, instance) | |
618 | struct partial_symtab *pst; | |
619 | char *name; | |
620 | int instance; | |
621 | { | |
622 | if (next_bincl >= bincl_list + bincls_allocated) | |
623 | { | |
624 | int offset = next_bincl - bincl_list; | |
625 | bincls_allocated *= 2; | |
626 | bincl_list = (struct header_file_location *) | |
627 | xrealloc ((char *)bincl_list, | |
628 | bincls_allocated * sizeof (struct header_file_location)); | |
629 | next_bincl = bincl_list + offset; | |
630 | } | |
631 | next_bincl->pst = pst; | |
632 | next_bincl->instance = instance; | |
633 | next_bincl++->name = name; | |
634 | } | |
635 | ||
636 | /* Given a name, value pair, find the corresponding | |
637 | bincl in the list. Return the partial symtab associated | |
638 | with that header_file_location. */ | |
639 | ||
9bba3334 | 640 | static struct partial_symtab * |
bd5635a1 RP |
641 | find_corresponding_bincl_psymtab (name, instance) |
642 | char *name; | |
643 | int instance; | |
644 | { | |
645 | struct header_file_location *bincl; | |
646 | ||
647 | for (bincl = bincl_list; bincl < next_bincl; bincl++) | |
648 | if (bincl->instance == instance | |
649 | && !strcmp (name, bincl->name)) | |
650 | return bincl->pst; | |
651 | ||
652 | return (struct partial_symtab *) 0; | |
653 | } | |
654 | ||
655 | /* Free the storage allocated for the bincl list. */ | |
656 | ||
657 | static void | |
658 | free_bincl_list () | |
659 | { | |
660 | free (bincl_list); | |
661 | bincls_allocated = 0; | |
662 | } | |
663 | ||
bd5635a1 RP |
664 | /* Given pointers to an a.out symbol table in core containing dbx |
665 | style data, setup partial_symtab's describing each source file for | |
666 | which debugging information is available. NLISTLEN is the number | |
667 | of symbols in the symbol table. All symbol names are given as | |
668 | offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of | |
669 | STRINGTAB. SYMFILE_NAME is the name of the file we are reading from | |
670 | and ADDR is its relocated address (if incremental) or 0 (if not). */ | |
671 | ||
672 | static void | |
7d9884b9 | 673 | read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen, |
bd5635a1 | 674 | text_addr, text_size) |
bd5635a1 | 675 | CORE_ADDR addr; |
7d9884b9 | 676 | struct objfile *objfile; |
bd5635a1 RP |
677 | register char *stringtab; |
678 | register long stringtab_size; | |
679 | register int nlistlen; | |
680 | CORE_ADDR text_addr; | |
681 | int text_size; | |
682 | { | |
afe4ca15 | 683 | register struct internal_nlist *bufp; |
bd5635a1 | 684 | register char *namestring; |
bd5635a1 RP |
685 | int nsl; |
686 | int past_first_source_file = 0; | |
687 | CORE_ADDR last_o_file_start = 0; | |
688 | struct cleanup *old_chain; | |
7d9884b9 | 689 | bfd *abfd; |
bd5635a1 RP |
690 | |
691 | /* End of the text segment of the executable file. */ | |
692 | CORE_ADDR end_of_text_addr; | |
693 | ||
694 | /* Current partial symtab */ | |
695 | struct partial_symtab *pst; | |
696 | ||
697 | /* List of current psymtab's include files */ | |
698 | char **psymtab_include_list; | |
699 | int includes_allocated; | |
700 | int includes_used; | |
701 | ||
702 | /* Index within current psymtab dependency list */ | |
703 | struct partial_symtab **dependency_list; | |
704 | int dependencies_used, dependencies_allocated; | |
705 | ||
706 | stringtab_global = stringtab; | |
707 | ||
708 | pst = (struct partial_symtab *) 0; | |
709 | ||
710 | includes_allocated = 30; | |
711 | includes_used = 0; | |
712 | psymtab_include_list = (char **) alloca (includes_allocated * | |
713 | sizeof (char *)); | |
714 | ||
715 | dependencies_allocated = 30; | |
716 | dependencies_used = 0; | |
717 | dependency_list = | |
718 | (struct partial_symtab **) alloca (dependencies_allocated * | |
719 | sizeof (struct partial_symtab *)); | |
720 | ||
7d9884b9 | 721 | old_chain = make_cleanup (free_objfile, objfile); |
bd5635a1 RP |
722 | |
723 | /* Init bincl list */ | |
724 | init_bincl_list (20); | |
725 | make_cleanup (free_bincl_list, 0); | |
726 | ||
727 | last_source_file = 0; | |
728 | ||
729 | #ifdef END_OF_TEXT_DEFAULT | |
730 | end_of_text_addr = END_OF_TEXT_DEFAULT; | |
731 | #else | |
5bc757e2 | 732 | end_of_text_addr = text_addr + addr + text_size; /* Relocate */ |
bd5635a1 RP |
733 | #endif |
734 | ||
7d9884b9 JG |
735 | symfile_bfd = objfile->obfd; /* For next_text_symbol */ |
736 | abfd = objfile->obfd; | |
bd5635a1 | 737 | symbuf_end = symbuf_idx = 0; |
aab77d5f | 738 | next_symbol_text_func = dbx_next_symbol_text; |
bd5635a1 RP |
739 | |
740 | for (symnum = 0; symnum < nlistlen; symnum++) | |
741 | { | |
742 | /* Get the symbol for this run and pull out some info */ | |
743 | QUIT; /* allow this to be interruptable */ | |
744 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 745 | fill_symbuf (abfd); |
bd5635a1 RP |
746 | bufp = &symbuf[symbuf_idx++]; |
747 | ||
748 | /* | |
749 | * Special case to speed up readin. | |
750 | */ | |
751 | if (bufp->n_type == (unsigned char)N_SLINE) continue; | |
752 | ||
7d9884b9 | 753 | SWAP_SYMBOL (bufp, abfd); |
bd5635a1 RP |
754 | |
755 | /* Ok. There is a lot of code duplicated in the rest of this | |
756 | switch statement (for efficiency reasons). Since I don't | |
757 | like duplicating code, I will do my penance here, and | |
758 | describe the code which is duplicated: | |
759 | ||
760 | *) The assignment to namestring. | |
761 | *) The call to strchr. | |
762 | *) The addition of a partial symbol the the two partial | |
763 | symbol lists. This last is a large section of code, so | |
764 | I've imbedded it in the following macro. | |
765 | */ | |
766 | ||
767 | /* Set namestring based on bufp. If the string table index is invalid, | |
768 | give a fake name, and print a single error message per symbol file read, | |
769 | rather than abort the symbol reading or flood the user with messages. */ | |
770 | #define SET_NAMESTRING()\ | |
7d9884b9 | 771 | if (((unsigned)bufp->n_strx) >= stringtab_size) { \ |
bd5635a1 RP |
772 | complain (&string_table_offset_complaint, symnum); \ |
773 | namestring = "foo"; \ | |
774 | } else \ | |
afe4ca15 | 775 | namestring = bufp->n_strx + stringtab |
bd5635a1 | 776 | |
7e258d18 PB |
777 | #define CUR_SYMBOL_TYPE bufp->n_type |
778 | #define CUR_SYMBOL_VALUE bufp->n_value | |
779 | #define DBXREAD_ONLY | |
7e258d18 PB |
780 | #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\ |
781 | start_psymtab(ofile, addr, fname, low, symoff, global_syms, static_syms) | |
782 | #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\ | |
783 | end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) | |
aab77d5f | 784 | |
7e258d18 | 785 | #include "partial-stab.h" |
bd5635a1 RP |
786 | } |
787 | ||
788 | /* If there's stuff to be cleaned up, clean it up. */ | |
63989338 JG |
789 | if (nlistlen > 0 /* We have some syms */ |
790 | && entry_point < bufp->n_value | |
bd5635a1 RP |
791 | && entry_point >= last_o_file_start) |
792 | { | |
793 | startup_file_start = last_o_file_start; | |
794 | startup_file_end = bufp->n_value; | |
795 | } | |
796 | ||
797 | if (pst) | |
798 | { | |
799 | end_psymtab (pst, psymtab_include_list, includes_used, | |
afe4ca15 | 800 | symnum * symbol_size, end_of_text_addr, |
7e258d18 | 801 | dependency_list, dependencies_used); |
bd5635a1 RP |
802 | } |
803 | ||
804 | free_bincl_list (); | |
805 | discard_cleanups (old_chain); | |
806 | } | |
807 | ||
4a35d6e9 FF |
808 | /* Allocate and partially fill a partial symtab. It will be |
809 | completely filled at the end of the symbol list. | |
810 | ||
811 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
812 | is the address relative to which its symbols are (incremental) or 0 | |
813 | (normal). */ | |
814 | ||
bd5635a1 | 815 | |
7e258d18 | 816 | struct partial_symtab * |
7d9884b9 | 817 | start_psymtab (objfile, addr, |
bd5635a1 | 818 | filename, textlow, ldsymoff, global_syms, static_syms) |
7d9884b9 | 819 | struct objfile *objfile; |
bd5635a1 RP |
820 | CORE_ADDR addr; |
821 | char *filename; | |
822 | CORE_ADDR textlow; | |
823 | int ldsymoff; | |
824 | struct partial_symbol *global_syms; | |
825 | struct partial_symbol *static_syms; | |
826 | { | |
827 | struct partial_symtab *result = | |
828 | (struct partial_symtab *) obstack_alloc (psymbol_obstack, | |
829 | sizeof (struct partial_symtab)); | |
830 | ||
831 | result->addr = addr; | |
832 | ||
bd5635a1 RP |
833 | result->filename = |
834 | (char *) obstack_alloc (psymbol_obstack, | |
835 | strlen (filename) + 1); | |
836 | strcpy (result->filename, filename); | |
837 | ||
838 | result->textlow = textlow; | |
4a35d6e9 FF |
839 | result->read_symtab_private = (char *) obstack_alloc (psymbol_obstack, |
840 | sizeof (struct symloc)); | |
7e258d18 PB |
841 | if (ldsymoff != -1) |
842 | LDSYMOFF(result) = ldsymoff; | |
bd5635a1 RP |
843 | |
844 | result->readin = 0; | |
845 | result->symtab = 0; | |
846 | result->read_symtab = dbx_psymtab_to_symtab; | |
847 | ||
848 | result->globals_offset = global_syms - global_psymbols.list; | |
849 | result->statics_offset = static_syms - static_psymbols.list; | |
850 | ||
851 | result->n_global_syms = 0; | |
852 | result->n_static_syms = 0; | |
853 | ||
7d9884b9 JG |
854 | /* Chain it to the list owned by the current object file. */ |
855 | result->objfile = objfile; | |
856 | result->objfile_chain = objfile->psymtabs; | |
857 | objfile->psymtabs = result; | |
bd5635a1 RP |
858 | |
859 | return result; | |
860 | } | |
861 | ||
862 | static int | |
863 | compare_psymbols (s1, s2) | |
864 | register struct partial_symbol *s1, *s2; | |
865 | { | |
866 | register char | |
867 | *st1 = SYMBOL_NAME (s1), | |
868 | *st2 = SYMBOL_NAME (s2); | |
869 | ||
0c4d2cc2 JG |
870 | if (st1[0] - st2[0]) |
871 | return st1[0] - st2[0]; | |
872 | if (st1[1] - st2[1]) | |
873 | return st1[1] - st2[1]; | |
7e258d18 | 874 | return strcmp (st1 + 2, st2 + 2); |
bd5635a1 RP |
875 | } |
876 | ||
bd5635a1 RP |
877 | /* Close off the current usage of a partial_symbol table entry. This |
878 | involves setting the correct number of includes (with a realloc), | |
879 | setting the high text mark, setting the symbol length in the | |
880 | executable, and setting the length of the global and static lists | |
881 | of psymbols. | |
882 | ||
883 | The global symbols and static symbols are then seperately sorted. | |
884 | ||
885 | Then the partial symtab is put on the global list. | |
886 | *** List variables and peculiarities of same. *** | |
887 | */ | |
7e258d18 | 888 | void |
bd5635a1 | 889 | end_psymtab (pst, include_list, num_includes, capping_symbol_offset, |
7e258d18 | 890 | capping_text, dependency_list, number_dependencies) |
bd5635a1 RP |
891 | struct partial_symtab *pst; |
892 | char **include_list; | |
893 | int num_includes; | |
894 | int capping_symbol_offset; | |
895 | CORE_ADDR capping_text; | |
896 | struct partial_symtab **dependency_list; | |
897 | int number_dependencies; | |
7e258d18 | 898 | /* struct partial_symbol *capping_global, *capping_static;*/ |
bd5635a1 RP |
899 | { |
900 | int i; | |
901 | ||
7e258d18 PB |
902 | if (capping_symbol_offset != -1) |
903 | LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst); | |
bd5635a1 RP |
904 | pst->texthigh = capping_text; |
905 | ||
906 | pst->n_global_syms = | |
7e258d18 | 907 | global_psymbols.next - (global_psymbols.list + pst->globals_offset); |
bd5635a1 | 908 | pst->n_static_syms = |
7e258d18 | 909 | static_psymbols.next - (static_psymbols.list + pst->statics_offset); |
bd5635a1 RP |
910 | |
911 | pst->number_of_dependencies = number_dependencies; | |
912 | if (number_dependencies) | |
913 | { | |
914 | pst->dependencies = (struct partial_symtab **) | |
915 | obstack_alloc (psymbol_obstack, | |
916 | number_dependencies * sizeof (struct partial_symtab *)); | |
7e258d18 | 917 | memcpy (pst->dependencies, dependency_list, |
bd5635a1 RP |
918 | number_dependencies * sizeof (struct partial_symtab *)); |
919 | } | |
920 | else | |
921 | pst->dependencies = 0; | |
922 | ||
923 | for (i = 0; i < num_includes; i++) | |
924 | { | |
bd5635a1 RP |
925 | struct partial_symtab *subpst = |
926 | (struct partial_symtab *) | |
927 | obstack_alloc (psymbol_obstack, | |
928 | sizeof (struct partial_symtab)); | |
929 | ||
930 | subpst->filename = | |
931 | (char *) obstack_alloc (psymbol_obstack, | |
932 | strlen (include_list[i]) + 1); | |
933 | strcpy (subpst->filename, include_list[i]); | |
934 | ||
7d9884b9 JG |
935 | /* Chain it to the list that this object file owns. */ |
936 | subpst->objfile = pst->objfile; | |
937 | subpst->objfile_chain = pst->objfile->psymtabs; | |
938 | pst->objfile->psymtabs = subpst; | |
939 | ||
bd5635a1 | 940 | subpst->addr = pst->addr; |
4a35d6e9 FF |
941 | subpst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack, |
942 | sizeof (struct symloc)); | |
943 | LDSYMOFF(subpst) = | |
944 | LDSYMLEN(subpst) = | |
bd5635a1 RP |
945 | subpst->textlow = |
946 | subpst->texthigh = 0; | |
947 | ||
3f83182d JG |
948 | /* We could save slight bits of space by only making one of these, |
949 | shared by the entire set of include files. FIXME-someday. */ | |
bd5635a1 RP |
950 | subpst->dependencies = (struct partial_symtab **) |
951 | obstack_alloc (psymbol_obstack, | |
952 | sizeof (struct partial_symtab *)); | |
953 | subpst->dependencies[0] = pst; | |
954 | subpst->number_of_dependencies = 1; | |
955 | ||
956 | subpst->globals_offset = | |
957 | subpst->n_global_syms = | |
958 | subpst->statics_offset = | |
959 | subpst->n_static_syms = 0; | |
960 | ||
961 | subpst->readin = 0; | |
9a822037 | 962 | subpst->symtab = 0; |
bd5635a1 RP |
963 | subpst->read_symtab = dbx_psymtab_to_symtab; |
964 | ||
965 | subpst->next = partial_symtab_list; | |
966 | partial_symtab_list = subpst; | |
967 | } | |
968 | ||
969 | /* Sort the global list; don't sort the static list */ | |
970 | qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms, | |
971 | sizeof (struct partial_symbol), compare_psymbols); | |
972 | ||
f9623881 JG |
973 | /* If there is already a psymtab or symtab for a file of this name, remove it. |
974 | (If there is a symtab, more drastic things also happen.) | |
975 | This happens in VxWorks. */ | |
976 | free_named_symtabs (pst->filename); | |
977 | ||
7d9884b9 JG |
978 | if (num_includes == 0 |
979 | && number_dependencies == 0 | |
980 | && pst->n_global_syms == 0 | |
981 | && pst->n_static_syms == 0) { | |
982 | /* Throw away this psymtab, it's empty. We can't deallocate it, since | |
983 | it is on the obstack, but we can forget to chain it on the list. */ | |
984 | ; | |
985 | } else { | |
986 | /* Put the psymtab on the psymtab list */ | |
987 | pst->next = partial_symtab_list; | |
988 | partial_symtab_list = pst; | |
989 | } | |
bd5635a1 RP |
990 | } |
991 | \f | |
992 | static void | |
7d9884b9 | 993 | psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset) |
bd5635a1 | 994 | struct partial_symtab *pst; |
bd5635a1 RP |
995 | char *stringtab; |
996 | int stringtab_size; | |
997 | int sym_offset; | |
998 | { | |
999 | struct cleanup *old_chain; | |
1000 | int i; | |
1001 | ||
1002 | if (!pst) | |
1003 | return; | |
1004 | ||
1005 | if (pst->readin) | |
1006 | { | |
1007 | fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
1008 | pst->filename); | |
1009 | return; | |
1010 | } | |
1011 | ||
afe4ca15 | 1012 | /* Read in all partial symtabs on which this one is dependent */ |
bd5635a1 RP |
1013 | for (i = 0; i < pst->number_of_dependencies; i++) |
1014 | if (!pst->dependencies[i]->readin) | |
1015 | { | |
1016 | /* Inform about additional files that need to be read in. */ | |
1017 | if (info_verbose) | |
1018 | { | |
1019 | fputs_filtered (" ", stdout); | |
1020 | wrap_here (""); | |
1021 | fputs_filtered ("and ", stdout); | |
1022 | wrap_here (""); | |
1023 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
1024 | wrap_here (""); /* Flush output */ | |
1025 | fflush (stdout); | |
1026 | } | |
7d9884b9 | 1027 | psymtab_to_symtab_1 (pst->dependencies[i], |
bd5635a1 RP |
1028 | stringtab, stringtab_size, sym_offset); |
1029 | } | |
1030 | ||
4a35d6e9 | 1031 | if (LDSYMLEN(pst)) /* Otherwise it's a dummy */ |
bd5635a1 RP |
1032 | { |
1033 | /* Init stuff necessary for reading in symbols */ | |
c0302457 | 1034 | buildsym_init (); |
bd5635a1 RP |
1035 | old_chain = make_cleanup (really_free_pendings, 0); |
1036 | ||
1037 | /* Read in this files symbols */ | |
7d9884b9 | 1038 | bfd_seek (pst->objfile->obfd, sym_offset, L_SET); |
9404978d | 1039 | pst->symtab = |
7d9884b9 | 1040 | read_ofile_symtab (pst->objfile, stringtab, stringtab_size, |
4a35d6e9 FF |
1041 | LDSYMOFF(pst), |
1042 | LDSYMLEN(pst), pst->textlow, | |
9404978d MT |
1043 | pst->texthigh - pst->textlow, pst->addr); |
1044 | sort_symtab_syms (pst->symtab); | |
bd5635a1 RP |
1045 | |
1046 | do_cleanups (old_chain); | |
1047 | } | |
1048 | ||
1049 | pst->readin = 1; | |
1050 | } | |
1051 | ||
1052 | /* | |
1053 | * Read in all of the symbols for a given psymtab for real. | |
1054 | * Be verbose about it if the user wants that. | |
1055 | */ | |
1056 | static void | |
1057 | dbx_psymtab_to_symtab (pst) | |
1058 | struct partial_symtab *pst; | |
1059 | { | |
bd5635a1 RP |
1060 | char *stringtab; |
1061 | int stsize, val; | |
bd5635a1 RP |
1062 | bfd *sym_bfd; |
1063 | long st_temp; | |
1064 | ||
1065 | if (!pst) | |
1066 | return; | |
1067 | ||
1068 | if (pst->readin) | |
1069 | { | |
1070 | fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
1071 | pst->filename); | |
1072 | return; | |
1073 | } | |
1074 | ||
4a35d6e9 | 1075 | if (LDSYMLEN(pst) || pst->number_of_dependencies) |
bd5635a1 RP |
1076 | { |
1077 | /* Print the message now, before reading the string table, | |
1078 | to avoid disconcerting pauses. */ | |
1079 | if (info_verbose) | |
1080 | { | |
1081 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
1082 | fflush (stdout); | |
1083 | } | |
1084 | ||
7d9884b9 | 1085 | sym_bfd = pst->objfile->obfd; |
bd5635a1 | 1086 | |
7d9884b9 | 1087 | /* We keep the string table for the main symfile resident in memory, but |
bd5635a1 | 1088 | not the string table for any other symbol files. */ |
7d9884b9 | 1089 | if (symfile_objfile != pst->objfile) |
bd5635a1 RP |
1090 | { |
1091 | /* Read in the string table */ | |
1092 | ||
1093 | /* FIXME, this uses internal BFD variables. See above in | |
1094 | dbx_symbol_file_open where the macro is defined! */ | |
7d9884b9 | 1095 | bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET); |
bd5635a1 | 1096 | |
7d9884b9 | 1097 | val = bfd_read (&st_temp, sizeof st_temp, 1, sym_bfd); |
bd5635a1 | 1098 | if (val < 0) |
7d9884b9 | 1099 | perror_with_name (pst->objfile->name); |
dcc35536 | 1100 | stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp); |
7d9884b9 JG |
1101 | #if 0 |
1102 | /* BFD doesn't provide a way to know the total file size, sigh */ | |
1103 | struct stat statbuf; | |
bd5635a1 | 1104 | if (fstat (desc, &statbuf) < 0) |
7d9884b9 | 1105 | perror_with_name (pst->objfile->name); |
bd5635a1 RP |
1106 | |
1107 | if (stsize >= 0 && stsize < statbuf.st_size) | |
7d9884b9 JG |
1108 | #else |
1109 | if (stsize >= 0) | |
1110 | #endif | |
bd5635a1 RP |
1111 | { |
1112 | #ifdef BROKEN_LARGE_ALLOCA | |
1113 | stringtab = (char *) xmalloc (stsize); | |
1114 | make_cleanup (free, stringtab); | |
1115 | #else | |
1116 | stringtab = (char *) alloca (stsize); | |
1117 | #endif | |
1118 | } | |
1119 | else | |
1120 | stringtab = NULL; | |
1121 | if (stringtab == NULL && stsize != 0) | |
1122 | error ("ridiculous string table size: %d bytes", stsize); | |
1123 | ||
1124 | /* FIXME, this uses internal BFD variables. See above in | |
1125 | dbx_symbol_file_open where the macro is defined! */ | |
7d9884b9 | 1126 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET); |
bd5635a1 | 1127 | if (val < 0) |
7d9884b9 JG |
1128 | perror_with_name (pst->objfile->name); |
1129 | val = bfd_read (stringtab, stsize, 1, sym_bfd); | |
bd5635a1 | 1130 | if (val < 0) |
7d9884b9 | 1131 | perror_with_name (pst->objfile->name); |
bd5635a1 RP |
1132 | } |
1133 | else | |
1134 | { | |
1135 | stringtab = symfile_string_table; | |
1136 | stsize = symfile_string_table_size; | |
1137 | } | |
1138 | ||
afe4ca15 JG |
1139 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ |
1140 | symbol_size = obj_symbol_entry_size (sym_bfd); | |
bd5635a1 | 1141 | |
aab77d5f PB |
1142 | next_symbol_text_func = dbx_next_symbol_text; |
1143 | ||
bd5635a1 RP |
1144 | /* FIXME, this uses internal BFD variables. See above in |
1145 | dbx_symbol_file_open where the macro is defined! */ | |
7d9884b9 | 1146 | psymtab_to_symtab_1 (pst, stringtab, stsize, |
bd5635a1 RP |
1147 | SYMBOL_TABLE_OFFSET); |
1148 | ||
1149 | /* Match with global symbols. This only needs to be done once, | |
1150 | after all of the symtabs and dependencies have been read in. */ | |
1151 | scan_file_globals (); | |
1152 | ||
bd5635a1 RP |
1153 | /* Finish up the debug error message. */ |
1154 | if (info_verbose) | |
1155 | printf_filtered ("done.\n"); | |
1156 | } | |
1157 | } | |
1158 | ||
bd5635a1 RP |
1159 | /* |
1160 | * Read in a defined section of a specific object file's symbols. | |
1161 | * | |
1162 | * DESC is the file descriptor for the file, positioned at the | |
1163 | * beginning of the symtab | |
1164 | * STRINGTAB is a pointer to the files string | |
1165 | * table, already read in | |
1166 | * SYM_OFFSET is the offset within the file of | |
1167 | * the beginning of the symbols we want to read, NUM_SUMBOLS is the | |
1168 | * number of symbols to read | |
1169 | * TEXT_OFFSET is the beginning of the text segment we are reading symbols for | |
1170 | * TEXT_SIZE is the size of the text segment read in. | |
1171 | * OFFSET is a relocation offset which gets added to each symbol | |
1172 | */ | |
1173 | ||
9404978d | 1174 | static struct symtab * |
7d9884b9 | 1175 | read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset, |
bd5635a1 | 1176 | sym_size, text_offset, text_size, offset) |
7d9884b9 | 1177 | struct objfile *objfile; |
bd5635a1 RP |
1178 | register char *stringtab; |
1179 | unsigned int stringtab_size; | |
1180 | int sym_offset; | |
1181 | int sym_size; | |
1182 | CORE_ADDR text_offset; | |
1183 | int text_size; | |
1184 | int offset; | |
1185 | { | |
1186 | register char *namestring; | |
7d9884b9 | 1187 | register struct internal_nlist *bufp; |
bd5635a1 | 1188 | unsigned char type; |
afe4ca15 | 1189 | unsigned max_symnum; |
7d9884b9 JG |
1190 | register bfd *abfd; |
1191 | ||
bd5635a1 RP |
1192 | subfile_stack = 0; |
1193 | ||
1194 | stringtab_global = stringtab; | |
1195 | last_source_file = 0; | |
1196 | ||
7d9884b9 JG |
1197 | abfd = objfile->obfd; |
1198 | symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */ | |
1199 | our_objfile = objfile; /* For end_symtab calls in process_one_symbol */ | |
bd5635a1 RP |
1200 | symbuf_end = symbuf_idx = 0; |
1201 | ||
1202 | /* It is necessary to actually read one symbol *before* the start | |
1203 | of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL | |
1204 | occurs before the N_SO symbol. | |
1205 | ||
1206 | Detecting this in read_dbx_symtab | |
1207 | would slow down initial readin, so we look for it here instead. */ | |
afe4ca15 | 1208 | if (sym_offset >= (int)symbol_size) |
bd5635a1 | 1209 | { |
7d9884b9 JG |
1210 | bfd_seek (symfile_bfd, sym_offset - symbol_size, L_INCR); |
1211 | fill_symbuf (abfd); | |
bd5635a1 | 1212 | bufp = &symbuf[symbuf_idx++]; |
7d9884b9 | 1213 | SWAP_SYMBOL (bufp, abfd); |
bd5635a1 | 1214 | |
afe4ca15 | 1215 | SET_NAMESTRING (); |
bd5635a1 RP |
1216 | |
1217 | processing_gcc_compilation = | |
1218 | (bufp->n_type == N_TEXT | |
0cf9329b PB |
1219 | && (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0 |
1220 | || strcmp(namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)); | |
bd5635a1 RP |
1221 | } |
1222 | else | |
1223 | { | |
1224 | /* The N_SO starting this symtab is the first symbol, so we | |
1225 | better not check the symbol before it. I'm not this can | |
1226 | happen, but it doesn't hurt to check for it. */ | |
7d9884b9 | 1227 | bfd_seek (symfile_bfd, sym_offset, L_INCR); |
bd5635a1 RP |
1228 | processing_gcc_compilation = 0; |
1229 | } | |
1230 | ||
1231 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 1232 | fill_symbuf (abfd); |
bd5635a1 RP |
1233 | bufp = &symbuf[symbuf_idx]; |
1234 | if (bufp->n_type != (unsigned char)N_SO) | |
1235 | error("First symbol in segment of executable not a source symbol"); | |
1236 | ||
afe4ca15 JG |
1237 | max_symnum = sym_size / symbol_size; |
1238 | ||
bd5635a1 | 1239 | for (symnum = 0; |
afe4ca15 | 1240 | symnum < max_symnum; |
bd5635a1 RP |
1241 | symnum++) |
1242 | { | |
1243 | QUIT; /* Allow this to be interruptable */ | |
1244 | if (symbuf_idx == symbuf_end) | |
7d9884b9 | 1245 | fill_symbuf(abfd); |
bd5635a1 | 1246 | bufp = &symbuf[symbuf_idx++]; |
7d9884b9 | 1247 | SWAP_SYMBOL (bufp, abfd); |
bd5635a1 | 1248 | |
c0302457 | 1249 | type = bufp->n_type; |
bd5635a1 RP |
1250 | if (type == (unsigned char)N_CATCH) |
1251 | { | |
1252 | /* N_CATCH is not fixed up by the linker, and unfortunately, | |
1253 | there's no other place to put it in the .stab map. */ | |
c55e6167 | 1254 | bufp->n_value += text_offset - offset; |
bd5635a1 | 1255 | } |
bd5635a1 | 1256 | |
afe4ca15 | 1257 | SET_NAMESTRING (); |
bd5635a1 | 1258 | |
7d9884b9 | 1259 | if (type & N_STAB) { |
c55e6167 JG |
1260 | process_one_symbol (type, bufp->n_desc, bufp->n_value, |
1261 | namestring, offset); | |
1262 | /* our_objfile is an implicit parameter. */ | |
7d9884b9 | 1263 | } |
bd5635a1 RP |
1264 | /* We skip checking for a new .o or -l file; that should never |
1265 | happen in this routine. */ | |
1266 | else if (type == N_TEXT | |
0cf9329b PB |
1267 | && (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0 |
1268 | || strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)) | |
bd5635a1 RP |
1269 | /* I don't think this code will ever be executed, because |
1270 | the GCC_COMPILED_FLAG_SYMBOL usually is right before | |
1271 | the N_SO symbol which starts this source file. | |
1272 | However, there is no reason not to accept | |
1273 | the GCC_COMPILED_FLAG_SYMBOL anywhere. */ | |
1274 | processing_gcc_compilation = 1; | |
1275 | else if (type & N_EXT || type == (unsigned char)N_TEXT | |
1276 | || type == (unsigned char)N_NBTEXT | |
0c4d2cc2 | 1277 | ) { |
bd5635a1 RP |
1278 | /* Global symbol: see if we came across a dbx defintion for |
1279 | a corresponding symbol. If so, store the value. Remove | |
1280 | syms from the chain when their values are stored, but | |
1281 | search the whole chain, as there may be several syms from | |
1282 | different files with the same name. */ | |
1283 | /* This is probably not true. Since the files will be read | |
1284 | in one at a time, each reference to a global symbol will | |
1285 | be satisfied in each file as it appears. So we skip this | |
1286 | section. */ | |
1287 | ; | |
0c4d2cc2 | 1288 | } |
bd5635a1 | 1289 | } |
9404978d | 1290 | |
7d9884b9 | 1291 | return end_symtab (text_offset + text_size, 0, 0, objfile); |
bd5635a1 RP |
1292 | } |
1293 | \f | |
c0302457 | 1294 | int |
bd5635a1 RP |
1295 | hashname (name) |
1296 | char *name; | |
1297 | { | |
1298 | register char *p = name; | |
1299 | register int total = p[0]; | |
1300 | register int c; | |
1301 | ||
1302 | c = p[1]; | |
1303 | total += c << 2; | |
1304 | if (c) | |
1305 | { | |
1306 | c = p[2]; | |
1307 | total += c << 4; | |
1308 | if (c) | |
1309 | total += p[3] << 6; | |
1310 | } | |
1311 | ||
1312 | /* Ensure result is positive. */ | |
1313 | if (total < 0) total += (1000 << 6); | |
1314 | return total % HASHSIZE; | |
1315 | } | |
bd5635a1 | 1316 | \f |
c55e6167 JG |
1317 | /* This handles a single symbol from the symbol-file, building symbols |
1318 | into a GDB symtab. It takes these arguments and an implicit argument. | |
1319 | ||
1320 | TYPE is the type field of the ".stab" symbol entry. | |
1321 | DESC is the desc field of the ".stab" entry. | |
1322 | VALU is the value field of the ".stab" entry. | |
1323 | NAME is the symbol name, in our address space. | |
1324 | OFFSET is the amount by which this object file was relocated | |
1325 | when it was loaded into memory. All symbols that refer | |
1326 | to memory locations need to be offset by this amount. | |
1327 | ||
1328 | The implicit argument is: | |
1329 | OUR_OBJFILE is the object file from which we are reading symbols. | |
1330 | It is used in end_symtab. */ | |
1331 | ||
7e258d18 | 1332 | void |
c55e6167 | 1333 | process_one_symbol (type, desc, valu, name, offset) |
bd5635a1 RP |
1334 | int type, desc; |
1335 | CORE_ADDR valu; | |
1336 | char *name; | |
c55e6167 | 1337 | int offset; |
bd5635a1 RP |
1338 | { |
1339 | #ifndef SUN_FIXED_LBRAC_BUG | |
0cf9329b | 1340 | /* This records the last pc address we've seen. We depend on there being |
bd5635a1 RP |
1341 | an SLINE or FUN or SO before the first LBRAC, since the variable does |
1342 | not get reset in between reads of different symbol files. */ | |
1343 | static CORE_ADDR last_pc_address; | |
1344 | #endif | |
1345 | register struct context_stack *new; | |
1346 | char *colon_pos; | |
1347 | ||
1348 | /* Something is wrong if we see real data before | |
1349 | seeing a source file name. */ | |
1350 | ||
1351 | if (last_source_file == 0 && type != (unsigned char)N_SO) | |
1352 | { | |
1353 | /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines | |
1354 | where that code is defined. */ | |
1355 | if (IGNORE_SYMBOL (type)) | |
1356 | return; | |
1357 | ||
1358 | /* FIXME, this should not be an error, since it precludes extending | |
1359 | the symbol table information in this way... */ | |
1360 | error ("Invalid symbol data: does not start by identifying a source file."); | |
1361 | } | |
1362 | ||
1363 | switch (type) | |
1364 | { | |
1365 | case N_FUN: | |
1366 | case N_FNAME: | |
0bd83fd7 | 1367 | #if 0 |
3c03b5de SG |
1368 | /* It seems that the Sun ANSI C compiler (acc) replaces N_FUN with N_GSYM and |
1369 | N_STSYM with a type code of f or F. Can't enable this until we get some | |
0bd83fd7 SG |
1370 | stuff straightened out with psymtabs. */ |
1371 | ||
3c03b5de SG |
1372 | case N_GSYM: |
1373 | case N_STSYM: | |
0bd83fd7 | 1374 | #endif /* 0 */ |
3c03b5de | 1375 | |
c55e6167 JG |
1376 | valu += offset; /* Relocate for dynamic loading */ |
1377 | ||
bd5635a1 RP |
1378 | /* Either of these types of symbols indicates the start of |
1379 | a new function. We must process its "name" normally for dbx, | |
1380 | but also record the start of a new lexical context, and possibly | |
1381 | also the end of the lexical context for the previous function. */ | |
1382 | /* This is not always true. This type of symbol may indicate a | |
1383 | text segment variable. */ | |
1384 | ||
bd5635a1 RP |
1385 | colon_pos = strchr (name, ':'); |
1386 | if (!colon_pos++ | |
1387 | || (*colon_pos != 'f' && *colon_pos != 'F')) | |
1388 | { | |
1389 | define_symbol (valu, name, desc, type); | |
1390 | break; | |
1391 | } | |
1392 | ||
3c03b5de SG |
1393 | #ifndef SUN_FIXED_LBRAC_BUG |
1394 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
1395 | #endif | |
1396 | ||
bd5635a1 RP |
1397 | within_function = 1; |
1398 | if (context_stack_depth > 0) | |
1399 | { | |
7d9884b9 | 1400 | new = pop_context (); |
bd5635a1 RP |
1401 | /* Make a block for the local symbols within. */ |
1402 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1403 | new->start_addr, valu); | |
1404 | } | |
1405 | /* Stack must be empty now. */ | |
1406 | if (context_stack_depth != 0) | |
3c03b5de | 1407 | complain (&lbrac_unmatched_complaint, symnum); |
bd5635a1 | 1408 | |
7d9884b9 | 1409 | new = push_context (0, valu); |
bd5635a1 | 1410 | new->name = define_symbol (valu, name, desc, type); |
bd5635a1 RP |
1411 | break; |
1412 | ||
1413 | case N_CATCH: | |
1414 | /* Record the address at which this catch takes place. */ | |
c55e6167 | 1415 | define_symbol (valu+offset, name, desc, type); |
bd5635a1 RP |
1416 | break; |
1417 | ||
1418 | case N_LBRAC: | |
1419 | /* This "symbol" just indicates the start of an inner lexical | |
1420 | context within a function. */ | |
1421 | ||
c55e6167 JG |
1422 | #if defined (BLOCK_ADDRESS_ABSOLUTE) |
1423 | valu += offset; /* Relocate for dynamic loading */ | |
1424 | #else | |
bd5635a1 RP |
1425 | /* On most machines, the block addresses are relative to the |
1426 | N_SO, the linker did not relocate them (sigh). */ | |
1427 | valu += last_source_start_addr; | |
1428 | #endif | |
1429 | ||
1430 | #ifndef SUN_FIXED_LBRAC_BUG | |
1431 | if (valu < last_pc_address) { | |
1432 | /* Patch current LBRAC pc value to match last handy pc value */ | |
1433 | complain (&lbrac_complaint, 0); | |
1434 | valu = last_pc_address; | |
1435 | } | |
1436 | #endif | |
7d9884b9 | 1437 | new = push_context (desc, valu); |
bd5635a1 RP |
1438 | break; |
1439 | ||
1440 | case N_RBRAC: | |
1441 | /* This "symbol" just indicates the end of an inner lexical | |
1442 | context that was started with N_LBRAC. */ | |
1443 | ||
c55e6167 JG |
1444 | #if defined (BLOCK_ADDRESS_ABSOLUTE) |
1445 | valu += offset; /* Relocate for dynamic loading */ | |
1446 | #else | |
bd5635a1 RP |
1447 | /* On most machines, the block addresses are relative to the |
1448 | N_SO, the linker did not relocate them (sigh). */ | |
1449 | valu += last_source_start_addr; | |
1450 | #endif | |
1451 | ||
7d9884b9 | 1452 | new = pop_context(); |
bd5635a1 | 1453 | if (desc != new->depth) |
3c03b5de | 1454 | complain (&lbrac_mismatch_complaint, symnum); |
bd5635a1 RP |
1455 | |
1456 | /* Some compilers put the variable decls inside of an | |
1457 | LBRAC/RBRAC block. This macro should be nonzero if this | |
1458 | is true. DESC is N_DESC from the N_RBRAC symbol. | |
0cf9329b PB |
1459 | GCC_P is true if we've detected the GCC_COMPILED_SYMBOL |
1460 | or the GCC2_COMPILED_SYMBOL. */ | |
bd5635a1 RP |
1461 | #if !defined (VARIABLES_INSIDE_BLOCK) |
1462 | #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0 | |
1463 | #endif | |
1464 | ||
1465 | /* Can only use new->locals as local symbols here if we're in | |
1466 | gcc or on a machine that puts them before the lbrack. */ | |
1467 | if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
1468 | local_symbols = new->locals; | |
1469 | ||
1470 | /* If this is not the outermost LBRAC...RBRAC pair in the | |
1471 | function, its local symbols preceded it, and are the ones | |
1472 | just recovered from the context stack. Defined the block for them. | |
1473 | ||
1474 | If this is the outermost LBRAC...RBRAC pair, there is no | |
1475 | need to do anything; leave the symbols that preceded it | |
1476 | to be attached to the function's own block. However, if | |
1477 | it is so, we need to indicate that we just moved outside | |
1478 | of the function. */ | |
1479 | if (local_symbols | |
1480 | && (context_stack_depth | |
1481 | > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))) | |
1482 | { | |
1483 | /* FIXME Muzzle a compiler bug that makes end < start. */ | |
1484 | if (new->start_addr > valu) | |
1485 | { | |
1486 | complain(&lbrac_rbrac_complaint, 0); | |
1487 | new->start_addr = valu; | |
1488 | } | |
1489 | /* Make a block for the local symbols within. */ | |
1490 | finish_block (0, &local_symbols, new->old_blocks, | |
1491 | new->start_addr, valu); | |
1492 | } | |
1493 | else | |
1494 | { | |
1495 | within_function = 0; | |
1496 | } | |
1497 | if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
1498 | /* Now pop locals of block just finished. */ | |
1499 | local_symbols = new->locals; | |
1500 | break; | |
1501 | ||
9bb30452 | 1502 | case N_FN: |
6150cc73 | 1503 | case N_FN_SEQ: |
9bb30452 | 1504 | /* This kind of symbol indicates the start of an object file. */ |
c55e6167 | 1505 | valu += offset; /* Relocate for dynamic loading */ |
bd5635a1 RP |
1506 | break; |
1507 | ||
1508 | case N_SO: | |
1509 | /* This type of symbol indicates the start of data | |
1510 | for one source file. | |
1511 | Finish the symbol table of the previous source file | |
1512 | (if any) and start accumulating a new symbol table. */ | |
c55e6167 JG |
1513 | valu += offset; /* Relocate for dynamic loading */ |
1514 | ||
bd5635a1 RP |
1515 | #ifndef SUN_FIXED_LBRAC_BUG |
1516 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
1517 | #endif | |
1518 | ||
1519 | #ifdef PCC_SOL_BROKEN | |
1520 | /* pcc bug, occasionally puts out SO for SOL. */ | |
1521 | if (context_stack_depth > 0) | |
1522 | { | |
1523 | start_subfile (name, NULL); | |
1524 | break; | |
1525 | } | |
1526 | #endif | |
1527 | if (last_source_file) | |
7e258d18 PB |
1528 | { |
1529 | /* Check if previous symbol was also an N_SO (with some | |
1530 | sanity checks). If so, that one was actually the directory | |
1531 | name, and the current one is the real file name. | |
1532 | Patch things up. */ | |
1533 | if (previous_stab_code == N_SO | |
1534 | && current_subfile && current_subfile->dirname == NULL | |
1535 | && current_subfile->name != NULL | |
1536 | && current_subfile->name[strlen(current_subfile->name)-1] == '/') | |
1537 | { | |
1538 | current_subfile->dirname = current_subfile->name; | |
1539 | current_subfile->name = obsavestring (name, strlen (name)); | |
1540 | break; | |
1541 | } | |
1542 | (void)end_symtab (valu, 0, 0); | |
1543 | } | |
bd5635a1 RP |
1544 | start_symtab (name, NULL, valu); |
1545 | break; | |
1546 | ||
c55e6167 | 1547 | |
bd5635a1 RP |
1548 | case N_SOL: |
1549 | /* This type of symbol indicates the start of data for | |
1550 | a sub-source-file, one whose contents were copied or | |
1551 | included in the compilation of the main source file | |
1552 | (whose name was given in the N_SO symbol.) */ | |
c55e6167 | 1553 | valu += offset; /* Relocate for dynamic loading */ |
bd5635a1 RP |
1554 | start_subfile (name, NULL); |
1555 | break; | |
1556 | ||
1557 | case N_BINCL: | |
1558 | push_subfile (); | |
1559 | add_new_header_file (name, valu); | |
1560 | start_subfile (name, NULL); | |
1561 | break; | |
1562 | ||
1563 | case N_EINCL: | |
1564 | start_subfile (pop_subfile (), NULL); | |
1565 | break; | |
1566 | ||
1567 | case N_EXCL: | |
1568 | add_old_header_file (name, valu); | |
1569 | break; | |
1570 | ||
1571 | case N_SLINE: | |
1572 | /* This type of "symbol" really just records | |
1573 | one line-number -- core-address correspondence. | |
1574 | Enter it in the line list for this symbol table. */ | |
c55e6167 | 1575 | valu += offset; /* Relocate for dynamic loading */ |
bd5635a1 RP |
1576 | #ifndef SUN_FIXED_LBRAC_BUG |
1577 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
1578 | #endif | |
4137c5fc | 1579 | record_line (current_subfile, desc, valu); |
bd5635a1 RP |
1580 | break; |
1581 | ||
1582 | case N_BCOMM: | |
1583 | if (common_block) | |
1584 | error ("Invalid symbol data: common within common at symtab pos %d", | |
1585 | symnum); | |
1586 | common_block = local_symbols; | |
1587 | common_block_i = local_symbols ? local_symbols->nsyms : 0; | |
1588 | break; | |
1589 | ||
1590 | case N_ECOMM: | |
1591 | /* Symbols declared since the BCOMM are to have the common block | |
1592 | start address added in when we know it. common_block points to | |
1593 | the first symbol after the BCOMM in the local_symbols list; | |
1594 | copy the list and hang it off the symbol for the common block name | |
1595 | for later fixup. */ | |
1596 | { | |
1597 | int i; | |
1598 | struct symbol *sym = | |
1599 | (struct symbol *) xmalloc (sizeof (struct symbol)); | |
1600 | bzero (sym, sizeof *sym); | |
1601 | SYMBOL_NAME (sym) = savestring (name, strlen (name)); | |
1602 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
1603 | SYMBOL_NAMESPACE (sym) = (enum namespace)((long) | |
1604 | copy_pending (local_symbols, common_block_i, common_block)); | |
1605 | i = hashname (SYMBOL_NAME (sym)); | |
1606 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; | |
1607 | global_sym_chain[i] = sym; | |
1608 | common_block = 0; | |
1609 | break; | |
1610 | } | |
1611 | ||
c55e6167 JG |
1612 | /* The following symbol types need to have the offset added to their |
1613 | value; then we process symbol definitions in the name. */ | |
1614 | case N_STSYM: /* Global symbol */ | |
1615 | case N_LCSYM: /* Local symbol */ | |
1616 | case N_DSLINE: /* Source line number, data seg */ | |
1617 | case N_BSLINE: /* Source line number, bss seg */ | |
1618 | /* N_BROWS: overlaps with N_BSLINE */ | |
1619 | case N_ENTRY: /* Alternate entry point */ | |
1620 | valu += offset; /* Relocate for dynamic loading */ | |
1621 | /* FALL THROUGH */ | |
1622 | ||
1623 | /* The following symbol types don't need the address field relocated, | |
1624 | since it is either unused, or is absolute. */ | |
1625 | case N_GSYM: /* Global variable */ | |
1626 | case N_NSYMS: /* Number of symbols (ultrix) */ | |
1627 | case N_NOMAP: /* No map? (ultrix) */ | |
1628 | case N_RSYM: /* Register variable */ | |
1629 | case N_DEFD: /* Modula-2 GNU module dependency */ | |
1630 | case N_SSYM: /* Struct or union element */ | |
1631 | case N_LSYM: /* Local symbol in stack */ | |
1632 | case N_PSYM: /* Parameter variable */ | |
1633 | case N_LENG: /* Length of preceding symbol type */ | |
1634 | if (name) | |
1635 | define_symbol (valu, name, desc, type); | |
bd5635a1 RP |
1636 | break; |
1637 | ||
c55e6167 JG |
1638 | /* The following symbol types we don't know how to process. Handle |
1639 | them in a "default" way, but complain to people who care. */ | |
bd5635a1 | 1640 | default: |
c55e6167 JG |
1641 | case N_EHDECL: /* Exception handler name */ |
1642 | case N_MAIN: /* Name of main routine (not used in C) */ | |
1643 | case N_PC: /* Global symbol in Pascal */ | |
1644 | case N_M2C: /* Modula-2 compilation unit */ | |
1645 | /* N_MOD2: overlaps with N_EHDECL */ | |
1646 | case N_SCOPE: /* Modula-2 scope information */ | |
1647 | case N_ECOML: /* End common (local name) */ | |
1648 | case N_NBTEXT: /* Gould Non-Base-Register symbols??? */ | |
1649 | case N_NBDATA: | |
1650 | case N_NBBSS: | |
1651 | case N_NBSTS: | |
1652 | case N_NBLCS: | |
1653 | complain (&unknown_symtype_complaint, local_hex_string(type)); | |
bd5635a1 RP |
1654 | if (name) |
1655 | define_symbol (valu, name, desc, type); | |
1656 | } | |
7e258d18 PB |
1657 | |
1658 | previous_stab_code = type; | |
bd5635a1 RP |
1659 | } |
1660 | \f | |
bd5635a1 RP |
1661 | /* Copy a pending list, used to record the contents of a common |
1662 | block for later fixup. */ | |
1663 | static struct pending * | |
1664 | copy_pending (beg, begi, end) | |
1665 | struct pending *beg, *end; | |
1666 | int begi; | |
1667 | { | |
1668 | struct pending *new = 0; | |
1669 | struct pending *next; | |
1670 | ||
1671 | for (next = beg; next != 0 && (next != end || begi < end->nsyms); | |
1672 | next = next->next, begi = 0) | |
1673 | { | |
1674 | register int j; | |
1675 | for (j = begi; j < next->nsyms; j++) | |
1676 | add_symbol_to_list (next->symbol[j], &new); | |
1677 | } | |
1678 | return new; | |
1679 | } | |
bd5635a1 RP |
1680 | \f |
1681 | /* Register our willingness to decode symbols for SunOS and a.out and | |
1682 | b.out files handled by BFD... */ | |
1683 | static struct sym_fns sunos_sym_fns = {"sunOs", 6, | |
9404978d | 1684 | dbx_new_init, dbx_symfile_init, dbx_symfile_read}; |
bd5635a1 RP |
1685 | |
1686 | static struct sym_fns aout_sym_fns = {"a.out", 5, | |
9404978d | 1687 | dbx_new_init, dbx_symfile_init, dbx_symfile_read}; |
bd5635a1 RP |
1688 | |
1689 | static struct sym_fns bout_sym_fns = {"b.out", 5, | |
9404978d | 1690 | dbx_new_init, dbx_symfile_init, dbx_symfile_read}; |
bd5635a1 RP |
1691 | |
1692 | void | |
1693 | _initialize_dbxread () | |
1694 | { | |
1695 | add_symtab_fns(&sunos_sym_fns); | |
1696 | add_symtab_fns(&aout_sym_fns); | |
1697 | add_symtab_fns(&bout_sym_fns); | |
bd5635a1 | 1698 | } |