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