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