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