Fixed segmentation violation detected by LD testsuite.
[deliverable/binutils-gdb.git] / gdb / hpread.c
CommitLineData
98c0e047 1/* Read hp debug symbols and convert to internal format, for GDB.
436d4143 2 Copyright 1993, 1996 Free Software Foundation, Inc.
98c0e047
JL
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
6c9638b4 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
98c0e047
JL
19
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
22
23#include "defs.h"
24#include "bfd.h"
2b576293 25#include "gdb_string.h"
2848f793 26#include "hp-symtab.h"
98c0e047
JL
27#include "syms.h"
28#include "symtab.h"
29#include "symfile.h"
30#include "objfiles.h"
31#include "buildsym.h"
32#include "complaints.h"
33#include "gdb-stabs.h"
34#include "gdbtypes.h"
eae8aa30 35#include "demangle.h"
98c0e047
JL
36
37/* Private information attached to an objfile which we use to find
38 and internalize the HP C debug symbols within that objfile. */
39
40struct hpread_symfile_info
41{
42 /* The contents of each of the debug sections (there are 4 of them). */
43 char *gntt;
44 char *lntt;
45 char *slt;
46 char *vt;
47
48 /* We keep the size of the $VT$ section for range checking. */
49 unsigned int vt_size;
50
51 /* Some routines still need to know the number of symbols in the
52 main debug sections ($LNTT$ and $GNTT$). */
53 unsigned int lntt_symcount;
54 unsigned int gntt_symcount;
55
56 /* To keep track of all the types we've processed. */
57 struct type **type_vector;
58 int type_vector_length;
59
60 /* Keeps track of the beginning of a range of source lines. */
2848f793 61 sltpointer sl_index;
98c0e047
JL
62
63 /* Some state variables we'll need. */
98c0e047
JL
64 int within_function;
65
38ab0632
JL
66 /* Keep track of the current function's address. We may need to look
67 up something based on this address. */
68 unsigned int current_function_value;
98c0e047
JL
69};
70
71/* Accessor macros to get at the fields. */
72#define HPUX_SYMFILE_INFO(o) \
73 ((struct hpread_symfile_info *)((o)->sym_private))
74#define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
75#define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
76#define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
77#define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
78#define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
79#define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
80#define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
81#define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
82#define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
83#define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
98c0e047
JL
84#define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
85#define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
86
87/* Given the native debug symbol SYM, set NAMEP to the name associated
88 with the debug symbol. Note we may be called with a debug symbol which
89 has no associated name, in that case we return an empty string.
90
91 Also note we "know" that the name for any symbol is always in the
92 same place. Hence we don't have to conditionalize on the symbol type. */
93#define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
94 if (! hpread_has_name ((SYM)->dblock.kind)) \
95 *NAMEP = ""; \
96 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
97 { \
98 complain (&string_table_offset_complaint, (char *) symnum); \
99 *NAMEP = ""; \
100 } \
101 else \
102 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
989d9cba 103\f
f133a597
JK
104/* We put a pointer to this structure in the read_symtab_private field
105 of the psymtab. */
98c0e047
JL
106
107struct symloc
108{
989d9cba
JK
109 /* The offset within the file symbol table of first local symbol for
110 this file. */
111
98c0e047 112 int ldsymoff;
989d9cba
JK
113
114 /* Length (in bytes) of the section of the symbol table devoted to
115 this file's symbols (actually, the section bracketed may contain
116 more than just this file's symbols). If ldsymlen is 0, the only
117 reason for this thing's existence is the dependency list.
118 Nothing else will happen when it is read in. */
119
98c0e047
JL
120 int ldsymlen;
121};
122
989d9cba
JK
123#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
124#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
125#define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
126\f
98c0e047
JL
127/* FIXME: Shouldn't this stuff be in a .h file somewhere? */
128/* Nonzero means give verbose info on gdb action. */
129extern int info_verbose;
130
131/* Complaints about the symbols we have encountered. */
132extern struct complaint string_table_offset_complaint;
133extern struct complaint lbrac_unmatched_complaint;
134extern struct complaint lbrac_mismatch_complaint;
135
136\f
137void hpread_symfile_init PARAMS ((struct objfile *));
138
3f550b59
FF
139static struct type *
140hpread_read_array_type PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
141
98c0e047 142static struct type *hpread_alloc_type
2848f793 143 PARAMS ((dnttpointer, struct objfile *));
98c0e047
JL
144
145static struct type **hpread_lookup_type
2848f793 146 PARAMS ((dnttpointer, struct objfile *));
98c0e047
JL
147
148static struct type *hpread_read_enum_type
2848f793 149 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
98c0e047
JL
150
151static struct type *hpread_read_set_type
2848f793 152 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
98c0e047
JL
153
154static struct type *hpread_read_subrange_type
2848f793 155 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
98c0e047
JL
156
157static struct type *hpread_read_struct_type
2848f793 158 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
98c0e047
JL
159
160void hpread_build_psymtabs
161 PARAMS ((struct objfile *, struct section_offsets *, int));
162
163void hpread_symfile_finish PARAMS ((struct objfile *));
164
165static struct partial_symtab *hpread_start_psymtab
166 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
2ad5709f 167 struct partial_symbol **, struct partial_symbol **));
98c0e047
JL
168
169static struct partial_symtab *hpread_end_psymtab
170 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
171 struct partial_symtab **, int));
172
173static struct symtab *hpread_expand_symtab
174 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
175 struct section_offsets *, char *));
176
177static void hpread_process_one_debug_symbol
178 PARAMS ((union dnttentry *, char *, struct section_offsets *,
179 struct objfile *, CORE_ADDR, int, char *, int));
180
2848f793 181static sltpointer hpread_record_lines
3a0fbb3b
JL
182 PARAMS ((struct subfile *, sltpointer, sltpointer,
183 struct objfile *, CORE_ADDR));
98c0e047
JL
184
185static struct type *hpread_read_function_type
2848f793 186 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
98c0e047
JL
187
188static struct type * hpread_type_lookup
2848f793 189 PARAMS ((dnttpointer, struct objfile *));
98c0e047
JL
190
191static unsigned long hpread_get_depth
2848f793 192 PARAMS ((sltpointer, struct objfile *));
98c0e047
JL
193
194static unsigned long hpread_get_line
2848f793 195 PARAMS ((sltpointer, struct objfile *));
98c0e047 196
2848f793
JL
197static CORE_ADDR hpread_get_location
198 PARAMS ((sltpointer, struct objfile *));
98c0e047 199
2848f793 200static int hpread_type_translate PARAMS ((dnttpointer));
98c0e047
JL
201static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
202static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
203static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
204static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
205static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
206static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
2848f793 207static int hpread_has_name PARAMS ((enum dntt_entry_type));
98c0e047
JL
208
209\f
210/* Initialization for reading native HP C debug symbols from OBJFILE.
211
212 It's only purpose in life is to set up the symbol reader's private
213 per-objfile data structures, and read in the raw contents of the debug
214 sections (attaching pointers to the debug info into the private data
2848f793 215 structures).
98c0e047
JL
216
217 Since BFD doesn't know how to read debug symbols in a format-independent
218 way (and may never do so...), we have to do it ourselves. Note we may
219 be called on a file without native HP C debugging symbols.
220 FIXME, there should be a cleaner peephole into the BFD environment here. */
221
222void
223hpread_symfile_init (objfile)
224 struct objfile *objfile;
225{
226 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
227
228 /* Allocate struct to keep track of the symfile */
229 objfile->sym_private = (PTR)
230 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
231 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
232
233 /* We haven't read in any types yet. */
234 TYPE_VECTOR (objfile) = 0;
235
236 /* Read in data from the $GNTT$ subspace. */
237 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
238 if (!gntt_section)
239 return;
240
241 GNTT (objfile)
242 = obstack_alloc (&objfile->symbol_obstack,
243 bfd_section_size (objfile->obfd, gntt_section));
244
245 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
246 0, bfd_section_size (objfile->obfd, gntt_section));
247
248 GNTT_SYMCOUNT (objfile)
2848f793
JL
249 = bfd_section_size (objfile->obfd, gntt_section)
250 / sizeof (struct dntt_type_block);
98c0e047
JL
251
252 /* Read in data from the $LNTT$ subspace. Also keep track of the number
253 of LNTT symbols. */
254 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
255 if (!lntt_section)
256 return;
257
258 LNTT (objfile)
259 = obstack_alloc (&objfile->symbol_obstack,
260 bfd_section_size (objfile->obfd, lntt_section));
261
262 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
263 0, bfd_section_size (objfile->obfd, lntt_section));
264
265 LNTT_SYMCOUNT (objfile)
2848f793
JL
266 = bfd_section_size (objfile->obfd, lntt_section)
267 / sizeof (struct dntt_type_block);
98c0e047
JL
268
269 /* Read in data from the $SLT$ subspace. $SLT$ contains information
270 on source line numbers. */
271 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
272 if (!slt_section)
273 return;
274
275 SLT (objfile) =
276 obstack_alloc (&objfile->symbol_obstack,
277 bfd_section_size (objfile->obfd, slt_section));
278
279 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
280 0, bfd_section_size (objfile->obfd, slt_section));
281
282 /* Read in data from the $VT$ subspace. $VT$ contains things like
283 names and constants. Keep track of the number of symbols in the VT. */
284 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
285 if (!vt_section)
286 return;
287
288 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
289
290 VT (objfile) =
291 (char *) obstack_alloc (&objfile->symbol_obstack,
292 VT_SIZE (objfile));
293
294 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
295 0, VT_SIZE (objfile));
296}
297
298/* Scan and build partial symbols for a symbol file.
299
300 The minimal symbol table (either SOM or HP a.out) has already been
301 read in; all we need to do is setup partial symbols based on the
302 native debugging information.
303
304 We assume hpread_symfile_init has been called to initialize the
305 symbol reader's private data structures.
306
307 SECTION_OFFSETS contains offsets relative to which the symbols in the
308 various sections are (depending where the sections were actually loaded).
309 MAINLINE is true if we are reading the main symbol
310 table (as opposed to a shared lib or dynamically loaded file). */
311
312void
313hpread_build_psymtabs (objfile, section_offsets, mainline)
314 struct objfile *objfile;
315 struct section_offsets *section_offsets;
316 int mainline;
317{
318 char *namestring;
319 int past_first_source_file = 0;
320 struct cleanup *old_chain;
321
322 int hp_symnum, symcount, i;
323
324 union dnttentry *dn_bufp;
325 unsigned long valu;
326 char *p;
327 int texthigh = 0;
328 int have_name = 0;
329
330 /* Current partial symtab */
331 struct partial_symtab *pst;
332
333 /* List of current psymtab's include files */
334 char **psymtab_include_list;
335 int includes_allocated;
336 int includes_used;
337
338 /* Index within current psymtab dependency list */
339 struct partial_symtab **dependency_list;
340 int dependencies_used, dependencies_allocated;
341
342 /* Just in case the stabs reader left turds lying around. */
a7f56d5a 343 free_pending_blocks ();
98c0e047
JL
344 make_cleanup (really_free_pendings, 0);
345
346 pst = (struct partial_symtab *) 0;
347
348 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
349 a number of problems with cross compilation and creating useless holes
350 in the stack when we have to allocate new entries. FIXME. */
351
352 includes_allocated = 30;
353 includes_used = 0;
354 psymtab_include_list = (char **) alloca (includes_allocated *
355 sizeof (char *));
356
357 dependencies_allocated = 30;
358 dependencies_used = 0;
359 dependency_list =
360 (struct partial_symtab **) alloca (dependencies_allocated *
361 sizeof (struct partial_symtab *));
362
363 old_chain = make_cleanup (free_objfile, objfile);
364
365 last_source_file = 0;
366
367 /* Make two passes, one ofr the GNTT symbols, the other for the
368 LNTT symbols. */
369 for (i = 0; i < 1; i++)
370 {
371 int within_function = 0;
372
373 if (i)
374 symcount = GNTT_SYMCOUNT (objfile);
375 else
376 symcount = LNTT_SYMCOUNT (objfile);
377
378 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
379 {
380 QUIT;
381 if (i)
382 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
383 else
384 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
385
386 if (dn_bufp->dblock.extension)
387 continue;
388
389 /* Only handle things which are necessary for minimal symbols.
390 everything else is ignored. */
391 switch (dn_bufp->dblock.kind)
392 {
2848f793 393 case DNTT_TYPE_SRCFILE:
98c0e047
JL
394 {
395 /* A source file of some kind. Note this may simply
396 be an included file. */
397 SET_NAMESTRING (dn_bufp, &namestring, objfile);
398
399 /* Check if this is the source file we are already working
400 with. */
401 if (pst && !strcmp (namestring, pst->filename))
402 continue;
403
404 /* Check if this is an include file, if so check if we have
405 already seen it. Add it to the include list */
406 p = strrchr (namestring, '.');
407 if (!strcmp (p, ".h"))
408 {
409 int j, found;
410
411 found = 0;
412 for (j = 0; j < includes_used; j++)
413 if (!strcmp (namestring, psymtab_include_list[j]))
414 {
415 found = 1;
416 break;
417 }
418 if (found)
419 continue;
420
421 /* Add it to the list of includes seen so far and
422 allocate more include space if necessary. */
423 psymtab_include_list[includes_used++] = namestring;
424 if (includes_used >= includes_allocated)
425 {
426 char **orig = psymtab_include_list;
427
428 psymtab_include_list = (char **)
429 alloca ((includes_allocated *= 2) *
430 sizeof (char *));
431 memcpy ((PTR) psymtab_include_list, (PTR) orig,
432 includes_used * sizeof (char *));
433 }
434 continue;
435 }
436
437
38ab0632 438 if (pst)
98c0e047
JL
439 {
440 if (!have_name)
441 {
38ab0632
JL
442 pst->filename = (char *)
443 obstack_alloc (&pst->objfile->psymbol_obstack,
444 strlen (namestring) + 1);
98c0e047
JL
445 strcpy (pst->filename, namestring);
446 have_name = 1;
447 continue;
448 }
449 continue;
450 }
451
452 /* This is a bonafide new source file.
453 End the current partial symtab and start a new one. */
454
455 if (pst && past_first_source_file)
456 {
98c0e047
JL
457 hpread_end_psymtab (pst, psymtab_include_list,
458 includes_used,
2848f793
JL
459 (hp_symnum
460 * sizeof (struct dntt_type_block)),
461 texthigh,
98c0e047
JL
462 dependency_list, dependencies_used);
463 pst = (struct partial_symtab *) 0;
464 includes_used = 0;
465 dependencies_used = 0;
466 }
467 else
468 past_first_source_file = 1;
469
470 valu = hpread_get_textlow (i, hp_symnum, objfile);
471 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
472 pst = hpread_start_psymtab (objfile, section_offsets,
473 namestring, valu,
2848f793
JL
474 (hp_symnum
475 * sizeof (struct dntt_type_block)),
98c0e047
JL
476 objfile->global_psymbols.next,
477 objfile->static_psymbols.next);
478 texthigh = valu;
38ab0632 479 have_name = 1;
98c0e047
JL
480 continue;
481 }
482
2848f793 483 case DNTT_TYPE_MODULE:
98c0e047 484 /* A source file. It's still unclear to me what the
2848f793 485 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
98c0e047
JL
486 is supposed to be. */
487 SET_NAMESTRING (dn_bufp, &namestring, objfile);
488 valu = hpread_get_textlow (i, hp_symnum, objfile);
489 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
38ab0632
JL
490 if (!pst)
491 {
492 pst = hpread_start_psymtab (objfile, section_offsets,
493 namestring, valu,
2848f793
JL
494 (hp_symnum
495 * sizeof (struct dntt_type_block)),
38ab0632
JL
496 objfile->global_psymbols.next,
497 objfile->static_psymbols.next);
498 texthigh = valu;
499 have_name = 0;
500 }
98c0e047 501 continue;
2848f793
JL
502 case DNTT_TYPE_FUNCTION:
503 case DNTT_TYPE_ENTRY:
504 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
98c0e047 505 a secondary entry point. */
3a0fbb3b
JL
506 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
507 SECT_OFF_TEXT);
508 if (valu > texthigh)
509 texthigh = valu;
98c0e047
JL
510 valu = dn_bufp->dfunc.lowaddr +
511 ANOFFSET (section_offsets, SECT_OFF_TEXT);
98c0e047 512 SET_NAMESTRING (dn_bufp, &namestring, objfile);
eae8aa30 513 add_psymbol_to_list (namestring, strlen (namestring),
98c0e047 514 VAR_NAMESPACE, LOC_BLOCK,
eae8aa30
FF
515 &objfile->static_psymbols, valu,
516 0, language_unknown, objfile);
98c0e047
JL
517 within_function = 1;
518 continue;
2848f793
JL
519 case DNTT_TYPE_BEGIN:
520 case DNTT_TYPE_END:
98c0e047
JL
521 /* Scope block begin/end. We only care about function
522 and file blocks right now. */
2848f793 523 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
98c0e047 524 {
98c0e047 525 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2848f793
JL
526 (hp_symnum
527 * sizeof (struct dntt_type_block)),
528 texthigh,
98c0e047
JL
529 dependency_list, dependencies_used);
530 pst = (struct partial_symtab *) 0;
531 includes_used = 0;
532 dependencies_used = 0;
98c0e047
JL
533 have_name = 0;
534 }
2848f793 535 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
98c0e047
JL
536 within_function = 0;
537 continue;
2848f793
JL
538 case DNTT_TYPE_SVAR:
539 case DNTT_TYPE_DVAR:
540 case DNTT_TYPE_TYPEDEF:
541 case DNTT_TYPE_TAGDEF:
98c0e047
JL
542 {
543 /* Variables, typedefs an the like. */
544 enum address_class storage;
60d5a517 545 namespace_enum namespace;
98c0e047
JL
546
547 /* Don't add locals to the partial symbol table. */
548 if (within_function
2848f793
JL
549 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
550 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
98c0e047
JL
551 continue;
552
553 /* TAGDEFs go into the structure namespace. */
2848f793 554 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
98c0e047
JL
555 namespace = STRUCT_NAMESPACE;
556 else
557 namespace = VAR_NAMESPACE;
558
559 /* What kind of "storage" does this use? */
2848f793 560 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
98c0e047 561 storage = LOC_STATIC;
2848f793 562 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
98c0e047
JL
563 && dn_bufp->ddvar.regvar)
564 storage = LOC_REGISTER;
2848f793 565 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
98c0e047
JL
566 storage = LOC_LOCAL;
567 else
568 storage = LOC_UNDEF;
569
570 SET_NAMESTRING (dn_bufp, &namestring, objfile);
571 if (!pst)
572 {
573 pst = hpread_start_psymtab (objfile, section_offsets,
574 "globals", 0,
2848f793
JL
575 (hp_symnum
576 * sizeof (struct dntt_type_block)),
98c0e047
JL
577 objfile->global_psymbols.next,
578 objfile->static_psymbols.next);
579 }
2848f793 580 if (dn_bufp->dsvar.global)
98c0e047 581 {
eae8aa30 582 add_psymbol_to_list (namestring, strlen (namestring),
98c0e047 583 namespace, storage,
eae8aa30 584 &objfile->global_psymbols,
98c0e047 585 dn_bufp->dsvar.location,
eae8aa30 586 0, language_unknown, objfile);
98c0e047
JL
587 }
588 else
589 {
eae8aa30 590 add_psymbol_to_list (namestring, strlen (namestring),
98c0e047 591 namespace, storage,
eae8aa30 592 &objfile->static_psymbols,
98c0e047 593 dn_bufp->dsvar.location,
eae8aa30 594 0, language_unknown, objfile);
98c0e047
JL
595 }
596 continue;
597 }
2848f793
JL
598 case DNTT_TYPE_MEMENUM:
599 case DNTT_TYPE_CONST:
98c0e047
JL
600 /* Constants and members of enumerated types. */
601 SET_NAMESTRING (dn_bufp, &namestring, objfile);
602 if (!pst)
603 {
604 pst = hpread_start_psymtab (objfile, section_offsets,
605 "globals", 0,
2848f793
JL
606 (hp_symnum
607 * sizeof (struct dntt_type_block)),
98c0e047
JL
608 objfile->global_psymbols.next,
609 objfile->static_psymbols.next);
610 }
eae8aa30 611 add_psymbol_to_list (namestring, strlen (namestring),
98c0e047 612 VAR_NAMESPACE, LOC_CONST,
eae8aa30
FF
613 &objfile->static_psymbols, 0,
614 0, language_unknown, objfile);
98c0e047
JL
615 continue;
616 default:
617 continue;
618 }
619 }
620 }
621
622 /* End any pending partial symbol table. */
623 if (pst)
624 {
625 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2848f793
JL
626 hp_symnum * sizeof (struct dntt_type_block),
627 0, dependency_list, dependencies_used);
98c0e047
JL
628 }
629
630 discard_cleanups (old_chain);
631}
632
633/* Perform any local cleanups required when we are done with a particular
634 objfile. I.E, we are in the process of discarding all symbol information
635 for an objfile, freeing up all memory held for it, and unlinking the
636 objfile struct from the global list of known objfiles. */
637
638void
639hpread_symfile_finish (objfile)
640 struct objfile *objfile;
641{
642 if (objfile->sym_private != NULL)
643 {
644 mfree (objfile->md, objfile->sym_private);
645 }
646}
647\f
648
649/* The remaining functions are all for internal use only. */
650
651/* Various small functions to get entries in the debug symbol sections. */
652
653static union dnttentry *
654hpread_get_lntt (index, objfile)
655 int index;
656 struct objfile *objfile;
657{
2848f793
JL
658 return (union dnttentry *)
659 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
98c0e047
JL
660}
661
662static union dnttentry *
663hpread_get_gntt (index, objfile)
664 int index;
665 struct objfile *objfile;
666{
2848f793
JL
667 return (union dnttentry *)
668 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
98c0e047
JL
669}
670
671static union sltentry *
672hpread_get_slt (index, objfile)
673 int index;
674 struct objfile *objfile;
675{
2848f793 676 return (union sltentry *)&(SLT (objfile)[index * sizeof (union sltentry)]);
98c0e047
JL
677}
678
679/* Get the low address associated with some symbol (typically the start
680 of a particular source file or module). Since that information is not
2848f793
JL
681 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
682 the existance of DNTT_TYPE_FUNCTION symbols. */
98c0e047
JL
683
684static unsigned long
685hpread_get_textlow (global, index, objfile)
686 int global;
687 int index;
688 struct objfile *objfile;
689{
690 union dnttentry *dn_bufp;
691 struct minimal_symbol *msymbol;
692
2848f793 693 /* Look for a DNTT_TYPE_FUNCTION symbol. */
98c0e047
JL
694 do
695 {
696 if (global)
697 dn_bufp = hpread_get_gntt (index++, objfile);
698 else
699 dn_bufp = hpread_get_lntt (index++, objfile);
2848f793
JL
700 } while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
701 && dn_bufp->dblock.kind != DNTT_TYPE_END);
98c0e047 702
2848f793 703 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
98c0e047 704 might happen when a sourcefile has no functions. */
2848f793 705 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
98c0e047
JL
706 return 0;
707
708 /* The minimal symbols are typically more accurate for some reason. */
2d336b1b 709 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
98c0e047
JL
710 objfile);
711 if (msymbol)
712 return SYMBOL_VALUE_ADDRESS (msymbol);
713 else
714 return dn_bufp->dfunc.lowaddr;
715}
716
717/* Get the nesting depth for the source line identified by INDEX. */
718
719static unsigned long
720hpread_get_depth (index, objfile)
2848f793 721 sltpointer index;
98c0e047
JL
722 struct objfile *objfile;
723{
724 union sltentry *sl_bufp;
725
726 sl_bufp = hpread_get_slt (index, objfile);
727 return sl_bufp->sspec.backptr.dnttp.index;
728}
729
730/* Get the source line number the the line identified by INDEX. */
731
732static unsigned long
733hpread_get_line (index, objfile)
2848f793 734 sltpointer index;
98c0e047
JL
735 struct objfile *objfile;
736{
737 union sltentry *sl_bufp;
738
739 sl_bufp = hpread_get_slt (index, objfile);
740 return sl_bufp->snorm.line;
741}
742
2848f793 743static CORE_ADDR
98c0e047 744hpread_get_location (index, objfile)
2848f793 745 sltpointer index;
98c0e047
JL
746 struct objfile *objfile;
747{
748 union sltentry *sl_bufp;
749 int i;
750
751 /* code location of special sltentrys is determined from context */
752 sl_bufp = hpread_get_slt (index, objfile);
753
754 if (sl_bufp->snorm.sltdesc == SLT_END)
755 {
756 /* find previous normal sltentry and get address */
757 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
758 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
759 sl_bufp = hpread_get_slt (index - i, objfile);
760 return sl_bufp->snorm.address;
761 }
762
763 /* find next normal sltentry and get address */
764 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
765 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
766 sl_bufp = hpread_get_slt (index + i, objfile);
767 return sl_bufp->snorm.address;
768}
769\f
770
771/* Return 1 if an HP debug symbol of type KIND has a name associated with
772 it, else return 0. */
773
774static int
775hpread_has_name (kind)
2848f793 776 enum dntt_entry_type kind;
98c0e047
JL
777{
778 switch (kind)
779 {
2848f793
JL
780 case DNTT_TYPE_SRCFILE:
781 case DNTT_TYPE_MODULE:
782 case DNTT_TYPE_FUNCTION:
783 case DNTT_TYPE_ENTRY:
784 case DNTT_TYPE_IMPORT:
785 case DNTT_TYPE_LABEL:
786 case DNTT_TYPE_FPARAM:
787 case DNTT_TYPE_SVAR:
788 case DNTT_TYPE_DVAR:
789 case DNTT_TYPE_CONST:
790 case DNTT_TYPE_TYPEDEF:
791 case DNTT_TYPE_TAGDEF:
792 case DNTT_TYPE_MEMENUM:
793 case DNTT_TYPE_FIELD:
794 case DNTT_TYPE_SA:
98c0e047
JL
795 return 1;
796
2848f793
JL
797 case DNTT_TYPE_BEGIN:
798 case DNTT_TYPE_END:
799 case DNTT_TYPE_WITH:
800 case DNTT_TYPE_COMMON:
801 case DNTT_TYPE_POINTER:
802 case DNTT_TYPE_ENUM:
803 case DNTT_TYPE_SET:
804 case DNTT_TYPE_SUBRANGE:
805 case DNTT_TYPE_ARRAY:
806 case DNTT_TYPE_STRUCT:
807 case DNTT_TYPE_UNION:
808 case DNTT_TYPE_VARIANT:
809 case DNTT_TYPE_FILE:
810 case DNTT_TYPE_FUNCTYPE:
811 case DNTT_TYPE_COBSTRUCT:
812 case DNTT_TYPE_XREF:
813 case DNTT_TYPE_MACRO:
98c0e047
JL
814 default:
815 return 0;
816 }
817}
818
819/* Allocate and partially fill a partial symtab. It will be
820 completely filled at the end of the symbol list.
821
822 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
823 is the address relative to which its symbols are (incremental) or 0
824 (normal). */
825
826static struct partial_symtab *
827hpread_start_psymtab (objfile, section_offsets,
828 filename, textlow, ldsymoff, global_syms, static_syms)
829 struct objfile *objfile;
830 struct section_offsets *section_offsets;
831 char *filename;
832 CORE_ADDR textlow;
833 int ldsymoff;
2ad5709f
FF
834 struct partial_symbol **global_syms;
835 struct partial_symbol **static_syms;
98c0e047
JL
836{
837 struct partial_symtab *result =
838 start_psymtab_common (objfile, section_offsets,
839 filename, textlow, global_syms, static_syms);
840
841 result->read_symtab_private = (char *)
842 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
843 LDSYMOFF (result) = ldsymoff;
844 result->read_symtab = hpread_psymtab_to_symtab;
845
846 return result;
847}
848\f
849
850/* Close off the current usage of PST.
851 Returns PST or NULL if the partial symtab was empty and thrown away.
852
853 FIXME: List variables and peculiarities of same. */
854
855static struct partial_symtab *
856hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
857 capping_text, dependency_list, number_dependencies)
858 struct partial_symtab *pst;
859 char **include_list;
860 int num_includes;
861 int capping_symbol_offset;
862 CORE_ADDR capping_text;
863 struct partial_symtab **dependency_list;
864 int number_dependencies;
865{
866 int i;
867 struct objfile *objfile = pst -> objfile;
868
869 if (capping_symbol_offset != -1)
870 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
871 pst->texthigh = capping_text;
872
873 pst->n_global_syms =
874 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
875 pst->n_static_syms =
876 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
877
878 pst->number_of_dependencies = number_dependencies;
879 if (number_dependencies)
880 {
881 pst->dependencies = (struct partial_symtab **)
882 obstack_alloc (&objfile->psymbol_obstack,
883 number_dependencies * sizeof (struct partial_symtab *));
884 memcpy (pst->dependencies, dependency_list,
885 number_dependencies * sizeof (struct partial_symtab *));
886 }
887 else
888 pst->dependencies = 0;
889
890 for (i = 0; i < num_includes; i++)
891 {
892 struct partial_symtab *subpst =
893 allocate_psymtab (include_list[i], objfile);
894
895 subpst->section_offsets = pst->section_offsets;
896 subpst->read_symtab_private =
897 (char *) obstack_alloc (&objfile->psymbol_obstack,
898 sizeof (struct symloc));
899 LDSYMOFF(subpst) =
900 LDSYMLEN(subpst) =
901 subpst->textlow =
902 subpst->texthigh = 0;
903
904 /* We could save slight bits of space by only making one of these,
905 shared by the entire set of include files. FIXME-someday. */
906 subpst->dependencies = (struct partial_symtab **)
907 obstack_alloc (&objfile->psymbol_obstack,
908 sizeof (struct partial_symtab *));
909 subpst->dependencies[0] = pst;
910 subpst->number_of_dependencies = 1;
911
912 subpst->globals_offset =
913 subpst->n_global_syms =
914 subpst->statics_offset =
915 subpst->n_static_syms = 0;
916
917 subpst->readin = 0;
918 subpst->symtab = 0;
919 subpst->read_symtab = pst->read_symtab;
920 }
921
922 sort_pst_symbols (pst);
923
924 /* If there is already a psymtab or symtab for a file of this name, remove it.
925 (If there is a symtab, more drastic things also happen.)
926 This happens in VxWorks. */
927 free_named_symtabs (pst->filename);
928
929 if (num_includes == 0
930 && number_dependencies == 0
931 && pst->n_global_syms == 0
932 && pst->n_static_syms == 0)
933 {
934 /* Throw away this psymtab, it's empty. We can't deallocate it, since
935 it is on the obstack, but we can forget to chain it on the list. */
936 /* Empty psymtabs happen as a result of header files which don't have
937 any symbols in them. There can be a lot of them. But this check
938 is wrong, in that a psymtab with N_SLINE entries but nothing else
939 is not empty, but we don't realize that. Fixing that without slowing
940 things down might be tricky. */
941 struct partial_symtab *prev_pst;
942
943 /* First, snip it out of the psymtab chain */
944
945 if (pst->objfile->psymtabs == pst)
946 pst->objfile->psymtabs = pst->next;
947 else
948 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
949 if (prev_pst->next == pst)
950 prev_pst->next = pst->next;
951
952 /* Next, put it on a free list for recycling */
953
954 pst->next = pst->objfile->free_psymtabs;
955 pst->objfile->free_psymtabs = pst;
956
957 /* Indicate that psymtab was thrown away. */
958 pst = (struct partial_symtab *)NULL;
959 }
960 return pst;
961}
962\f
963/* Do the dirty work of reading in the full symbol from a partial symbol
964 table. */
965
966static void
967hpread_psymtab_to_symtab_1 (pst)
968 struct partial_symtab *pst;
969{
970 struct cleanup *old_chain;
971 int i;
972
973 /* Get out quick if passed junk. */
974 if (!pst)
975 return;
976
977 /* Complain if we've already read in this symbol table. */
978 if (pst->readin)
979 {
980 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
981 pst->filename);
982 return;
983 }
984
985 /* Read in all partial symtabs on which this one is dependent */
986 for (i = 0; i < pst->number_of_dependencies; i++)
987 if (!pst->dependencies[i]->readin)
988 {
989 /* Inform about additional files that need to be read in. */
990 if (info_verbose)
991 {
992 fputs_filtered (" ", stdout);
993 wrap_here ("");
994 fputs_filtered ("and ", stdout);
995 wrap_here ("");
996 printf_filtered ("%s...", pst->dependencies[i]->filename);
997 wrap_here (""); /* Flush output */
998 fflush (stdout);
999 }
1000 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
1001 }
1002
1003 /* If it's real... */
1004 if (LDSYMLEN (pst))
1005 {
1006 /* Init stuff necessary for reading in symbols */
1007 buildsym_init ();
1008 old_chain = make_cleanup (really_free_pendings, 0);
1009
1010 pst->symtab =
1011 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1012 pst->textlow, pst->texthigh - pst->textlow,
1013 pst->section_offsets, pst->filename);
1014 sort_symtab_syms (pst->symtab);
1015
1016 do_cleanups (old_chain);
1017 }
1018
1019 pst->readin = 1;
1020}
1021
1022/* Read in all of the symbols for a given psymtab for real.
1023 Be verbose about it if the user wants that. */
1024
1025static void
1026hpread_psymtab_to_symtab (pst)
1027 struct partial_symtab *pst;
1028{
1029 /* Get out quick if given junk. */
1030 if (!pst)
1031 return;
1032
1033 /* Sanity check. */
1034 if (pst->readin)
1035 {
1036 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1037 pst->filename);
1038 return;
1039 }
1040
1041 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1042 {
1043 /* Print the message now, before reading the string table,
1044 to avoid disconcerting pauses. */
1045 if (info_verbose)
1046 {
1047 printf_filtered ("Reading in symbols for %s...", pst->filename);
1048 fflush (stdout);
1049 }
1050
1051 hpread_psymtab_to_symtab_1 (pst);
1052
1053 /* Match with global symbols. This only needs to be done once,
1054 after all of the symtabs and dependencies have been read in. */
1055 scan_file_globals (pst->objfile);
1056
1057 /* Finish up the debug error message. */
1058 if (info_verbose)
1059 printf_filtered ("done.\n");
1060 }
1061}
1062/* Read in a defined section of a specific object file's symbols.
1063
1064 DESC is the file descriptor for the file, positioned at the
1065 beginning of the symtab
1066 SYM_OFFSET is the offset within the file of
1067 the beginning of the symbols we want to read
1068 SYM_SIZE is the size of the symbol info to read in.
1069 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1070 TEXT_SIZE is the size of the text segment read in.
1071 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1072
1073static struct symtab *
1074hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1075 section_offsets, filename)
1076 struct objfile *objfile;
1077 int sym_offset;
1078 int sym_size;
1079 CORE_ADDR text_offset;
1080 int text_size;
1081 struct section_offsets *section_offsets;
1082 char *filename;
1083{
1084 char *namestring;
1085 union dnttentry *dn_bufp;
1086 unsigned max_symnum;
1087
2848f793 1088 int sym_index = sym_offset / sizeof (struct dntt_type_block);
98c0e047
JL
1089
1090 current_objfile = objfile;
1091 subfile_stack = 0;
1092
1093 last_source_file = 0;
1094
1095 dn_bufp = hpread_get_lntt (sym_index, objfile);
2848f793
JL
1096 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1097 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
609fd033
FF
1098 {
1099 start_symtab ("globals", NULL, 0);
1100 record_debugformat ("HP");
1101 }
98c0e047 1102
2848f793 1103 max_symnum = sym_size / sizeof (struct dntt_type_block);
98c0e047
JL
1104
1105 /* Read in and process each debug symbol within the specified range. */
1106 for (symnum = 0;
1107 symnum < max_symnum;
1108 symnum++)
1109 {
1110 QUIT; /* Allow this to be interruptable */
1111 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1112
1113 if (dn_bufp->dblock.extension)
1114 continue;
1115
1116 /* Yow! We call SET_NAMESTRING on things without names! */
1117 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1118
1119 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1120 objfile, text_offset, text_size,
1121 filename, symnum + sym_index);
1122 }
1123
1124 current_objfile = NULL;
1125
436d4143 1126 return end_symtab (text_offset + text_size, objfile, 0);
98c0e047
JL
1127}
1128\f
1129
1130/* Convert basic types from HP debug format into GDB internal format. */
1131
1132static int
1133hpread_type_translate (typep)
2848f793 1134 dnttpointer typep;
98c0e047
JL
1135{
1136 if (!typep.dntti.immediate)
1137 abort ();
1138
1139 switch (typep.dntti.type)
1140 {
2848f793
JL
1141 case HP_TYPE_BOOLEAN:
1142 case HP_TYPE_BOOLEAN_S300_COMPAT:
1143 case HP_TYPE_BOOLEAN_VAX_COMPAT:
98c0e047
JL
1144 return FT_BOOLEAN;
1145 /* Ugh. No way to distinguish between signed and unsigned chars. */
2848f793
JL
1146 case HP_TYPE_CHAR:
1147 case HP_TYPE_WIDE_CHAR:
98c0e047 1148 return FT_CHAR;
2848f793 1149 case HP_TYPE_INT:
98c0e047
JL
1150 if (typep.dntti.bitlength <= 8)
1151 return FT_CHAR;
1152 if (typep.dntti.bitlength <= 16)
1153 return FT_SHORT;
1154 if (typep.dntti.bitlength <= 32)
1155 return FT_INTEGER;
1156 return FT_LONG_LONG;
2848f793 1157 case HP_TYPE_LONG:
98c0e047 1158 return FT_LONG;
2848f793 1159 case HP_TYPE_UNSIGNED_LONG:
510ceea9
JL
1160 if (typep.dntti.bitlength <= 8)
1161 return FT_UNSIGNED_CHAR;
1162 if (typep.dntti.bitlength <= 16)
1163 return FT_UNSIGNED_SHORT;
1164 if (typep.dntti.bitlength <= 32)
1165 return FT_UNSIGNED_LONG;
1166 return FT_UNSIGNED_LONG_LONG;
2848f793 1167 case HP_TYPE_UNSIGNED_INT:
98c0e047
JL
1168 if (typep.dntti.bitlength <= 8)
1169 return FT_UNSIGNED_CHAR;
1170 if (typep.dntti.bitlength <= 16)
1171 return FT_UNSIGNED_SHORT;
1172 if (typep.dntti.bitlength <= 32)
1173 return FT_UNSIGNED_INTEGER;
1174 return FT_UNSIGNED_LONG_LONG;
2848f793
JL
1175 case HP_TYPE_REAL:
1176 case HP_TYPE_REAL_3000:
1177 case HP_TYPE_DOUBLE:
98c0e047
JL
1178 if (typep.dntti.bitlength == 64)
1179 return FT_DBL_PREC_FLOAT;
1180 if (typep.dntti.bitlength == 128)
1181 return FT_EXT_PREC_FLOAT;
1182 return FT_FLOAT;
2848f793
JL
1183 case HP_TYPE_COMPLEX:
1184 case HP_TYPE_COMPLEXS3000:
98c0e047
JL
1185 if (typep.dntti.bitlength == 128)
1186 return FT_DBL_PREC_COMPLEX;
1187 if (typep.dntti.bitlength == 192)
1188 return FT_EXT_PREC_COMPLEX;
1189 return FT_COMPLEX;
2848f793
JL
1190 case HP_TYPE_STRING200:
1191 case HP_TYPE_LONGSTRING200:
1192 case HP_TYPE_FTN_STRING_SPEC:
1193 case HP_TYPE_MOD_STRING_SPEC:
1194 case HP_TYPE_MOD_STRING_3000:
1195 case HP_TYPE_FTN_STRING_S300_COMPAT:
1196 case HP_TYPE_FTN_STRING_VAX_COMPAT:
98c0e047
JL
1197 return FT_STRING;
1198 default:
1199 abort ();
1200 }
1201}
1202
1203/* Return the type associated with the index found in HP_TYPE. */
1204
1205static struct type **
1206hpread_lookup_type (hp_type, objfile)
2848f793 1207 dnttpointer hp_type;
98c0e047
JL
1208 struct objfile *objfile;
1209{
1210 unsigned old_len;
1211 int index = hp_type.dnttp.index;
1212
1213 if (hp_type.dntti.immediate)
1214 return NULL;
1215
1216 if (index < LNTT_SYMCOUNT (objfile))
1217 {
1218 if (index >= TYPE_VECTOR_LENGTH (objfile))
1219 {
1220 old_len = TYPE_VECTOR_LENGTH (objfile);
1221 if (old_len == 0)
1222 {
1223 TYPE_VECTOR_LENGTH (objfile) = 100;
1224 TYPE_VECTOR (objfile) = (struct type **)
d369b213
FF
1225 xmmalloc (objfile -> md,
1226 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
98c0e047
JL
1227 }
1228 while (index >= TYPE_VECTOR_LENGTH (objfile))
1229 TYPE_VECTOR_LENGTH (objfile) *= 2;
1230 TYPE_VECTOR (objfile) = (struct type **)
d369b213
FF
1231 xmrealloc (objfile -> md,
1232 (char *) TYPE_VECTOR (objfile),
98c0e047
JL
1233 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1234 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1235 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1236 sizeof (struct type *));
1237 }
1238 return &TYPE_VECTOR (objfile)[index];
1239 }
1240 else
1241 return NULL;
1242}
1243
1244/* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1245 Note we'll just return the address of a GDB internal type if we already
1246 have it lying around. */
1247
1248static struct type *
1249hpread_alloc_type (hp_type, objfile)
2848f793 1250 dnttpointer hp_type;
98c0e047
JL
1251 struct objfile *objfile;
1252{
1253 struct type **type_addr;
1254
1255 type_addr = hpread_lookup_type (hp_type, objfile);
1256 if (*type_addr == 0)
1257 *type_addr = alloc_type (objfile);
1258
1259 TYPE_CPLUS_SPECIFIC (*type_addr)
1260 = (struct cplus_struct_type *) &cplus_struct_default;
1261 return *type_addr;
1262}
1263
1264/* Read a native enumerated type and return it in GDB internal form. */
1265
1266static struct type *
1267hpread_read_enum_type (hp_type, dn_bufp, objfile)
2848f793 1268 dnttpointer hp_type;
98c0e047
JL
1269 union dnttentry *dn_bufp;
1270 struct objfile *objfile;
1271{
1272 struct type *type;
1273 struct pending **symlist, *osyms, *syms;
1274 int o_nsyms, nsyms = 0;
2848f793 1275 dnttpointer mem;
98c0e047
JL
1276 union dnttentry *memp;
1277 char *name;
1278 long n;
1279 struct symbol *sym;
1280
1281 type = hpread_alloc_type (hp_type, objfile);
1282 TYPE_LENGTH (type) = 4;
1283
1284 symlist = &file_symbols;
1285 osyms = *symlist;
1286 o_nsyms = osyms ? osyms->nsyms : 0;
1287
1288 /* Get a name for each member and add it to our list of members. */
1289 mem = dn_bufp->denum.firstmem;
1290 while (mem.dnttp.extension && mem.word != DNTTNIL)
1291 {
1292 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1293
1294 name = VT (objfile) + memp->dmember.name;
1295 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1296 sizeof (struct symbol));
1297 memset (sym, 0, sizeof (struct symbol));
ace4b8d7
FF
1298 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1299 &objfile->symbol_obstack);
98c0e047
JL
1300 SYMBOL_CLASS (sym) = LOC_CONST;
1301 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1302 SYMBOL_VALUE (sym) = memp->dmember.value;
1303 add_symbol_to_list (sym, symlist);
1304 nsyms++;
1305 mem = memp->dmember.nextmem;
1306 }
1307
1308 /* Now that we know more about the enum, fill in more info. */
1309 TYPE_CODE (type) = TYPE_CODE_ENUM;
1310 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1311 TYPE_NFIELDS (type) = nsyms;
1312 TYPE_FIELDS (type) = (struct field *)
1313 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1314
1315 /* Find the symbols for the members and put them into the type.
1316 The symbols can be found in the symlist that we put them on
1317 to cause them to be defined. osyms contains the old value
1318 of that symlist; everything up to there was defined by us.
1319
1320 Note that we preserve the order of the enum constants, so
1321 that in something like "enum {FOO, LAST_THING=FOO}" we print
1322 FOO, not LAST_THING. */
1323 for (syms = *symlist, n = 0; syms; syms = syms->next)
1324 {
1325 int j = 0;
1326 if (syms == osyms)
1327 j = o_nsyms;
1328 for (; j < syms->nsyms; j++, n++)
1329 {
1330 struct symbol *xsym = syms->symbol[j];
1331 SYMBOL_TYPE (xsym) = type;
1332 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
98c0e047
JL
1333 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1334 TYPE_FIELD_BITSIZE (type, n) = 0;
1335 }
1336 if (syms == osyms)
1337 break;
1338 }
1339
1340 return type;
1341}
1342
1343/* Read and internalize a native function debug symbol. */
1344
1345static struct type *
1346hpread_read_function_type (hp_type, dn_bufp, objfile)
2848f793 1347 dnttpointer hp_type;
98c0e047
JL
1348 union dnttentry *dn_bufp;
1349 struct objfile *objfile;
1350{
1351 struct type *type, *type1;
1352 struct pending **symlist, *osyms, *syms;
1353 int o_nsyms, nsyms = 0;
2848f793 1354 dnttpointer param;
98c0e047
JL
1355 union dnttentry *paramp;
1356 char *name;
1357 long n;
1358 struct symbol *sym;
1359
1360 param = dn_bufp->dfunc.firstparam;
1361
1362 /* See if we've already read in this type. */
1363 type = hpread_alloc_type (hp_type, objfile);
1364 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1365 return type;
1366
1367 /* Nope, so read it in and store it away. */
1368 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1369 objfile));
1370 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1371
1372 symlist = &local_symbols;
1373 osyms = *symlist;
1374 o_nsyms = osyms ? osyms->nsyms : 0;
1375
1376 /* Now examine each parameter noting its type, location, and a
1377 wealth of other information. */
1378 while (param.word && param.word != DNTTNIL)
1379 {
1380 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1381 nsyms++;
1382 param = paramp->dfparam.nextparam;
1383
1384 /* Get the name. */
1385 name = VT (objfile) + paramp->dfparam.name;
1386 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1387 sizeof (struct symbol));
1388 (void) memset (sym, 0, sizeof (struct symbol));
ace4b8d7
FF
1389 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1390 &objfile->symbol_obstack);
98c0e047
JL
1391
1392 /* Figure out where it lives. */
1393 if (paramp->dfparam.regparam)
1394 SYMBOL_CLASS (sym) = LOC_REGPARM;
1395 else if (paramp->dfparam.indirect)
1396 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1397 else
1398 SYMBOL_CLASS (sym) = LOC_ARG;
1399 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1400 if (paramp->dfparam.copyparam)
1401 {
1402 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1403#ifdef HPREAD_ADJUST_STACK_ADDRESS
1404 SYMBOL_VALUE (sym)
1405 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1406#endif
1407 /* This is likely a pass-by-invisible reference parameter,
1408 Hack on the symbol class to make GDB happy. */
1409 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1410 }
1411 else
1412 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1413
1414 /* Get its type. */
1415 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1416
1417 /* Add it to the list. */
1418 add_symbol_to_list (sym, symlist);
1419 }
1420
1421 /* Note how many parameters we found. */
1422 TYPE_NFIELDS (type) = nsyms;
1423 TYPE_FIELDS (type) = (struct field *)
1424 obstack_alloc (&objfile->type_obstack,
1425 sizeof (struct field) * nsyms);
1426
1427 /* Find the symbols for the values and put them into the type.
1428 The symbols can be found in the symlist that we put them on
1429 to cause them to be defined. osyms contains the old value
1430 of that symlist; everything up to there was defined by us. */
1431 /* Note that we preserve the order of the parameters, so
1432 that in something like "enum {FOO, LAST_THING=FOO}" we print
1433 FOO, not LAST_THING. */
1434 for (syms = *symlist, n = 0; syms; syms = syms->next)
1435 {
1436 int j = 0;
1437 if (syms == osyms)
1438 j = o_nsyms;
1439 for (; j < syms->nsyms; j++, n++)
1440 {
1441 struct symbol *xsym = syms->symbol[j];
1442 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1443 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1444 TYPE_FIELD_BITPOS (type, n) = n;
1445 TYPE_FIELD_BITSIZE (type, n) = 0;
1446 }
1447 if (syms == osyms)
1448 break;
1449 }
1450 return type;
1451}
1452
1453/* Read in and internalize a structure definition. */
1454
1455static struct type *
1456hpread_read_struct_type (hp_type, dn_bufp, objfile)
2848f793 1457 dnttpointer hp_type;
98c0e047
JL
1458 union dnttentry *dn_bufp;
1459 struct objfile *objfile;
1460{
1461 struct nextfield
1462 {
1463 struct nextfield *next;
1464 struct field field;
1465 };
1466
1467 struct type *type;
1468 struct nextfield *list = 0;
1469 struct nextfield *new;
1470 int n, nfields = 0;
2848f793 1471 dnttpointer field;
98c0e047
JL
1472 union dnttentry *fieldp;
1473
1474 /* Is it something we've already dealt with? */
1475 type = hpread_alloc_type (hp_type, objfile);
1476 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1477 (TYPE_CODE (type) == TYPE_CODE_UNION))
1478 return type;
1479
1480 /* Get the basic type correct. */
2848f793 1481 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
98c0e047
JL
1482 {
1483 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1484 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1485 }
2848f793 1486 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
98c0e047
JL
1487 {
1488 TYPE_CODE (type) = TYPE_CODE_UNION;
1489 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1490 }
1491 else
1492 return type;
1493
1494
1495 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1496
1497 /* Read in and internalize all the fields. */
1498 field = dn_bufp->dstruct.firstfield;
1499 while (field.word != DNTTNIL && field.dnttp.extension)
1500 {
1501 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1502
1503 /* Get space to record the next field's data. */
1504 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1505 new->next = list;
1506 list = new;
1507
1508 list->field.name = VT (objfile) + fieldp->dfield.name;
c031a0bd 1509 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
98c0e047 1510 if (fieldp->dfield.bitlength % 8)
c031a0bd 1511 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
98c0e047 1512 else
c031a0bd 1513 FIELD_BITSIZE (list->field) = 0;
98c0e047
JL
1514 nfields++;
1515 field = fieldp->dfield.nextfield;
c031a0bd
JL
1516 FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1517 objfile);
98c0e047
JL
1518 }
1519
1520 TYPE_NFIELDS (type) = nfields;
1521 TYPE_FIELDS (type) = (struct field *)
1522 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1523
1524 /* Copy the saved-up fields into the field vector. */
1525 for (n = nfields; list; list = list->next)
1526 {
1527 n -= 1;
1528 TYPE_FIELD (type, n) = list->field;
1529 }
1530 return type;
1531}
1532
1533/* Read in and internalize a set debug symbol. */
1534
1535static struct type *
1536hpread_read_set_type (hp_type, dn_bufp, objfile)
2848f793 1537 dnttpointer hp_type;
98c0e047
JL
1538 union dnttentry *dn_bufp;
1539 struct objfile *objfile;
1540{
1541 struct type *type;
1542
1543 /* See if it's something we've already deal with. */
1544 type = hpread_alloc_type (hp_type, objfile);
1545 if (TYPE_CODE (type) == TYPE_CODE_SET)
1546 return type;
1547
1548 /* Nope. Fill in the appropriate fields. */
1549 TYPE_CODE (type) = TYPE_CODE_SET;
1550 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1551 TYPE_NFIELDS (type) = 0;
1552 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1553 objfile);
1554 return type;
1555}
1556
1557/* Read in and internalize an array debug symbol. */
1558
1559static struct type *
1560hpread_read_array_type (hp_type, dn_bufp, objfile)
2848f793 1561 dnttpointer hp_type;
98c0e047
JL
1562 union dnttentry *dn_bufp;
1563 struct objfile *objfile;
1564{
1565 struct type *type;
1566 union dnttentry save;
1567 save = *dn_bufp;
1568
1569 /* Why no check here? Because it kept us from properly determining
1570 the size of the array! */
1571 type = hpread_alloc_type (hp_type, objfile);
1572
1573 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1574
1575 /* values are not normalized. */
1576 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1577 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1578 abort ();
1579 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1580 {
1581 /* The HP debug format represents char foo[]; as an array with
1582 length 0x7fffffff. Internally GDB wants to represent this
e042d326
JL
1583 as an array of length zero. */
1584 TYPE_LENGTH (type) = 0;
98c0e047
JL
1585 }
1586 else
1587 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1588
1589 TYPE_NFIELDS (type) = 1;
1590 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1591 objfile);
1592 dn_bufp = &save;
1593 TYPE_FIELDS (type) = (struct field *)
1594 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1595 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1596 objfile);
1597 return type;
1598}
1599
1600/* Read in and internalize a subrange debug symbol. */
1601static struct type *
1602hpread_read_subrange_type (hp_type, dn_bufp, objfile)
2848f793 1603 dnttpointer hp_type;
98c0e047
JL
1604 union dnttentry *dn_bufp;
1605 struct objfile *objfile;
1606{
1607 struct type *type;
1608
1609 /* Is it something we've already dealt with. */
1610 type = hpread_alloc_type (hp_type, objfile);
1611 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1612 return type;
1613
1614 /* Nope, internalize it. */
1615 TYPE_CODE (type) = TYPE_CODE_RANGE;
1616 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1617 TYPE_NFIELDS (type) = 2;
3a0fbb3b
JL
1618 TYPE_FIELDS (type)
1619 = (struct field *) obstack_alloc (&objfile->type_obstack,
1620 2 * sizeof (struct field));
98c0e047
JL
1621
1622 if (dn_bufp->dsubr.dyn_low)
1623 TYPE_FIELD_BITPOS (type, 0) = 0;
1624 else
1625 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1626
1627 if (dn_bufp->dsubr.dyn_high)
1628 TYPE_FIELD_BITPOS (type, 1) = -1;
1629 else
1630 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1631 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1632 objfile);
1633 return type;
1634}
1635
1636static struct type *
1637hpread_type_lookup (hp_type, objfile)
2848f793 1638 dnttpointer hp_type;
98c0e047
JL
1639 struct objfile *objfile;
1640{
1641 union dnttentry *dn_bufp;
1642
1643 /* First see if it's a simple builtin type. */
1644 if (hp_type.dntti.immediate)
1645 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1646
1647 /* Not a builtin type. We'll have to read it in. */
1648 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1649 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1650 else
1651 return lookup_fundamental_type (objfile, FT_VOID);
1652
1653 switch (dn_bufp->dblock.kind)
1654 {
2848f793
JL
1655 case DNTT_TYPE_SRCFILE:
1656 case DNTT_TYPE_MODULE:
1657 case DNTT_TYPE_FUNCTION:
1658 case DNTT_TYPE_ENTRY:
1659 case DNTT_TYPE_BEGIN:
1660 case DNTT_TYPE_END:
1661 case DNTT_TYPE_IMPORT:
1662 case DNTT_TYPE_LABEL:
1663 case DNTT_TYPE_WITH:
1664 case DNTT_TYPE_COMMON:
1665 case DNTT_TYPE_FPARAM:
1666 case DNTT_TYPE_SVAR:
1667 case DNTT_TYPE_DVAR:
1668 case DNTT_TYPE_CONST:
98c0e047
JL
1669 /* Opps. Something went very wrong. */
1670 return lookup_fundamental_type (objfile, FT_VOID);
1671
2848f793 1672 case DNTT_TYPE_TYPEDEF:
98c0e047
JL
1673 {
1674 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1675 objfile);
1676 char *suffix;
1677 suffix = VT (objfile) + dn_bufp->dtype.name;
1678
1679 TYPE_CPLUS_SPECIFIC (structtype)
1680 = (struct cplus_struct_type *) &cplus_struct_default;
1681 TYPE_NAME (structtype) = suffix;
1682 return structtype;
1683 }
1684
2848f793 1685 case DNTT_TYPE_TAGDEF:
98c0e047
JL
1686 {
1687 /* Just a little different from above. We have to tack on
1688 an identifier of some kind (struct, union, enum, etc). */
1689 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1690 objfile);
1691 char *prefix, *suffix;
1692 suffix = VT (objfile) + dn_bufp->dtype.name;
1693
1694 /* Lookup the next type in the list. It should be a structure,
1695 union, or enum type. We will need to attach that to our name. */
1696 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1697 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1698 else
1699 abort ();
1700
2848f793 1701 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
98c0e047 1702 prefix = "struct ";
2848f793 1703 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
98c0e047
JL
1704 prefix = "union ";
1705 else
1706 prefix = "enum ";
1707
1708 /* Build the correct name. */
1709 structtype->name
1710 = (char *) obstack_alloc (&objfile->type_obstack,
1711 strlen (prefix) + strlen (suffix) + 1);
1712 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1713 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1714 TYPE_TAG_NAME (structtype) = suffix;
1715
1716 TYPE_CPLUS_SPECIFIC (structtype)
1717 = (struct cplus_struct_type *) &cplus_struct_default;
1718
1719 return structtype;
1720 }
2848f793 1721 case DNTT_TYPE_POINTER:
98c0e047
JL
1722 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1723 objfile));
2848f793 1724 case DNTT_TYPE_ENUM:
98c0e047 1725 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
2848f793 1726 case DNTT_TYPE_MEMENUM:
98c0e047 1727 return lookup_fundamental_type (objfile, FT_VOID);
2848f793 1728 case DNTT_TYPE_SET:
98c0e047 1729 return hpread_read_set_type (hp_type, dn_bufp, objfile);
2848f793 1730 case DNTT_TYPE_SUBRANGE:
98c0e047 1731 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
2848f793 1732 case DNTT_TYPE_ARRAY:
98c0e047 1733 return hpread_read_array_type (hp_type, dn_bufp, objfile);
2848f793
JL
1734 case DNTT_TYPE_STRUCT:
1735 case DNTT_TYPE_UNION:
98c0e047 1736 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
2848f793 1737 case DNTT_TYPE_FIELD:
98c0e047 1738 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
2848f793
JL
1739 case DNTT_TYPE_VARIANT:
1740 case DNTT_TYPE_FILE:
98c0e047 1741 return lookup_fundamental_type (objfile, FT_VOID);
2848f793 1742 case DNTT_TYPE_FUNCTYPE:
98c0e047
JL
1743 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1744 objfile));
2848f793
JL
1745 case DNTT_TYPE_COBSTRUCT:
1746 case DNTT_TYPE_XREF:
1747 case DNTT_TYPE_SA:
1748 case DNTT_TYPE_MACRO:
98c0e047
JL
1749 default:
1750 return lookup_fundamental_type (objfile, FT_VOID);
1751 }
1752}
1753
2848f793 1754static sltpointer
3a0fbb3b 1755hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
98c0e047 1756 struct subfile *subfile;
2848f793 1757 sltpointer s_idx, e_idx;
98c0e047 1758 struct objfile *objfile;
3a0fbb3b 1759 CORE_ADDR offset;
98c0e047
JL
1760{
1761 union sltentry *sl_bufp;
1762
1763 while (s_idx <= e_idx)
1764 {
1765 sl_bufp = hpread_get_slt (s_idx, objfile);
1766 /* Only record "normal" entries in the SLT. */
1767 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1768 || sl_bufp->snorm.sltdesc == SLT_EXIT)
3a0fbb3b
JL
1769 record_line (subfile, sl_bufp->snorm.line,
1770 sl_bufp->snorm.address + offset);
98c0e047
JL
1771 s_idx++;
1772 }
1773 return e_idx;
1774}
1775
1776/* Internalize one native debug symbol. */
1777
1778static void
1779hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1780 text_offset, text_size, filename, index)
1781 union dnttentry *dn_bufp;
1782 char *name;
1783 struct section_offsets *section_offsets;
1784 struct objfile *objfile;
1785 CORE_ADDR text_offset;
1786 int text_size;
1787 char *filename;
1788 int index;
1789{
1790 unsigned long desc;
1791 int type;
1792 CORE_ADDR valu;
1793 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1794 union dnttentry *dn_temp;
2848f793 1795 dnttpointer hp_type;
98c0e047
JL
1796 struct symbol *sym;
1797 struct context_stack *new;
98c0e047
JL
1798
1799 /* Allocate one GDB debug symbol and fill in some default values. */
1800 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1801 sizeof (struct symbol));
1802 memset (sym, 0, sizeof (struct symbol));
ace4b8d7 1803 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
98c0e047
JL
1804 SYMBOL_LANGUAGE (sym) = language_auto;
1805 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1806 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1807 SYMBOL_LINE (sym) = 0;
1808 SYMBOL_VALUE (sym) = 0;
1809 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1810
1811 hp_type.dnttp.extension = 1;
1812 hp_type.dnttp.immediate = 0;
1813 hp_type.dnttp.global = 0;
1814 hp_type.dnttp.index = index;
1815
1816 type = dn_bufp->dblock.kind;
1817
1818 switch (type)
1819 {
2848f793 1820 case DNTT_TYPE_SRCFILE:
98c0e047
JL
1821 /* This type of symbol indicates from which source file or include file
1822 the following data comes. If there are no modules it also may
1823 indicate the start of a new source file, in which case we must
1824 finish the symbol table of the previous source file
1825 (if any) and start accumulating a new symbol table. */
1826
3a0fbb3b 1827 valu = text_offset;
38ab0632 1828 if (!last_source_file)
3a0fbb3b
JL
1829 {
1830 start_symtab (name, NULL, valu);
609fd033 1831 record_debugformat ("HP");
3a0fbb3b
JL
1832 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1833 }
1834 else
1835 {
1836 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1837 SL_INDEX (objfile),
1838 dn_bufp->dsfile.address,
1839 objfile, offset);
1840 }
38ab0632 1841 start_subfile (name, NULL);
98c0e047 1842 break;
38ab0632 1843
2848f793
JL
1844 case DNTT_TYPE_MODULE:
1845 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
98c0e047
JL
1846 break;
1847
2848f793
JL
1848 case DNTT_TYPE_FUNCTION:
1849 case DNTT_TYPE_ENTRY:
98c0e047
JL
1850 /* A function or secondary entry point. */
1851 valu = dn_bufp->dfunc.lowaddr + offset;
1852 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1853 SL_INDEX (objfile),
1854 dn_bufp->dfunc.address,
3a0fbb3b 1855 objfile, offset);
98c0e047
JL
1856
1857 WITHIN_FUNCTION (objfile) = 1;
1858 CURRENT_FUNCTION_VALUE (objfile) = valu;
1859
1860 /* Stack must be empty now. */
1861 if (context_stack_depth != 0)
1862 complain (&lbrac_unmatched_complaint, (char *) symnum);
1863 new = push_context (0, valu);
1864
1865 SYMBOL_CLASS (sym) = LOC_BLOCK;
1866 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
2848f793 1867 if (dn_bufp->dfunc.global)
98c0e047
JL
1868 add_symbol_to_list (sym, &global_symbols);
1869 else
1870 add_symbol_to_list (sym, &file_symbols);
1871 new->name = sym;
1872
1873 /* Search forward to the next scope beginning. */
2848f793 1874 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
98c0e047
JL
1875 {
1876 dn_bufp = hpread_get_lntt (++index, objfile);
1877 if (dn_bufp->dblock.extension)
1878 continue;
1879 }
1880 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1881 SL_INDEX (objfile),
1882 dn_bufp->dbegin.address,
3a0fbb3b 1883 objfile, offset);
98c0e047
JL
1884 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1885 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1886 break;
1887
2848f793 1888 case DNTT_TYPE_BEGIN:
98c0e047
JL
1889 /* Begin a new scope. */
1890 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1891 SL_INDEX (objfile),
1892 dn_bufp->dbegin.address,
3a0fbb3b 1893 objfile, offset);
98c0e047
JL
1894 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1895 valu += offset; /* Relocate for dynamic loading */
1896 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1897 new = push_context (desc, valu);
1898 break;
1899
2848f793 1900 case DNTT_TYPE_END:
98c0e047
JL
1901 /* End a scope. */
1902 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1903 SL_INDEX (objfile),
1904 dn_bufp->dend.address + 1,
3a0fbb3b 1905 objfile, offset);
98c0e047
JL
1906 switch (dn_bufp->dend.endkind)
1907 {
2848f793 1908 case DNTT_TYPE_MODULE:
98c0e047
JL
1909 /* Ending a module ends the symbol table for that module. */
1910 valu = text_offset + text_size + offset;
436d4143 1911 (void) end_symtab (valu, objfile, 0);
98c0e047
JL
1912 break;
1913
2848f793 1914 case DNTT_TYPE_FUNCTION:
98c0e047
JL
1915 /* Ending a function, well, ends the function's scope. */
1916 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1917 objfile);
1918 valu = dn_temp->dfunc.hiaddr + offset;
1919 new = pop_context ();
1920 /* Make a block for the local symbols within. */
1921 finish_block (new->name, &local_symbols, new->old_blocks,
1922 new->start_addr, valu, objfile);
1923 WITHIN_FUNCTION (objfile) = 0;
1924 break;
2848f793 1925 case DNTT_TYPE_BEGIN:
98c0e047
JL
1926 /* Just ending a local scope. */
1927 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1928 /* Why in the hell is this needed? */
1929 valu += offset + 9; /* Relocate for dynamic loading */
1930 new = pop_context ();
1931 desc = dn_bufp->dend.beginscope.dnttp.index;
1932 if (desc != new->depth)
1933 complain (&lbrac_mismatch_complaint, (char *) symnum);
1934 /* Make a block for the local symbols within. */
1935 finish_block (new->name, &local_symbols, new->old_blocks,
1936 new->start_addr, valu, objfile);
1937 local_symbols = new->locals;
1938 break;
1939 }
1940 break;
2848f793 1941 case DNTT_TYPE_LABEL:
98c0e047
JL
1942 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1943 break;
2848f793 1944 case DNTT_TYPE_FPARAM:
98c0e047
JL
1945 /* Function parameters. */
1946 if (dn_bufp->dfparam.regparam)
1947 SYMBOL_CLASS (sym) = LOC_REGISTER;
1948 else
1949 SYMBOL_CLASS (sym) = LOC_LOCAL;
1950 if (dn_bufp->dfparam.copyparam)
1951 {
1952 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1953#ifdef HPREAD_ADJUST_STACK_ADDRESS
1954 SYMBOL_VALUE (sym)
1955 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1956#endif
1957 }
1958 else
1959 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1960 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1961 add_symbol_to_list (sym, &local_symbols);
1962 break;
2848f793 1963 case DNTT_TYPE_SVAR:
98c0e047
JL
1964 /* Static variables. */
1965 SYMBOL_CLASS (sym) = LOC_STATIC;
1966 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1967 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
2848f793 1968 if (dn_bufp->dsvar.global)
98c0e047
JL
1969 add_symbol_to_list (sym, &global_symbols);
1970 else if (WITHIN_FUNCTION (objfile))
1971 add_symbol_to_list (sym, &local_symbols);
1972 else
1973 add_symbol_to_list (sym, &file_symbols);
1974 break;
2848f793 1975 case DNTT_TYPE_DVAR:
98c0e047
JL
1976 /* Dynamic variables. */
1977 if (dn_bufp->ddvar.regvar)
1978 SYMBOL_CLASS (sym) = LOC_REGISTER;
1979 else
1980 SYMBOL_CLASS (sym) = LOC_LOCAL;
1981 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
dc192b86 1982#ifdef HPREAD_ADJUST_STACK_ADDRESS
98c0e047 1983 SYMBOL_VALUE (sym)
dc192b86 1984 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
98c0e047
JL
1985#endif
1986 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
2848f793 1987 if (dn_bufp->ddvar.global)
98c0e047
JL
1988 add_symbol_to_list (sym, &global_symbols);
1989 else if (WITHIN_FUNCTION (objfile))
1990 add_symbol_to_list (sym, &local_symbols);
1991 else
1992 add_symbol_to_list (sym, &file_symbols);
1993 break;
2848f793 1994 case DNTT_TYPE_CONST:
98c0e047
JL
1995 /* A constant (pascal?). */
1996 SYMBOL_CLASS (sym) = LOC_CONST;
1997 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1998 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
2848f793 1999 if (dn_bufp->dconst.global)
98c0e047
JL
2000 add_symbol_to_list (sym, &global_symbols);
2001 else if (WITHIN_FUNCTION (objfile))
2002 add_symbol_to_list (sym, &local_symbols);
2003 else
2004 add_symbol_to_list (sym, &file_symbols);
2005 break;
2848f793 2006 case DNTT_TYPE_TYPEDEF:
98c0e047
JL
2007 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2008 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2848f793 2009 if (dn_bufp->dtype.global)
98c0e047
JL
2010 add_symbol_to_list (sym, &global_symbols);
2011 else if (WITHIN_FUNCTION (objfile))
2012 add_symbol_to_list (sym, &local_symbols);
2013 else
2014 add_symbol_to_list (sym, &file_symbols);
2015 break;
2848f793 2016 case DNTT_TYPE_TAGDEF:
98c0e047
JL
2017 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2018 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2019 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2020 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2848f793 2021 if (dn_bufp->dtype.global)
98c0e047
JL
2022 add_symbol_to_list (sym, &global_symbols);
2023 else if (WITHIN_FUNCTION (objfile))
2024 add_symbol_to_list (sym, &local_symbols);
2025 else
2026 add_symbol_to_list (sym, &file_symbols);
2027 break;
2848f793 2028 case DNTT_TYPE_POINTER:
98c0e047
JL
2029 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2030 (dn_bufp->dptr.pointsto,
2031 objfile));
2032 add_symbol_to_list (sym, &file_symbols);
2033 break;
2848f793 2034 case DNTT_TYPE_ENUM:
98c0e047
JL
2035 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2036 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2037 add_symbol_to_list (sym, &file_symbols);
2038 break;
2848f793 2039 case DNTT_TYPE_MEMENUM:
98c0e047 2040 break;
2848f793 2041 case DNTT_TYPE_SET:
98c0e047
JL
2042 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2043 add_symbol_to_list (sym, &file_symbols);
2044 break;
2848f793 2045 case DNTT_TYPE_SUBRANGE:
98c0e047
JL
2046 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2047 objfile);
2048 add_symbol_to_list (sym, &file_symbols);
2049 break;
2848f793 2050 case DNTT_TYPE_ARRAY:
98c0e047
JL
2051 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2052 add_symbol_to_list (sym, &file_symbols);
2053 break;
2848f793
JL
2054 case DNTT_TYPE_STRUCT:
2055 case DNTT_TYPE_UNION:
98c0e047
JL
2056 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2057 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2058 add_symbol_to_list (sym, &file_symbols);
2059 break;
2060 default:
2061 break;
2062 }
2063}
This page took 0.235674 seconds and 4 git commands to generate.