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