gdb-2.4+.aux.coff
[deliverable/binutils-gdb.git] / gdb / RCS / coffread.c,v
1 head 1.4;
2 access ;
3 symbols RMS-has:1.2;
4 locks ; strict;
5 comment @ * @;
6
7
8 1.4
9 date 88.06.08.23.13.40; author gnu; state Exp;
10 branches ;
11 next 1.3;
12
13 1.3
14 date 88.02.28.03.37.53; author gnu; state Exp;
15 branches ;
16 next 1.2;
17
18 1.2
19 date 88.01.26.05.02.32; author gnu; state Exp;
20 branches ;
21 next 1.1;
22
23 1.1
24 date 88.01.26.00.38.04; author gnu; state Exp;
25 branches ;
26 next ;
27
28
29 desc
30 @Original from RMS's work dirs on Wheaties
31 @
32
33
34 1.4
35 log
36 @Half reasonable reading of coff files. Problem was that it assumed
37 that a .text would show up sometime, and it never did. We have to close
38 out each source file's symtab as we hit the next one.
39 @
40 text
41 @/* Read coff symbol tables and convert to internal format, for GDB.
42 Design and support routines derived from dbxread.c, and UMAX COFF
43 specific routines written 9/1/87 by David D. Johnson, Brown University.
44 Revised 11/27/87 ddj@@cs.brown.edu
45 Copyright (C) 1987 Free Software Foundation, Inc.
46
47 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
48 WARRANTY. No author or distributor accepts responsibility to anyone
49 for the consequences of using it or for whether it serves any
50 particular purpose or works at all, unless he says so in writing.
51 Refer to the GDB General Public License for full details.
52
53 Everyone is granted permission to copy, modify and redistribute GDB,
54 but only under the conditions described in the GDB General Public
55 License. A copy of this license is supposed to have been given to you
56 along with GDB so you can know your rights and responsibilities. It
57 should be in a file named COPYING. Among other things, the copyright
58 notice and this notice must be preserved on all copies.
59
60 In other words, go ahead and share GDB, but don't try to stop
61 anyone else from sharing it farther. Help stamp out software hoarding!
62 */
63 \f
64 #include "defs.h"
65 #include "param.h"
66 #ifdef COFF_FORMAT
67 #include "initialize.h"
68 #include "symtab.h"
69
70 #include <a.out.h>
71 #include <stdio.h>
72 #include <obstack.h>
73 #include <sys/types.h>
74 #include <sys/param.h>
75 #include <sys/file.h>
76
77 static void add_symbol_to_list ();
78 static void read_coff_symtab ();
79 static void patch_opaque_types ();
80 static struct type *decode_function_type ();
81 static struct type *decode_type ();
82 static struct type *decode_base_type ();
83 static struct type *read_enum_type ();
84 static struct type *read_struct_type ();
85 static void finish_block ();
86 static struct blockvector *make_blockvector ();
87 static struct symbol *process_coff_symbol ();
88 static int init_stringtab ();
89 static void free_stringtab ();
90 static char *getfilename ();
91 static char *getsymname ();
92 static int init_lineno ();
93 static void enter_linenos ();
94
95 START_FILE
96
97 /* Name of source file whose symbol data we are now processing.
98 This comes from a symbol named ".file". */
99
100 static char *last_source_file;
101
102 /* Core address of start and end of text of current source file.
103 This comes from a ".text" symbol where x_nlinno > 0. */
104
105 static CORE_ADDR cur_src_start_addr;
106 static CORE_ADDR cur_src_end_addr;
107
108 /* End of the text segment of the executable file,
109 as found in the symbol _etext. */
110
111 static CORE_ADDR end_of_text_addr;
112
113 /* The addresses of the symbol table stream and number of symbols
114 of the object file we are reading (as copied into core). */
115
116 static FILE *nlist_stream_global;
117 static int nlist_nsyms_global;
118
119 /* The file and text section headers of the symbol file */
120
121 static FILHDR file_hdr;
122 static SCNHDR text_hdr;
123
124 /* The index in the symbol table of the last coff symbol that was processed. */
125
126 static int symnum;
127
128 /* Vector of types defined so far, indexed by their coff symnum. */
129
130 static struct typevector *type_vector;
131
132 /* Number of elements allocated for type_vector currently. */
133
134 static int type_vector_length;
135
136 /* Vector of line number information. */
137
138 static struct linetable *line_vector;
139
140 /* Index of next entry to go in line_vector_index. */
141
142 static int line_vector_index;
143
144 /* Last line number recorded in the line vector. */
145
146 static int prev_line_number;
147
148 /* Number of elements allocated for line_vector currently. */
149
150 static int line_vector_length;
151
152 /* Chain of typedefs of pointers to empty struct/union types.
153 They are chained thru the SYMBOL_VALUE. */
154
155 #define HASHSIZE 127
156 static struct symbol *opaque_type_chain[HASHSIZE];
157
158 /* Record the symbols defined for each context in a list.
159 We don't create a struct block for the context until we
160 know how long to make it. */
161
162 struct pending
163 {
164 struct pending *next;
165 struct symbol *symbol;
166 };
167
168 /* Here are the three lists that symbols are put on. */
169
170 struct pending *file_symbols; /* static at top level, and types */
171
172 struct pending *global_symbols; /* global functions and variables */
173
174 struct pending *local_symbols; /* everything local to lexical context */
175
176 /* List of unclosed lexical contexts
177 (that will become blocks, eventually). */
178
179 struct context_stack
180 {
181 struct context_stack *next;
182 struct pending *locals;
183 struct pending_block *old_blocks;
184 struct symbol *name;
185 CORE_ADDR start_addr;
186 int depth;
187 };
188
189 struct context_stack *context_stack;
190
191 /* Nonzero if within a function (so symbols should be local,
192 if nothing says specifically). */
193
194 int within_function;
195
196 /* List of blocks already made (lexical contexts already closed).
197 This is used at the end to make the blockvector. */
198
199 struct pending_block
200 {
201 struct pending_block *next;
202 struct block *block;
203 };
204
205 struct pending_block *pending_blocks;
206
207 extern CORE_ADDR first_object_file_end; /* From blockframe.c */
208
209 /* File name symbols were loaded from. */
210
211 static char *symfile;
212
213 int debug = 1;
214
215 \f
216 /* Look up a coff type-number index. Return the address of the slot
217 where the type for that index is stored.
218 The type-number is in INDEX.
219
220 This can be used for finding the type associated with that index
221 or for associating a new type with the index. */
222
223 static struct type **
224 coff_lookup_type (index)
225 register int index;
226 {
227 if (index >= type_vector_length)
228 {
229 type_vector_length *= 2;
230 type_vector = (struct typevector *)
231 xrealloc (type_vector, sizeof (struct typevector)
232 + type_vector_length * sizeof (struct type *));
233 bzero (&type_vector->type[type_vector_length / 2],
234 type_vector_length * sizeof (struct type *) / 2);
235 }
236 return &type_vector->type[index];
237 }
238
239 /* Make sure there is a type allocated for type number index
240 and return the type object.
241 This can create an empty (zeroed) type object. */
242
243 static struct type *
244 coff_alloc_type (index)
245 int index;
246 {
247 register struct type **type_addr = coff_lookup_type (index);
248 register struct type *type = *type_addr;
249
250 /* If we are referring to a type not known at all yet,
251 allocate an empty type for it.
252 We will fill it in later if we find out how. */
253 if (type == 0)
254 {
255 type = (struct type *) obstack_alloc (symbol_obstack,
256 sizeof (struct type));
257 bzero (type, sizeof (struct type));
258 *type_addr = type;
259 }
260 return type;
261 }
262 \f
263 /* maintain the lists of symbols and blocks */
264
265 /* Add a symbol to one of the lists of symbols. */
266 static void
267 add_symbol_to_list (symbol, listhead)
268 struct symbol *symbol;
269 struct pending **listhead;
270 {
271 register struct pending *link
272 = (struct pending *) xmalloc (sizeof (struct pending));
273
274 link->next = *listhead;
275 link->symbol = symbol;
276 *listhead = link;
277 }
278
279 /* Take one of the lists of symbols and make a block from it.
280 Put the block on the list of pending blocks. */
281
282 static void
283 finish_block (symbol, listhead, old_blocks, start, end)
284 struct symbol *symbol;
285 struct pending **listhead;
286 struct pending_block *old_blocks;
287 CORE_ADDR start, end;
288 {
289 register struct pending *next, *next1;
290 register struct block *block;
291 register struct pending_block *pblock;
292 struct pending_block *opblock;
293 register int i;
294
295 /* Count the length of the list of symbols. */
296
297 for (next = *listhead, i = 0; next; next = next->next, i++);
298
299 block = (struct block *) xmalloc (sizeof (struct block) + (i - 1) * sizeof (struct symbol *));
300
301 /* Copy the symbols into the block. */
302
303 BLOCK_NSYMS (block) = i;
304 for (next = *listhead; next; next = next->next
This page took 0.036134 seconds and 4 git commands to generate.