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