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