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