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