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