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