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