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