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