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