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