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