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