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