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