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