2003-01-18 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / gdb / dwarfread.c
1 /* DWARF debugging format support for GDB.
2
3 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
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
9 This file is part of GDB.
10
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.
15
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.
20
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. */
24
25 /*
26
27 FIXME: Do we need to generate dependencies in partial symtabs?
28 (Perhaps we don't need to).
29
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.
35
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())
38
39 FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
40 other things to work on, if you get bored. :-)
41
42 */
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"
52 #include "expression.h" /* Needed for enum exp_opcode in language.h, sigh... */
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
66 static void
67 bad_die_ref_complaint (int arg1, const char *arg2, int arg3)
68 {
69 complaint (&symfile_complaints,
70 "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit",
71 arg1, arg2, arg3);
72 }
73
74 static void
75 unknown_attribute_form_complaint (int arg1, const char *arg2, int arg3)
76 {
77 complaint (&symfile_complaints,
78 "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", arg1, arg2,
79 arg3);
80 }
81
82 static void
83 dup_user_type_definition_complaint (int arg1, const char *arg2)
84 {
85 complaint (&symfile_complaints,
86 "DIE @ 0x%x \"%s\", internal error: duplicate user type definition",
87 arg1, arg2);
88 }
89
90 static void
91 bad_array_element_type_complaint (int arg1, const char *arg2, int arg3)
92 {
93 complaint (&symfile_complaints,
94 "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", arg1,
95 arg2, arg3);
96 }
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
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
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.
185
186 */
187
188 typedef char BLOCK;
189
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 };
246
247 static int diecount; /* Approximate count of dies for compilation unit */
248 static struct dieinfo *curdie; /* For warnings and such */
249
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 */
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
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 };
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
345 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
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
363 static void free_utypes (void *);
364
365 static int attribute_size (unsigned int);
366
367 static CORE_ADDR target_to_host (char *, int, int, struct objfile *);
368
369 static void add_enum_psymbol (struct dieinfo *, struct objfile *);
370
371 static void handle_producer (char *);
372
373 static void
374 read_file_scope (struct dieinfo *, char *, char *, struct objfile *);
375
376 static void
377 read_func_scope (struct dieinfo *, char *, char *, struct objfile *);
378
379 static void
380 read_lexical_block_scope (struct dieinfo *, char *, char *, struct objfile *);
381
382 static void scan_partial_symbols (char *, char *, struct objfile *);
383
384 static void
385 scan_compilation_units (char *, char *, file_ptr, file_ptr, struct objfile *);
386
387 static void add_partial_symbol (struct dieinfo *, struct objfile *);
388
389 static void basicdieinfo (struct dieinfo *, char *, struct objfile *);
390
391 static void completedieinfo (struct dieinfo *, struct objfile *);
392
393 static void dwarf_psymtab_to_symtab (struct partial_symtab *);
394
395 static void psymtab_to_symtab_1 (struct partial_symtab *);
396
397 static void read_ofile_symtab (struct partial_symtab *);
398
399 static void process_dies (char *, char *, struct objfile *);
400
401 static void
402 read_structure_scope (struct dieinfo *, char *, char *, struct objfile *);
403
404 static struct type *decode_array_element_type (char *);
405
406 static struct type *decode_subscript_data_item (char *, char *);
407
408 static void dwarf_read_array_type (struct dieinfo *);
409
410 static void read_tag_pointer_type (struct dieinfo *dip);
411
412 static void read_tag_string_type (struct dieinfo *dip);
413
414 static void read_subroutine_type (struct dieinfo *, char *, char *);
415
416 static void
417 read_enumeration (struct dieinfo *, char *, char *, struct objfile *);
418
419 static struct type *struct_type (struct dieinfo *, char *, char *,
420 struct objfile *);
421
422 static struct type *enum_type (struct dieinfo *, struct objfile *);
423
424 static void decode_line_numbers (char *);
425
426 static struct type *decode_die_type (struct dieinfo *);
427
428 static struct type *decode_mod_fund_type (char *);
429
430 static struct type *decode_mod_u_d_type (char *);
431
432 static struct type *decode_modified_type (char *, unsigned int, int);
433
434 static struct type *decode_fund_type (unsigned int);
435
436 static char *create_name (char *, struct obstack *);
437
438 static struct type *lookup_utype (DIE_REF);
439
440 static struct type *alloc_utype (DIE_REF, struct type *);
441
442 static struct symbol *new_symbol (struct dieinfo *, struct objfile *);
443
444 static void
445 synthesize_typedef (struct dieinfo *, struct objfile *, struct type *);
446
447 static int locval (struct dieinfo *);
448
449 static void set_cu_language (struct dieinfo *);
450
451 static struct type *dwarf_fundamental_type (struct objfile *, int);
452
453
454 /*
455
456 LOCAL FUNCTION
457
458 dwarf_fundamental_type -- lookup or create a fundamental type
459
460 SYNOPSIS
461
462 struct type *
463 dwarf_fundamental_type (struct objfile *objfile, int typeid)
464
465 DESCRIPTION
466
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.
472
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.
481
482 RETURNS
483
484 Pointer to a fundamental type.
485
486 */
487
488 static struct type *
489 dwarf_fundamental_type (struct objfile *objfile, int typeid)
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 {
502 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
503 }
504
505 return (ftypes[typeid]);
506 }
507
508 /*
509
510 LOCAL FUNCTION
511
512 set_cu_language -- set local copy of language for compilation unit
513
514 SYNOPSIS
515
516 void
517 set_cu_language (struct dieinfo *dip)
518
519 DESCRIPTION
520
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.
524
525 RETURNS
526
527 No return value.
528
529 */
530
531 static void
532 set_cu_language (struct dieinfo *dip)
533 {
534 switch (dip->at_language)
535 {
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;
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;
561 }
562 cu_language_defn = language_def (cu_language);
563 }
564
565 /*
566
567 GLOBAL FUNCTION
568
569 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
570
571 SYNOPSIS
572
573 void dwarf_build_psymtabs (struct objfile *objfile,
574 int mainline, file_ptr dbfoff, unsigned int dbfsize,
575 file_ptr lnoffset, unsigned int lnsize)
576
577 DESCRIPTION
578
579 This function is called upon to build partial symtabs from files
580 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
581
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.
589
590 RETURNS
591
592 No return value.
593
594 */
595
596 void
597 dwarf_build_psymtabs (struct objfile *objfile, int mainline, file_ptr dbfoff,
598 unsigned int dbfsize, file_ptr lnoffset,
599 unsigned int lnsize)
600 {
601 bfd *abfd = objfile->obfd;
602 struct cleanup *back_to;
603
604 current_objfile = objfile;
605 dbsize = dbfsize;
606 dbbase = xmalloc (dbsize);
607 dbroff = 0;
608 if ((bfd_seek (abfd, dbfoff, SEEK_SET) != 0) ||
609 (bfd_bread (dbbase, dbsize, abfd) != dbsize))
610 {
611 xfree (dbbase);
612 error ("can't read DWARF data from '%s'", bfd_get_filename (abfd));
613 }
614 back_to = make_cleanup (xfree, dbbase);
615
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. */
619
620 if (mainline
621 || (objfile->global_psymbols.size == 0
622 && objfile->static_psymbols.size == 0))
623 {
624 init_psymbol_list (objfile, 1024);
625 }
626
627 /* Save the relocation factor where everybody can see it. */
628
629 base_section_offsets = objfile->section_offsets;
630 baseaddr = ANOFFSET (objfile->section_offsets, 0);
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. */
635
636 scan_compilation_units (dbbase, dbbase + dbsize, dbfoff, lnoffset, objfile);
637
638 do_cleanups (back_to);
639 current_objfile = NULL;
640 }
641
642 /*
643
644 LOCAL FUNCTION
645
646 read_lexical_block_scope -- process all dies in a lexical block
647
648 SYNOPSIS
649
650 static void read_lexical_block_scope (struct dieinfo *dip,
651 char *thisdie, char *enddie)
652
653 DESCRIPTION
654
655 Process all the DIES contained within a lexical block scope.
656 Start a new scope, process the dies, and then close the scope.
657
658 */
659
660 static void
661 read_lexical_block_scope (struct dieinfo *dip, char *thisdie, char *enddie,
662 struct objfile *objfile)
663 {
664 register struct context_stack *new;
665
666 push_context (0, dip->at_low_pc);
667 process_dies (thisdie + dip->die_length, enddie, objfile);
668 new = pop_context ();
669 if (local_symbols != NULL)
670 {
671 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
672 dip->at_high_pc, objfile);
673 }
674 local_symbols = new->locals;
675 }
676
677 /*
678
679 LOCAL FUNCTION
680
681 lookup_utype -- look up a user defined type from die reference
682
683 SYNOPSIS
684
685 static type *lookup_utype (DIE_REF die_ref)
686
687 DESCRIPTION
688
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.
694 */
695
696 static struct type *
697 lookup_utype (DIE_REF die_ref)
698 {
699 struct type *type = NULL;
700 int utypeidx;
701
702 utypeidx = (die_ref - dbroff) / 4;
703 if ((utypeidx < 0) || (utypeidx >= numutypes))
704 {
705 bad_die_ref_complaint (DIE_ID, DIE_NAME, die_ref);
706 }
707 else
708 {
709 type = *(utypes + utypeidx);
710 }
711 return (type);
712 }
713
714
715 /*
716
717 LOCAL FUNCTION
718
719 alloc_utype -- add a user defined type for die reference
720
721 SYNOPSIS
722
723 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
724
725 DESCRIPTION
726
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.
731
732 We should only be called after calling lookup_utype() to verify that
733 there is not currently a type registered for DIE_REF.
734 */
735
736 static struct type *
737 alloc_utype (DIE_REF die_ref, struct type *utypep)
738 {
739 struct type **typep;
740 int utypeidx;
741
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);
747 bad_die_ref_complaint (DIE_ID, DIE_NAME, die_ref);
748 }
749 else if (*typep != NULL)
750 {
751 utypep = *typep;
752 complaint (&symfile_complaints,
753 "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation",
754 DIE_ID, DIE_NAME);
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
769 LOCAL FUNCTION
770
771 free_utypes -- free the utypes array and reset pointer & count
772
773 SYNOPSIS
774
775 static void free_utypes (void *dummy)
776
777 DESCRIPTION
778
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.
782 */
783
784 static void
785 free_utypes (void *dummy)
786 {
787 xfree (utypes);
788 utypes = NULL;
789 numutypes = 0;
790 }
791
792
793 /*
794
795 LOCAL FUNCTION
796
797 decode_die_type -- return a type for a specified die
798
799 SYNOPSIS
800
801 static struct type *decode_die_type (struct dieinfo *dip)
802
803 DESCRIPTION
804
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.
808 */
809
810 static struct type *
811 decode_die_type (struct dieinfo *dip)
812 {
813 struct type *type = NULL;
814
815 if (dip->at_fund_type != 0)
816 {
817 type = decode_fund_type (dip->at_fund_type);
818 }
819 else if (dip->at_mod_fund_type != NULL)
820 {
821 type = decode_mod_fund_type (dip->at_mod_fund_type);
822 }
823 else if (dip->at_user_def_type)
824 {
825 if ((type = lookup_utype (dip->at_user_def_type)) == NULL)
826 {
827 type = alloc_utype (dip->at_user_def_type, NULL);
828 }
829 }
830 else if (dip->at_mod_u_d_type)
831 {
832 type = decode_mod_u_d_type (dip->at_mod_u_d_type);
833 }
834 else
835 {
836 type = dwarf_fundamental_type (current_objfile, FT_VOID);
837 }
838 return (type);
839 }
840
841 /*
842
843 LOCAL FUNCTION
844
845 struct_type -- compute and return the type for a struct or union
846
847 SYNOPSIS
848
849 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
850 char *enddie, struct objfile *objfile)
851
852 DESCRIPTION
853
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.
859 */
860
861 static struct type *
862 struct_type (struct dieinfo *dip, char *thisdie, char *enddie,
863 struct objfile *objfile)
864 {
865 struct type *type;
866 struct nextfield
867 {
868 struct nextfield *next;
869 struct field field;
870 };
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;
878
879 if ((type = lookup_utype (dip->die_ref)) == NULL)
880 {
881 /* No forward references created an empty type, so install one now */
882 type = alloc_utype (dip->die_ref, NULL);
883 }
884 INIT_CPLUS_SPECIFIC (type);
885 switch (dip->die_tag)
886 {
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;
899 complaint (&symfile_complaints,
900 "DIE @ 0x%x \"%s\", missing class, structure, or union tag",
901 DIE_ID, DIE_NAME);
902 break;
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... */
907 if (dip->at_name != NULL
908 && *dip->at_name != '~'
909 && *dip->at_name != '.')
910 {
911 TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
912 "", "", dip->at_name);
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. */
919 TYPE_LENGTH (type) = dip->at_byte_size;
920 thisdie += dip->die_length;
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));
942 new->next = list;
943 list = new;
944 /* Save the data. */
945 list->field.name =
946 obsavestring (mbr.at_name, strlen (mbr.at_name),
947 &objfile->type_obstack);
948 FIELD_TYPE (list->field) = decode_die_type (&mbr);
949 FIELD_BITPOS (list->field) = 8 * locval (&mbr);
950 FIELD_STATIC_KIND (list->field) = 0;
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
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. */
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
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. */
972 if (mbr.at_bit_size > 0)
973 {
974 if (mbr.has_at_byte_size)
975 {
976 /* The size of the anonymous object containing
977 the bit field is explicit, so use the
978 indicated size (in bytes). */
979 anonymous_size = mbr.at_byte_size;
980 }
981 else
982 {
983 /* The size of the anonymous object containing
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);
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. */
1017 for (n = nfields; list; list = list->next)
1018 {
1019 TYPE_FIELD (type, --n) = list->field;
1020 }
1021 }
1022 return (type);
1023 }
1024
1025 /*
1026
1027 LOCAL FUNCTION
1028
1029 read_structure_scope -- process all dies within struct or union
1030
1031 SYNOPSIS
1032
1033 static void read_structure_scope (struct dieinfo *dip,
1034 char *thisdie, char *enddie, struct objfile *objfile)
1035
1036 DESCRIPTION
1037
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.
1042
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).
1056
1057 */
1058
1059 static void
1060 read_structure_scope (struct dieinfo *dip, char *thisdie, char *enddie,
1061 struct objfile *objfile)
1062 {
1063 struct type *type;
1064 struct symbol *sym;
1065
1066 type = struct_type (dip, thisdie, enddie, objfile);
1067 if (!TYPE_STUB (type))
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
1083 LOCAL FUNCTION
1084
1085 decode_array_element_type -- decode type of the array elements
1086
1087 SYNOPSIS
1088
1089 static struct type *decode_array_element_type (char *scan, char *end)
1090
1091 DESCRIPTION
1092
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.
1098 */
1099
1100 static struct type *
1101 decode_array_element_type (char *scan)
1102 {
1103 struct type *typep;
1104 DIE_REF die_ref;
1105 unsigned short attribute;
1106 unsigned short fundtype;
1107 int nbytes;
1108
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 {
1114 bad_array_element_type_complaint (DIE_ID, DIE_NAME, attribute);
1115 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1116 }
1117 else
1118 {
1119 switch (attribute)
1120 {
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:
1141 bad_array_element_type_complaint (DIE_ID, DIE_NAME, attribute);
1142 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1143 break;
1144 }
1145 }
1146 return (typep);
1147 }
1148
1149 /*
1150
1151 LOCAL FUNCTION
1152
1153 decode_subscript_data_item -- decode array subscript item
1154
1155 SYNOPSIS
1156
1157 static struct type *
1158 decode_subscript_data_item (char *scan, char *end)
1159
1160 DESCRIPTION
1161
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).
1169
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.
1174
1175 The last data item is the description of the type of each of
1176 the array elements.
1177
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.
1182
1183 If we somehow fail to decode some data, we complain about it
1184 and return a type "array of int".
1185
1186 BUGS
1187 FIXME: This code only implements the forms currently used
1188 by the AT&T and GNU C compilers.
1189
1190 The end pointer is supplied for error checking, maybe we should
1191 use it for that...
1192 */
1193
1194 static struct type *
1195 decode_subscript_data_item (char *scan, char *end)
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;
1206
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. */
1229 complaint (&symfile_complaints,
1230 "DIE @ 0x%x \"%s\", can't decode subscript data items",
1231 DIE_ID, DIE_NAME);
1232 nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1233 }
1234 rangetype = create_range_type ((struct type *) NULL, indextype,
1235 lowbound, highbound);
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:
1245 complaint (&symfile_complaints,
1246 "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet",
1247 DIE_ID, DIE_NAME, format);
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:
1253 complaint (&symfile_complaints,
1254 "DIE @ 0x%x \"%s\", unknown array subscript format %x", DIE_ID,
1255 DIE_NAME, format);
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
1266 LOCAL FUNCTION
1267
1268 dwarf_read_array_type -- read TAG_array_type DIE
1269
1270 SYNOPSIS
1271
1272 static void dwarf_read_array_type (struct dieinfo *dip)
1273
1274 DESCRIPTION
1275
1276 Extract all information from a TAG_array_type DIE and add to
1277 the user defined type vector.
1278 */
1279
1280 static void
1281 dwarf_read_array_type (struct dieinfo *dip)
1282 {
1283 struct type *type;
1284 struct type *utype;
1285 char *sub;
1286 char *subend;
1287 unsigned short blocksz;
1288 int nbytes;
1289
1290 if (dip->at_ordering != ORD_row_major)
1291 {
1292 /* FIXME: Can gdb even handle column major arrays? */
1293 complaint (&symfile_complaints,
1294 "DIE @ 0x%x \"%s\", array not row major; not handled correctly",
1295 DIE_ID, DIE_NAME);
1296 }
1297 if ((sub = dip->at_subscr_data) != NULL)
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);
1304 if ((utype = lookup_utype (dip->die_ref)) == NULL)
1305 {
1306 /* Install user defined type that has not been referenced yet. */
1307 alloc_utype (dip->die_ref, type);
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. */
1325 dup_user_type_definition_complaint (DIE_ID, DIE_NAME);
1326 }
1327 }
1328 }
1329
1330 /*
1331
1332 LOCAL FUNCTION
1333
1334 read_tag_pointer_type -- read TAG_pointer_type DIE
1335
1336 SYNOPSIS
1337
1338 static void read_tag_pointer_type (struct dieinfo *dip)
1339
1340 DESCRIPTION
1341
1342 Extract all information from a TAG_pointer_type DIE and add to
1343 the user defined type vector.
1344 */
1345
1346 static void
1347 read_tag_pointer_type (struct dieinfo *dip)
1348 {
1349 struct type *type;
1350 struct type *utype;
1351
1352 type = decode_die_type (dip);
1353 if ((utype = lookup_utype (dip->die_ref)) == NULL)
1354 {
1355 utype = lookup_pointer_type (type);
1356 alloc_utype (dip->die_ref, utype);
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 */
1365 TYPE_LENGTH (utype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
1366 TYPE_CODE (utype) = TYPE_CODE_PTR;
1367 }
1368 }
1369
1370 /*
1371
1372 LOCAL FUNCTION
1373
1374 read_tag_string_type -- read TAG_string_type DIE
1375
1376 SYNOPSIS
1377
1378 static void read_tag_string_type (struct dieinfo *dip)
1379
1380 DESCRIPTION
1381
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.
1386 */
1387
1388 static void
1389 read_tag_string_type (struct dieinfo *dip)
1390 {
1391 struct type *utype;
1392 struct type *indextype;
1393 struct type *rangetype;
1394 unsigned long lowbound = 0;
1395 unsigned long highbound;
1396
1397 if (dip->has_at_byte_size)
1398 {
1399 /* A fixed bounds string */
1400 highbound = dip->at_byte_size - 1;
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);
1410
1411 utype = lookup_utype (dip->die_ref);
1412 if (utype == NULL)
1413 {
1414 /* No type defined, go ahead and create a blank one to use. */
1415 utype = alloc_utype (dip->die_ref, (struct type *) NULL);
1416 }
1417 else
1418 {
1419 /* Already a type in our slot due to a forward reference. Make sure it
1420 is a blank one. If not, complain and leave it alone. */
1421 if (TYPE_CODE (utype) != TYPE_CODE_UNDEF)
1422 {
1423 dup_user_type_definition_complaint (DIE_ID, DIE_NAME);
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
1434 LOCAL FUNCTION
1435
1436 read_subroutine_type -- process TAG_subroutine_type dies
1437
1438 SYNOPSIS
1439
1440 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1441 char *enddie)
1442
1443 DESCRIPTION
1444
1445 Handle DIES due to C code like:
1446
1447 struct foo {
1448 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1449 int b;
1450 };
1451
1452 NOTES
1453
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)
1457 */
1458
1459 static void
1460 read_subroutine_type (struct dieinfo *dip, char *thisdie, char *enddie)
1461 {
1462 struct type *type; /* Type that this function returns */
1463 struct type *ftype; /* Function that returns above type */
1464
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
1472 if ((ftype = lookup_utype (dip->die_ref)) == NULL)
1473 {
1474 /* This is the first reference to one of these types. Make
1475 a new one and place it in the user defined types. */
1476 ftype = lookup_function_type (type);
1477 alloc_utype (dip->die_ref, ftype);
1478 }
1479 else if (TYPE_CODE (ftype) == TYPE_CODE_UNDEF)
1480 {
1481 /* We have an existing partially constructed type, so bash it
1482 into the correct type. */
1483 TYPE_TARGET_TYPE (ftype) = type;
1484 TYPE_LENGTH (ftype) = 1;
1485 TYPE_CODE (ftype) = TYPE_CODE_FUNC;
1486 }
1487 else
1488 {
1489 dup_user_type_definition_complaint (DIE_ID, DIE_NAME);
1490 }
1491 }
1492
1493 /*
1494
1495 LOCAL FUNCTION
1496
1497 read_enumeration -- process dies which define an enumeration
1498
1499 SYNOPSIS
1500
1501 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1502 char *enddie, struct objfile *objfile)
1503
1504 DESCRIPTION
1505
1506 Given a pointer to a die which begins an enumeration, process all
1507 the dies that define the members of the enumeration.
1508
1509 NOTES
1510
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).
1514 */
1515
1516 static void
1517 read_enumeration (struct dieinfo *dip, char *thisdie, char *enddie,
1518 struct objfile *objfile)
1519 {
1520 struct type *type;
1521 struct symbol *sym;
1522
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
1537 LOCAL FUNCTION
1538
1539 enum_type -- decode and return a type for an enumeration
1540
1541 SYNOPSIS
1542
1543 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1544
1545 DESCRIPTION
1546
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.
1550
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.
1554
1555 NOTES
1556
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.
1564 */
1565
1566 static struct type *
1567 enum_type (struct dieinfo *dip, struct objfile *objfile)
1568 {
1569 struct type *type;
1570 struct nextfield
1571 {
1572 struct nextfield *next;
1573 struct field field;
1574 };
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;
1585
1586 if ((type = lookup_utype (dip->die_ref)) == NULL)
1587 {
1588 /* No forward references created an empty type, so install one now */
1589 type = alloc_utype (dip->die_ref, NULL);
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... */
1595 if (dip->at_name != NULL
1596 && *dip->at_name != '~'
1597 && *dip->at_name != '.')
1598 {
1599 TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
1600 "", "", dip->at_name);
1601 }
1602 if (dip->at_byte_size != 0)
1603 {
1604 TYPE_LENGTH (type) = dip->at_byte_size;
1605 }
1606 if ((scan = dip->at_element_list) != NULL)
1607 {
1608 if (dip->short_element_list)
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));
1622 new->next = list;
1623 list = new;
1624 FIELD_TYPE (list->field) = NULL;
1625 FIELD_BITSIZE (list->field) = 0;
1626 FIELD_STATIC_KIND (list->field) = 0;
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);
1631 list->field.name = obsavestring (scan, strlen (scan),
1632 &objfile->type_obstack);
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));
1639 SYMBOL_NAME (sym) = create_name (list->field.name,
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
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. */
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. */
1663 for (n = 0; (n < nfields) && (list != NULL); list = list->next)
1664 {
1665 TYPE_FIELD (type, n++) = list->field;
1666 }
1667 }
1668 }
1669 return (type);
1670 }
1671
1672 /*
1673
1674 LOCAL FUNCTION
1675
1676 read_func_scope -- process all dies within a function scope
1677
1678 DESCRIPTION
1679
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)
1691 */
1692
1693 static void
1694 read_func_scope (struct dieinfo *dip, char *thisdie, char *enddie,
1695 struct objfile *objfile)
1696 {
1697 register struct context_stack *new;
1698
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. */
1703 if (dip->at_name == NULL)
1704 {
1705 complaint (&symfile_complaints, "DIE @ 0x%x, AT_name tag missing",
1706 DIE_ID);
1707 return;
1708 }
1709
1710 if (objfile->ei.entry_point >= dip->at_low_pc &&
1711 objfile->ei.entry_point < dip->at_high_pc)
1712 {
1713 objfile->ei.entry_func_lowpc = dip->at_low_pc;
1714 objfile->ei.entry_func_highpc = dip->at_high_pc;
1715 }
1716 new = push_context (0, dip->at_low_pc);
1717 new->name = new_symbol (dip, objfile);
1718 list_in_scope = &local_symbols;
1719 process_dies (thisdie + dip->die_length, enddie, objfile);
1720 new = pop_context ();
1721 /* Make a block for the local symbols within. */
1722 finish_block (new->name, &local_symbols, new->old_blocks,
1723 new->start_addr, dip->at_high_pc, objfile);
1724 list_in_scope = &file_symbols;
1725 }
1726
1727
1728 /*
1729
1730 LOCAL FUNCTION
1731
1732 handle_producer -- process the AT_producer attribute
1733
1734 DESCRIPTION
1735
1736 Perform any operations that depend on finding a particular
1737 AT_producer attribute.
1738
1739 */
1740
1741 static void
1742 handle_producer (char *producer)
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 =
1756 STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER));
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 {
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. */
1771 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1772 #endif
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
1784 LOCAL FUNCTION
1785
1786 read_file_scope -- process all dies within a file scope
1787
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.
1794
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.
1802 */
1803
1804 static void
1805 read_file_scope (struct dieinfo *dip, char *thisdie, char *enddie,
1806 struct objfile *objfile)
1807 {
1808 struct cleanup *back_to;
1809 struct symtab *symtab;
1810
1811 if (objfile->ei.entry_point >= dip->at_low_pc &&
1812 objfile->ei.entry_point < dip->at_high_pc)
1813 {
1814 objfile->ei.entry_file_lowpc = dip->at_low_pc;
1815 objfile->ei.entry_file_highpc = dip->at_high_pc;
1816 }
1817 set_cu_language (dip);
1818 if (dip->at_producer != NULL)
1819 {
1820 handle_producer (dip->at_producer);
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 *));
1827 start_symtab (dip->at_name, dip->at_comp_dir, dip->at_low_pc);
1828 record_debugformat ("DWARF 1");
1829 decode_line_numbers (lnbase);
1830 process_dies (thisdie + dip->die_length, enddie, objfile);
1831
1832 symtab = end_symtab (dip->at_high_pc, objfile, 0);
1833 if (symtab != NULL)
1834 {
1835 symtab->language = cu_language;
1836 }
1837 do_cleanups (back_to);
1838 }
1839
1840 /*
1841
1842 LOCAL FUNCTION
1843
1844 process_dies -- process a range of DWARF Information Entries
1845
1846 SYNOPSIS
1847
1848 static void process_dies (char *thisdie, char *enddie,
1849 struct objfile *objfile)
1850
1851 DESCRIPTION
1852
1853 Process all DIE's in a specified range. May be (and almost
1854 certainly will be) called recursively.
1855 */
1856
1857 static void
1858 process_dies (char *thisdie, char *enddie, struct objfile *objfile)
1859 {
1860 char *nextdie;
1861 struct dieinfo di;
1862
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 }
1885 /* I think that these are always text, not data, addresses. */
1886 di.at_low_pc = SMASH_TEXT_ADDRESS (di.at_low_pc);
1887 di.at_high_pc = SMASH_TEXT_ADDRESS (di.at_high_pc);
1888 switch (di.die_tag)
1889 {
1890 case TAG_compile_unit:
1891 /* Skip Tag_compile_unit if we are already inside a compilation
1892 unit, we are unable to handle nested compilation units
1893 properly (FIXME). */
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
1940 LOCAL FUNCTION
1941
1942 decode_line_numbers -- decode a line number table fragment
1943
1944 SYNOPSIS
1945
1946 static void decode_line_numbers (char *tblscan, char *tblend,
1947 long length, long base, long line, long pc)
1948
1949 DESCRIPTION
1950
1951 Translate the DWARF line number information to gdb form.
1952
1953 The ".line" section contains one or more line number tables, one for
1954 each ".line" section from the objects that were linked.
1955
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.
1959
1960 The table itself has the following structure:
1961
1962 <table length><base address><source statement entry>
1963 4 bytes 4 bytes 10 bytes
1964
1965 The table length is the total size of the table, including the 4 bytes
1966 for the length information.
1967
1968 The base address is the address of the first instruction generated
1969 for the source file.
1970
1971 Each source statement entry has the following structure:
1972
1973 <line number><statement position><address delta>
1974 4 bytes 2 bytes 4 bytes
1975
1976 The line number is relative to the start of the file, starting with
1977 line 1.
1978
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.
1981
1982 The address delta is the difference between the base address and
1983 the address of the first instruction for the statement.
1984
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.
1988
1989 BUGS
1990
1991 Does gdb expect the line numbers to be sorted? They are now by
1992 chance/luck, but are not required to be. (FIXME)
1993
1994 The line with number 0 is unused, gdb apparently can discover the
1995 span of the last line some other way. How? (FIXME)
1996 */
1997
1998 static void
1999 decode_line_numbers (char *linetable)
2000 {
2001 char *tblscan;
2002 char *tblend;
2003 unsigned long length;
2004 unsigned long base;
2005 unsigned long line;
2006 unsigned long pc;
2007
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
2038 LOCAL FUNCTION
2039
2040 locval -- compute the value of a location attribute
2041
2042 SYNOPSIS
2043
2044 static int locval (struct dieinfo *dip)
2045
2046 DESCRIPTION
2047
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.
2053
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.
2058
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.
2069 */
2070
2071 static int
2072 locval (struct dieinfo *dip)
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;
2082
2083 loc = dip->at_location;
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;
2090 dip->isreg = 0;
2091 dip->offreg = 0;
2092 dip->optimized_out = 1;
2093 loc_value_size = TARGET_FT_LONG_SIZE (current_objfile);
2094 while (loc < end)
2095 {
2096 dip->optimized_out = 0;
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 {
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) */
2139 complaint (&symfile_complaints,
2140 "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%lx not handled",
2141 DIE_ID, DIE_NAME, stack[stacki]);
2142 break;
2143 case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */
2144 complaint (&symfile_complaints,
2145 "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%lx not handled",
2146 DIE_ID, DIE_NAME, stack[stacki]);
2147 break;
2148 case OP_ADD: /* pop top 2 items, add, push result */
2149 stack[stacki - 1] += stack[stacki];
2150 stacki--;
2151 break;
2152 }
2153 }
2154 return (stack[stacki]);
2155 }
2156
2157 /*
2158
2159 LOCAL FUNCTION
2160
2161 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
2162
2163 SYNOPSIS
2164
2165 static void read_ofile_symtab (struct partial_symtab *pst)
2166
2167 DESCRIPTION
2168
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.
2174 */
2175
2176 static void
2177 read_ofile_symtab (struct partial_symtab *pst)
2178 {
2179 struct cleanup *back_to;
2180 unsigned long lnsize;
2181 file_ptr foffset;
2182 bfd *abfd;
2183 char lnsizedata[SIZEOF_LINETBL_LENGTH];
2184
2185 abfd = pst->objfile->obfd;
2186 current_objfile = pst->objfile;
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);
2194 dbroff = DBROFF (pst);
2195 foffset = DBFOFF (pst) + dbroff;
2196 base_section_offsets = pst->section_offsets;
2197 baseaddr = ANOFFSET (pst->section_offsets, 0);
2198 if (bfd_seek (abfd, foffset, SEEK_SET) ||
2199 (bfd_bread (dbbase, dbsize, abfd) != dbsize))
2200 {
2201 xfree (dbbase);
2202 error ("can't read DWARF data");
2203 }
2204 back_to = make_cleanup (xfree, dbbase);
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) ||
2215 (bfd_bread (lnsizedata, sizeof (lnsizedata), abfd)
2216 != sizeof (lnsizedata)))
2217 {
2218 error ("can't read DWARF line number table size");
2219 }
2220 lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH,
2221 GET_UNSIGNED, pst->objfile);
2222 lnbase = xmalloc (lnsize);
2223 if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
2224 (bfd_bread (lnbase, lnsize, abfd) != lnsize))
2225 {
2226 xfree (lnbase);
2227 error ("can't read DWARF line numbers");
2228 }
2229 make_cleanup (xfree, lnbase);
2230 }
2231
2232 process_dies (dbbase, dbbase + dbsize, pst->objfile);
2233 do_cleanups (back_to);
2234 current_objfile = NULL;
2235 pst->symtab = pst->objfile->symtabs;
2236 }
2237
2238 /*
2239
2240 LOCAL FUNCTION
2241
2242 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
2243
2244 SYNOPSIS
2245
2246 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
2247
2248 DESCRIPTION
2249
2250 Called once for each partial symbol table entry that needs to be
2251 expanded into a full symbol table entry.
2252
2253 */
2254
2255 static void
2256 psymtab_to_symtab_1 (struct partial_symtab *pst)
2257 {
2258 int i;
2259 struct cleanup *old_chain;
2260
2261 if (pst != NULL)
2262 {
2263 if (pst->readin)
2264 {
2265 warning ("psymtab for %s already read in. Shouldn't happen.",
2266 pst->filename);
2267 }
2268 else
2269 {
2270 /* Read in all partial symtabs on which this one is dependent */
2271 for (i = 0; i < pst->number_of_dependencies; i++)
2272 {
2273 if (!pst->dependencies[i]->readin)
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...",
2283 pst->dependencies[i]->filename);
2284 wrap_here ("");
2285 gdb_flush (gdb_stdout); /* Flush output */
2286 }
2287 psymtab_to_symtab_1 (pst->dependencies[i]);
2288 }
2289 }
2290 if (DBLENGTH (pst)) /* Otherwise it's a dummy */
2291 {
2292 buildsym_init ();
2293 old_chain = make_cleanup (really_free_pendings, 0);
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 }
2301 sort_symtab_syms (pst->symtab);
2302 do_cleanups (old_chain);
2303 }
2304 pst->readin = 1;
2305 }
2306 }
2307 }
2308
2309 /*
2310
2311 LOCAL FUNCTION
2312
2313 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2314
2315 SYNOPSIS
2316
2317 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2318
2319 DESCRIPTION
2320
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.
2324
2325 */
2326
2327 static void
2328 dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2329 {
2330
2331 if (pst != NULL)
2332 {
2333 if (pst->readin)
2334 {
2335 warning ("psymtab for %s already read in. Shouldn't happen.",
2336 pst->filename);
2337 }
2338 else
2339 {
2340 if (DBLENGTH (pst) || pst->number_of_dependencies)
2341 {
2342 /* Print the message now, before starting serious work, to avoid
2343 disconcerting pauses. */
2344 if (info_verbose)
2345 {
2346 printf_filtered ("Reading in symbols for %s...",
2347 pst->filename);
2348 gdb_flush (gdb_stdout);
2349 }
2350
2351 psymtab_to_symtab_1 (pst);
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);
2360 #endif
2361
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
2375 LOCAL FUNCTION
2376
2377 add_enum_psymbol -- add enumeration members to partial symbol table
2378
2379 DESCRIPTION
2380
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 */
2385
2386 static void
2387 add_enum_psymbol (struct dieinfo *dip, struct objfile *objfile)
2388 {
2389 char *scan;
2390 char *listend;
2391 unsigned short blocksz;
2392 int nbytes;
2393
2394 if ((scan = dip->at_element_list) != NULL)
2395 {
2396 if (dip->short_element_list)
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,
2411 &objfile->static_psymbols, 0, 0, cu_language,
2412 objfile);
2413 scan += strlen (scan) + 1;
2414 }
2415 }
2416 }
2417
2418 /*
2419
2420 LOCAL FUNCTION
2421
2422 add_partial_symbol -- add symbol to partial symbol table
2423
2424 DESCRIPTION
2425
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.
2429
2430 NOTES
2431
2432 The caller must ensure that the DIE has a valid name attribute.
2433 */
2434
2435 static void
2436 add_partial_symbol (struct dieinfo *dip, struct objfile *objfile)
2437 {
2438 switch (dip->die_tag)
2439 {
2440 case TAG_global_subroutine:
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);
2445 break;
2446 case TAG_global_variable:
2447 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2448 VAR_NAMESPACE, LOC_STATIC,
2449 &objfile->global_psymbols,
2450 0, 0, cu_language, objfile);
2451 break;
2452 case TAG_subroutine:
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);
2457 break;
2458 case TAG_local_variable:
2459 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2460 VAR_NAMESPACE, LOC_STATIC,
2461 &objfile->static_psymbols,
2462 0, 0, cu_language, objfile);
2463 break;
2464 case TAG_typedef:
2465 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2466 VAR_NAMESPACE, LOC_TYPEDEF,
2467 &objfile->static_psymbols,
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. */
2475 if (!dip->has_at_byte_size)
2476 break;
2477 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2478 STRUCT_NAMESPACE, LOC_TYPEDEF,
2479 &objfile->static_psymbols,
2480 0, 0, cu_language, objfile);
2481 if (cu_language == language_cplus)
2482 {
2483 /* For C++, these implicitly act as typedefs as well. */
2484 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2485 VAR_NAMESPACE, LOC_TYPEDEF,
2486 &objfile->static_psymbols,
2487 0, 0, cu_language, objfile);
2488 }
2489 break;
2490 }
2491 }
2492 /* *INDENT-OFF* */
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 */
2556 /* *INDENT-ON* */
2557
2558
2559
2560 static void
2561 scan_partial_symbols (char *thisdie, char *enddie, struct objfile *objfile)
2562 {
2563 char *nextdie;
2564 char *temp;
2565 struct dieinfo di;
2566
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 {
2596 bad_die_ref_complaint (DIE_ID, DIE_NAME,
2597 di.at_sibling);
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
2640 LOCAL FUNCTION
2641
2642 scan_compilation_units -- build a psymtab entry for each compilation
2643
2644 DESCRIPTION
2645
2646 This is the top level dwarf parsing routine for building partial
2647 symbol tables.
2648
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
2667
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.
2674
2675 RETURNS
2676
2677 Returns no value.
2678
2679 */
2680
2681 static void
2682 scan_compilation_units (char *thisdie, char *enddie, file_ptr dbfoff,
2683 file_ptr lnoffset, struct objfile *objfile)
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,
2723 objfile->global_psymbols.next,
2724 objfile->static_psymbols.next);
2725
2726 pst->texthigh = di.at_high_pc;
2727 pst->read_symtab_private = (char *)
2728 obstack_alloc (&objfile->psymbol_obstack,
2729 sizeof (struct dwfinfo));
2730 DBFOFF (pst) = dbfoff;
2731 DBROFF (pst) = curoff;
2732 DBLENGTH (pst) = culength;
2733 LNFOFF (pst) = curlnoffset;
2734 pst->read_symtab = dwarf_psymtab_to_symtab;
2735
2736 /* Now look for partial symbols */
2737
2738 scan_partial_symbols (thisdie + di.die_length, nextdie, objfile);
2739
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);
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. */
2748 free_named_symtabs (pst->filename);
2749 }
2750 thisdie = nextdie;
2751 }
2752 }
2753
2754 /*
2755
2756 LOCAL FUNCTION
2757
2758 new_symbol -- make a symbol table entry for a new symbol
2759
2760 SYNOPSIS
2761
2762 static struct symbol *new_symbol (struct dieinfo *dip,
2763 struct objfile *objfile)
2764
2765 DESCRIPTION
2766
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.
2770 */
2771
2772 static struct symbol *
2773 new_symbol (struct dieinfo *dip, struct objfile *objfile)
2774 {
2775 struct symbol *sym = NULL;
2776
2777 if (dip->at_name != NULL)
2778 {
2779 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
2780 sizeof (struct symbol));
2781 OBJSTAT (objfile, n_syms++);
2782 memset (sym, 0, sizeof (struct symbol));
2783 SYMBOL_NAME (sym) = create_name (dip->at_name,
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
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. */
2794
2795 SYMBOL_LANGUAGE (sym) = cu_language;
2796 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
2797 switch (dip->die_tag)
2798 {
2799 case TAG_label:
2800 SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
2801 SYMBOL_CLASS (sym) = LOC_LABEL;
2802 break;
2803 case TAG_global_subroutine:
2804 case TAG_subroutine:
2805 SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
2806 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
2807 if (dip->at_prototyped)
2808 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
2809 SYMBOL_CLASS (sym) = LOC_BLOCK;
2810 if (dip->die_tag == TAG_global_subroutine)
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:
2820 if (dip->at_location != NULL)
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:
2829 if (dip->at_location != NULL)
2830 {
2831 int loc = locval (dip);
2832 if (dip->optimized_out)
2833 {
2834 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
2835 }
2836 else if (dip->isreg)
2837 {
2838 SYMBOL_CLASS (sym) = LOC_REGISTER;
2839 }
2840 else if (dip->offreg)
2841 {
2842 SYMBOL_CLASS (sym) = LOC_BASEREG;
2843 SYMBOL_BASEREG (sym) = dip->basereg;
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:
2864 if (dip->at_location != NULL)
2865 {
2866 SYMBOL_VALUE (sym) = locval (dip);
2867 }
2868 add_symbol_to_list (sym, list_in_scope);
2869 if (dip->isreg)
2870 {
2871 SYMBOL_CLASS (sym) = LOC_REGPARM;
2872 }
2873 else if (dip->offreg)
2874 {
2875 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
2876 SYMBOL_BASEREG (sym) = dip->basereg;
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
2912 LOCAL FUNCTION
2913
2914 synthesize_typedef -- make a symbol table entry for a "fake" typedef
2915
2916 SYNOPSIS
2917
2918 static void synthesize_typedef (struct dieinfo *dip,
2919 struct objfile *objfile,
2920 struct type *type);
2921
2922 DESCRIPTION
2923
2924 Given a pointer to a DWARF information entry, synthesize a typedef
2925 for the name in the DIE, using the specified type.
2926
2927 This is used for C++ class, structs, unions, and enumerations to
2928 set up the tag name as a type.
2929
2930 */
2931
2932 static void
2933 synthesize_typedef (struct dieinfo *dip, struct objfile *objfile,
2934 struct type *type)
2935 {
2936 struct symbol *sym = NULL;
2937
2938 if (dip->at_name != NULL)
2939 {
2940 sym = (struct symbol *)
2941 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2942 OBJSTAT (objfile, n_syms++);
2943 memset (sym, 0, sizeof (struct symbol));
2944 SYMBOL_NAME (sym) = create_name (dip->at_name,
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
2956 LOCAL FUNCTION
2957
2958 decode_mod_fund_type -- decode a modified fundamental type
2959
2960 SYNOPSIS
2961
2962 static struct type *decode_mod_fund_type (char *typedata)
2963
2964 DESCRIPTION
2965
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.
2972
2973 We simply compute the number of modifiers and call the general
2974 function decode_modified_type to do the actual work.
2975 */
2976
2977 static struct type *
2978 decode_mod_fund_type (char *typedata)
2979 {
2980 struct type *typep = NULL;
2981 unsigned short modcount;
2982 int nbytes;
2983
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
3002 LOCAL FUNCTION
3003
3004 decode_mod_u_d_type -- decode a modified user defined type
3005
3006 SYNOPSIS
3007
3008 static struct type *decode_mod_u_d_type (char *typedata)
3009
3010 DESCRIPTION
3011
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.
3018
3019 We simply compute the number of modifiers and call the general
3020 function decode_modified_type to do the actual work.
3021 */
3022
3023 static struct type *
3024 decode_mod_u_d_type (char *typedata)
3025 {
3026 struct type *typep = NULL;
3027 unsigned short modcount;
3028 int nbytes;
3029
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
3048 LOCAL FUNCTION
3049
3050 decode_modified_type -- decode modified user or fundamental type
3051
3052 SYNOPSIS
3053
3054 static struct type *decode_modified_type (char *modifiers,
3055 unsigned short modcount, int mtype)
3056
3057 DESCRIPTION
3058
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.
3067
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
3075
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.
3079
3080 BUGS
3081
3082 We currently ignore MOD_const and MOD_volatile. (FIXME)
3083
3084 */
3085
3086 static struct type *
3087 decode_modified_type (char *modifiers, unsigned int modcount, int mtype)
3088 {
3089 struct type *typep = NULL;
3090 unsigned short fundtype;
3091 DIE_REF die_ref;
3092 char modifier;
3093 int nbytes;
3094
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:
3115 complaint (&symfile_complaints,
3116 "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)",
3117 DIE_ID, DIE_NAME, mtype);
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 {
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:
3135 complaint (&symfile_complaints,
3136 "DIE @ 0x%x \"%s\", type modifier 'const' ignored", DIE_ID,
3137 DIE_NAME); /* FIXME */
3138 break;
3139 case MOD_volatile:
3140 complaint (&symfile_complaints,
3141 "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored",
3142 DIE_ID, DIE_NAME); /* FIXME */
3143 break;
3144 default:
3145 if (!(MOD_lo_user <= (unsigned char) modifier
3146 && (unsigned char) modifier <= MOD_hi_user))
3147 {
3148 complaint (&symfile_complaints,
3149 "DIE @ 0x%x \"%s\", unknown type modifier %u", DIE_ID,
3150 DIE_NAME, modifier);
3151 }
3152 break;
3153 }
3154 }
3155 return (typep);
3156 }
3157
3158 /*
3159
3160 LOCAL FUNCTION
3161
3162 decode_fund_type -- translate basic DWARF type to gdb base type
3163
3164 DESCRIPTION
3165
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 *").
3169
3170 NOTES
3171
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 */
3179
3180 static struct type *
3181 decode_fund_type (unsigned int fundtype)
3182 {
3183 struct type *typep = NULL;
3184
3185 switch (fundtype)
3186 {
3187
3188 case FT_void:
3189 typep = dwarf_fundamental_type (current_objfile, FT_VOID);
3190 break;
3191
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;
3200
3201 case FT_char:
3202 typep = dwarf_fundamental_type (current_objfile, FT_CHAR);
3203 break;
3204
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;
3212
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;
3220
3221 case FT_unsigned_short:
3222 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
3223 break;
3224
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;
3232
3233 case FT_unsigned_integer:
3234 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
3235 break;
3236
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;
3244
3245 case FT_unsigned_long:
3246 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
3247 break;
3248
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;
3264
3265 case FT_dbl_prec_float:
3266 typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
3267 break;
3268
3269 case FT_ext_prec_float:
3270 typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
3271 break;
3272
3273 case FT_complex:
3274 typep = dwarf_fundamental_type (current_objfile, FT_COMPLEX);
3275 break;
3276
3277 case FT_dbl_prec_complex:
3278 typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
3279 break;
3280
3281 case FT_ext_prec_complex:
3282 typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX);
3283 break;
3284
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 {
3292 complaint (&symfile_complaints,
3293 "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x",
3294 DIE_ID, DIE_NAME, fundtype);
3295 }
3296 }
3297
3298 return (typep);
3299 }
3300
3301 /*
3302
3303 LOCAL FUNCTION
3304
3305 create_name -- allocate a fresh copy of a string on an obstack
3306
3307 DESCRIPTION
3308
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.
3311
3312 */
3313
3314 static char *
3315 create_name (char *name, struct obstack *obstackp)
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
3328 LOCAL FUNCTION
3329
3330 basicdieinfo -- extract the minimal die info from raw die data
3331
3332 SYNOPSIS
3333
3334 void basicdieinfo (char *diep, struct dieinfo *dip,
3335 struct objfile *objfile)
3336
3337 DESCRIPTION
3338
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.
3343
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.
3348
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.
3355
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.
3360
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.
3367
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.
3378 */
3379
3380 static void
3381 basicdieinfo (struct dieinfo *dip, char *diep, struct objfile *objfile)
3382 {
3383 curdie = dip;
3384 memset (dip, 0, sizeof (struct dieinfo));
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)))
3391 {
3392 complaint (&symfile_complaints,
3393 "DIE @ 0x%x \"%s\", malformed DIE, bad length (%ld bytes)",
3394 DIE_ID, DIE_NAME, dip->die_length);
3395 dip->die_length = 0;
3396 }
3397 else if (dip->die_length < (SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG))
3398 {
3399 dip->die_tag = TAG_padding;
3400 }
3401 else
3402 {
3403 diep += SIZEOF_DIE_LENGTH;
3404 dip->die_tag = target_to_host (diep, SIZEOF_DIE_TAG, GET_UNSIGNED,
3405 objfile);
3406 }
3407 }
3408
3409 /*
3410
3411 LOCAL FUNCTION
3412
3413 completedieinfo -- finish reading the information for a given DIE
3414
3415 SYNOPSIS
3416
3417 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3418
3419 DESCRIPTION
3420
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.
3424
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.
3431
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.
3438
3439 */
3440
3441 static void
3442 completedieinfo (struct dieinfo *dip, struct objfile *objfile)
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 */
3449
3450 diecount++;
3451 diep = dip->die;
3452 end = diep + dip->die_length;
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 {
3460 complaint (&symfile_complaints,
3461 "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes",
3462 DIE_ID, DIE_NAME);
3463 diep = end;
3464 continue;
3465 }
3466 switch (attr)
3467 {
3468 case AT_fund_type:
3469 dip->at_fund_type = target_to_host (diep, nbytes, GET_UNSIGNED,
3470 objfile);
3471 break;
3472 case AT_ordering:
3473 dip->at_ordering = target_to_host (diep, nbytes, GET_UNSIGNED,
3474 objfile);
3475 break;
3476 case AT_bit_offset:
3477 dip->at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED,
3478 objfile);
3479 break;
3480 case AT_sibling:
3481 dip->at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED,
3482 objfile);
3483 break;
3484 case AT_stmt_list:
3485 dip->at_stmt_list = target_to_host (diep, nbytes, GET_UNSIGNED,
3486 objfile);
3487 dip->has_at_stmt_list = 1;
3488 break;
3489 case AT_low_pc:
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;
3494 break;
3495 case AT_high_pc:
3496 dip->at_high_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
3497 objfile);
3498 dip->at_high_pc += baseaddr;
3499 break;
3500 case AT_language:
3501 dip->at_language = target_to_host (diep, nbytes, GET_UNSIGNED,
3502 objfile);
3503 break;
3504 case AT_user_def_type:
3505 dip->at_user_def_type = target_to_host (diep, nbytes,
3506 GET_UNSIGNED, objfile);
3507 break;
3508 case AT_byte_size:
3509 dip->at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3510 objfile);
3511 dip->has_at_byte_size = 1;
3512 break;
3513 case AT_bit_size:
3514 dip->at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3515 objfile);
3516 break;
3517 case AT_member:
3518 dip->at_member = target_to_host (diep, nbytes, GET_UNSIGNED,
3519 objfile);
3520 break;
3521 case AT_discr:
3522 dip->at_discr = target_to_host (diep, nbytes, GET_UNSIGNED,
3523 objfile);
3524 break;
3525 case AT_location:
3526 dip->at_location = diep;
3527 break;
3528 case AT_mod_fund_type:
3529 dip->at_mod_fund_type = diep;
3530 break;
3531 case AT_subscr_data:
3532 dip->at_subscr_data = diep;
3533 break;
3534 case AT_mod_u_d_type:
3535 dip->at_mod_u_d_type = diep;
3536 break;
3537 case AT_element_list:
3538 dip->at_element_list = diep;
3539 dip->short_element_list = 0;
3540 break;
3541 case AT_short_element_list:
3542 dip->at_element_list = diep;
3543 dip->short_element_list = 1;
3544 break;
3545 case AT_discr_value:
3546 dip->at_discr_value = diep;
3547 break;
3548 case AT_string_length:
3549 dip->at_string_length = diep;
3550 break;
3551 case AT_name:
3552 dip->at_name = diep;
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). */
3557 dip->at_comp_dir = strrchr (diep, ':');
3558 if (dip->at_comp_dir != NULL)
3559 {
3560 dip->at_comp_dir++;
3561 }
3562 else
3563 {
3564 dip->at_comp_dir = diep;
3565 }
3566 break;
3567 case AT_producer:
3568 dip->at_producer = diep;
3569 break;
3570 case AT_start_scope:
3571 dip->at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED,
3572 objfile);
3573 break;
3574 case AT_stride_size:
3575 dip->at_stride_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3576 objfile);
3577 break;
3578 case AT_src_info:
3579 dip->at_src_info = target_to_host (diep, nbytes, GET_UNSIGNED,
3580 objfile);
3581 break;
3582 case AT_prototyped:
3583 dip->at_prototyped = diep;
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:
3619 unknown_attribute_form_complaint (DIE_ID, DIE_NAME, form);
3620 diep = end;
3621 break;
3622 }
3623 }
3624 }
3625
3626 /*
3627
3628 LOCAL FUNCTION
3629
3630 target_to_host -- swap in target data to host
3631
3632 SYNOPSIS
3633
3634 target_to_host (char *from, int nbytes, int signextend,
3635 struct objfile *objfile)
3636
3637 DESCRIPTION
3638
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.
3644
3645 NOTES
3646
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.
3650
3651 FIXME: Would a 32 bit target ever need an 8 byte result?
3652
3653 */
3654
3655 static CORE_ADDR
3656 target_to_host (char *from, int nbytes, int signextend, /* FIXME: Unused */
3657 struct objfile *objfile)
3658 {
3659 CORE_ADDR rtnval;
3660
3661 switch (nbytes)
3662 {
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:
3676 complaint (&symfile_complaints,
3677 "DIE @ 0x%x \"%s\", no bfd support for %d byte data object",
3678 DIE_ID, DIE_NAME, nbytes);
3679 rtnval = 0;
3680 break;
3681 }
3682 return (rtnval);
3683 }
3684
3685 /*
3686
3687 LOCAL FUNCTION
3688
3689 attribute_size -- compute size of data for a DWARF attribute
3690
3691 SYNOPSIS
3692
3693 static int attribute_size (unsigned int attr)
3694
3695 DESCRIPTION
3696
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.
3700
3701 Returns -1 for unrecognized attributes.
3702
3703 */
3704
3705 static int
3706 attribute_size (unsigned int attr)
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 {
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:
3733 unknown_attribute_form_complaint (DIE_ID, DIE_NAME, form);
3734 nbytes = -1;
3735 break;
3736 }
3737 return (nbytes);
3738 }
This page took 0.158806 seconds and 4 git commands to generate.