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