Commit | Line | Data |
---|---|---|
35f5886e | 1 | /* DWARF debugging format support for GDB. |
1ab3bf1b JG |
2 | Copyright (C) 1991, 1992 Free Software Foundation, Inc. |
3 | Written by Fred Fish at Cygnus Support. Portions based on dbxread.c, | |
35f5886e FF |
4 | mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port. |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
21 | ||
22 | /* | |
23 | ||
24 | FIXME: Figure out how to get the frame pointer register number in the | |
25 | execution environment of the target. Remove R_FP kludge | |
26 | ||
27 | FIXME: Add generation of dependencies list to partial symtab code. | |
28 | ||
29 | FIXME: Currently we ignore host/target byte ordering and integer size | |
30 | differences. Should remap data from external form to an internal form | |
31 | before trying to use it. | |
32 | ||
33 | FIXME: Resolve minor differences between what information we put in the | |
34 | partial symbol table and what dbxread puts in. For example, we don't yet | |
35 | put enum constants there. And dbxread seems to invent a lot of typedefs | |
36 | we never see. Use the new printpsym command to see the partial symbol table | |
37 | contents. | |
38 | ||
35f5886e FF |
39 | FIXME: Figure out a better way to tell gdb about the name of the function |
40 | contain the user's entry point (I.E. main()) | |
41 | ||
42 | FIXME: The current DWARF specification has a very strong bias towards | |
43 | machines with 32-bit integers, as it assumes that many attributes of the | |
44 | program (such as an address) will fit in such an integer. There are many | |
45 | references in the spec to things that are 2, 4, or 8 bytes long. Given that | |
46 | we will probably run into problems on machines where some of these assumptions | |
47 | are invalid (64-bit ints for example), we don't bother at this time to try to | |
48 | make this code more flexible and just use shorts, ints, and longs (and their | |
49 | sizes) where it seems appropriate. I.E. we use a short int to hold DWARF | |
50 | tags, and assume that the tag size in the file is the same as sizeof(short). | |
51 | ||
35f5886e FF |
52 | FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for |
53 | other things to work on, if you get bored. :-) | |
54 | ||
55 | */ | |
4d315a07 | 56 | |
35f5886e | 57 | #include <stdio.h> |
313fdead | 58 | #include <varargs.h> |
35f5886e FF |
59 | #include <fcntl.h> |
60 | ||
61 | #include "defs.h" | |
35f5886e FF |
62 | #include "bfd.h" |
63 | #include "symtab.h" | |
1ab3bf1b | 64 | #include "gdbtypes.h" |
35f5886e | 65 | #include "symfile.h" |
f5f0679a | 66 | #include "elf/dwarf.h" |
4d315a07 | 67 | #include "buildsym.h" |
35f5886e FF |
68 | |
69 | #ifdef MAINTENANCE /* Define to 1 to compile in some maintenance stuff */ | |
70 | #define SQUAWK(stuff) dwarfwarn stuff | |
71 | #else | |
72 | #define SQUAWK(stuff) | |
73 | #endif | |
74 | ||
75 | #ifndef R_FP /* FIXME */ | |
76 | #define R_FP 14 /* Kludge to get frame pointer register number */ | |
77 | #endif | |
78 | ||
79 | typedef unsigned int DIEREF; /* Reference to a DIE */ | |
80 | ||
4d315a07 FF |
81 | #ifndef GCC_PRODUCER |
82 | #define GCC_PRODUCER "GNU C " | |
83 | #endif | |
35f5886e FF |
84 | |
85 | #define STREQ(a,b) (strcmp(a,b)==0) | |
4d315a07 | 86 | #define STREQN(a,b,n) (strncmp(a,b,n)==0) |
35f5886e | 87 | |
768be6e1 FF |
88 | /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a |
89 | FORM_BLOCK2, and this is the value emitted by the AT&T compiler. | |
90 | However, the Issue 2 DWARF specification from AT&T defines it as | |
91 | a FORM_BLOCK4, as does the latest specification from UI/PLSIG. | |
92 | For backwards compatibility with the AT&T compiler produced executables | |
93 | we define AT_short_element_list for this variant. */ | |
94 | ||
95 | #define AT_short_element_list (0x00f0|FORM_BLOCK2) | |
96 | ||
97 | /* External variables referenced. */ | |
98 | ||
35f5886e FF |
99 | extern CORE_ADDR startup_file_start; /* From blockframe.c */ |
100 | extern CORE_ADDR startup_file_end; /* From blockframe.c */ | |
101 | extern CORE_ADDR entry_scope_lowpc; /* From blockframe.c */ | |
102 | extern CORE_ADDR entry_scope_highpc; /* From blockframc.c */ | |
103 | extern CORE_ADDR main_scope_lowpc; /* From blockframe.c */ | |
104 | extern CORE_ADDR main_scope_highpc; /* From blockframc.c */ | |
105 | extern int info_verbose; /* From main.c; nonzero => verbose */ | |
106 | ||
107 | ||
108 | /* The DWARF debugging information consists of two major pieces, | |
109 | one is a block of DWARF Information Entries (DIE's) and the other | |
110 | is a line number table. The "struct dieinfo" structure contains | |
111 | the information for a single DIE, the one currently being processed. | |
112 | ||
113 | In order to make it easier to randomly access the attribute fields | |
114 | of the current DIE, which are specifically unordered within the DIE | |
115 | each DIE is scanned and an instance of the "struct dieinfo" | |
116 | structure is initialized. | |
117 | ||
118 | Initialization is done in two levels. The first, done by basicdieinfo(), | |
119 | just initializes those fields that are vital to deciding whether or not | |
120 | to use this DIE, how to skip past it, etc. The second, done by the | |
121 | function completedieinfo(), fills in the rest of the information. | |
122 | ||
123 | Attributes which have block forms are not interpreted at the time | |
124 | the DIE is scanned, instead we just save pointers to the start | |
125 | of their value fields. | |
126 | ||
127 | Some fields have a flag <name>_p that is set when the value of the | |
128 | field is valid (I.E. we found a matching attribute in the DIE). Since | |
129 | we may want to test for the presence of some attributes in the DIE, | |
2d6186f4 | 130 | such as AT_low_pc, without restricting the values of the field, |
35f5886e FF |
131 | we need someway to note that we found such an attribute. |
132 | ||
133 | */ | |
134 | ||
135 | typedef char BLOCK; | |
136 | ||
137 | struct dieinfo { | |
138 | char * die; /* Pointer to the raw DIE data */ | |
139 | long dielength; /* Length of the raw DIE data */ | |
140 | DIEREF dieref; /* Offset of this DIE */ | |
141 | short dietag; /* Tag for this DIE */ | |
142 | long at_padding; | |
143 | long at_sibling; | |
144 | BLOCK * at_location; | |
145 | char * at_name; | |
146 | unsigned short at_fund_type; | |
147 | BLOCK * at_mod_fund_type; | |
148 | long at_user_def_type; | |
149 | BLOCK * at_mod_u_d_type; | |
150 | short at_ordering; | |
151 | BLOCK * at_subscr_data; | |
152 | long at_byte_size; | |
153 | short at_bit_offset; | |
154 | long at_bit_size; | |
35f5886e FF |
155 | BLOCK * at_element_list; |
156 | long at_stmt_list; | |
157 | long at_low_pc; | |
158 | long at_high_pc; | |
159 | long at_language; | |
160 | long at_member; | |
161 | long at_discr; | |
162 | BLOCK * at_discr_value; | |
163 | short at_visibility; | |
164 | long at_import; | |
165 | BLOCK * at_string_length; | |
166 | char * at_comp_dir; | |
167 | char * at_producer; | |
35f5886e | 168 | long at_frame_base; |
35f5886e FF |
169 | long at_start_scope; |
170 | long at_stride_size; | |
171 | long at_src_info; | |
172 | short at_prototyped; | |
2d6186f4 FF |
173 | unsigned int has_at_low_pc:1; |
174 | unsigned int has_at_stmt_list:1; | |
768be6e1 | 175 | unsigned int short_element_list:1; |
35f5886e FF |
176 | }; |
177 | ||
178 | static int diecount; /* Approximate count of dies for compilation unit */ | |
179 | static struct dieinfo *curdie; /* For warnings and such */ | |
180 | ||
181 | static char *dbbase; /* Base pointer to dwarf info */ | |
182 | static int dbroff; /* Relative offset from start of .debug section */ | |
183 | static char *lnbase; /* Base pointer to line section */ | |
184 | static int isreg; /* Kludge to identify register variables */ | |
a5bd5ba6 | 185 | static int offreg; /* Kludge to identify basereg references */ |
35f5886e FF |
186 | |
187 | static CORE_ADDR baseaddr; /* Add to each symbol value */ | |
188 | ||
189 | /* Each partial symbol table entry contains a pointer to private data for the | |
190 | read_symtab() function to use when expanding a partial symbol table entry | |
191 | to a full symbol table entry. For DWARF debugging info, this data is | |
192 | contained in the following structure and macros are provided for easy | |
193 | access to the members given a pointer to a partial symbol table entry. | |
194 | ||
195 | dbfoff Always the absolute file offset to the start of the ".debug" | |
196 | section for the file containing the DIE's being accessed. | |
197 | ||
198 | dbroff Relative offset from the start of the ".debug" access to the | |
199 | first DIE to be accessed. When building the partial symbol | |
200 | table, this value will be zero since we are accessing the | |
201 | entire ".debug" section. When expanding a partial symbol | |
202 | table entry, this value will be the offset to the first | |
203 | DIE for the compilation unit containing the symbol that | |
204 | triggers the expansion. | |
205 | ||
206 | dblength The size of the chunk of DIE's being examined, in bytes. | |
207 | ||
208 | lnfoff The absolute file offset to the line table fragment. Ignored | |
209 | when building partial symbol tables, but used when expanding | |
210 | them, and contains the absolute file offset to the fragment | |
211 | of the ".line" section containing the line numbers for the | |
212 | current compilation unit. | |
213 | */ | |
214 | ||
215 | struct dwfinfo { | |
216 | int dbfoff; /* Absolute file offset to start of .debug section */ | |
217 | int dbroff; /* Relative offset from start of .debug section */ | |
218 | int dblength; /* Size of the chunk of DIE's being examined */ | |
219 | int lnfoff; /* Absolute file offset to line table fragment */ | |
220 | }; | |
221 | ||
222 | #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff) | |
223 | #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff) | |
224 | #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength) | |
225 | #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff) | |
226 | ||
4d315a07 FF |
227 | /* The generic symbol table building routines have separate lists for |
228 | file scope symbols and all all other scopes (local scopes). So | |
229 | we need to select the right one to pass to add_symbol_to_list(). | |
230 | We do it by keeping a pointer to the correct list in list_in_scope. | |
35f5886e | 231 | |
4d315a07 FF |
232 | FIXME: The original dwarf code just treated the file scope as the first |
233 | local scope, and all other local scopes as nested local scopes, and worked | |
234 | fine. Check to see if we really need to distinguish these in buildsym.c */ | |
35f5886e | 235 | |
99140c31 | 236 | struct pending **list_in_scope = &file_symbols; |
35f5886e FF |
237 | |
238 | /* DIES which have user defined types or modified user defined types refer to | |
239 | other DIES for the type information. Thus we need to associate the offset | |
240 | of a DIE for a user defined type with a pointer to the type information. | |
241 | ||
242 | Originally this was done using a simple but expensive algorithm, with an | |
243 | array of unsorted structures, each containing an offset/type-pointer pair. | |
244 | This array was scanned linearly each time a lookup was done. The result | |
245 | was that gdb was spending over half it's startup time munging through this | |
246 | array of pointers looking for a structure that had the right offset member. | |
247 | ||
248 | The second attempt used the same array of structures, but the array was | |
249 | sorted using qsort each time a new offset/type was recorded, and a binary | |
250 | search was used to find the type pointer for a given DIE offset. This was | |
251 | even slower, due to the overhead of sorting the array each time a new | |
252 | offset/type pair was entered. | |
253 | ||
254 | The third attempt uses a fixed size array of type pointers, indexed by a | |
255 | value derived from the DIE offset. Since the minimum DIE size is 4 bytes, | |
256 | we can divide any DIE offset by 4 to obtain a unique index into this fixed | |
257 | size array. Since each element is a 4 byte pointer, it takes exactly as | |
258 | much memory to hold this array as to hold the DWARF info for a given | |
259 | compilation unit. But it gets freed as soon as we are done with it. */ | |
260 | ||
261 | static struct type **utypes; /* Pointer to array of user type pointers */ | |
262 | static int numutypes; /* Max number of user type pointers */ | |
263 | ||
264 | /* Forward declarations of static functions so we don't have to worry | |
1ab3bf1b JG |
265 | about ordering within this file. */ |
266 | ||
267 | static void | |
268 | add_enum_psymbol PARAMS ((struct dieinfo *, struct objfile *)); | |
269 | ||
270 | static void | |
271 | read_file_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *)); | |
35f5886e | 272 | |
58050209 | 273 | static void |
1ab3bf1b | 274 | read_func_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *)); |
35f5886e FF |
275 | |
276 | static void | |
1ab3bf1b JG |
277 | read_lexical_block_scope PARAMS ((struct dieinfo *, char *, char *, |
278 | struct objfile *)); | |
35f5886e FF |
279 | |
280 | static void | |
1ab3bf1b | 281 | dwarfwarn (); |
4d315a07 | 282 | |
35f5886e | 283 | static void |
1ab3bf1b | 284 | scan_partial_symbols PARAMS ((char *, char *, struct objfile *)); |
35f5886e | 285 | |
35f5886e | 286 | static void |
1ab3bf1b JG |
287 | scan_compilation_units PARAMS ((char *, char *, char *, unsigned int, |
288 | unsigned int, struct objfile *)); | |
35f5886e FF |
289 | |
290 | static void | |
1ab3bf1b | 291 | add_partial_symbol PARAMS ((struct dieinfo *, struct objfile *)); |
35f5886e FF |
292 | |
293 | static void | |
1ab3bf1b | 294 | init_psymbol_list PARAMS ((struct objfile *, int)); |
35f5886e FF |
295 | |
296 | static void | |
1ab3bf1b | 297 | basicdieinfo PARAMS ((struct dieinfo *, char *)); |
35f5886e FF |
298 | |
299 | static void | |
1ab3bf1b JG |
300 | completedieinfo PARAMS ((struct dieinfo *)); |
301 | ||
302 | static void | |
303 | dwarf_psymtab_to_symtab PARAMS ((struct partial_symtab *)); | |
304 | ||
305 | static void | |
306 | psymtab_to_symtab_1 PARAMS ((struct partial_symtab *)); | |
35f5886e FF |
307 | |
308 | static struct symtab * | |
1ab3bf1b | 309 | read_ofile_symtab PARAMS ((struct partial_symtab *)); |
35f5886e FF |
310 | |
311 | static void | |
1ab3bf1b | 312 | process_dies PARAMS ((char *, char *, struct objfile *)); |
35f5886e FF |
313 | |
314 | static void | |
1ab3bf1b JG |
315 | read_structure_scope PARAMS ((struct dieinfo *, char *, char *, |
316 | struct objfile *)); | |
35f5886e FF |
317 | |
318 | static struct type * | |
1ab3bf1b | 319 | decode_array_element_type PARAMS ((char *, char *)); |
35f5886e FF |
320 | |
321 | static struct type * | |
1ab3bf1b | 322 | decode_subscr_data PARAMS ((char *, char *)); |
35f5886e FF |
323 | |
324 | static void | |
1ab3bf1b | 325 | dwarf_read_array_type PARAMS ((struct dieinfo *)); |
35f5886e | 326 | |
9e4c1921 | 327 | static void |
1ab3bf1b | 328 | read_tag_pointer_type PARAMS ((struct dieinfo *dip)); |
9e4c1921 | 329 | |
35f5886e | 330 | static void |
1ab3bf1b | 331 | read_subroutine_type PARAMS ((struct dieinfo *, char *, char *)); |
35f5886e FF |
332 | |
333 | static void | |
1ab3bf1b | 334 | read_enumeration PARAMS ((struct dieinfo *, char *, char *, struct objfile *)); |
35f5886e FF |
335 | |
336 | static struct type * | |
1ab3bf1b | 337 | struct_type PARAMS ((struct dieinfo *, char *, char *, struct objfile *)); |
35f5886e FF |
338 | |
339 | static struct type * | |
1ab3bf1b | 340 | enum_type PARAMS ((struct dieinfo *, struct objfile *)); |
35f5886e | 341 | |
35f5886e | 342 | static void |
1ab3bf1b | 343 | decode_line_numbers PARAMS ((char *)); |
35f5886e FF |
344 | |
345 | static struct type * | |
1ab3bf1b | 346 | decode_die_type PARAMS ((struct dieinfo *)); |
35f5886e FF |
347 | |
348 | static struct type * | |
1ab3bf1b | 349 | decode_mod_fund_type PARAMS ((char *)); |
35f5886e FF |
350 | |
351 | static struct type * | |
1ab3bf1b | 352 | decode_mod_u_d_type PARAMS ((char *)); |
35f5886e FF |
353 | |
354 | static struct type * | |
1ab3bf1b | 355 | decode_modified_type PARAMS ((unsigned char *, unsigned int, int)); |
35f5886e FF |
356 | |
357 | static struct type * | |
1ab3bf1b | 358 | decode_fund_type PARAMS ((unsigned int)); |
35f5886e FF |
359 | |
360 | static char * | |
1ab3bf1b | 361 | create_name PARAMS ((char *, struct obstack *)); |
35f5886e | 362 | |
35f5886e | 363 | static struct type * |
1ab3bf1b | 364 | lookup_utype PARAMS ((DIEREF)); |
35f5886e FF |
365 | |
366 | static struct type * | |
1ab3bf1b | 367 | alloc_utype PARAMS ((DIEREF, struct type *)); |
35f5886e FF |
368 | |
369 | static struct symbol * | |
1ab3bf1b | 370 | new_symbol PARAMS ((struct dieinfo *, struct objfile *)); |
35f5886e FF |
371 | |
372 | static int | |
1ab3bf1b | 373 | locval PARAMS ((char *)); |
35f5886e FF |
374 | |
375 | static void | |
1ab3bf1b JG |
376 | record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type, |
377 | struct objfile *)); | |
35f5886e FF |
378 | |
379 | /* | |
380 | ||
381 | GLOBAL FUNCTION | |
382 | ||
383 | dwarf_build_psymtabs -- build partial symtabs from DWARF debug info | |
384 | ||
385 | SYNOPSIS | |
386 | ||
387 | void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr, | |
388 | int mainline, unsigned int dbfoff, unsigned int dbsize, | |
a048c8f5 JG |
389 | unsigned int lnoffset, unsigned int lnsize, |
390 | struct objfile *objfile) | |
35f5886e FF |
391 | |
392 | DESCRIPTION | |
393 | ||
394 | This function is called upon to build partial symtabs from files | |
395 | containing DIE's (Dwarf Information Entries) and DWARF line numbers. | |
396 | ||
397 | It is passed a file descriptor for an open file containing the DIES | |
398 | and line number information, the corresponding filename for that | |
399 | file, a base address for relocating the symbols, a flag indicating | |
400 | whether or not this debugging information is from a "main symbol | |
401 | table" rather than a shared library or dynamically linked file, | |
402 | and file offset/size pairs for the DIE information and line number | |
403 | information. | |
404 | ||
405 | RETURNS | |
406 | ||
407 | No return value. | |
408 | ||
409 | */ | |
410 | ||
411 | void | |
1ab3bf1b JG |
412 | dwarf_build_psymtabs (desc, filename, addr, mainline, dbfoff, dbsize, |
413 | lnoffset, lnsize, objfile) | |
414 | int desc; | |
415 | char *filename; | |
416 | CORE_ADDR addr; | |
417 | int mainline; | |
418 | unsigned int dbfoff; | |
419 | unsigned int dbsize; | |
420 | unsigned int lnoffset; | |
421 | unsigned int lnsize; | |
422 | struct objfile *objfile; | |
35f5886e FF |
423 | { |
424 | struct cleanup *back_to; | |
425 | ||
426 | dbbase = xmalloc (dbsize); | |
427 | dbroff = 0; | |
428 | if ((lseek (desc, dbfoff, 0) != dbfoff) || | |
429 | (read (desc, dbbase, dbsize) != dbsize)) | |
430 | { | |
431 | free (dbbase); | |
432 | error ("can't read DWARF data from '%s'", filename); | |
433 | } | |
434 | back_to = make_cleanup (free, dbbase); | |
435 | ||
436 | /* If we are reinitializing, or if we have never loaded syms yet, init. | |
437 | Since we have no idea how many DIES we are looking at, we just guess | |
438 | some arbitrary value. */ | |
439 | ||
1ab3bf1b | 440 | if (mainline || objfile->global_psymbols.size == 0 || objfile->static_psymbols.size == 0) |
35f5886e | 441 | { |
1ab3bf1b | 442 | init_psymbol_list (objfile, 1024); |
35f5886e FF |
443 | } |
444 | ||
f8b76e70 | 445 | /* From this point on, we don't need to pass mainline around, so zap |
4d315a07 | 446 | baseaddr to zero if we don't need relocation. */ |
f8b76e70 FF |
447 | |
448 | if (mainline) | |
449 | { | |
4d315a07 FF |
450 | baseaddr = 0; |
451 | } | |
452 | else | |
453 | { | |
454 | baseaddr = addr; | |
f8b76e70 FF |
455 | } |
456 | ||
35f5886e FF |
457 | /* Follow the compilation unit sibling chain, building a partial symbol |
458 | table entry for each one. Save enough information about each compilation | |
459 | unit to locate the full DWARF information later. */ | |
460 | ||
4d315a07 | 461 | scan_compilation_units (filename, dbbase, dbbase + dbsize, |
a048c8f5 | 462 | dbfoff, lnoffset, objfile); |
35f5886e | 463 | |
35f5886e FF |
464 | do_cleanups (back_to); |
465 | } | |
466 | ||
467 | ||
468 | /* | |
469 | ||
470 | LOCAL FUNCTION | |
471 | ||
1ab3bf1b | 472 | record_minimal_symbol -- add entry to gdb's minimal symbol table |
35f5886e FF |
473 | |
474 | SYNOPSIS | |
475 | ||
1ab3bf1b JG |
476 | static void record_minimal_symbol (char *name, CORE_ADDR address, |
477 | enum minimal_symbol_type ms_type, | |
478 | struct objfile *objfile) | |
35f5886e FF |
479 | |
480 | DESCRIPTION | |
481 | ||
482 | Given a pointer to the name of a symbol that should be added to the | |
1ab3bf1b | 483 | minimal symbol table, and the address associated with that |
35f5886e | 484 | symbol, records this information for later use in building the |
1ab3bf1b | 485 | minimal symbol table. |
35f5886e | 486 | |
35f5886e FF |
487 | */ |
488 | ||
489 | static void | |
1ab3bf1b JG |
490 | record_minimal_symbol (name, address, ms_type, objfile) |
491 | char *name; | |
492 | CORE_ADDR address; | |
493 | enum minimal_symbol_type ms_type; | |
494 | struct objfile *objfile; | |
35f5886e | 495 | { |
1ab3bf1b JG |
496 | name = obsavestring (name, strlen (name), &objfile -> symbol_obstack); |
497 | prim_record_minimal_symbol (name, address, ms_type); | |
35f5886e FF |
498 | } |
499 | ||
500 | /* | |
501 | ||
502 | LOCAL FUNCTION | |
503 | ||
504 | dwarfwarn -- issue a DWARF related warning | |
505 | ||
506 | DESCRIPTION | |
507 | ||
508 | Issue warnings about DWARF related things that aren't serious enough | |
509 | to warrant aborting with an error, but should not be ignored either. | |
510 | This includes things like detectable corruption in DIE's, missing | |
511 | DIE's, unimplemented features, etc. | |
512 | ||
513 | In general, running across tags or attributes that we don't recognize | |
514 | is not considered to be a problem and we should not issue warnings | |
515 | about such. | |
516 | ||
517 | NOTES | |
518 | ||
519 | We mostly follow the example of the error() routine, but without | |
520 | returning to command level. It is arguable about whether warnings | |
521 | should be issued at all, and if so, where they should go (stdout or | |
522 | stderr). | |
523 | ||
524 | We assume that curdie is valid and contains at least the basic | |
525 | information for the DIE where the problem was noticed. | |
526 | */ | |
527 | ||
528 | static void | |
313fdead JG |
529 | dwarfwarn (va_alist) |
530 | va_dcl | |
35f5886e FF |
531 | { |
532 | va_list ap; | |
313fdead | 533 | char *fmt; |
35f5886e | 534 | |
313fdead JG |
535 | va_start (ap); |
536 | fmt = va_arg (ap, char *); | |
35f5886e FF |
537 | warning_setup (); |
538 | fprintf (stderr, "DWARF warning (ref 0x%x): ", curdie -> dieref); | |
539 | if (curdie -> at_name) | |
540 | { | |
541 | fprintf (stderr, "'%s': ", curdie -> at_name); | |
542 | } | |
543 | vfprintf (stderr, fmt, ap); | |
544 | fprintf (stderr, "\n"); | |
545 | fflush (stderr); | |
546 | va_end (ap); | |
547 | } | |
4d315a07 | 548 | |
35f5886e FF |
549 | /* |
550 | ||
551 | LOCAL FUNCTION | |
552 | ||
553 | read_lexical_block_scope -- process all dies in a lexical block | |
554 | ||
555 | SYNOPSIS | |
556 | ||
557 | static void read_lexical_block_scope (struct dieinfo *dip, | |
558 | char *thisdie, char *enddie) | |
559 | ||
560 | DESCRIPTION | |
561 | ||
562 | Process all the DIES contained within a lexical block scope. | |
563 | Start a new scope, process the dies, and then close the scope. | |
564 | ||
565 | */ | |
566 | ||
567 | static void | |
1ab3bf1b JG |
568 | read_lexical_block_scope (dip, thisdie, enddie, objfile) |
569 | struct dieinfo *dip; | |
570 | char *thisdie; | |
571 | char *enddie; | |
572 | struct objfile *objfile; | |
35f5886e | 573 | { |
4d315a07 FF |
574 | register struct context_stack *new; |
575 | ||
576 | (void) push_context (0, dip -> at_low_pc); | |
a048c8f5 | 577 | process_dies (thisdie + dip -> dielength, enddie, objfile); |
4d315a07 FF |
578 | new = pop_context (); |
579 | if (local_symbols != NULL) | |
580 | { | |
581 | finish_block (0, &local_symbols, new -> old_blocks, new -> start_addr, | |
1ab3bf1b | 582 | dip -> at_high_pc, objfile); |
4d315a07 FF |
583 | } |
584 | local_symbols = new -> locals; | |
35f5886e FF |
585 | } |
586 | ||
587 | /* | |
588 | ||
589 | LOCAL FUNCTION | |
590 | ||
591 | lookup_utype -- look up a user defined type from die reference | |
592 | ||
593 | SYNOPSIS | |
594 | ||
595 | static type *lookup_utype (DIEREF dieref) | |
596 | ||
597 | DESCRIPTION | |
598 | ||
599 | Given a DIE reference, lookup the user defined type associated with | |
600 | that DIE, if it has been registered already. If not registered, then | |
601 | return NULL. Alloc_utype() can be called to register an empty | |
602 | type for this reference, which will be filled in later when the | |
603 | actual referenced DIE is processed. | |
604 | */ | |
605 | ||
606 | static struct type * | |
1ab3bf1b JG |
607 | lookup_utype (dieref) |
608 | DIEREF dieref; | |
35f5886e FF |
609 | { |
610 | struct type *type = NULL; | |
611 | int utypeidx; | |
612 | ||
613 | utypeidx = (dieref - dbroff) / 4; | |
614 | if ((utypeidx < 0) || (utypeidx >= numutypes)) | |
615 | { | |
616 | dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref); | |
617 | } | |
618 | else | |
619 | { | |
620 | type = *(utypes + utypeidx); | |
621 | } | |
622 | return (type); | |
623 | } | |
624 | ||
625 | ||
626 | /* | |
627 | ||
628 | LOCAL FUNCTION | |
629 | ||
630 | alloc_utype -- add a user defined type for die reference | |
631 | ||
632 | SYNOPSIS | |
633 | ||
634 | static type *alloc_utype (DIEREF dieref, struct type *utypep) | |
635 | ||
636 | DESCRIPTION | |
637 | ||
638 | Given a die reference DIEREF, and a possible pointer to a user | |
639 | defined type UTYPEP, register that this reference has a user | |
640 | defined type and either use the specified type in UTYPEP or | |
641 | make a new empty type that will be filled in later. | |
642 | ||
643 | We should only be called after calling lookup_utype() to verify that | |
644 | there is not currently a type registered for DIEREF. | |
645 | */ | |
646 | ||
647 | static struct type * | |
1ab3bf1b JG |
648 | alloc_utype (dieref, utypep) |
649 | DIEREF dieref; | |
650 | struct type *utypep; | |
35f5886e FF |
651 | { |
652 | struct type **typep; | |
653 | int utypeidx; | |
654 | ||
655 | utypeidx = (dieref - dbroff) / 4; | |
656 | typep = utypes + utypeidx; | |
657 | if ((utypeidx < 0) || (utypeidx >= numutypes)) | |
658 | { | |
1ab3bf1b | 659 | utypep = lookup_fundamental_type (current_objfile, FT_INTEGER); |
35f5886e FF |
660 | dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref); |
661 | } | |
662 | else if (*typep != NULL) | |
663 | { | |
664 | utypep = *typep; | |
665 | SQUAWK (("internal error: dup user type allocation")); | |
666 | } | |
667 | else | |
668 | { | |
669 | if (utypep == NULL) | |
670 | { | |
671 | utypep = (struct type *) | |
1ab3bf1b JG |
672 | obstack_alloc (¤t_objfile -> type_obstack, |
673 | sizeof (struct type)); | |
35f5886e | 674 | (void) memset (utypep, 0, sizeof (struct type)); |
1ab3bf1b | 675 | TYPE_OBJFILE (utypep) = current_objfile; |
35f5886e FF |
676 | } |
677 | *typep = utypep; | |
678 | } | |
679 | return (utypep); | |
680 | } | |
681 | ||
682 | /* | |
683 | ||
684 | LOCAL FUNCTION | |
685 | ||
686 | decode_die_type -- return a type for a specified die | |
687 | ||
688 | SYNOPSIS | |
689 | ||
690 | static struct type *decode_die_type (struct dieinfo *dip) | |
691 | ||
692 | DESCRIPTION | |
693 | ||
694 | Given a pointer to a die information structure DIP, decode the | |
695 | type of the die and return a pointer to the decoded type. All | |
696 | dies without specific types default to type int. | |
697 | */ | |
698 | ||
699 | static struct type * | |
1ab3bf1b JG |
700 | decode_die_type (dip) |
701 | struct dieinfo *dip; | |
35f5886e FF |
702 | { |
703 | struct type *type = NULL; | |
704 | ||
705 | if (dip -> at_fund_type != 0) | |
706 | { | |
707 | type = decode_fund_type (dip -> at_fund_type); | |
708 | } | |
709 | else if (dip -> at_mod_fund_type != NULL) | |
710 | { | |
711 | type = decode_mod_fund_type (dip -> at_mod_fund_type); | |
712 | } | |
713 | else if (dip -> at_user_def_type) | |
714 | { | |
715 | if ((type = lookup_utype (dip -> at_user_def_type)) == NULL) | |
716 | { | |
717 | type = alloc_utype (dip -> at_user_def_type, NULL); | |
718 | } | |
719 | } | |
720 | else if (dip -> at_mod_u_d_type) | |
721 | { | |
722 | type = decode_mod_u_d_type (dip -> at_mod_u_d_type); | |
723 | } | |
724 | else | |
725 | { | |
1ab3bf1b | 726 | type = lookup_fundamental_type (current_objfile, FT_INTEGER); |
35f5886e FF |
727 | } |
728 | return (type); | |
729 | } | |
730 | ||
731 | /* | |
732 | ||
733 | LOCAL FUNCTION | |
734 | ||
735 | struct_type -- compute and return the type for a struct or union | |
736 | ||
737 | SYNOPSIS | |
738 | ||
739 | static struct type *struct_type (struct dieinfo *dip, char *thisdie, | |
8b5b6fae | 740 | char *enddie, struct objfile *objfile) |
35f5886e FF |
741 | |
742 | DESCRIPTION | |
743 | ||
744 | Given pointer to a die information structure for a die which | |
715cafcb FF |
745 | defines a union or structure (and MUST define one or the other), |
746 | and pointers to the raw die data that define the range of dies which | |
747 | define the members, compute and return the user defined type for the | |
748 | structure or union. | |
35f5886e FF |
749 | */ |
750 | ||
751 | static struct type * | |
1ab3bf1b JG |
752 | struct_type (dip, thisdie, enddie, objfile) |
753 | struct dieinfo *dip; | |
754 | char *thisdie; | |
755 | char *enddie; | |
756 | struct objfile *objfile; | |
35f5886e FF |
757 | { |
758 | struct type *type; | |
759 | struct nextfield { | |
760 | struct nextfield *next; | |
761 | struct field field; | |
762 | }; | |
763 | struct nextfield *list = NULL; | |
764 | struct nextfield *new; | |
765 | int nfields = 0; | |
766 | int n; | |
767 | char *tpart1; | |
35f5886e | 768 | struct dieinfo mbr; |
8b5b6fae | 769 | char *nextdie; |
35f5886e FF |
770 | |
771 | if ((type = lookup_utype (dip -> dieref)) == NULL) | |
772 | { | |
5edf98d7 | 773 | /* No forward references created an empty type, so install one now */ |
35f5886e FF |
774 | type = alloc_utype (dip -> dieref, NULL); |
775 | } | |
a3723a43 | 776 | INIT_CPLUS_SPECIFIC(type); |
715cafcb | 777 | switch (dip -> dietag) |
35f5886e | 778 | { |
715cafcb | 779 | case TAG_structure_type: |
5edf98d7 | 780 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
715cafcb FF |
781 | tpart1 = "struct"; |
782 | break; | |
783 | case TAG_union_type: | |
784 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
785 | tpart1 = "union"; | |
786 | break; | |
787 | default: | |
788 | /* Should never happen */ | |
789 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
790 | tpart1 = "???"; | |
791 | SQUAWK (("missing structure or union tag")); | |
792 | break; | |
35f5886e | 793 | } |
5edf98d7 FF |
794 | /* Some compilers try to be helpful by inventing "fake" names for |
795 | anonymous enums, structures, and unions, like "~0fake" or ".0fake". | |
796 | Thanks, but no thanks... */ | |
715cafcb FF |
797 | if (dip -> at_name != NULL |
798 | && *dip -> at_name != '~' | |
799 | && *dip -> at_name != '.') | |
35f5886e | 800 | { |
1ab3bf1b JG |
801 | TYPE_NAME (type) = obconcat (¤t_objfile -> type_obstack, |
802 | tpart1, " ", dip -> at_name); | |
35f5886e | 803 | } |
715cafcb | 804 | if (dip -> at_byte_size != 0) |
35f5886e | 805 | { |
35f5886e | 806 | TYPE_LENGTH (type) = dip -> at_byte_size; |
35f5886e | 807 | } |
35f5886e FF |
808 | thisdie += dip -> dielength; |
809 | while (thisdie < enddie) | |
810 | { | |
811 | basicdieinfo (&mbr, thisdie); | |
812 | completedieinfo (&mbr); | |
813 | if (mbr.dielength <= sizeof (long)) | |
814 | { | |
815 | break; | |
816 | } | |
8b5b6fae FF |
817 | else if (mbr.at_sibling != 0) |
818 | { | |
819 | nextdie = dbbase + mbr.at_sibling - dbroff; | |
820 | } | |
821 | else | |
822 | { | |
823 | nextdie = thisdie + mbr.dielength; | |
824 | } | |
35f5886e FF |
825 | switch (mbr.dietag) |
826 | { | |
827 | case TAG_member: | |
828 | /* Get space to record the next field's data. */ | |
829 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
830 | new -> next = list; | |
831 | list = new; | |
832 | /* Save the data. */ | |
833 | list -> field.name = savestring (mbr.at_name, strlen (mbr.at_name)); | |
834 | list -> field.type = decode_die_type (&mbr); | |
835 | list -> field.bitpos = 8 * locval (mbr.at_location); | |
836 | list -> field.bitsize = 0; | |
837 | nfields++; | |
838 | break; | |
839 | default: | |
8b5b6fae | 840 | process_dies (thisdie, nextdie, objfile); |
35f5886e FF |
841 | break; |
842 | } | |
8b5b6fae | 843 | thisdie = nextdie; |
35f5886e | 844 | } |
5edf98d7 FF |
845 | /* Now create the vector of fields, and record how big it is. We may |
846 | not even have any fields, if this DIE was generated due to a reference | |
847 | to an anonymous structure or union. In this case, TYPE_FLAG_STUB is | |
848 | set, which clues gdb in to the fact that it needs to search elsewhere | |
849 | for the full structure definition. */ | |
850 | if (nfields == 0) | |
35f5886e | 851 | { |
5edf98d7 FF |
852 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; |
853 | } | |
854 | else | |
855 | { | |
856 | TYPE_NFIELDS (type) = nfields; | |
857 | TYPE_FIELDS (type) = (struct field *) | |
1ab3bf1b JG |
858 | obstack_alloc (¤t_objfile -> type_obstack, |
859 | sizeof (struct field) * nfields); | |
5edf98d7 FF |
860 | /* Copy the saved-up fields into the field vector. */ |
861 | for (n = nfields; list; list = list -> next) | |
862 | { | |
863 | TYPE_FIELD (type, --n) = list -> field; | |
864 | } | |
865 | } | |
35f5886e FF |
866 | return (type); |
867 | } | |
868 | ||
869 | /* | |
870 | ||
871 | LOCAL FUNCTION | |
872 | ||
873 | read_structure_scope -- process all dies within struct or union | |
874 | ||
875 | SYNOPSIS | |
876 | ||
877 | static void read_structure_scope (struct dieinfo *dip, | |
8b5b6fae | 878 | char *thisdie, char *enddie, struct objfile *objfile) |
35f5886e FF |
879 | |
880 | DESCRIPTION | |
881 | ||
882 | Called when we find the DIE that starts a structure or union | |
883 | scope (definition) to process all dies that define the members | |
884 | of the structure or union. DIP is a pointer to the die info | |
885 | struct for the DIE that names the structure or union. | |
886 | ||
887 | NOTES | |
888 | ||
889 | Note that we need to call struct_type regardless of whether or not | |
84ce6717 FF |
890 | the DIE has an at_name attribute, since it might be an anonymous |
891 | structure or union. This gets the type entered into our set of | |
892 | user defined types. | |
893 | ||
894 | However, if the structure is incomplete (an opaque struct/union) | |
895 | then suppress creating a symbol table entry for it since gdb only | |
896 | wants to find the one with the complete definition. Note that if | |
897 | it is complete, we just call new_symbol, which does it's own | |
898 | checking about whether the struct/union is anonymous or not (and | |
899 | suppresses creating a symbol table entry itself). | |
900 | ||
35f5886e FF |
901 | */ |
902 | ||
903 | static void | |
1ab3bf1b JG |
904 | read_structure_scope (dip, thisdie, enddie, objfile) |
905 | struct dieinfo *dip; | |
906 | char *thisdie; | |
907 | char *enddie; | |
908 | struct objfile *objfile; | |
35f5886e FF |
909 | { |
910 | struct type *type; | |
911 | struct symbol *sym; | |
912 | ||
8b5b6fae | 913 | type = struct_type (dip, thisdie, enddie, objfile); |
84ce6717 | 914 | if (!(TYPE_FLAGS (type) & TYPE_FLAG_STUB)) |
35f5886e | 915 | { |
1ab3bf1b | 916 | if ((sym = new_symbol (dip, objfile)) != NULL) |
84ce6717 FF |
917 | { |
918 | SYMBOL_TYPE (sym) = type; | |
919 | } | |
35f5886e FF |
920 | } |
921 | } | |
922 | ||
923 | /* | |
924 | ||
925 | LOCAL FUNCTION | |
926 | ||
927 | decode_array_element_type -- decode type of the array elements | |
928 | ||
929 | SYNOPSIS | |
930 | ||
931 | static struct type *decode_array_element_type (char *scan, char *end) | |
932 | ||
933 | DESCRIPTION | |
934 | ||
935 | As the last step in decoding the array subscript information for an | |
936 | array DIE, we need to decode the type of the array elements. We are | |
937 | passed a pointer to this last part of the subscript information and | |
938 | must return the appropriate type. If the type attribute is not | |
939 | recognized, just warn about the problem and return type int. | |
940 | */ | |
941 | ||
942 | static struct type * | |
1ab3bf1b JG |
943 | decode_array_element_type (scan, end) |
944 | char *scan; | |
945 | char *end; | |
35f5886e FF |
946 | { |
947 | struct type *typep; | |
948 | short attribute; | |
949 | DIEREF dieref; | |
950 | unsigned short fundtype; | |
951 | ||
952 | (void) memcpy (&attribute, scan, sizeof (short)); | |
953 | scan += sizeof (short); | |
954 | switch (attribute) | |
955 | { | |
956 | case AT_fund_type: | |
957 | (void) memcpy (&fundtype, scan, sizeof (short)); | |
958 | typep = decode_fund_type (fundtype); | |
959 | break; | |
960 | case AT_mod_fund_type: | |
961 | typep = decode_mod_fund_type (scan); | |
962 | break; | |
963 | case AT_user_def_type: | |
964 | (void) memcpy (&dieref, scan, sizeof (DIEREF)); | |
965 | if ((typep = lookup_utype (dieref)) == NULL) | |
966 | { | |
967 | typep = alloc_utype (dieref, NULL); | |
968 | } | |
969 | break; | |
970 | case AT_mod_u_d_type: | |
971 | typep = decode_mod_u_d_type (scan); | |
972 | break; | |
973 | default: | |
974 | SQUAWK (("bad array element type attribute 0x%x", attribute)); | |
1ab3bf1b | 975 | typep = lookup_fundamental_type (current_objfile, FT_INTEGER); |
35f5886e FF |
976 | break; |
977 | } | |
978 | return (typep); | |
979 | } | |
980 | ||
981 | /* | |
982 | ||
983 | LOCAL FUNCTION | |
984 | ||
985 | decode_subscr_data -- decode array subscript and element type data | |
986 | ||
987 | SYNOPSIS | |
988 | ||
989 | static struct type *decode_subscr_data (char *scan, char *end) | |
990 | ||
991 | DESCRIPTION | |
992 | ||
993 | The array subscripts and the data type of the elements of an | |
994 | array are described by a list of data items, stored as a block | |
995 | of contiguous bytes. There is a data item describing each array | |
996 | dimension, and a final data item describing the element type. | |
997 | The data items are ordered the same as their appearance in the | |
998 | source (I.E. leftmost dimension first, next to leftmost second, | |
999 | etc). | |
1000 | ||
1001 | We are passed a pointer to the start of the block of bytes | |
1002 | containing the data items, and a pointer to the first byte past | |
1003 | the data. This function decodes the data and returns a type. | |
1004 | ||
1005 | BUGS | |
1006 | FIXME: This code only implements the forms currently used | |
1007 | by the AT&T and GNU C compilers. | |
1008 | ||
1009 | The end pointer is supplied for error checking, maybe we should | |
1010 | use it for that... | |
1011 | */ | |
1012 | ||
1013 | static struct type * | |
1ab3bf1b JG |
1014 | decode_subscr_data (scan, end) |
1015 | char *scan; | |
1016 | char *end; | |
35f5886e FF |
1017 | { |
1018 | struct type *typep = NULL; | |
1019 | struct type *nexttype; | |
1020 | int format; | |
1021 | short fundtype; | |
1022 | long lowbound; | |
1023 | long highbound; | |
1024 | ||
1025 | format = *scan++; | |
1026 | switch (format) | |
1027 | { | |
1028 | case FMT_ET: | |
1029 | typep = decode_array_element_type (scan, end); | |
1030 | break; | |
1031 | case FMT_FT_C_C: | |
1032 | (void) memcpy (&fundtype, scan, sizeof (short)); | |
1033 | scan += sizeof (short); | |
1034 | if (fundtype != FT_integer && fundtype != FT_signed_integer | |
1035 | && fundtype != FT_unsigned_integer) | |
1036 | { | |
1037 | SQUAWK (("array subscripts must be integral types, not type 0x%x", | |
1038 | fundtype)); | |
1039 | } | |
1040 | else | |
1041 | { | |
1042 | (void) memcpy (&lowbound, scan, sizeof (long)); | |
1043 | scan += sizeof (long); | |
1044 | (void) memcpy (&highbound, scan, sizeof (long)); | |
1045 | scan += sizeof (long); | |
1046 | nexttype = decode_subscr_data (scan, end); | |
1047 | if (nexttype != NULL) | |
1048 | { | |
1049 | typep = (struct type *) | |
1ab3bf1b JG |
1050 | obstack_alloc (¤t_objfile -> type_obstack, |
1051 | sizeof (struct type)); | |
35f5886e | 1052 | (void) memset (typep, 0, sizeof (struct type)); |
1ab3bf1b | 1053 | TYPE_OBJFILE (typep) = current_objfile; |
35f5886e FF |
1054 | TYPE_CODE (typep) = TYPE_CODE_ARRAY; |
1055 | TYPE_LENGTH (typep) = TYPE_LENGTH (nexttype); | |
1056 | TYPE_LENGTH (typep) *= lowbound + highbound + 1; | |
1057 | TYPE_TARGET_TYPE (typep) = nexttype; | |
1058 | } | |
1059 | } | |
1060 | break; | |
1061 | case FMT_FT_C_X: | |
1062 | case FMT_FT_X_C: | |
1063 | case FMT_FT_X_X: | |
1064 | case FMT_UT_C_C: | |
1065 | case FMT_UT_C_X: | |
1066 | case FMT_UT_X_C: | |
1067 | case FMT_UT_X_X: | |
1068 | SQUAWK (("array subscript format 0x%x not handled yet", format)); | |
1069 | break; | |
1070 | default: | |
1071 | SQUAWK (("unknown array subscript format %x", format)); | |
1072 | break; | |
1073 | } | |
1074 | return (typep); | |
1075 | } | |
1076 | ||
1077 | /* | |
1078 | ||
1079 | LOCAL FUNCTION | |
1080 | ||
4d315a07 | 1081 | dwarf_read_array_type -- read TAG_array_type DIE |
35f5886e FF |
1082 | |
1083 | SYNOPSIS | |
1084 | ||
4d315a07 | 1085 | static void dwarf_read_array_type (struct dieinfo *dip) |
35f5886e FF |
1086 | |
1087 | DESCRIPTION | |
1088 | ||
1089 | Extract all information from a TAG_array_type DIE and add to | |
1090 | the user defined type vector. | |
1091 | */ | |
1092 | ||
1093 | static void | |
1ab3bf1b JG |
1094 | dwarf_read_array_type (dip) |
1095 | struct dieinfo *dip; | |
35f5886e FF |
1096 | { |
1097 | struct type *type; | |
af213624 | 1098 | struct type *utype; |
35f5886e FF |
1099 | char *sub; |
1100 | char *subend; | |
1101 | short temp; | |
1102 | ||
1103 | if (dip -> at_ordering != ORD_row_major) | |
1104 | { | |
1105 | /* FIXME: Can gdb even handle column major arrays? */ | |
1106 | SQUAWK (("array not row major; not handled correctly")); | |
1107 | } | |
1108 | if ((sub = dip -> at_subscr_data) != NULL) | |
1109 | { | |
1110 | (void) memcpy (&temp, sub, sizeof (short)); | |
1111 | subend = sub + sizeof (short) + temp; | |
1112 | sub += sizeof (short); | |
1113 | type = decode_subscr_data (sub, subend); | |
1114 | if (type == NULL) | |
1115 | { | |
af213624 FF |
1116 | if ((utype = lookup_utype (dip -> dieref)) == NULL) |
1117 | { | |
1118 | utype = alloc_utype (dip -> dieref, NULL); | |
1119 | } | |
1120 | TYPE_CODE (utype) = TYPE_CODE_ARRAY; | |
1ab3bf1b JG |
1121 | TYPE_TARGET_TYPE (utype) = |
1122 | lookup_fundamental_type (current_objfile, FT_INTEGER); | |
af213624 | 1123 | TYPE_LENGTH (utype) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype)); |
35f5886e FF |
1124 | } |
1125 | else | |
1126 | { | |
af213624 FF |
1127 | if ((utype = lookup_utype (dip -> dieref)) == NULL) |
1128 | { | |
1129 | (void) alloc_utype (dip -> dieref, type); | |
1130 | } | |
1131 | else | |
1132 | { | |
1133 | TYPE_CODE (utype) = TYPE_CODE_ARRAY; | |
1134 | TYPE_LENGTH (utype) = TYPE_LENGTH (type); | |
1135 | TYPE_TARGET_TYPE (utype) = TYPE_TARGET_TYPE (type); | |
1136 | } | |
35f5886e FF |
1137 | } |
1138 | } | |
1139 | } | |
1140 | ||
1141 | /* | |
1142 | ||
9e4c1921 FF |
1143 | LOCAL FUNCTION |
1144 | ||
1145 | read_tag_pointer_type -- read TAG_pointer_type DIE | |
1146 | ||
1147 | SYNOPSIS | |
1148 | ||
1149 | static void read_tag_pointer_type (struct dieinfo *dip) | |
1150 | ||
1151 | DESCRIPTION | |
1152 | ||
1153 | Extract all information from a TAG_pointer_type DIE and add to | |
1154 | the user defined type vector. | |
1155 | */ | |
1156 | ||
1157 | static void | |
1ab3bf1b JG |
1158 | read_tag_pointer_type (dip) |
1159 | struct dieinfo *dip; | |
9e4c1921 FF |
1160 | { |
1161 | struct type *type; | |
1162 | struct type *utype; | |
1163 | char *sub; | |
1164 | char *subend; | |
1165 | short temp; | |
1166 | ||
1167 | type = decode_die_type (dip); | |
1168 | if ((utype = lookup_utype (dip -> dieref)) == NULL) | |
1169 | { | |
1170 | utype = lookup_pointer_type (type); | |
1171 | (void) alloc_utype (dip -> dieref, utype); | |
1172 | } | |
1173 | else | |
1174 | { | |
1175 | TYPE_TARGET_TYPE (utype) = type; | |
1176 | TYPE_POINTER_TYPE (type) = utype; | |
1177 | ||
1178 | /* We assume the machine has only one representation for pointers! */ | |
1179 | /* FIXME: This confuses host<->target data representations, and is a | |
1180 | poor assumption besides. */ | |
1181 | ||
1182 | TYPE_LENGTH (utype) = sizeof (char *); | |
1183 | TYPE_CODE (utype) = TYPE_CODE_PTR; | |
1184 | } | |
1185 | } | |
1186 | ||
1187 | /* | |
1188 | ||
35f5886e FF |
1189 | LOCAL FUNCTION |
1190 | ||
1191 | read_subroutine_type -- process TAG_subroutine_type dies | |
1192 | ||
1193 | SYNOPSIS | |
1194 | ||
1195 | static void read_subroutine_type (struct dieinfo *dip, char thisdie, | |
1196 | char *enddie) | |
1197 | ||
1198 | DESCRIPTION | |
1199 | ||
1200 | Handle DIES due to C code like: | |
1201 | ||
1202 | struct foo { | |
1203 | int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE) | |
1204 | int b; | |
1205 | }; | |
1206 | ||
1207 | NOTES | |
1208 | ||
1209 | The parameter DIES are currently ignored. See if gdb has a way to | |
1210 | include this info in it's type system, and decode them if so. Is | |
1211 | this what the type structure's "arg_types" field is for? (FIXME) | |
1212 | */ | |
1213 | ||
1214 | static void | |
1ab3bf1b JG |
1215 | read_subroutine_type (dip, thisdie, enddie) |
1216 | struct dieinfo *dip; | |
1217 | char *thisdie; | |
1218 | char *enddie; | |
35f5886e | 1219 | { |
af213624 FF |
1220 | struct type *type; /* Type that this function returns */ |
1221 | struct type *ftype; /* Function that returns above type */ | |
35f5886e | 1222 | |
af213624 FF |
1223 | /* Decode the type that this subroutine returns */ |
1224 | ||
35f5886e | 1225 | type = decode_die_type (dip); |
af213624 FF |
1226 | |
1227 | /* Check to see if we already have a partially constructed user | |
1228 | defined type for this DIE, from a forward reference. */ | |
1229 | ||
1230 | if ((ftype = lookup_utype (dip -> dieref)) == NULL) | |
1231 | { | |
1232 | /* This is the first reference to one of these types. Make | |
1233 | a new one and place it in the user defined types. */ | |
1234 | ftype = lookup_function_type (type); | |
1235 | (void) alloc_utype (dip -> dieref, ftype); | |
1236 | } | |
1237 | else | |
1238 | { | |
1239 | /* We have an existing partially constructed type, so bash it | |
1240 | into the correct type. */ | |
1241 | TYPE_TARGET_TYPE (ftype) = type; | |
1242 | TYPE_FUNCTION_TYPE (type) = ftype; | |
1243 | TYPE_LENGTH (ftype) = 1; | |
1244 | TYPE_CODE (ftype) = TYPE_CODE_FUNC; | |
1245 | } | |
35f5886e FF |
1246 | } |
1247 | ||
1248 | /* | |
1249 | ||
1250 | LOCAL FUNCTION | |
1251 | ||
1252 | read_enumeration -- process dies which define an enumeration | |
1253 | ||
1254 | SYNOPSIS | |
1255 | ||
1256 | static void read_enumeration (struct dieinfo *dip, char *thisdie, | |
1ab3bf1b | 1257 | char *enddie, struct objfile *objfile) |
35f5886e FF |
1258 | |
1259 | DESCRIPTION | |
1260 | ||
1261 | Given a pointer to a die which begins an enumeration, process all | |
1262 | the dies that define the members of the enumeration. | |
1263 | ||
1264 | NOTES | |
1265 | ||
1266 | Note that we need to call enum_type regardless of whether or not we | |
1267 | have a symbol, since we might have an enum without a tag name (thus | |
1268 | no symbol for the tagname). | |
1269 | */ | |
1270 | ||
1271 | static void | |
1ab3bf1b JG |
1272 | read_enumeration (dip, thisdie, enddie, objfile) |
1273 | struct dieinfo *dip; | |
1274 | char *thisdie; | |
1275 | char *enddie; | |
1276 | struct objfile *objfile; | |
35f5886e FF |
1277 | { |
1278 | struct type *type; | |
1279 | struct symbol *sym; | |
1280 | ||
1ab3bf1b JG |
1281 | type = enum_type (dip, objfile); |
1282 | if ((sym = new_symbol (dip, objfile)) != NULL) | |
35f5886e FF |
1283 | { |
1284 | SYMBOL_TYPE (sym) = type; | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | /* | |
1289 | ||
1290 | LOCAL FUNCTION | |
1291 | ||
1292 | enum_type -- decode and return a type for an enumeration | |
1293 | ||
1294 | SYNOPSIS | |
1295 | ||
1ab3bf1b | 1296 | static type *enum_type (struct dieinfo *dip, struct objfile *objfile) |
35f5886e FF |
1297 | |
1298 | DESCRIPTION | |
1299 | ||
1300 | Given a pointer to a die information structure for the die which | |
1301 | starts an enumeration, process all the dies that define the members | |
1302 | of the enumeration and return a type pointer for the enumeration. | |
98618bf7 | 1303 | |
715cafcb FF |
1304 | At the same time, for each member of the enumeration, create a |
1305 | symbol for it with namespace VAR_NAMESPACE and class LOC_CONST, | |
1306 | and give it the type of the enumeration itself. | |
1307 | ||
1308 | NOTES | |
1309 | ||
98618bf7 FF |
1310 | Note that the DWARF specification explicitly mandates that enum |
1311 | constants occur in reverse order from the source program order, | |
1312 | for "consistency" and because this ordering is easier for many | |
1ab3bf1b | 1313 | compilers to generate. (Draft 6, sec 3.8.5, Enumeration type |
715cafcb FF |
1314 | Entries). Because gdb wants to see the enum members in program |
1315 | source order, we have to ensure that the order gets reversed while | |
98618bf7 | 1316 | we are processing them. |
35f5886e FF |
1317 | */ |
1318 | ||
1319 | static struct type * | |
1ab3bf1b JG |
1320 | enum_type (dip, objfile) |
1321 | struct dieinfo *dip; | |
1322 | struct objfile *objfile; | |
35f5886e FF |
1323 | { |
1324 | struct type *type; | |
1325 | struct nextfield { | |
1326 | struct nextfield *next; | |
1327 | struct field field; | |
1328 | }; | |
1329 | struct nextfield *list = NULL; | |
1330 | struct nextfield *new; | |
1331 | int nfields = 0; | |
1332 | int n; | |
35f5886e FF |
1333 | char *scan; |
1334 | char *listend; | |
768be6e1 FF |
1335 | long ltemp; |
1336 | short stemp; | |
715cafcb | 1337 | struct symbol *sym; |
35f5886e FF |
1338 | |
1339 | if ((type = lookup_utype (dip -> dieref)) == NULL) | |
1340 | { | |
84ce6717 | 1341 | /* No forward references created an empty type, so install one now */ |
35f5886e FF |
1342 | type = alloc_utype (dip -> dieref, NULL); |
1343 | } | |
1344 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
84ce6717 FF |
1345 | /* Some compilers try to be helpful by inventing "fake" names for |
1346 | anonymous enums, structures, and unions, like "~0fake" or ".0fake". | |
1347 | Thanks, but no thanks... */ | |
715cafcb FF |
1348 | if (dip -> at_name != NULL |
1349 | && *dip -> at_name != '~' | |
1350 | && *dip -> at_name != '.') | |
35f5886e | 1351 | { |
1ab3bf1b JG |
1352 | TYPE_NAME (type) = obconcat (¤t_objfile -> type_obstack, "enum", |
1353 | " ", dip -> at_name); | |
35f5886e | 1354 | } |
715cafcb | 1355 | if (dip -> at_byte_size != 0) |
35f5886e FF |
1356 | { |
1357 | TYPE_LENGTH (type) = dip -> at_byte_size; | |
35f5886e | 1358 | } |
35f5886e FF |
1359 | if ((scan = dip -> at_element_list) != NULL) |
1360 | { | |
768be6e1 FF |
1361 | if (dip -> short_element_list) |
1362 | { | |
1363 | (void) memcpy (&stemp, scan, sizeof (stemp)); | |
1364 | listend = scan + stemp + sizeof (stemp); | |
1365 | scan += sizeof (stemp); | |
1366 | } | |
1367 | else | |
1368 | { | |
1369 | (void) memcpy (<emp, scan, sizeof (ltemp)); | |
1370 | listend = scan + ltemp + sizeof (ltemp); | |
1371 | scan += sizeof (ltemp); | |
1372 | } | |
35f5886e FF |
1373 | while (scan < listend) |
1374 | { | |
1375 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1376 | new -> next = list; | |
1377 | list = new; | |
1378 | list -> field.type = NULL; | |
1379 | list -> field.bitsize = 0; | |
1380 | (void) memcpy (&list -> field.bitpos, scan, sizeof (long)); | |
1381 | scan += sizeof (long); | |
1382 | list -> field.name = savestring (scan, strlen (scan)); | |
1383 | scan += strlen (scan) + 1; | |
1384 | nfields++; | |
715cafcb | 1385 | /* Handcraft a new symbol for this enum member. */ |
1ab3bf1b | 1386 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, |
715cafcb FF |
1387 | sizeof (struct symbol)); |
1388 | (void) memset (sym, 0, sizeof (struct symbol)); | |
1ab3bf1b | 1389 | SYMBOL_NAME (sym) = create_name (list -> field.name, &objfile->symbol_obstack); |
715cafcb FF |
1390 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
1391 | SYMBOL_CLASS (sym) = LOC_CONST; | |
1392 | SYMBOL_TYPE (sym) = type; | |
1393 | SYMBOL_VALUE (sym) = list -> field.bitpos; | |
4d315a07 | 1394 | add_symbol_to_list (sym, list_in_scope); |
35f5886e | 1395 | } |
84ce6717 FF |
1396 | /* Now create the vector of fields, and record how big it is. This is |
1397 | where we reverse the order, by pulling the members of the list in | |
1398 | reverse order from how they were inserted. If we have no fields | |
1399 | (this is apparently possible in C++) then skip building a field | |
1400 | vector. */ | |
1401 | if (nfields > 0) | |
1402 | { | |
1403 | TYPE_NFIELDS (type) = nfields; | |
1404 | TYPE_FIELDS (type) = (struct field *) | |
1ab3bf1b | 1405 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) * nfields); |
84ce6717 FF |
1406 | /* Copy the saved-up fields into the field vector. */ |
1407 | for (n = 0; (n < nfields) && (list != NULL); list = list -> next) | |
1408 | { | |
1409 | TYPE_FIELD (type, n++) = list -> field; | |
1410 | } | |
1411 | } | |
35f5886e | 1412 | } |
35f5886e FF |
1413 | return (type); |
1414 | } | |
1415 | ||
1416 | /* | |
1417 | ||
1418 | LOCAL FUNCTION | |
1419 | ||
1420 | read_func_scope -- process all dies within a function scope | |
1421 | ||
35f5886e FF |
1422 | DESCRIPTION |
1423 | ||
1424 | Process all dies within a given function scope. We are passed | |
1425 | a die information structure pointer DIP for the die which | |
1426 | starts the function scope, and pointers into the raw die data | |
1427 | that define the dies within the function scope. | |
1428 | ||
1429 | For now, we ignore lexical block scopes within the function. | |
1430 | The problem is that AT&T cc does not define a DWARF lexical | |
1431 | block scope for the function itself, while gcc defines a | |
1432 | lexical block scope for the function. We need to think about | |
1433 | how to handle this difference, or if it is even a problem. | |
1434 | (FIXME) | |
1435 | */ | |
1436 | ||
1437 | static void | |
1ab3bf1b JG |
1438 | read_func_scope (dip, thisdie, enddie, objfile) |
1439 | struct dieinfo *dip; | |
1440 | char *thisdie; | |
1441 | char *enddie; | |
1442 | struct objfile *objfile; | |
35f5886e | 1443 | { |
4d315a07 | 1444 | register struct context_stack *new; |
35f5886e FF |
1445 | |
1446 | if (entry_point >= dip -> at_low_pc && entry_point < dip -> at_high_pc) | |
1447 | { | |
1448 | entry_scope_lowpc = dip -> at_low_pc; | |
1449 | entry_scope_highpc = dip -> at_high_pc; | |
1450 | } | |
4d315a07 | 1451 | if (STREQ (dip -> at_name, "main")) /* FIXME: hardwired name */ |
35f5886e FF |
1452 | { |
1453 | main_scope_lowpc = dip -> at_low_pc; | |
1454 | main_scope_highpc = dip -> at_high_pc; | |
1455 | } | |
4d315a07 | 1456 | new = push_context (0, dip -> at_low_pc); |
1ab3bf1b | 1457 | new -> name = new_symbol (dip, objfile); |
4d315a07 | 1458 | list_in_scope = &local_symbols; |
a048c8f5 | 1459 | process_dies (thisdie + dip -> dielength, enddie, objfile); |
4d315a07 FF |
1460 | new = pop_context (); |
1461 | /* Make a block for the local symbols within. */ | |
1462 | finish_block (new -> name, &local_symbols, new -> old_blocks, | |
1ab3bf1b | 1463 | new -> start_addr, dip -> at_high_pc, objfile); |
4d315a07 | 1464 | list_in_scope = &file_symbols; |
35f5886e FF |
1465 | } |
1466 | ||
1467 | /* | |
1468 | ||
1469 | LOCAL FUNCTION | |
1470 | ||
1471 | read_file_scope -- process all dies within a file scope | |
1472 | ||
35f5886e FF |
1473 | DESCRIPTION |
1474 | ||
1475 | Process all dies within a given file scope. We are passed a | |
1476 | pointer to the die information structure for the die which | |
1477 | starts the file scope, and pointers into the raw die data which | |
1478 | mark the range of dies within the file scope. | |
1479 | ||
1480 | When the partial symbol table is built, the file offset for the line | |
1481 | number table for each compilation unit is saved in the partial symbol | |
1482 | table entry for that compilation unit. As the symbols for each | |
1483 | compilation unit are read, the line number table is read into memory | |
1484 | and the variable lnbase is set to point to it. Thus all we have to | |
1485 | do is use lnbase to access the line number table for the current | |
1486 | compilation unit. | |
1487 | */ | |
1488 | ||
1489 | static void | |
1ab3bf1b JG |
1490 | read_file_scope (dip, thisdie, enddie, objfile) |
1491 | struct dieinfo *dip; | |
1492 | char *thisdie; | |
1493 | char *enddie; | |
1494 | struct objfile *objfile; | |
35f5886e FF |
1495 | { |
1496 | struct cleanup *back_to; | |
4d315a07 | 1497 | struct symtab *symtab; |
35f5886e FF |
1498 | |
1499 | if (entry_point >= dip -> at_low_pc && entry_point < dip -> at_high_pc) | |
1500 | { | |
1501 | startup_file_start = dip -> at_low_pc; | |
1502 | startup_file_end = dip -> at_high_pc; | |
1503 | } | |
4d315a07 FF |
1504 | if (dip -> at_producer != NULL) |
1505 | { | |
1506 | processing_gcc_compilation = | |
1507 | STREQN (dip -> at_producer, GCC_PRODUCER, strlen (GCC_PRODUCER)); | |
1508 | } | |
35f5886e FF |
1509 | numutypes = (enddie - thisdie) / 4; |
1510 | utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *)); | |
1511 | back_to = make_cleanup (free, utypes); | |
1512 | (void) memset (utypes, 0, numutypes * sizeof (struct type *)); | |
4d315a07 | 1513 | start_symtab (dip -> at_name, NULL, dip -> at_low_pc); |
35f5886e | 1514 | decode_line_numbers (lnbase); |
a048c8f5 | 1515 | process_dies (thisdie + dip -> dielength, enddie, objfile); |
4d315a07 FF |
1516 | symtab = end_symtab (dip -> at_high_pc, 0, 0, objfile); |
1517 | /* FIXME: The following may need to be expanded for other languages */ | |
1518 | switch (dip -> at_language) | |
1519 | { | |
1520 | case LANG_C89: | |
1521 | case LANG_C: | |
1522 | symtab -> language = language_c; | |
1523 | break; | |
1524 | case LANG_C_PLUS_PLUS: | |
1525 | symtab -> language = language_cplus; | |
1526 | break; | |
1527 | default: | |
1528 | ; | |
1529 | } | |
35f5886e FF |
1530 | do_cleanups (back_to); |
1531 | utypes = NULL; | |
1532 | numutypes = 0; | |
1533 | } | |
1534 | ||
1535 | /* | |
1536 | ||
35f5886e FF |
1537 | LOCAL FUNCTION |
1538 | ||
1539 | process_dies -- process a range of DWARF Information Entries | |
1540 | ||
1541 | SYNOPSIS | |
1542 | ||
8b5b6fae FF |
1543 | static void process_dies (char *thisdie, char *enddie, |
1544 | struct objfile *objfile) | |
35f5886e FF |
1545 | |
1546 | DESCRIPTION | |
1547 | ||
1548 | Process all DIE's in a specified range. May be (and almost | |
1549 | certainly will be) called recursively. | |
1550 | */ | |
1551 | ||
1552 | static void | |
1ab3bf1b JG |
1553 | process_dies (thisdie, enddie, objfile) |
1554 | char *thisdie; | |
1555 | char *enddie; | |
1556 | struct objfile *objfile; | |
35f5886e FF |
1557 | { |
1558 | char *nextdie; | |
1559 | struct dieinfo di; | |
1560 | ||
1561 | while (thisdie < enddie) | |
1562 | { | |
1563 | basicdieinfo (&di, thisdie); | |
1564 | if (di.dielength < sizeof (long)) | |
1565 | { | |
1566 | break; | |
1567 | } | |
1568 | else if (di.dietag == TAG_padding) | |
1569 | { | |
1570 | nextdie = thisdie + di.dielength; | |
1571 | } | |
1572 | else | |
1573 | { | |
1574 | completedieinfo (&di); | |
1575 | if (di.at_sibling != 0) | |
1576 | { | |
1577 | nextdie = dbbase + di.at_sibling - dbroff; | |
1578 | } | |
1579 | else | |
1580 | { | |
1581 | nextdie = thisdie + di.dielength; | |
1582 | } | |
1583 | switch (di.dietag) | |
1584 | { | |
1585 | case TAG_compile_unit: | |
a048c8f5 | 1586 | read_file_scope (&di, thisdie, nextdie, objfile); |
35f5886e FF |
1587 | break; |
1588 | case TAG_global_subroutine: | |
1589 | case TAG_subroutine: | |
2d6186f4 | 1590 | if (di.has_at_low_pc) |
35f5886e | 1591 | { |
a048c8f5 | 1592 | read_func_scope (&di, thisdie, nextdie, objfile); |
35f5886e FF |
1593 | } |
1594 | break; | |
1595 | case TAG_lexical_block: | |
a048c8f5 | 1596 | read_lexical_block_scope (&di, thisdie, nextdie, objfile); |
35f5886e FF |
1597 | break; |
1598 | case TAG_structure_type: | |
1599 | case TAG_union_type: | |
8b5b6fae | 1600 | read_structure_scope (&di, thisdie, nextdie, objfile); |
35f5886e FF |
1601 | break; |
1602 | case TAG_enumeration_type: | |
1ab3bf1b | 1603 | read_enumeration (&di, thisdie, nextdie, objfile); |
35f5886e FF |
1604 | break; |
1605 | case TAG_subroutine_type: | |
1606 | read_subroutine_type (&di, thisdie, nextdie); | |
1607 | break; | |
1608 | case TAG_array_type: | |
4d315a07 | 1609 | dwarf_read_array_type (&di); |
35f5886e | 1610 | break; |
9e4c1921 FF |
1611 | case TAG_pointer_type: |
1612 | read_tag_pointer_type (&di); | |
1613 | break; | |
35f5886e | 1614 | default: |
1ab3bf1b | 1615 | (void) new_symbol (&di, objfile); |
35f5886e FF |
1616 | break; |
1617 | } | |
1618 | } | |
1619 | thisdie = nextdie; | |
1620 | } | |
1621 | } | |
1622 | ||
1623 | /* | |
1624 | ||
35f5886e FF |
1625 | LOCAL FUNCTION |
1626 | ||
1627 | decode_line_numbers -- decode a line number table fragment | |
1628 | ||
1629 | SYNOPSIS | |
1630 | ||
1631 | static void decode_line_numbers (char *tblscan, char *tblend, | |
1632 | long length, long base, long line, long pc) | |
1633 | ||
1634 | DESCRIPTION | |
1635 | ||
1636 | Translate the DWARF line number information to gdb form. | |
1637 | ||
1638 | The ".line" section contains one or more line number tables, one for | |
1639 | each ".line" section from the objects that were linked. | |
1640 | ||
1641 | The AT_stmt_list attribute for each TAG_source_file entry in the | |
1642 | ".debug" section contains the offset into the ".line" section for the | |
1643 | start of the table for that file. | |
1644 | ||
1645 | The table itself has the following structure: | |
1646 | ||
1647 | <table length><base address><source statement entry> | |
1648 | 4 bytes 4 bytes 10 bytes | |
1649 | ||
1650 | The table length is the total size of the table, including the 4 bytes | |
1651 | for the length information. | |
1652 | ||
1653 | The base address is the address of the first instruction generated | |
1654 | for the source file. | |
1655 | ||
1656 | Each source statement entry has the following structure: | |
1657 | ||
1658 | <line number><statement position><address delta> | |
1659 | 4 bytes 2 bytes 4 bytes | |
1660 | ||
1661 | The line number is relative to the start of the file, starting with | |
1662 | line 1. | |
1663 | ||
1664 | The statement position either -1 (0xFFFF) or the number of characters | |
1665 | from the beginning of the line to the beginning of the statement. | |
1666 | ||
1667 | The address delta is the difference between the base address and | |
1668 | the address of the first instruction for the statement. | |
1669 | ||
1670 | Note that we must copy the bytes from the packed table to our local | |
1671 | variables before attempting to use them, to avoid alignment problems | |
1672 | on some machines, particularly RISC processors. | |
1673 | ||
1674 | BUGS | |
1675 | ||
1676 | Does gdb expect the line numbers to be sorted? They are now by | |
1677 | chance/luck, but are not required to be. (FIXME) | |
1678 | ||
1679 | The line with number 0 is unused, gdb apparently can discover the | |
1680 | span of the last line some other way. How? (FIXME) | |
1681 | */ | |
1682 | ||
1683 | static void | |
1ab3bf1b JG |
1684 | decode_line_numbers (linetable) |
1685 | char *linetable; | |
35f5886e FF |
1686 | { |
1687 | char *tblscan; | |
1688 | char *tblend; | |
1689 | long length; | |
1690 | long base; | |
1691 | long line; | |
1692 | long pc; | |
1693 | ||
1694 | if (linetable != NULL) | |
1695 | { | |
1696 | tblscan = tblend = linetable; | |
1697 | (void) memcpy (&length, tblscan, sizeof (long)); | |
1698 | tblscan += sizeof (long); | |
1699 | tblend += length; | |
1700 | (void) memcpy (&base, tblscan, sizeof (long)); | |
1701 | base += baseaddr; | |
1702 | tblscan += sizeof (long); | |
1703 | while (tblscan < tblend) | |
1704 | { | |
1705 | (void) memcpy (&line, tblscan, sizeof (long)); | |
1706 | tblscan += sizeof (long) + sizeof (short); | |
1707 | (void) memcpy (&pc, tblscan, sizeof (long)); | |
1708 | tblscan += sizeof (long); | |
1709 | pc += base; | |
1710 | if (line > 0) | |
1711 | { | |
4d315a07 | 1712 | record_line (current_subfile, line, pc); |
35f5886e FF |
1713 | } |
1714 | } | |
1715 | } | |
1716 | } | |
1717 | ||
1718 | /* | |
1719 | ||
35f5886e FF |
1720 | LOCAL FUNCTION |
1721 | ||
1722 | locval -- compute the value of a location attribute | |
1723 | ||
1724 | SYNOPSIS | |
1725 | ||
1726 | static int locval (char *loc) | |
1727 | ||
1728 | DESCRIPTION | |
1729 | ||
1730 | Given pointer to a string of bytes that define a location, compute | |
1731 | the location and return the value. | |
1732 | ||
1733 | When computing values involving the current value of the frame pointer, | |
1734 | the value zero is used, which results in a value relative to the frame | |
1735 | pointer, rather than the absolute value. This is what GDB wants | |
1736 | anyway. | |
1737 | ||
1738 | When the result is a register number, the global isreg flag is set, | |
1739 | otherwise it is cleared. This is a kludge until we figure out a better | |
1740 | way to handle the problem. Gdb's design does not mesh well with the | |
1741 | DWARF notion of a location computing interpreter, which is a shame | |
1742 | because the flexibility goes unused. | |
1743 | ||
1744 | NOTES | |
1745 | ||
1746 | Note that stack[0] is unused except as a default error return. | |
1747 | Note that stack overflow is not yet handled. | |
1748 | */ | |
1749 | ||
1750 | static int | |
1ab3bf1b JG |
1751 | locval (loc) |
1752 | char *loc; | |
35f5886e FF |
1753 | { |
1754 | unsigned short nbytes; | |
1755 | auto int stack[64]; | |
1756 | int stacki; | |
1757 | char *end; | |
1758 | long regno; | |
1759 | ||
1760 | (void) memcpy (&nbytes, loc, sizeof (short)); | |
1761 | end = loc + sizeof (short) + nbytes; | |
1762 | stacki = 0; | |
1763 | stack[stacki] = 0; | |
1764 | isreg = 0; | |
a5bd5ba6 | 1765 | offreg = 0; |
35f5886e FF |
1766 | for (loc += sizeof (short); loc < end; loc += sizeof (long)) |
1767 | { | |
1768 | switch (*loc++) { | |
1769 | case 0: | |
1770 | /* error */ | |
1771 | loc = end; | |
1772 | break; | |
1773 | case OP_REG: | |
1774 | /* push register (number) */ | |
1775 | (void) memcpy (&stack[++stacki], loc, sizeof (long)); | |
1776 | isreg = 1; | |
1777 | break; | |
1778 | case OP_BASEREG: | |
1779 | /* push value of register (number) */ | |
1780 | /* Actually, we compute the value as if register has 0 */ | |
a5bd5ba6 | 1781 | offreg = 1; |
35f5886e FF |
1782 | (void) memcpy (®no, loc, sizeof (long)); |
1783 | if (regno == R_FP) | |
1784 | { | |
1785 | stack[++stacki] = 0; | |
1786 | } | |
1787 | else | |
1788 | { | |
1789 | stack[++stacki] = 0; | |
1790 | SQUAWK (("BASEREG %d not handled!", regno)); | |
1791 | } | |
1792 | break; | |
1793 | case OP_ADDR: | |
1794 | /* push address (relocated address) */ | |
1795 | (void) memcpy (&stack[++stacki], loc, sizeof (long)); | |
1796 | break; | |
1797 | case OP_CONST: | |
1798 | /* push constant (number) */ | |
1799 | (void) memcpy (&stack[++stacki], loc, sizeof (long)); | |
1800 | break; | |
1801 | case OP_DEREF2: | |
1802 | /* pop, deref and push 2 bytes (as a long) */ | |
1803 | SQUAWK (("OP_DEREF2 address %#x not handled", stack[stacki])); | |
1804 | break; | |
1805 | case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */ | |
1806 | SQUAWK (("OP_DEREF4 address %#x not handled", stack[stacki])); | |
1807 | break; | |
1808 | case OP_ADD: /* pop top 2 items, add, push result */ | |
1809 | stack[stacki - 1] += stack[stacki]; | |
1810 | stacki--; | |
1811 | break; | |
1812 | } | |
1813 | } | |
1814 | return (stack[stacki]); | |
1815 | } | |
1816 | ||
1817 | /* | |
1818 | ||
1819 | LOCAL FUNCTION | |
1820 | ||
1821 | read_ofile_symtab -- build a full symtab entry from chunk of DIE's | |
1822 | ||
1823 | SYNOPSIS | |
1824 | ||
a048c8f5 | 1825 | static struct symtab *read_ofile_symtab (struct partial_symtab *pst) |
35f5886e FF |
1826 | |
1827 | DESCRIPTION | |
1828 | ||
1ab3bf1b JG |
1829 | When expanding a partial symbol table entry to a full symbol table |
1830 | entry, this is the function that gets called to read in the symbols | |
1831 | for the compilation unit. | |
1832 | ||
1833 | Returns a pointer to the newly constructed symtab (which is now | |
1834 | the new first one on the objfile's symtab list). | |
35f5886e FF |
1835 | */ |
1836 | ||
1837 | static struct symtab * | |
1ab3bf1b JG |
1838 | read_ofile_symtab (pst) |
1839 | struct partial_symtab *pst; | |
35f5886e FF |
1840 | { |
1841 | struct cleanup *back_to; | |
1842 | long lnsize; | |
1843 | int foffset; | |
1ab3bf1b JG |
1844 | bfd *abfd; |
1845 | ||
1846 | abfd = pst -> objfile -> obfd; | |
1847 | current_objfile = pst -> objfile; | |
1848 | ||
35f5886e FF |
1849 | /* Allocate a buffer for the entire chunk of DIE's for this compilation |
1850 | unit, seek to the location in the file, and read in all the DIE's. */ | |
1851 | ||
1852 | diecount = 0; | |
1853 | dbbase = xmalloc (DBLENGTH(pst)); | |
1854 | dbroff = DBROFF(pst); | |
1855 | foffset = DBFOFF(pst) + dbroff; | |
f8b76e70 | 1856 | baseaddr = pst -> addr; |
a048c8f5 JG |
1857 | if (bfd_seek (abfd, foffset, 0) || |
1858 | (bfd_read (dbbase, DBLENGTH(pst), 1, abfd) != DBLENGTH(pst))) | |
35f5886e FF |
1859 | { |
1860 | free (dbbase); | |
1861 | error ("can't read DWARF data"); | |
1862 | } | |
1863 | back_to = make_cleanup (free, dbbase); | |
1864 | ||
1865 | /* If there is a line number table associated with this compilation unit | |
1866 | then read the first long word from the line number table fragment, which | |
1867 | contains the size of the fragment in bytes (including the long word | |
1868 | itself). Allocate a buffer for the fragment and read it in for future | |
1869 | processing. */ | |
1870 | ||
1871 | lnbase = NULL; | |
1872 | if (LNFOFF (pst)) | |
1873 | { | |
a048c8f5 JG |
1874 | if (bfd_seek (abfd, LNFOFF (pst), 0) || |
1875 | (bfd_read (&lnsize, sizeof(long), 1, abfd) != sizeof(long))) | |
35f5886e FF |
1876 | { |
1877 | error ("can't read DWARF line number table size"); | |
1878 | } | |
1879 | lnbase = xmalloc (lnsize); | |
a048c8f5 JG |
1880 | if (bfd_seek (abfd, LNFOFF (pst), 0) || |
1881 | (bfd_read (lnbase, lnsize, 1, abfd) != lnsize)) | |
35f5886e FF |
1882 | { |
1883 | free (lnbase); | |
1884 | error ("can't read DWARF line numbers"); | |
1885 | } | |
1886 | make_cleanup (free, lnbase); | |
1887 | } | |
1888 | ||
f8b76e70 | 1889 | process_dies (dbbase, dbbase + DBLENGTH(pst), pst -> objfile); |
35f5886e | 1890 | do_cleanups (back_to); |
1ab3bf1b JG |
1891 | current_objfile = NULL; |
1892 | return (pst -> objfile -> symtabs); | |
35f5886e FF |
1893 | } |
1894 | ||
1895 | /* | |
1896 | ||
1897 | LOCAL FUNCTION | |
1898 | ||
1899 | psymtab_to_symtab_1 -- do grunt work for building a full symtab entry | |
1900 | ||
1901 | SYNOPSIS | |
1902 | ||
a048c8f5 | 1903 | static void psymtab_to_symtab_1 (struct partial_symtab *pst) |
35f5886e FF |
1904 | |
1905 | DESCRIPTION | |
1906 | ||
1907 | Called once for each partial symbol table entry that needs to be | |
1908 | expanded into a full symbol table entry. | |
1909 | ||
1910 | */ | |
1911 | ||
1912 | static void | |
1ab3bf1b JG |
1913 | psymtab_to_symtab_1 (pst) |
1914 | struct partial_symtab *pst; | |
35f5886e FF |
1915 | { |
1916 | int i; | |
1917 | ||
1ab3bf1b | 1918 | if (pst != NULL) |
35f5886e | 1919 | { |
1ab3bf1b | 1920 | if (pst->readin) |
35f5886e | 1921 | { |
1ab3bf1b JG |
1922 | warning ("Psymtab for %s already read in. Shouldn't happen.", |
1923 | pst -> filename); | |
1924 | } | |
1925 | else | |
1926 | { | |
1927 | /* Read in all partial symtabs on which this one is dependent */ | |
1928 | for (i = 0; i < pst -> number_of_dependencies; i++) | |
1929 | { | |
1930 | if (!pst -> dependencies[i] -> readin) | |
1931 | { | |
1932 | /* Inform about additional files that need to be read in. */ | |
1933 | if (info_verbose) | |
1934 | { | |
1935 | fputs_filtered (" ", stdout); | |
1936 | wrap_here (""); | |
1937 | fputs_filtered ("and ", stdout); | |
1938 | wrap_here (""); | |
1939 | printf_filtered ("%s...", | |
1940 | pst -> dependencies[i] -> filename); | |
1941 | wrap_here (""); | |
1942 | fflush (stdout); /* Flush output */ | |
1943 | } | |
1944 | psymtab_to_symtab_1 (pst -> dependencies[i]); | |
1945 | } | |
1946 | } | |
1947 | if (DBLENGTH (pst)) /* Otherwise it's a dummy */ | |
1948 | { | |
1949 | pst -> symtab = read_ofile_symtab (pst); | |
1950 | if (info_verbose) | |
1951 | { | |
1952 | printf_filtered ("%d DIE's, sorting...", diecount); | |
1953 | wrap_here (""); | |
1954 | fflush (stdout); | |
1955 | } | |
1956 | sort_symtab_syms (pst -> symtab); | |
1957 | } | |
1958 | pst -> readin = 1; | |
35f5886e | 1959 | } |
35f5886e | 1960 | } |
35f5886e FF |
1961 | } |
1962 | ||
1963 | /* | |
1964 | ||
1965 | LOCAL FUNCTION | |
1966 | ||
1967 | dwarf_psymtab_to_symtab -- build a full symtab entry from partial one | |
1968 | ||
1969 | SYNOPSIS | |
1970 | ||
1971 | static void dwarf_psymtab_to_symtab (struct partial_symtab *pst) | |
1972 | ||
1973 | DESCRIPTION | |
1974 | ||
1975 | This is the DWARF support entry point for building a full symbol | |
1976 | table entry from a partial symbol table entry. We are passed a | |
1977 | pointer to the partial symbol table entry that needs to be expanded. | |
1978 | ||
1979 | */ | |
1980 | ||
1981 | static void | |
1ab3bf1b JG |
1982 | dwarf_psymtab_to_symtab (pst) |
1983 | struct partial_symtab *pst; | |
35f5886e | 1984 | { |
7d9884b9 | 1985 | |
1ab3bf1b | 1986 | if (pst != NULL) |
35f5886e | 1987 | { |
1ab3bf1b | 1988 | if (pst -> readin) |
35f5886e | 1989 | { |
1ab3bf1b JG |
1990 | warning ("Psymtab for %s already read in. Shouldn't happen.", |
1991 | pst -> filename); | |
35f5886e | 1992 | } |
1ab3bf1b | 1993 | else |
35f5886e | 1994 | { |
1ab3bf1b JG |
1995 | if (DBLENGTH (pst) || pst -> number_of_dependencies) |
1996 | { | |
1997 | /* Print the message now, before starting serious work, to avoid | |
1998 | disconcerting pauses. */ | |
1999 | if (info_verbose) | |
2000 | { | |
2001 | printf_filtered ("Reading in symbols for %s...", | |
2002 | pst -> filename); | |
2003 | fflush (stdout); | |
2004 | } | |
2005 | ||
2006 | psymtab_to_symtab_1 (pst); | |
2007 | ||
2008 | #if 0 /* FIXME: Check to see what dbxread is doing here and see if | |
2009 | we need to do an equivalent or is this something peculiar to | |
2010 | stabs/a.out format. | |
2011 | Match with global symbols. This only needs to be done once, | |
2012 | after all of the symtabs and dependencies have been read in. | |
2013 | */ | |
2014 | scan_file_globals (pst -> objfile); | |
2015 | #endif | |
2016 | ||
2017 | /* Finish up the verbose info message. */ | |
2018 | if (info_verbose) | |
2019 | { | |
2020 | printf_filtered ("done.\n"); | |
2021 | fflush (stdout); | |
2022 | } | |
2023 | } | |
35f5886e FF |
2024 | } |
2025 | } | |
2026 | } | |
2027 | ||
2028 | /* | |
2029 | ||
2030 | LOCAL FUNCTION | |
2031 | ||
2032 | init_psymbol_list -- initialize storage for partial symbols | |
2033 | ||
2034 | SYNOPSIS | |
2035 | ||
1ab3bf1b | 2036 | static void init_psymbol_list (struct objfile *objfile, int total_symbols) |
35f5886e FF |
2037 | |
2038 | DESCRIPTION | |
2039 | ||
2040 | Initializes storage for all of the partial symbols that will be | |
2041 | created by dwarf_build_psymtabs and subsidiaries. | |
2042 | */ | |
2043 | ||
2044 | static void | |
1ab3bf1b JG |
2045 | init_psymbol_list (objfile, total_symbols) |
2046 | struct objfile *objfile; | |
2047 | int total_symbols; | |
35f5886e FF |
2048 | { |
2049 | /* Free any previously allocated psymbol lists. */ | |
2050 | ||
1ab3bf1b | 2051 | if (objfile -> global_psymbols.list) |
35f5886e | 2052 | { |
1ab3bf1b | 2053 | (*objfile -> free) (objfile -> global_psymbols.list); |
35f5886e | 2054 | } |
1ab3bf1b | 2055 | if (objfile -> static_psymbols.list) |
35f5886e | 2056 | { |
1ab3bf1b | 2057 | (*objfile -> free) (objfile -> static_psymbols.list); |
35f5886e FF |
2058 | } |
2059 | ||
2060 | /* Current best guess is that there are approximately a twentieth | |
2061 | of the total symbols (in a debugging file) are global or static | |
2062 | oriented symbols */ | |
2063 | ||
1ab3bf1b JG |
2064 | objfile -> global_psymbols.size = total_symbols / 10; |
2065 | objfile -> static_psymbols.size = total_symbols / 10; | |
2066 | objfile -> global_psymbols.next = | |
2067 | objfile -> global_psymbols.list = (struct partial_symbol *) | |
2068 | (*objfile -> xmalloc) (objfile -> global_psymbols.size | |
2069 | * sizeof (struct partial_symbol)); | |
2070 | objfile -> static_psymbols.next = | |
2071 | objfile -> static_psymbols.list = (struct partial_symbol *) | |
2072 | (*objfile -> xmalloc) (objfile -> static_psymbols.size | |
2073 | * sizeof (struct partial_symbol)); | |
35f5886e FF |
2074 | } |
2075 | ||
35f5886e FF |
2076 | /* |
2077 | ||
715cafcb FF |
2078 | LOCAL FUNCTION |
2079 | ||
2080 | add_enum_psymbol -- add enumeration members to partial symbol table | |
2081 | ||
2082 | DESCRIPTION | |
2083 | ||
2084 | Given pointer to a DIE that is known to be for an enumeration, | |
2085 | extract the symbolic names of the enumeration members and add | |
2086 | partial symbols for them. | |
2087 | */ | |
2088 | ||
2089 | static void | |
1ab3bf1b JG |
2090 | add_enum_psymbol (dip, objfile) |
2091 | struct dieinfo *dip; | |
2092 | struct objfile *objfile; | |
715cafcb FF |
2093 | { |
2094 | char *scan; | |
2095 | char *listend; | |
2096 | long ltemp; | |
2097 | short stemp; | |
2098 | ||
2099 | if ((scan = dip -> at_element_list) != NULL) | |
2100 | { | |
2101 | if (dip -> short_element_list) | |
2102 | { | |
2103 | (void) memcpy (&stemp, scan, sizeof (stemp)); | |
2104 | listend = scan + stemp + sizeof (stemp); | |
2105 | scan += sizeof (stemp); | |
2106 | } | |
2107 | else | |
2108 | { | |
2109 | (void) memcpy (<emp, scan, sizeof (ltemp)); | |
2110 | listend = scan + ltemp + sizeof (ltemp); | |
2111 | scan += sizeof (ltemp); | |
2112 | } | |
2113 | while (scan < listend) | |
2114 | { | |
2115 | scan += sizeof (long); | |
b440b1e9 | 2116 | ADD_PSYMBOL_TO_LIST (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST, |
1ab3bf1b | 2117 | objfile -> static_psymbols, 0); |
715cafcb FF |
2118 | scan += strlen (scan) + 1; |
2119 | } | |
2120 | } | |
2121 | } | |
2122 | ||
2123 | /* | |
2124 | ||
35f5886e FF |
2125 | LOCAL FUNCTION |
2126 | ||
2127 | add_partial_symbol -- add symbol to partial symbol table | |
2128 | ||
2129 | DESCRIPTION | |
2130 | ||
2131 | Given a DIE, if it is one of the types that we want to | |
2132 | add to a partial symbol table, finish filling in the die info | |
2133 | and then add a partial symbol table entry for it. | |
2134 | ||
2135 | */ | |
2136 | ||
2137 | static void | |
1ab3bf1b JG |
2138 | add_partial_symbol (dip, objfile) |
2139 | struct dieinfo *dip; | |
2140 | struct objfile *objfile; | |
35f5886e FF |
2141 | { |
2142 | switch (dip -> dietag) | |
2143 | { | |
2144 | case TAG_global_subroutine: | |
1ab3bf1b JG |
2145 | record_minimal_symbol (dip -> at_name, dip -> at_low_pc, mst_text, |
2146 | objfile); | |
b440b1e9 | 2147 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2148 | VAR_NAMESPACE, LOC_BLOCK, |
2149 | objfile -> global_psymbols, | |
b440b1e9 | 2150 | dip -> at_low_pc); |
35f5886e FF |
2151 | break; |
2152 | case TAG_global_variable: | |
1ab3bf1b JG |
2153 | record_minimal_symbol (dip -> at_name, locval (dip -> at_location), |
2154 | mst_data, objfile); | |
b440b1e9 | 2155 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2156 | VAR_NAMESPACE, LOC_STATIC, |
2157 | objfile -> global_psymbols, | |
b440b1e9 | 2158 | 0); |
35f5886e FF |
2159 | break; |
2160 | case TAG_subroutine: | |
b440b1e9 | 2161 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2162 | VAR_NAMESPACE, LOC_BLOCK, |
2163 | objfile -> static_psymbols, | |
b440b1e9 | 2164 | dip -> at_low_pc); |
35f5886e FF |
2165 | break; |
2166 | case TAG_local_variable: | |
b440b1e9 | 2167 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2168 | VAR_NAMESPACE, LOC_STATIC, |
2169 | objfile -> static_psymbols, | |
b440b1e9 | 2170 | 0); |
35f5886e FF |
2171 | break; |
2172 | case TAG_typedef: | |
b440b1e9 | 2173 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2174 | VAR_NAMESPACE, LOC_TYPEDEF, |
2175 | objfile -> static_psymbols, | |
b440b1e9 | 2176 | 0); |
35f5886e FF |
2177 | break; |
2178 | case TAG_structure_type: | |
2179 | case TAG_union_type: | |
b440b1e9 | 2180 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2181 | STRUCT_NAMESPACE, LOC_TYPEDEF, |
2182 | objfile -> static_psymbols, | |
b440b1e9 | 2183 | 0); |
35f5886e | 2184 | break; |
715cafcb FF |
2185 | case TAG_enumeration_type: |
2186 | if (dip -> at_name) | |
2187 | { | |
b440b1e9 | 2188 | ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name), |
1ab3bf1b JG |
2189 | STRUCT_NAMESPACE, LOC_TYPEDEF, |
2190 | objfile -> static_psymbols, | |
b440b1e9 | 2191 | 0); |
715cafcb | 2192 | } |
1ab3bf1b | 2193 | add_enum_psymbol (dip, objfile); |
715cafcb | 2194 | break; |
35f5886e FF |
2195 | } |
2196 | } | |
2197 | ||
2198 | /* | |
2199 | ||
2200 | LOCAL FUNCTION | |
2201 | ||
2202 | scan_partial_symbols -- scan DIE's within a single compilation unit | |
2203 | ||
2204 | DESCRIPTION | |
2205 | ||
2206 | Process the DIE's within a single compilation unit, looking for | |
2207 | interesting DIE's that contribute to the partial symbol table entry | |
2208 | for this compilation unit. Since we cannot follow any sibling | |
2209 | chains without reading the complete DIE info for every DIE, | |
2210 | it is probably faster to just sequentially check each one to | |
715cafcb FF |
2211 | see if it is one of the types we are interested in, and if so, |
2212 | then extract all the attributes info and generate a partial | |
2213 | symbol table entry. | |
35f5886e | 2214 | |
2d6186f4 FF |
2215 | NOTES |
2216 | ||
715cafcb FF |
2217 | Don't attempt to add anonymous structures or unions since they have |
2218 | no name. Anonymous enumerations however are processed, because we | |
2219 | want to extract their member names (the check for a tag name is | |
2220 | done later). | |
2d6186f4 | 2221 | |
715cafcb FF |
2222 | Also, for variables and subroutines, check that this is the place |
2223 | where the actual definition occurs, rather than just a reference | |
2224 | to an external. | |
35f5886e FF |
2225 | */ |
2226 | ||
2227 | static void | |
1ab3bf1b JG |
2228 | scan_partial_symbols (thisdie, enddie, objfile) |
2229 | char *thisdie; | |
2230 | char *enddie; | |
2231 | struct objfile *objfile; | |
35f5886e FF |
2232 | { |
2233 | char *nextdie; | |
2234 | struct dieinfo di; | |
2235 | ||
2236 | while (thisdie < enddie) | |
2237 | { | |
2238 | basicdieinfo (&di, thisdie); | |
2239 | if (di.dielength < sizeof (long)) | |
2240 | { | |
2241 | break; | |
2242 | } | |
2243 | else | |
2244 | { | |
2245 | nextdie = thisdie + di.dielength; | |
715cafcb FF |
2246 | /* To avoid getting complete die information for every die, we |
2247 | only do it (below) for the cases we are interested in. */ | |
35f5886e FF |
2248 | switch (di.dietag) |
2249 | { | |
2250 | case TAG_global_subroutine: | |
35f5886e | 2251 | case TAG_subroutine: |
2d6186f4 | 2252 | case TAG_global_variable: |
35f5886e | 2253 | case TAG_local_variable: |
2d6186f4 FF |
2254 | completedieinfo (&di); |
2255 | if (di.at_name && (di.has_at_low_pc || di.at_location)) | |
2256 | { | |
1ab3bf1b | 2257 | add_partial_symbol (&di, objfile); |
2d6186f4 FF |
2258 | } |
2259 | break; | |
35f5886e FF |
2260 | case TAG_typedef: |
2261 | case TAG_structure_type: | |
2262 | case TAG_union_type: | |
35f5886e | 2263 | completedieinfo (&di); |
2d6186f4 | 2264 | if (di.at_name) |
35f5886e | 2265 | { |
1ab3bf1b | 2266 | add_partial_symbol (&di, objfile); |
35f5886e FF |
2267 | } |
2268 | break; | |
715cafcb FF |
2269 | case TAG_enumeration_type: |
2270 | completedieinfo (&di); | |
1ab3bf1b | 2271 | add_partial_symbol (&di, objfile); |
715cafcb | 2272 | break; |
35f5886e FF |
2273 | } |
2274 | } | |
2275 | thisdie = nextdie; | |
2276 | } | |
2277 | } | |
2278 | ||
2279 | /* | |
2280 | ||
2281 | LOCAL FUNCTION | |
2282 | ||
2283 | scan_compilation_units -- build a psymtab entry for each compilation | |
2284 | ||
2285 | DESCRIPTION | |
2286 | ||
2287 | This is the top level dwarf parsing routine for building partial | |
2288 | symbol tables. | |
2289 | ||
2290 | It scans from the beginning of the DWARF table looking for the first | |
2291 | TAG_compile_unit DIE, and then follows the sibling chain to locate | |
2292 | each additional TAG_compile_unit DIE. | |
2293 | ||
2294 | For each TAG_compile_unit DIE it creates a partial symtab structure, | |
2295 | calls a subordinate routine to collect all the compilation unit's | |
2296 | global DIE's, file scope DIEs, typedef DIEs, etc, and then links the | |
2297 | new partial symtab structure into the partial symbol table. It also | |
2298 | records the appropriate information in the partial symbol table entry | |
2299 | to allow the chunk of DIE's and line number table for this compilation | |
2300 | unit to be located and re-read later, to generate a complete symbol | |
2301 | table entry for the compilation unit. | |
2302 | ||
2303 | Thus it effectively partitions up a chunk of DIE's for multiple | |
2304 | compilation units into smaller DIE chunks and line number tables, | |
2305 | and associates them with a partial symbol table entry. | |
2306 | ||
2307 | NOTES | |
2308 | ||
2309 | If any compilation unit has no line number table associated with | |
2310 | it for some reason (a missing at_stmt_list attribute, rather than | |
2311 | just one with a value of zero, which is valid) then we ensure that | |
2312 | the recorded file offset is zero so that the routine which later | |
2313 | reads line number table fragments knows that there is no fragment | |
2314 | to read. | |
2315 | ||
2316 | RETURNS | |
2317 | ||
2318 | Returns no value. | |
2319 | ||
2320 | */ | |
2321 | ||
2322 | static void | |
1ab3bf1b JG |
2323 | scan_compilation_units (filename, thisdie, enddie, dbfoff, lnoffset, objfile) |
2324 | char *filename; | |
2325 | char *thisdie; | |
2326 | char *enddie; | |
2327 | unsigned int dbfoff; | |
2328 | unsigned int lnoffset; | |
2329 | struct objfile *objfile; | |
35f5886e FF |
2330 | { |
2331 | char *nextdie; | |
2332 | struct dieinfo di; | |
2333 | struct partial_symtab *pst; | |
2334 | int culength; | |
2335 | int curoff; | |
2336 | int curlnoffset; | |
2337 | ||
2338 | while (thisdie < enddie) | |
2339 | { | |
2340 | basicdieinfo (&di, thisdie); | |
2341 | if (di.dielength < sizeof (long)) | |
2342 | { | |
2343 | break; | |
2344 | } | |
2345 | else if (di.dietag != TAG_compile_unit) | |
2346 | { | |
2347 | nextdie = thisdie + di.dielength; | |
2348 | } | |
2349 | else | |
2350 | { | |
2351 | completedieinfo (&di); | |
2352 | if (di.at_sibling != 0) | |
2353 | { | |
2354 | nextdie = dbbase + di.at_sibling - dbroff; | |
2355 | } | |
2356 | else | |
2357 | { | |
2358 | nextdie = thisdie + di.dielength; | |
2359 | } | |
2360 | curoff = thisdie - dbbase; | |
2361 | culength = nextdie - thisdie; | |
2d6186f4 | 2362 | curlnoffset = di.has_at_stmt_list ? lnoffset + di.at_stmt_list : 0; |
1ab3bf1b JG |
2363 | |
2364 | /* First allocate a new partial symbol table structure */ | |
2365 | ||
2366 | pst = start_psymtab_common (objfile, baseaddr, di.at_name, | |
2367 | di.at_low_pc, | |
2368 | objfile -> global_psymbols.next, | |
2369 | objfile -> static_psymbols.next); | |
2370 | ||
2371 | pst -> texthigh = di.at_high_pc; | |
2372 | pst -> read_symtab_private = (char *) | |
2373 | obstack_alloc (&objfile -> psymbol_obstack, | |
2374 | sizeof (struct dwfinfo)); | |
2375 | DBFOFF (pst) = dbfoff; | |
2376 | DBROFF (pst) = curoff; | |
2377 | DBLENGTH (pst) = culength; | |
2378 | LNFOFF (pst) = curlnoffset; | |
2379 | pst -> read_symtab = dwarf_psymtab_to_symtab; | |
2380 | ||
2381 | /* Now look for partial symbols */ | |
2382 | ||
2383 | scan_partial_symbols (thisdie + di.dielength, nextdie, objfile); | |
2384 | ||
2385 | pst -> n_global_syms = objfile -> global_psymbols.next - | |
2386 | (objfile -> global_psymbols.list + pst -> globals_offset); | |
2387 | pst -> n_static_syms = objfile -> static_psymbols.next - | |
2388 | (objfile -> static_psymbols.list + pst -> statics_offset); | |
2389 | sort_pst_symbols (pst); | |
35f5886e FF |
2390 | /* If there is already a psymtab or symtab for a file of this name, |
2391 | remove it. (If there is a symtab, more drastic things also | |
2392 | happen.) This happens in VxWorks. */ | |
2393 | free_named_symtabs (pst -> filename); | |
35f5886e FF |
2394 | } |
2395 | thisdie = nextdie; | |
2396 | } | |
2397 | } | |
2398 | ||
2399 | /* | |
2400 | ||
2401 | LOCAL FUNCTION | |
2402 | ||
2403 | new_symbol -- make a symbol table entry for a new symbol | |
2404 | ||
2405 | SYNOPSIS | |
2406 | ||
1ab3bf1b JG |
2407 | static struct symbol *new_symbol (struct dieinfo *dip, |
2408 | struct objfile *objfile) | |
35f5886e FF |
2409 | |
2410 | DESCRIPTION | |
2411 | ||
2412 | Given a pointer to a DWARF information entry, figure out if we need | |
2413 | to make a symbol table entry for it, and if so, create a new entry | |
2414 | and return a pointer to it. | |
2415 | */ | |
2416 | ||
2417 | static struct symbol * | |
1ab3bf1b JG |
2418 | new_symbol (dip, objfile) |
2419 | struct dieinfo *dip; | |
2420 | struct objfile *objfile; | |
35f5886e FF |
2421 | { |
2422 | struct symbol *sym = NULL; | |
2423 | ||
2424 | if (dip -> at_name != NULL) | |
2425 | { | |
1ab3bf1b | 2426 | sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack, |
35f5886e FF |
2427 | sizeof (struct symbol)); |
2428 | (void) memset (sym, 0, sizeof (struct symbol)); | |
1ab3bf1b | 2429 | SYMBOL_NAME (sym) = create_name (dip -> at_name, &objfile->symbol_obstack); |
35f5886e FF |
2430 | /* default assumptions */ |
2431 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
2432 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
2433 | SYMBOL_TYPE (sym) = decode_die_type (dip); | |
2434 | switch (dip -> dietag) | |
2435 | { | |
2436 | case TAG_label: | |
4d315a07 | 2437 | SYMBOL_VALUE (sym) = dip -> at_low_pc; |
35f5886e FF |
2438 | SYMBOL_CLASS (sym) = LOC_LABEL; |
2439 | break; | |
2440 | case TAG_global_subroutine: | |
2441 | case TAG_subroutine: | |
4d315a07 | 2442 | SYMBOL_VALUE (sym) = dip -> at_low_pc; |
35f5886e FF |
2443 | SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); |
2444 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
2445 | if (dip -> dietag == TAG_global_subroutine) | |
2446 | { | |
2447 | add_symbol_to_list (sym, &global_symbols); | |
2448 | } | |
2449 | else | |
2450 | { | |
4d315a07 | 2451 | add_symbol_to_list (sym, list_in_scope); |
35f5886e FF |
2452 | } |
2453 | break; | |
2454 | case TAG_global_variable: | |
35f5886e FF |
2455 | if (dip -> at_location != NULL) |
2456 | { | |
2457 | SYMBOL_VALUE (sym) = locval (dip -> at_location); | |
35f5886e FF |
2458 | add_symbol_to_list (sym, &global_symbols); |
2459 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
2460 | SYMBOL_VALUE (sym) += baseaddr; | |
2461 | } | |
a5bd5ba6 FF |
2462 | break; |
2463 | case TAG_local_variable: | |
2464 | if (dip -> at_location != NULL) | |
35f5886e | 2465 | { |
a5bd5ba6 | 2466 | SYMBOL_VALUE (sym) = locval (dip -> at_location); |
4d315a07 | 2467 | add_symbol_to_list (sym, list_in_scope); |
a5bd5ba6 FF |
2468 | if (isreg) |
2469 | { | |
2470 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
2471 | } | |
2472 | else if (offreg) | |
35f5886e | 2473 | { |
a5bd5ba6 | 2474 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
35f5886e FF |
2475 | } |
2476 | else | |
2477 | { | |
2478 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
2479 | SYMBOL_VALUE (sym) += baseaddr; | |
2480 | } | |
2481 | } | |
2482 | break; | |
2483 | case TAG_formal_parameter: | |
2484 | if (dip -> at_location != NULL) | |
2485 | { | |
2486 | SYMBOL_VALUE (sym) = locval (dip -> at_location); | |
2487 | } | |
4d315a07 | 2488 | add_symbol_to_list (sym, list_in_scope); |
35f5886e FF |
2489 | if (isreg) |
2490 | { | |
2491 | SYMBOL_CLASS (sym) = LOC_REGPARM; | |
2492 | } | |
2493 | else | |
2494 | { | |
2495 | SYMBOL_CLASS (sym) = LOC_ARG; | |
2496 | } | |
2497 | break; | |
2498 | case TAG_unspecified_parameters: | |
2499 | /* From varargs functions; gdb doesn't seem to have any interest in | |
2500 | this information, so just ignore it for now. (FIXME?) */ | |
2501 | break; | |
2502 | case TAG_structure_type: | |
2503 | case TAG_union_type: | |
2504 | case TAG_enumeration_type: | |
2505 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
2506 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
4d315a07 | 2507 | add_symbol_to_list (sym, list_in_scope); |
35f5886e FF |
2508 | break; |
2509 | case TAG_typedef: | |
2510 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
2511 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
4d315a07 | 2512 | add_symbol_to_list (sym, list_in_scope); |
35f5886e FF |
2513 | break; |
2514 | default: | |
2515 | /* Not a tag we recognize. Hopefully we aren't processing trash | |
2516 | data, but since we must specifically ignore things we don't | |
2517 | recognize, there is nothing else we should do at this point. */ | |
2518 | break; | |
2519 | } | |
2520 | } | |
2521 | return (sym); | |
2522 | } | |
2523 | ||
2524 | /* | |
2525 | ||
2526 | LOCAL FUNCTION | |
2527 | ||
2528 | decode_mod_fund_type -- decode a modified fundamental type | |
2529 | ||
2530 | SYNOPSIS | |
2531 | ||
2532 | static struct type *decode_mod_fund_type (char *typedata) | |
2533 | ||
2534 | DESCRIPTION | |
2535 | ||
2536 | Decode a block of data containing a modified fundamental | |
2537 | type specification. TYPEDATA is a pointer to the block, | |
2538 | which consists of a two byte length, containing the size | |
2539 | of the rest of the block. At the end of the block is a | |
2540 | two byte value that gives the fundamental type. Everything | |
2541 | in between are type modifiers. | |
2542 | ||
2543 | We simply compute the number of modifiers and call the general | |
2544 | function decode_modified_type to do the actual work. | |
2545 | */ | |
2546 | ||
2547 | static struct type * | |
1ab3bf1b JG |
2548 | decode_mod_fund_type (typedata) |
2549 | char *typedata; | |
35f5886e FF |
2550 | { |
2551 | struct type *typep = NULL; | |
2552 | unsigned short modcount; | |
2553 | unsigned char *modifiers; | |
2554 | ||
2555 | /* Get the total size of the block, exclusive of the size itself */ | |
2556 | (void) memcpy (&modcount, typedata, sizeof (short)); | |
2557 | /* Deduct the size of the fundamental type bytes at the end of the block. */ | |
2558 | modcount -= sizeof (short); | |
2559 | /* Skip over the two size bytes at the beginning of the block. */ | |
c8c0a2bd | 2560 | modifiers = (unsigned char *) typedata + sizeof (short); |
35f5886e FF |
2561 | /* Now do the actual decoding */ |
2562 | typep = decode_modified_type (modifiers, modcount, AT_mod_fund_type); | |
2563 | return (typep); | |
2564 | } | |
2565 | ||
2566 | /* | |
2567 | ||
2568 | LOCAL FUNCTION | |
2569 | ||
2570 | decode_mod_u_d_type -- decode a modified user defined type | |
2571 | ||
2572 | SYNOPSIS | |
2573 | ||
2574 | static struct type *decode_mod_u_d_type (char *typedata) | |
2575 | ||
2576 | DESCRIPTION | |
2577 | ||
2578 | Decode a block of data containing a modified user defined | |
2579 | type specification. TYPEDATA is a pointer to the block, | |
2580 | which consists of a two byte length, containing the size | |
2581 | of the rest of the block. At the end of the block is a | |
2582 | four byte value that gives a reference to a user defined type. | |
2583 | Everything in between are type modifiers. | |
2584 | ||
2585 | We simply compute the number of modifiers and call the general | |
2586 | function decode_modified_type to do the actual work. | |
2587 | */ | |
2588 | ||
2589 | static struct type * | |
1ab3bf1b JG |
2590 | decode_mod_u_d_type (typedata) |
2591 | char *typedata; | |
35f5886e FF |
2592 | { |
2593 | struct type *typep = NULL; | |
2594 | unsigned short modcount; | |
2595 | unsigned char *modifiers; | |
2596 | ||
2597 | /* Get the total size of the block, exclusive of the size itself */ | |
2598 | (void) memcpy (&modcount, typedata, sizeof (short)); | |
2599 | /* Deduct the size of the reference type bytes at the end of the block. */ | |
2600 | modcount -= sizeof (long); | |
2601 | /* Skip over the two size bytes at the beginning of the block. */ | |
c8c0a2bd | 2602 | modifiers = (unsigned char *) typedata + sizeof (short); |
35f5886e FF |
2603 | /* Now do the actual decoding */ |
2604 | typep = decode_modified_type (modifiers, modcount, AT_mod_u_d_type); | |
2605 | return (typep); | |
2606 | } | |
2607 | ||
2608 | /* | |
2609 | ||
2610 | LOCAL FUNCTION | |
2611 | ||
2612 | decode_modified_type -- decode modified user or fundamental type | |
2613 | ||
2614 | SYNOPSIS | |
2615 | ||
2616 | static struct type *decode_modified_type (unsigned char *modifiers, | |
2617 | unsigned short modcount, int mtype) | |
2618 | ||
2619 | DESCRIPTION | |
2620 | ||
2621 | Decode a modified type, either a modified fundamental type or | |
2622 | a modified user defined type. MODIFIERS is a pointer to the | |
2623 | block of bytes that define MODCOUNT modifiers. Immediately | |
2624 | following the last modifier is a short containing the fundamental | |
2625 | type or a long containing the reference to the user defined | |
2626 | type. Which one is determined by MTYPE, which is either | |
2627 | AT_mod_fund_type or AT_mod_u_d_type to indicate what modified | |
2628 | type we are generating. | |
2629 | ||
2630 | We call ourself recursively to generate each modified type,` | |
2631 | until MODCOUNT reaches zero, at which point we have consumed | |
2632 | all the modifiers and generate either the fundamental type or | |
2633 | user defined type. When the recursion unwinds, each modifier | |
2634 | is applied in turn to generate the full modified type. | |
2635 | ||
2636 | NOTES | |
2637 | ||
2638 | If we find a modifier that we don't recognize, and it is not one | |
2639 | of those reserved for application specific use, then we issue a | |
2640 | warning and simply ignore the modifier. | |
2641 | ||
2642 | BUGS | |
2643 | ||
2644 | We currently ignore MOD_const and MOD_volatile. (FIXME) | |
2645 | ||
2646 | */ | |
2647 | ||
2648 | static struct type * | |
1ab3bf1b JG |
2649 | decode_modified_type (modifiers, modcount, mtype) |
2650 | unsigned char *modifiers; | |
2651 | unsigned int modcount; | |
2652 | int mtype; | |
35f5886e FF |
2653 | { |
2654 | struct type *typep = NULL; | |
2655 | unsigned short fundtype; | |
2656 | DIEREF dieref; | |
2657 | unsigned char modifier; | |
2658 | ||
2659 | if (modcount == 0) | |
2660 | { | |
2661 | switch (mtype) | |
2662 | { | |
2663 | case AT_mod_fund_type: | |
2664 | (void) memcpy (&fundtype, modifiers, sizeof (short)); | |
2665 | typep = decode_fund_type (fundtype); | |
2666 | break; | |
2667 | case AT_mod_u_d_type: | |
2668 | (void) memcpy (&dieref, modifiers, sizeof (DIEREF)); | |
2669 | if ((typep = lookup_utype (dieref)) == NULL) | |
2670 | { | |
2671 | typep = alloc_utype (dieref, NULL); | |
2672 | } | |
2673 | break; | |
2674 | default: | |
2675 | SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype)); | |
1ab3bf1b | 2676 | typep = lookup_fundamental_type (current_objfile, FT_INTEGER); |
35f5886e FF |
2677 | break; |
2678 | } | |
2679 | } | |
2680 | else | |
2681 | { | |
2682 | modifier = *modifiers++; | |
2683 | typep = decode_modified_type (modifiers, --modcount, mtype); | |
2684 | switch (modifier) | |
2685 | { | |
2686 | case MOD_pointer_to: | |
2687 | typep = lookup_pointer_type (typep); | |
2688 | break; | |
2689 | case MOD_reference_to: | |
2690 | typep = lookup_reference_type (typep); | |
2691 | break; | |
2692 | case MOD_const: | |
2693 | SQUAWK (("type modifier 'const' ignored")); /* FIXME */ | |
2694 | break; | |
2695 | case MOD_volatile: | |
2696 | SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */ | |
2697 | break; | |
2698 | default: | |
2699 | if (!(MOD_lo_user <= modifier && modifier <= MOD_hi_user)) | |
2700 | { | |
2701 | SQUAWK (("unknown type modifier %u", modifier)); | |
2702 | } | |
2703 | break; | |
2704 | } | |
2705 | } | |
2706 | return (typep); | |
2707 | } | |
2708 | ||
2709 | /* | |
2710 | ||
2711 | LOCAL FUNCTION | |
2712 | ||
2713 | decode_fund_type -- translate basic DWARF type to gdb base type | |
2714 | ||
2715 | DESCRIPTION | |
2716 | ||
2717 | Given an integer that is one of the fundamental DWARF types, | |
2718 | translate it to one of the basic internal gdb types and return | |
2719 | a pointer to the appropriate gdb type (a "struct type *"). | |
2720 | ||
2721 | NOTES | |
2722 | ||
2723 | If we encounter a fundamental type that we are unprepared to | |
2724 | deal with, and it is not in the range of those types defined | |
2725 | as application specific types, then we issue a warning and | |
1ab3bf1b | 2726 | treat the type as an "int". |
35f5886e FF |
2727 | */ |
2728 | ||
2729 | static struct type * | |
1ab3bf1b JG |
2730 | decode_fund_type (fundtype) |
2731 | unsigned int fundtype; | |
35f5886e FF |
2732 | { |
2733 | struct type *typep = NULL; | |
2734 | ||
2735 | switch (fundtype) | |
2736 | { | |
2737 | ||
2738 | case FT_void: | |
1ab3bf1b | 2739 | typep = lookup_fundamental_type (current_objfile, FT_VOID); |
35f5886e FF |
2740 | break; |
2741 | ||
1ab3bf1b JG |
2742 | case FT_boolean: /* Was FT_set in AT&T version */ |
2743 | typep = lookup_fundamental_type (current_objfile, FT_BOOLEAN); | |
2744 | break; | |
2745 | ||
35f5886e | 2746 | case FT_pointer: /* (void *) */ |
1ab3bf1b JG |
2747 | typep = lookup_fundamental_type (current_objfile, FT_VOID); |
2748 | typep = lookup_pointer_type (typep); | |
35f5886e FF |
2749 | break; |
2750 | ||
2751 | case FT_char: | |
1ab3bf1b JG |
2752 | typep = lookup_fundamental_type (current_objfile, FT_CHAR); |
2753 | break; | |
2754 | ||
35f5886e | 2755 | case FT_signed_char: |
1ab3bf1b JG |
2756 | typep = lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR); |
2757 | break; | |
2758 | ||
2759 | case FT_unsigned_char: | |
2760 | typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR); | |
35f5886e FF |
2761 | break; |
2762 | ||
2763 | case FT_short: | |
1ab3bf1b JG |
2764 | typep = lookup_fundamental_type (current_objfile, FT_SHORT); |
2765 | break; | |
2766 | ||
35f5886e | 2767 | case FT_signed_short: |
1ab3bf1b JG |
2768 | typep = lookup_fundamental_type (current_objfile, FT_SIGNED_SHORT); |
2769 | break; | |
2770 | ||
2771 | case FT_unsigned_short: | |
2772 | typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT); | |
35f5886e FF |
2773 | break; |
2774 | ||
2775 | case FT_integer: | |
1ab3bf1b JG |
2776 | typep = lookup_fundamental_type (current_objfile, FT_INTEGER); |
2777 | break; | |
2778 | ||
35f5886e | 2779 | case FT_signed_integer: |
1ab3bf1b JG |
2780 | typep = lookup_fundamental_type (current_objfile, FT_SIGNED_INTEGER); |
2781 | break; | |
2782 | ||
2783 | case FT_unsigned_integer: | |
2784 | typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); | |
35f5886e FF |
2785 | break; |
2786 | ||
2787 | case FT_long: | |
1ab3bf1b JG |
2788 | typep = lookup_fundamental_type (current_objfile, FT_LONG); |
2789 | break; | |
2790 | ||
35f5886e | 2791 | case FT_signed_long: |
1ab3bf1b | 2792 | typep = lookup_fundamental_type (current_objfile, FT_SIGNED_LONG); |
35f5886e FF |
2793 | break; |
2794 | ||
1ab3bf1b JG |
2795 | case FT_unsigned_long: |
2796 | typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG); | |
35f5886e FF |
2797 | break; |
2798 | ||
1ab3bf1b JG |
2799 | case FT_long_long: |
2800 | typep = lookup_fundamental_type (current_objfile, FT_LONG_LONG); | |
35f5886e | 2801 | break; |
1ab3bf1b JG |
2802 | |
2803 | case FT_signed_long_long: | |
2804 | typep = lookup_fundamental_type (current_objfile, FT_SIGNED_LONG_LONG); | |
35f5886e | 2805 | break; |
1ab3bf1b JG |
2806 | |
2807 | case FT_unsigned_long_long: | |
2808 | typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG); | |
35f5886e | 2809 | break; |
1ab3bf1b JG |
2810 | |
2811 | case FT_float: | |
2812 | typep = lookup_fundamental_type (current_objfile, FT_FLOAT); | |
35f5886e FF |
2813 | break; |
2814 | ||
1ab3bf1b JG |
2815 | case FT_dbl_prec_float: |
2816 | typep = lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT); | |
35f5886e FF |
2817 | break; |
2818 | ||
2819 | case FT_ext_prec_float: | |
1ab3bf1b | 2820 | typep = lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT); |
35f5886e FF |
2821 | break; |
2822 | ||
2823 | case FT_complex: | |
1ab3bf1b | 2824 | typep = lookup_fundamental_type (current_objfile, FT_COMPLEX); |
35f5886e FF |
2825 | break; |
2826 | ||
2827 | case FT_dbl_prec_complex: | |
1ab3bf1b | 2828 | typep = lookup_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX); |
35f5886e FF |
2829 | break; |
2830 | ||
1ab3bf1b JG |
2831 | case FT_ext_prec_complex: |
2832 | typep = lookup_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX); | |
35f5886e | 2833 | break; |
1ab3bf1b | 2834 | |
35f5886e FF |
2835 | } |
2836 | ||
2837 | if ((typep == NULL) && !(FT_lo_user <= fundtype && fundtype <= FT_hi_user)) | |
2838 | { | |
2839 | SQUAWK (("unexpected fundamental type 0x%x", fundtype)); | |
1ab3bf1b | 2840 | typep = lookup_fundamental_type (current_objfile, FT_VOID); |
35f5886e FF |
2841 | } |
2842 | ||
2843 | return (typep); | |
2844 | } | |
2845 | ||
2846 | /* | |
2847 | ||
2848 | LOCAL FUNCTION | |
2849 | ||
2850 | create_name -- allocate a fresh copy of a string on an obstack | |
2851 | ||
2852 | DESCRIPTION | |
2853 | ||
2854 | Given a pointer to a string and a pointer to an obstack, allocates | |
2855 | a fresh copy of the string on the specified obstack. | |
2856 | ||
2857 | */ | |
2858 | ||
2859 | static char * | |
1ab3bf1b JG |
2860 | create_name (name, obstackp) |
2861 | char *name; | |
2862 | struct obstack *obstackp; | |
35f5886e FF |
2863 | { |
2864 | int length; | |
2865 | char *newname; | |
2866 | ||
2867 | length = strlen (name) + 1; | |
2868 | newname = (char *) obstack_alloc (obstackp, length); | |
2869 | (void) strcpy (newname, name); | |
2870 | return (newname); | |
2871 | } | |
2872 | ||
2873 | /* | |
2874 | ||
2875 | LOCAL FUNCTION | |
2876 | ||
2877 | basicdieinfo -- extract the minimal die info from raw die data | |
2878 | ||
2879 | SYNOPSIS | |
2880 | ||
2881 | void basicdieinfo (char *diep, struct dieinfo *dip) | |
2882 | ||
2883 | DESCRIPTION | |
2884 | ||
2885 | Given a pointer to raw DIE data, and a pointer to an instance of a | |
2886 | die info structure, this function extracts the basic information | |
2887 | from the DIE data required to continue processing this DIE, along | |
2888 | with some bookkeeping information about the DIE. | |
2889 | ||
2890 | The information we absolutely must have includes the DIE tag, | |
2891 | and the DIE length. If we need the sibling reference, then we | |
2892 | will have to call completedieinfo() to process all the remaining | |
2893 | DIE information. | |
2894 | ||
2895 | Note that since there is no guarantee that the data is properly | |
2896 | aligned in memory for the type of access required (indirection | |
2897 | through anything other than a char pointer), we use memcpy to | |
2898 | shuffle data items larger than a char. Possibly inefficient, but | |
2899 | quite portable. | |
2900 | ||
2901 | We also take care of some other basic things at this point, such | |
2902 | as ensuring that the instance of the die info structure starts | |
2903 | out completely zero'd and that curdie is initialized for use | |
2904 | in error reporting if we have a problem with the current die. | |
2905 | ||
2906 | NOTES | |
2907 | ||
2908 | All DIE's must have at least a valid length, thus the minimum | |
2909 | DIE size is sizeof (long). In order to have a valid tag, the | |
2910 | DIE size must be at least sizeof (short) larger, otherwise they | |
2911 | are forced to be TAG_padding DIES. | |
2912 | ||
2913 | Padding DIES must be at least sizeof(long) in length, implying that | |
2914 | if a padding DIE is used for alignment and the amount needed is less | |
2915 | than sizeof(long) then the padding DIE has to be big enough to align | |
2916 | to the next alignment boundry. | |
2917 | */ | |
2918 | ||
2919 | static void | |
1ab3bf1b JG |
2920 | basicdieinfo (dip, diep) |
2921 | struct dieinfo *dip; | |
2922 | char *diep; | |
35f5886e FF |
2923 | { |
2924 | curdie = dip; | |
2925 | (void) memset (dip, 0, sizeof (struct dieinfo)); | |
2926 | dip -> die = diep; | |
2927 | dip -> dieref = dbroff + (diep - dbbase); | |
2928 | (void) memcpy (&dip -> dielength, diep, sizeof (long)); | |
2929 | if (dip -> dielength < sizeof (long)) | |
2930 | { | |
2931 | dwarfwarn ("malformed DIE, bad length (%d bytes)", dip -> dielength); | |
2932 | } | |
2933 | else if (dip -> dielength < (sizeof (long) + sizeof (short))) | |
2934 | { | |
2935 | dip -> dietag = TAG_padding; | |
2936 | } | |
2937 | else | |
2938 | { | |
2939 | (void) memcpy (&dip -> dietag, diep + sizeof (long), sizeof (short)); | |
2940 | } | |
2941 | } | |
2942 | ||
2943 | /* | |
2944 | ||
2945 | LOCAL FUNCTION | |
2946 | ||
2947 | completedieinfo -- finish reading the information for a given DIE | |
2948 | ||
2949 | SYNOPSIS | |
2950 | ||
2951 | void completedieinfo (struct dieinfo *dip) | |
2952 | ||
2953 | DESCRIPTION | |
2954 | ||
2955 | Given a pointer to an already partially initialized die info structure, | |
2956 | scan the raw DIE data and finish filling in the die info structure | |
2957 | from the various attributes found. | |
2958 | ||
2959 | Note that since there is no guarantee that the data is properly | |
2960 | aligned in memory for the type of access required (indirection | |
2961 | through anything other than a char pointer), we use memcpy to | |
2962 | shuffle data items larger than a char. Possibly inefficient, but | |
2963 | quite portable. | |
2964 | ||
2965 | NOTES | |
2966 | ||
2967 | Each time we are called, we increment the diecount variable, which | |
2968 | keeps an approximate count of the number of dies processed for | |
2969 | each compilation unit. This information is presented to the user | |
2970 | if the info_verbose flag is set. | |
2971 | ||
2972 | */ | |
2973 | ||
2974 | static void | |
1ab3bf1b JG |
2975 | completedieinfo (dip) |
2976 | struct dieinfo *dip; | |
35f5886e FF |
2977 | { |
2978 | char *diep; /* Current pointer into raw DIE data */ | |
2979 | char *end; /* Terminate DIE scan here */ | |
2980 | unsigned short attr; /* Current attribute being scanned */ | |
2981 | unsigned short form; /* Form of the attribute */ | |
2982 | short block2sz; /* Size of a block2 attribute field */ | |
2983 | long block4sz; /* Size of a block4 attribute field */ | |
2984 | ||
2985 | diecount++; | |
2986 | diep = dip -> die; | |
2987 | end = diep + dip -> dielength; | |
2988 | diep += sizeof (long) + sizeof (short); | |
2989 | while (diep < end) | |
2990 | { | |
2991 | (void) memcpy (&attr, diep, sizeof (short)); | |
2992 | diep += sizeof (short); | |
2993 | switch (attr) | |
2994 | { | |
2995 | case AT_fund_type: | |
2996 | (void) memcpy (&dip -> at_fund_type, diep, sizeof (short)); | |
2997 | break; | |
2998 | case AT_ordering: | |
2999 | (void) memcpy (&dip -> at_ordering, diep, sizeof (short)); | |
3000 | break; | |
3001 | case AT_bit_offset: | |
3002 | (void) memcpy (&dip -> at_bit_offset, diep, sizeof (short)); | |
3003 | break; | |
3004 | case AT_visibility: | |
3005 | (void) memcpy (&dip -> at_visibility, diep, sizeof (short)); | |
3006 | break; | |
3007 | case AT_sibling: | |
3008 | (void) memcpy (&dip -> at_sibling, diep, sizeof (long)); | |
3009 | break; | |
3010 | case AT_stmt_list: | |
3011 | (void) memcpy (&dip -> at_stmt_list, diep, sizeof (long)); | |
2d6186f4 | 3012 | dip -> has_at_stmt_list = 1; |
35f5886e FF |
3013 | break; |
3014 | case AT_low_pc: | |
3015 | (void) memcpy (&dip -> at_low_pc, diep, sizeof (long)); | |
4d315a07 | 3016 | dip -> at_low_pc += baseaddr; |
2d6186f4 | 3017 | dip -> has_at_low_pc = 1; |
35f5886e FF |
3018 | break; |
3019 | case AT_high_pc: | |
3020 | (void) memcpy (&dip -> at_high_pc, diep, sizeof (long)); | |
4d315a07 | 3021 | dip -> at_high_pc += baseaddr; |
35f5886e FF |
3022 | break; |
3023 | case AT_language: | |
3024 | (void) memcpy (&dip -> at_language, diep, sizeof (long)); | |
3025 | break; | |
3026 | case AT_user_def_type: | |
3027 | (void) memcpy (&dip -> at_user_def_type, diep, sizeof (long)); | |
3028 | break; | |
3029 | case AT_byte_size: | |
3030 | (void) memcpy (&dip -> at_byte_size, diep, sizeof (long)); | |
3031 | break; | |
3032 | case AT_bit_size: | |
3033 | (void) memcpy (&dip -> at_bit_size, diep, sizeof (long)); | |
3034 | break; | |
3035 | case AT_member: | |
3036 | (void) memcpy (&dip -> at_member, diep, sizeof (long)); | |
3037 | break; | |
3038 | case AT_discr: | |
3039 | (void) memcpy (&dip -> at_discr, diep, sizeof (long)); | |
3040 | break; | |
3041 | case AT_import: | |
3042 | (void) memcpy (&dip -> at_import, diep, sizeof (long)); | |
3043 | break; | |
3044 | case AT_location: | |
3045 | dip -> at_location = diep; | |
3046 | break; | |
3047 | case AT_mod_fund_type: | |
3048 | dip -> at_mod_fund_type = diep; | |
3049 | break; | |
3050 | case AT_subscr_data: | |
3051 | dip -> at_subscr_data = diep; | |
3052 | break; | |
3053 | case AT_mod_u_d_type: | |
3054 | dip -> at_mod_u_d_type = diep; | |
3055 | break; | |
35f5886e FF |
3056 | case AT_element_list: |
3057 | dip -> at_element_list = diep; | |
768be6e1 FF |
3058 | dip -> short_element_list = 0; |
3059 | break; | |
3060 | case AT_short_element_list: | |
3061 | dip -> at_element_list = diep; | |
3062 | dip -> short_element_list = 1; | |
35f5886e FF |
3063 | break; |
3064 | case AT_discr_value: | |
3065 | dip -> at_discr_value = diep; | |
3066 | break; | |
3067 | case AT_string_length: | |
3068 | dip -> at_string_length = diep; | |
3069 | break; | |
3070 | case AT_name: | |
3071 | dip -> at_name = diep; | |
3072 | break; | |
3073 | case AT_comp_dir: | |
3074 | dip -> at_comp_dir = diep; | |
3075 | break; | |
3076 | case AT_producer: | |
3077 | dip -> at_producer = diep; | |
3078 | break; | |
35f5886e FF |
3079 | case AT_frame_base: |
3080 | (void) memcpy (&dip -> at_frame_base, diep, sizeof (long)); | |
3081 | break; | |
35f5886e FF |
3082 | case AT_start_scope: |
3083 | (void) memcpy (&dip -> at_start_scope, diep, sizeof (long)); | |
3084 | break; | |
3085 | case AT_stride_size: | |
3086 | (void) memcpy (&dip -> at_stride_size, diep, sizeof (long)); | |
3087 | break; | |
3088 | case AT_src_info: | |
3089 | (void) memcpy (&dip -> at_src_info, diep, sizeof (long)); | |
3090 | break; | |
3091 | case AT_prototyped: | |
3092 | (void) memcpy (&dip -> at_prototyped, diep, sizeof (short)); | |
3093 | break; | |
35f5886e FF |
3094 | default: |
3095 | /* Found an attribute that we are unprepared to handle. However | |
3096 | it is specifically one of the design goals of DWARF that | |
3097 | consumers should ignore unknown attributes. As long as the | |
3098 | form is one that we recognize (so we know how to skip it), | |
3099 | we can just ignore the unknown attribute. */ | |
3100 | break; | |
3101 | } | |
3102 | form = attr & 0xF; | |
3103 | switch (form) | |
3104 | { | |
3105 | case FORM_DATA2: | |
3106 | diep += sizeof (short); | |
3107 | break; | |
3108 | case FORM_DATA4: | |
3109 | diep += sizeof (long); | |
3110 | break; | |
3111 | case FORM_DATA8: | |
3112 | diep += 8 * sizeof (char); /* sizeof (long long) ? */ | |
3113 | break; | |
3114 | case FORM_ADDR: | |
3115 | case FORM_REF: | |
3116 | diep += sizeof (long); | |
3117 | break; | |
3118 | case FORM_BLOCK2: | |
3119 | (void) memcpy (&block2sz, diep, sizeof (short)); | |
3120 | block2sz += sizeof (short); | |
3121 | diep += block2sz; | |
3122 | break; | |
3123 | case FORM_BLOCK4: | |
3124 | (void) memcpy (&block4sz, diep, sizeof (long)); | |
3125 | block4sz += sizeof (long); | |
3126 | diep += block4sz; | |
3127 | break; | |
3128 | case FORM_STRING: | |
3129 | diep += strlen (diep) + 1; | |
3130 | break; | |
3131 | default: | |
3132 | SQUAWK (("unknown attribute form (0x%x), skipped rest", form)); | |
3133 | diep = end; | |
3134 | break; | |
3135 | } | |
3136 | } | |
3137 | } |