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