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