Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Read dbx symbol tables and convert to internal format, for GDB. |
2 | Copyright (C) 1986-1991 Free Software Foundation, Inc. | |
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" | |
37 | #include "param.h" | |
38 | ||
39 | #ifdef USG | |
40 | #include <sys/types.h> | |
41 | #include <fcntl.h> | |
42 | #define L_SET 0 | |
43 | #define L_INCR 1 | |
44 | #endif | |
45 | ||
46 | #include "a.out.gnu.h" | |
47 | #include "stab.gnu.h" /* We always use GNU stabs, not native, now */ | |
48 | #include <ctype.h> | |
49 | ||
50 | #ifndef NO_GNU_STABS | |
51 | /* | |
52 | * Define specifically gnu symbols here. | |
53 | */ | |
54 | ||
55 | /* The following type indicates the definition of a symbol as being | |
56 | an indirect reference to another symbol. The other symbol | |
57 | appears as an undefined reference, immediately following this symbol. | |
58 | ||
59 | Indirection is asymmetrical. The other symbol's value will be used | |
60 | to satisfy requests for the indirect symbol, but not vice versa. | |
61 | If the other symbol does not have a definition, libraries will | |
62 | be searched to find a definition. */ | |
63 | #ifndef N_INDR | |
64 | #define N_INDR 0xa | |
65 | #endif | |
66 | ||
67 | /* The following symbols refer to set elements. | |
68 | All the N_SET[ATDB] symbols with the same name form one set. | |
69 | Space is allocated for the set in the text section, and each set | |
70 | element's value is stored into one word of the space. | |
71 | The first word of the space is the length of the set (number of elements). | |
72 | ||
73 | The address of the set is made into an N_SETV symbol | |
74 | whose name is the same as the name of the set. | |
75 | This symbol acts like a N_DATA global symbol | |
76 | in that it can satisfy undefined external references. */ | |
77 | ||
78 | #ifndef N_SETA | |
79 | #define N_SETA 0x14 /* Absolute set element symbol */ | |
80 | #endif /* This is input to LD, in a .o file. */ | |
81 | ||
82 | #ifndef N_SETT | |
83 | #define N_SETT 0x16 /* Text set element symbol */ | |
84 | #endif /* This is input to LD, in a .o file. */ | |
85 | ||
86 | #ifndef N_SETD | |
87 | #define N_SETD 0x18 /* Data set element symbol */ | |
88 | #endif /* This is input to LD, in a .o file. */ | |
89 | ||
90 | #ifndef N_SETB | |
91 | #define N_SETB 0x1A /* Bss set element symbol */ | |
92 | #endif /* This is input to LD, in a .o file. */ | |
93 | ||
94 | /* Macros dealing with the set element symbols defined in a.out.h */ | |
95 | #define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT)) | |
96 | #define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS) | |
97 | ||
98 | #ifndef N_SETV | |
99 | #define N_SETV 0x1C /* Pointer to set vector in data area. */ | |
100 | #endif /* This is output from LD. */ | |
101 | ||
102 | #ifndef N_WARNING | |
103 | #define N_WARNING 0x1E /* Warning message to print if file included */ | |
104 | #endif /* This is input to ld */ | |
105 | ||
106 | #endif /* NO_GNU_STABS */ | |
107 | ||
108 | #include <obstack.h> | |
109 | #include <sys/param.h> | |
110 | #include <sys/file.h> | |
111 | #include <sys/stat.h> | |
112 | #include "symtab.h" | |
113 | #include "breakpoint.h" | |
114 | #include "command.h" | |
115 | #include "target.h" | |
116 | #include "gdbcore.h" /* for bfd stuff */ | |
d11c44f1 | 117 | #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ |
bd5635a1 RP |
118 | #include "symfile.h" |
119 | ||
120 | struct dbx_symfile_info { | |
121 | asection *text_sect; /* Text section accessor */ | |
122 | int symcount; /* How many symbols are there in the file */ | |
123 | char *stringtab; /* The actual string table */ | |
124 | int stringtab_size; /* Its size */ | |
125 | off_t symtab_offset; /* Offset in file to symbol table */ | |
126 | int desc; /* File descriptor of symbol file */ | |
127 | }; | |
128 | ||
129 | extern void qsort (); | |
130 | extern double atof (); | |
131 | extern struct cmd_list_element *cmdlist; | |
132 | ||
133 | extern void symbol_file_command (); | |
134 | ||
135 | /* Forward declarations */ | |
136 | ||
137 | static void add_symbol_to_list (); | |
138 | static void read_dbx_symtab (); | |
139 | static void init_psymbol_list (); | |
140 | static void process_one_symbol (); | |
141 | static struct type *read_type (); | |
142 | static struct type *read_range_type (); | |
143 | static struct type *read_enum_type (); | |
144 | static struct type *read_struct_type (); | |
145 | static struct type *read_array_type (); | |
146 | static long read_number (); | |
147 | static void finish_block (); | |
148 | static struct blockvector *make_blockvector (); | |
149 | static struct symbol *define_symbol (); | |
150 | static void start_subfile (); | |
151 | static int hashname (); | |
152 | static struct pending *copy_pending (); | |
153 | static void fix_common_block (); | |
154 | static void add_undefined_type (); | |
155 | static void cleanup_undefined_types (); | |
156 | static void scan_file_globals (); | |
9404978d | 157 | static struct symtab *read_ofile_symtab (); |
bd5635a1 RP |
158 | static void dbx_psymtab_to_symtab (); |
159 | ||
160 | /* C++ */ | |
161 | static struct type **read_args (); | |
162 | ||
9404978d MT |
163 | static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' }; |
164 | static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' }; | |
bd5635a1 RP |
165 | |
166 | /* Macro to determine which symbols to ignore when reading the first symbol | |
167 | of a file. Some machines override this definition. */ | |
168 | #ifndef IGNORE_SYMBOL | |
169 | /* This code is used on Ultrix systems. Ignore it */ | |
170 | #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS) | |
171 | #endif | |
172 | ||
173 | /* Macro for name of symbol to indicate a file compiled with gcc. */ | |
174 | #ifndef GCC_COMPILED_FLAG_SYMBOL | |
175 | #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled." | |
176 | #endif | |
177 | ||
178 | /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */ | |
179 | ||
180 | #ifndef STAB_REG_TO_REGNUM | |
181 | #define STAB_REG_TO_REGNUM(VALUE) (VALUE) | |
182 | #endif | |
183 | ||
184 | /* Define this as 1 if a pcc declaration of a char or short argument | |
185 | gives the correct address. Otherwise assume pcc gives the | |
186 | address of the corresponding int, which is not the same on a | |
187 | big-endian machine. */ | |
188 | ||
189 | #ifndef BELIEVE_PCC_PROMOTION | |
190 | #define BELIEVE_PCC_PROMOTION 0 | |
191 | #endif | |
192 | \f | |
193 | /* Nonzero means give verbose info on gdb action. From main.c. */ | |
194 | extern int info_verbose; | |
195 | ||
196 | /* Name of source file whose symbol data we are now processing. | |
197 | This comes from a symbol of type N_SO. */ | |
198 | ||
199 | static char *last_source_file; | |
200 | ||
201 | /* Core address of start of text of current source file. | |
202 | This too comes from the N_SO symbol. */ | |
203 | ||
204 | static CORE_ADDR last_source_start_addr; | |
205 | ||
206 | /* The entry point of a file we are reading. */ | |
207 | CORE_ADDR entry_point; | |
208 | ||
209 | /* The list of sub-source-files within the current individual compilation. | |
210 | Each file gets its own symtab with its own linetable and associated info, | |
211 | but they all share one blockvector. */ | |
212 | ||
213 | struct subfile | |
214 | { | |
215 | struct subfile *next; | |
216 | char *name; | |
217 | char *dirname; | |
218 | struct linetable *line_vector; | |
219 | int line_vector_length; | |
220 | int line_vector_index; | |
221 | int prev_line_number; | |
222 | }; | |
223 | ||
224 | static struct subfile *subfiles; | |
225 | ||
226 | static struct subfile *current_subfile; | |
227 | ||
228 | /* Count symbols as they are processed, for error messages. */ | |
229 | ||
230 | static unsigned int symnum; | |
231 | ||
232 | /* Vector of types defined so far, indexed by their dbx type numbers. | |
233 | (In newer sun systems, dbx uses a pair of numbers in parens, | |
234 | as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be | |
235 | translated through the type_translations hash table to get | |
236 | the index into the type vector.) */ | |
237 | ||
7cefc05e | 238 | static struct type **type_vector; |
bd5635a1 RP |
239 | |
240 | /* Number of elements allocated for type_vector currently. */ | |
241 | ||
242 | static int type_vector_length; | |
243 | ||
244 | /* Vector of line number information. */ | |
245 | ||
246 | static struct linetable *line_vector; | |
247 | ||
248 | /* Index of next entry to go in line_vector_index. */ | |
249 | ||
250 | static int line_vector_index; | |
251 | ||
252 | /* Last line number recorded in the line vector. */ | |
253 | ||
254 | static int prev_line_number; | |
255 | ||
256 | /* Number of elements allocated for line_vector currently. */ | |
257 | ||
258 | static int line_vector_length; | |
259 | ||
260 | /* Hash table of global symbols whose values are not known yet. | |
261 | They are chained thru the SYMBOL_VALUE_CHAIN, since we don't | |
262 | have the correct data for that slot yet. */ | |
263 | /* The use of the LOC_BLOCK code in this chain is nonstandard-- | |
264 | it refers to a FORTRAN common block rather than the usual meaning. */ | |
265 | ||
266 | #define HASHSIZE 127 | |
267 | static struct symbol *global_sym_chain[HASHSIZE]; | |
268 | ||
269 | /* Record the symbols defined for each context in a list. | |
270 | We don't create a struct block for the context until we | |
271 | know how long to make it. */ | |
272 | ||
273 | #define PENDINGSIZE 100 | |
274 | ||
275 | struct pending | |
276 | { | |
277 | struct pending *next; | |
278 | int nsyms; | |
279 | struct symbol *symbol[PENDINGSIZE]; | |
280 | }; | |
281 | ||
282 | /* List of free `struct pending' structures for reuse. */ | |
283 | struct pending *free_pendings; | |
284 | ||
285 | /* Here are the three lists that symbols are put on. */ | |
286 | ||
287 | struct pending *file_symbols; /* static at top level, and types */ | |
288 | ||
289 | struct pending *global_symbols; /* global functions and variables */ | |
290 | ||
291 | struct pending *local_symbols; /* everything local to lexical context */ | |
292 | ||
293 | /* List of symbols declared since the last BCOMM. This list is a tail | |
294 | of local_symbols. When ECOMM is seen, the symbols on the list | |
295 | are noted so their proper addresses can be filled in later, | |
296 | using the common block base address gotten from the assembler | |
297 | stabs. */ | |
298 | ||
299 | struct pending *common_block; | |
300 | int common_block_i; | |
301 | ||
302 | /* Stack representing unclosed lexical contexts | |
303 | (that will become blocks, eventually). */ | |
304 | ||
305 | struct context_stack | |
306 | { | |
307 | struct pending *locals; | |
308 | struct pending_block *old_blocks; | |
309 | struct symbol *name; | |
310 | CORE_ADDR start_addr; | |
311 | CORE_ADDR end_addr; /* Temp slot for exception handling. */ | |
312 | int depth; | |
313 | }; | |
314 | ||
315 | struct context_stack *context_stack; | |
316 | ||
317 | /* Index of first unused entry in context stack. */ | |
318 | int context_stack_depth; | |
319 | ||
320 | /* Currently allocated size of context stack. */ | |
321 | ||
322 | int context_stack_size; | |
323 | ||
324 | /* Nonzero if within a function (so symbols should be local, | |
325 | if nothing says specifically). */ | |
326 | ||
327 | int within_function; | |
328 | ||
0c4d2cc2 JG |
329 | #if 0 |
330 | /* The type of the function we are currently reading in. This is | |
331 | used by define_symbol to record the type of arguments to a function. */ | |
332 | ||
333 | static struct type *in_function_type; | |
334 | #endif | |
335 | ||
bd5635a1 RP |
336 | /* List of blocks already made (lexical contexts already closed). |
337 | This is used at the end to make the blockvector. */ | |
338 | ||
339 | struct pending_block | |
340 | { | |
341 | struct pending_block *next; | |
342 | struct block *block; | |
343 | }; | |
344 | ||
345 | struct pending_block *pending_blocks; | |
346 | ||
347 | extern CORE_ADDR startup_file_start; /* From blockframe.c */ | |
348 | extern CORE_ADDR startup_file_end; /* From blockframe.c */ | |
349 | ||
350 | /* Global variable which, when set, indicates that we are processing a | |
351 | .o file compiled with gcc */ | |
352 | ||
353 | static unsigned char processing_gcc_compilation; | |
354 | ||
355 | /* Make a list of forward references which haven't been defined. */ | |
356 | static struct type **undef_types; | |
357 | static int undef_types_allocated, undef_types_length; | |
358 | ||
359 | /* String table for the main symbol file. It is kept in memory | |
360 | permanently, to speed up symbol reading. Other files' symbol tables | |
361 | are read in on demand. FIXME, this should be cleaner. */ | |
362 | ||
363 | static char *symfile_string_table; | |
364 | static int symfile_string_table_size; | |
365 | ||
366 | /* Setup a define to deal cleanly with the underscore problem */ | |
367 | ||
368 | #ifdef NAMES_HAVE_UNDERSCORE | |
369 | #define HASH_OFFSET 1 | |
370 | #else | |
371 | #define HASH_OFFSET 0 | |
372 | #endif | |
373 | ||
374 | /* Complaints about the symbols we have encountered. */ | |
375 | ||
376 | struct complaint innerblock_complaint = | |
377 | {"inner block not inside outer block in %s", 0, 0}; | |
378 | ||
379 | struct complaint blockvector_complaint = | |
380 | {"block at %x out of order", 0, 0}; | |
381 | ||
382 | struct complaint lbrac_complaint = | |
383 | {"bad block start address patched", 0, 0}; | |
384 | ||
385 | #if 0 | |
386 | struct complaint dbx_class_complaint = | |
387 | {"encountered DBX-style class variable debugging information.\n\ | |
388 | You seem to have compiled your program with \ | |
389 | \"g++ -g0\" instead of \"g++ -g\".\n\ | |
390 | Therefore GDB will not know about your class variables", 0, 0}; | |
391 | #endif | |
392 | ||
393 | struct complaint string_table_offset_complaint = | |
394 | {"bad string table offset in symbol %d", 0, 0}; | |
395 | ||
396 | struct complaint unknown_symtype_complaint = | |
0c4d2cc2 | 397 | {"unknown symbol type %s", 0, 0}; |
bd5635a1 RP |
398 | |
399 | struct complaint lbrac_rbrac_complaint = | |
400 | {"block start larger than block end", 0, 0}; | |
401 | ||
402 | struct complaint const_vol_complaint = | |
9bb30452 | 403 | {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0}; |
bd5635a1 RP |
404 | |
405 | struct complaint error_type_complaint = | |
5bc757e2 | 406 | {"debug info mismatch between compiler and debugger", 0, 0}; |
bd5635a1 RP |
407 | |
408 | struct complaint invalid_member_complaint = | |
409 | {"invalid (minimal) member type data format at symtab pos %d.", 0, 0}; | |
9bb30452 JG |
410 | |
411 | struct complaint range_type_base_complaint = | |
412 | {"base type %d of range type is not defined", 0, 0}; | |
bd5635a1 RP |
413 | \f |
414 | /* Support for Sun changes to dbx symbol format */ | |
415 | ||
416 | /* For each identified header file, we have a table of types defined | |
417 | in that header file. | |
418 | ||
419 | header_files maps header file names to their type tables. | |
420 | It is a vector of n_header_files elements. | |
421 | Each element describes one header file. | |
422 | It contains a vector of types. | |
423 | ||
424 | Sometimes it can happen that the same header file produces | |
425 | different results when included in different places. | |
426 | This can result from conditionals or from different | |
427 | things done before including the file. | |
428 | When this happens, there are multiple entries for the file in this table, | |
429 | one entry for each distinct set of results. | |
430 | The entries are distinguished by the INSTANCE field. | |
431 | The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is | |
432 | used to match header-file references to their corresponding data. */ | |
433 | ||
434 | struct header_file | |
435 | { | |
436 | char *name; /* Name of header file */ | |
437 | int instance; /* Numeric code distinguishing instances | |
438 | of one header file that produced | |
439 | different results when included. | |
440 | It comes from the N_BINCL or N_EXCL. */ | |
441 | struct type **vector; /* Pointer to vector of types */ | |
442 | int length; /* Allocated length (# elts) of that vector */ | |
443 | }; | |
444 | ||
445 | static struct header_file *header_files = 0; | |
446 | ||
447 | static int n_header_files; | |
448 | ||
449 | static int n_allocated_header_files; | |
450 | ||
451 | /* During initial symbol readin, we need to have a structure to keep | |
452 | track of which psymtabs have which bincls in them. This structure | |
453 | is used during readin to setup the list of dependencies within each | |
454 | partial symbol table. */ | |
455 | ||
456 | struct header_file_location | |
457 | { | |
458 | char *name; /* Name of header file */ | |
459 | int instance; /* See above */ | |
460 | struct partial_symtab *pst; /* Partial symtab that has the | |
461 | BINCL/EINCL defs for this file */ | |
462 | }; | |
463 | ||
464 | /* The actual list and controling variables */ | |
465 | static struct header_file_location *bincl_list, *next_bincl; | |
466 | static int bincls_allocated; | |
467 | ||
468 | /* Within each object file, various header files are assigned numbers. | |
469 | A type is defined or referred to with a pair of numbers | |
470 | (FILENUM,TYPENUM) where FILENUM is the number of the header file | |
471 | and TYPENUM is the number within that header file. | |
472 | TYPENUM is the index within the vector of types for that header file. | |
473 | ||
474 | FILENUM == 1 is special; it refers to the main source of the object file, | |
475 | and not to any header file. FILENUM != 1 is interpreted by looking it up | |
476 | in the following table, which contains indices in header_files. */ | |
477 | ||
478 | static int *this_object_header_files = 0; | |
479 | ||
480 | static int n_this_object_header_files; | |
481 | ||
482 | static int n_allocated_this_object_header_files; | |
483 | ||
484 | /* When a header file is getting special overriding definitions | |
485 | for one source file, record here the header_files index | |
486 | of its normal definition vector. | |
487 | At other times, this is -1. */ | |
488 | ||
489 | static int header_file_prev_index; | |
490 | ||
491 | /* Free up old header file tables, and allocate new ones. | |
492 | We're reading a new symbol file now. */ | |
493 | ||
9bba3334 | 494 | static void |
bd5635a1 RP |
495 | free_and_init_header_files () |
496 | { | |
497 | register int i; | |
498 | for (i = 0; i < n_header_files; i++) | |
499 | free (header_files[i].name); | |
500 | if (header_files) /* First time null */ | |
501 | free (header_files); | |
502 | if (this_object_header_files) /* First time null */ | |
503 | free (this_object_header_files); | |
504 | ||
505 | n_allocated_header_files = 10; | |
506 | header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file)); | |
507 | n_header_files = 0; | |
508 | ||
509 | n_allocated_this_object_header_files = 10; | |
510 | this_object_header_files = (int *) xmalloc (10 * sizeof (int)); | |
511 | } | |
512 | ||
513 | /* Called at the start of each object file's symbols. | |
514 | Clear out the mapping of header file numbers to header files. */ | |
515 | ||
516 | static void | |
517 | new_object_header_files () | |
518 | { | |
519 | /* Leave FILENUM of 0 free for builtin types and this file's types. */ | |
520 | n_this_object_header_files = 1; | |
521 | header_file_prev_index = -1; | |
522 | } | |
523 | ||
524 | /* Add header file number I for this object file | |
525 | at the next successive FILENUM. */ | |
526 | ||
527 | static void | |
528 | add_this_object_header_file (i) | |
529 | int i; | |
530 | { | |
531 | if (n_this_object_header_files == n_allocated_this_object_header_files) | |
532 | { | |
533 | n_allocated_this_object_header_files *= 2; | |
534 | this_object_header_files | |
535 | = (int *) xrealloc (this_object_header_files, | |
536 | n_allocated_this_object_header_files * sizeof (int)); | |
537 | } | |
538 | ||
539 | this_object_header_files[n_this_object_header_files++] = i; | |
540 | } | |
541 | ||
542 | /* Add to this file an "old" header file, one already seen in | |
543 | a previous object file. NAME is the header file's name. | |
544 | INSTANCE is its instance code, to select among multiple | |
545 | symbol tables for the same header file. */ | |
546 | ||
547 | static void | |
548 | add_old_header_file (name, instance) | |
549 | char *name; | |
550 | int instance; | |
551 | { | |
552 | register struct header_file *p = header_files; | |
553 | register int i; | |
554 | ||
555 | for (i = 0; i < n_header_files; i++) | |
556 | if (!strcmp (p[i].name, name) && instance == p[i].instance) | |
557 | { | |
558 | add_this_object_header_file (i); | |
559 | return; | |
560 | } | |
561 | error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.", | |
562 | symnum); | |
563 | } | |
564 | ||
565 | /* Add to this file a "new" header file: definitions for its types follow. | |
566 | NAME is the header file's name. | |
567 | Most often this happens only once for each distinct header file, | |
568 | but not necessarily. If it happens more than once, INSTANCE has | |
569 | a different value each time, and references to the header file | |
570 | use INSTANCE values to select among them. | |
571 | ||
572 | dbx output contains "begin" and "end" markers for each new header file, | |
573 | but at this level we just need to know which files there have been; | |
574 | so we record the file when its "begin" is seen and ignore the "end". */ | |
575 | ||
576 | static void | |
577 | add_new_header_file (name, instance) | |
578 | char *name; | |
579 | int instance; | |
580 | { | |
581 | register int i; | |
582 | header_file_prev_index = -1; | |
583 | ||
584 | /* Make sure there is room for one more header file. */ | |
585 | ||
586 | if (n_header_files == n_allocated_header_files) | |
587 | { | |
588 | n_allocated_header_files *= 2; | |
589 | header_files = (struct header_file *) | |
590 | xrealloc (header_files, | |
591 | (n_allocated_header_files | |
592 | * sizeof (struct header_file))); | |
593 | } | |
594 | ||
595 | /* Create an entry for this header file. */ | |
596 | ||
597 | i = n_header_files++; | |
598 | header_files[i].name = savestring (name, strlen(name)); | |
599 | header_files[i].instance = instance; | |
600 | header_files[i].length = 10; | |
601 | header_files[i].vector | |
602 | = (struct type **) xmalloc (10 * sizeof (struct type *)); | |
603 | bzero (header_files[i].vector, 10 * sizeof (struct type *)); | |
604 | ||
605 | add_this_object_header_file (i); | |
606 | } | |
607 | ||
608 | /* Look up a dbx type-number pair. Return the address of the slot | |
609 | where the type for that number-pair is stored. | |
610 | The number-pair is in TYPENUMS. | |
611 | ||
612 | This can be used for finding the type associated with that pair | |
613 | or for associating a new type with the pair. */ | |
614 | ||
615 | static struct type ** | |
616 | dbx_lookup_type (typenums) | |
617 | int typenums[2]; | |
618 | { | |
619 | register int filenum = typenums[0], index = typenums[1]; | |
620 | ||
621 | if (filenum < 0 || filenum >= n_this_object_header_files) | |
622 | error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", | |
623 | filenum, index, symnum); | |
624 | ||
625 | if (filenum == 0) | |
626 | { | |
627 | /* Type is defined outside of header files. | |
628 | Find it in this object file's type vector. */ | |
5b0a744f | 629 | while (index >= type_vector_length) |
bd5635a1 RP |
630 | { |
631 | type_vector_length *= 2; | |
7cefc05e | 632 | type_vector = (struct type **) |
bd5635a1 | 633 | xrealloc (type_vector, |
7cefc05e JG |
634 | (type_vector_length * sizeof (struct type *))); |
635 | bzero (&type_vector[type_vector_length / 2], | |
bd5635a1 RP |
636 | type_vector_length * sizeof (struct type *) / 2); |
637 | } | |
7cefc05e | 638 | return &type_vector[index]; |
bd5635a1 RP |
639 | } |
640 | else | |
641 | { | |
642 | register int real_filenum = this_object_header_files[filenum]; | |
643 | register struct header_file *f; | |
644 | int f_orig_length; | |
645 | ||
646 | if (real_filenum >= n_header_files) | |
647 | abort (); | |
648 | ||
649 | f = &header_files[real_filenum]; | |
650 | ||
651 | f_orig_length = f->length; | |
652 | if (index >= f_orig_length) | |
653 | { | |
654 | while (index >= f->length) | |
655 | f->length *= 2; | |
656 | f->vector = (struct type **) | |
657 | xrealloc (f->vector, f->length * sizeof (struct type *)); | |
658 | bzero (&f->vector[f_orig_length], | |
659 | (f->length - f_orig_length) * sizeof (struct type *)); | |
660 | } | |
661 | return &f->vector[index]; | |
662 | } | |
663 | } | |
664 | ||
665 | /* Create a type object. Occaisionally used when you need a type | |
666 | which isn't going to be given a type number. */ | |
667 | ||
668 | static struct type * | |
669 | dbx_create_type () | |
670 | { | |
671 | register struct type *type = | |
672 | (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type)); | |
673 | ||
674 | bzero (type, sizeof (struct type)); | |
675 | TYPE_VPTR_FIELDNO (type) = -1; | |
62c4f98b | 676 | TYPE_VPTR_BASETYPE (type) = 0; |
bd5635a1 RP |
677 | return type; |
678 | } | |
679 | ||
680 | /* Make sure there is a type allocated for type numbers TYPENUMS | |
681 | and return the type object. | |
682 | This can create an empty (zeroed) type object. | |
683 | TYPENUMS may be (-1, -1) to return a new type object that is not | |
684 | put into the type vector, and so may not be referred to by number. */ | |
685 | ||
686 | static struct type * | |
687 | dbx_alloc_type (typenums) | |
688 | int typenums[2]; | |
689 | { | |
690 | register struct type **type_addr; | |
691 | register struct type *type; | |
692 | ||
693 | if (typenums[1] != -1) | |
694 | { | |
695 | type_addr = dbx_lookup_type (typenums); | |
696 | type = *type_addr; | |
697 | } | |
698 | else | |
699 | { | |
700 | type_addr = 0; | |
701 | type = 0; | |
702 | } | |
703 | ||
704 | /* If we are referring to a type not known at all yet, | |
705 | allocate an empty type for it. | |
706 | We will fill it in later if we find out how. */ | |
707 | if (type == 0) | |
708 | { | |
709 | type = dbx_create_type (); | |
710 | if (type_addr) | |
711 | *type_addr = type; | |
712 | } | |
713 | ||
714 | return type; | |
715 | } | |
716 | ||
717 | #if 0 | |
718 | static struct type ** | |
719 | explicit_lookup_type (real_filenum, index) | |
720 | int real_filenum, index; | |
721 | { | |
722 | register struct header_file *f = &header_files[real_filenum]; | |
723 | ||
724 | if (index >= f->length) | |
725 | { | |
726 | f->length *= 2; | |
727 | f->vector = (struct type **) | |
728 | xrealloc (f->vector, f->length * sizeof (struct type *)); | |
729 | bzero (&f->vector[f->length / 2], | |
730 | f->length * sizeof (struct type *) / 2); | |
731 | } | |
732 | return &f->vector[index]; | |
733 | } | |
734 | #endif | |
735 | \f | |
736 | /* maintain the lists of symbols and blocks */ | |
737 | ||
738 | /* Add a symbol to one of the lists of symbols. */ | |
739 | static void | |
740 | add_symbol_to_list (symbol, listhead) | |
741 | struct symbol *symbol; | |
742 | struct pending **listhead; | |
743 | { | |
744 | /* We keep PENDINGSIZE symbols in each link of the list. | |
745 | If we don't have a link with room in it, add a new link. */ | |
746 | if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE) | |
747 | { | |
748 | register struct pending *link; | |
749 | if (free_pendings) | |
750 | { | |
751 | link = free_pendings; | |
752 | free_pendings = link->next; | |
753 | } | |
754 | else | |
755 | link = (struct pending *) xmalloc (sizeof (struct pending)); | |
756 | ||
757 | link->next = *listhead; | |
758 | *listhead = link; | |
759 | link->nsyms = 0; | |
760 | } | |
761 | ||
762 | (*listhead)->symbol[(*listhead)->nsyms++] = symbol; | |
763 | } | |
764 | ||
765 | /* At end of reading syms, or in case of quit, | |
766 | really free as many `struct pending's as we can easily find. */ | |
767 | ||
768 | /* ARGSUSED */ | |
769 | static void | |
770 | really_free_pendings (foo) | |
771 | int foo; | |
772 | { | |
773 | struct pending *next, *next1; | |
e1ce8aa5 | 774 | #if 0 |
bd5635a1 | 775 | struct pending_block *bnext, *bnext1; |
e1ce8aa5 | 776 | #endif |
bd5635a1 RP |
777 | |
778 | for (next = free_pendings; next; next = next1) | |
779 | { | |
780 | next1 = next->next; | |
781 | free (next); | |
782 | } | |
783 | free_pendings = 0; | |
784 | ||
785 | #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */ | |
786 | for (bnext = pending_blocks; bnext; bnext = bnext1) | |
787 | { | |
788 | bnext1 = bnext->next; | |
789 | free (bnext); | |
790 | } | |
791 | #endif | |
792 | pending_blocks = 0; | |
793 | ||
794 | for (next = file_symbols; next; next = next1) | |
795 | { | |
796 | next1 = next->next; | |
797 | free (next); | |
798 | } | |
3f2e006b JG |
799 | file_symbols = 0; |
800 | ||
bd5635a1 RP |
801 | for (next = global_symbols; next; next = next1) |
802 | { | |
803 | next1 = next->next; | |
804 | free (next); | |
805 | } | |
3f2e006b | 806 | global_symbols = 0; |
bd5635a1 RP |
807 | } |
808 | ||
809 | /* Take one of the lists of symbols and make a block from it. | |
810 | Keep the order the symbols have in the list (reversed from the input file). | |
811 | Put the block on the list of pending blocks. */ | |
812 | ||
813 | static void | |
814 | finish_block (symbol, listhead, old_blocks, start, end) | |
815 | struct symbol *symbol; | |
816 | struct pending **listhead; | |
817 | struct pending_block *old_blocks; | |
818 | CORE_ADDR start, end; | |
819 | { | |
820 | register struct pending *next, *next1; | |
821 | register struct block *block; | |
822 | register struct pending_block *pblock; | |
823 | struct pending_block *opblock; | |
824 | register int i; | |
825 | ||
826 | /* Count the length of the list of symbols. */ | |
827 | ||
828 | for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next) | |
829 | /*EMPTY*/; | |
830 | ||
831 | block = (struct block *) obstack_alloc (symbol_obstack, | |
832 | (sizeof (struct block) | |
833 | + ((i - 1) | |
834 | * sizeof (struct symbol *)))); | |
835 | ||
836 | /* Copy the symbols into the block. */ | |
837 | ||
838 | BLOCK_NSYMS (block) = i; | |
839 | for (next = *listhead; next; next = next->next) | |
840 | { | |
841 | register int j; | |
842 | for (j = next->nsyms - 1; j >= 0; j--) | |
843 | BLOCK_SYM (block, --i) = next->symbol[j]; | |
844 | } | |
845 | ||
846 | BLOCK_START (block) = start; | |
847 | BLOCK_END (block) = end; | |
848 | BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */ | |
849 | BLOCK_GCC_COMPILED (block) = processing_gcc_compilation; | |
850 | ||
851 | /* Put the block in as the value of the symbol that names it. */ | |
852 | ||
853 | if (symbol) | |
854 | { | |
855 | SYMBOL_BLOCK_VALUE (symbol) = block; | |
856 | BLOCK_FUNCTION (block) = symbol; | |
857 | } | |
858 | else | |
859 | BLOCK_FUNCTION (block) = 0; | |
860 | ||
861 | /* Now "free" the links of the list, and empty the list. */ | |
862 | ||
863 | for (next = *listhead; next; next = next1) | |
864 | { | |
865 | next1 = next->next; | |
866 | next->next = free_pendings; | |
867 | free_pendings = next; | |
868 | } | |
869 | *listhead = 0; | |
870 | ||
871 | /* Install this block as the superblock | |
872 | of all blocks made since the start of this scope | |
873 | that don't have superblocks yet. */ | |
874 | ||
875 | opblock = 0; | |
876 | for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next) | |
877 | { | |
878 | if (BLOCK_SUPERBLOCK (pblock->block) == 0) { | |
879 | #if 1 | |
880 | /* Check to be sure the blocks are nested as we receive them. | |
881 | If the compiler/assembler/linker work, this just burns a small | |
882 | amount of time. */ | |
883 | if (BLOCK_START (pblock->block) < BLOCK_START (block) | |
884 | || BLOCK_END (pblock->block) > BLOCK_END (block)) { | |
885 | complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol): | |
886 | "(don't know)"); | |
887 | BLOCK_START (pblock->block) = BLOCK_START (block); | |
888 | BLOCK_END (pblock->block) = BLOCK_END (block); | |
889 | } | |
890 | #endif | |
891 | BLOCK_SUPERBLOCK (pblock->block) = block; | |
892 | } | |
893 | opblock = pblock; | |
894 | } | |
895 | ||
896 | /* Record this block on the list of all blocks in the file. | |
897 | Put it after opblock, or at the beginning if opblock is 0. | |
898 | This puts the block in the list after all its subblocks. */ | |
899 | ||
900 | /* Allocate in the symbol_obstack to save time. | |
901 | It wastes a little space. */ | |
902 | pblock = (struct pending_block *) | |
903 | obstack_alloc (symbol_obstack, | |
904 | sizeof (struct pending_block)); | |
905 | pblock->block = block; | |
906 | if (opblock) | |
907 | { | |
908 | pblock->next = opblock->next; | |
909 | opblock->next = pblock; | |
910 | } | |
911 | else | |
912 | { | |
913 | pblock->next = pending_blocks; | |
914 | pending_blocks = pblock; | |
915 | } | |
916 | } | |
917 | ||
918 | static struct blockvector * | |
919 | make_blockvector () | |
920 | { | |
921 | register struct pending_block *next; | |
922 | register struct blockvector *blockvector; | |
923 | register int i; | |
924 | ||
925 | /* Count the length of the list of blocks. */ | |
926 | ||
927 | for (next = pending_blocks, i = 0; next; next = next->next, i++); | |
928 | ||
929 | blockvector = (struct blockvector *) | |
930 | obstack_alloc (symbol_obstack, | |
931 | (sizeof (struct blockvector) | |
932 | + (i - 1) * sizeof (struct block *))); | |
933 | ||
934 | /* Copy the blocks into the blockvector. | |
935 | This is done in reverse order, which happens to put | |
936 | the blocks into the proper order (ascending starting address). | |
937 | finish_block has hair to insert each block into the list | |
938 | after its subblocks in order to make sure this is true. */ | |
939 | ||
940 | BLOCKVECTOR_NBLOCKS (blockvector) = i; | |
941 | for (next = pending_blocks; next; next = next->next) { | |
942 | BLOCKVECTOR_BLOCK (blockvector, --i) = next->block; | |
943 | } | |
944 | ||
945 | #if 0 /* Now we make the links in the obstack, so don't free them. */ | |
946 | /* Now free the links of the list, and empty the list. */ | |
947 | ||
948 | for (next = pending_blocks; next; next = next1) | |
949 | { | |
950 | next1 = next->next; | |
951 | free (next); | |
952 | } | |
953 | #endif | |
954 | pending_blocks = 0; | |
955 | ||
956 | #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */ | |
957 | /* Some compilers output blocks in the wrong order, but we depend | |
958 | on their being in the right order so we can binary search. | |
959 | Check the order and moan about it. FIXME. */ | |
960 | if (BLOCKVECTOR_NBLOCKS (blockvector) > 1) | |
961 | for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) { | |
962 | if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1)) | |
963 | > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) { | |
964 | complain (&blockvector_complaint, | |
965 | BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))); | |
966 | } | |
967 | } | |
968 | #endif | |
969 | ||
970 | return blockvector; | |
971 | } | |
972 | \f | |
973 | /* Manage the vector of line numbers. */ | |
974 | ||
975 | static void | |
976 | record_line (line, pc) | |
977 | int line; | |
978 | CORE_ADDR pc; | |
979 | { | |
980 | struct linetable_entry *e; | |
981 | /* Ignore the dummy line number in libg.o */ | |
982 | ||
983 | if (line == 0xffff) | |
984 | return; | |
985 | ||
986 | /* Make sure line vector is big enough. */ | |
987 | ||
988 | if (line_vector_index + 1 >= line_vector_length) | |
989 | { | |
990 | line_vector_length *= 2; | |
991 | line_vector = (struct linetable *) | |
992 | xrealloc (line_vector, | |
993 | (sizeof (struct linetable) | |
994 | + line_vector_length * sizeof (struct linetable_entry))); | |
995 | current_subfile->line_vector = line_vector; | |
996 | } | |
997 | ||
998 | e = line_vector->item + line_vector_index++; | |
999 | e->line = line; e->pc = pc; | |
1000 | } | |
1001 | \f | |
1002 | /* Start a new symtab for a new source file. | |
1003 | This is called when a dbx symbol of type N_SO is seen; | |
1004 | it indicates the start of data for one original source file. */ | |
1005 | ||
1006 | static void | |
1007 | start_symtab (name, dirname, start_addr) | |
1008 | char *name; | |
1009 | char *dirname; | |
1010 | CORE_ADDR start_addr; | |
1011 | { | |
1012 | ||
1013 | last_source_file = name; | |
1014 | last_source_start_addr = start_addr; | |
1015 | file_symbols = 0; | |
1016 | global_symbols = 0; | |
1017 | within_function = 0; | |
1018 | ||
1019 | /* Context stack is initially empty, with room for 10 levels. */ | |
1020 | context_stack | |
1021 | = (struct context_stack *) xmalloc (10 * sizeof (struct context_stack)); | |
1022 | context_stack_size = 10; | |
1023 | context_stack_depth = 0; | |
1024 | ||
1025 | new_object_header_files (); | |
1026 | ||
1027 | type_vector_length = 160; | |
7cefc05e JG |
1028 | type_vector = (struct type **) |
1029 | xmalloc (type_vector_length * sizeof (struct type *)); | |
1030 | bzero (type_vector, type_vector_length * sizeof (struct type *)); | |
bd5635a1 RP |
1031 | |
1032 | /* Initialize the list of sub source files with one entry | |
1033 | for this file (the top-level source file). */ | |
1034 | ||
1035 | subfiles = 0; | |
1036 | current_subfile = 0; | |
1037 | start_subfile (name, dirname); | |
1038 | } | |
1039 | ||
1040 | /* Handle an N_SOL symbol, which indicates the start of | |
1041 | code that came from an included (or otherwise merged-in) | |
1042 | source file with a different name. */ | |
1043 | ||
1044 | static void | |
1045 | start_subfile (name, dirname) | |
1046 | char *name; | |
1047 | char *dirname; | |
1048 | { | |
1049 | register struct subfile *subfile; | |
1050 | ||
1051 | /* Save the current subfile's line vector data. */ | |
1052 | ||
1053 | if (current_subfile) | |
1054 | { | |
1055 | current_subfile->line_vector_index = line_vector_index; | |
1056 | current_subfile->line_vector_length = line_vector_length; | |
1057 | current_subfile->prev_line_number = prev_line_number; | |
1058 | } | |
1059 | ||
1060 | /* See if this subfile is already known as a subfile of the | |
1061 | current main source file. */ | |
1062 | ||
1063 | for (subfile = subfiles; subfile; subfile = subfile->next) | |
1064 | { | |
1065 | if (!strcmp (subfile->name, name)) | |
1066 | { | |
1067 | line_vector = subfile->line_vector; | |
1068 | line_vector_index = subfile->line_vector_index; | |
1069 | line_vector_length = subfile->line_vector_length; | |
1070 | prev_line_number = subfile->prev_line_number; | |
1071 | current_subfile = subfile; | |
1072 | return; | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | /* This subfile is not known. Add an entry for it. */ | |
1077 | ||
1078 | line_vector_index = 0; | |
1079 | line_vector_length = 1000; | |
1080 | prev_line_number = -2; /* Force first line number to be explicit */ | |
1081 | line_vector = (struct linetable *) | |
1082 | xmalloc (sizeof (struct linetable) | |
1083 | + line_vector_length * sizeof (struct linetable_entry)); | |
1084 | ||
1085 | /* Make an entry for this subfile in the list of all subfiles | |
1086 | of the current main source file. */ | |
1087 | ||
1088 | subfile = (struct subfile *) xmalloc (sizeof (struct subfile)); | |
1089 | subfile->next = subfiles; | |
1090 | subfile->name = obsavestring (name, strlen (name)); | |
1091 | if (dirname == NULL) | |
1092 | subfile->dirname = NULL; | |
1093 | else | |
1094 | subfile->dirname = obsavestring (dirname, strlen (dirname)); | |
1095 | ||
1096 | subfile->line_vector = line_vector; | |
1097 | subfiles = subfile; | |
1098 | current_subfile = subfile; | |
1099 | } | |
1100 | ||
1101 | /* Finish the symbol definitions for one main source file, | |
1102 | close off all the lexical contexts for that file | |
1103 | (creating struct block's for them), then make the struct symtab | |
1104 | for that file and put it in the list of all such. | |
1105 | ||
1106 | END_ADDR is the address of the end of the file's text. */ | |
1107 | ||
9404978d | 1108 | static struct symtab * |
bd5635a1 RP |
1109 | end_symtab (end_addr) |
1110 | CORE_ADDR end_addr; | |
1111 | { | |
1112 | register struct symtab *symtab; | |
1113 | register struct blockvector *blockvector; | |
1114 | register struct subfile *subfile; | |
1115 | register struct linetable *lv; | |
1116 | struct subfile *nextsub; | |
1117 | ||
1118 | /* Finish the lexical context of the last function in the file; | |
1119 | pop the context stack. */ | |
1120 | ||
1121 | if (context_stack_depth > 0) | |
1122 | { | |
1123 | register struct context_stack *cstk; | |
1124 | context_stack_depth--; | |
1125 | cstk = &context_stack[context_stack_depth]; | |
1126 | /* Make a block for the local symbols within. */ | |
1127 | finish_block (cstk->name, &local_symbols, cstk->old_blocks, | |
1128 | cstk->start_addr, end_addr); | |
1129 | } | |
1130 | ||
1131 | /* Cleanup any undefined types that have been left hanging around | |
1132 | (this needs to be done before the finish_blocks so that | |
1133 | file_symbols is still good). */ | |
1134 | cleanup_undefined_types (); | |
1135 | ||
3f83182d | 1136 | /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */ |
bd5635a1 RP |
1137 | finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr); |
1138 | finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr); | |
1139 | blockvector = make_blockvector (); | |
1140 | ||
1141 | current_subfile->line_vector_index = line_vector_index; | |
1142 | ||
1143 | /* Now create the symtab objects proper, one for each subfile. */ | |
9404978d | 1144 | /* (The main file is the last one on the chain.) */ |
bd5635a1 RP |
1145 | |
1146 | for (subfile = subfiles; subfile; subfile = nextsub) | |
1147 | { | |
0c4d2cc2 | 1148 | symtab = allocate_symtab (subfile->name); |
bd5635a1 RP |
1149 | |
1150 | /* Fill in its components. */ | |
1151 | symtab->blockvector = blockvector; | |
1152 | lv = subfile->line_vector; | |
1153 | lv->nitems = subfile->line_vector_index; | |
1154 | symtab->linetable = (struct linetable *) | |
1155 | xrealloc (lv, (sizeof (struct linetable) | |
1156 | + lv->nitems * sizeof (struct linetable_entry))); | |
bd5635a1 | 1157 | |
bd5635a1 RP |
1158 | symtab->dirname = subfile->dirname; |
1159 | ||
1160 | symtab->free_code = free_linetable; | |
1161 | symtab->free_ptr = 0; | |
bd5635a1 | 1162 | |
f9623881 JG |
1163 | /* There should never already be a symtab for this name, since |
1164 | any prev dups have been removed when the psymtab was read in. | |
1165 | FIXME, there ought to be a way to check this here. */ | |
1166 | /* FIXME blewit |= free_named_symtabs (symtab->filename); */ | |
bd5635a1 RP |
1167 | |
1168 | /* Link the new symtab into the list of such. */ | |
1169 | symtab->next = symtab_list; | |
1170 | symtab_list = symtab; | |
1171 | ||
1172 | nextsub = subfile->next; | |
1173 | free (subfile); | |
1174 | } | |
1175 | ||
7cefc05e | 1176 | free ((char *) type_vector); |
bd5635a1 RP |
1177 | type_vector = 0; |
1178 | type_vector_length = -1; | |
1179 | line_vector = 0; | |
1180 | line_vector_length = -1; | |
1181 | last_source_file = 0; | |
9404978d MT |
1182 | |
1183 | return symtab; | |
bd5635a1 RP |
1184 | } |
1185 | \f | |
1186 | /* Handle the N_BINCL and N_EINCL symbol types | |
1187 | that act like N_SOL for switching source files | |
1188 | (different subfiles, as we call them) within one object file, | |
1189 | but using a stack rather than in an arbitrary order. */ | |
1190 | ||
1191 | struct subfile_stack | |
1192 | { | |
1193 | struct subfile_stack *next; | |
1194 | char *name; | |
1195 | int prev_index; | |
1196 | }; | |
1197 | ||
1198 | struct subfile_stack *subfile_stack; | |
1199 | ||
1200 | static void | |
1201 | push_subfile () | |
1202 | { | |
1203 | register struct subfile_stack *tem | |
1204 | = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack)); | |
1205 | ||
1206 | tem->next = subfile_stack; | |
1207 | subfile_stack = tem; | |
1208 | if (current_subfile == 0 || current_subfile->name == 0) | |
1209 | abort (); | |
1210 | tem->name = current_subfile->name; | |
1211 | tem->prev_index = header_file_prev_index; | |
1212 | } | |
1213 | ||
1214 | static char * | |
1215 | pop_subfile () | |
1216 | { | |
1217 | register char *name; | |
1218 | register struct subfile_stack *link = subfile_stack; | |
1219 | ||
1220 | if (link == 0) | |
1221 | abort (); | |
1222 | ||
1223 | name = link->name; | |
1224 | subfile_stack = link->next; | |
1225 | header_file_prev_index = link->prev_index; | |
1226 | free (link); | |
1227 | ||
1228 | return name; | |
1229 | } | |
1230 | \f | |
9bba3334 | 1231 | static void |
bd5635a1 RP |
1232 | record_misc_function (name, address, type) |
1233 | char *name; | |
1234 | CORE_ADDR address; | |
1235 | int type; | |
1236 | { | |
0c4d2cc2 JG |
1237 | enum misc_function_type misc_type; |
1238 | ||
1239 | switch (type &~ N_EXT) { | |
1240 | case N_TEXT: misc_type = mf_text; break; | |
1241 | case N_DATA: misc_type = mf_data; break; | |
1242 | case N_BSS: misc_type = mf_bss; break; | |
1243 | case N_ABS: misc_type = mf_abs; break; | |
1244 | #ifdef N_SETV | |
1245 | case N_SETV: misc_type = mf_data; break; | |
1246 | #endif | |
1247 | default: misc_type = mf_unknown; break; | |
1248 | } | |
bd5635a1 RP |
1249 | |
1250 | prim_record_misc_function (obsavestring (name, strlen (name)), | |
1251 | address, misc_type); | |
1252 | } | |
1253 | \f | |
e1ce8aa5 JK |
1254 | /* The BFD for this file -- only good while we're actively reading |
1255 | symbols into a psymtab or a symtab. */ | |
1256 | ||
1257 | static bfd *symfile_bfd; | |
1258 | ||
bd5635a1 RP |
1259 | /* Scan and build partial symbols for a symbol file. |
1260 | We have been initialized by a call to dbx_symfile_init, which | |
1261 | put all the relevant info into a "struct dbx_symfile_info" | |
1262 | hung off the struct sym_fns SF. | |
1263 | ||
1264 | ADDR is the address relative to which the symbols in it are (e.g. | |
1265 | the base address of the text segment). | |
1266 | MAINLINE is true if we are reading the main symbol | |
1267 | table (as opposed to a shared lib or dynamically loaded file). */ | |
1268 | ||
9bba3334 | 1269 | static void |
bd5635a1 RP |
1270 | dbx_symfile_read (sf, addr, mainline) |
1271 | struct sym_fns *sf; | |
1272 | CORE_ADDR addr; | |
1273 | int mainline; /* FIXME comments above */ | |
1274 | { | |
1275 | struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private); | |
1276 | bfd *sym_bfd = sf->sym_bfd; | |
1277 | int val; | |
1278 | char *filename = bfd_get_filename (sym_bfd); | |
1279 | ||
1280 | val = lseek (info->desc, info->symtab_offset, L_SET); | |
1281 | if (val < 0) | |
1282 | perror_with_name (filename); | |
1283 | ||
1284 | /* If mainline, set global string table pointers, and reinitialize global | |
1285 | partial symbol list. */ | |
1286 | if (mainline) { | |
1287 | symfile_string_table = info->stringtab; | |
1288 | symfile_string_table_size = info->stringtab_size; | |
bd5635a1 RP |
1289 | } |
1290 | ||
66eeea27 JG |
1291 | /* If we are reinitializing, or if we have never loaded syms yet, init */ |
1292 | if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0) | |
1293 | init_psymbol_list (info->symcount); | |
1294 | ||
bd5635a1 RP |
1295 | symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */ |
1296 | ||
1297 | pending_blocks = 0; | |
1298 | make_cleanup (really_free_pendings, 0); | |
1299 | ||
1300 | init_misc_bunches (); | |
1301 | make_cleanup (discard_misc_bunches, 0); | |
1302 | ||
1303 | /* Now that the symbol table data of the executable file are all in core, | |
1304 | process them and define symbols accordingly. */ | |
1305 | ||
1306 | read_dbx_symtab (filename, | |
1307 | addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/ | |
1308 | info->desc, info->stringtab, info->stringtab_size, | |
1309 | info->symcount, | |
1310 | bfd_section_vma (sym_bfd, info->text_sect), | |
1311 | bfd_section_size (sym_bfd, info->text_sect)); | |
1312 | ||
1313 | /* Go over the misc symbol bunches and install them in vector. */ | |
1314 | ||
1315 | condense_misc_bunches (!mainline); | |
1316 | ||
1317 | /* Free up any memory we allocated for ourselves. */ | |
1318 | ||
1319 | if (!mainline) { | |
1320 | free (info->stringtab); /* Stringtab is only saved for mainline */ | |
1321 | } | |
1322 | free (info); | |
1323 | sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */ | |
1324 | ||
9404978d MT |
1325 | if (!partial_symtab_list) { |
1326 | wrap_here (""); | |
1327 | printf_filtered ("(no debugging symbols found)..."); | |
1328 | wrap_here (""); | |
1329 | } | |
bd5635a1 RP |
1330 | } |
1331 | ||
9404978d MT |
1332 | /* Initialize anything that needs initializing when a completely new |
1333 | symbol file is specified (not just adding some symbols from another | |
1334 | file, e.g. a shared library). */ | |
bd5635a1 | 1335 | |
9bba3334 | 1336 | static void |
9404978d | 1337 | dbx_new_init () |
bd5635a1 | 1338 | { |
bd5635a1 RP |
1339 | /* Empty the hash table of global syms looking for values. */ |
1340 | bzero (global_sym_chain, sizeof global_sym_chain); | |
1341 | ||
1342 | free_pendings = 0; | |
1343 | file_symbols = 0; | |
1344 | global_symbols = 0; | |
bd5635a1 | 1345 | |
bd5635a1 | 1346 | /* Don't put these on the cleanup chain; they need to stick around |
9404978d | 1347 | until the next call to dbx_new_init. *Then* we'll free them. */ |
bd5635a1 RP |
1348 | if (symfile_string_table) |
1349 | { | |
1350 | free (symfile_string_table); | |
1351 | symfile_string_table = 0; | |
1352 | symfile_string_table_size = 0; | |
1353 | } | |
1354 | free_and_init_header_files (); | |
1355 | } | |
1356 | ||
1357 | ||
1358 | /* dbx_symfile_init () | |
1359 | is the dbx-specific initialization routine for reading symbols. | |
1360 | It is passed a struct sym_fns which contains, among other things, | |
1361 | the BFD for the file whose symbols are being read, and a slot for a pointer | |
1362 | to "private data" which we fill with goodies. | |
1363 | ||
1364 | We read the string table into malloc'd space and stash a pointer to it. | |
1365 | ||
1366 | Since BFD doesn't know how to read debug symbols in a format-independent | |
1367 | way (and may never do so...), we have to do it ourselves. We will never | |
1368 | be called unless this is an a.out (or very similar) file. | |
1369 | FIXME, there should be a cleaner peephole into the BFD environment here. */ | |
1370 | ||
9bba3334 | 1371 | static void |
bd5635a1 RP |
1372 | dbx_symfile_init (sf) |
1373 | struct sym_fns *sf; | |
1374 | { | |
1375 | int val; | |
1376 | int desc; | |
1377 | struct stat statbuf; | |
1378 | bfd *sym_bfd = sf->sym_bfd; | |
1379 | char *name = bfd_get_filename (sym_bfd); | |
1380 | struct dbx_symfile_info *info; | |
1381 | unsigned char size_temp[4]; | |
1382 | ||
1383 | /* Allocate struct to keep track of the symfile */ | |
1384 | sf->sym_private = xmalloc (sizeof (*info)); /* FIXME storage leak */ | |
1385 | info = (struct dbx_symfile_info *)sf->sym_private; | |
1386 | ||
1387 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
1388 | desc = fileno ((FILE *)(sym_bfd->iostream)); /* Raw file descriptor */ | |
1389 | #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd)) | |
1390 | #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd)) | |
1391 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
1392 | ||
1393 | info->desc = desc; | |
1394 | info->text_sect = bfd_get_section_by_name (sym_bfd, ".text"); | |
1395 | if (!info->text_sect) | |
1396 | abort(); | |
63989338 | 1397 | info->symcount = bfd_get_symcount (sym_bfd); |
bd5635a1 RP |
1398 | |
1399 | /* Read the string table size and check it for bogosity. */ | |
1400 | val = lseek (desc, STRING_TABLE_OFFSET, L_SET); | |
1401 | if (val < 0) | |
1402 | perror_with_name (name); | |
1403 | if (fstat (desc, &statbuf) == -1) | |
1404 | perror_with_name (name); | |
1405 | ||
1406 | val = myread (desc, size_temp, sizeof (long)); | |
1407 | if (val < 0) | |
1408 | perror_with_name (name); | |
dcc35536 | 1409 | info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp); |
bd5635a1 RP |
1410 | |
1411 | if (info->stringtab_size >= 0 && info->stringtab_size < statbuf.st_size) | |
1412 | { | |
1413 | info->stringtab = (char *) xmalloc (info->stringtab_size); | |
1414 | /* Caller is responsible for freeing the string table. No cleanup. */ | |
1415 | } | |
1416 | else | |
1417 | info->stringtab = NULL; | |
1418 | if (info->stringtab == NULL && info->stringtab_size != 0) | |
1419 | error ("ridiculous string table size: %d bytes", info->stringtab_size); | |
1420 | ||
1421 | /* Now read in the string table in one big gulp. */ | |
1422 | ||
1423 | val = lseek (desc, STRING_TABLE_OFFSET, L_SET); | |
1424 | if (val < 0) | |
1425 | perror_with_name (name); | |
1426 | val = myread (desc, info->stringtab, info->stringtab_size); | |
1427 | if (val < 0) | |
1428 | perror_with_name (name); | |
1429 | ||
1430 | /* Record the position of the symbol table for later use. */ | |
1431 | ||
1432 | info->symtab_offset = SYMBOL_TABLE_OFFSET; | |
1433 | } | |
1434 | \f | |
1435 | /* Buffer for reading the symbol table entries. */ | |
1436 | static struct nlist symbuf[4096]; | |
1437 | static int symbuf_idx; | |
1438 | static int symbuf_end; | |
1439 | ||
1440 | /* I/O descriptor for reading the symbol table. */ | |
1441 | static int symtab_input_desc; | |
1442 | ||
1443 | /* The address in memory of the string table of the object file we are | |
1444 | reading (which might not be the "main" object file, but might be a | |
1445 | shared library or some other dynamically loaded thing). This is set | |
1446 | by read_dbx_symtab when building psymtabs, and by read_ofile_symtab | |
1447 | when building symtabs, and is used only by next_symbol_text. */ | |
1448 | static char *stringtab_global; | |
1449 | ||
1450 | /* Refill the symbol table input buffer | |
1451 | and set the variables that control fetching entries from it. | |
1452 | Reports an error if no data available. | |
1453 | This function can read past the end of the symbol table | |
1454 | (into the string table) but this does no harm. */ | |
1455 | ||
1456 | static int | |
1457 | fill_symbuf () | |
1458 | { | |
1459 | int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf)); | |
1460 | if (nbytes < 0) | |
1461 | perror_with_name ("<symbol file>"); | |
1462 | else if (nbytes == 0) | |
1463 | error ("Premature end of file reading symbol table"); | |
1464 | symbuf_end = nbytes / sizeof (struct nlist); | |
1465 | symbuf_idx = 0; | |
1466 | return 1; | |
1467 | } | |
1468 | ||
1469 | #define SWAP_SYMBOL(symp) \ | |
1470 | { \ | |
dcc35536 | 1471 | (symp)->n_un.n_strx = bfd_h_get_32(symfile_bfd, \ |
bd5635a1 | 1472 | (unsigned char *)&(symp)->n_un.n_strx); \ |
dcc35536 | 1473 | (symp)->n_desc = bfd_h_get_16 (symfile_bfd, \ |
bd5635a1 | 1474 | (unsigned char *)&(symp)->n_desc); \ |
dcc35536 | 1475 | (symp)->n_value = bfd_h_get_32 (symfile_bfd, \ |
bd5635a1 RP |
1476 | (unsigned char *)&(symp)->n_value); \ |
1477 | } | |
1478 | ||
1479 | /* Invariant: The symbol pointed to by symbuf_idx is the first one | |
1480 | that hasn't been swapped. Swap the symbol at the same time | |
1481 | that symbuf_idx is incremented. */ | |
1482 | ||
1483 | /* dbx allows the text of a symbol name to be continued into the | |
1484 | next symbol name! When such a continuation is encountered | |
1485 | (a \ at the end of the text of a name) | |
1486 | call this function to get the continuation. */ | |
1487 | ||
1488 | static char * | |
1489 | next_symbol_text () | |
1490 | { | |
1491 | if (symbuf_idx == symbuf_end) | |
1492 | fill_symbuf (); | |
1493 | symnum++; | |
1494 | SWAP_SYMBOL(&symbuf[symbuf_idx]); | |
1495 | return symbuf[symbuf_idx++].n_un.n_strx + stringtab_global; | |
1496 | } | |
1497 | \f | |
1498 | /* Initializes storage for all of the partial symbols that will be | |
1499 | created by read_dbx_symtab and subsidiaries. */ | |
1500 | ||
1501 | static void | |
1502 | init_psymbol_list (total_symbols) | |
1503 | int total_symbols; | |
1504 | { | |
1505 | /* Free any previously allocated psymbol lists. */ | |
1506 | if (global_psymbols.list) | |
1507 | free (global_psymbols.list); | |
1508 | if (static_psymbols.list) | |
1509 | free (static_psymbols.list); | |
1510 | ||
1511 | /* Current best guess is that there are approximately a twentieth | |
1512 | of the total symbols (in a debugging file) are global or static | |
1513 | oriented symbols */ | |
1514 | global_psymbols.size = total_symbols / 10; | |
1515 | static_psymbols.size = total_symbols / 10; | |
1516 | global_psymbols.next = global_psymbols.list = (struct partial_symbol *) | |
1517 | xmalloc (global_psymbols.size * sizeof (struct partial_symbol)); | |
1518 | static_psymbols.next = static_psymbols.list = (struct partial_symbol *) | |
1519 | xmalloc (static_psymbols.size * sizeof (struct partial_symbol)); | |
1520 | } | |
1521 | ||
1522 | /* Initialize the list of bincls to contain none and have some | |
1523 | allocated. */ | |
1524 | ||
1525 | static void | |
1526 | init_bincl_list (number) | |
1527 | int number; | |
1528 | { | |
1529 | bincls_allocated = number; | |
1530 | next_bincl = bincl_list = (struct header_file_location *) | |
1531 | xmalloc (bincls_allocated * sizeof(struct header_file_location)); | |
1532 | } | |
1533 | ||
1534 | /* Add a bincl to the list. */ | |
1535 | ||
1536 | static void | |
1537 | add_bincl_to_list (pst, name, instance) | |
1538 | struct partial_symtab *pst; | |
1539 | char *name; | |
1540 | int instance; | |
1541 | { | |
1542 | if (next_bincl >= bincl_list + bincls_allocated) | |
1543 | { | |
1544 | int offset = next_bincl - bincl_list; | |
1545 | bincls_allocated *= 2; | |
1546 | bincl_list = (struct header_file_location *) | |
1547 | xrealloc ((char *)bincl_list, | |
1548 | bincls_allocated * sizeof (struct header_file_location)); | |
1549 | next_bincl = bincl_list + offset; | |
1550 | } | |
1551 | next_bincl->pst = pst; | |
1552 | next_bincl->instance = instance; | |
1553 | next_bincl++->name = name; | |
1554 | } | |
1555 | ||
1556 | /* Given a name, value pair, find the corresponding | |
1557 | bincl in the list. Return the partial symtab associated | |
1558 | with that header_file_location. */ | |
1559 | ||
9bba3334 | 1560 | static struct partial_symtab * |
bd5635a1 RP |
1561 | find_corresponding_bincl_psymtab (name, instance) |
1562 | char *name; | |
1563 | int instance; | |
1564 | { | |
1565 | struct header_file_location *bincl; | |
1566 | ||
1567 | for (bincl = bincl_list; bincl < next_bincl; bincl++) | |
1568 | if (bincl->instance == instance | |
1569 | && !strcmp (name, bincl->name)) | |
1570 | return bincl->pst; | |
1571 | ||
1572 | return (struct partial_symtab *) 0; | |
1573 | } | |
1574 | ||
1575 | /* Free the storage allocated for the bincl list. */ | |
1576 | ||
1577 | static void | |
1578 | free_bincl_list () | |
1579 | { | |
1580 | free (bincl_list); | |
1581 | bincls_allocated = 0; | |
1582 | } | |
1583 | ||
1584 | static struct partial_symtab *start_psymtab (); | |
1585 | static void end_psymtab(); | |
1586 | ||
1587 | #ifdef DEBUG | |
1588 | /* This is normally a macro defined in read_dbx_symtab, but this | |
1589 | is a lot easier to debug. */ | |
1590 | ||
1591 | ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, PLIST, VALUE) | |
1592 | char *NAME; | |
1593 | int NAMELENGTH; | |
1594 | enum namespace NAMESPACE; | |
1595 | enum address_class CLASS; | |
1596 | struct psymbol_allocation_list *PLIST; | |
1597 | unsigned long VALUE; | |
1598 | { | |
1599 | register struct partial_symbol *psym; | |
1600 | ||
1601 | #define LIST *PLIST | |
1602 | do { | |
1603 | if ((LIST).next >= | |
1604 | (LIST).list + (LIST).size) | |
1605 | { | |
1606 | (LIST).list = (struct partial_symbol *) | |
1607 | xrealloc ((LIST).list, | |
1608 | ((LIST).size * 2 | |
1609 | * sizeof (struct partial_symbol))); | |
1610 | /* Next assumes we only went one over. Should be good if | |
1611 | program works correctly */ | |
1612 | (LIST).next = | |
1613 | (LIST).list + (LIST).size; | |
1614 | (LIST).size *= 2; | |
1615 | } | |
1616 | psym = (LIST).next++; | |
1617 | #undef LIST | |
1618 | ||
1619 | SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, | |
1620 | (NAMELENGTH) + 1); | |
1621 | strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); | |
1622 | SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; | |
1623 | SYMBOL_NAMESPACE (psym) = (NAMESPACE); | |
1624 | SYMBOL_CLASS (psym) = (CLASS); | |
1625 | SYMBOL_VALUE (psym) = (VALUE); | |
1626 | } while (0); | |
1627 | } | |
1628 | ||
1629 | /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */ | |
1630 | #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \ | |
1631 | ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE) | |
1632 | ||
1633 | #endif /* DEBUG */ | |
1634 | ||
1635 | /* Given pointers to an a.out symbol table in core containing dbx | |
1636 | style data, setup partial_symtab's describing each source file for | |
1637 | which debugging information is available. NLISTLEN is the number | |
1638 | of symbols in the symbol table. All symbol names are given as | |
1639 | offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of | |
1640 | STRINGTAB. SYMFILE_NAME is the name of the file we are reading from | |
1641 | and ADDR is its relocated address (if incremental) or 0 (if not). */ | |
1642 | ||
1643 | static void | |
1644 | read_dbx_symtab (symfile_name, addr, | |
1645 | desc, stringtab, stringtab_size, nlistlen, | |
1646 | text_addr, text_size) | |
1647 | char *symfile_name; | |
1648 | CORE_ADDR addr; | |
1649 | int desc; | |
1650 | register char *stringtab; | |
1651 | register long stringtab_size; | |
1652 | register int nlistlen; | |
1653 | CORE_ADDR text_addr; | |
1654 | int text_size; | |
1655 | { | |
1656 | register struct nlist *bufp; | |
1657 | register char *namestring; | |
1658 | register struct partial_symbol *psym; | |
1659 | int nsl; | |
1660 | int past_first_source_file = 0; | |
1661 | CORE_ADDR last_o_file_start = 0; | |
1662 | struct cleanup *old_chain; | |
1663 | char *p; | |
1664 | ||
1665 | /* End of the text segment of the executable file. */ | |
1666 | CORE_ADDR end_of_text_addr; | |
1667 | ||
1668 | /* Current partial symtab */ | |
1669 | struct partial_symtab *pst; | |
1670 | ||
1671 | /* List of current psymtab's include files */ | |
1672 | char **psymtab_include_list; | |
1673 | int includes_allocated; | |
1674 | int includes_used; | |
1675 | ||
1676 | /* Index within current psymtab dependency list */ | |
1677 | struct partial_symtab **dependency_list; | |
1678 | int dependencies_used, dependencies_allocated; | |
1679 | ||
1680 | stringtab_global = stringtab; | |
1681 | ||
1682 | pst = (struct partial_symtab *) 0; | |
1683 | ||
1684 | includes_allocated = 30; | |
1685 | includes_used = 0; | |
1686 | psymtab_include_list = (char **) alloca (includes_allocated * | |
1687 | sizeof (char *)); | |
1688 | ||
1689 | dependencies_allocated = 30; | |
1690 | dependencies_used = 0; | |
1691 | dependency_list = | |
1692 | (struct partial_symtab **) alloca (dependencies_allocated * | |
1693 | sizeof (struct partial_symtab *)); | |
1694 | ||
1695 | /* FIXME!! If an error occurs, this blows away the whole symbol table! | |
1696 | It should only blow away the psymtabs created herein. We could | |
1697 | be reading a shared library or a dynloaded file! */ | |
1698 | old_chain = make_cleanup (free_all_psymtabs, 0); | |
1699 | ||
1700 | /* Init bincl list */ | |
1701 | init_bincl_list (20); | |
1702 | make_cleanup (free_bincl_list, 0); | |
1703 | ||
1704 | last_source_file = 0; | |
1705 | ||
1706 | #ifdef END_OF_TEXT_DEFAULT | |
1707 | end_of_text_addr = END_OF_TEXT_DEFAULT; | |
1708 | #else | |
5bc757e2 | 1709 | end_of_text_addr = text_addr + addr + text_size; /* Relocate */ |
bd5635a1 RP |
1710 | #endif |
1711 | ||
1712 | symtab_input_desc = desc; /* This is needed for fill_symbuf below */ | |
1713 | symbuf_end = symbuf_idx = 0; | |
1714 | ||
1715 | for (symnum = 0; symnum < nlistlen; symnum++) | |
1716 | { | |
1717 | /* Get the symbol for this run and pull out some info */ | |
1718 | QUIT; /* allow this to be interruptable */ | |
1719 | if (symbuf_idx == symbuf_end) | |
1720 | fill_symbuf (); | |
1721 | bufp = &symbuf[symbuf_idx++]; | |
1722 | ||
1723 | /* | |
1724 | * Special case to speed up readin. | |
1725 | */ | |
1726 | if (bufp->n_type == (unsigned char)N_SLINE) continue; | |
1727 | ||
1728 | SWAP_SYMBOL (bufp); | |
1729 | ||
1730 | /* Ok. There is a lot of code duplicated in the rest of this | |
1731 | switch statement (for efficiency reasons). Since I don't | |
1732 | like duplicating code, I will do my penance here, and | |
1733 | describe the code which is duplicated: | |
1734 | ||
1735 | *) The assignment to namestring. | |
1736 | *) The call to strchr. | |
1737 | *) The addition of a partial symbol the the two partial | |
1738 | symbol lists. This last is a large section of code, so | |
1739 | I've imbedded it in the following macro. | |
1740 | */ | |
1741 | ||
1742 | /* Set namestring based on bufp. If the string table index is invalid, | |
1743 | give a fake name, and print a single error message per symbol file read, | |
1744 | rather than abort the symbol reading or flood the user with messages. */ | |
1745 | #define SET_NAMESTRING()\ | |
1746 | if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) { \ | |
1747 | complain (&string_table_offset_complaint, symnum); \ | |
1748 | namestring = "foo"; \ | |
1749 | } else \ | |
1750 | namestring = bufp->n_un.n_strx + stringtab | |
1751 | ||
1752 | /* Add a symbol with an integer value to a psymtab. */ | |
1753 | /* This is a macro unless we're debugging. See above this function. */ | |
1754 | #ifndef DEBUG | |
1755 | # define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \ | |
1756 | ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \ | |
1757 | SYMBOL_VALUE) | |
1758 | #endif /* DEBUG */ | |
1759 | ||
1760 | /* Add a symbol with a CORE_ADDR value to a psymtab. */ | |
1761 | #define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \ | |
1762 | ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \ | |
1763 | SYMBOL_VALUE_ADDRESS) | |
1764 | ||
1765 | /* Add any kind of symbol to a psymtab. */ | |
1766 | #define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\ | |
1767 | do { \ | |
1768 | if ((LIST).next >= \ | |
1769 | (LIST).list + (LIST).size) \ | |
1770 | { \ | |
1771 | (LIST).list = (struct partial_symbol *) \ | |
1772 | xrealloc ((LIST).list, \ | |
1773 | ((LIST).size * 2 \ | |
1774 | * sizeof (struct partial_symbol))); \ | |
1775 | /* Next assumes we only went one over. Should be good if \ | |
1776 | program works correctly */ \ | |
1777 | (LIST).next = \ | |
1778 | (LIST).list + (LIST).size; \ | |
1779 | (LIST).size *= 2; \ | |
1780 | } \ | |
1781 | psym = (LIST).next++; \ | |
1782 | \ | |
1783 | SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \ | |
1784 | (NAMELENGTH) + 1); \ | |
1785 | strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \ | |
1786 | SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \ | |
1787 | SYMBOL_NAMESPACE (psym) = (NAMESPACE); \ | |
1788 | SYMBOL_CLASS (psym) = (CLASS); \ | |
1789 | VT (psym) = (VALUE); \ | |
1790 | } while (0); | |
1791 | ||
1792 | /* End of macro definitions, now let's handle them symbols! */ | |
1793 | ||
1794 | switch (bufp->n_type) | |
1795 | { | |
1796 | /* | |
1797 | * Standard, external, non-debugger, symbols | |
1798 | */ | |
1799 | ||
1800 | case N_TEXT | N_EXT: | |
1801 | case N_NBTEXT | N_EXT: | |
1802 | case N_NBDATA | N_EXT: | |
1803 | case N_NBBSS | N_EXT: | |
1804 | case N_SETV | N_EXT: | |
1805 | case N_ABS | N_EXT: | |
1806 | case N_DATA | N_EXT: | |
1807 | case N_BSS | N_EXT: | |
1808 | ||
1809 | bufp->n_value += addr; /* Relocate */ | |
1810 | ||
1811 | SET_NAMESTRING(); | |
1812 | ||
1813 | bss_ext_symbol: | |
1814 | record_misc_function (namestring, bufp->n_value, | |
1815 | bufp->n_type); /* Always */ | |
1816 | ||
1817 | continue; | |
1818 | ||
1819 | /* Standard, local, non-debugger, symbols */ | |
1820 | ||
1821 | case N_NBTEXT: | |
1822 | ||
1823 | /* We need to be able to deal with both N_FN or N_TEXT, | |
1824 | because we have no way of knowing whether the sys-supplied ld | |
1825 | or GNU ld was used to make the executable. */ | |
bd5635a1 | 1826 | case N_FN: |
bd5635a1 RP |
1827 | case N_TEXT: |
1828 | bufp->n_value += addr; /* Relocate */ | |
1829 | SET_NAMESTRING(); | |
1830 | if ((namestring[0] == '-' && namestring[1] == 'l') | |
1831 | || (namestring [(nsl = strlen (namestring)) - 1] == 'o' | |
1832 | && namestring [nsl - 2] == '.')) | |
1833 | { | |
1834 | if (entry_point < bufp->n_value | |
1835 | && entry_point >= last_o_file_start | |
1836 | && addr == 0) /* FIXME nogood nomore */ | |
1837 | { | |
1838 | startup_file_start = last_o_file_start; | |
1839 | startup_file_end = bufp->n_value; | |
1840 | } | |
1841 | if (past_first_source_file && pst | |
1842 | /* The gould NP1 uses low values for .o and -l symbols | |
1843 | which are not the address. */ | |
1844 | && bufp->n_value > pst->textlow) | |
1845 | { | |
1846 | end_psymtab (pst, psymtab_include_list, includes_used, | |
1847 | symnum * sizeof (struct nlist), bufp->n_value, | |
1848 | dependency_list, dependencies_used, | |
1849 | global_psymbols.next, static_psymbols.next); | |
1850 | pst = (struct partial_symtab *) 0; | |
1851 | includes_used = 0; | |
1852 | dependencies_used = 0; | |
1853 | } | |
1854 | else | |
1855 | past_first_source_file = 1; | |
1856 | last_o_file_start = bufp->n_value; | |
1857 | } | |
1858 | continue; | |
1859 | ||
1860 | case N_DATA: | |
1861 | bufp->n_value += addr; /* Relocate */ | |
1862 | SET_NAMESTRING (); | |
1863 | /* Check for __DYNAMIC, which is used by Sun shared libraries. | |
62c4f98b JK |
1864 | Record it even if it's local, not global, so we can find it. |
1865 | Same with virtual function tables, both global and static. */ | |
1866 | if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0)) | |
1867 | || VTBL_PREFIX_P ((namestring+HASH_OFFSET))) | |
bd5635a1 RP |
1868 | { |
1869 | /* Not really a function here, but... */ | |
1870 | record_misc_function (namestring, bufp->n_value, | |
1871 | bufp->n_type); /* Always */ | |
1872 | } | |
1873 | continue; | |
1874 | ||
1875 | case N_UNDF | N_EXT: | |
1876 | if (bufp->n_value != 0) { | |
1877 | /* This is a "Fortran COMMON" symbol. See if the target | |
1878 | environment knows where it has been relocated to. */ | |
1879 | ||
1880 | CORE_ADDR reladdr; | |
1881 | ||
1882 | SET_NAMESTRING(); | |
1883 | if (target_lookup_symbol (namestring, &reladdr)) { | |
1884 | continue; /* Error in lookup; ignore symbol for now. */ | |
1885 | } | |
1886 | bufp->n_type ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */ | |
1887 | bufp->n_value = reladdr; | |
1888 | goto bss_ext_symbol; | |
1889 | } | |
1890 | continue; /* Just undefined, not COMMON */ | |
1891 | ||
1892 | /* Lots of symbol types we can just ignore. */ | |
1893 | ||
1894 | case N_UNDF: | |
1895 | case N_ABS: | |
1896 | case N_BSS: | |
1897 | case N_NBDATA: | |
1898 | case N_NBBSS: | |
1899 | continue; | |
1900 | ||
1901 | /* Keep going . . .*/ | |
1902 | ||
1903 | /* | |
1904 | * Special symbol types for GNU | |
1905 | */ | |
1906 | case N_INDR: | |
1907 | case N_INDR | N_EXT: | |
1908 | case N_SETA: | |
1909 | case N_SETA | N_EXT: | |
1910 | case N_SETT: | |
1911 | case N_SETT | N_EXT: | |
1912 | case N_SETD: | |
1913 | case N_SETD | N_EXT: | |
1914 | case N_SETB: | |
1915 | case N_SETB | N_EXT: | |
1916 | case N_SETV: | |
1917 | continue; | |
1918 | ||
1919 | /* | |
1920 | * Debugger symbols | |
1921 | */ | |
1922 | ||
1923 | case N_SO: { | |
1924 | unsigned long valu = bufp->n_value; | |
1925 | /* Symbol number of the first symbol of this file (i.e. the N_SO | |
1926 | if there is just one, or the first if we have a pair). */ | |
1927 | int first_symnum = symnum; | |
1928 | ||
1929 | /* End the current partial symtab and start a new one */ | |
1930 | ||
1931 | SET_NAMESTRING(); | |
1932 | ||
1933 | /* Peek at the next symbol. If it is also an N_SO, the | |
1934 | first one just indicates the directory. */ | |
1935 | if (symbuf_idx == symbuf_end) | |
1936 | fill_symbuf (); | |
1937 | bufp = &symbuf[symbuf_idx]; | |
1938 | /* n_type is only a char, so swapping swapping is irrelevant. */ | |
1939 | if (bufp->n_type == (unsigned char)N_SO) | |
1940 | { | |
1941 | SWAP_SYMBOL (bufp); | |
1942 | SET_NAMESTRING (); | |
1943 | valu = bufp->n_value; | |
1944 | symbuf_idx++; | |
1945 | symnum++; | |
1946 | } | |
1947 | valu += addr; /* Relocate */ | |
1948 | ||
1949 | if (pst && past_first_source_file) | |
1950 | { | |
1951 | end_psymtab (pst, psymtab_include_list, includes_used, | |
1952 | first_symnum * sizeof (struct nlist), valu, | |
1953 | dependency_list, dependencies_used, | |
1954 | global_psymbols.next, static_psymbols.next); | |
1955 | pst = (struct partial_symtab *) 0; | |
1956 | includes_used = 0; | |
1957 | dependencies_used = 0; | |
1958 | } | |
1959 | else | |
1960 | past_first_source_file = 1; | |
1961 | ||
1962 | pst = start_psymtab (symfile_name, addr, | |
1963 | namestring, valu, | |
1964 | first_symnum * sizeof (struct nlist), | |
1965 | global_psymbols.next, static_psymbols.next); | |
bd5635a1 RP |
1966 | continue; |
1967 | } | |
1968 | ||
1969 | case N_BINCL: | |
1970 | /* Add this bincl to the bincl_list for future EXCLs. No | |
1971 | need to save the string; it'll be around until | |
1972 | read_dbx_symtab function returns */ | |
1973 | ||
1974 | SET_NAMESTRING(); | |
1975 | ||
1976 | add_bincl_to_list (pst, namestring, bufp->n_value); | |
1977 | ||
1978 | /* Mark down an include file in the current psymtab */ | |
1979 | ||
1980 | psymtab_include_list[includes_used++] = namestring; | |
1981 | if (includes_used >= includes_allocated) | |
1982 | { | |
1983 | char **orig = psymtab_include_list; | |
1984 | ||
1985 | psymtab_include_list = (char **) | |
1986 | alloca ((includes_allocated *= 2) * | |
1987 | sizeof (char *)); | |
1988 | bcopy (orig, psymtab_include_list, | |
1989 | includes_used * sizeof (char *)); | |
1990 | } | |
1991 | ||
1992 | continue; | |
1993 | ||
1994 | case N_SOL: | |
1995 | /* Mark down an include file in the current psymtab */ | |
1996 | ||
1997 | SET_NAMESTRING(); | |
1998 | ||
1999 | /* In C++, one may expect the same filename to come round many | |
2000 | times, when code is coming alternately from the main file | |
2001 | and from inline functions in other files. So I check to see | |
f9623881 JG |
2002 | if this is a file we've seen before -- either the main |
2003 | source file, or a previously included file. | |
bd5635a1 RP |
2004 | |
2005 | This seems to be a lot of time to be spending on N_SOL, but | |
9bb30452 | 2006 | things like "break c-exp.y:435" need to work (I |
bd5635a1 RP |
2007 | suppose the psymtab_include_list could be hashed or put |
2008 | in a binary tree, if profiling shows this is a major hog). */ | |
f9623881 JG |
2009 | if (!strcmp (namestring, pst->filename)) |
2010 | continue; | |
bd5635a1 RP |
2011 | { |
2012 | register int i; | |
2013 | for (i = 0; i < includes_used; i++) | |
2014 | if (!strcmp (namestring, psymtab_include_list[i])) | |
2015 | { | |
2016 | i = -1; | |
2017 | break; | |
2018 | } | |
2019 | if (i == -1) | |
2020 | continue; | |
2021 | } | |
2022 | ||
2023 | psymtab_include_list[includes_used++] = namestring; | |
2024 | if (includes_used >= includes_allocated) | |
2025 | { | |
2026 | char **orig = psymtab_include_list; | |
2027 | ||
2028 | psymtab_include_list = (char **) | |
2029 | alloca ((includes_allocated *= 2) * | |
2030 | sizeof (char *)); | |
2031 | bcopy (orig, psymtab_include_list, | |
2032 | includes_used * sizeof (char *)); | |
2033 | } | |
2034 | continue; | |
2035 | ||
2036 | case N_LSYM: /* Typedef or automatic variable. */ | |
9bb30452 JG |
2037 | case N_STSYM: /* Data seg var -- static */ |
2038 | case N_LCSYM: /* BSS " */ | |
2039 | case N_NBSTS: /* Gould nobase. */ | |
2040 | case N_NBLCS: /* symbols. */ | |
2041 | ||
bd5635a1 RP |
2042 | SET_NAMESTRING(); |
2043 | ||
2044 | p = (char *) strchr (namestring, ':'); | |
2045 | ||
2046 | /* Skip if there is no :. */ | |
2047 | if (!p) continue; | |
2048 | ||
2049 | switch (p[1]) | |
2050 | { | |
2051 | case 'T': | |
2052 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2053 | STRUCT_NAMESPACE, LOC_TYPEDEF, | |
2054 | static_psymbols, bufp->n_value); | |
2055 | if (p[2] == 't') | |
2056 | { | |
2057 | /* Also a typedef with the same name. */ | |
2058 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2059 | VAR_NAMESPACE, LOC_TYPEDEF, | |
2060 | static_psymbols, bufp->n_value); | |
2061 | p += 1; | |
2062 | } | |
2063 | goto check_enum; | |
2064 | case 't': | |
2065 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2066 | VAR_NAMESPACE, LOC_TYPEDEF, | |
2067 | static_psymbols, bufp->n_value); | |
2068 | check_enum: | |
2069 | /* If this is an enumerated type, we need to | |
2070 | add all the enum constants to the partial symbol | |
2071 | table. This does not cover enums without names, e.g. | |
2072 | "enum {a, b} c;" in C, but fortunately those are | |
2073 | rare. There is no way for GDB to find those from the | |
2074 | enum type without spending too much time on it. Thus | |
2075 | to solve this problem, the compiler needs to put out separate | |
2076 | constant symbols ('c' N_LSYMS) for enum constants in | |
2077 | enums without names, or put out a dummy type. */ | |
2078 | ||
2079 | /* We are looking for something of the form | |
2080 | <name> ":" ("t" | "T") [<number> "="] "e" | |
2081 | {<constant> ":" <value> ","} ";". */ | |
2082 | ||
2083 | /* Skip over the colon and the 't' or 'T'. */ | |
2084 | p += 2; | |
2085 | /* This type may be given a number. Skip over it. */ | |
2086 | while ((*p >= '0' && *p <= '9') | |
2087 | || *p == '=') | |
2088 | p++; | |
2089 | ||
2090 | if (*p++ == 'e') | |
2091 | { | |
2092 | /* We have found an enumerated type. */ | |
2093 | /* According to comments in read_enum_type | |
2094 | a comma could end it instead of a semicolon. | |
2095 | I don't know where that happens. | |
2096 | Accept either. */ | |
2097 | while (*p && *p != ';' && *p != ',') | |
2098 | { | |
2099 | char *q; | |
2100 | ||
2101 | /* Check for and handle cretinous dbx symbol name | |
2102 | continuation! */ | |
2103 | if (*p == '\\') | |
2104 | p = next_symbol_text (); | |
2105 | ||
2106 | /* Point to the character after the name | |
2107 | of the enum constant. */ | |
2108 | for (q = p; *q && *q != ':'; q++) | |
2109 | ; | |
2110 | /* Note that the value doesn't matter for | |
2111 | enum constants in psymtabs, just in symtabs. */ | |
2112 | ADD_PSYMBOL_TO_LIST (p, q - p, | |
2113 | VAR_NAMESPACE, LOC_CONST, | |
2114 | static_psymbols, 0); | |
2115 | /* Point past the name. */ | |
2116 | p = q; | |
2117 | /* Skip over the value. */ | |
2118 | while (*p && *p != ',') | |
2119 | p++; | |
2120 | /* Advance past the comma. */ | |
2121 | if (*p) | |
2122 | p++; | |
2123 | } | |
2124 | } | |
2125 | ||
2126 | continue; | |
2127 | case 'c': | |
2128 | /* Constant, e.g. from "const" in Pascal. */ | |
2129 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2130 | VAR_NAMESPACE, LOC_CONST, | |
2131 | static_psymbols, bufp->n_value); | |
2132 | continue; | |
2133 | default: | |
2134 | /* Skip if the thing following the : is | |
2135 | not a letter (which indicates declaration of a local | |
2136 | variable, which we aren't interested in). */ | |
2137 | continue; | |
2138 | } | |
2139 | ||
2140 | case N_FUN: | |
2141 | case N_GSYM: /* Global (extern) variable; can be | |
2142 | data or bss (sigh). */ | |
bd5635a1 RP |
2143 | |
2144 | /* Following may probably be ignored; I'll leave them here | |
2145 | for now (until I do Pascal and Modula 2 extensions). */ | |
2146 | ||
2147 | case N_PC: /* I may or may not need this; I | |
2148 | suspect not. */ | |
2149 | case N_M2C: /* I suspect that I can ignore this here. */ | |
2150 | case N_SCOPE: /* Same. */ | |
2151 | ||
2152 | SET_NAMESTRING(); | |
2153 | ||
2154 | p = (char *) strchr (namestring, ':'); | |
2155 | if (!p) | |
2156 | continue; /* Not a debugging symbol. */ | |
2157 | ||
2158 | ||
2159 | ||
2160 | /* Main processing section for debugging symbols which | |
2161 | the initial read through the symbol tables needs to worry | |
2162 | about. If we reach this point, the symbol which we are | |
2163 | considering is definitely one we are interested in. | |
2164 | p must also contain the (valid) index into the namestring | |
2165 | which indicates the debugging type symbol. */ | |
2166 | ||
2167 | switch (p[1]) | |
2168 | { | |
2169 | case 'c': | |
2170 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2171 | VAR_NAMESPACE, LOC_CONST, | |
2172 | static_psymbols, bufp->n_value); | |
2173 | continue; | |
2174 | case 'S': | |
2175 | bufp->n_value += addr; /* Relocate */ | |
2176 | ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring, | |
2177 | VAR_NAMESPACE, LOC_STATIC, | |
2178 | static_psymbols, bufp->n_value); | |
2179 | continue; | |
2180 | case 'G': | |
2181 | bufp->n_value += addr; /* Relocate */ | |
c3a21801 JG |
2182 | /* The addresses in these entries are reported to be |
2183 | wrong. See the code that reads 'G's for symtabs. */ | |
bd5635a1 | 2184 | ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring, |
c3a21801 | 2185 | VAR_NAMESPACE, LOC_STATIC, |
bd5635a1 RP |
2186 | global_psymbols, bufp->n_value); |
2187 | continue; | |
2188 | ||
2189 | case 't': | |
2190 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2191 | VAR_NAMESPACE, LOC_TYPEDEF, | |
9bb30452 | 2192 | static_psymbols, bufp->n_value); |
bd5635a1 RP |
2193 | continue; |
2194 | ||
2195 | case 'f': | |
2196 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2197 | VAR_NAMESPACE, LOC_BLOCK, | |
2198 | static_psymbols, bufp->n_value); | |
2199 | continue; | |
2200 | ||
f9623881 JG |
2201 | /* Global functions were ignored here, but now they |
2202 | are put into the global psymtab like one would expect. | |
2203 | They're also in the misc fn vector... | |
2204 | FIXME, why did it used to ignore these? That broke | |
2205 | "i fun" on these functions. */ | |
2206 | case 'F': | |
2207 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
2208 | VAR_NAMESPACE, LOC_BLOCK, | |
2209 | global_psymbols, bufp->n_value); | |
2210 | continue; | |
2211 | ||
bd5635a1 RP |
2212 | /* Two things show up here (hopefully); static symbols of |
2213 | local scope (static used inside braces) or extensions | |
2214 | of structure symbols. We can ignore both. */ | |
2215 | case 'V': | |
2216 | case '(': | |
2217 | case '0': | |
2218 | case '1': | |
2219 | case '2': | |
2220 | case '3': | |
2221 | case '4': | |
2222 | case '5': | |
2223 | case '6': | |
2224 | case '7': | |
2225 | case '8': | |
2226 | case '9': | |
bd5635a1 RP |
2227 | continue; |
2228 | ||
2229 | default: | |
2230 | /* Unexpected symbol. Ignore it; perhaps it is an extension | |
2231 | that we don't know about. | |
2232 | ||
2233 | Someone says sun cc puts out symbols like | |
2234 | /foo/baz/maclib::/usr/local/bin/maclib, | |
2235 | which would get here with a symbol type of ':'. */ | |
2236 | continue; | |
2237 | } | |
2238 | ||
2239 | case N_EXCL: | |
2240 | ||
2241 | SET_NAMESTRING(); | |
2242 | ||
2243 | /* Find the corresponding bincl and mark that psymtab on the | |
2244 | psymtab dependency list */ | |
2245 | { | |
2246 | struct partial_symtab *needed_pst = | |
2247 | find_corresponding_bincl_psymtab (namestring, bufp->n_value); | |
2248 | ||
2249 | /* If this include file was defined earlier in this file, | |
2250 | leave it alone. */ | |
2251 | if (needed_pst == pst) continue; | |
2252 | ||
2253 | if (needed_pst) | |
2254 | { | |
2255 | int i; | |
2256 | int found = 0; | |
2257 | ||
2258 | for (i = 0; i < dependencies_used; i++) | |
2259 | if (dependency_list[i] == needed_pst) | |
2260 | { | |
2261 | found = 1; | |
2262 | break; | |
2263 | } | |
2264 | ||
2265 | /* If it's already in the list, skip the rest. */ | |
2266 | if (found) continue; | |
2267 | ||
2268 | dependency_list[dependencies_used++] = needed_pst; | |
2269 | if (dependencies_used >= dependencies_allocated) | |
2270 | { | |
2271 | struct partial_symtab **orig = dependency_list; | |
2272 | dependency_list = | |
2273 | (struct partial_symtab **) | |
2274 | alloca ((dependencies_allocated *= 2) | |
2275 | * sizeof (struct partial_symtab *)); | |
2276 | bcopy (orig, dependency_list, | |
2277 | (dependencies_used | |
2278 | * sizeof (struct partial_symtab *))); | |
2279 | #ifdef DEBUG_INFO | |
2280 | fprintf (stderr, "Had to reallocate dependency list.\n"); | |
2281 | fprintf (stderr, "New dependencies allocated: %d\n", | |
2282 | dependencies_allocated); | |
2283 | #endif | |
2284 | } | |
2285 | } | |
2286 | else | |
2287 | error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.", | |
2288 | symnum); | |
2289 | } | |
2290 | continue; | |
2291 | ||
2292 | case N_EINCL: | |
2293 | case N_DSLINE: | |
2294 | case N_BSLINE: | |
2295 | case N_SSYM: /* Claim: Structure or union element. | |
2296 | Hopefully, I can ignore this. */ | |
2297 | case N_ENTRY: /* Alternate entry point; can ignore. */ | |
2298 | case N_MAIN: /* Can definitely ignore this. */ | |
2299 | case N_CATCH: /* These are GNU C++ extensions */ | |
2300 | case N_EHDECL: /* that can safely be ignored here. */ | |
2301 | case N_LENG: | |
2302 | case N_BCOMM: | |
2303 | case N_ECOMM: | |
2304 | case N_ECOML: | |
2305 | case N_FNAME: | |
2306 | case N_SLINE: | |
2307 | case N_RSYM: | |
2308 | case N_PSYM: | |
2309 | case N_LBRAC: | |
2310 | case N_RBRAC: | |
2311 | case N_NSYMS: /* Ultrix 4.0: symbol count */ | |
0c4d2cc2 | 2312 | case N_DEFD: /* GNU Modula-2 */ |
bd5635a1 RP |
2313 | /* These symbols aren't interesting; don't worry about them */ |
2314 | ||
2315 | continue; | |
2316 | ||
2317 | default: | |
2318 | /* If we haven't found it yet, ignore it. It's probably some | |
2319 | new type we don't know about yet. */ | |
0c4d2cc2 | 2320 | complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type)); |
bd5635a1 RP |
2321 | continue; |
2322 | } | |
2323 | } | |
2324 | ||
2325 | /* If there's stuff to be cleaned up, clean it up. */ | |
63989338 JG |
2326 | if (nlistlen > 0 /* We have some syms */ |
2327 | && entry_point < bufp->n_value | |
bd5635a1 RP |
2328 | && entry_point >= last_o_file_start) |
2329 | { | |
2330 | startup_file_start = last_o_file_start; | |
2331 | startup_file_end = bufp->n_value; | |
2332 | } | |
2333 | ||
2334 | if (pst) | |
2335 | { | |
2336 | end_psymtab (pst, psymtab_include_list, includes_used, | |
2337 | symnum * sizeof (struct nlist), end_of_text_addr, | |
2338 | dependency_list, dependencies_used, | |
2339 | global_psymbols.next, static_psymbols.next); | |
2340 | includes_used = 0; | |
2341 | dependencies_used = 0; | |
2342 | pst = (struct partial_symtab *) 0; | |
2343 | } | |
2344 | ||
2345 | free_bincl_list (); | |
2346 | discard_cleanups (old_chain); | |
2347 | } | |
2348 | ||
2349 | /* | |
2350 | * Allocate and partially fill a partial symtab. It will be | |
2351 | * completely filled at the end of the symbol list. | |
2352 | ||
2353 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
2354 | is the address relative to which its symbols are (incremental) or 0 | |
2355 | (normal). */ | |
2356 | static struct partial_symtab * | |
2357 | start_psymtab (symfile_name, addr, | |
2358 | filename, textlow, ldsymoff, global_syms, static_syms) | |
2359 | char *symfile_name; | |
2360 | CORE_ADDR addr; | |
2361 | char *filename; | |
2362 | CORE_ADDR textlow; | |
2363 | int ldsymoff; | |
2364 | struct partial_symbol *global_syms; | |
2365 | struct partial_symbol *static_syms; | |
2366 | { | |
2367 | struct partial_symtab *result = | |
2368 | (struct partial_symtab *) obstack_alloc (psymbol_obstack, | |
2369 | sizeof (struct partial_symtab)); | |
2370 | ||
2371 | result->addr = addr; | |
2372 | ||
2373 | result->symfile_name = | |
2374 | (char *) obstack_alloc (psymbol_obstack, | |
2375 | strlen (symfile_name) + 1); | |
2376 | strcpy (result->symfile_name, symfile_name); | |
2377 | ||
2378 | result->filename = | |
2379 | (char *) obstack_alloc (psymbol_obstack, | |
2380 | strlen (filename) + 1); | |
2381 | strcpy (result->filename, filename); | |
2382 | ||
2383 | result->textlow = textlow; | |
2384 | result->ldsymoff = ldsymoff; | |
2385 | ||
2386 | result->readin = 0; | |
2387 | result->symtab = 0; | |
2388 | result->read_symtab = dbx_psymtab_to_symtab; | |
2389 | ||
2390 | result->globals_offset = global_syms - global_psymbols.list; | |
2391 | result->statics_offset = static_syms - static_psymbols.list; | |
2392 | ||
2393 | result->n_global_syms = 0; | |
2394 | result->n_static_syms = 0; | |
2395 | ||
2396 | ||
2397 | return result; | |
2398 | } | |
2399 | ||
2400 | static int | |
2401 | compare_psymbols (s1, s2) | |
2402 | register struct partial_symbol *s1, *s2; | |
2403 | { | |
2404 | register char | |
2405 | *st1 = SYMBOL_NAME (s1), | |
2406 | *st2 = SYMBOL_NAME (s2); | |
2407 | ||
0c4d2cc2 JG |
2408 | if (st1[0] - st2[0]) |
2409 | return st1[0] - st2[0]; | |
2410 | if (st1[1] - st2[1]) | |
2411 | return st1[1] - st2[1]; | |
2412 | return strcmp (st1 + 1, st2 + 1); | |
bd5635a1 RP |
2413 | } |
2414 | ||
2415 | ||
2416 | /* Close off the current usage of a partial_symbol table entry. This | |
2417 | involves setting the correct number of includes (with a realloc), | |
2418 | setting the high text mark, setting the symbol length in the | |
2419 | executable, and setting the length of the global and static lists | |
2420 | of psymbols. | |
2421 | ||
2422 | The global symbols and static symbols are then seperately sorted. | |
2423 | ||
2424 | Then the partial symtab is put on the global list. | |
2425 | *** List variables and peculiarities of same. *** | |
2426 | */ | |
2427 | static void | |
2428 | end_psymtab (pst, include_list, num_includes, capping_symbol_offset, | |
2429 | capping_text, dependency_list, number_dependencies, | |
2430 | capping_global, capping_static) | |
2431 | struct partial_symtab *pst; | |
2432 | char **include_list; | |
2433 | int num_includes; | |
2434 | int capping_symbol_offset; | |
2435 | CORE_ADDR capping_text; | |
2436 | struct partial_symtab **dependency_list; | |
2437 | int number_dependencies; | |
2438 | struct partial_symbol *capping_global, *capping_static; | |
2439 | { | |
2440 | int i; | |
2441 | ||
2442 | pst->ldsymlen = capping_symbol_offset - pst->ldsymoff; | |
2443 | pst->texthigh = capping_text; | |
2444 | ||
2445 | pst->n_global_syms = | |
2446 | capping_global - (global_psymbols.list + pst->globals_offset); | |
2447 | pst->n_static_syms = | |
2448 | capping_static - (static_psymbols.list + pst->statics_offset); | |
2449 | ||
2450 | pst->number_of_dependencies = number_dependencies; | |
2451 | if (number_dependencies) | |
2452 | { | |
2453 | pst->dependencies = (struct partial_symtab **) | |
2454 | obstack_alloc (psymbol_obstack, | |
2455 | number_dependencies * sizeof (struct partial_symtab *)); | |
2456 | bcopy (dependency_list, pst->dependencies, | |
2457 | number_dependencies * sizeof (struct partial_symtab *)); | |
2458 | } | |
2459 | else | |
2460 | pst->dependencies = 0; | |
2461 | ||
2462 | for (i = 0; i < num_includes; i++) | |
2463 | { | |
2464 | /* Eventually, put this on obstack */ | |
2465 | struct partial_symtab *subpst = | |
2466 | (struct partial_symtab *) | |
2467 | obstack_alloc (psymbol_obstack, | |
2468 | sizeof (struct partial_symtab)); | |
2469 | ||
2470 | subpst->filename = | |
2471 | (char *) obstack_alloc (psymbol_obstack, | |
2472 | strlen (include_list[i]) + 1); | |
2473 | strcpy (subpst->filename, include_list[i]); | |
2474 | ||
2475 | subpst->symfile_name = pst->symfile_name; | |
2476 | subpst->addr = pst->addr; | |
2477 | subpst->ldsymoff = | |
2478 | subpst->ldsymlen = | |
2479 | subpst->textlow = | |
2480 | subpst->texthigh = 0; | |
2481 | ||
3f83182d JG |
2482 | /* We could save slight bits of space by only making one of these, |
2483 | shared by the entire set of include files. FIXME-someday. */ | |
bd5635a1 RP |
2484 | subpst->dependencies = (struct partial_symtab **) |
2485 | obstack_alloc (psymbol_obstack, | |
2486 | sizeof (struct partial_symtab *)); | |
2487 | subpst->dependencies[0] = pst; | |
2488 | subpst->number_of_dependencies = 1; | |
2489 | ||
2490 | subpst->globals_offset = | |
2491 | subpst->n_global_syms = | |
2492 | subpst->statics_offset = | |
2493 | subpst->n_static_syms = 0; | |
2494 | ||
2495 | subpst->readin = 0; | |
9a822037 | 2496 | subpst->symtab = 0; |
bd5635a1 RP |
2497 | subpst->read_symtab = dbx_psymtab_to_symtab; |
2498 | ||
2499 | subpst->next = partial_symtab_list; | |
2500 | partial_symtab_list = subpst; | |
2501 | } | |
2502 | ||
2503 | /* Sort the global list; don't sort the static list */ | |
2504 | qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms, | |
2505 | sizeof (struct partial_symbol), compare_psymbols); | |
2506 | ||
f9623881 JG |
2507 | /* If there is already a psymtab or symtab for a file of this name, remove it. |
2508 | (If there is a symtab, more drastic things also happen.) | |
2509 | This happens in VxWorks. */ | |
2510 | free_named_symtabs (pst->filename); | |
2511 | ||
bd5635a1 RP |
2512 | /* Put the psymtab on the psymtab list */ |
2513 | pst->next = partial_symtab_list; | |
2514 | partial_symtab_list = pst; | |
2515 | } | |
2516 | \f | |
2517 | static void | |
2518 | psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset) | |
2519 | struct partial_symtab *pst; | |
2520 | int desc; | |
2521 | char *stringtab; | |
2522 | int stringtab_size; | |
2523 | int sym_offset; | |
2524 | { | |
2525 | struct cleanup *old_chain; | |
2526 | int i; | |
2527 | ||
2528 | if (!pst) | |
2529 | return; | |
2530 | ||
2531 | if (pst->readin) | |
2532 | { | |
2533 | fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
2534 | pst->filename); | |
2535 | return; | |
2536 | } | |
2537 | ||
2538 | /* Read in all partial symbtabs on which this one is dependent */ | |
2539 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2540 | if (!pst->dependencies[i]->readin) | |
2541 | { | |
2542 | /* Inform about additional files that need to be read in. */ | |
2543 | if (info_verbose) | |
2544 | { | |
2545 | fputs_filtered (" ", stdout); | |
2546 | wrap_here (""); | |
2547 | fputs_filtered ("and ", stdout); | |
2548 | wrap_here (""); | |
2549 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2550 | wrap_here (""); /* Flush output */ | |
2551 | fflush (stdout); | |
2552 | } | |
2553 | psymtab_to_symtab_1 (pst->dependencies[i], desc, | |
2554 | stringtab, stringtab_size, sym_offset); | |
2555 | } | |
2556 | ||
2557 | if (pst->ldsymlen) /* Otherwise it's a dummy */ | |
2558 | { | |
2559 | /* Init stuff necessary for reading in symbols */ | |
2560 | free_pendings = 0; | |
2561 | pending_blocks = 0; | |
2562 | file_symbols = 0; | |
2563 | global_symbols = 0; | |
2564 | old_chain = make_cleanup (really_free_pendings, 0); | |
2565 | ||
2566 | /* Read in this files symbols */ | |
2567 | lseek (desc, sym_offset, L_SET); | |
9404978d MT |
2568 | pst->symtab = |
2569 | read_ofile_symtab (desc, stringtab, stringtab_size, | |
2570 | pst->ldsymoff, | |
2571 | pst->ldsymlen, pst->textlow, | |
2572 | pst->texthigh - pst->textlow, pst->addr); | |
2573 | sort_symtab_syms (pst->symtab); | |
bd5635a1 RP |
2574 | |
2575 | do_cleanups (old_chain); | |
2576 | } | |
2577 | ||
2578 | pst->readin = 1; | |
2579 | } | |
2580 | ||
2581 | /* | |
2582 | * Read in all of the symbols for a given psymtab for real. | |
2583 | * Be verbose about it if the user wants that. | |
2584 | */ | |
2585 | static void | |
2586 | dbx_psymtab_to_symtab (pst) | |
2587 | struct partial_symtab *pst; | |
2588 | { | |
2589 | int desc; | |
2590 | char *stringtab; | |
2591 | int stsize, val; | |
2592 | struct stat statbuf; | |
2593 | struct cleanup *old_chain; | |
2594 | bfd *sym_bfd; | |
2595 | long st_temp; | |
2596 | ||
2597 | if (!pst) | |
2598 | return; | |
2599 | ||
2600 | if (pst->readin) | |
2601 | { | |
2602 | fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
2603 | pst->filename); | |
2604 | return; | |
2605 | } | |
2606 | ||
2607 | if (pst->ldsymlen || pst->number_of_dependencies) | |
2608 | { | |
2609 | /* Print the message now, before reading the string table, | |
2610 | to avoid disconcerting pauses. */ | |
2611 | if (info_verbose) | |
2612 | { | |
2613 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
2614 | fflush (stdout); | |
2615 | } | |
2616 | ||
2617 | /* Open symbol file and read in string table. Symbol_file_command | |
2618 | guarantees that the symbol file name will be absolute, so there is | |
2619 | no need for openp. */ | |
2620 | desc = open(pst->symfile_name, O_RDONLY, 0); | |
2621 | ||
2622 | if (desc < 0) | |
2623 | perror_with_name (pst->symfile_name); | |
2624 | ||
2625 | sym_bfd = bfd_fdopenr (pst->symfile_name, NULL, desc); | |
2626 | if (!sym_bfd) | |
2627 | { | |
2628 | (void)close (desc); | |
2629 | error ("Could not open `%s' to read symbols: %s", | |
2630 | pst->symfile_name, bfd_errmsg (bfd_error)); | |
2631 | } | |
2632 | old_chain = make_cleanup (bfd_close, sym_bfd); | |
2633 | if (!bfd_check_format (sym_bfd, bfd_object)) | |
2634 | error ("\"%s\": can't read symbols: %s.", | |
2635 | pst->symfile_name, bfd_errmsg (bfd_error)); | |
2636 | ||
2637 | /* We keep the string table for symfile resident in memory, but | |
2638 | not the string table for any other symbol files. */ | |
66eeea27 | 2639 | if ((symfile == 0) || 0 != strcmp(pst->symfile_name, symfile)) |
bd5635a1 RP |
2640 | { |
2641 | /* Read in the string table */ | |
2642 | ||
2643 | /* FIXME, this uses internal BFD variables. See above in | |
2644 | dbx_symbol_file_open where the macro is defined! */ | |
2645 | lseek (desc, STRING_TABLE_OFFSET, L_SET); | |
2646 | ||
2647 | val = myread (desc, &st_temp, sizeof st_temp); | |
2648 | if (val < 0) | |
2649 | perror_with_name (pst->symfile_name); | |
dcc35536 | 2650 | stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp); |
bd5635a1 RP |
2651 | if (fstat (desc, &statbuf) < 0) |
2652 | perror_with_name (pst->symfile_name); | |
2653 | ||
2654 | if (stsize >= 0 && stsize < statbuf.st_size) | |
2655 | { | |
2656 | #ifdef BROKEN_LARGE_ALLOCA | |
2657 | stringtab = (char *) xmalloc (stsize); | |
2658 | make_cleanup (free, stringtab); | |
2659 | #else | |
2660 | stringtab = (char *) alloca (stsize); | |
2661 | #endif | |
2662 | } | |
2663 | else | |
2664 | stringtab = NULL; | |
2665 | if (stringtab == NULL && stsize != 0) | |
2666 | error ("ridiculous string table size: %d bytes", stsize); | |
2667 | ||
2668 | /* FIXME, this uses internal BFD variables. See above in | |
2669 | dbx_symbol_file_open where the macro is defined! */ | |
2670 | val = lseek (desc, STRING_TABLE_OFFSET, L_SET); | |
2671 | if (val < 0) | |
2672 | perror_with_name (pst->symfile_name); | |
2673 | val = myread (desc, stringtab, stsize); | |
2674 | if (val < 0) | |
2675 | perror_with_name (pst->symfile_name); | |
2676 | } | |
2677 | else | |
2678 | { | |
2679 | stringtab = symfile_string_table; | |
2680 | stsize = symfile_string_table_size; | |
2681 | } | |
2682 | ||
2683 | symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */ | |
2684 | ||
2685 | /* FIXME, this uses internal BFD variables. See above in | |
2686 | dbx_symbol_file_open where the macro is defined! */ | |
2687 | psymtab_to_symtab_1 (pst, desc, stringtab, stsize, | |
2688 | SYMBOL_TABLE_OFFSET); | |
2689 | ||
2690 | /* Match with global symbols. This only needs to be done once, | |
2691 | after all of the symtabs and dependencies have been read in. */ | |
2692 | scan_file_globals (); | |
2693 | ||
2694 | do_cleanups (old_chain); | |
2695 | ||
2696 | /* Finish up the debug error message. */ | |
2697 | if (info_verbose) | |
2698 | printf_filtered ("done.\n"); | |
2699 | } | |
2700 | } | |
2701 | ||
2702 | /* | |
2703 | * Scan through all of the global symbols defined in the object file, | |
2704 | * assigning values to the debugging symbols that need to be assigned | |
2705 | * to. Get these symbols from the misc function list. | |
2706 | */ | |
2707 | static void | |
2708 | scan_file_globals () | |
2709 | { | |
2710 | int hash; | |
2711 | int mf; | |
2712 | ||
2713 | for (mf = 0; mf < misc_function_count; mf++) | |
2714 | { | |
2715 | char *namestring = misc_function_vector[mf].name; | |
2716 | struct symbol *sym, *prev; | |
2717 | ||
2718 | QUIT; | |
2719 | ||
2720 | prev = (struct symbol *) 0; | |
2721 | ||
2722 | /* Get the hash index and check all the symbols | |
2723 | under that hash index. */ | |
2724 | ||
2725 | hash = hashname (namestring); | |
2726 | ||
2727 | for (sym = global_sym_chain[hash]; sym;) | |
2728 | { | |
2729 | if (*namestring == SYMBOL_NAME (sym)[0] | |
2730 | && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1)) | |
2731 | { | |
2732 | /* Splice this symbol out of the hash chain and | |
2733 | assign the value we have to it. */ | |
2734 | if (prev) | |
2735 | SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); | |
2736 | else | |
2737 | global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); | |
2738 | ||
2739 | /* Check to see whether we need to fix up a common block. */ | |
2740 | /* Note: this code might be executed several times for | |
2741 | the same symbol if there are multiple references. */ | |
2742 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
2743 | fix_common_block (sym, misc_function_vector[mf].address); | |
2744 | else | |
2745 | SYMBOL_VALUE_ADDRESS (sym) = misc_function_vector[mf].address; | |
2746 | ||
2747 | if (prev) | |
2748 | sym = SYMBOL_VALUE_CHAIN (prev); | |
2749 | else | |
2750 | sym = global_sym_chain[hash]; | |
2751 | } | |
2752 | else | |
2753 | { | |
2754 | prev = sym; | |
2755 | sym = SYMBOL_VALUE_CHAIN (sym); | |
2756 | } | |
2757 | } | |
2758 | } | |
2759 | } | |
2760 | ||
2761 | /* Process a pair of symbols. Currently they must both be N_SO's. */ | |
0c4d2cc2 | 2762 | /* ARGSUSED */ |
bd5635a1 RP |
2763 | static void |
2764 | process_symbol_pair (type1, desc1, value1, name1, | |
2765 | type2, desc2, value2, name2) | |
2766 | int type1; | |
2767 | int desc1; | |
2768 | CORE_ADDR value1; | |
2769 | char *name1; | |
2770 | int type2; | |
2771 | int desc2; | |
2772 | CORE_ADDR value2; | |
2773 | char *name2; | |
2774 | { | |
2775 | /* No need to check PCC_SOL_BROKEN, on the assumption that such | |
2776 | broken PCC's don't put out N_SO pairs. */ | |
2777 | if (last_source_file) | |
9404978d | 2778 | (void)end_symtab (value2); |
bd5635a1 RP |
2779 | start_symtab (name2, name1, value2); |
2780 | } | |
2781 | ||
2782 | /* | |
2783 | * Read in a defined section of a specific object file's symbols. | |
2784 | * | |
2785 | * DESC is the file descriptor for the file, positioned at the | |
2786 | * beginning of the symtab | |
2787 | * STRINGTAB is a pointer to the files string | |
2788 | * table, already read in | |
2789 | * SYM_OFFSET is the offset within the file of | |
2790 | * the beginning of the symbols we want to read, NUM_SUMBOLS is the | |
2791 | * number of symbols to read | |
2792 | * TEXT_OFFSET is the beginning of the text segment we are reading symbols for | |
2793 | * TEXT_SIZE is the size of the text segment read in. | |
2794 | * OFFSET is a relocation offset which gets added to each symbol | |
2795 | */ | |
2796 | ||
9404978d | 2797 | static struct symtab * |
bd5635a1 RP |
2798 | read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset, |
2799 | sym_size, text_offset, text_size, offset) | |
2800 | int desc; | |
2801 | register char *stringtab; | |
2802 | unsigned int stringtab_size; | |
2803 | int sym_offset; | |
2804 | int sym_size; | |
2805 | CORE_ADDR text_offset; | |
2806 | int text_size; | |
2807 | int offset; | |
2808 | { | |
2809 | register char *namestring; | |
2810 | struct nlist *bufp; | |
2811 | unsigned char type; | |
2812 | subfile_stack = 0; | |
2813 | ||
2814 | stringtab_global = stringtab; | |
2815 | last_source_file = 0; | |
2816 | ||
2817 | symtab_input_desc = desc; | |
2818 | symbuf_end = symbuf_idx = 0; | |
2819 | ||
2820 | /* It is necessary to actually read one symbol *before* the start | |
2821 | of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL | |
2822 | occurs before the N_SO symbol. | |
2823 | ||
2824 | Detecting this in read_dbx_symtab | |
2825 | would slow down initial readin, so we look for it here instead. */ | |
2826 | if (sym_offset >= (int)sizeof (struct nlist)) | |
2827 | { | |
2828 | lseek (desc, sym_offset - sizeof (struct nlist), L_INCR); | |
2829 | fill_symbuf (); | |
2830 | bufp = &symbuf[symbuf_idx++]; | |
2831 | SWAP_SYMBOL (bufp); | |
2832 | ||
2833 | if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) | |
2834 | error ("Invalid symbol data: bad string table offset: %d", | |
2835 | bufp->n_un.n_strx); | |
2836 | namestring = bufp->n_un.n_strx + stringtab; | |
2837 | ||
2838 | processing_gcc_compilation = | |
2839 | (bufp->n_type == N_TEXT | |
2840 | && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL)); | |
2841 | } | |
2842 | else | |
2843 | { | |
2844 | /* The N_SO starting this symtab is the first symbol, so we | |
2845 | better not check the symbol before it. I'm not this can | |
2846 | happen, but it doesn't hurt to check for it. */ | |
2847 | lseek(desc, sym_offset, L_INCR); | |
2848 | processing_gcc_compilation = 0; | |
2849 | } | |
2850 | ||
2851 | if (symbuf_idx == symbuf_end) | |
2852 | fill_symbuf(); | |
2853 | bufp = &symbuf[symbuf_idx]; | |
2854 | if (bufp->n_type != (unsigned char)N_SO) | |
2855 | error("First symbol in segment of executable not a source symbol"); | |
2856 | ||
2857 | for (symnum = 0; | |
2858 | symnum < sym_size / sizeof(struct nlist); | |
2859 | symnum++) | |
2860 | { | |
2861 | QUIT; /* Allow this to be interruptable */ | |
2862 | if (symbuf_idx == symbuf_end) | |
2863 | fill_symbuf(); | |
2864 | bufp = &symbuf[symbuf_idx++]; | |
2865 | SWAP_SYMBOL (bufp); | |
2866 | ||
2867 | type = bufp->n_type & N_TYPE; | |
2868 | if (type == (unsigned char)N_CATCH) | |
2869 | { | |
2870 | /* N_CATCH is not fixed up by the linker, and unfortunately, | |
2871 | there's no other place to put it in the .stab map. */ | |
62c4f98b | 2872 | bufp->n_value += text_offset + offset; |
bd5635a1 RP |
2873 | } |
2874 | else if (type == N_TEXT || type == N_DATA || type == N_BSS) | |
2875 | bufp->n_value += offset; | |
2876 | ||
2877 | type = bufp->n_type; | |
2878 | if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) | |
2879 | error ("Invalid symbol data: bad string table offset: %d", | |
2880 | bufp->n_un.n_strx); | |
2881 | namestring = bufp->n_un.n_strx + stringtab; | |
2882 | ||
2883 | if (type & N_STAB) | |
2884 | { | |
e1ce8aa5 | 2885 | short bufp_n_desc = bufp->n_desc; |
bd5635a1 RP |
2886 | unsigned long valu = bufp->n_value; |
2887 | ||
2888 | /* Check for a pair of N_SO symbols. */ | |
2889 | if (type == (unsigned char)N_SO) | |
2890 | { | |
2891 | if (symbuf_idx == symbuf_end) | |
2892 | fill_symbuf (); | |
2893 | bufp = &symbuf[symbuf_idx]; | |
2894 | if (bufp->n_type == (unsigned char)N_SO) | |
2895 | { | |
2896 | char *namestring2; | |
2897 | ||
2898 | SWAP_SYMBOL (bufp); | |
2899 | bufp->n_value += offset; /* Relocate */ | |
2900 | symbuf_idx++; | |
2901 | symnum++; | |
2902 | ||
2903 | if (bufp->n_un.n_strx < 0 | |
2904 | || bufp->n_un.n_strx >= stringtab_size) | |
2905 | error ("Invalid symbol data: bad string table offset: %d", | |
2906 | bufp->n_un.n_strx); | |
2907 | namestring2 = bufp->n_un.n_strx + stringtab; | |
2908 | ||
e1ce8aa5 | 2909 | process_symbol_pair (N_SO, bufp_n_desc, valu, namestring, |
bd5635a1 RP |
2910 | N_SO, bufp->n_desc, bufp->n_value, |
2911 | namestring2); | |
2912 | } | |
2913 | else | |
e1ce8aa5 | 2914 | process_one_symbol(type, bufp_n_desc, valu, namestring); |
bd5635a1 RP |
2915 | } |
2916 | else | |
e1ce8aa5 | 2917 | process_one_symbol (type, bufp_n_desc, valu, namestring); |
bd5635a1 RP |
2918 | } |
2919 | /* We skip checking for a new .o or -l file; that should never | |
2920 | happen in this routine. */ | |
2921 | else if (type == N_TEXT | |
2922 | && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
2923 | /* I don't think this code will ever be executed, because | |
2924 | the GCC_COMPILED_FLAG_SYMBOL usually is right before | |
2925 | the N_SO symbol which starts this source file. | |
2926 | However, there is no reason not to accept | |
2927 | the GCC_COMPILED_FLAG_SYMBOL anywhere. */ | |
2928 | processing_gcc_compilation = 1; | |
2929 | else if (type & N_EXT || type == (unsigned char)N_TEXT | |
2930 | || type == (unsigned char)N_NBTEXT | |
0c4d2cc2 | 2931 | ) { |
bd5635a1 RP |
2932 | /* Global symbol: see if we came across a dbx defintion for |
2933 | a corresponding symbol. If so, store the value. Remove | |
2934 | syms from the chain when their values are stored, but | |
2935 | search the whole chain, as there may be several syms from | |
2936 | different files with the same name. */ | |
2937 | /* This is probably not true. Since the files will be read | |
2938 | in one at a time, each reference to a global symbol will | |
2939 | be satisfied in each file as it appears. So we skip this | |
2940 | section. */ | |
2941 | ; | |
0c4d2cc2 | 2942 | } |
bd5635a1 | 2943 | } |
9404978d MT |
2944 | |
2945 | return end_symtab (text_offset + text_size); | |
bd5635a1 RP |
2946 | } |
2947 | \f | |
2948 | static int | |
2949 | hashname (name) | |
2950 | char *name; | |
2951 | { | |
2952 | register char *p = name; | |
2953 | register int total = p[0]; | |
2954 | register int c; | |
2955 | ||
2956 | c = p[1]; | |
2957 | total += c << 2; | |
2958 | if (c) | |
2959 | { | |
2960 | c = p[2]; | |
2961 | total += c << 4; | |
2962 | if (c) | |
2963 | total += p[3] << 6; | |
2964 | } | |
2965 | ||
2966 | /* Ensure result is positive. */ | |
2967 | if (total < 0) total += (1000 << 6); | |
2968 | return total % HASHSIZE; | |
2969 | } | |
2970 | ||
2971 | \f | |
2972 | static void | |
2973 | process_one_symbol (type, desc, valu, name) | |
2974 | int type, desc; | |
2975 | CORE_ADDR valu; | |
2976 | char *name; | |
2977 | { | |
2978 | #ifndef SUN_FIXED_LBRAC_BUG | |
2979 | /* This records the last pc address we've seen. We depend on their being | |
2980 | an SLINE or FUN or SO before the first LBRAC, since the variable does | |
2981 | not get reset in between reads of different symbol files. */ | |
2982 | static CORE_ADDR last_pc_address; | |
2983 | #endif | |
2984 | register struct context_stack *new; | |
2985 | char *colon_pos; | |
2986 | ||
2987 | /* Something is wrong if we see real data before | |
2988 | seeing a source file name. */ | |
2989 | ||
2990 | if (last_source_file == 0 && type != (unsigned char)N_SO) | |
2991 | { | |
2992 | /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines | |
2993 | where that code is defined. */ | |
2994 | if (IGNORE_SYMBOL (type)) | |
2995 | return; | |
2996 | ||
2997 | /* FIXME, this should not be an error, since it precludes extending | |
2998 | the symbol table information in this way... */ | |
2999 | error ("Invalid symbol data: does not start by identifying a source file."); | |
3000 | } | |
3001 | ||
3002 | switch (type) | |
3003 | { | |
3004 | case N_FUN: | |
3005 | case N_FNAME: | |
3006 | /* Either of these types of symbols indicates the start of | |
3007 | a new function. We must process its "name" normally for dbx, | |
3008 | but also record the start of a new lexical context, and possibly | |
3009 | also the end of the lexical context for the previous function. */ | |
3010 | /* This is not always true. This type of symbol may indicate a | |
3011 | text segment variable. */ | |
3012 | ||
3013 | #ifndef SUN_FIXED_LBRAC_BUG | |
3014 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
3015 | #endif | |
3016 | ||
3017 | colon_pos = strchr (name, ':'); | |
3018 | if (!colon_pos++ | |
3019 | || (*colon_pos != 'f' && *colon_pos != 'F')) | |
3020 | { | |
3021 | define_symbol (valu, name, desc, type); | |
3022 | break; | |
3023 | } | |
3024 | ||
3025 | within_function = 1; | |
3026 | if (context_stack_depth > 0) | |
3027 | { | |
3028 | new = &context_stack[--context_stack_depth]; | |
3029 | /* Make a block for the local symbols within. */ | |
3030 | finish_block (new->name, &local_symbols, new->old_blocks, | |
3031 | new->start_addr, valu); | |
3032 | } | |
3033 | /* Stack must be empty now. */ | |
3034 | if (context_stack_depth != 0) | |
3035 | error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.", | |
3036 | symnum); | |
3037 | ||
3038 | new = &context_stack[context_stack_depth++]; | |
3039 | new->old_blocks = pending_blocks; | |
3040 | new->start_addr = valu; | |
3041 | new->name = define_symbol (valu, name, desc, type); | |
3042 | local_symbols = 0; | |
3043 | break; | |
3044 | ||
3045 | case N_CATCH: | |
3046 | /* Record the address at which this catch takes place. */ | |
3047 | define_symbol (valu, name, desc, type); | |
3048 | break; | |
3049 | ||
3050 | case N_EHDECL: | |
3051 | /* Don't know what to do with these yet. */ | |
3052 | error ("action uncertain for eh extensions"); | |
3053 | break; | |
3054 | ||
3055 | case N_LBRAC: | |
3056 | /* This "symbol" just indicates the start of an inner lexical | |
3057 | context within a function. */ | |
3058 | ||
3059 | #if !defined (BLOCK_ADDRESS_ABSOLUTE) | |
3060 | /* On most machines, the block addresses are relative to the | |
3061 | N_SO, the linker did not relocate them (sigh). */ | |
3062 | valu += last_source_start_addr; | |
3063 | #endif | |
3064 | ||
3065 | #ifndef SUN_FIXED_LBRAC_BUG | |
3066 | if (valu < last_pc_address) { | |
3067 | /* Patch current LBRAC pc value to match last handy pc value */ | |
3068 | complain (&lbrac_complaint, 0); | |
3069 | valu = last_pc_address; | |
3070 | } | |
3071 | #endif | |
3072 | if (context_stack_depth == context_stack_size) | |
3073 | { | |
3074 | context_stack_size *= 2; | |
3075 | context_stack = (struct context_stack *) | |
3076 | xrealloc (context_stack, | |
3077 | (context_stack_size | |
3078 | * sizeof (struct context_stack))); | |
3079 | } | |
3080 | ||
3081 | new = &context_stack[context_stack_depth++]; | |
3082 | new->depth = desc; | |
3083 | new->locals = local_symbols; | |
3084 | new->old_blocks = pending_blocks; | |
3085 | new->start_addr = valu; | |
3086 | new->name = 0; | |
3087 | local_symbols = 0; | |
3088 | break; | |
3089 | ||
3090 | case N_RBRAC: | |
3091 | /* This "symbol" just indicates the end of an inner lexical | |
3092 | context that was started with N_LBRAC. */ | |
3093 | ||
3094 | #if !defined (BLOCK_ADDRESS_ABSOLUTE) | |
3095 | /* On most machines, the block addresses are relative to the | |
3096 | N_SO, the linker did not relocate them (sigh). */ | |
3097 | valu += last_source_start_addr; | |
3098 | #endif | |
3099 | ||
3100 | new = &context_stack[--context_stack_depth]; | |
3101 | if (desc != new->depth) | |
3102 | error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum); | |
3103 | ||
3104 | /* Some compilers put the variable decls inside of an | |
3105 | LBRAC/RBRAC block. This macro should be nonzero if this | |
3106 | is true. DESC is N_DESC from the N_RBRAC symbol. | |
3107 | GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */ | |
3108 | #if !defined (VARIABLES_INSIDE_BLOCK) | |
3109 | #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0 | |
3110 | #endif | |
3111 | ||
3112 | /* Can only use new->locals as local symbols here if we're in | |
3113 | gcc or on a machine that puts them before the lbrack. */ | |
3114 | if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
3115 | local_symbols = new->locals; | |
3116 | ||
3117 | /* If this is not the outermost LBRAC...RBRAC pair in the | |
3118 | function, its local symbols preceded it, and are the ones | |
3119 | just recovered from the context stack. Defined the block for them. | |
3120 | ||
3121 | If this is the outermost LBRAC...RBRAC pair, there is no | |
3122 | need to do anything; leave the symbols that preceded it | |
3123 | to be attached to the function's own block. However, if | |
3124 | it is so, we need to indicate that we just moved outside | |
3125 | of the function. */ | |
3126 | if (local_symbols | |
3127 | && (context_stack_depth | |
3128 | > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))) | |
3129 | { | |
3130 | /* FIXME Muzzle a compiler bug that makes end < start. */ | |
3131 | if (new->start_addr > valu) | |
3132 | { | |
3133 | complain(&lbrac_rbrac_complaint, 0); | |
3134 | new->start_addr = valu; | |
3135 | } | |
3136 | /* Make a block for the local symbols within. */ | |
3137 | finish_block (0, &local_symbols, new->old_blocks, | |
3138 | new->start_addr, valu); | |
3139 | } | |
3140 | else | |
3141 | { | |
3142 | within_function = 0; | |
3143 | } | |
3144 | if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
3145 | /* Now pop locals of block just finished. */ | |
3146 | local_symbols = new->locals; | |
3147 | break; | |
3148 | ||
9bb30452 JG |
3149 | case N_FN: |
3150 | /* This kind of symbol indicates the start of an object file. */ | |
bd5635a1 RP |
3151 | break; |
3152 | ||
3153 | case N_SO: | |
3154 | /* This type of symbol indicates the start of data | |
3155 | for one source file. | |
3156 | Finish the symbol table of the previous source file | |
3157 | (if any) and start accumulating a new symbol table. */ | |
3158 | #ifndef SUN_FIXED_LBRAC_BUG | |
3159 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
3160 | #endif | |
3161 | ||
3162 | #ifdef PCC_SOL_BROKEN | |
3163 | /* pcc bug, occasionally puts out SO for SOL. */ | |
3164 | if (context_stack_depth > 0) | |
3165 | { | |
3166 | start_subfile (name, NULL); | |
3167 | break; | |
3168 | } | |
3169 | #endif | |
3170 | if (last_source_file) | |
9404978d | 3171 | (void)end_symtab (valu); |
bd5635a1 RP |
3172 | start_symtab (name, NULL, valu); |
3173 | break; | |
3174 | ||
3175 | case N_SOL: | |
3176 | /* This type of symbol indicates the start of data for | |
3177 | a sub-source-file, one whose contents were copied or | |
3178 | included in the compilation of the main source file | |
3179 | (whose name was given in the N_SO symbol.) */ | |
3180 | start_subfile (name, NULL); | |
3181 | break; | |
3182 | ||
3183 | case N_BINCL: | |
3184 | push_subfile (); | |
3185 | add_new_header_file (name, valu); | |
3186 | start_subfile (name, NULL); | |
3187 | break; | |
3188 | ||
3189 | case N_EINCL: | |
3190 | start_subfile (pop_subfile (), NULL); | |
3191 | break; | |
3192 | ||
3193 | case N_EXCL: | |
3194 | add_old_header_file (name, valu); | |
3195 | break; | |
3196 | ||
3197 | case N_SLINE: | |
3198 | /* This type of "symbol" really just records | |
3199 | one line-number -- core-address correspondence. | |
3200 | Enter it in the line list for this symbol table. */ | |
3201 | #ifndef SUN_FIXED_LBRAC_BUG | |
3202 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
3203 | #endif | |
3204 | record_line (desc, valu); | |
3205 | break; | |
3206 | ||
3207 | case N_BCOMM: | |
3208 | if (common_block) | |
3209 | error ("Invalid symbol data: common within common at symtab pos %d", | |
3210 | symnum); | |
3211 | common_block = local_symbols; | |
3212 | common_block_i = local_symbols ? local_symbols->nsyms : 0; | |
3213 | break; | |
3214 | ||
3215 | case N_ECOMM: | |
3216 | /* Symbols declared since the BCOMM are to have the common block | |
3217 | start address added in when we know it. common_block points to | |
3218 | the first symbol after the BCOMM in the local_symbols list; | |
3219 | copy the list and hang it off the symbol for the common block name | |
3220 | for later fixup. */ | |
3221 | { | |
3222 | int i; | |
3223 | struct symbol *sym = | |
3224 | (struct symbol *) xmalloc (sizeof (struct symbol)); | |
3225 | bzero (sym, sizeof *sym); | |
3226 | SYMBOL_NAME (sym) = savestring (name, strlen (name)); | |
3227 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
3228 | SYMBOL_NAMESPACE (sym) = (enum namespace)((long) | |
3229 | copy_pending (local_symbols, common_block_i, common_block)); | |
3230 | i = hashname (SYMBOL_NAME (sym)); | |
3231 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; | |
3232 | global_sym_chain[i] = sym; | |
3233 | common_block = 0; | |
3234 | break; | |
3235 | } | |
3236 | ||
3237 | case N_ECOML: | |
3238 | case N_LENG: | |
0c4d2cc2 | 3239 | case N_DEFD: /* GNU Modula-2 symbol */ |
bd5635a1 RP |
3240 | break; |
3241 | ||
3242 | default: | |
3243 | if (name) | |
3244 | define_symbol (valu, name, desc, type); | |
3245 | } | |
3246 | } | |
3247 | \f | |
3248 | /* Read a number by which a type is referred to in dbx data, | |
3249 | or perhaps read a pair (FILENUM, TYPENUM) in parentheses. | |
3250 | Just a single number N is equivalent to (0,N). | |
3251 | Return the two numbers by storing them in the vector TYPENUMS. | |
3252 | TYPENUMS will then be used as an argument to dbx_lookup_type. */ | |
3253 | ||
3254 | static void | |
3255 | read_type_number (pp, typenums) | |
3256 | register char **pp; | |
3257 | register int *typenums; | |
3258 | { | |
3259 | if (**pp == '(') | |
3260 | { | |
3261 | (*pp)++; | |
3262 | typenums[0] = read_number (pp, ','); | |
3263 | typenums[1] = read_number (pp, ')'); | |
3264 | } | |
3265 | else | |
3266 | { | |
3267 | typenums[0] = 0; | |
3268 | typenums[1] = read_number (pp, 0); | |
3269 | } | |
3270 | } | |
3271 | \f | |
3272 | /* To handle GNU C++ typename abbreviation, we need to be able to | |
3273 | fill in a type's name as soon as space for that type is allocated. | |
3274 | `type_synonym_name' is the name of the type being allocated. | |
3275 | It is cleared as soon as it is used (lest all allocated types | |
3276 | get this name). */ | |
3277 | static char *type_synonym_name; | |
3278 | ||
0c4d2cc2 | 3279 | /* ARGSUSED */ |
bd5635a1 RP |
3280 | static struct symbol * |
3281 | define_symbol (valu, string, desc, type) | |
3282 | unsigned int valu; | |
3283 | char *string; | |
3284 | int desc; | |
3285 | int type; | |
3286 | { | |
3287 | register struct symbol *sym; | |
3288 | char *p = (char *) strchr (string, ':'); | |
3289 | int deftype; | |
3290 | int synonym = 0; | |
3291 | register int i; | |
3292 | ||
3293 | /* Ignore syms with empty names. */ | |
3294 | if (string[0] == 0) | |
3295 | return 0; | |
3296 | ||
3297 | /* Ignore old-style symbols from cc -go */ | |
3298 | if (p == 0) | |
3299 | return 0; | |
3300 | ||
3301 | sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol)); | |
3302 | ||
3303 | if (processing_gcc_compilation) { | |
3304 | /* GCC 2.x puts the line number in desc. SunOS apparently puts in the | |
3305 | number of bytes occupied by a type or object, which we ignore. */ | |
3306 | SYMBOL_LINE(sym) = desc; | |
3307 | } else { | |
3308 | SYMBOL_LINE(sym) = 0; /* unknown */ | |
3309 | } | |
aec4cb91 | 3310 | |
bd5635a1 RP |
3311 | if (string[0] == CPLUS_MARKER) |
3312 | { | |
3313 | /* Special GNU C++ names. */ | |
3314 | switch (string[1]) | |
3315 | { | |
3316 | case 't': | |
3317 | SYMBOL_NAME (sym) = "this"; | |
3318 | break; | |
3319 | case 'v': /* $vtbl_ptr_type */ | |
3320 | /* Was: SYMBOL_NAME (sym) = "vptr"; */ | |
3321 | goto normal; | |
3322 | case 'e': | |
3323 | SYMBOL_NAME (sym) = "eh_throw"; | |
3324 | break; | |
3325 | ||
3326 | case '_': | |
3327 | /* This was an anonymous type that was never fixed up. */ | |
3328 | goto normal; | |
3329 | ||
3330 | default: | |
3331 | abort (); | |
3332 | } | |
3333 | } | |
3334 | else | |
3335 | { | |
3336 | normal: | |
3337 | SYMBOL_NAME (sym) | |
3338 | = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1)); | |
3339 | /* Open-coded bcopy--saves function call time. */ | |
3340 | { | |
3341 | register char *p1 = string; | |
3342 | register char *p2 = SYMBOL_NAME (sym); | |
3343 | while (p1 != p) | |
3344 | *p2++ = *p1++; | |
3345 | *p2++ = '\0'; | |
3346 | } | |
3347 | } | |
3348 | p++; | |
3349 | /* Determine the type of name being defined. */ | |
3350 | /* The Acorn RISC machine's compiler can put out locals that don't | |
3351 | start with "234=" or "(3,4)=", so assume anything other than the | |
3352 | deftypes we know how to handle is a local. */ | |
3353 | /* (Peter Watkins @ Computervision) | |
3354 | Handle Sun-style local fortran array types 'ar...' . | |
3355 | (gnu@cygnus.com) -- this strchr() handles them properly? | |
3356 | (tiemann@cygnus.com) -- 'C' is for catch. */ | |
3357 | if (!strchr ("cfFGpPrStTvVXC", *p)) | |
3358 | deftype = 'l'; | |
3359 | else | |
3360 | deftype = *p++; | |
3361 | ||
3362 | /* c is a special case, not followed by a type-number. | |
3363 | SYMBOL:c=iVALUE for an integer constant symbol. | |
3364 | SYMBOL:c=rVALUE for a floating constant symbol. | |
3365 | SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. | |
3366 | e.g. "b:c=e6,0" for "const b = blob1" | |
3367 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
3368 | if (deftype == 'c') | |
3369 | { | |
3370 | if (*p++ != '=') | |
3371 | error ("Invalid symbol data at symtab pos %d.", symnum); | |
3372 | switch (*p++) | |
3373 | { | |
3374 | case 'r': | |
3375 | { | |
3376 | double d = atof (p); | |
e1ce8aa5 | 3377 | char *dbl_valu; |
bd5635a1 RP |
3378 | |
3379 | SYMBOL_TYPE (sym) = builtin_type_double; | |
e1ce8aa5 JK |
3380 | dbl_valu = |
3381 | (char *) obstack_alloc (symbol_obstack, sizeof (double)); | |
3382 | bcopy (&d, dbl_valu, sizeof (double)); | |
3383 | SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double)); | |
3384 | SYMBOL_VALUE_BYTES (sym) = dbl_valu; | |
bd5635a1 RP |
3385 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
3386 | } | |
3387 | break; | |
3388 | case 'i': | |
3389 | { | |
3390 | SYMBOL_TYPE (sym) = builtin_type_int; | |
3391 | SYMBOL_VALUE (sym) = atoi (p); | |
3392 | SYMBOL_CLASS (sym) = LOC_CONST; | |
3393 | } | |
3394 | break; | |
3395 | case 'e': | |
3396 | /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. | |
3397 | e.g. "b:c=e6,0" for "const b = blob1" | |
3398 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
3399 | { | |
3400 | int typenums[2]; | |
3401 | ||
3402 | read_type_number (&p, typenums); | |
3403 | if (*p++ != ',') | |
3404 | error ("Invalid symbol data: no comma in enum const symbol"); | |
3405 | ||
3406 | SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums); | |
3407 | SYMBOL_VALUE (sym) = atoi (p); | |
3408 | SYMBOL_CLASS (sym) = LOC_CONST; | |
3409 | } | |
3410 | break; | |
3411 | default: | |
3412 | error ("Invalid symbol data at symtab pos %d.", symnum); | |
3413 | } | |
3414 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3415 | add_symbol_to_list (sym, &file_symbols); | |
3416 | return sym; | |
3417 | } | |
3418 | ||
3419 | /* Now usually comes a number that says which data type, | |
3420 | and possibly more stuff to define the type | |
3421 | (all of which is handled by read_type) */ | |
3422 | ||
3423 | if (deftype == 'p' && *p == 'F') | |
3424 | /* pF is a two-letter code that means a function parameter in Fortran. | |
3425 | The type-number specifies the type of the return value. | |
3426 | Translate it into a pointer-to-function type. */ | |
3427 | { | |
3428 | p++; | |
3429 | SYMBOL_TYPE (sym) | |
3430 | = lookup_pointer_type (lookup_function_type (read_type (&p))); | |
3431 | } | |
3432 | else | |
3433 | { | |
e1ce8aa5 | 3434 | struct type *type_read; |
bd5635a1 RP |
3435 | synonym = *p == 't'; |
3436 | ||
3437 | if (synonym) | |
3438 | { | |
3439 | p += 1; | |
3440 | type_synonym_name = obsavestring (SYMBOL_NAME (sym), | |
3441 | strlen (SYMBOL_NAME (sym))); | |
3442 | } | |
3443 | ||
e1ce8aa5 | 3444 | type_read = read_type (&p); |
bd5635a1 RP |
3445 | |
3446 | if ((deftype == 'F' || deftype == 'f') | |
e1ce8aa5 | 3447 | && TYPE_CODE (type_read) != TYPE_CODE_FUNC) |
0c4d2cc2 JG |
3448 | { |
3449 | #if 0 | |
3450 | /* This code doesn't work -- it needs to realloc and can't. */ | |
3451 | struct type *new = (struct type *) | |
3452 | obstack_alloc (symbol_obstack, sizeof (struct type)); | |
3453 | ||
3454 | /* Generate a template for the type of this function. The | |
3455 | types of the arguments will be added as we read the symbol | |
3456 | table. */ | |
3457 | *new = *lookup_function_type (type_read); | |
3458 | SYMBOL_TYPE(sym) = new; | |
3459 | in_function_type = new; | |
3460 | #else | |
e1ce8aa5 | 3461 | SYMBOL_TYPE (sym) = lookup_function_type (type_read); |
0c4d2cc2 JG |
3462 | #endif |
3463 | } | |
bd5635a1 | 3464 | else |
e1ce8aa5 | 3465 | SYMBOL_TYPE (sym) = type_read; |
bd5635a1 RP |
3466 | } |
3467 | ||
3468 | switch (deftype) | |
3469 | { | |
3470 | case 'C': | |
3471 | /* The name of a caught exception. */ | |
3472 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
3473 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3474 | SYMBOL_VALUE_ADDRESS (sym) = valu; | |
3475 | add_symbol_to_list (sym, &local_symbols); | |
3476 | break; | |
3477 | ||
3478 | case 'f': | |
3479 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
3480 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3481 | add_symbol_to_list (sym, &file_symbols); | |
3482 | break; | |
3483 | ||
3484 | case 'F': | |
3485 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
3486 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3487 | add_symbol_to_list (sym, &global_symbols); | |
3488 | break; | |
3489 | ||
3490 | case 'G': | |
3491 | /* For a class G (global) symbol, it appears that the | |
3492 | value is not correct. It is necessary to search for the | |
3493 | corresponding linker definition to find the value. | |
3494 | These definitions appear at the end of the namelist. */ | |
3495 | i = hashname (SYMBOL_NAME (sym)); | |
3496 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; | |
3497 | global_sym_chain[i] = sym; | |
3498 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
3499 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3500 | add_symbol_to_list (sym, &global_symbols); | |
3501 | break; | |
3502 | ||
3503 | /* This case is faked by a conditional above, | |
3504 | when there is no code letter in the dbx data. | |
3505 | Dbx data never actually contains 'l'. */ | |
3506 | case 'l': | |
3507 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
3508 | SYMBOL_VALUE (sym) = valu; | |
3509 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3510 | add_symbol_to_list (sym, &local_symbols); | |
3511 | break; | |
3512 | ||
3513 | case 'p': | |
3514 | /* Normally this is a parameter, a LOC_ARG. On the i960, it | |
3515 | can also be a LOC_LOCAL_ARG depending on symbol type. */ | |
3516 | #ifndef DBX_PARM_SYMBOL_CLASS | |
3517 | #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG | |
3518 | #endif | |
3519 | SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type); | |
3520 | SYMBOL_VALUE (sym) = valu; | |
3521 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
0c4d2cc2 JG |
3522 | #if 0 |
3523 | /* This doesn't work yet. */ | |
3524 | add_param_to_type (&in_function_type, sym); | |
3525 | #endif | |
bd5635a1 RP |
3526 | add_symbol_to_list (sym, &local_symbols); |
3527 | ||
3528 | /* If it's gcc-compiled, if it says `short', believe it. */ | |
3529 | if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION) | |
3530 | break; | |
3531 | ||
3532 | #if defined(BELIEVE_PCC_PROMOTION_TYPE) | |
3533 | /* This macro is defined on machines (e.g. sparc) where | |
3534 | we should believe the type of a PCC 'short' argument, | |
3535 | but shouldn't believe the address (the address is | |
3536 | the address of the corresponding int). Note that | |
3537 | this is only different from the BELIEVE_PCC_PROMOTION | |
3538 | case on big-endian machines. | |
3539 | ||
3540 | My guess is that this correction, as opposed to changing | |
3541 | the parameter to an 'int' (as done below, for PCC | |
3542 | on most machines), is the right thing to do | |
3543 | on all machines, but I don't want to risk breaking | |
3544 | something that already works. On most PCC machines, | |
3545 | the sparc problem doesn't come up because the calling | |
3546 | function has to zero the top bytes (not knowing whether | |
3547 | the called function wants an int or a short), so there | |
3548 | is no practical difference between an int and a short | |
3549 | (except perhaps what happens when the GDB user types | |
3550 | "print short_arg = 0x10000;"). | |
3551 | ||
3552 | Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler | |
3553 | actually produces the correct address (we don't need to fix it | |
3554 | up). I made this code adapt so that it will offset the symbol | |
3555 | if it was pointing at an int-aligned location and not | |
3556 | otherwise. This way you can use the same gdb for 4.0.x and | |
3557 | 4.1 systems. */ | |
3558 | ||
3559 | if (0 == SYMBOL_VALUE (sym) % sizeof (int)) | |
3560 | { | |
3561 | if (SYMBOL_TYPE (sym) == builtin_type_char | |
3562 | || SYMBOL_TYPE (sym) == builtin_type_unsigned_char) | |
3563 | SYMBOL_VALUE (sym) += 3; | |
3564 | else if (SYMBOL_TYPE (sym) == builtin_type_short | |
3565 | || SYMBOL_TYPE (sym) == builtin_type_unsigned_short) | |
3566 | SYMBOL_VALUE (sym) += 2; | |
3567 | } | |
3568 | break; | |
3569 | ||
3570 | #else /* no BELIEVE_PCC_PROMOTION_TYPE. */ | |
3571 | ||
3572 | /* If PCC says a parameter is a short or a char, | |
3573 | it is really an int. */ | |
3574 | if (SYMBOL_TYPE (sym) == builtin_type_char | |
3575 | || SYMBOL_TYPE (sym) == builtin_type_short) | |
3576 | SYMBOL_TYPE (sym) = builtin_type_int; | |
3577 | else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char | |
3578 | || SYMBOL_TYPE (sym) == builtin_type_unsigned_short) | |
3579 | SYMBOL_TYPE (sym) = builtin_type_unsigned_int; | |
3580 | break; | |
3581 | ||
3582 | #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */ | |
3583 | ||
3584 | case 'P': | |
3585 | SYMBOL_CLASS (sym) = LOC_REGPARM; | |
3586 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); | |
3587 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3588 | add_symbol_to_list (sym, &local_symbols); | |
3589 | break; | |
3590 | ||
3591 | case 'r': | |
3592 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
3593 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); | |
3594 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3595 | add_symbol_to_list (sym, &local_symbols); | |
3596 | break; | |
3597 | ||
3598 | case 'S': | |
3599 | /* Static symbol at top level of file */ | |
3600 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
3601 | SYMBOL_VALUE_ADDRESS (sym) = valu; | |
3602 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3603 | add_symbol_to_list (sym, &file_symbols); | |
3604 | break; | |
3605 | ||
3606 | case 't': | |
3607 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
3608 | SYMBOL_VALUE (sym) = valu; | |
3609 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3610 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0 | |
3611 | && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0) | |
3612 | TYPE_NAME (SYMBOL_TYPE (sym)) = | |
3613 | obsavestring (SYMBOL_NAME (sym), | |
3614 | strlen (SYMBOL_NAME (sym))); | |
3615 | /* C++ vagaries: we may have a type which is derived from | |
3616 | a base type which did not have its name defined when the | |
3617 | derived class was output. We fill in the derived class's | |
3618 | base part member's name here in that case. */ | |
3619 | else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT | |
3620 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) | |
3621 | && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) | |
3622 | { | |
0c4d2cc2 JG |
3623 | int j; |
3624 | for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--) | |
3625 | if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0) | |
3626 | TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) = | |
3627 | type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)); | |
bd5635a1 RP |
3628 | } |
3629 | ||
3630 | add_symbol_to_list (sym, &file_symbols); | |
3631 | break; | |
3632 | ||
3633 | case 'T': | |
3634 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
3635 | SYMBOL_VALUE (sym) = valu; | |
3636 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
3637 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0 | |
3638 | && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0) | |
3639 | TYPE_NAME (SYMBOL_TYPE (sym)) | |
3640 | = obconcat ("", | |
3641 | (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM | |
3642 | ? "enum " | |
3643 | : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT | |
3644 | ? "struct " : "union ")), | |
3645 | SYMBOL_NAME (sym)); | |
3646 | add_symbol_to_list (sym, &file_symbols); | |
3647 | ||
3648 | if (synonym) | |
3649 | { | |
3650 | register struct symbol *typedef_sym | |
3651 | = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol)); | |
3652 | SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym); | |
3653 | SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym); | |
3654 | ||
3655 | SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; | |
3656 | SYMBOL_VALUE (typedef_sym) = valu; | |
3657 | SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; | |
3658 | add_symbol_to_list (typedef_sym, &file_symbols); | |
3659 | } | |
3660 | break; | |
3661 | ||
3662 | case 'V': | |
3663 | /* Static symbol of local scope */ | |
3664 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
3665 | SYMBOL_VALUE_ADDRESS (sym) = valu; | |
3666 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3667 | add_symbol_to_list (sym, &local_symbols); | |
3668 | break; | |
3669 | ||
3670 | case 'v': | |
3671 | /* Reference parameter */ | |
3672 | SYMBOL_CLASS (sym) = LOC_REF_ARG; | |
3673 | SYMBOL_VALUE (sym) = valu; | |
3674 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3675 | add_symbol_to_list (sym, &local_symbols); | |
3676 | break; | |
3677 | ||
3678 | case 'X': | |
3679 | /* This is used by Sun FORTRAN for "function result value". | |
3680 | Sun claims ("dbx and dbxtool interfaces", 2nd ed) | |
3681 | that Pascal uses it too, but when I tried it Pascal used | |
3682 | "x:3" (local symbol) instead. */ | |
3683 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
3684 | SYMBOL_VALUE (sym) = valu; | |
3685 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3686 | add_symbol_to_list (sym, &local_symbols); | |
3687 | break; | |
3688 | ||
3689 | default: | |
3690 | error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum); | |
3691 | } | |
3692 | return sym; | |
3693 | } | |
3694 | \f | |
3695 | /* What about types defined as forward references inside of a small lexical | |
3696 | scope? */ | |
3697 | /* Add a type to the list of undefined types to be checked through | |
3698 | once this file has been read in. */ | |
3699 | static void | |
3700 | add_undefined_type (type) | |
3701 | struct type *type; | |
3702 | { | |
3703 | if (undef_types_length == undef_types_allocated) | |
3704 | { | |
3705 | undef_types_allocated *= 2; | |
3706 | undef_types = (struct type **) | |
3707 | xrealloc (undef_types, | |
3708 | undef_types_allocated * sizeof (struct type *)); | |
3709 | } | |
3710 | undef_types[undef_types_length++] = type; | |
3711 | } | |
3712 | ||
3713 | /* Add here something to go through each undefined type, see if it's | |
3714 | still undefined, and do a full lookup if so. */ | |
3715 | static void | |
3716 | cleanup_undefined_types () | |
3717 | { | |
3718 | struct type **type; | |
3719 | ||
3720 | for (type = undef_types; type < undef_types + undef_types_length; type++) | |
3721 | { | |
3722 | /* Reasonable test to see if it's been defined since. */ | |
3723 | if (TYPE_NFIELDS (*type) == 0) | |
3724 | { | |
3725 | struct pending *ppt; | |
3726 | int i; | |
3727 | /* Name of the type, without "struct" or "union" */ | |
3728 | char *typename = TYPE_NAME (*type); | |
3729 | ||
3730 | if (!strncmp (typename, "struct ", 7)) | |
3731 | typename += 7; | |
3732 | if (!strncmp (typename, "union ", 6)) | |
3733 | typename += 6; | |
3734 | ||
3735 | for (ppt = file_symbols; ppt; ppt = ppt->next) | |
3736 | for (i = 0; i < ppt->nsyms; i++) | |
3737 | { | |
3738 | struct symbol *sym = ppt->symbol[i]; | |
3739 | ||
3740 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
3741 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE | |
3742 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == | |
3743 | TYPE_CODE (*type)) | |
3744 | && !strcmp (SYMBOL_NAME (sym), typename)) | |
3745 | bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type)); | |
3746 | } | |
3747 | } | |
3748 | else | |
3749 | /* It has been defined; don't mark it as a stub. */ | |
3750 | TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB; | |
3751 | } | |
3752 | undef_types_length = 0; | |
3753 | } | |
3754 | ||
3755 | /* Skip rest of this symbol and return an error type. | |
3756 | ||
3757 | General notes on error recovery: error_type always skips to the | |
3758 | end of the symbol (modulo cretinous dbx symbol name continuation). | |
3759 | Thus code like this: | |
3760 | ||
3761 | if (*(*pp)++ != ';') | |
3762 | return error_type (pp); | |
3763 | ||
3764 | is wrong because if *pp starts out pointing at '\0' (typically as the | |
3765 | result of an earlier error), it will be incremented to point to the | |
3766 | start of the next symbol, which might produce strange results, at least | |
3767 | if you run off the end of the string table. Instead use | |
3768 | ||
3769 | if (**pp != ';') | |
3770 | return error_type (pp); | |
3771 | ++*pp; | |
3772 | ||
3773 | or | |
3774 | ||
3775 | if (**pp != ';') | |
3776 | foo = error_type (pp); | |
3777 | else | |
3778 | ++*pp; | |
3779 | ||
3780 | And in case it isn't obvious, the point of all this hair is so the compiler | |
3781 | can define new types and new syntaxes, and old versions of the | |
3782 | debugger will be able to read the new symbol tables. */ | |
3783 | ||
3784 | static struct type * | |
3785 | error_type (pp) | |
3786 | char **pp; | |
3787 | { | |
3788 | complain (&error_type_complaint, 0); | |
3789 | while (1) | |
3790 | { | |
3791 | /* Skip to end of symbol. */ | |
3792 | while (**pp != '\0') | |
3793 | (*pp)++; | |
3794 | ||
3795 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
3796 | if ((*pp)[-1] == '\\') | |
3797 | *pp = next_symbol_text (); | |
3798 | else | |
3799 | break; | |
3800 | } | |
3801 | return builtin_type_error; | |
3802 | } | |
3803 | \f | |
3804 | /* Read a dbx type reference or definition; | |
3805 | return the type that is meant. | |
3806 | This can be just a number, in which case it references | |
3807 | a type already defined and placed in type_vector. | |
3808 | Or the number can be followed by an =, in which case | |
3809 | it means to define a new type according to the text that | |
3810 | follows the =. */ | |
3811 | ||
3812 | static | |
3813 | struct type * | |
3814 | read_type (pp) | |
3815 | register char **pp; | |
3816 | { | |
3817 | register struct type *type = 0; | |
3818 | struct type *type1; | |
3819 | int typenums[2]; | |
3820 | int xtypenums[2]; | |
3821 | ||
3822 | /* Read type number if present. The type number may be omitted. | |
3823 | for instance in a two-dimensional array declared with type | |
3824 | "ar1;1;10;ar1;1;10;4". */ | |
3825 | if ((**pp >= '0' && **pp <= '9') | |
3826 | || **pp == '(') | |
3827 | { | |
3828 | read_type_number (pp, typenums); | |
3829 | ||
3830 | /* Detect random reference to type not yet defined. | |
3831 | Allocate a type object but leave it zeroed. */ | |
3832 | if (**pp != '=') | |
3833 | return dbx_alloc_type (typenums); | |
3834 | ||
3835 | *pp += 2; | |
3836 | } | |
3837 | else | |
3838 | { | |
3839 | /* 'typenums=' not present, type is anonymous. Read and return | |
3840 | the definition, but don't put it in the type vector. */ | |
3841 | typenums[0] = typenums[1] = -1; | |
3842 | *pp += 1; | |
3843 | } | |
3844 | ||
3845 | switch ((*pp)[-1]) | |
3846 | { | |
3847 | case 'x': | |
3848 | { | |
3849 | enum type_code code; | |
3850 | ||
3851 | /* Used to index through file_symbols. */ | |
3852 | struct pending *ppt; | |
3853 | int i; | |
3854 | ||
3855 | /* Name including "struct", etc. */ | |
3856 | char *type_name; | |
3857 | ||
3858 | /* Name without "struct", etc. */ | |
3859 | char *type_name_only; | |
3860 | ||
3861 | { | |
3862 | char *prefix; | |
3863 | char *from, *to; | |
3864 | ||
3865 | /* Set the type code according to the following letter. */ | |
3866 | switch ((*pp)[0]) | |
3867 | { | |
3868 | case 's': | |
3869 | code = TYPE_CODE_STRUCT; | |
3870 | prefix = "struct "; | |
3871 | break; | |
3872 | case 'u': | |
3873 | code = TYPE_CODE_UNION; | |
3874 | prefix = "union "; | |
3875 | break; | |
3876 | case 'e': | |
3877 | code = TYPE_CODE_ENUM; | |
3878 | prefix = "enum "; | |
3879 | break; | |
3880 | default: | |
3881 | return error_type (pp); | |
3882 | } | |
3883 | ||
3884 | to = type_name = (char *) | |
3885 | obstack_alloc (symbol_obstack, | |
3886 | (strlen (prefix) + | |
3887 | ((char *) strchr (*pp, ':') - (*pp)) + 1)); | |
3888 | ||
3889 | /* Copy the prefix. */ | |
3890 | from = prefix; | |
3891 | while (*to++ = *from++) | |
3892 | ; | |
3893 | to--; | |
3894 | ||
3895 | type_name_only = to; | |
3896 | ||
3897 | /* Copy the name. */ | |
3898 | from = *pp + 1; | |
3899 | while ((*to++ = *from++) != ':') | |
3900 | ; | |
3901 | *--to = '\0'; | |
3902 | ||
3903 | /* Set the pointer ahead of the name which we just read. */ | |
3904 | *pp = from; | |
3905 | ||
3906 | #if 0 | |
3907 | /* The following hack is clearly wrong, because it doesn't | |
3908 | check whether we are in a baseclass. I tried to reproduce | |
3909 | the case that it is trying to fix, but I couldn't get | |
3910 | g++ to put out a cross reference to a basetype. Perhaps | |
3911 | it doesn't do it anymore. */ | |
3912 | /* Note: for C++, the cross reference may be to a base type which | |
3913 | has not yet been seen. In this case, we skip to the comma, | |
3914 | which will mark the end of the base class name. (The ':' | |
3915 | at the end of the base class name will be skipped as well.) | |
3916 | But sometimes (ie. when the cross ref is the last thing on | |
3917 | the line) there will be no ','. */ | |
3918 | from = (char *) strchr (*pp, ','); | |
3919 | if (from) | |
3920 | *pp = from; | |
3921 | #endif /* 0 */ | |
3922 | } | |
3923 | ||
3924 | /* Now check to see whether the type has already been declared. */ | |
3925 | /* This is necessary at least in the case where the | |
3926 | program says something like | |
3927 | struct foo bar[5]; | |
3928 | The compiler puts out a cross-reference; we better find | |
3929 | set the length of the structure correctly so we can | |
3930 | set the length of the array. */ | |
3931 | for (ppt = file_symbols; ppt; ppt = ppt->next) | |
3932 | for (i = 0; i < ppt->nsyms; i++) | |
3933 | { | |
3934 | struct symbol *sym = ppt->symbol[i]; | |
3935 | ||
3936 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
3937 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE | |
3938 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == code) | |
3939 | && !strcmp (SYMBOL_NAME (sym), type_name_only)) | |
3940 | { | |
3941 | obstack_free (symbol_obstack, type_name); | |
3942 | type = SYMBOL_TYPE (sym); | |
3943 | return type; | |
3944 | } | |
3945 | } | |
3946 | ||
3947 | /* Didn't find the type to which this refers, so we must | |
3948 | be dealing with a forward reference. Allocate a type | |
3949 | structure for it, and keep track of it so we can | |
3950 | fill in the rest of the fields when we get the full | |
3951 | type. */ | |
3952 | type = dbx_alloc_type (typenums); | |
3953 | TYPE_CODE (type) = code; | |
3954 | TYPE_NAME (type) = type_name; | |
3955 | ||
3956 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
3957 | ||
3958 | add_undefined_type (type); | |
3959 | return type; | |
3960 | } | |
3961 | ||
3962 | case '0': | |
3963 | case '1': | |
3964 | case '2': | |
3965 | case '3': | |
3966 | case '4': | |
3967 | case '5': | |
3968 | case '6': | |
3969 | case '7': | |
3970 | case '8': | |
3971 | case '9': | |
3972 | case '(': | |
3973 | (*pp)--; | |
3974 | read_type_number (pp, xtypenums); | |
3975 | type = *dbx_lookup_type (xtypenums); | |
3976 | if (type == 0) | |
3977 | type = builtin_type_void; | |
3978 | if (typenums[0] != -1) | |
3979 | *dbx_lookup_type (typenums) = type; | |
3980 | break; | |
3981 | ||
3982 | case '*': | |
3983 | type1 = read_type (pp); | |
3984 | type = lookup_pointer_type (type1); | |
3985 | if (typenums[0] != -1) | |
3986 | *dbx_lookup_type (typenums) = type; | |
3987 | break; | |
3988 | ||
3989 | case '@': | |
3990 | { | |
3991 | struct type *domain = read_type (pp); | |
3992 | struct type *memtype; | |
3993 | ||
3994 | if (**pp != ',') | |
3995 | /* Invalid member type data format. */ | |
3996 | return error_type (pp); | |
3997 | ++*pp; | |
3998 | ||
3999 | memtype = read_type (pp); | |
4000 | type = dbx_alloc_type (typenums); | |
4001 | smash_to_member_type (type, domain, memtype); | |
4002 | } | |
4003 | break; | |
4004 | ||
4005 | case '#': | |
4006 | if ((*pp)[0] == '#') | |
4007 | { | |
4008 | /* We'll get the parameter types from the name. */ | |
4009 | struct type *return_type; | |
4010 | ||
4011 | *pp += 1; | |
4012 | return_type = read_type (pp); | |
4013 | if (*(*pp)++ != ';') | |
4014 | complain (&invalid_member_complaint, symnum); | |
62c4f98b | 4015 | type = allocate_stub_method (return_type); |
bd5635a1 RP |
4016 | if (typenums[0] != -1) |
4017 | *dbx_lookup_type (typenums) = type; | |
bd5635a1 RP |
4018 | } |
4019 | else | |
4020 | { | |
4021 | struct type *domain = read_type (pp); | |
4022 | struct type *return_type; | |
4023 | struct type **args; | |
4024 | ||
4025 | if (*(*pp)++ != ',') | |
4026 | error ("invalid member type data format, at symtab pos %d.", | |
4027 | symnum); | |
4028 | ||
4029 | return_type = read_type (pp); | |
4030 | args = read_args (pp, ';'); | |
4031 | type = dbx_alloc_type (typenums); | |
4032 | smash_to_method_type (type, domain, return_type, args); | |
4033 | } | |
4034 | break; | |
4035 | ||
4036 | case '&': | |
4037 | type1 = read_type (pp); | |
4038 | type = lookup_reference_type (type1); | |
4039 | if (typenums[0] != -1) | |
4040 | *dbx_lookup_type (typenums) = type; | |
4041 | break; | |
4042 | ||
4043 | case 'f': | |
4044 | type1 = read_type (pp); | |
4045 | type = lookup_function_type (type1); | |
4046 | if (typenums[0] != -1) | |
4047 | *dbx_lookup_type (typenums) = type; | |
4048 | break; | |
4049 | ||
4050 | case 'r': | |
4051 | type = read_range_type (pp, typenums); | |
4052 | if (typenums[0] != -1) | |
4053 | *dbx_lookup_type (typenums) = type; | |
4054 | break; | |
4055 | ||
4056 | case 'e': | |
4057 | type = dbx_alloc_type (typenums); | |
4058 | type = read_enum_type (pp, type); | |
4059 | *dbx_lookup_type (typenums) = type; | |
4060 | break; | |
4061 | ||
4062 | case 's': | |
4063 | type = dbx_alloc_type (typenums); | |
4064 | TYPE_NAME (type) = type_synonym_name; | |
4065 | type_synonym_name = 0; | |
4066 | type = read_struct_type (pp, type); | |
4067 | break; | |
4068 | ||
4069 | case 'u': | |
4070 | type = dbx_alloc_type (typenums); | |
4071 | TYPE_NAME (type) = type_synonym_name; | |
4072 | type_synonym_name = 0; | |
4073 | type = read_struct_type (pp, type); | |
4074 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
4075 | break; | |
4076 | ||
4077 | case 'a': | |
4078 | if (**pp != 'r') | |
4079 | return error_type (pp); | |
4080 | ++*pp; | |
4081 | ||
4082 | type = dbx_alloc_type (typenums); | |
4083 | type = read_array_type (pp, type); | |
4084 | break; | |
4085 | ||
4086 | default: | |
5bc757e2 JG |
4087 | --*pp; /* Go back to the symbol in error */ |
4088 | /* Particularly important if it was \0! */ | |
bd5635a1 RP |
4089 | return error_type (pp); |
4090 | } | |
4091 | ||
4092 | if (type == 0) | |
4093 | abort (); | |
4094 | ||
4095 | #if 0 | |
4096 | /* If this is an overriding temporary alteration for a header file's | |
4097 | contents, and this type number is unknown in the global definition, | |
4098 | put this type into the global definition at this type number. */ | |
4099 | if (header_file_prev_index >= 0) | |
4100 | { | |
4101 | register struct type **tp | |
4102 | = explicit_lookup_type (header_file_prev_index, typenums[1]); | |
4103 | if (*tp == 0) | |
4104 | *tp = type; | |
4105 | } | |
4106 | #endif | |
4107 | return type; | |
4108 | } | |
4109 | \f | |
4110 | #if 0 | |
4111 | /* This would be a good idea, but it doesn't really work. The problem | |
4112 | is that in order to get the virtual context for a particular type, | |
4113 | you need to know the virtual info from all of its basetypes, | |
4114 | and you need to have processed its methods. Since GDB reads | |
4115 | symbols on a file-by-file basis, this means processing the symbols | |
4116 | of all the files that are needed for each baseclass, which | |
4117 | means potentially reading in all the debugging info just to fill | |
4118 | in information we may never need. */ | |
4119 | ||
4120 | /* This page contains subroutines of read_type. */ | |
4121 | ||
4122 | /* FOR_TYPE is a struct type defining a virtual function NAME with type | |
4123 | FN_TYPE. The `virtual context' for this virtual function is the | |
4124 | first base class of FOR_TYPE in which NAME is defined with signature | |
4125 | matching FN_TYPE. OFFSET serves as a hash on matches here. | |
4126 | ||
4127 | TYPE is the current type in which we are searching. */ | |
4128 | ||
4129 | static struct type * | |
4130 | virtual_context (for_type, type, name, fn_type, offset) | |
4131 | struct type *for_type, *type; | |
4132 | char *name; | |
4133 | struct type *fn_type; | |
4134 | int offset; | |
4135 | { | |
4136 | struct type *basetype = 0; | |
4137 | int i; | |
4138 | ||
4139 | if (for_type != type) | |
4140 | { | |
4141 | /* Check the methods of TYPE. */ | |
4142 | /* Need to do a check_stub_type here, but that breaks | |
4143 | things because we can get infinite regress. */ | |
4144 | for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i) | |
4145 | if (!strcmp (TYPE_FN_FIELDLIST_NAME (type, i), name)) | |
4146 | break; | |
4147 | if (i >= 0) | |
4148 | { | |
4149 | int j = TYPE_FN_FIELDLIST_LENGTH (type, i); | |
4150 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
4151 | ||
4152 | while (--j >= 0) | |
4153 | if (TYPE_FN_FIELD_VOFFSET (f, j) == offset-1) | |
4154 | return TYPE_FN_FIELD_FCONTEXT (f, j); | |
4155 | } | |
4156 | } | |
62c4f98b | 4157 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) |
bd5635a1 RP |
4158 | { |
4159 | basetype = virtual_context (for_type, TYPE_BASECLASS (type, i), name, | |
4160 | fn_type, offset); | |
4161 | if (basetype != for_type) | |
4162 | return basetype; | |
4163 | } | |
4164 | return for_type; | |
4165 | } | |
4166 | #endif | |
4167 | ||
4168 | /* Read the description of a structure (or union type) | |
4169 | and return an object describing the type. */ | |
4170 | ||
4171 | static struct type * | |
4172 | read_struct_type (pp, type) | |
4173 | char **pp; | |
4174 | register struct type *type; | |
4175 | { | |
4176 | /* Total number of methods defined in this class. | |
4177 | If the class defines two `f' methods, and one `g' method, | |
4178 | then this will have the value 3. */ | |
4179 | int total_length = 0; | |
4180 | ||
4181 | struct nextfield | |
4182 | { | |
4183 | struct nextfield *next; | |
4184 | int visibility; /* 0=public, 1=protected, 2=public */ | |
4185 | struct field field; | |
4186 | }; | |
4187 | ||
4188 | struct next_fnfield | |
4189 | { | |
4190 | struct next_fnfield *next; | |
4191 | int visibility; /* 0=public, 1=protected, 2=public */ | |
4192 | struct fn_field fn_field; | |
4193 | }; | |
4194 | ||
4195 | struct next_fnfieldlist | |
4196 | { | |
4197 | struct next_fnfieldlist *next; | |
4198 | struct fn_fieldlist fn_fieldlist; | |
4199 | }; | |
4200 | ||
4201 | register struct nextfield *list = 0; | |
4202 | struct nextfield *new; | |
4203 | register char *p; | |
4204 | int nfields = 0; | |
4205 | register int n; | |
4206 | ||
4207 | register struct next_fnfieldlist *mainlist = 0; | |
4208 | int nfn_fields = 0; | |
4209 | ||
4210 | if (TYPE_MAIN_VARIANT (type) == 0) | |
4211 | { | |
4212 | TYPE_MAIN_VARIANT (type) = type; | |
4213 | } | |
4214 | ||
4215 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
4216 | ||
4217 | /* First comes the total size in bytes. */ | |
4218 | ||
4219 | TYPE_LENGTH (type) = read_number (pp, 0); | |
4220 | ||
4221 | /* C++: Now, if the class is a derived class, then the next character | |
4222 | will be a '!', followed by the number of base classes derived from. | |
4223 | Each element in the list contains visibility information, | |
4224 | the offset of this base class in the derived structure, | |
4225 | and then the base type. */ | |
4226 | if (**pp == '!') | |
4227 | { | |
4228 | int i, n_baseclasses, offset; | |
4229 | struct type *baseclass; | |
4230 | int via_public; | |
4231 | ||
4232 | /* Nonzero if it is a virtual baseclass, i.e., | |
4233 | ||
4234 | struct A{}; | |
4235 | struct B{}; | |
4236 | struct C : public B, public virtual A {}; | |
4237 | ||
4238 | B is a baseclass of C; A is a virtual baseclass for C. This is a C++ | |
4239 | 2.0 language feature. */ | |
4240 | int via_virtual; | |
4241 | ||
4242 | *pp += 1; | |
4243 | ||
4244 | n_baseclasses = read_number (pp, ','); | |
4245 | TYPE_FIELD_VIRTUAL_BITS (type) = | |
4246 | (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses)); | |
4247 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses); | |
4248 | ||
4249 | for (i = 0; i < n_baseclasses; i++) | |
4250 | { | |
4251 | if (**pp == '\\') | |
4252 | *pp = next_symbol_text (); | |
4253 | ||
4254 | switch (**pp) | |
4255 | { | |
4256 | case '0': | |
4257 | via_virtual = 0; | |
4258 | break; | |
4259 | case '1': | |
4260 | via_virtual = 1; | |
4261 | break; | |
4262 | default: | |
4263 | /* Bad visibility format. */ | |
4264 | return error_type (pp); | |
4265 | } | |
4266 | ++*pp; | |
4267 | ||
4268 | switch (**pp) | |
4269 | { | |
4270 | case '0': | |
4271 | via_public = 0; | |
4272 | break; | |
4273 | case '2': | |
4274 | via_public = 2; | |
4275 | break; | |
4276 | default: | |
4277 | /* Bad visibility format. */ | |
4278 | return error_type (pp); | |
4279 | } | |
4280 | if (via_virtual) | |
4281 | SET_TYPE_FIELD_VIRTUAL (type, i); | |
4282 | ++*pp; | |
4283 | ||
4284 | /* Offset of the portion of the object corresponding to | |
4285 | this baseclass. Always zero in the absence of | |
4286 | multiple inheritance. */ | |
4287 | offset = read_number (pp, ','); | |
4288 | baseclass = read_type (pp); | |
4289 | *pp += 1; /* skip trailing ';' */ | |
4290 | ||
bd5635a1 RP |
4291 | /* Make this baseclass visible for structure-printing purposes. */ |
4292 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
4293 | new->next = list; | |
4294 | list = new; | |
4295 | list->visibility = via_public; | |
4296 | list->field.type = baseclass; | |
4297 | list->field.name = type_name_no_tag (baseclass); | |
4298 | list->field.bitpos = offset; | |
4299 | list->field.bitsize = 0; /* this should be an unpacked field! */ | |
4300 | nfields++; | |
4301 | } | |
4302 | TYPE_N_BASECLASSES (type) = n_baseclasses; | |
4303 | } | |
4304 | ||
4305 | /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one. | |
4306 | At the end, we see a semicolon instead of a field. | |
4307 | ||
4308 | In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for | |
4309 | a static field. | |
4310 | ||
4311 | The `?' is a placeholder for one of '/2' (public visibility), | |
4312 | '/1' (protected visibility), '/0' (private visibility), or nothing | |
4313 | (C style symbol table, public visibility). */ | |
4314 | ||
4315 | /* We better set p right now, in case there are no fields at all... */ | |
4316 | p = *pp; | |
4317 | ||
4318 | while (**pp != ';') | |
4319 | { | |
4320 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
4321 | if (**pp == '\\') *pp = next_symbol_text (); | |
4322 | ||
4323 | /* Get space to record the next field's data. */ | |
4324 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
4325 | new->next = list; | |
4326 | list = new; | |
4327 | ||
4328 | /* Get the field name. */ | |
4329 | p = *pp; | |
4330 | if (*p == CPLUS_MARKER) | |
4331 | { | |
4332 | /* Special GNU C++ name. */ | |
4333 | if (*++p == 'v') | |
4334 | { | |
e1ce8aa5 JK |
4335 | const char *prefix; |
4336 | char *name = 0; | |
bd5635a1 RP |
4337 | struct type *context; |
4338 | ||
4339 | switch (*++p) | |
4340 | { | |
4341 | case 'f': | |
4342 | prefix = vptr_name; | |
4343 | break; | |
4344 | case 'b': | |
4345 | prefix = vb_name; | |
4346 | break; | |
4347 | default: | |
4348 | error ("invalid abbreviation at symtab pos %d.", symnum); | |
4349 | } | |
4350 | *pp = p + 1; | |
4351 | context = read_type (pp); | |
4352 | if (type_name_no_tag (context) == 0) | |
4353 | { | |
4354 | if (name == 0) | |
4355 | error ("type name unknown at symtab pos %d.", symnum); | |
62c4f98b | 4356 | /* FIXME-tiemann: when is `name' ever non-0? */ |
bd5635a1 RP |
4357 | TYPE_NAME (context) = obsavestring (name, p - name - 1); |
4358 | } | |
4359 | list->field.name = obconcat (prefix, type_name_no_tag (context), ""); | |
4360 | p = ++(*pp); | |
4361 | if (p[-1] != ':') | |
4362 | error ("invalid abbreviation at symtab pos %d.", symnum); | |
4363 | list->field.type = read_type (pp); | |
4364 | (*pp)++; /* Skip the comma. */ | |
4365 | list->field.bitpos = read_number (pp, ';'); | |
4366 | /* This field is unpacked. */ | |
4367 | list->field.bitsize = 0; | |
4368 | } | |
9404978d MT |
4369 | /* GNU C++ anonymous type. */ |
4370 | else if (*p == '_') | |
4371 | break; | |
bd5635a1 RP |
4372 | else |
4373 | error ("invalid abbreviation at symtab pos %d.", symnum); | |
4374 | ||
4375 | nfields++; | |
4376 | continue; | |
4377 | } | |
4378 | ||
4379 | while (*p != ':') p++; | |
4380 | list->field.name = obsavestring (*pp, p - *pp); | |
4381 | ||
4382 | /* C++: Check to see if we have hit the methods yet. */ | |
4383 | if (p[1] == ':') | |
4384 | break; | |
4385 | ||
4386 | *pp = p + 1; | |
4387 | ||
4388 | /* This means we have a visibility for a field coming. */ | |
4389 | if (**pp == '/') | |
4390 | { | |
4391 | switch (*++*pp) | |
4392 | { | |
4393 | case '0': | |
4394 | list->visibility = 0; /* private */ | |
4395 | *pp += 1; | |
4396 | break; | |
4397 | ||
4398 | case '1': | |
4399 | list->visibility = 1; /* protected */ | |
4400 | *pp += 1; | |
4401 | break; | |
4402 | ||
4403 | case '2': | |
4404 | list->visibility = 2; /* public */ | |
4405 | *pp += 1; | |
4406 | break; | |
4407 | } | |
4408 | } | |
4409 | else /* normal dbx-style format. */ | |
4410 | list->visibility = 2; /* public */ | |
4411 | ||
4412 | list->field.type = read_type (pp); | |
4413 | if (**pp == ':') | |
4414 | { | |
4415 | /* Static class member. */ | |
4416 | list->field.bitpos = (long)-1; | |
4417 | p = ++(*pp); | |
4418 | while (*p != ';') p++; | |
4419 | list->field.bitsize = (long) savestring (*pp, p - *pp); | |
4420 | *pp = p + 1; | |
4421 | nfields++; | |
4422 | continue; | |
4423 | } | |
4424 | else if (**pp != ',') | |
4425 | /* Bad structure-type format. */ | |
4426 | return error_type (pp); | |
4427 | ||
4428 | (*pp)++; /* Skip the comma. */ | |
4429 | list->field.bitpos = read_number (pp, ','); | |
4430 | list->field.bitsize = read_number (pp, ';'); | |
4431 | ||
4432 | #if 0 | |
62c4f98b JK |
4433 | /* FIXME-tiemann: Can't the compiler put out something which |
4434 | lets us distinguish these? (or maybe just not put out anything | |
4435 | for the field). What is the story here? What does the compiler | |
bd5635a1 RP |
4436 | really do? Also, patch gdb.texinfo for this case; I document |
4437 | it as a possible problem there. Search for "DBX-style". */ | |
4438 | ||
4439 | /* This is wrong because this is identical to the symbols | |
4440 | produced for GCC 0-size arrays. For example: | |
4441 | typedef union { | |
4442 | int num; | |
4443 | char str[0]; | |
4444 | } foo; | |
4445 | The code which dumped core in such circumstances should be | |
4446 | fixed not to dump core. */ | |
4447 | ||
4448 | /* g++ -g0 can put out bitpos & bitsize zero for a static | |
4449 | field. This does not give us any way of getting its | |
4450 | class, so we can't know its name. But we can just | |
4451 | ignore the field so we don't dump core and other nasty | |
4452 | stuff. */ | |
4453 | if (list->field.bitpos == 0 | |
4454 | && list->field.bitsize == 0) | |
4455 | { | |
4456 | complain (&dbx_class_complaint, 0); | |
4457 | /* Ignore this field. */ | |
4458 | list = list->next; | |
4459 | } | |
4460 | else | |
4461 | #endif /* 0 */ | |
4462 | { | |
4463 | /* Detect an unpacked field and mark it as such. | |
4464 | dbx gives a bit size for all fields. | |
4465 | Note that forward refs cannot be packed, | |
4466 | and treat enums as if they had the width of ints. */ | |
4467 | if (TYPE_CODE (list->field.type) != TYPE_CODE_INT | |
4468 | && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM) | |
4469 | list->field.bitsize = 0; | |
4470 | if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type) | |
4471 | || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM | |
4472 | && (list->field.bitsize | |
4473 | == 8 * TYPE_LENGTH (builtin_type_int)) | |
4474 | ) | |
4475 | ) | |
4476 | && | |
4477 | list->field.bitpos % 8 == 0) | |
4478 | list->field.bitsize = 0; | |
4479 | nfields++; | |
4480 | } | |
4481 | } | |
4482 | ||
4483 | if (p[1] == ':') | |
4484 | /* chill the list of fields: the last entry (at the head) | |
4485 | is a partially constructed entry which we now scrub. */ | |
4486 | list = list->next; | |
4487 | ||
4488 | /* Now create the vector of fields, and record how big it is. | |
4489 | We need this info to record proper virtual function table information | |
4490 | for this class's virtual functions. */ | |
4491 | ||
4492 | TYPE_NFIELDS (type) = nfields; | |
4493 | TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, | |
4494 | sizeof (struct field) * nfields); | |
4495 | ||
4496 | TYPE_FIELD_PRIVATE_BITS (type) = | |
4497 | (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields)); | |
4498 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
4499 | ||
4500 | TYPE_FIELD_PROTECTED_BITS (type) = | |
4501 | (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields)); | |
4502 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
4503 | ||
4504 | /* Copy the saved-up fields into the field vector. */ | |
4505 | ||
4506 | for (n = nfields; list; list = list->next) | |
4507 | { | |
4508 | n -= 1; | |
4509 | TYPE_FIELD (type, n) = list->field; | |
4510 | if (list->visibility == 0) | |
4511 | SET_TYPE_FIELD_PRIVATE (type, n); | |
4512 | else if (list->visibility == 1) | |
4513 | SET_TYPE_FIELD_PROTECTED (type, n); | |
4514 | } | |
4515 | ||
4516 | /* Now come the method fields, as NAME::methods | |
4517 | where each method is of the form TYPENUM,ARGS,...:PHYSNAME; | |
4518 | At the end, we see a semicolon instead of a field. | |
4519 | ||
4520 | For the case of overloaded operators, the format is | |
4521 | OPERATOR::*.methods, where OPERATOR is the string "operator", | |
4522 | `*' holds the place for an operator name (such as `+=') | |
4523 | and `.' marks the end of the operator name. */ | |
4524 | if (p[1] == ':') | |
4525 | { | |
4526 | /* Now, read in the methods. To simplify matters, we | |
4527 | "unread" the name that has been read, so that we can | |
4528 | start from the top. */ | |
4529 | ||
4530 | /* For each list of method lists... */ | |
4531 | do | |
4532 | { | |
4533 | int i; | |
4534 | struct next_fnfield *sublist = 0; | |
dcc35536 | 4535 | struct type *look_ahead_type = NULL; |
bd5635a1 RP |
4536 | int length = 0; |
4537 | struct next_fnfieldlist *new_mainlist = | |
4538 | (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist)); | |
4539 | char *main_fn_name; | |
4540 | ||
4541 | p = *pp; | |
4542 | ||
4543 | /* read in the name. */ | |
4544 | while (*p != ':') p++; | |
4545 | if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER) | |
4546 | { | |
4547 | /* This lets the user type "break operator+". | |
4548 | We could just put in "+" as the name, but that wouldn't | |
4549 | work for "*". */ | |
62c4f98b JK |
4550 | static char opname[32] = {'o', 'p', CPLUS_MARKER}; |
4551 | char *o = opname + 3; | |
bd5635a1 RP |
4552 | |
4553 | /* Skip past '::'. */ | |
4554 | p += 2; | |
4555 | while (*p != '.') | |
4556 | *o++ = *p++; | |
4557 | main_fn_name = savestring (opname, o - opname); | |
4558 | /* Skip past '.' */ | |
4559 | *pp = p + 1; | |
4560 | } | |
4561 | else | |
4562 | { | |
4563 | i = 0; | |
4564 | main_fn_name = savestring (*pp, p - *pp); | |
4565 | /* Skip past '::'. */ | |
4566 | *pp = p + 2; | |
4567 | } | |
4568 | new_mainlist->fn_fieldlist.name = main_fn_name; | |
4569 | ||
4570 | do | |
4571 | { | |
4572 | struct next_fnfield *new_sublist = | |
4573 | (struct next_fnfield *)alloca (sizeof (struct next_fnfield)); | |
4574 | ||
4575 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
dcc35536 JG |
4576 | if (look_ahead_type == NULL) /* Normal case. */ |
4577 | { | |
4578 | if (**pp == '\\') *pp = next_symbol_text (); | |
bd5635a1 | 4579 | |
dcc35536 JG |
4580 | new_sublist->fn_field.type = read_type (pp); |
4581 | if (**pp != ':') | |
4582 | /* Invalid symtab info for method. */ | |
4583 | return error_type (pp); | |
4584 | } | |
4585 | else | |
4586 | { /* g++ version 1 kludge */ | |
4587 | new_sublist->fn_field.type = look_ahead_type; | |
4588 | look_ahead_type = NULL; | |
4589 | } | |
bd5635a1 RP |
4590 | |
4591 | *pp += 1; | |
4592 | p = *pp; | |
4593 | while (*p != ';') p++; | |
4594 | /* If this is just a stub, then we don't have the | |
4595 | real name here. */ | |
4596 | new_sublist->fn_field.physname = savestring (*pp, p - *pp); | |
4597 | *pp = p + 1; | |
4598 | new_sublist->visibility = *(*pp)++ - '0'; | |
4599 | if (**pp == '\\') *pp = next_symbol_text (); | |
62c4f98b | 4600 | /* FIXME-tiemann: need to add const/volatile info |
bd5635a1 RP |
4601 | to the methods. For now, just skip the char. |
4602 | In future, here's what we need to implement: | |
4603 | ||
4604 | A for normal functions. | |
4605 | B for `const' member functions. | |
4606 | C for `volatile' member functions. | |
4607 | D for `const volatile' member functions. */ | |
4608 | if (**pp == 'A' || **pp == 'B' || **pp == 'C' || **pp == 'D') | |
4609 | (*pp)++; | |
9bb30452 | 4610 | |
9107291d JK |
4611 | /* This probably just means we're processing a file compiled |
4612 | with g++ version 1. */ | |
bd5635a1 RP |
4613 | else |
4614 | complain(&const_vol_complaint, **pp); | |
4615 | ||
4616 | switch (*(*pp)++) | |
4617 | { | |
4618 | case '*': | |
4619 | /* virtual member function, followed by index. */ | |
4620 | /* The sign bit is set to distinguish pointers-to-methods | |
4621 | from virtual function indicies. Since the array is | |
4622 | in words, the quantity must be shifted left by 1 | |
4623 | on 16 bit machine, and by 2 on 32 bit machine, forcing | |
4624 | the sign bit out, and usable as a valid index into | |
4625 | the array. Remove the sign bit here. */ | |
4626 | new_sublist->fn_field.voffset = | |
4627 | (0x7fffffff & read_number (pp, ';')) + 1; | |
4628 | ||
dcc35536 JG |
4629 | if (**pp == '\\') *pp = next_symbol_text (); |
4630 | ||
9107291d JK |
4631 | if (**pp == ';' || **pp == '\0') |
4632 | /* Must be g++ version 1. */ | |
4633 | new_sublist->fn_field.fcontext = 0; | |
bd5635a1 | 4634 | else |
9107291d JK |
4635 | { |
4636 | /* Figure out from whence this virtual function came. | |
4637 | It may belong to virtual function table of | |
4638 | one of its baseclasses. */ | |
dcc35536 JG |
4639 | look_ahead_type = read_type (pp); |
4640 | if (**pp == ':') | |
4641 | { /* g++ version 1 overloaded methods. */ } | |
9107291d | 4642 | else |
dcc35536 JG |
4643 | { |
4644 | new_sublist->fn_field.fcontext = look_ahead_type; | |
4645 | if (**pp != ';') | |
4646 | return error_type (pp); | |
4647 | else | |
4648 | ++*pp; | |
4649 | look_ahead_type = NULL; | |
4650 | } | |
9107291d | 4651 | } |
bd5635a1 RP |
4652 | break; |
4653 | ||
4654 | case '?': | |
4655 | /* static member function. */ | |
4656 | new_sublist->fn_field.voffset = VOFFSET_STATIC; | |
4657 | break; | |
4658 | default: | |
4659 | /* **pp == '.'. */ | |
4660 | /* normal member function. */ | |
4661 | new_sublist->fn_field.voffset = 0; | |
62c4f98b | 4662 | new_sublist->fn_field.fcontext = 0; |
bd5635a1 RP |
4663 | break; |
4664 | } | |
4665 | ||
4666 | new_sublist->next = sublist; | |
4667 | sublist = new_sublist; | |
4668 | length++; | |
4669 | } | |
9107291d | 4670 | while (**pp != ';' && **pp != '\0'); |
bd5635a1 RP |
4671 | |
4672 | *pp += 1; | |
4673 | ||
4674 | new_mainlist->fn_fieldlist.fn_fields = | |
4675 | (struct fn_field *) obstack_alloc (symbol_obstack, | |
4676 | sizeof (struct fn_field) * length); | |
4677 | TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) = | |
4678 | (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length)); | |
4679 | B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length); | |
4680 | ||
4681 | TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) = | |
4682 | (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length)); | |
4683 | B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length); | |
4684 | ||
4685 | for (i = length; (i--, sublist); sublist = sublist->next) | |
4686 | { | |
4687 | new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field; | |
4688 | if (sublist->visibility == 0) | |
4689 | B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i); | |
4690 | else if (sublist->visibility == 1) | |
4691 | B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i); | |
4692 | } | |
4693 | ||
4694 | new_mainlist->fn_fieldlist.length = length; | |
4695 | new_mainlist->next = mainlist; | |
4696 | mainlist = new_mainlist; | |
4697 | nfn_fields++; | |
4698 | total_length += length; | |
4699 | } | |
4700 | while (**pp != ';'); | |
4701 | } | |
4702 | ||
4703 | *pp += 1; | |
4704 | ||
4705 | TYPE_FN_FIELDLISTS (type) = | |
4706 | (struct fn_fieldlist *) obstack_alloc (symbol_obstack, | |
4707 | sizeof (struct fn_fieldlist) * nfn_fields); | |
4708 | ||
4709 | TYPE_NFN_FIELDS (type) = nfn_fields; | |
4710 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
4711 | ||
4712 | { | |
4713 | int i; | |
4714 | for (i = 0; i < TYPE_N_BASECLASSES (type); ++i) | |
4715 | TYPE_NFN_FIELDS_TOTAL (type) += | |
4716 | TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i)); | |
4717 | } | |
4718 | ||
4719 | for (n = nfn_fields; mainlist; mainlist = mainlist->next) | |
4720 | TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist; | |
4721 | ||
4722 | if (**pp == '~') | |
4723 | { | |
4724 | *pp += 1; | |
4725 | ||
4726 | if (**pp == '=') | |
4727 | { | |
4728 | TYPE_FLAGS (type) | |
4729 | |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR; | |
4730 | *pp += 1; | |
4731 | } | |
4732 | else if (**pp == '+') | |
4733 | { | |
4734 | TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR; | |
4735 | *pp += 1; | |
4736 | } | |
4737 | else if (**pp == '-') | |
4738 | { | |
4739 | TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR; | |
4740 | *pp += 1; | |
4741 | } | |
4742 | ||
4743 | /* Read either a '%' or the final ';'. */ | |
4744 | if (*(*pp)++ == '%') | |
4745 | { | |
4746 | /* Now we must record the virtual function table pointer's | |
4747 | field information. */ | |
4748 | ||
4749 | struct type *t; | |
4750 | int i; | |
4751 | ||
4752 | t = read_type (pp); | |
4753 | p = (*pp)++; | |
4754 | while (*p != '\0' && *p != ';') | |
4755 | p++; | |
4756 | if (*p == '\0') | |
4757 | /* Premature end of symbol. */ | |
4758 | return error_type (pp); | |
4759 | ||
4760 | TYPE_VPTR_BASETYPE (type) = t; | |
4761 | if (type == t) | |
4762 | { | |
4763 | if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0) | |
62c4f98b JK |
4764 | { |
4765 | /* FIXME-tiemann: what's this? */ | |
4766 | #if 0 | |
4767 | TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t); | |
4768 | #else | |
4769 | error_type (pp); | |
4770 | #endif | |
4771 | } | |
bd5635a1 RP |
4772 | else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i) |
4773 | if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name, | |
4774 | sizeof (vptr_name) -1)) | |
4775 | { | |
4776 | TYPE_VPTR_FIELDNO (type) = i; | |
4777 | break; | |
4778 | } | |
4779 | if (i < 0) | |
4780 | /* Virtual function table field not found. */ | |
4781 | return error_type (pp); | |
4782 | } | |
4783 | else | |
4784 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
4785 | *pp = p + 1; | |
4786 | } | |
bd5635a1 RP |
4787 | } |
4788 | ||
4789 | return type; | |
4790 | } | |
4791 | ||
4792 | /* Read a definition of an array type, | |
4793 | and create and return a suitable type object. | |
4794 | Also creates a range type which represents the bounds of that | |
4795 | array. */ | |
4796 | static struct type * | |
4797 | read_array_type (pp, type) | |
4798 | register char **pp; | |
4799 | register struct type *type; | |
4800 | { | |
4801 | struct type *index_type, *element_type, *range_type; | |
4802 | int lower, upper; | |
4803 | int adjustable = 0; | |
4804 | ||
4805 | /* Format of an array type: | |
4806 | "ar<index type>;lower;upper;<array_contents_type>". Put code in | |
4807 | to handle this. | |
4808 | ||
4809 | Fortran adjustable arrays use Adigits or Tdigits for lower or upper; | |
4810 | for these, produce a type like float[][]. */ | |
4811 | ||
4812 | index_type = read_type (pp); | |
4813 | if (**pp != ';') | |
4814 | /* Improper format of array type decl. */ | |
4815 | return error_type (pp); | |
4816 | ++*pp; | |
4817 | ||
4818 | if (!(**pp >= '0' && **pp <= '9')) | |
4819 | { | |
4820 | *pp += 1; | |
4821 | adjustable = 1; | |
4822 | } | |
4823 | lower = read_number (pp, ';'); | |
4824 | ||
4825 | if (!(**pp >= '0' && **pp <= '9')) | |
4826 | { | |
4827 | *pp += 1; | |
4828 | adjustable = 1; | |
4829 | } | |
4830 | upper = read_number (pp, ';'); | |
4831 | ||
4832 | element_type = read_type (pp); | |
4833 | ||
4834 | if (adjustable) | |
4835 | { | |
4836 | lower = 0; | |
4837 | upper = -1; | |
4838 | } | |
4839 | ||
4840 | { | |
4841 | /* Create range type. */ | |
4842 | range_type = (struct type *) obstack_alloc (symbol_obstack, | |
4843 | sizeof (struct type)); | |
4844 | TYPE_CODE (range_type) = TYPE_CODE_RANGE; | |
4845 | TYPE_TARGET_TYPE (range_type) = index_type; | |
4846 | ||
4847 | /* This should never be needed. */ | |
4848 | TYPE_LENGTH (range_type) = sizeof (int); | |
4849 | ||
4850 | TYPE_NFIELDS (range_type) = 2; | |
4851 | TYPE_FIELDS (range_type) = | |
4852 | (struct field *) obstack_alloc (symbol_obstack, | |
4853 | 2 * sizeof (struct field)); | |
4854 | TYPE_FIELD_BITPOS (range_type, 0) = lower; | |
4855 | TYPE_FIELD_BITPOS (range_type, 1) = upper; | |
4856 | } | |
4857 | ||
4858 | TYPE_CODE (type) = TYPE_CODE_ARRAY; | |
4859 | TYPE_TARGET_TYPE (type) = element_type; | |
4860 | TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type); | |
4861 | TYPE_NFIELDS (type) = 1; | |
4862 | TYPE_FIELDS (type) = | |
4863 | (struct field *) obstack_alloc (symbol_obstack, | |
4864 | sizeof (struct field)); | |
4865 | TYPE_FIELD_TYPE (type, 0) = range_type; | |
4866 | ||
4867 | return type; | |
4868 | } | |
4869 | ||
4870 | ||
4871 | /* Read a definition of an enumeration type, | |
4872 | and create and return a suitable type object. | |
4873 | Also defines the symbols that represent the values of the type. */ | |
4874 | ||
4875 | static struct type * | |
4876 | read_enum_type (pp, type) | |
4877 | register char **pp; | |
4878 | register struct type *type; | |
4879 | { | |
4880 | register char *p; | |
4881 | char *name; | |
4882 | register long n; | |
4883 | register struct symbol *sym; | |
4884 | int nsyms = 0; | |
4885 | struct pending **symlist; | |
4886 | struct pending *osyms, *syms; | |
4887 | int o_nsyms; | |
4888 | ||
4889 | if (within_function) | |
4890 | symlist = &local_symbols; | |
4891 | else | |
4892 | symlist = &file_symbols; | |
4893 | osyms = *symlist; | |
4894 | o_nsyms = osyms ? osyms->nsyms : 0; | |
4895 | ||
4896 | /* Read the value-names and their values. | |
4897 | The input syntax is NAME:VALUE,NAME:VALUE, and so on. | |
4898 | A semicolon or comman instead of a NAME means the end. */ | |
4899 | while (**pp && **pp != ';' && **pp != ',') | |
4900 | { | |
4901 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
4902 | if (**pp == '\\') *pp = next_symbol_text (); | |
4903 | ||
4904 | p = *pp; | |
4905 | while (*p != ':') p++; | |
4906 | name = obsavestring (*pp, p - *pp); | |
4907 | *pp = p + 1; | |
4908 | n = read_number (pp, ','); | |
4909 | ||
4910 | sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol)); | |
4911 | bzero (sym, sizeof (struct symbol)); | |
4912 | SYMBOL_NAME (sym) = name; | |
4913 | SYMBOL_CLASS (sym) = LOC_CONST; | |
4914 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
4915 | SYMBOL_VALUE (sym) = n; | |
4916 | add_symbol_to_list (sym, symlist); | |
4917 | nsyms++; | |
4918 | } | |
4919 | ||
4920 | if (**pp == ';') | |
4921 | (*pp)++; /* Skip the semicolon. */ | |
4922 | ||
4923 | /* Now fill in the fields of the type-structure. */ | |
4924 | ||
4925 | TYPE_LENGTH (type) = sizeof (int); | |
4926 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
4927 | TYPE_NFIELDS (type) = nsyms; | |
4928 | TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms); | |
4929 | ||
4930 | /* Find the symbols for the values and put them into the type. | |
4931 | The symbols can be found in the symlist that we put them on | |
4932 | to cause them to be defined. osyms contains the old value | |
4933 | of that symlist; everything up to there was defined by us. */ | |
4934 | /* Note that we preserve the order of the enum constants, so | |
4935 | that in something like "enum {FOO, LAST_THING=FOO}" we print | |
4936 | FOO, not LAST_THING. */ | |
4937 | ||
4938 | for (syms = *symlist, n = 0; syms; syms = syms->next) | |
4939 | { | |
4940 | int j = 0; | |
4941 | if (syms == osyms) | |
4942 | j = o_nsyms; | |
4943 | for (; j < syms->nsyms; j++,n++) | |
4944 | { | |
0c4d2cc2 JG |
4945 | struct symbol *xsym = syms->symbol[j]; |
4946 | SYMBOL_TYPE (xsym) = type; | |
4947 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); | |
bd5635a1 | 4948 | TYPE_FIELD_VALUE (type, n) = 0; |
0c4d2cc2 | 4949 | TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); |
bd5635a1 RP |
4950 | TYPE_FIELD_BITSIZE (type, n) = 0; |
4951 | } | |
4952 | if (syms == osyms) | |
4953 | break; | |
4954 | } | |
4955 | ||
0c4d2cc2 JG |
4956 | /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */ |
4957 | if(TYPE_NFIELDS(type) == 2 && | |
4958 | ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") && | |
4959 | !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) || | |
4960 | (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") && | |
4961 | !strcmp(TYPE_FIELD_NAME(type,0),"FALSE")))) | |
4962 | TYPE_CODE(type) = TYPE_CODE_BOOL; | |
4963 | ||
bd5635a1 RP |
4964 | return type; |
4965 | } | |
4966 | ||
4967 | /* Read a number from the string pointed to by *PP. | |
4968 | The value of *PP is advanced over the number. | |
4969 | If END is nonzero, the character that ends the | |
4970 | number must match END, or an error happens; | |
4971 | and that character is skipped if it does match. | |
4972 | If END is zero, *PP is left pointing to that character. | |
4973 | ||
4974 | If the number fits in a long, set *VALUE and set *BITS to 0. | |
4975 | If not, set *BITS to be the number of bits in the number. | |
4976 | ||
4977 | If encounter garbage, set *BITS to -1. */ | |
4978 | ||
4979 | static void | |
4980 | read_huge_number (pp, end, valu, bits) | |
4981 | char **pp; | |
4982 | int end; | |
4983 | long *valu; | |
4984 | int *bits; | |
4985 | { | |
4986 | char *p = *pp; | |
4987 | int sign = 1; | |
4988 | long n = 0; | |
4989 | int radix = 10; | |
4990 | char overflow = 0; | |
4991 | int nbits = 0; | |
4992 | int c; | |
d11c44f1 | 4993 | long upper_limit; |
bd5635a1 RP |
4994 | |
4995 | if (*p == '-') | |
4996 | { | |
4997 | sign = -1; | |
4998 | p++; | |
4999 | } | |
5000 | ||
5001 | /* Leading zero means octal. GCC uses this to output values larger | |
5002 | than an int (because that would be hard in decimal). */ | |
5003 | if (*p == '0') | |
5004 | { | |
5005 | radix = 8; | |
5006 | p++; | |
5007 | } | |
5008 | ||
d11c44f1 | 5009 | upper_limit = LONG_MAX / radix; |
bd5635a1 RP |
5010 | while ((c = *p++) >= '0' && c <= ('0' + radix)) |
5011 | { | |
d11c44f1 | 5012 | if (n <= upper_limit) |
bd5635a1 RP |
5013 | { |
5014 | n *= radix; | |
5015 | n += c - '0'; /* FIXME this overflows anyway */ | |
5016 | } | |
5017 | else | |
5018 | overflow = 1; | |
5019 | ||
5020 | /* This depends on large values being output in octal, which is | |
5021 | what GCC does. */ | |
5022 | if (radix == 8) | |
5023 | { | |
5024 | if (nbits == 0) | |
5025 | { | |
5026 | if (c == '0') | |
5027 | /* Ignore leading zeroes. */ | |
5028 | ; | |
5029 | else if (c == '1') | |
5030 | nbits = 1; | |
5031 | else if (c == '2' || c == '3') | |
5032 | nbits = 2; | |
5033 | else | |
5034 | nbits = 3; | |
5035 | } | |
5036 | else | |
5037 | nbits += 3; | |
5038 | } | |
5039 | } | |
5040 | if (end) | |
5041 | { | |
5042 | if (c && c != end) | |
5043 | { | |
5044 | if (bits != NULL) | |
5045 | *bits = -1; | |
5046 | return; | |
5047 | } | |
5048 | } | |
5049 | else | |
5050 | --p; | |
5051 | ||
5052 | *pp = p; | |
5053 | if (overflow) | |
5054 | { | |
5055 | if (nbits == 0) | |
5056 | { | |
5057 | /* Large decimal constants are an error (because it is hard to | |
5058 | count how many bits are in them). */ | |
5059 | if (bits != NULL) | |
5060 | *bits = -1; | |
5061 | return; | |
5062 | } | |
5063 | ||
5064 | /* -0x7f is the same as 0x80. So deal with it by adding one to | |
5065 | the number of bits. */ | |
5066 | if (sign == -1) | |
5067 | ++nbits; | |
5068 | if (bits) | |
5069 | *bits = nbits; | |
5070 | } | |
5071 | else | |
5072 | { | |
5073 | if (valu) | |
5074 | *valu = n * sign; | |
5075 | if (bits) | |
5076 | *bits = 0; | |
5077 | } | |
5078 | } | |
5079 | ||
0c4d2cc2 JG |
5080 | #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1) |
5081 | #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1))) | |
bd5635a1 RP |
5082 | |
5083 | static struct type * | |
5084 | read_range_type (pp, typenums) | |
5085 | char **pp; | |
5086 | int typenums[2]; | |
5087 | { | |
5088 | int rangenums[2]; | |
5089 | long n2, n3; | |
5090 | int n2bits, n3bits; | |
5091 | int self_subrange; | |
5092 | struct type *result_type; | |
5093 | ||
5094 | /* First comes a type we are a subrange of. | |
5095 | In C it is usually 0, 1 or the type being defined. */ | |
5096 | read_type_number (pp, rangenums); | |
5097 | self_subrange = (rangenums[0] == typenums[0] && | |
5098 | rangenums[1] == typenums[1]); | |
5099 | ||
5100 | /* A semicolon should now follow; skip it. */ | |
5101 | if (**pp == ';') | |
5102 | (*pp)++; | |
5103 | ||
5104 | /* The remaining two operands are usually lower and upper bounds | |
5105 | of the range. But in some special cases they mean something else. */ | |
5106 | read_huge_number (pp, ';', &n2, &n2bits); | |
5107 | read_huge_number (pp, ';', &n3, &n3bits); | |
5108 | ||
5109 | if (n2bits == -1 || n3bits == -1) | |
5110 | return error_type (pp); | |
5111 | ||
5112 | /* If limits are huge, must be large integral type. */ | |
5113 | if (n2bits != 0 || n3bits != 0) | |
5114 | { | |
5115 | char got_signed = 0; | |
5116 | char got_unsigned = 0; | |
5117 | /* Number of bits in the type. */ | |
5118 | int nbits; | |
5119 | ||
5120 | /* Range from 0 to <large number> is an unsigned large integral type. */ | |
5121 | if ((n2bits == 0 && n2 == 0) && n3bits != 0) | |
5122 | { | |
5123 | got_unsigned = 1; | |
5124 | nbits = n3bits; | |
5125 | } | |
5126 | /* Range from <large number> to <large number>-1 is a large signed | |
5127 | integral type. */ | |
5128 | else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) | |
5129 | { | |
5130 | got_signed = 1; | |
5131 | nbits = n2bits; | |
5132 | } | |
5133 | ||
62c4f98b JK |
5134 | /* Check for "long long". */ |
5135 | if (got_signed && nbits == TARGET_LONG_LONG_BIT) | |
5136 | return builtin_type_long_long; | |
5137 | if (got_unsigned && nbits == TARGET_LONG_LONG_BIT) | |
5138 | return builtin_type_unsigned_long_long; | |
5139 | ||
bd5635a1 RP |
5140 | if (got_signed || got_unsigned) |
5141 | { | |
5142 | result_type = (struct type *) obstack_alloc (symbol_obstack, | |
5143 | sizeof (struct type)); | |
5144 | bzero (result_type, sizeof (struct type)); | |
5145 | TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT; | |
5146 | TYPE_MAIN_VARIANT (result_type) = result_type; | |
5147 | TYPE_CODE (result_type) = TYPE_CODE_INT; | |
5148 | if (got_unsigned) | |
5149 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; | |
5150 | return result_type; | |
5151 | } | |
5152 | else | |
5153 | return error_type (pp); | |
5154 | } | |
5155 | ||
5156 | /* A type defined as a subrange of itself, with bounds both 0, is void. */ | |
5157 | if (self_subrange && n2 == 0 && n3 == 0) | |
5158 | return builtin_type_void; | |
5159 | ||
5160 | /* If n3 is zero and n2 is not, we want a floating type, | |
5161 | and n2 is the width in bytes. | |
5162 | ||
5163 | Fortran programs appear to use this for complex types also, | |
5164 | and they give no way to distinguish between double and single-complex! | |
5165 | We don't have complex types, so we would lose on all fortran files! | |
5166 | So return type `double' for all of those. It won't work right | |
5167 | for the complex values, but at least it makes the file loadable. */ | |
5168 | ||
5169 | if (n3 == 0 && n2 > 0) | |
5170 | { | |
5171 | if (n2 == sizeof (float)) | |
5172 | return builtin_type_float; | |
5173 | return builtin_type_double; | |
5174 | } | |
5175 | ||
5176 | /* If the upper bound is -1, it must really be an unsigned int. */ | |
5177 | ||
5178 | else if (n2 == 0 && n3 == -1) | |
5179 | { | |
5180 | if (sizeof (int) == sizeof (long)) | |
5181 | return builtin_type_unsigned_int; | |
5182 | else | |
5183 | return builtin_type_unsigned_long; | |
5184 | } | |
5185 | ||
5186 | /* Special case: char is defined (Who knows why) as a subrange of | |
5187 | itself with range 0-127. */ | |
5188 | else if (self_subrange && n2 == 0 && n3 == 127) | |
5189 | return builtin_type_char; | |
5190 | ||
5191 | /* Assumptions made here: Subrange of self is equivalent to subrange | |
5192 | of int. */ | |
5193 | else if (n2 == 0 | |
5194 | && (self_subrange || | |
5195 | *dbx_lookup_type (rangenums) == builtin_type_int)) | |
5196 | { | |
5197 | /* an unsigned type */ | |
5198 | #ifdef LONG_LONG | |
5199 | if (n3 == - sizeof (long long)) | |
5200 | return builtin_type_unsigned_long_long; | |
5201 | #endif | |
5202 | if (n3 == (unsigned int)~0L) | |
5203 | return builtin_type_unsigned_int; | |
5204 | if (n3 == (unsigned long)~0L) | |
5205 | return builtin_type_unsigned_long; | |
5206 | if (n3 == (unsigned short)~0L) | |
5207 | return builtin_type_unsigned_short; | |
5208 | if (n3 == (unsigned char)~0L) | |
5209 | return builtin_type_unsigned_char; | |
5210 | } | |
5211 | #ifdef LONG_LONG | |
5212 | else if (n3 == 0 && n2 == -sizeof (long long)) | |
5213 | return builtin_type_long_long; | |
5214 | #endif | |
5215 | else if (n2 == -n3 -1) | |
5216 | { | |
5217 | /* a signed type */ | |
5218 | if (n3 == (1 << (8 * sizeof (int) - 1)) - 1) | |
5219 | return builtin_type_int; | |
5220 | if (n3 == (1 << (8 * sizeof (long) - 1)) - 1) | |
5221 | return builtin_type_long; | |
5222 | if (n3 == (1 << (8 * sizeof (short) - 1)) - 1) | |
5223 | return builtin_type_short; | |
5224 | if (n3 == (1 << (8 * sizeof (char) - 1)) - 1) | |
5225 | return builtin_type_char; | |
5226 | } | |
5227 | ||
5228 | /* We have a real range type on our hands. Allocate space and | |
5229 | return a real pointer. */ | |
5230 | ||
5231 | /* At this point I don't have the faintest idea how to deal with | |
5232 | a self_subrange type; I'm going to assume that this is used | |
5233 | as an idiom, and that all of them are special cases. So . . . */ | |
5234 | if (self_subrange) | |
5235 | return error_type (pp); | |
5236 | ||
5237 | result_type = (struct type *) obstack_alloc (symbol_obstack, | |
5238 | sizeof (struct type)); | |
5239 | bzero (result_type, sizeof (struct type)); | |
5240 | ||
0c4d2cc2 JG |
5241 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; |
5242 | ||
5243 | TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums); | |
9bb30452 JG |
5244 | if (TYPE_TARGET_TYPE (result_type) == 0) { |
5245 | complain (&range_type_base_complaint, rangenums[1]); | |
5246 | TYPE_TARGET_TYPE (result_type) = builtin_type_int; | |
5247 | } | |
0c4d2cc2 JG |
5248 | |
5249 | TYPE_NFIELDS (result_type) = 2; | |
5250 | TYPE_FIELDS (result_type) = | |
5251 | (struct field *) obstack_alloc (symbol_obstack, | |
5252 | 2 * sizeof (struct field)); | |
5253 | bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field)); | |
5254 | TYPE_FIELD_BITPOS (result_type, 0) = n2; | |
5255 | TYPE_FIELD_BITPOS (result_type, 1) = n3; | |
bd5635a1 | 5256 | |
0c4d2cc2 JG |
5257 | #if 0 |
5258 | /* Note that TYPE_LENGTH (result_type) is just overridden a few | |
5259 | statements down. What do we really need here? */ | |
bd5635a1 RP |
5260 | /* We have to figure out how many bytes it takes to hold this |
5261 | range type. I'm going to assume that anything that is pushing | |
5262 | the bounds of a long was taken care of above. */ | |
0c4d2cc2 | 5263 | if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char)) |
bd5635a1 | 5264 | TYPE_LENGTH (result_type) = 1; |
0c4d2cc2 | 5265 | else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short)) |
bd5635a1 | 5266 | TYPE_LENGTH (result_type) = sizeof (short); |
0c4d2cc2 | 5267 | else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int)) |
bd5635a1 | 5268 | TYPE_LENGTH (result_type) = sizeof (int); |
0c4d2cc2 | 5269 | else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long)) |
bd5635a1 RP |
5270 | TYPE_LENGTH (result_type) = sizeof (long); |
5271 | else | |
5272 | /* Ranged type doesn't fit within known sizes. */ | |
0c4d2cc2 | 5273 | /* FIXME -- use "long long" here. */ |
bd5635a1 | 5274 | return error_type (pp); |
0c4d2cc2 | 5275 | #endif |
bd5635a1 RP |
5276 | |
5277 | TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type)); | |
bd5635a1 RP |
5278 | |
5279 | return result_type; | |
5280 | } | |
5281 | ||
5282 | /* Read a number from the string pointed to by *PP. | |
5283 | The value of *PP is advanced over the number. | |
5284 | If END is nonzero, the character that ends the | |
5285 | number must match END, or an error happens; | |
5286 | and that character is skipped if it does match. | |
5287 | If END is zero, *PP is left pointing to that character. */ | |
5288 | ||
5289 | static long | |
5290 | read_number (pp, end) | |
5291 | char **pp; | |
5292 | int end; | |
5293 | { | |
5294 | register char *p = *pp; | |
5295 | register long n = 0; | |
5296 | register int c; | |
5297 | int sign = 1; | |
5298 | ||
5299 | /* Handle an optional leading minus sign. */ | |
5300 | ||
5301 | if (*p == '-') | |
5302 | { | |
5303 | sign = -1; | |
5304 | p++; | |
5305 | } | |
5306 | ||
5307 | /* Read the digits, as far as they go. */ | |
5308 | ||
5309 | while ((c = *p++) >= '0' && c <= '9') | |
5310 | { | |
5311 | n *= 10; | |
5312 | n += c - '0'; | |
5313 | } | |
5314 | if (end) | |
5315 | { | |
5316 | if (c && c != end) | |
5317 | error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum); | |
5318 | } | |
5319 | else | |
5320 | --p; | |
5321 | ||
5322 | *pp = p; | |
5323 | return n * sign; | |
5324 | } | |
5325 | ||
5326 | /* Read in an argument list. This is a list of types, separated by commas | |
5327 | and terminated with END. Return the list of types read in, or (struct type | |
5328 | **)-1 if there is an error. */ | |
5329 | static struct type ** | |
5330 | read_args (pp, end) | |
5331 | char **pp; | |
5332 | int end; | |
5333 | { | |
5334 | struct type *types[1024], **rval; /* allow for fns of 1023 parameters */ | |
5335 | int n = 0; | |
5336 | ||
5337 | while (**pp != end) | |
5338 | { | |
5339 | if (**pp != ',') | |
5340 | /* Invalid argument list: no ','. */ | |
5341 | return (struct type **)-1; | |
5342 | *pp += 1; | |
5343 | ||
5344 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
5345 | if (**pp == '\\') | |
5346 | *pp = next_symbol_text (); | |
5347 | ||
5348 | types[n++] = read_type (pp); | |
5349 | } | |
5350 | *pp += 1; /* get past `end' (the ':' character) */ | |
5351 | ||
5352 | if (n == 1) | |
5353 | { | |
5354 | rval = (struct type **) xmalloc (2 * sizeof (struct type *)); | |
5355 | } | |
5356 | else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID) | |
5357 | { | |
5358 | rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *)); | |
5359 | bzero (rval + n, sizeof (struct type *)); | |
5360 | } | |
5361 | else | |
5362 | { | |
5363 | rval = (struct type **) xmalloc (n * sizeof (struct type *)); | |
5364 | } | |
5365 | bcopy (types, rval, n * sizeof (struct type *)); | |
5366 | return rval; | |
5367 | } | |
5368 | \f | |
5369 | /* Copy a pending list, used to record the contents of a common | |
5370 | block for later fixup. */ | |
5371 | static struct pending * | |
5372 | copy_pending (beg, begi, end) | |
5373 | struct pending *beg, *end; | |
5374 | int begi; | |
5375 | { | |
5376 | struct pending *new = 0; | |
5377 | struct pending *next; | |
5378 | ||
5379 | for (next = beg; next != 0 && (next != end || begi < end->nsyms); | |
5380 | next = next->next, begi = 0) | |
5381 | { | |
5382 | register int j; | |
5383 | for (j = begi; j < next->nsyms; j++) | |
5384 | add_symbol_to_list (next->symbol[j], &new); | |
5385 | } | |
5386 | return new; | |
5387 | } | |
5388 | ||
5389 | /* Add a common block's start address to the offset of each symbol | |
5390 | declared to be in it (by being between a BCOMM/ECOMM pair that uses | |
5391 | the common block name). */ | |
5392 | ||
5393 | static void | |
5394 | fix_common_block (sym, valu) | |
5395 | struct symbol *sym; | |
5396 | int valu; | |
5397 | { | |
5398 | struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym); | |
5399 | for ( ; next; next = next->next) | |
5400 | { | |
5401 | register int j; | |
5402 | for (j = next->nsyms - 1; j >= 0; j--) | |
5403 | SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu; | |
5404 | } | |
5405 | } | |
5406 | \f | |
5407 | /* Register our willingness to decode symbols for SunOS and a.out and | |
5408 | b.out files handled by BFD... */ | |
5409 | static struct sym_fns sunos_sym_fns = {"sunOs", 6, | |
9404978d | 5410 | dbx_new_init, dbx_symfile_init, dbx_symfile_read}; |
bd5635a1 RP |
5411 | |
5412 | static struct sym_fns aout_sym_fns = {"a.out", 5, | |
9404978d | 5413 | dbx_new_init, dbx_symfile_init, dbx_symfile_read}; |
bd5635a1 RP |
5414 | |
5415 | static struct sym_fns bout_sym_fns = {"b.out", 5, | |
9404978d | 5416 | dbx_new_init, dbx_symfile_init, dbx_symfile_read}; |
bd5635a1 RP |
5417 | |
5418 | void | |
5419 | _initialize_dbxread () | |
5420 | { | |
5421 | add_symtab_fns(&sunos_sym_fns); | |
5422 | add_symtab_fns(&aout_sym_fns); | |
5423 | add_symtab_fns(&bout_sym_fns); | |
5424 | ||
5425 | undef_types_allocated = 20; | |
5426 | undef_types_length = 0; | |
5427 | undef_types = (struct type **) xmalloc (undef_types_allocated * | |
5428 | sizeof (struct type *)); | |
5429 | } |