2004-04-17 Randolph Chung <tausq@debian.org>
[deliverable/binutils-gdb.git] / gdb / hpread.c
CommitLineData
c906108c 1/* Read hp debug symbols and convert to internal format, for GDB.
9f9057da
MC
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004 Free Software Foundation, Inc.
c906108c
SS
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
c5aa993b
JM
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
c906108c
SS
21
22 Written by the Center for Software Science at the University of Utah
23 and by Cygnus Support. */
24
25#include "defs.h"
26#include "bfd.h"
27#include "gdb_string.h"
28#include "hp-symtab.h"
29#include "syms.h"
30#include "symtab.h"
31#include "symfile.h"
32#include "objfiles.h"
33#include "buildsym.h"
34#include "complaints.h"
35#include "gdb-stabs.h"
36#include "gdbtypes.h"
37#include "demangle.h"
65e82032
AC
38#include "somsolib.h"
39#include "gdb_assert.h"
c906108c
SS
40
41/* Private information attached to an objfile which we use to find
42 and internalize the HP C debug symbols within that objfile. */
43
44struct hpread_symfile_info
c5aa993b
JM
45 {
46 /* The contents of each of the debug sections (there are 4 of them). */
47 char *gntt;
48 char *lntt;
49 char *slt;
50 char *vt;
c906108c 51
c5aa993b
JM
52 /* We keep the size of the $VT$ section for range checking. */
53 unsigned int vt_size;
c906108c 54
c5aa993b
JM
55 /* Some routines still need to know the number of symbols in the
56 main debug sections ($LNTT$ and $GNTT$). */
57 unsigned int lntt_symcount;
58 unsigned int gntt_symcount;
c906108c 59
c5aa993b 60 /* To keep track of all the types we've processed. */
9a6f53fe
EZ
61 struct type **dntt_type_vector;
62 int dntt_type_vector_length;
c906108c 63
c5aa993b
JM
64 /* Keeps track of the beginning of a range of source lines. */
65 sltpointer sl_index;
c906108c 66
c5aa993b
JM
67 /* Some state variables we'll need. */
68 int within_function;
c906108c 69
c5aa993b
JM
70 /* Keep track of the current function's address. We may need to look
71 up something based on this address. */
72 unsigned int current_function_value;
73 };
c906108c
SS
74
75/* Accessor macros to get at the fields. */
76#define HPUX_SYMFILE_INFO(o) \
77 ((struct hpread_symfile_info *)((o)->sym_private))
78#define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
79#define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
80#define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
81#define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
82#define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
83#define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
84#define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
9a6f53fe
EZ
85#define DNTT_TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->dntt_type_vector)
86#define DNTT_TYPE_VECTOR_LENGTH(o) \
87 (HPUX_SYMFILE_INFO(o)->dntt_type_vector_length)
c906108c
SS
88#define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
89#define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
90#define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
91
c906108c
SS
92\f
93/* We put a pointer to this structure in the read_symtab_private field
94 of the psymtab. */
95
96struct symloc
c5aa993b
JM
97 {
98 /* The offset within the file symbol table of first local symbol for
99 this file. */
c906108c 100
c5aa993b 101 int ldsymoff;
c906108c 102
c5aa993b
JM
103 /* Length (in bytes) of the section of the symbol table devoted to
104 this file's symbols (actually, the section bracketed may contain
105 more than just this file's symbols). If ldsymlen is 0, the only
106 reason for this thing's existence is the dependency list.
107 Nothing else will happen when it is read in. */
c906108c 108
c5aa993b
JM
109 int ldsymlen;
110 };
c906108c
SS
111
112#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
113#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
114#define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
115\f
c906108c 116/* Complaints about the symbols we have encountered. */
23136709
KB
117static void
118lbrac_unmatched_complaint (int arg1)
8af51c36 119{
23136709
KB
120 complaint (&symfile_complaints, "unmatched N_LBRAC before symtab pos %d",
121 arg1);
122}
8af51c36 123
23136709
KB
124static void
125lbrac_mismatch_complaint (int arg1)
8af51c36 126{
23136709
KB
127 complaint (&symfile_complaints,
128 "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1);
129}
8af51c36
EZ
130
131/* To generate dumping code, uncomment this define. The dumping
132 itself is controlled by routine-local statics called "dumping". */
133/* #define DUMPING 1 */
134
135/* To use the quick look-up tables, uncomment this define. */
136#define QUICK_LOOK_UP 1
137
138/* To call PXDB to process un-processed files, uncomment this define. */
139#define USE_PXDB 1
140
141/* Forward procedure declarations */
142
f5479e9c 143/* Used in somread.c. */
8af51c36
EZ
144void hpread_symfile_init (struct objfile *);
145
146void do_pxdb (bfd *);
c906108c 147
a14ed312 148void hpread_build_psymtabs (struct objfile *, int);
c906108c 149
a14ed312 150void hpread_symfile_finish (struct objfile *);
c906108c 151
f5479e9c
EZ
152static void set_namestring (union dnttentry *sym, char **namep,
153 struct objfile *objfile);
154
8af51c36
EZ
155static union dnttentry *hpread_get_gntt (int, struct objfile *);
156
2f4150cc
AC
157static union dnttentry *hpread_get_lntt (int index, struct objfile *objfile);
158
159
8af51c36
EZ
160static unsigned long hpread_get_textlow (int, int, struct objfile *, int);
161
c906108c 162static struct partial_symtab *hpread_start_psymtab
a14ed312
KB
163 (struct objfile *, char *, CORE_ADDR, int,
164 struct partial_symbol **, struct partial_symbol **);
c906108c
SS
165
166static struct partial_symtab *hpread_end_psymtab
a14ed312
KB
167 (struct partial_symtab *, char **, int, int, CORE_ADDR,
168 struct partial_symtab **, int);
c906108c 169
8af51c36
EZ
170static unsigned long hpread_get_scope_start (sltpointer, struct objfile *);
171
172static unsigned long hpread_get_line (sltpointer, struct objfile *);
173
174static CORE_ADDR hpread_get_location (sltpointer, struct objfile *);
175
f5479e9c 176static int hpread_has_name (enum dntt_entry_type kind);
504d5c7e 177
8af51c36
EZ
178static void hpread_psymtab_to_symtab_1 (struct partial_symtab *);
179
f5479e9c 180static void hpread_psymtab_to_symtab (struct partial_symtab *);
8af51c36 181
c906108c 182static struct symtab *hpread_expand_symtab
a14ed312
KB
183 (struct objfile *, int, int, CORE_ADDR, int,
184 struct section_offsets *, char *);
c906108c 185
8af51c36 186static int hpread_type_translate (dnttpointer);
c906108c 187
8af51c36
EZ
188static struct type **hpread_lookup_type (dnttpointer, struct objfile *);
189
190static struct type *hpread_alloc_type (dnttpointer, struct objfile *);
191
192static struct type *hpread_read_enum_type
193 (dnttpointer, union dnttentry *, struct objfile *);
c906108c
SS
194
195static struct type *hpread_read_function_type
8af51c36
EZ
196 (dnttpointer, union dnttentry *, struct objfile *, int);
197
198static struct type *hpread_read_doc_function_type
199 (dnttpointer, union dnttentry *, struct objfile *, int);
200
201static struct type *hpread_read_struct_type
a14ed312 202 (dnttpointer, union dnttentry *, struct objfile *);
c906108c 203
8af51c36 204static struct type *hpread_get_nth_template_arg (struct objfile *, int);
c906108c 205
8af51c36
EZ
206static struct type *hpread_read_templ_arg_type
207 (dnttpointer, union dnttentry *, struct objfile *, char *);
c906108c 208
8af51c36
EZ
209static struct type *hpread_read_set_type
210 (dnttpointer, union dnttentry *, struct objfile *);
c906108c 211
8af51c36
EZ
212static struct type *hpread_read_array_type
213 (dnttpointer, union dnttentry *dn_bufp, struct objfile *objfile);
c906108c 214
8af51c36
EZ
215static struct type *hpread_read_subrange_type
216 (dnttpointer, union dnttentry *, struct objfile *);
c5aa993b 217
8af51c36 218static struct type *hpread_type_lookup (dnttpointer, struct objfile *);
c906108c 219
8af51c36
EZ
220static sltpointer hpread_record_lines
221 (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR);
c906108c 222
8af51c36
EZ
223static void hpread_process_one_debug_symbol
224 (union dnttentry *, char *, struct section_offsets *,
225 struct objfile *, CORE_ADDR, int, char *, int, int *);
c906108c 226
8af51c36 227static int hpread_get_scope_depth (union dnttentry *, struct objfile *, int);
c906108c 228
8af51c36
EZ
229static void fix_static_member_physnames
230 (struct type *, char *, struct objfile *);
c906108c 231
8af51c36
EZ
232static void fixup_class_method_type
233 (struct type *, struct type *, struct objfile *);
c906108c 234
8af51c36 235static void hpread_adjust_bitoffsets (struct type *, int);
c906108c 236
8af51c36
EZ
237static dnttpointer hpread_get_next_skip_over_anon_unions
238 (int, dnttpointer, union dnttentry **, struct objfile *);
c906108c 239
8af51c36 240\f
8af51c36
EZ
241/* Static used to indicate a class type that requires a
242 fix-up of one of its method types */
243static struct type *fixup_class = NULL;
c906108c 244
8af51c36
EZ
245/* Static used to indicate the method type that is to be
246 used to fix-up the type for fixup_class */
247static struct type *fixup_method = NULL;
c906108c 248
8af51c36 249#ifdef USE_PXDB
c906108c 250
8af51c36 251/* NOTE use of system files! May not be portable. */
c906108c 252
8af51c36
EZ
253#define PXDB_SVR4 "/opt/langtools/bin/pxdb"
254#define PXDB_BSD "/usr/bin/pxdb"
c906108c 255
8af51c36
EZ
256#include <stdlib.h>
257#include "gdb_string.h"
c906108c 258
8af51c36 259/* check for the existence of a file, given its full pathname */
f5479e9c 260static int
8af51c36
EZ
261file_exists (char *filename)
262{
263 if (filename)
264 return (access (filename, F_OK) == 0);
265 return 0;
266}
c906108c 267
c906108c 268
8af51c36
EZ
269/* Translate from the "hp_language" enumeration in hp-symtab.h
270 used in the debug info to gdb's generic enumeration in defs.h. */
271static enum language
272trans_lang (enum hp_language in_lang)
273{
274 if (in_lang == HP_LANGUAGE_C)
275 return language_c;
c906108c 276
8af51c36
EZ
277 else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
278 return language_cplus;
c906108c 279
8af51c36
EZ
280 else if (in_lang == HP_LANGUAGE_FORTRAN)
281 return language_fortran;
c906108c 282
8af51c36
EZ
283 else
284 return language_unknown;
c906108c
SS
285}
286
8af51c36
EZ
287static char main_string[] = "main";
288\f
68b8d23e
JB
289
290/* Given the native debug symbol SYM, set NAMEP to the name associated
291 with the debug symbol. Note we may be called with a debug symbol which
292 has no associated name, in that case we return an empty string. */
293
294static void
295set_namestring (union dnttentry *sym, char **namep, struct objfile *objfile)
296{
297 /* Note that we "know" that the name for any symbol is always in the same
298 place. Hence we don't have to conditionalize on the symbol type. */
299 if (! hpread_has_name (sym->dblock.kind))
300 *namep = "";
301 else if ((unsigned) sym->dsfile.name >= VT_SIZE (objfile))
302 {
303 complaint (&symfile_complaints, "bad string table offset in symbol %d",
304 symnum);
305 *namep = "";
306 }
307 else
308 *namep = sym->dsfile.name + VT (objfile);
309}
310
8af51c36 311/* Call PXDB to process our file.
c906108c 312
8af51c36
EZ
313 Approach copied from DDE's "dbgk_run_pxdb". Note: we
314 don't check for BSD location of pxdb, nor for existence
315 of pxdb itself, etc.
c906108c 316
8af51c36 317 NOTE: uses system function and string functions directly.
c906108c 318
8af51c36 319 Return value: 1 if ok, 0 if not */
f5479e9c 320static int
8af51c36 321hpread_call_pxdb (const char *file_name)
c906108c 322{
8af51c36
EZ
323 char *p;
324 int status;
325 int retval;
c906108c 326
8af51c36
EZ
327 if (file_exists (PXDB_SVR4))
328 {
329 p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
330 strcpy (p, PXDB_SVR4);
331 strcat (p, " ");
332 strcat (p, file_name);
c906108c 333
8af51c36
EZ
334 warning ("File not processed by pxdb--about to process now.\n");
335 status = system (p);
c906108c 336
8af51c36
EZ
337 retval = (status == 0);
338 }
339 else
340 {
341 warning ("pxdb not found at standard location: /opt/langtools/bin\ngdb will not be able to debug %s.\nPlease install pxdb at the above location and then restart gdb.\nYou can also run pxdb on %s with the command\n\"pxdb %s\" and then restart gdb.", file_name, file_name, file_name);
c906108c 342
8af51c36
EZ
343 retval = 0;
344 }
345 return retval;
346} /* hpread_call_pxdb */
347\f
c906108c 348
8af51c36
EZ
349/* Return 1 if the file turns out to need pre-processing
350 by PXDB, and we have thus called PXDB to do this processing
351 and the file therefore needs to be re-loaded. Otherwise
352 return 0. */
f5479e9c 353static int
8af51c36
EZ
354hpread_pxdb_needed (bfd *sym_bfd)
355{
356 asection *pinfo_section, *debug_section, *header_section;
357 unsigned int do_pxdb;
358 char *buf;
359 bfd_size_type header_section_size;
c906108c 360
8af51c36
EZ
361 unsigned long tmp;
362 unsigned int pxdbed;
c906108c 363
8af51c36
EZ
364 header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
365 if (!header_section)
366 {
367 return 0; /* No header at all, can't recover... */
368 }
c906108c 369
8af51c36
EZ
370 debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
371 pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
c906108c 372
8af51c36
EZ
373 if (pinfo_section && !debug_section)
374 {
375 /* Debug info with DOC, has different header format.
376 this only happens if the file was pxdbed and compiled optimized
377 otherwise the PINFO section is not there. */
378 header_section_size = bfd_section_size (objfile->obfd, header_section);
c906108c 379
8af51c36
EZ
380 if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
381 {
382 buf = alloca (sizeof (DOC_info_PXDB_header));
c906108c 383
8af51c36
EZ
384 if (!bfd_get_section_contents (sym_bfd,
385 header_section,
386 buf, 0,
387 header_section_size))
388 error ("bfd_get_section_contents\n");
c906108c 389
8af51c36
EZ
390 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
391 pxdbed = (tmp >> 31) & 0x1;
c906108c 392
8af51c36
EZ
393 if (!pxdbed)
394 error ("file debug header info invalid\n");
395 do_pxdb = 0;
396 }
c906108c 397
c906108c 398 else
8af51c36
EZ
399 error ("invalid $HEADER$ size in executable \n");
400 }
401
402 else
403 {
c906108c 404
8af51c36
EZ
405 /* this can be three different cases:
406 1. pxdbed and not doc
407 - DEBUG and HEADER sections are there
408 - header is PXDB_header type
409 - pxdbed flag is set to 1
410
411 2. not pxdbed and doc
412 - DEBUG and HEADER sections are there
413 - header is DOC_info_header type
414 - pxdbed flag is set to 0
415
416 3. not pxdbed and not doc
417 - DEBUG and HEADER sections are there
418 - header is XDB_header type
419 - pxdbed flag is set to 0
420
421 NOTE: the pxdbed flag is meaningful also in the not
422 already pxdb processed version of the header,
423 because in case on non-already processed by pxdb files
424 that same bit in the header would be always zero.
425 Why? Because the bit is the leftmost bit of a word
426 which contains a 'length' which is always a positive value
427 so that bit is never set to 1 (otherwise it would be negative)
428
429 Given the above, we have two choices : either we ignore the
430 size of the header itself and just look at the pxdbed field,
431 or we check the size and then we (for safety and paranoia related
432 issues) check the bit.
433 The first solution is used by DDE, the second by PXDB itself.
434 I am using the second one here, because I already wrote it,
435 and it is the end of a long day.
436 Also, using the first approach would still involve size issues
437 because we need to read in the contents of the header section, and
438 give the correct amount of stuff we want to read to the
439 get_bfd_section_contents function. */
440
441 /* decide which case depending on the size of the header section.
442 The size is as defined in hp-symtab.h */
443
444 header_section_size = bfd_section_size (objfile->obfd, header_section);
445
446 if (header_section_size == (bfd_size_type) sizeof (PXDB_header)) /* pxdb and not doc */
c906108c 447 {
8af51c36
EZ
448
449 buf = alloca (sizeof (PXDB_header));
450 if (!bfd_get_section_contents (sym_bfd,
451 header_section,
452 buf, 0,
453 header_section_size))
454 error ("bfd_get_section_contents\n");
455
456 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
457 pxdbed = (tmp >> 31) & 0x1;
458
459 if (pxdbed)
460 do_pxdb = 0;
c906108c 461 else
8af51c36
EZ
462 error ("file debug header invalid\n");
463 }
464 else /*not pxdbed and doc OR not pxdbed and non doc */
465 do_pxdb = 1;
466 }
c906108c 467
8af51c36
EZ
468 if (do_pxdb)
469 {
470 return 1;
471 }
472 else
473 {
474 return 0;
475 }
476} /* hpread_pxdb_needed */
c906108c 477
8af51c36 478#endif
c906108c 479
8af51c36
EZ
480/* Check whether the file needs to be preprocessed by pxdb.
481 If so, call pxdb. */
c906108c 482
8af51c36
EZ
483void
484do_pxdb (bfd *sym_bfd)
485{
486 /* The following code is HP-specific. The "right" way of
487 doing this is unknown, but we bet would involve a target-
488 specific pre-file-load check using a generic mechanism. */
c906108c 489
8af51c36
EZ
490 /* This code will not be executed if the file is not in SOM
491 format (i.e. if compiled with gcc) */
492 if (hpread_pxdb_needed (sym_bfd))
493 {
494 /*This file has not been pre-processed. Preprocess now */
c906108c 495
8af51c36
EZ
496 if (hpread_call_pxdb (sym_bfd->filename))
497 {
498 /* The call above has changed the on-disk file,
499 we can close the file anyway, because the
500 symbols will be reread in when the target is run */
501 bfd_close (sym_bfd);
502 }
503 }
504}
505\f
c906108c 506
c906108c 507
8af51c36 508#ifdef QUICK_LOOK_UP
c906108c 509
8af51c36 510/* Code to handle quick lookup-tables follows. */
c906108c 511
c906108c 512
8af51c36
EZ
513/* Some useful macros */
514#define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries)
515#define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
516#define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries)
517#define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries)
c906108c 518
8af51c36
EZ
519#define FILE_START(i) (qFD[i].adrStart)
520#define MODULE_START(i) (qMD[i].adrStart)
521#define PROC_START(i) (qPD[i].adrStart)
c906108c 522
8af51c36
EZ
523#define FILE_END(i) (qFD[i].adrEnd)
524#define MODULE_END(i) (qMD[i].adrEnd)
525#define PROC_END(i) (qPD[i].adrEnd)
c906108c 526
8af51c36
EZ
527#define FILE_ISYM(i) (qFD[i].isym)
528#define MODULE_ISYM(i) (qMD[i].isym)
529#define PROC_ISYM(i) (qPD[i].isym)
c906108c 530
8af51c36
EZ
531#define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries)
532#define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries)
533#define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries)
534#define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries)
c906108c 535
8af51c36
EZ
536#define CURR_FILE_START (qFD[curr_fd].adrStart)
537#define CURR_MODULE_START (qMD[curr_md].adrStart)
538#define CURR_PROC_START (qPD[curr_pd].adrStart)
c906108c 539
8af51c36
EZ
540#define CURR_FILE_END (qFD[curr_fd].adrEnd)
541#define CURR_MODULE_END (qMD[curr_md].adrEnd)
542#define CURR_PROC_END (qPD[curr_pd].adrEnd)
c906108c 543
8af51c36
EZ
544#define CURR_FILE_ISYM (qFD[curr_fd].isym)
545#define CURR_MODULE_ISYM (qMD[curr_md].isym)
546#define CURR_PROC_ISYM (qPD[curr_pd].isym)
c906108c 547
8af51c36
EZ
548#define TELL_OBJFILE \
549 do { \
550 if( !told_objfile ) { \
551 told_objfile = 1; \
552 warning ("\nIn object file \"%s\":\n", \
553 objfile->name); \
554 } \
555 } while (0)
556\f
c906108c 557
c906108c 558
8af51c36
EZ
559/* Keeping track of the start/end symbol table (LNTT) indices of
560 psymtabs created so far */
561
562typedef struct
c906108c 563{
8af51c36
EZ
564 int start;
565 int end;
c906108c 566}
8af51c36 567pst_syms_struct;
c906108c 568
8af51c36 569static pst_syms_struct *pst_syms_array = 0;
c906108c 570
504d5c7e
JB
571static int pst_syms_count = 0;
572static int pst_syms_size = 0;
c906108c 573
8af51c36 574/* used by the TELL_OBJFILE macro */
504d5c7e 575static int told_objfile = 0;
8af51c36
EZ
576
577/* Set up psymtab symbol index stuff */
578static void
579init_pst_syms (void)
c906108c 580{
8af51c36
EZ
581 pst_syms_count = 0;
582 pst_syms_size = 20;
583 pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
c906108c
SS
584}
585
8af51c36
EZ
586/* Clean up psymtab symbol index stuff */
587static void
588clear_pst_syms (void)
c906108c 589{
8af51c36
EZ
590 pst_syms_count = 0;
591 pst_syms_size = 0;
592 xfree (pst_syms_array);
593 pst_syms_array = 0;
c906108c
SS
594}
595
8af51c36
EZ
596/* Add information about latest psymtab to symbol index table */
597static void
598record_pst_syms (int start_sym, int end_sym)
c906108c 599{
8af51c36
EZ
600 if (++pst_syms_count > pst_syms_size)
601 {
602 pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
603 2 * pst_syms_size * sizeof (pst_syms_struct));
604 pst_syms_size *= 2;
605 }
606 pst_syms_array[pst_syms_count - 1].start = start_sym;
607 pst_syms_array[pst_syms_count - 1].end = end_sym;
c906108c
SS
608}
609
8af51c36
EZ
610/* Find a suitable symbol table index which can serve as the upper
611 bound of a psymtab that starts at INDEX
c906108c 612
8af51c36
EZ
613 This scans backwards in the psymtab symbol index table to find a
614 "hole" in which the given index can fit. This is a heuristic!!
615 We don't search the entire table to check for multiple holes,
616 we don't care about overlaps, etc.
617
618 Return 0 => not found */
619static int
620find_next_pst_start (int index)
c906108c 621{
8af51c36 622 int i;
c906108c 623
8af51c36
EZ
624 for (i = pst_syms_count - 1; i >= 0; i--)
625 if (pst_syms_array[i].end <= index)
626 return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
c906108c 627
8af51c36
EZ
628 if (pst_syms_array[0].start > index)
629 return pst_syms_array[0].start - 1;
c906108c 630
8af51c36 631 return 0;
c906108c 632}
8af51c36 633\f
c906108c 634
c906108c 635
8af51c36 636/* Utility functions to find the ending symbol index for a psymtab */
c906108c 637
8af51c36
EZ
638/* Find the next file entry that begins beyond INDEX, and return
639 its starting symbol index - 1.
640 QFD is the file table, CURR_FD is the file entry from where to start,
641 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
642
643 Return 0 => not found */
644static int
645find_next_file_isym (int index, quick_file_entry *qFD, int curr_fd,
646 PXDB_header_ptr pxdb_header_p)
647{
648 while (VALID_CURR_FILE)
649 {
650 if (CURR_FILE_ISYM >= index)
651 return CURR_FILE_ISYM - 1;
652 curr_fd++;
653 }
654 return 0;
c906108c
SS
655}
656
8af51c36
EZ
657/* Find the next procedure entry that begins beyond INDEX, and return
658 its starting symbol index - 1.
659 QPD is the procedure table, CURR_PD is the proc entry from where to start,
660 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
c906108c 661
8af51c36
EZ
662 Return 0 => not found */
663static int
664find_next_proc_isym (int index, quick_procedure_entry *qPD, int curr_pd,
665 PXDB_header_ptr pxdb_header_p)
c906108c 666{
8af51c36
EZ
667 while (VALID_CURR_PROC)
668 {
669 if (CURR_PROC_ISYM >= index)
670 return CURR_PROC_ISYM - 1;
671 curr_pd++;
672 }
673 return 0;
c906108c
SS
674}
675
8af51c36
EZ
676/* Find the next module entry that begins beyond INDEX, and return
677 its starting symbol index - 1.
678 QMD is the module table, CURR_MD is the modue entry from where to start,
679 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
c906108c 680
8af51c36
EZ
681 Return 0 => not found */
682static int
683find_next_module_isym (int index, quick_module_entry *qMD, int curr_md,
684 PXDB_header_ptr pxdb_header_p)
685{
686 while (VALID_CURR_MODULE)
c906108c 687 {
8af51c36
EZ
688 if (CURR_MODULE_ISYM >= index)
689 return CURR_MODULE_ISYM - 1;
690 curr_md++;
c906108c 691 }
8af51c36 692 return 0;
c906108c 693}
c906108c 694
8af51c36
EZ
695/* Scan and record partial symbols for all functions starting from index
696 pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
697 Other parameters are explained in comments below. */
698
699/* This used to be inline in hpread_quick_traverse, but now that we do
700 essentially the same thing for two different cases (modules and
701 module-less files), it's better organized in a separate routine,
702 although it does take lots of arguments. pai/1997-10-08
703
704 CURR_PD_P is the pointer to the current proc index. QPD is the
705 procedure quick lookup table. MAX_PROCS is the number of entries
706 in the proc. table. START_ADR is the beginning of the code range
707 for the current psymtab. end_adr is the end of the code range for
708 the current psymtab. PST is the current psymtab. VT_bits is
709 a pointer to the strings table of SOM debug space. OBJFILE is
710 the current object file. */
c906108c
SS
711
712static int
8af51c36
EZ
713scan_procs (int *curr_pd_p, quick_procedure_entry *qPD, int max_procs,
714 CORE_ADDR start_adr, CORE_ADDR end_adr, struct partial_symtab *pst,
715 char *vt_bits, struct objfile *objfile)
c906108c 716{
8af51c36
EZ
717 union dnttentry *dn_bufp;
718 int symbol_count = 0; /* Total number of symbols in this psymtab */
719 int curr_pd = *curr_pd_p; /* Convenience variable -- avoid dereferencing pointer all the time */
c906108c 720
8af51c36
EZ
721#ifdef DUMPING
722 /* Turn this on for lots of debugging information in this routine */
723 static int dumping = 0;
724#endif
725
726#ifdef DUMPING
727 if (dumping)
728 {
729 printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
c906108c 730 }
8af51c36 731#endif
c906108c 732
8af51c36
EZ
733 while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
734 {
c906108c 735
8af51c36
EZ
736 char *rtn_name; /* mangled name */
737 char *rtn_dem_name; /* qualified demangled name */
738 char *class_name;
739 int class;
c906108c 740
8af51c36
EZ
741 if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
742 vt_bits[(long) qPD[curr_pd].sbAlias]) /* not a null string */
743 {
744 /* Get mangled name for the procedure, and demangle it */
745 rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
746 rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
747 }
748 else
749 {
750 rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
751 rtn_dem_name = NULL;
752 }
c906108c 753
8af51c36
EZ
754 /* Hack to get around HP C/C++ compilers' insistence on providing
755 "_MAIN_" as an alternate name for "main" */
756 if ((strcmp (rtn_name, "_MAIN_") == 0) &&
757 (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
758 rtn_dem_name = rtn_name = main_string;
c906108c 759
8af51c36
EZ
760#ifdef DUMPING
761 if (dumping)
762 {
763 printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
764 }
765#endif
766
767 /* Check for module-spanning routines. */
768 if (CURR_PROC_END > end_adr)
769 {
770 TELL_OBJFILE;
771 warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
772 }
773
774 /* Add this routine symbol to the list in the objfile.
775 Unfortunately we have to go to the LNTT to determine the
776 correct list to put it on. An alternative (which the
777 code used to do) would be to not check and always throw
778 it on the "static" list. But if we go that route, then
779 symbol_lookup() needs to be tweaked a bit to account
780 for the fact that the function might not be found on
781 the correct list in the psymtab. - RT */
782 dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
783 if (dn_bufp->dfunc.global)
784 add_psymbol_with_dem_name_to_list (rtn_name,
785 strlen (rtn_name),
786 rtn_dem_name,
787 strlen (rtn_dem_name),
176620f1 788 VAR_DOMAIN,
8af51c36
EZ
789 LOC_BLOCK, /* "I am a routine" */
790 &objfile->global_psymbols,
791 (qPD[curr_pd].adrStart + /* Starting address of rtn */
792 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
793 0, /* core addr?? */
794 trans_lang ((enum hp_language) qPD[curr_pd].language),
795 objfile);
796 else
797 add_psymbol_with_dem_name_to_list (rtn_name,
798 strlen (rtn_name),
799 rtn_dem_name,
800 strlen (rtn_dem_name),
176620f1 801 VAR_DOMAIN,
8af51c36
EZ
802 LOC_BLOCK, /* "I am a routine" */
803 &objfile->static_psymbols,
804 (qPD[curr_pd].adrStart + /* Starting address of rtn */
805 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
806 0, /* core addr?? */
807 trans_lang ((enum hp_language) qPD[curr_pd].language),
808 objfile);
809
810 symbol_count++;
811 *curr_pd_p = ++curr_pd; /* bump up count & reflect in caller */
812 } /* loop over procedures */
813
814#ifdef DUMPING
815 if (dumping)
816 {
817 if (symbol_count == 0)
818 printf ("Scan_procs: no symbols found!\n");
819 }
820#endif
821
822 return symbol_count;
c906108c 823}
c906108c 824
c906108c 825
8af51c36 826/* Traverse the quick look-up tables, building a set of psymtabs.
c906108c 827
8af51c36
EZ
828 This constructs a psymtab for modules and files in the quick lookup
829 tables.
c906108c 830
8af51c36
EZ
831 Mostly, modules correspond to compilation units, so we try to
832 create psymtabs that correspond to modules; however, in some cases
833 a file can result in a compiled object which does not have a module
834 entry for it, so in such cases we create a psymtab for the file. */
c906108c 835
f5479e9c 836static int
8af51c36
EZ
837hpread_quick_traverse (struct objfile *objfile, char *gntt_bits,
838 char *vt_bits, PXDB_header_ptr pxdb_header_p)
839{
840 struct partial_symtab *pst;
c906108c 841
8af51c36 842 char *addr;
c906108c 843
8af51c36
EZ
844 quick_procedure_entry *qPD;
845 quick_file_entry *qFD;
846 quick_module_entry *qMD;
847 quick_class_entry *qCD;
c906108c 848
8af51c36
EZ
849 int idx;
850 int i;
851 CORE_ADDR start_adr; /* current psymtab's starting code addr */
852 CORE_ADDR end_adr; /* current psymtab's ending code addr */
853 CORE_ADDR next_mod_adr; /* next module's starting code addr */
854 int curr_pd; /* current procedure */
855 int curr_fd; /* current file */
856 int curr_md; /* current module */
857 int start_sym; /* current psymtab's starting symbol index */
858 int end_sym; /* current psymtab's ending symbol index */
859 int max_LNTT_sym_index;
860 int syms_in_pst;
861 B_TYPE *class_entered;
862
863 struct partial_symbol **global_syms; /* We'll be filling in the "global" */
864 struct partial_symbol **static_syms; /* and "static" tables in the objfile
865 as we go, so we need a pair of
866 current pointers. */
867
868#ifdef DUMPING
869 /* Turn this on for lots of debugging information in this routine.
870 You get a blow-by-blow account of quick lookup table reading */
871 static int dumping = 0;
872#endif
c906108c 873
8af51c36 874 pst = (struct partial_symtab *) 0;
c906108c 875
8af51c36
EZ
876 /* Clear out some globals */
877 init_pst_syms ();
878 told_objfile = 0;
c906108c 879
8af51c36
EZ
880 /* Demangling style -- if EDG style already set, don't change it,
881 as HP style causes some problems with the KAI EDG compiler */
882 if (current_demangling_style != edg_demangling)
883 {
884 /* Otherwise, ensure that we are using HP style demangling */
885 set_demangling_style (HP_DEMANGLING_STYLE_STRING);
c906108c
SS
886 }
887
8af51c36
EZ
888 /* First we need to find the starting points of the quick
889 look-up tables in the GNTT. */
c906108c 890
8af51c36 891 addr = gntt_bits;
c906108c 892
8af51c36
EZ
893 qPD = (quick_procedure_entry_ptr) addr;
894 addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
895
896#ifdef DUMPING
897 if (dumping)
c906108c 898 {
8af51c36
EZ
899 printf ("\n Printing routines as we see them\n");
900 for (i = 0; VALID_PROC (i); i++)
901 {
902 idx = (long) qPD[i].sbProc;
903 printf ("%s %x..%x\n", &vt_bits[idx],
904 (int) PROC_START (i),
905 (int) PROC_END (i));
906 }
907 }
908#endif
c906108c 909
8af51c36
EZ
910 qFD = (quick_file_entry_ptr) addr;
911 addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
c906108c 912
8af51c36
EZ
913#ifdef DUMPING
914 if (dumping)
915 {
916 printf ("\n Printing files as we see them\n");
917 for (i = 0; VALID_FILE (i); i++)
918 {
919 idx = (long) qFD[i].sbFile;
920 printf ("%s %x..%x\n", &vt_bits[idx],
921 (int) FILE_START (i),
922 (int) FILE_END (i));
923 }
c906108c 924 }
8af51c36 925#endif
c906108c 926
8af51c36
EZ
927 qMD = (quick_module_entry_ptr) addr;
928 addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
c906108c 929
8af51c36
EZ
930#ifdef DUMPING
931 if (dumping)
c906108c 932 {
8af51c36
EZ
933 printf ("\n Printing modules as we see them\n");
934 for (i = 0; i < pxdb_header_p->md_entries; i++)
935 {
936 idx = (long) qMD[i].sbMod;
937 printf ("%s\n", &vt_bits[idx]);
938 }
c906108c 939 }
8af51c36 940#endif
c906108c 941
8af51c36
EZ
942 qCD = (quick_class_entry_ptr) addr;
943 addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
c906108c 944
8af51c36
EZ
945#ifdef DUMPING
946 if (dumping)
c906108c 947 {
8af51c36
EZ
948 printf ("\n Printing classes as we see them\n");
949 for (i = 0; VALID_CLASS (i); i++)
950 {
951 idx = (long) qCD[i].sbClass;
952 printf ("%s\n", &vt_bits[idx]);
953 }
c906108c 954
8af51c36 955 printf ("\n Done with dump, on to build!\n");
c906108c 956 }
8af51c36 957#endif
c906108c 958
8af51c36
EZ
959 /* We need this index only while hp-symtab-read.c expects
960 a byte offset to the end of the LNTT entries for a given
961 psymtab. Thus the need for it should go away someday.
962
963 When it goes away, then we won't have any need to load the
964 LNTT from the objfile at psymtab-time, and start-up will be
965 faster. To make that work, we'll need some way to create
966 a null pst for the "globals" pseudo-module. */
967 max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
968
969 /* Scan the module descriptors and make a psymtab for each.
970
971 We know the MDs, FDs and the PDs are in order by starting
972 address. We use that fact to traverse all three arrays in
973 parallel, knowing when the next PD is in a new file
974 and we need to create a new psymtab. */
975 curr_pd = 0; /* Current procedure entry */
976 curr_fd = 0; /* Current file entry */
977 curr_md = 0; /* Current module entry */
978
979 start_adr = 0; /* Current psymtab code range */
980 end_adr = 0;
981
982 start_sym = 0; /* Current psymtab symbol range */
983 end_sym = 0;
984
985 syms_in_pst = 0; /* Symbol count for psymtab */
986
987 /* Psts actually just have pointers into the objfile's
988 symbol table, not their own symbol tables. */
989 global_syms = objfile->global_psymbols.list;
990 static_syms = objfile->static_psymbols.list;
991
992
993 /* First skip over pseudo-entries with address 0. These represent inlined
994 routines and abstract (uninstantiated) template routines.
995 FIXME: These should be read in and available -- even if we can't set
996 breakpoints, etc., there's some information that can be presented
997 to the user. pai/1997-10-08 */
998
999 while (VALID_CURR_PROC && (CURR_PROC_START == 0))
1000 curr_pd++;
1001
1002 /* Loop over files, modules, and procedures in code address order. Each
1003 time we enter an iteration of this loop, curr_pd points to the first
1004 unprocessed procedure, curr_fd points to the first unprocessed file, and
1005 curr_md to the first unprocessed module. Each iteration of this loop
1006 updates these as required -- any or all of them may be bumpd up
1007 each time around. When we exit this loop, we are done with all files
1008 and modules in the tables -- there may still be some procedures, however.
1009
1010 Note: This code used to loop only over module entries, under the assumption
1011 that files can occur via inclusions and are thus unreliable, while a
1012 compiled object always corresponds to a module. With CTTI in the HP aCC
1013 compiler, it turns out that compiled objects may have only files and no
1014 modules; so we have to loop over files and modules, creating psymtabs for
1015 either as appropriate. Unfortunately there are some problems (notably:
1016 1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
1017 to the ending symbol indices of a module or a file) which make it quite hard
1018 to do this correctly. Currently it uses a bunch of heuristics to start and
1019 end psymtabs; they seem to work well with most objects generated by aCC, but
1020 who knows when that will change... */
1021
1022 while (VALID_CURR_FILE || VALID_CURR_MODULE)
1023 {
c906108c 1024
65e82032 1025 char *mod_name_string = NULL;
8af51c36 1026 char *full_name_string;
c906108c 1027
8af51c36
EZ
1028 /* First check for modules like "version.c", which have no code
1029 in them but still have qMD entries. They also have no qFD or
1030 qPD entries. Their start address is -1 and their end address
1031 is 0. */
1032 if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
1033 {
c906108c 1034
8af51c36 1035 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
c906108c 1036
8af51c36
EZ
1037#ifdef DUMPING
1038 if (dumping)
1039 printf ("Module with data only %s\n", mod_name_string);
1040#endif
1041
1042 /* We'll skip the rest (it makes error-checking easier), and
1043 just make an empty pst. Right now empty psts are not put
1044 in the pst chain, so all this is for naught, but later it
1045 might help. */
1046
1047 pst = hpread_start_psymtab (objfile,
1048 mod_name_string,
1049 CURR_MODULE_START, /* Low text address: bogus! */
1050 (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
1051 /* ldsymoff */
1052 global_syms,
1053 static_syms);
1054
1055 pst = hpread_end_psymtab (pst,
1056 NULL, /* psymtab_include_list */
1057 0, /* includes_used */
1058 end_sym * sizeof (struct dntt_type_block),
1059 /* byte index in LNTT of end
1060 = capping symbol offset
1061 = LDSYMOFF of nextfile */
1062 0, /* text high */
1063 NULL, /* dependency_list */
1064 0); /* dependencies_used */
1065
1066 global_syms = objfile->global_psymbols.next;
1067 static_syms = objfile->static_psymbols.next;
1068
1069 curr_md++;
1070 }
1071 else if (VALID_CURR_MODULE &&
1072 ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
1073 (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
c906108c 1074 {
8af51c36
EZ
1075 TELL_OBJFILE;
1076 warning ("Module \"%s\" [0x%s] has non-standard addresses. It starts at 0x%s, ends at 0x%s, and will be skipped.",
1077 mod_name_string, paddr_nz (curr_md), paddr_nz (start_adr), paddr_nz (end_adr));
1078 /* On to next module */
1079 curr_md++;
c906108c 1080 }
8af51c36
EZ
1081 else
1082 {
1083 /* First check if we are looking at a file with code in it
1084 that does not overlap the current module's code range */
c906108c 1085
8af51c36
EZ
1086 if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
1087 {
c906108c 1088
8af51c36
EZ
1089 /* Looking at file not corresponding to any module,
1090 create a psymtab for it */
1091 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1092 start_adr = CURR_FILE_START;
1093 end_adr = CURR_FILE_END;
1094 start_sym = CURR_FILE_ISYM;
c906108c 1095
8af51c36
EZ
1096 /* Check if there are any procedures not handled until now, that
1097 begin before the start address of this file, and if so, adjust
1098 this module's start address to include them. This handles routines that
1099 are in between file or module ranges for some reason (probably
1100 indicates a compiler bug */
c906108c 1101
8af51c36
EZ
1102 if (CURR_PROC_START < start_adr)
1103 {
1104 TELL_OBJFILE;
1105 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1106 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1107 start_adr = CURR_PROC_START;
1108 if (CURR_PROC_ISYM < start_sym)
1109 start_sym = CURR_PROC_ISYM;
1110 }
c906108c 1111
8af51c36
EZ
1112 /* Sometimes (compiler bug -- COBOL) the module end address is higher
1113 than the start address of the next module, so check for that and
1114 adjust accordingly */
c906108c 1115
8af51c36
EZ
1116 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1117 {
1118 TELL_OBJFILE;
1119 warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1120 full_name_string, curr_fd);
1121 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1122 }
1123 if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
1124 {
1125 TELL_OBJFILE;
1126 warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1127 full_name_string, curr_fd);
1128 end_adr = CURR_MODULE_START - 1; /* Is -4 (or -8 for 64-bit) better? */
1129 }
c906108c 1130
c906108c 1131
8af51c36
EZ
1132#ifdef DUMPING
1133 if (dumping)
1134 {
1135 printf ("Make new psymtab for file %s (%x to %x).\n",
1136 full_name_string, start_adr, end_adr);
1137 }
1138#endif
1139 /* Create the basic psymtab, connecting it in the list
1140 for this objfile and pointing its symbol entries
1141 to the current end of the symbol areas in the objfile.
1142
1143 The "ldsymoff" parameter is the byte offset in the LNTT
1144 of the first symbol in this file. Some day we should
1145 turn this into an index (fix in hp-symtab-read.c as well).
1146 And it's not even the right byte offset, as we're using
1147 the size of a union! FIXME! */
1148 pst = hpread_start_psymtab (objfile,
1149 full_name_string,
1150 start_adr, /* Low text address */
1151 (start_sym * sizeof (struct dntt_type_block)),
1152 /* ldsymoff */
1153 global_syms,
1154 static_syms);
1155
1156 /* Set up to only enter each class referenced in this module once. */
1157 class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
1158 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1159
1160 /* Scan the procedure descriptors for procedures in the current
1161 file, based on the starting addresses. */
1162
1163 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1164 start_adr, end_adr, pst, vt_bits, objfile);
1165
1166 /* Get ending symbol offset */
1167
1168 end_sym = 0;
1169 /* First check for starting index before previous psymtab */
1170 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1171 {
1172 end_sym = find_next_pst_start (start_sym);
1173 }
1174 /* Look for next start index of a file or module, or procedure */
1175 if (!end_sym)
1176 {
1177 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1178 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
1179 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1180
1181 if (next_file_isym && next_module_isym)
1182 {
1183 /* pick lower of next file or module start index */
1184 end_sym = min (next_file_isym, next_module_isym);
1185 }
1186 else
1187 {
1188 /* one of them is zero, pick the other */
1189 end_sym = max (next_file_isym, next_module_isym);
1190 }
1191
1192 /* As a precaution, check next procedure index too */
1193 if (!end_sym)
1194 end_sym = next_proc_isym;
1195 else
1196 end_sym = min (end_sym, next_proc_isym);
1197 }
c906108c 1198
8af51c36
EZ
1199 /* Couldn't find procedure, file, or module, use globals as default */
1200 if (!end_sym)
1201 end_sym = pxdb_header_p->globals;
c906108c 1202
8af51c36
EZ
1203#ifdef DUMPING
1204 if (dumping)
1205 {
1206 printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1207 }
1208#endif
c906108c 1209
8af51c36
EZ
1210 pst = hpread_end_psymtab (pst,
1211 NULL, /* psymtab_include_list */
1212 0, /* includes_used */
1213 end_sym * sizeof (struct dntt_type_block),
1214 /* byte index in LNTT of end
1215 = capping symbol offset
1216 = LDSYMOFF of nextfile */
1217 end_adr, /* text high */
1218 NULL, /* dependency_list */
1219 0); /* dependencies_used */
c906108c 1220
8af51c36 1221 record_pst_syms (start_sym, end_sym);
c906108c 1222
8af51c36
EZ
1223 if (NULL == pst)
1224 warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
c906108c 1225
8af51c36
EZ
1226#ifdef DUMPING
1227 if (dumping)
1228 {
1229 printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1230 full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1231 }
1232#endif
1233 /* Prepare for the next psymtab. */
1234 global_syms = objfile->global_psymbols.next;
1235 static_syms = objfile->static_psymbols.next;
1236 xfree (class_entered);
c906108c 1237
8af51c36
EZ
1238 curr_fd++;
1239 } /* Psymtab for file */
1240 else
1241 {
1242 /* We have a module for which we create a psymtab */
c906108c 1243
8af51c36 1244 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
c906108c 1245
8af51c36
EZ
1246 /* We will include the code ranges of any files that happen to
1247 overlap with this module */
c906108c 1248
8af51c36
EZ
1249 /* So, first pick the lower of the file's and module's start addresses */
1250 start_adr = CURR_MODULE_START;
1251 if (VALID_CURR_FILE)
1252 {
1253 if (CURR_FILE_START < CURR_MODULE_START)
1254 {
1255 TELL_OBJFILE;
1256 warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1257 &vt_bits[(long) qFD[curr_fd].sbFile],
1258 curr_fd, mod_name_string);
1259
1260 start_adr = CURR_FILE_START;
1261 }
1262 }
c906108c 1263
8af51c36
EZ
1264 /* Also pick the lower of the file's and the module's start symbol indices */
1265 start_sym = CURR_MODULE_ISYM;
1266 if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1267 start_sym = CURR_FILE_ISYM;
c906108c 1268
8af51c36
EZ
1269 /* For the end address, we scan through the files till we find one
1270 that overlaps the current module but ends beyond it; if no such file exists we
1271 simply use the module's start address.
1272 (Note, if file entries themselves overlap
1273 we take the longest overlapping extension beyond the end of the module...)
1274 We assume that modules never overlap. */
c906108c 1275
8af51c36 1276 end_adr = CURR_MODULE_END;
c906108c 1277
8af51c36
EZ
1278 if (VALID_CURR_FILE)
1279 {
1280 while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1281 {
c906108c 1282
8af51c36
EZ
1283#ifdef DUMPING
1284 if (dumping)
1285 printf ("Maybe skipping file %s which overlaps with module %s\n",
1286 &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1287#endif
1288 if (CURR_FILE_END > end_adr)
1289 {
1290 TELL_OBJFILE;
1291 warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1292 &vt_bits[(long) qFD[curr_fd].sbFile],
1293 curr_fd, mod_name_string);
1294 end_adr = CURR_FILE_END;
1295 }
1296 curr_fd++;
1297 }
1298 curr_fd--; /* back up after going too far */
1299 }
1300
1301 /* Sometimes (compiler bug -- COBOL) the module end address is higher
1302 than the start address of the next module, so check for that and
1303 adjust accordingly */
1304
1305 if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1306 {
1307 TELL_OBJFILE;
1308 warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1309 mod_name_string, curr_md);
1310 end_adr = MODULE_START (curr_md + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1311 }
1312 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1313 {
1314 TELL_OBJFILE;
1315 warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1316 mod_name_string, curr_md);
1317 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1318 }
1319
1320 /* Use one file to get the full name for the module. This
1321 situation can arise if there is executable code in a #include
1322 file. Each file with code in it gets a qFD. Files which don't
1323 contribute code don't get a qFD, even if they include files
1324 which do, e.g.:
1325
1326 body.c: rtn.h:
1327 int x; int main() {
1328 #include "rtn.h" return x;
1329 }
1330
1331 There will a qFD for "rtn.h",and a qMD for "body.c",
1332 but no qMD for "rtn.h" or qFD for "body.c"!
1333
1334 We pick the name of the last file to overlap with this
1335 module. C convention is to put include files first. In a
1336 perfect world, we could check names and use the file whose full
1337 path name ends with the module name. */
1338
1339 if (VALID_CURR_FILE)
1340 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1341 else
1342 full_name_string = mod_name_string;
1343
1344 /* Check if there are any procedures not handled until now, that
1345 begin before the start address we have now, and if so, adjust
1346 this psymtab's start address to include them. This handles routines that
1347 are in between file or module ranges for some reason (probably
1348 indicates a compiler bug */
1349
1350 if (CURR_PROC_START < start_adr)
1351 {
1352 TELL_OBJFILE;
1353 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1354 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1355 start_adr = CURR_PROC_START;
1356 if (CURR_PROC_ISYM < start_sym)
1357 start_sym = CURR_PROC_ISYM;
1358 }
1359
1360#ifdef DUMPING
1361 if (dumping)
1362 {
1363 printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1364 mod_name_string, start_adr, end_adr, full_name_string);
1365 }
1366#endif
1367 /* Create the basic psymtab, connecting it in the list
1368 for this objfile and pointing its symbol entries
1369 to the current end of the symbol areas in the objfile.
1370
1371 The "ldsymoff" parameter is the byte offset in the LNTT
1372 of the first symbol in this file. Some day we should
1373 turn this into an index (fix in hp-symtab-read.c as well).
1374 And it's not even the right byte offset, as we're using
1375 the size of a union! FIXME! */
1376 pst = hpread_start_psymtab (objfile,
1377 full_name_string,
1378 start_adr, /* Low text address */
1379 (start_sym * sizeof (struct dntt_type_block)),
1380 /* ldsymoff */
1381 global_syms,
1382 static_syms);
1383
1384 /* Set up to only enter each class referenced in this module once. */
1385 class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
1386 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1387
1388 /* Scan the procedure descriptors for procedures in the current
1389 module, based on the starting addresses. */
1390
1391 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1392 start_adr, end_adr, pst, vt_bits, objfile);
1393
1394 /* Get ending symbol offset */
1395
1396 end_sym = 0;
1397 /* First check for starting index before previous psymtab */
1398 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1399 {
1400 end_sym = find_next_pst_start (start_sym);
1401 }
1402 /* Look for next start index of a file or module, or procedure */
1403 if (!end_sym)
1404 {
1405 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1406 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1407 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1408
1409 if (next_file_isym && next_module_isym)
1410 {
1411 /* pick lower of next file or module start index */
1412 end_sym = min (next_file_isym, next_module_isym);
1413 }
1414 else
1415 {
1416 /* one of them is zero, pick the other */
1417 end_sym = max (next_file_isym, next_module_isym);
1418 }
1419
1420 /* As a precaution, check next procedure index too */
1421 if (!end_sym)
1422 end_sym = next_proc_isym;
1423 else
1424 end_sym = min (end_sym, next_proc_isym);
1425 }
1426
1427 /* Couldn't find procedure, file, or module, use globals as default */
1428 if (!end_sym)
1429 end_sym = pxdb_header_p->globals;
1430
1431#ifdef DUMPING
1432 if (dumping)
1433 {
1434 printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1435 }
1436#endif
1437
1438 pst = hpread_end_psymtab (pst,
1439 NULL, /* psymtab_include_list */
1440 0, /* includes_used */
1441 end_sym * sizeof (struct dntt_type_block),
1442 /* byte index in LNTT of end
1443 = capping symbol offset
1444 = LDSYMOFF of nextfile */
1445 end_adr, /* text high */
1446 NULL, /* dependency_list */
1447 0); /* dependencies_used */
1448
1449 record_pst_syms (start_sym, end_sym);
1450
1451 if (NULL == pst)
1452 warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1453
1454#ifdef DUMPING
1455 if (dumping)
1456 {
1457 printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1458 mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1459 }
1460#endif
1461
1462 /* Prepare for the next psymtab. */
1463 global_syms = objfile->global_psymbols.next;
1464 static_syms = objfile->static_psymbols.next;
1465 xfree (class_entered);
1466
1467 curr_md++;
1468 curr_fd++;
1469 } /* psymtab for module */
1470 } /* psymtab for non-bogus file or module */
1471 } /* End of while loop over all files & modules */
1472
1473 /* There may be some routines after all files and modules -- these will get
1474 inserted in a separate new module of their own */
1475 if (VALID_CURR_PROC)
c906108c 1476 {
8af51c36
EZ
1477 start_adr = CURR_PROC_START;
1478 end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1479 TELL_OBJFILE;
1480 warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1481#ifdef DUMPING
1482 if (dumping)
c906108c 1483 {
8af51c36
EZ
1484 printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1485 curr_pd, start_adr, end_adr);
c906108c 1486 }
8af51c36
EZ
1487#endif
1488 pst = hpread_start_psymtab (objfile,
1489 "orphans",
1490 start_adr, /* Low text address */
1491 (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1492 /* ldsymoff */
1493 global_syms,
1494 static_syms);
1495
1496 scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1497 start_adr, end_adr, pst, vt_bits, objfile);
1498
1499 pst = hpread_end_psymtab (pst,
1500 NULL, /* psymtab_include_list */
1501 0, /* includes_used */
1502 pxdb_header_p->globals * sizeof (struct dntt_type_block),
1503 /* byte index in LNTT of end
1504 = capping symbol offset
1505 = LDSYMOFF of nextfile */
1506 end_adr, /* text high */
1507 NULL, /* dependency_list */
1508 0); /* dependencies_used */
c906108c 1509 }
c906108c 1510
c906108c 1511
8af51c36
EZ
1512#ifdef NEVER_NEVER
1513 /* Now build psts for non-module things (in the tail of
1514 the LNTT, after the last END MODULE entry).
1515
1516 If null psts were kept on the chain, this would be
1517 a solution. FIXME */
1518 pst = hpread_start_psymtab (objfile,
1519 "globals",
1520 0,
1521 (pxdb_header_p->globals
1522 * sizeof (struct dntt_type_block)),
1523 objfile->global_psymbols.next,
1524 objfile->static_psymbols.next);
1525 hpread_end_psymtab (pst,
1526 NULL, 0,
1527 (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1528 0,
1529 NULL, 0);
1530#endif
c906108c 1531
8af51c36 1532 clear_pst_syms ();
c906108c 1533
8af51c36 1534 return 1;
c906108c 1535
8af51c36
EZ
1536} /* End of hpread_quick_traverse. */
1537\f
c906108c 1538
8af51c36
EZ
1539/* Get appropriate header, based on pxdb type.
1540 Return value: 1 if ok, 0 if not */
f5479e9c 1541static int
8af51c36 1542hpread_get_header (struct objfile *objfile, PXDB_header_ptr pxdb_header_p)
c906108c 1543{
8af51c36 1544 asection *pinfo_section, *debug_section, *header_section;
c906108c 1545
8af51c36
EZ
1546#ifdef DUMPING
1547 /* Turn on for debugging information */
1548 static int dumping = 0;
1549#endif
c906108c 1550
8af51c36
EZ
1551 header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1552 if (!header_section)
1553 {
1554 /* We don't have either PINFO or DEBUG sections. But
1555 stuff like "libc.sl" has no debug info. There's no
1556 need to warn the user of this, as it may be ok. The
1557 caller will figure it out and issue any needed
1558 messages. */
1559#ifdef DUMPING
1560 if (dumping)
1561 printf ("==No debug info at all for %s.\n", objfile->name);
1562#endif
1563
1564 return 0;
1565 }
1566
1567 /* We would like either a $DEBUG$ or $PINFO$ section.
1568 Once we know which, we can understand the header
1569 data (which we have defined to suit the more common
1570 $DEBUG$ case). */
1571 debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1572 pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1573 if (debug_section)
1574 {
1575 /* The expected case: normal pxdb header. */
1576 bfd_get_section_contents (objfile->obfd, header_section,
1577 pxdb_header_p, 0, sizeof (PXDB_header));
1578
1579 if (!pxdb_header_p->pxdbed)
1580 {
1581 /* This shouldn't happen if we check in "symfile.c". */
1582 return 0;
1583 } /* DEBUG section */
1584 }
1585
1586 else if (pinfo_section)
1587 {
1588 /* The DOC case; we need to translate this into a
1589 regular header. */
1590 DOC_info_PXDB_header doc_header;
1591
1592#ifdef DUMPING
1593 if (dumping)
1594 {
1595 printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1596 }
1597#endif
1598
1599 bfd_get_section_contents (objfile->obfd,
1600 header_section,
1601 &doc_header, 0,
1602 sizeof (DOC_info_PXDB_header));
1603
1604 if (!doc_header.pxdbed)
1605 {
1606 /* This shouldn't happen if we check in "symfile.c". */
1607 warning ("File \"%s\" not processed by pxdb!", objfile->name);
1608 return 0;
1609 }
1610
1611 /* Copy relevent fields to standard header passed in. */
1612 pxdb_header_p->pd_entries = doc_header.pd_entries;
1613 pxdb_header_p->fd_entries = doc_header.fd_entries;
1614 pxdb_header_p->md_entries = doc_header.md_entries;
1615 pxdb_header_p->pxdbed = doc_header.pxdbed;
1616 pxdb_header_p->bighdr = doc_header.bighdr;
1617 pxdb_header_p->sa_header = doc_header.sa_header;
1618 pxdb_header_p->inlined = doc_header.inlined;
1619 pxdb_header_p->globals = doc_header.globals;
1620 pxdb_header_p->time = doc_header.time;
1621 pxdb_header_p->pg_entries = doc_header.pg_entries;
1622 pxdb_header_p->functions = doc_header.functions;
1623 pxdb_header_p->files = doc_header.files;
1624 pxdb_header_p->cd_entries = doc_header.cd_entries;
1625 pxdb_header_p->aa_entries = doc_header.aa_entries;
1626 pxdb_header_p->oi_entries = doc_header.oi_entries;
1627 pxdb_header_p->version = doc_header.version;
1628 } /* PINFO section */
1629
1630 else
1631 {
1632#ifdef DUMPING
1633 if (dumping)
1634 printf ("==No debug info at all for %s.\n", objfile->name);
1635#endif
1636
1637 return 0;
1638
1639 }
1640
1641 return 1;
1642} /* End of hpread_get_header */
1643#endif /* QUICK_LOOK_UP */
1644\f
1645
1646/* Initialization for reading native HP C debug symbols from OBJFILE.
1647
1648 Its only purpose in life is to set up the symbol reader's private
1649 per-objfile data structures, and read in the raw contents of the debug
1650 sections (attaching pointers to the debug info into the private data
1651 structures).
1652
1653 Since BFD doesn't know how to read debug symbols in a format-independent
1654 way (and may never do so...), we have to do it ourselves. Note we may
1655 be called on a file without native HP C debugging symbols.
1656
1657 FIXME, there should be a cleaner peephole into the BFD environment
1658 here. */
1659void
1660hpread_symfile_init (struct objfile *objfile)
1661{
1662 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1663
1664 /* Allocate struct to keep track of the symfile */
4efb68b1 1665 objfile->sym_private =
8af51c36
EZ
1666 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
1667 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1668
1669 /* We haven't read in any types yet. */
9a6f53fe 1670 DNTT_TYPE_VECTOR (objfile) = 0;
8af51c36
EZ
1671
1672 /* Read in data from the $GNTT$ subspace. */
1673 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1674 if (!gntt_section)
1675 return;
1676
1677 GNTT (objfile)
4a146b47 1678 = obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
1679 bfd_section_size (objfile->obfd, gntt_section));
1680
1681 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1682 0, bfd_section_size (objfile->obfd, gntt_section));
1683
1684 GNTT_SYMCOUNT (objfile)
1685 = bfd_section_size (objfile->obfd, gntt_section)
1686 / sizeof (struct dntt_type_block);
1687
1688 /* Read in data from the $LNTT$ subspace. Also keep track of the number
1689 of LNTT symbols.
1690
1691 FIXME: this could be moved into the psymtab-to-symtab expansion
1692 code, and save startup time. At the moment this data is
1693 still used, though. We'd need a way to tell hp-symtab-read.c
1694 whether or not to load the LNTT. */
1695 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1696 if (!lntt_section)
1697 return;
1698
1699 LNTT (objfile)
4a146b47 1700 = obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
1701 bfd_section_size (objfile->obfd, lntt_section));
1702
1703 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1704 0, bfd_section_size (objfile->obfd, lntt_section));
1705
1706 LNTT_SYMCOUNT (objfile)
1707 = bfd_section_size (objfile->obfd, lntt_section)
1708 / sizeof (struct dntt_type_block);
1709
1710 /* Read in data from the $SLT$ subspace. $SLT$ contains information
1711 on source line numbers. */
1712 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1713 if (!slt_section)
1714 return;
1715
1716 SLT (objfile) =
4a146b47 1717 obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
1718 bfd_section_size (objfile->obfd, slt_section));
1719
1720 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1721 0, bfd_section_size (objfile->obfd, slt_section));
1722
1723 /* Read in data from the $VT$ subspace. $VT$ contains things like
1724 names and constants. Keep track of the number of symbols in the VT. */
1725 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1726 if (!vt_section)
1727 return;
1728
1729 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1730
1731 VT (objfile) =
4a146b47 1732 (char *) obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
1733 VT_SIZE (objfile));
1734
1735 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1736 0, VT_SIZE (objfile));
1737}
1738
1739/* Scan and build partial symbols for a symbol file.
1740
1741 The minimal symbol table (either SOM or HP a.out) has already been
1742 read in; all we need to do is setup partial symbols based on the
1743 native debugging information.
1744
1745 Note that the minimal table is produced by the linker, and has
1746 only global routines in it; the psymtab is based on compiler-
1747 generated debug information and has non-global
1748 routines in it as well as files and class information.
1749
1750 We assume hpread_symfile_init has been called to initialize the
1751 symbol reader's private data structures.
1752
1753 MAINLINE is true if we are reading the main symbol table (as
1754 opposed to a shared lib or dynamically loaded file). */
1755
1756void
1757hpread_build_psymtabs (struct objfile *objfile, int mainline)
1758{
1759
1760#ifdef DUMPING
1761 /* Turn this on to get debugging output. */
1762 static int dumping = 0;
1763#endif
1764
1765 char *namestring;
1766 int past_first_source_file = 0;
1767 struct cleanup *old_chain;
1768
1769 int hp_symnum, symcount, i;
1770 int scan_start = 0;
1771
1772 union dnttentry *dn_bufp;
1773 unsigned long valu;
1774 char *p;
1775 int texthigh = 0;
1776 int have_name = 0;
1777
1778 /* Current partial symtab */
1779 struct partial_symtab *pst;
1780
1781 /* List of current psymtab's include files */
1782 char **psymtab_include_list;
1783 int includes_allocated;
1784 int includes_used;
1785
1786 /* Index within current psymtab dependency list */
1787 struct partial_symtab **dependency_list;
1788 int dependencies_used, dependencies_allocated;
1789
1790 /* Just in case the stabs reader left turds lying around. */
1791 free_pending_blocks ();
1792 make_cleanup (really_free_pendings, 0);
1793
1794 pst = (struct partial_symtab *) 0;
1795
1796 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
1797 a number of problems with cross compilation and creating useless holes
1798 in the stack when we have to allocate new entries. FIXME. */
1799
1800 includes_allocated = 30;
1801 includes_used = 0;
1802 psymtab_include_list = (char **) alloca (includes_allocated *
1803 sizeof (char *));
1804
1805 dependencies_allocated = 30;
1806 dependencies_used = 0;
1807 dependency_list =
1808 (struct partial_symtab **) alloca (dependencies_allocated *
1809 sizeof (struct partial_symtab *));
1810
1811 old_chain = make_cleanup_free_objfile (objfile);
1812
1813 last_source_file = 0;
1814
1815#ifdef QUICK_LOOK_UP
1816 {
1817 /* Begin code for new-style loading of quick look-up tables. */
1818
1819 /* elz: this checks whether the file has beeen processed by pxdb.
1820 If not we would like to try to read the psymbols in
1821 anyway, but it turns out to be not so easy. So this could
1822 actually be commented out, but I leave it in, just in case
1823 we decide to add support for non-pxdb-ed stuff in the future. */
1824 PXDB_header pxdb_header;
1825 int found_modules_in_program;
1826
1827 if (hpread_get_header (objfile, &pxdb_header))
1828 {
1829 /* Build a minimal table. No types, no global variables,
1830 no include files.... */
1831#ifdef DUMPING
1832 if (dumping)
1833 printf ("\nNew method for %s\n", objfile->name);
1834#endif
1835
1836 /* elz: quick_traverse returns true if it found
1837 some modules in the main source file, other
1838 than those in end.c
1839 In C and C++, all the files have MODULES entries
1840 in the LNTT, and the quick table traverse is all
1841 based on finding these MODULES entries. Without
1842 those it cannot work.
1843 It happens that F77 programs don't have MODULES
1844 so the quick traverse gets confused. F90 programs
1845 have modules, and the quick method still works.
1846 So, if modules (other than those in end.c) are
1847 not found we give up on the quick table stuff,
1848 and fall back on the slower method */
1849 found_modules_in_program = hpread_quick_traverse (objfile,
1850 GNTT (objfile),
1851 VT (objfile),
1852 &pxdb_header);
1853
1854 discard_cleanups (old_chain);
1855
1856 /* Set up to scan the global section of the LNTT.
1857
1858 This field is not always correct: if there are
1859 no globals, it will point to the last record in
1860 the regular LNTT, which is usually an END MODULE.
1861
1862 Since it might happen that there could be a file
1863 with just one global record, there's no way to
1864 tell other than by looking at the record, so that's
1865 done below. */
1866 if (found_modules_in_program)
1867 scan_start = pxdb_header.globals;
1868 }
1869#ifdef DUMPING
1870 else
1871 {
1872 if (dumping)
1873 printf ("\nGoing on to old method for %s\n", objfile->name);
1874 }
1875#endif
1876 }
1877#endif /* QUICK_LOOK_UP */
1878
1879 /* Make two passes, one over the GNTT symbols, the other for the
1880 LNTT symbols.
1881
1882 JB comment: above isn't true--they only make one pass, over
1883 the LNTT. */
1884 for (i = 0; i < 1; i++)
1885 {
1886 int within_function = 0;
1887
1888 if (i)
1889 symcount = GNTT_SYMCOUNT (objfile);
1890 else
1891 symcount = LNTT_SYMCOUNT (objfile);
1892
1893
1894 for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1895 {
1896 QUIT;
1897 if (i)
1898 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1899 else
1900 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1901
1902 if (dn_bufp->dblock.extension)
1903 continue;
1904
1905 /* Only handle things which are necessary for minimal symbols.
1906 everything else is ignored. */
1907 switch (dn_bufp->dblock.kind)
1908 {
1909 case DNTT_TYPE_SRCFILE:
1910 {
1911#ifdef QUICK_LOOK_UP
1912 if (scan_start == hp_symnum
1913 && symcount == hp_symnum + 1)
1914 {
1915 /* If there are NO globals in an executable,
1916 PXDB's index to the globals will point to
1917 the last record in the file, which
1918 could be this record. (this happened for F77 libraries)
1919 ignore it and be done! */
1920 continue;
1921 }
1922#endif /* QUICK_LOOK_UP */
1923
1924 /* A source file of some kind. Note this may simply
1925 be an included file. */
68b8d23e 1926 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
1927
1928 /* Check if this is the source file we are already working
1929 with. */
1930 if (pst && !strcmp (namestring, pst->filename))
1931 continue;
1932
1933 /* Check if this is an include file, if so check if we have
1934 already seen it. Add it to the include list */
1935 p = strrchr (namestring, '.');
1936 if (!strcmp (p, ".h"))
1937 {
1938 int j, found;
1939
1940 found = 0;
1941 for (j = 0; j < includes_used; j++)
1942 if (!strcmp (namestring, psymtab_include_list[j]))
1943 {
1944 found = 1;
1945 break;
1946 }
1947 if (found)
1948 continue;
1949
1950 /* Add it to the list of includes seen so far and
1951 allocate more include space if necessary. */
1952 psymtab_include_list[includes_used++] = namestring;
1953 if (includes_used >= includes_allocated)
1954 {
1955 char **orig = psymtab_include_list;
1956
1957 psymtab_include_list = (char **)
1958 alloca ((includes_allocated *= 2) *
1959 sizeof (char *));
4efb68b1 1960 memcpy (psymtab_include_list, orig,
8af51c36
EZ
1961 includes_used * sizeof (char *));
1962 }
1963 continue;
1964 }
1965
1966 if (pst)
1967 {
1968 if (!have_name)
1969 {
1970 pst->filename = (char *)
8b92e4d5 1971 obstack_alloc (&pst->objfile->objfile_obstack,
8af51c36
EZ
1972 strlen (namestring) + 1);
1973 strcpy (pst->filename, namestring);
1974 have_name = 1;
1975 continue;
1976 }
1977 continue;
1978 }
1979
1980 /* This is a bonafide new source file.
1981 End the current partial symtab and start a new one. */
1982
1983 if (pst && past_first_source_file)
1984 {
1985 hpread_end_psymtab (pst, psymtab_include_list,
1986 includes_used,
1987 (hp_symnum
1988 * sizeof (struct dntt_type_block)),
1989 texthigh,
1990 dependency_list, dependencies_used);
1991 pst = (struct partial_symtab *) 0;
1992 includes_used = 0;
1993 dependencies_used = 0;
1994 }
1995 else
1996 past_first_source_file = 1;
1997
1998 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1999 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2000 pst = hpread_start_psymtab (objfile,
2001 namestring, valu,
2002 (hp_symnum
2003 * sizeof (struct dntt_type_block)),
2004 objfile->global_psymbols.next,
2005 objfile->static_psymbols.next);
2006 texthigh = valu;
2007 have_name = 1;
2008 continue;
2009 }
2010
2011 case DNTT_TYPE_MODULE:
2012 /* A source file. It's still unclear to me what the
2013 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
2014 is supposed to be. */
2015
2016 /* First end the previous psymtab */
2017 if (pst)
2018 {
2019 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2020 ((hp_symnum - 1)
2021 * sizeof (struct dntt_type_block)),
2022 texthigh,
2023 dependency_list, dependencies_used);
2024 pst = (struct partial_symtab *) 0;
2025 includes_used = 0;
2026 dependencies_used = 0;
2027 have_name = 0;
2028 }
2029
2030 /* Now begin a new module and a new psymtab for it */
68b8d23e 2031 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
2032 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
2033 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2034 if (!pst)
2035 {
2036 pst = hpread_start_psymtab (objfile,
2037 namestring, valu,
2038 (hp_symnum
2039 * sizeof (struct dntt_type_block)),
2040 objfile->global_psymbols.next,
2041 objfile->static_psymbols.next);
2042 texthigh = valu;
2043 have_name = 0;
2044 }
2045 continue;
2046
2047 case DNTT_TYPE_FUNCTION:
2048 case DNTT_TYPE_ENTRY:
2049 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
2050 a secondary entry point. */
2051 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
2052 SECT_OFF_TEXT (objfile));
2053 if (valu > texthigh)
2054 texthigh = valu;
2055 valu = dn_bufp->dfunc.lowaddr +
2056 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
68b8d23e 2057 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
2058 if (dn_bufp->dfunc.global)
2059 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2060 VAR_DOMAIN, LOC_BLOCK,
8af51c36
EZ
2061 &objfile->global_psymbols, valu,
2062 0, language_unknown, objfile);
2063 else
2064 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2065 VAR_DOMAIN, LOC_BLOCK,
8af51c36
EZ
2066 &objfile->static_psymbols, valu,
2067 0, language_unknown, objfile);
2068 within_function = 1;
2069 continue;
2070
2071 case DNTT_TYPE_DOC_FUNCTION:
2072 valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (objfile->section_offsets,
2073 SECT_OFF_TEXT (objfile));
2074 if (valu > texthigh)
2075 texthigh = valu;
2076 valu = dn_bufp->ddocfunc.lowaddr +
2077 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
68b8d23e 2078 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
2079 if (dn_bufp->ddocfunc.global)
2080 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2081 VAR_DOMAIN, LOC_BLOCK,
8af51c36
EZ
2082 &objfile->global_psymbols, valu,
2083 0, language_unknown, objfile);
2084 else
2085 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2086 VAR_DOMAIN, LOC_BLOCK,
8af51c36
EZ
2087 &objfile->static_psymbols, valu,
2088 0, language_unknown, objfile);
2089 within_function = 1;
2090 continue;
2091
2092 case DNTT_TYPE_BEGIN:
2093 case DNTT_TYPE_END:
2094 /* We don't check MODULE end here, because there can be
2095 symbols beyond the module end which properly belong to the
2096 current psymtab -- so we wait till the next MODULE start */
2097
2098
2099#ifdef QUICK_LOOK_UP
2100 if (scan_start == hp_symnum
2101 && symcount == hp_symnum + 1)
2102 {
2103 /* If there are NO globals in an executable,
2104 PXDB's index to the globals will point to
2105 the last record in the file, which is
2106 probably an END MODULE, i.e. this record.
2107 ignore it and be done! */
2108 continue;
2109 }
2110#endif /* QUICK_LOOK_UP */
2111
2112 /* Scope block begin/end. We only care about function
2113 and file blocks right now. */
2114
2115 if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
2116 (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
2117 within_function = 0;
2118 continue;
2119
2120 case DNTT_TYPE_SVAR:
2121 case DNTT_TYPE_DVAR:
2122 case DNTT_TYPE_TYPEDEF:
2123 case DNTT_TYPE_TAGDEF:
2124 {
2125 /* Variables, typedefs an the like. */
2126 enum address_class storage;
176620f1 2127 domain_enum domain;
8af51c36
EZ
2128
2129 /* Don't add locals to the partial symbol table. */
2130 if (within_function
2131 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
2132 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
2133 continue;
2134
176620f1 2135 /* TAGDEFs go into the structure domain. */
8af51c36 2136 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
176620f1 2137 domain = STRUCT_DOMAIN;
8af51c36 2138 else
176620f1 2139 domain = VAR_DOMAIN;
8af51c36
EZ
2140
2141 /* What kind of "storage" does this use? */
2142 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
2143 storage = LOC_STATIC;
2144 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
2145 && dn_bufp->ddvar.regvar)
2146 storage = LOC_REGISTER;
2147 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
2148 storage = LOC_LOCAL;
2149 else
2150 storage = LOC_UNDEF;
2151
68b8d23e 2152 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
2153 if (!pst)
2154 {
2155 pst = hpread_start_psymtab (objfile,
2156 "globals", 0,
2157 (hp_symnum
2158 * sizeof (struct dntt_type_block)),
2159 objfile->global_psymbols.next,
2160 objfile->static_psymbols.next);
2161 }
2162
2163 /* Compute address of the data symbol */
2164 valu = dn_bufp->dsvar.location;
2165 /* Relocate in case it's in a shared library */
2166 if (storage == LOC_STATIC)
2167 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2168
2169 /* Luckily, dvar, svar, typedef, and tagdef all
2170 have their "global" bit in the same place, so it works
2171 (though it's bad programming practice) to reference
2172 "dsvar.global" even though we may be looking at
2173 any of the above four types. */
2174 if (dn_bufp->dsvar.global)
2175 {
2176 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2177 domain, storage,
8af51c36
EZ
2178 &objfile->global_psymbols,
2179 valu,
2180 0, language_unknown, objfile);
2181 }
2182 else
2183 {
2184 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2185 domain, storage,
8af51c36
EZ
2186 &objfile->static_psymbols,
2187 valu,
2188 0, language_unknown, objfile);
2189 }
2190
2191 /* For TAGDEF's, the above code added the tagname to the
176620f1 2192 struct domain. This will cause tag "t" to be found
8af51c36
EZ
2193 on a reference of the form "(struct t) x". But for
2194 C++ classes, "t" will also be a typename, which we
2195 want to find on a reference of the form "ptype t".
176620f1 2196 Therefore, we also add "t" to the var domain.
8af51c36
EZ
2197 Do the same for enum's due to the way aCC generates
2198 debug info for these (see more extended comment
2199 in hp-symtab-read.c).
2200 We do the same for templates, so that "ptype t"
2201 where "t" is a template also works. */
2202 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2203 dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2204 {
2205 int global = dn_bufp->dtag.global;
2206 /* Look ahead to see if it's a C++ class */
2207 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2208 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2209 dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2210 dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2211 {
2212 if (global)
2213 {
2214 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2215 VAR_DOMAIN, storage,
8af51c36
EZ
2216 &objfile->global_psymbols,
2217 dn_bufp->dsvar.location,
2218 0, language_unknown, objfile);
2219 }
2220 else
2221 {
2222 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2223 VAR_DOMAIN, storage,
8af51c36
EZ
2224 &objfile->static_psymbols,
2225 dn_bufp->dsvar.location,
2226 0, language_unknown, objfile);
2227 }
2228 }
2229 }
2230 }
2231 continue;
2232
2233 case DNTT_TYPE_MEMENUM:
2234 case DNTT_TYPE_CONST:
2235 /* Constants and members of enumerated types. */
68b8d23e 2236 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
2237 if (!pst)
2238 {
2239 pst = hpread_start_psymtab (objfile,
2240 "globals", 0,
2241 (hp_symnum
2242 * sizeof (struct dntt_type_block)),
2243 objfile->global_psymbols.next,
2244 objfile->static_psymbols.next);
2245 }
2246 if (dn_bufp->dconst.global)
2247 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2248 VAR_DOMAIN, LOC_CONST,
8af51c36
EZ
2249 &objfile->global_psymbols, 0,
2250 0, language_unknown, objfile);
2251 else
2252 add_psymbol_to_list (namestring, strlen (namestring),
176620f1 2253 VAR_DOMAIN, LOC_CONST,
8af51c36
EZ
2254 &objfile->static_psymbols, 0,
2255 0, language_unknown, objfile);
2256 continue;
2257 default:
2258 continue;
2259 }
2260 }
2261 }
2262
2263 /* End any pending partial symbol table. */
2264 if (pst)
2265 {
2266 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2267 hp_symnum * sizeof (struct dntt_type_block),
2268 0, dependency_list, dependencies_used);
2269 }
2270
2271 discard_cleanups (old_chain);
2272}
2273
2274/* Perform any local cleanups required when we are done with a particular
2275 objfile. I.E, we are in the process of discarding all symbol information
2276 for an objfile, freeing up all memory held for it, and unlinking the
2277 objfile struct from the global list of known objfiles. */
2278
2279void
2280hpread_symfile_finish (struct objfile *objfile)
2281{
2282 if (objfile->sym_private != NULL)
2283 {
2284 xmfree (objfile->md, objfile->sym_private);
2285 }
2286}
2287\f
2288
2289/* The remaining functions are all for internal use only. */
2290
2291/* Various small functions to get entries in the debug symbol sections. */
2292
f5479e9c 2293static union dnttentry *
8af51c36
EZ
2294hpread_get_lntt (int index, struct objfile *objfile)
2295{
2296 return (union dnttentry *)
2297 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2298}
2299
2300static union dnttentry *
2301hpread_get_gntt (int index, struct objfile *objfile)
2302{
2303 return (union dnttentry *)
2304 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2305}
2306
f5479e9c 2307static union sltentry *
8af51c36
EZ
2308hpread_get_slt (int index, struct objfile *objfile)
2309{
2310 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2311}
2312
2313/* Get the low address associated with some symbol (typically the start
2314 of a particular source file or module). Since that information is not
2315 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
2316 must infer it from the existence of DNTT_TYPE_FUNCTION symbols. */
2317
2318static unsigned long
2319hpread_get_textlow (int global, int index, struct objfile *objfile,
2320 int symcount)
2321{
65e82032 2322 union dnttentry *dn_bufp = NULL;
8af51c36
EZ
2323 struct minimal_symbol *msymbol;
2324
2325 /* Look for a DNTT_TYPE_FUNCTION symbol. */
2326 if (index < symcount) /* symcount is the number of symbols in */
2327 { /* the dbinfo, LNTT table */
2328 do
2329 {
2330 if (global)
2331 dn_bufp = hpread_get_gntt (index++, objfile);
2332 else
2333 dn_bufp = hpread_get_lntt (index++, objfile);
2334 }
2335 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2336 && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2337 && dn_bufp->dblock.kind != DNTT_TYPE_END
2338 && index < symcount);
2339 }
2340
65e82032
AC
2341 /* NOTE: cagney/2003-03-29: If !(index < symcount), dn_bufp is left
2342 undefined and that means that the test below is using a garbage
2343 pointer from the stack. */
2344 gdb_assert (dn_bufp != NULL);
2345
8af51c36
EZ
2346 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
2347 might happen when a sourcefile has no functions. */
2348 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2349 return 0;
2350
2351 /* Avoid going past the end of the LNTT file */
2352 if (index == symcount)
2353 return 0;
2354
2355 /* The minimal symbols are typically more accurate for some reason. */
2356 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2357 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2358 objfile);
2359 else /* must be a DNTT_TYPE_DOC_FUNCTION */
2360 msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2361 objfile);
2362
2363 if (msymbol)
2364 return SYMBOL_VALUE_ADDRESS (msymbol);
2365 else
2366 return dn_bufp->dfunc.lowaddr;
2367}
2368
2369/* Allocate and partially fill a partial symtab. It will be
2370 completely filled at the end of the symbol list.
2371
2372 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2373 is the address relative to which its symbols are (incremental) or 0
2374 (normal). */
2375
2376static struct partial_symtab *
2377hpread_start_psymtab (struct objfile *objfile, char *filename,
2378 CORE_ADDR textlow, int ldsymoff,
2379 struct partial_symbol **global_syms,
2380 struct partial_symbol **static_syms)
2381{
2382 int offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2383 extern void hpread_psymtab_to_symtab ();
2384 struct partial_symtab *result =
2385 start_psymtab_common (objfile, objfile->section_offsets,
2386 filename, textlow, global_syms, static_syms);
2387
2388 result->textlow += offset;
2389 result->read_symtab_private = (char *)
8b92e4d5 2390 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
8af51c36
EZ
2391 LDSYMOFF (result) = ldsymoff;
2392 result->read_symtab = hpread_psymtab_to_symtab;
2393
2394 return result;
2395}
2396\f
2397
2398/* Close off the current usage of PST.
2399 Returns PST or NULL if the partial symtab was empty and thrown away.
2400
2401 capping_symbol_offset --Byte index in LNTT or GNTT of the
2402 last symbol processed during the build
2403 of the previous pst.
2404
2405 FIXME: List variables and peculiarities of same. */
2406
2407static struct partial_symtab *
2408hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
2409 int num_includes, int capping_symbol_offset,
2410 CORE_ADDR capping_text,
2411 struct partial_symtab **dependency_list,
2412 int number_dependencies)
2413{
2414 int i;
2415 struct objfile *objfile = pst->objfile;
2416 int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
2417
2418#ifdef DUMPING
2419 /* Turn on to see what kind of a psymtab we've built. */
2420 static int dumping = 0;
2421#endif
2422
2423 if (capping_symbol_offset != -1)
2424 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2425 else
2426 LDSYMLEN (pst) = 0;
2427 pst->texthigh = capping_text + offset;
2428
2429 pst->n_global_syms =
2430 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2431 pst->n_static_syms =
2432 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2433
2434#ifdef DUMPING
2435 if (dumping)
2436 {
2437 printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2438 pst->filename,
2439 LDSYMOFF (pst),
2440 LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2441 LDSYMLEN (pst),
2442 LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2443 pst->n_global_syms, pst->n_static_syms);
2444 }
2445#endif
2446
2447 pst->number_of_dependencies = number_dependencies;
2448 if (number_dependencies)
2449 {
2450 pst->dependencies = (struct partial_symtab **)
8b92e4d5 2451 obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
2452 number_dependencies * sizeof (struct partial_symtab *));
2453 memcpy (pst->dependencies, dependency_list,
2454 number_dependencies * sizeof (struct partial_symtab *));
2455 }
2456 else
2457 pst->dependencies = 0;
2458
2459 for (i = 0; i < num_includes; i++)
2460 {
2461 struct partial_symtab *subpst =
2462 allocate_psymtab (include_list[i], objfile);
2463
2464 subpst->section_offsets = pst->section_offsets;
2465 subpst->read_symtab_private =
8b92e4d5 2466 (char *) obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
2467 sizeof (struct symloc));
2468 LDSYMOFF (subpst) =
2469 LDSYMLEN (subpst) =
2470 subpst->textlow =
2471 subpst->texthigh = 0;
2472
2473 /* We could save slight bits of space by only making one of these,
2474 shared by the entire set of include files. FIXME-someday. */
2475 subpst->dependencies = (struct partial_symtab **)
8b92e4d5 2476 obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
2477 sizeof (struct partial_symtab *));
2478 subpst->dependencies[0] = pst;
2479 subpst->number_of_dependencies = 1;
2480
2481 subpst->globals_offset =
2482 subpst->n_global_syms =
2483 subpst->statics_offset =
2484 subpst->n_static_syms = 0;
2485
2486 subpst->readin = 0;
2487 subpst->symtab = 0;
2488 subpst->read_symtab = pst->read_symtab;
2489 }
2490
2491 sort_pst_symbols (pst);
2492
2493 /* If there is already a psymtab or symtab for a file of this name, remove it.
2494 (If there is a symtab, more drastic things also happen.)
2495 This happens in VxWorks. */
2496 free_named_symtabs (pst->filename);
2497
2498 if (num_includes == 0
2499 && number_dependencies == 0
2500 && pst->n_global_syms == 0
2501 && pst->n_static_syms == 0)
2502 {
2503 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2504 it is on the obstack, but we can forget to chain it on the list.
2505 Empty psymtabs happen as a result of header files which don't have
2506 any symbols in them. There can be a lot of them. But this check
2507 is wrong, in that a psymtab with N_SLINE entries but nothing else
2508 is not empty, but we don't realize that. Fixing that without slowing
2509 things down might be tricky.
2510 It's also wrong if we're using the quick look-up tables, as
2511 we can get empty psymtabs from modules with no routines in
2512 them. */
2513
2514 discard_psymtab (pst);
2515
2516 /* Indicate that psymtab was thrown away. */
2517 pst = (struct partial_symtab *) NULL;
2518
2519 }
2520 return pst;
2521}
2522
2523\f
2524/* Get the nesting depth for the source line identified by INDEX. */
2525
2526static unsigned long
2527hpread_get_scope_start (sltpointer index, struct objfile *objfile)
2528{
2529 union sltentry *sl_bufp;
2530
2531 sl_bufp = hpread_get_slt (index, objfile);
2532 return sl_bufp->sspec.backptr.dnttp.index;
2533}
2534
2535/* Get the source line number the the line identified by INDEX. */
2536
2537static unsigned long
2538hpread_get_line (sltpointer index, struct objfile *objfile)
2539{
2540 union sltentry *sl_bufp;
2541
2542 sl_bufp = hpread_get_slt (index, objfile);
2543 return sl_bufp->snorm.line;
2544}
2545
2546/* Find the code address associated with a given sltpointer */
2547
2548static CORE_ADDR
2549hpread_get_location (sltpointer index, struct objfile *objfile)
2550{
2551 union sltentry *sl_bufp;
2552 int i;
2553
2554 /* code location of special sltentrys is determined from context */
2555 sl_bufp = hpread_get_slt (index, objfile);
2556
2557 if (sl_bufp->snorm.sltdesc == SLT_END)
2558 {
2559 /* find previous normal sltentry and get address */
2560 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
2561 (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
2562 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
2563 sl_bufp = hpread_get_slt (index - i, objfile);
2564 if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2565 return sl_bufp->snormoff.address;
2566 else
2567 return sl_bufp->snorm.address;
2568 }
2569
2570 /* find next normal sltentry and get address */
2571 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
2572 (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
2573 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
2574 sl_bufp = hpread_get_slt (index + i, objfile);
2575 if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2576 return sl_bufp->snormoff.address;
2577 else
2578 return sl_bufp->snorm.address;
2579}
2580\f
2581
2582/* Return 1 if an HP debug symbol of type KIND has a name associated with
2583 * it, else return 0. (This function is not currently used, but I'll
2584 * leave it here in case it proves useful later on. - RT).
2585 */
2586
f5479e9c 2587static int
8af51c36
EZ
2588hpread_has_name (enum dntt_entry_type kind)
2589{
2590 switch (kind)
2591 {
2592 case DNTT_TYPE_SRCFILE:
2593 case DNTT_TYPE_MODULE:
2594 case DNTT_TYPE_FUNCTION:
2595 case DNTT_TYPE_DOC_FUNCTION:
2596 case DNTT_TYPE_ENTRY:
2597 case DNTT_TYPE_IMPORT:
2598 case DNTT_TYPE_LABEL:
2599 case DNTT_TYPE_FPARAM:
2600 case DNTT_TYPE_SVAR:
2601 case DNTT_TYPE_DVAR:
2602 case DNTT_TYPE_CONST:
2603 case DNTT_TYPE_TYPEDEF:
2604 case DNTT_TYPE_TAGDEF:
2605 case DNTT_TYPE_MEMENUM:
2606 case DNTT_TYPE_FIELD:
2607 case DNTT_TYPE_SA:
2608 case DNTT_TYPE_BLOCKDATA:
2609 case DNTT_TYPE_MEMFUNC:
2610 case DNTT_TYPE_DOC_MEMFUNC:
2611 return 1;
2612
2613 case DNTT_TYPE_BEGIN:
2614 case DNTT_TYPE_END:
2615 case DNTT_TYPE_POINTER:
2616 case DNTT_TYPE_ENUM:
2617 case DNTT_TYPE_SET:
2618 case DNTT_TYPE_ARRAY:
2619 case DNTT_TYPE_STRUCT:
2620 case DNTT_TYPE_UNION:
2621 case DNTT_TYPE_VARIANT:
2622 case DNTT_TYPE_FILE:
2623 case DNTT_TYPE_FUNCTYPE:
2624 case DNTT_TYPE_SUBRANGE:
2625 case DNTT_TYPE_WITH:
2626 case DNTT_TYPE_COMMON:
2627 case DNTT_TYPE_COBSTRUCT:
2628 case DNTT_TYPE_XREF:
2629 case DNTT_TYPE_MACRO:
2630 case DNTT_TYPE_CLASS_SCOPE:
2631 case DNTT_TYPE_REFERENCE:
2632 case DNTT_TYPE_PTRMEM:
2633 case DNTT_TYPE_PTRMEMFUNC:
2634 case DNTT_TYPE_CLASS:
2635 case DNTT_TYPE_GENFIELD:
2636 case DNTT_TYPE_VFUNC:
2637 case DNTT_TYPE_MEMACCESS:
2638 case DNTT_TYPE_INHERITANCE:
2639 case DNTT_TYPE_FRIEND_CLASS:
2640 case DNTT_TYPE_FRIEND_FUNC:
2641 case DNTT_TYPE_MODIFIER:
2642 case DNTT_TYPE_OBJECT_ID:
2643 case DNTT_TYPE_TEMPLATE:
2644 case DNTT_TYPE_TEMPLATE_ARG:
2645 case DNTT_TYPE_FUNC_TEMPLATE:
2646 case DNTT_TYPE_LINK:
2647 /* DNTT_TYPE_DYN_ARRAY_DESC ? */
2648 /* DNTT_TYPE_DESC_SUBRANGE ? */
2649 /* DNTT_TYPE_BEGIN_EXT ? */
2650 /* DNTT_TYPE_INLN ? */
2651 /* DNTT_TYPE_INLN_LIST ? */
2652 /* DNTT_TYPE_ALIAS ? */
2653 default:
2654 return 0;
2655 }
2656}
2657
2658/* Do the dirty work of reading in the full symbol from a partial symbol
2659 table. */
2660
2661static void
2662hpread_psymtab_to_symtab_1 (struct partial_symtab *pst)
2663{
2664 struct cleanup *old_chain;
2665 int i;
2666
2667 /* Get out quick if passed junk. */
2668 if (!pst)
2669 return;
2670
2671 /* Complain if we've already read in this symbol table. */
2672 if (pst->readin)
2673 {
2b9848d8
PM
2674 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in."
2675 " Shouldn't happen.\n",
2676 pst->filename);
8af51c36
EZ
2677 return;
2678 }
2679
2680 /* Read in all partial symtabs on which this one is dependent */
2681 for (i = 0; i < pst->number_of_dependencies; i++)
2682 if (!pst->dependencies[i]->readin)
2683 {
2684 /* Inform about additional files that need to be read in. */
2685 if (info_verbose)
2686 {
2687 fputs_filtered (" ", gdb_stdout);
2688 wrap_here ("");
2689 fputs_filtered ("and ", gdb_stdout);
2690 wrap_here ("");
2691 printf_filtered ("%s...", pst->dependencies[i]->filename);
2692 wrap_here (""); /* Flush output */
2693 gdb_flush (gdb_stdout);
2694 }
2695 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
2696 }
2697
2698 /* If it's real... */
2699 if (LDSYMLEN (pst))
2700 {
2701 /* Init stuff necessary for reading in symbols */
2702 buildsym_init ();
2703 old_chain = make_cleanup (really_free_pendings, 0);
2704
2705 pst->symtab =
2706 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
2707 pst->textlow, pst->texthigh - pst->textlow,
2708 pst->section_offsets, pst->filename);
8af51c36
EZ
2709
2710 do_cleanups (old_chain);
2711 }
2712
2713 pst->readin = 1;
2714}
2715
2716/* Read in all of the symbols for a given psymtab for real.
2717 Be verbose about it if the user wants that. */
2718
f5479e9c 2719static void
8af51c36
EZ
2720hpread_psymtab_to_symtab (struct partial_symtab *pst)
2721{
2722 /* Get out quick if given junk. */
2723 if (!pst)
2724 return;
2725
2726 /* Sanity check. */
2727 if (pst->readin)
2728 {
2b9848d8
PM
2729 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in."
2730 " Shouldn't happen.\n",
2731 pst->filename);
8af51c36
EZ
2732 return;
2733 }
2734
2735 /* elz: setting the flag to indicate that the code of the target
2736 was compiled using an HP compiler (aCC, cc)
2737 the processing_acc_compilation variable is declared in the
2738 file buildsym.h, the HP_COMPILED_TARGET is defined to be equal
2739 to 3 in the file tm_hppa.h */
2740
2741 processing_gcc_compilation = 0;
2742
2743 if (LDSYMLEN (pst) || pst->number_of_dependencies)
2744 {
2745 /* Print the message now, before reading the string table,
2746 to avoid disconcerting pauses. */
2747 if (info_verbose)
2748 {
2749 printf_filtered ("Reading in symbols for %s...", pst->filename);
2750 gdb_flush (gdb_stdout);
2751 }
2752
2753 hpread_psymtab_to_symtab_1 (pst);
2754
2755 /* Match with global symbols. This only needs to be done once,
2756 after all of the symtabs and dependencies have been read in. */
2757 scan_file_globals (pst->objfile);
2758
2759 /* Finish up the debug error message. */
2760 if (info_verbose)
2761 printf_filtered ("done.\n");
2762 }
2763}
2764
2765/* Read in a defined section of a specific object file's symbols.
2766
2767 DESC is the file descriptor for the file, positioned at the
2768 beginning of the symtab
2769 SYM_OFFSET is the offset within the file of
2770 the beginning of the symbols we want to read
2771 SYM_SIZE is the size of the symbol info to read in.
2772 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
2773 TEXT_SIZE is the size of the text segment read in.
2774 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
2775
2776static struct symtab *
2777hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size,
2778 CORE_ADDR text_offset, int text_size,
2779 struct section_offsets *section_offsets, char *filename)
2780{
2781 char *namestring;
2782 union dnttentry *dn_bufp;
2783 unsigned max_symnum;
2784 int at_module_boundary = 0;
2785 /* 1 => at end, -1 => at beginning */
2786
2787 int sym_index = sym_offset / sizeof (struct dntt_type_block);
2788
2789 current_objfile = objfile;
2790 subfile_stack = 0;
2791
2792 last_source_file = 0;
2793
2794 /* Demangling style -- if EDG style already set, don't change it,
2795 as HP style causes some problems with the KAI EDG compiler */
2796 if (current_demangling_style != edg_demangling)
2797 {
2798 /* Otherwise, ensure that we are using HP style demangling */
2799 set_demangling_style (HP_DEMANGLING_STYLE_STRING);
2800 }
2801
2802 dn_bufp = hpread_get_lntt (sym_index, objfile);
2803 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
2804 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
2805 {
2806 start_symtab ("globals", NULL, 0);
2807 record_debugformat ("HP");
2808 }
2809
2810 /* The psymtab builder (hp-psymtab-read.c) is the one that
2811 * determined the "sym_size" argument (i.e. how many DNTT symbols
2812 * are in this symtab), which we use to compute "max_symnum"
2813 * (point in DNTT to which we read).
2814 *
2815 * Perhaps this should be changed so that
2816 * process_one_debug_symbol() "knows" when
2817 * to stop reading (based on reading from the MODULE to the matching
2818 * END), and take out this reliance on a #-syms being passed in...
2819 * (I'm worried about the reliability of this number). But I'll
2820 * leave it as-is, for now. - RT
2821 *
2822 * The change above has been made. I've left the "for" loop control
2823 * in to prepare for backing this out again. -JB
2824 */
2825 max_symnum = sym_size / sizeof (struct dntt_type_block);
2826 /* No reason to multiply on pst side and divide on sym side... FIXME */
2827
2828 /* Read in and process each debug symbol within the specified range.
2829 */
2830 for (symnum = 0;
2831 symnum < max_symnum;
2832 symnum++)
2833 {
2834 QUIT; /* Allow this to be interruptable */
2835 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
2836
2837 if (dn_bufp->dblock.extension)
2838 continue;
2839
68b8d23e
JB
2840 /* Yow! We call set_namestring on things without names! */
2841 set_namestring (dn_bufp, &namestring, objfile);
8af51c36
EZ
2842
2843 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
2844 objfile, text_offset, text_size,
2845 filename, symnum + sym_index,
2846 &at_module_boundary
2847 );
2848
2849 /* OLD COMMENTS: This routine is only called for psts. All psts
2850 * correspond to MODULES. If we ever do lazy-reading of globals
2851 * from the LNTT, then there will be a pst which ends when the
2852 * LNTT ends, and not at an END MODULE entry. Then we'll have
2853 * to re-visit this break.
2854
2855 if( at_end_of_module )
2856 break;
2857
2858 */
2859
2860 /* We no longer break out of the loop when we reach the end of a
2861 module. The reason is that with CTTI, the compiler can generate
2862 function symbols (for template function instantiations) which are not
2863 in any module; typically they show up beyond a module's end, and
2864 before the next module's start. We include them in the current
2865 module. However, we still don't trust the MAX_SYMNUM value from
2866 the psymtab, so we break out if we enter a new module. */
2867
2868 if (at_module_boundary == -1)
2869 break;
2870 }
2871
2872 current_objfile = NULL;
f83f82bc 2873 deprecated_hp_som_som_object_present = 1; /* Indicate we've processed an HP SOM SOM file */
8af51c36
EZ
2874
2875 return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
2876}
2877\f
2878
2879
2880
2881/* Convert basic types from HP debug format into GDB internal format. */
2882
2883static int
2884hpread_type_translate (dnttpointer typep)
2885{
2886 if (!typep.dntti.immediate)
2887 {
2888 error ("error in hpread_type_translate\n.");
2889 return FT_VOID;
2890 }
2891
2892 switch (typep.dntti.type)
2893 {
2894 case HP_TYPE_BOOLEAN:
2895 case HP_TYPE_BOOLEAN_S300_COMPAT:
2896 case HP_TYPE_BOOLEAN_VAX_COMPAT:
2897 return FT_BOOLEAN;
2898 case HP_TYPE_CHAR: /* C signed char, C++ plain char */
2899
2900 case HP_TYPE_WIDE_CHAR:
2901 return FT_CHAR;
2902 case HP_TYPE_INT:
2903 if (typep.dntti.bitlength <= 8)
2904 return FT_SIGNED_CHAR; /* C++ signed char */
2905 if (typep.dntti.bitlength <= 16)
2906 return FT_SHORT;
2907 if (typep.dntti.bitlength <= 32)
2908 return FT_INTEGER;
2909 return FT_LONG_LONG;
2910 case HP_TYPE_LONG:
2911 if (typep.dntti.bitlength <= 8)
2912 return FT_SIGNED_CHAR; /* C++ signed char. */
2913 return FT_LONG;
2914 case HP_TYPE_UNSIGNED_LONG:
2915 if (typep.dntti.bitlength <= 8)
2916 return FT_UNSIGNED_CHAR; /* C/C++ unsigned char */
2917 if (typep.dntti.bitlength <= 16)
2918 return FT_UNSIGNED_SHORT;
2919 if (typep.dntti.bitlength <= 32)
2920 return FT_UNSIGNED_LONG;
2921 return FT_UNSIGNED_LONG_LONG;
2922 case HP_TYPE_UNSIGNED_INT:
2923 if (typep.dntti.bitlength <= 8)
2924 return FT_UNSIGNED_CHAR;
2925 if (typep.dntti.bitlength <= 16)
2926 return FT_UNSIGNED_SHORT;
2927 if (typep.dntti.bitlength <= 32)
2928 return FT_UNSIGNED_INTEGER;
2929 return FT_UNSIGNED_LONG_LONG;
2930 case HP_TYPE_REAL:
2931 case HP_TYPE_REAL_3000:
2932 case HP_TYPE_DOUBLE:
2933 if (typep.dntti.bitlength == 64)
2934 return FT_DBL_PREC_FLOAT;
2935 if (typep.dntti.bitlength == 128)
2936 return FT_EXT_PREC_FLOAT;
2937 return FT_FLOAT;
2938 case HP_TYPE_COMPLEX:
2939 case HP_TYPE_COMPLEXS3000:
2940 if (typep.dntti.bitlength == 128)
2941 return FT_DBL_PREC_COMPLEX;
2942 if (typep.dntti.bitlength == 192)
2943 return FT_EXT_PREC_COMPLEX;
2944 return FT_COMPLEX;
2945 case HP_TYPE_VOID:
2946 return FT_VOID;
2947 case HP_TYPE_STRING200:
2948 case HP_TYPE_LONGSTRING200:
2949 case HP_TYPE_FTN_STRING_SPEC:
2950 case HP_TYPE_MOD_STRING_SPEC:
2951 case HP_TYPE_MOD_STRING_3000:
2952 case HP_TYPE_FTN_STRING_S300_COMPAT:
2953 case HP_TYPE_FTN_STRING_VAX_COMPAT:
2954 return FT_STRING;
2955 case HP_TYPE_TEMPLATE_ARG:
2956 return FT_TEMPLATE_ARG;
2957 case HP_TYPE_TEXT:
2958 case HP_TYPE_FLABEL:
2959 case HP_TYPE_PACKED_DECIMAL:
2960 case HP_TYPE_ANYPOINTER:
2961 case HP_TYPE_GLOBAL_ANYPOINTER:
2962 case HP_TYPE_LOCAL_ANYPOINTER:
2963 default:
2964 warning ("hpread_type_translate: unhandled type code.\n");
2965 return FT_VOID;
2966 }
2967}
2968
2969/* Given a position in the DNTT, return a pointer to the
2970 * already-built "struct type" (if any), for the type defined
2971 * at that position.
2972 */
2973
2974static struct type **
2975hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile)
2976{
2977 unsigned old_len;
2978 int index = hp_type.dnttp.index;
2979 int size_changed = 0;
2980
2981 /* The immediate flag indicates this doesn't actually point to
2982 * a type DNTT.
2983 */
2984 if (hp_type.dntti.immediate)
2985 return NULL;
2986
2987 /* For each objfile, we maintain a "type vector".
2988 * This an array of "struct type *"'s with one pointer per DNTT index.
2989 * Given a DNTT index, we look in this array to see if we have
2990 * already processed this DNTT and if it is a type definition.
2991 * If so, then we can locate a pointer to the already-built
2992 * "struct type", and not build it again.
2993 *
2994 * The need for this arises because our DNTT-walking code wanders
2995 * around. In particular, it will encounter the same type multiple
2996 * times (once for each object of that type). We don't want to
2997 * built multiple "struct type"'s for the same thing.
2998 *
2999 * Having said this, I should point out that this type-vector is
3000 * an expensive way to keep track of this. If most DNTT entries are
3001 * 3 words, the type-vector will be 1/3 the size of the DNTT itself.
3002 * Alternative solutions:
3003 * - Keep a compressed or hashed table. Less memory, but more expensive
3004 * to search and update.
3005 * - (Suggested by JB): Overwrite the DNTT entry itself
3006 * with the info. Create a new type code "ALREADY_BUILT", and modify
3007 * the DNTT to have that type code and point to the already-built entry.
3008 * -RT
3009 */
3010
3011 if (index < LNTT_SYMCOUNT (objfile))
3012 {
9a6f53fe 3013 if (index >= DNTT_TYPE_VECTOR_LENGTH (objfile))
8af51c36 3014 {
9a6f53fe 3015 old_len = DNTT_TYPE_VECTOR_LENGTH (objfile);
8af51c36
EZ
3016
3017 /* See if we need to allocate a type-vector. */
3018 if (old_len == 0)
3019 {
9a6f53fe
EZ
3020 DNTT_TYPE_VECTOR_LENGTH (objfile) = LNTT_SYMCOUNT (objfile) + GNTT_SYMCOUNT (objfile);
3021 DNTT_TYPE_VECTOR (objfile) = (struct type **)
3022 xmmalloc (objfile->md, DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
3023 memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0,
3024 (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) *
8af51c36
EZ
3025 sizeof (struct type *));
3026 }
3027
3028 /* See if we need to resize type-vector. With my change to
3029 * initially allocate a correct-size type-vector, this code
3030 * should no longer trigger.
3031 */
9a6f53fe 3032 while (index >= DNTT_TYPE_VECTOR_LENGTH (objfile))
8af51c36 3033 {
9a6f53fe 3034 DNTT_TYPE_VECTOR_LENGTH (objfile) *= 2;
8af51c36
EZ
3035 size_changed = 1;
3036 }
3037 if (size_changed)
3038 {
9a6f53fe 3039 DNTT_TYPE_VECTOR (objfile) = (struct type **)
8af51c36 3040 xmrealloc (objfile->md,
9a6f53fe
EZ
3041 (char *) DNTT_TYPE_VECTOR (objfile),
3042 (DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
8af51c36 3043
9a6f53fe
EZ
3044 memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0,
3045 (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) *
8af51c36
EZ
3046 sizeof (struct type *));
3047 }
3048
3049 }
9a6f53fe 3050 return &DNTT_TYPE_VECTOR (objfile)[index];
8af51c36
EZ
3051 }
3052 else
3053 return NULL;
3054}
3055
3056/* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
3057 Note we'll just return the address of a GDB internal type if we already
3058 have it lying around. */
3059
3060static struct type *
3061hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile)
3062{
3063 struct type **type_addr;
3064
3065 type_addr = hpread_lookup_type (hp_type, objfile);
3066 if (*type_addr == 0)
3067 {
3068 *type_addr = alloc_type (objfile);
3069
3070 /* A hack - if we really are a C++ class symbol, then this default
3071 * will get overriden later on.
3072 */
3073 TYPE_CPLUS_SPECIFIC (*type_addr)
3074 = (struct cplus_struct_type *) &cplus_struct_default;
3075 }
3076
3077 return *type_addr;
3078}
3079
3080/* Read a native enumerated type and return it in GDB internal form. */
3081
3082static struct type *
3083hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3084 struct objfile *objfile)
3085{
3086 struct type *type;
3087 struct pending **symlist, *osyms, *syms;
3088 struct pending *local_list = NULL;
3089 int o_nsyms, nsyms = 0;
3090 dnttpointer mem;
3091 union dnttentry *memp;
3092 char *name;
3093 long n;
3094 struct symbol *sym;
3095
3096 /* Allocate a GDB type. If we've already read in this enum type,
3097 * it'll return the already built GDB type, so stop here.
3098 * (Note: I added this check, to conform with what's done for
3099 * struct, union, class.
3100 * I assume this is OK. - RT)
3101 */
3102 type = hpread_alloc_type (hp_type, objfile);
3103 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3104 return type;
3105
3106 /* HP C supports "sized enums", where a specifier such as "short" or
3107 "char" can be used to get enums of different sizes. So don't assume
3108 an enum is always 4 bytes long. pai/1997-08-21 */
3109 TYPE_LENGTH (type) = dn_bufp->denum.bitlength / 8;
3110
3111 symlist = &file_symbols;
3112 osyms = *symlist;
c906108c
SS
3113 o_nsyms = osyms ? osyms->nsyms : 0;
3114
8af51c36
EZ
3115 /* Get a name for each member and add it to our list of members.
3116 * The list of "mem" SOM records we are walking should all be
3117 * SOM type DNTT_TYPE_MEMENUM (not checked).
3118 */
c906108c 3119 mem = dn_bufp->denum.firstmem;
8af51c36 3120 while (mem.word && mem.word != DNTTNIL)
c906108c
SS
3121 {
3122 memp = hpread_get_lntt (mem.dnttp.index, objfile);
3123
3124 name = VT (objfile) + memp->dmember.name;
4a146b47 3125 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
3126 sizeof (struct symbol));
3127 memset (sym, 0, sizeof (struct symbol));
22abf04a 3128 DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
4a146b47 3129 &objfile->objfile_obstack);
c906108c 3130 SYMBOL_CLASS (sym) = LOC_CONST;
176620f1 3131 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
c906108c
SS
3132 SYMBOL_VALUE (sym) = memp->dmember.value;
3133 add_symbol_to_list (sym, symlist);
3134 nsyms++;
3135 mem = memp->dmember.nextmem;
3136 }
3137
3138 /* Now that we know more about the enum, fill in more info. */
3139 TYPE_CODE (type) = TYPE_CODE_ENUM;
3140 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3141 TYPE_NFIELDS (type) = nsyms;
3142 TYPE_FIELDS (type) = (struct field *)
b99607ea 3143 obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nsyms);
c906108c
SS
3144
3145 /* Find the symbols for the members and put them into the type.
3146 The symbols can be found in the symlist that we put them on
3147 to cause them to be defined. osyms contains the old value
3148 of that symlist; everything up to there was defined by us.
3149
3150 Note that we preserve the order of the enum constants, so
3151 that in something like "enum {FOO, LAST_THING=FOO}" we print
3152 FOO, not LAST_THING. */
3153 for (syms = *symlist, n = 0; syms; syms = syms->next)
3154 {
3155 int j = 0;
3156 if (syms == osyms)
3157 j = o_nsyms;
3158 for (; j < syms->nsyms; j++, n++)
3159 {
3160 struct symbol *xsym = syms->symbol[j];
3161 SYMBOL_TYPE (xsym) = type;
22abf04a 3162 TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
c906108c
SS
3163 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3164 TYPE_FIELD_BITSIZE (type, n) = 0;
01ad7f36 3165 TYPE_FIELD_STATIC_KIND (type, n) = 0;
c906108c 3166 }
8af51c36
EZ
3167 if (syms == osyms)
3168 break;
3169 }
3170
3171 return type;
3172}
3173
3174/* Read and internalize a native function debug symbol. */
3175
3176static struct type *
3177hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3178 struct objfile *objfile, int newblock)
3179{
3180 struct type *type, *type1;
3181 struct pending *syms;
3182 struct pending *local_list = NULL;
3183 int nsyms = 0;
3184 dnttpointer param;
3185 union dnttentry *paramp;
3186 char *name;
3187 long n;
3188 struct symbol *sym;
3189 int record_args = 1;
3190
3191 /* See if we've already read in this type. */
3192 type = hpread_alloc_type (hp_type, objfile);
3193 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
3194 {
3195 record_args = 0; /* already read in, don't modify type */
3196 }
3197 else
3198 {
3199 /* Nope, so read it in and store it away. */
3200 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
3201 dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
3202 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
3203 objfile));
3204 else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
3205 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
3206 objfile));
3207 else /* expect DNTT_TYPE_FUNC_TEMPLATE */
3208 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc_template.retval,
3209 objfile));
0004e5a2 3210 replace_type (type, type1);
8af51c36
EZ
3211
3212 /* Mark it -- in the middle of processing */
3213 TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3214 }
3215
3216 /* Now examine each parameter noting its type, location, and a
3217 wealth of other information. */
3218 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
3219 dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
3220 param = dn_bufp->dfunc.firstparam;
3221 else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
3222 param = dn_bufp->dfunctype.firstparam;
3223 else /* expect DNTT_TYPE_FUNC_TEMPLATE */
3224 param = dn_bufp->dfunc_template.firstparam;
3225 while (param.word && param.word != DNTTNIL)
3226 {
3227 paramp = hpread_get_lntt (param.dnttp.index, objfile);
3228 nsyms++;
3229 param = paramp->dfparam.nextparam;
3230
3231 /* Get the name. */
3232 name = VT (objfile) + paramp->dfparam.name;
4a146b47 3233 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
3234 sizeof (struct symbol));
3235 (void) memset (sym, 0, sizeof (struct symbol));
22abf04a 3236 DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
4a146b47 3237 &objfile->objfile_obstack);
8af51c36
EZ
3238
3239 /* Figure out where it lives. */
3240 if (paramp->dfparam.regparam)
3241 SYMBOL_CLASS (sym) = LOC_REGPARM;
3242 else if (paramp->dfparam.indirect)
3243 SYMBOL_CLASS (sym) = LOC_REF_ARG;
3244 else
3245 SYMBOL_CLASS (sym) = LOC_ARG;
176620f1 3246 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8af51c36
EZ
3247 if (paramp->dfparam.copyparam)
3248 {
3249 SYMBOL_VALUE (sym) = paramp->dfparam.location;
3250#ifdef HPREAD_ADJUST_STACK_ADDRESS
3251 SYMBOL_VALUE (sym)
3252 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
3253#endif
3254 /* This is likely a pass-by-invisible reference parameter,
3255 Hack on the symbol class to make GDB happy. */
3256 /* ??rehrauer: This appears to be broken w/r/t to passing
3257 C values of type float and struct. Perhaps this ought
3258 to be highighted as a special case, but for now, just
3259 allowing these to be LOC_ARGs seems to work fine.
3260 */
3261#if 0
3262 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
3263#endif
3264 }
3265 else
3266 SYMBOL_VALUE (sym) = paramp->dfparam.location;
3267
3268 /* Get its type. */
3269 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
3270 /* Add it to the symbol list. */
3271 /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
3272 * called on FPARAM symbols from the process_one_debug_symbol()
3273 * level... so parameters are getting added twice! (this shows
3274 * up in the symbol dump you get from "maint print symbols ...").
3275 * Note 2 (RT) I took out the processing of FPARAM from the
3276 * process_one_debug_symbol() level, so at the moment parameters are only
3277 * being processed here. This seems to have no ill effect.
3278 */
3279 /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
3280 each fparam on the local_symbols list from here. Now we use the
3281 local_list to which fparams are added below, and set the param_symbols
3282 global to point to that at the end of this routine. */
3283 /* elz: I added this new list of symbols which is local to the function.
3284 this list is the one which is actually used to build the type for the
3285 function rather than the gloabal list pointed to by symlist.
3286 Using a global list to keep track of the parameters is wrong, because
3287 this function is called recursively if one parameter happend to be
3288 a function itself with more parameters in it. Adding parameters to the
3289 same global symbol list would not work!
3290 Actually it did work in case of cc compiled programs where you do
3291 not check the parameter lists of the arguments. */
3292 add_symbol_to_list (sym, &local_list);
3293
3294 }
3295
3296 /* If type was read in earlier, don't bother with modifying
3297 the type struct */
3298 if (!record_args)
3299 goto finish;
3300
3301 /* Note how many parameters we found. */
3302 TYPE_NFIELDS (type) = nsyms;
3303 TYPE_FIELDS (type) = (struct field *)
b99607ea 3304 obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
3305 sizeof (struct field) * nsyms);
3306
3307 /* Find the symbols for the parameters and
3308 use them to fill parameter-type information into the function-type.
3309 The parameter symbols can be found in the local_list that we just put them on. */
3310 /* Note that we preserve the order of the parameters, so
3311 that in something like "enum {FOO, LAST_THING=FOO}" we print
3312 FOO, not LAST_THING. */
3313
3314 /* get the parameters types from the local list not the global list
3315 so that the type can be correctly constructed for functions which
3316 have function as parameters */
3317 for (syms = local_list, n = 0; syms; syms = syms->next)
3318 {
3319 int j = 0;
3320 for (j = 0; j < syms->nsyms; j++, n++)
3321 {
3322 struct symbol *xsym = syms->symbol[j];
22abf04a 3323 TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
8af51c36
EZ
3324 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
3325 TYPE_FIELD_ARTIFICIAL (type, n) = 0;
3326 TYPE_FIELD_BITSIZE (type, n) = 0;
01ad7f36 3327 TYPE_FIELD_STATIC_KIND (type, n) = 0;
8af51c36
EZ
3328 }
3329 }
3330 /* Mark it as having been processed */
3331 TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
3332
3333 /* Check whether we need to fix-up a class type with this function's type */
3334 if (fixup_class && (fixup_method == type))
3335 {
3336 fixup_class_method_type (fixup_class, fixup_method, objfile);
3337 fixup_class = NULL;
3338 fixup_method = NULL;
c906108c
SS
3339 }
3340
8af51c36
EZ
3341 /* Set the param list of this level of the context stack
3342 to our local list. Do this only if this function was
3343 called for creating a new block, and not if it was called
3344 simply to get the function type. This prevents recursive
3345 invocations from trashing param_symbols. */
3346finish:
3347 if (newblock)
3348 param_symbols = local_list;
3349
c906108c
SS
3350 return type;
3351}
3352
c906108c 3353
8af51c36
EZ
3354/* Read and internalize a native DOC function debug symbol. */
3355/* This is almost identical to hpread_read_function_type(), except
3356 * for references to dn_bufp->ddocfunc instead of db_bufp->dfunc.
3357 * Since debug information for DOC functions is more likely to be
3358 * volatile, please leave it this way.
3359 */
c906108c 3360static struct type *
8af51c36
EZ
3361hpread_read_doc_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3362 struct objfile *objfile, int newblock)
c906108c 3363{
8af51c36
EZ
3364 struct pending *syms;
3365 struct pending *local_list = NULL;
3366 int nsyms = 0;
65e82032 3367 struct type *type;
c906108c
SS
3368 dnttpointer param;
3369 union dnttentry *paramp;
3370 char *name;
3371 long n;
3372 struct symbol *sym;
8af51c36 3373 int record_args = 1;
c906108c
SS
3374
3375 /* See if we've already read in this type. */
3376 type = hpread_alloc_type (hp_type, objfile);
3377 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
8af51c36
EZ
3378 {
3379 record_args = 0; /* already read in, don't modify type */
3380 }
3381 else
3382 {
65e82032 3383 struct type *type1 = NULL;
8af51c36
EZ
3384 /* Nope, so read it in and store it away. */
3385 if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
3386 dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
3387 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->ddocfunc.retval,
3388 objfile));
65e82032
AC
3389 /* NOTE: cagney/2003-03-29: Oh, no not again. TYPE1 is
3390 potentially left undefined here. Assert it isn't and hope
3391 the assert never fails ... */
3392 gdb_assert (type1 != NULL);
3393
0004e5a2 3394 replace_type (type, type1);
8af51c36
EZ
3395
3396 /* Mark it -- in the middle of processing */
3397 TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3398 }
c906108c
SS
3399
3400 /* Now examine each parameter noting its type, location, and a
3401 wealth of other information. */
8af51c36
EZ
3402 if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
3403 dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
3404 param = dn_bufp->ddocfunc.firstparam;
c906108c
SS
3405 while (param.word && param.word != DNTTNIL)
3406 {
3407 paramp = hpread_get_lntt (param.dnttp.index, objfile);
3408 nsyms++;
3409 param = paramp->dfparam.nextparam;
3410
3411 /* Get the name. */
3412 name = VT (objfile) + paramp->dfparam.name;
4a146b47 3413 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
3414 sizeof (struct symbol));
3415 (void) memset (sym, 0, sizeof (struct symbol));
22abf04a 3416 DEPRECATED_SYMBOL_NAME (sym) = name;
8af51c36
EZ
3417
3418 /* Figure out where it lives. */
3419 if (paramp->dfparam.regparam)
3420 SYMBOL_CLASS (sym) = LOC_REGPARM;
3421 else if (paramp->dfparam.indirect)
3422 SYMBOL_CLASS (sym) = LOC_REF_ARG;
3423 else
3424 SYMBOL_CLASS (sym) = LOC_ARG;
176620f1 3425 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
8af51c36
EZ
3426 if (paramp->dfparam.copyparam)
3427 {
3428 SYMBOL_VALUE (sym) = paramp->dfparam.location;
3429#ifdef HPREAD_ADJUST_STACK_ADDRESS
3430 SYMBOL_VALUE (sym)
3431 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
3432#endif
3433 /* This is likely a pass-by-invisible reference parameter,
3434 Hack on the symbol class to make GDB happy. */
3435 /* ??rehrauer: This appears to be broken w/r/t to passing
3436 C values of type float and struct. Perhaps this ought
3437 to be highighted as a special case, but for now, just
3438 allowing these to be LOC_ARGs seems to work fine.
3439 */
3440#if 0
3441 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
3442#endif
3443 }
3444 else
3445 SYMBOL_VALUE (sym) = paramp->dfparam.location;
3446
3447 /* Get its type. */
3448 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
3449 /* Add it to the symbol list. */
3450 /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
3451 * called on FPARAM symbols from the process_one_debug_symbol()
3452 * level... so parameters are getting added twice! (this shows
3453 * up in the symbol dump you get from "maint print symbols ...").
3454 * Note 2 (RT) I took out the processing of FPARAM from the
3455 * process_one_debug_symbol() level, so at the moment parameters are only
3456 * being processed here. This seems to have no ill effect.
3457 */
3458 /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
3459 each fparam on the local_symbols list from here. Now we use the
3460 local_list to which fparams are added below, and set the param_symbols
3461 global to point to that at the end of this routine. */
3462
3463 /* elz: I added this new list of symbols which is local to the function.
3464 this list is the one which is actually used to build the type for the
3465 function rather than the gloabal list pointed to by symlist.
3466 Using a global list to keep track of the parameters is wrong, because
3467 this function is called recursively if one parameter happend to be
3468 a function itself with more parameters in it. Adding parameters to the
3469 same global symbol list would not work!
3470 Actually it did work in case of cc compiled programs where you do not check the
3471 parameter lists of the arguments. */
3472 add_symbol_to_list (sym, &local_list);
3473 }
3474
3475 /* If type was read in earlier, don't bother with modifying
3476 the type struct */
3477 if (!record_args)
3478 goto finish;
3479
3480 /* Note how many parameters we found. */
3481 TYPE_NFIELDS (type) = nsyms;
3482 TYPE_FIELDS (type) = (struct field *)
b99607ea 3483 obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
3484 sizeof (struct field) * nsyms);
3485
3486 /* Find the symbols for the parameters and
3487 use them to fill parameter-type information into the function-type.
3488 The parameter symbols can be found in the local_list that we just put them on. */
3489 /* Note that we preserve the order of the parameters, so
3490 that in something like "enum {FOO, LAST_THING=FOO}" we print
3491 FOO, not LAST_THING. */
3492
3493 /* get the parameters types from the local list not the global list
3494 so that the type can be correctly constructed for functions which
3495 have function as parameters
3496 */
3497 for (syms = local_list, n = 0; syms; syms = syms->next)
3498 {
3499 int j = 0;
3500 for (j = 0; j < syms->nsyms; j++, n++)
3501 {
3502 struct symbol *xsym = syms->symbol[j];
22abf04a 3503 TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
8af51c36
EZ
3504 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
3505 TYPE_FIELD_ARTIFICIAL (type, n) = 0;
3506 TYPE_FIELD_BITSIZE (type, n) = 0;
01ad7f36 3507 TYPE_FIELD_STATIC_KIND (type, n) = 0;
8af51c36
EZ
3508 }
3509 }
3510
3511 /* Mark it as having been processed */
3512 TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
3513
3514 /* Check whether we need to fix-up a class type with this function's type */
3515 if (fixup_class && (fixup_method == type))
3516 {
3517 fixup_class_method_type (fixup_class, fixup_method, objfile);
3518 fixup_class = NULL;
3519 fixup_method = NULL;
3520 }
3521
3522 /* Set the param list of this level of the context stack
3523 to our local list. Do this only if this function was
3524 called for creating a new block, and not if it was called
3525 simply to get the function type. This prevents recursive
3526 invocations from trashing param_symbols. */
3527finish:
3528 if (newblock)
3529 param_symbols = local_list;
3530
3531 return type;
3532}
3533
3534
3535
3536/* A file-level variable which keeps track of the current-template
3537 * being processed. Set in hpread_read_struct_type() while processing
3538 * a template type. Referred to in hpread_get_nth_templ_arg().
3539 * Yes, this is a kludge, but it arises from the kludge that already
3540 * exists in symtab.h, namely the fact that they encode
3541 * "template argument n" with fundamental type FT_TEMPLATE_ARG and
3542 * bitlength n. This means that deep in processing fundamental types
3543 * I need to ask the question "what template am I in the middle of?".
3544 * The alternative to stuffing a global would be to pass an argument
3545 * down the chain of calls just for this purpose.
3546 *
3547 * There may be problems handling nested templates... tough.
3548 */
3549static struct type *current_template = NULL;
3550
3551/* Read in and internalize a structure definition.
3552 * This same routine is called for struct, union, and class types.
3553 * Also called for templates, since they build a very similar
3554 * type entry as for class types.
3555 */
3556
3557static struct type *
3558hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3559 struct objfile *objfile)
3560{
3561 /* The data members get linked together into a list of struct nextfield's */
3562 struct nextfield
3563 {
3564 struct nextfield *next;
3565 struct field field;
3566 unsigned char attributes; /* store visibility and virtuality info */
3567#define ATTR_VIRTUAL 1
3568#define ATTR_PRIVATE 2
3569#define ATTR_PROTECT 3
3570 };
3571
3572
3573 /* The methods get linked together into a list of struct next_fn_field's */
3574 struct next_fn_field
3575 {
3576 struct next_fn_field *next;
3577 struct fn_fieldlist field;
3578 struct fn_field fn_field;
3579 int num_fn_fields;
3580 };
3581
3582 /* The template args get linked together into a list of struct next_template's */
3583 struct next_template
3584 {
3585 struct next_template *next;
3586 struct template_arg arg;
3587 };
3588
3589 /* The template instantiations get linked together into a list of these... */
3590 struct next_instantiation
3591 {
3592 struct next_instantiation *next;
3593 struct type *t;
3594 };
3595
3596 struct type *type;
3597 struct type *baseclass;
3598 struct type *memtype;
3599 struct nextfield *list = 0, *tmp_list = 0;
3600 struct next_fn_field *fn_list = 0;
3601 struct next_fn_field *fn_p;
3602 struct next_template *t_new, *t_list = 0;
3603 struct nextfield *new;
3604 struct next_fn_field *fn_new;
3605 struct next_instantiation *i_new, *i_list = 0;
3606 int n, nfields = 0, n_fn_fields = 0, n_fn_fields_total = 0;
3607 int n_base_classes = 0, n_templ_args = 0;
3608 int ninstantiations = 0;
3609 dnttpointer field, fn_field, parent;
3610 union dnttentry *fieldp, *fn_fieldp, *parentp;
3611 int i;
3612 int static_member = 0;
3613 int const_member = 0;
3614 int volatile_member = 0;
3615 unsigned long vtbl_offset;
3616 int need_bitvectors = 0;
3617 char *method_name = NULL;
3618 char *method_alias = NULL;
3619
3620
3621 /* Is it something we've already dealt with? */
3622 type = hpread_alloc_type (hp_type, objfile);
3623 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
3624 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
3625 (TYPE_CODE (type) == TYPE_CODE_CLASS) ||
3626 (TYPE_CODE (type) == TYPE_CODE_TEMPLATE))
3627 return type;
3628
3629 /* Get the basic type correct. */
3630 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
3631 {
3632 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3633 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
3634 }
3635 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
3636 {
3637 TYPE_CODE (type) = TYPE_CODE_UNION;
3638 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
3639 }
3640 else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3641 {
3642 TYPE_CODE (type) = TYPE_CODE_CLASS;
3643 TYPE_LENGTH (type) = dn_bufp->dclass.bitlength / 8;
3644
3645 /* Overrides the TYPE_CPLUS_SPECIFIC(type) with allocated memory
3646 * rather than &cplus_struct_default.
3647 */
3648 allocate_cplus_struct_type (type);
3649
3650 /* Fill in declared-type.
3651 * (The C++ compiler will emit TYPE_CODE_CLASS
3652 * for all 3 of "class", "struct"
3653 * "union", and we have to look at the "class_decl" field if we
3654 * want to know how it was really declared)
3655 */
3656 /* (0==class, 1==union, 2==struct) */
3657 TYPE_DECLARED_TYPE (type) = dn_bufp->dclass.class_decl;
3658 }
3659 else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3660 {
3661 /* Get the basic type correct. */
3662 TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
3663 allocate_cplus_struct_type (type);
3664 TYPE_DECLARED_TYPE (type) = DECLARED_TYPE_TEMPLATE;
3665 }
3666 else
3667 return type;
3668
3669
3670 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3671
3672 /* For classes, read the parent list.
3673 * Question (RT): Do we need to do this for templates also?
3674 */
3675 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3676 {
3677
3678 /* First read the parent-list (classes from which we derive fields) */
3679 parent = dn_bufp->dclass.parentlist;
3680 while (parent.word && parent.word != DNTTNIL)
3681 {
3682 parentp = hpread_get_lntt (parent.dnttp.index, objfile);
3683
3684 /* "parentp" should point to a DNTT_TYPE_INHERITANCE record */
3685
3686 /* Get space to record the next field/data-member. */
3687 new = (struct nextfield *) alloca (sizeof (struct nextfield));
3688 new->next = list;
3689 list = new;
3690
3691 FIELD_BITSIZE (list->field) = 0;
01ad7f36 3692 FIELD_STATIC_KIND (list->field) = 0;
8af51c36
EZ
3693
3694 /* The "classname" field is actually a DNTT pointer to the base class */
3695 baseclass = hpread_type_lookup (parentp->dinheritance.classname,
3696 objfile);
3697 FIELD_TYPE (list->field) = baseclass;
3698
3699 list->field.name = type_name_no_tag (FIELD_TYPE (list->field));
3700
3701 list->attributes = 0;
3702
3703 /* Check for virtuality of base, and set the
3704 * offset of the base subobject within the object.
3705 * (Offset set to -1 for virtual bases (for now).)
3706 */
3707 if (parentp->dinheritance.Virtual)
3708 {
3709 B_SET (&(list->attributes), ATTR_VIRTUAL);
3710 parentp->dinheritance.offset = -1;
3711 }
3712 else
3713 FIELD_BITPOS (list->field) = parentp->dinheritance.offset;
3714
3715 /* Check visibility */
3716 switch (parentp->dinheritance.visibility)
3717 {
3718 case 1:
3719 B_SET (&(list->attributes), ATTR_PROTECT);
3720 break;
3721 case 2:
3722 B_SET (&(list->attributes), ATTR_PRIVATE);
3723 break;
3724 }
3725
3726 n_base_classes++;
3727 nfields++;
3728
3729 parent = parentp->dinheritance.next;
3730 }
3731 }
3732
3733 /* For templates, read the template argument list.
3734 * This must be done before processing the member list, because
3735 * the member list may refer back to this. E.g.:
3736 * template <class T1, class T2> class q2 {
3737 * public:
3738 * T1 a;
3739 * T2 b;
3740 * };
3741 * We need to read the argument list "T1", "T2" first.
3742 */
3743 if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3744 {
3745 /* Kludge alert: This stuffs a global "current_template" which
3746 * is referred to by hpread_get_nth_templ_arg(). The global
3747 * is cleared at the end of this routine.
3748 */
3749 current_template = type;
3750
3751 /* Read in the argument list */
3752 field = dn_bufp->dtemplate.arglist;
3753 while (field.word && field.word != DNTTNIL)
3754 {
3755 /* Get this template argument */
3756 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
3757 if (fieldp->dblock.kind != DNTT_TYPE_TEMPLATE_ARG)
3758 {
3759 warning ("Invalid debug info: Template argument entry is of wrong kind");
3760 break;
3761 }
3762 /* Bump the count */
3763 n_templ_args++;
3764 /* Allocate and fill in a struct next_template */
3765 t_new = (struct next_template *) alloca (sizeof (struct next_template));
3766 t_new->next = t_list;
3767 t_list = t_new;
3768 t_list->arg.name = VT (objfile) + fieldp->dtempl_arg.name;
3769 t_list->arg.type = hpread_read_templ_arg_type (field, fieldp,
3770 objfile, t_list->arg.name);
3771 /* Walk to the next template argument */
3772 field = fieldp->dtempl_arg.nextarg;
3773 }
3774 }
3775
3776 TYPE_NTEMPLATE_ARGS (type) = n_templ_args;
3777
3778 if (n_templ_args > 0)
3779 TYPE_TEMPLATE_ARGS (type) = (struct template_arg *)
b99607ea 3780 obstack_alloc (&objfile->objfile_obstack, sizeof (struct template_arg) * n_templ_args);
8af51c36
EZ
3781 for (n = n_templ_args; t_list; t_list = t_list->next)
3782 {
3783 n -= 1;
3784 TYPE_TEMPLATE_ARG (type, n) = t_list->arg;
3785 }
3786
3787 /* Next read in and internalize all the fields/members. */
3788 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
3789 field = dn_bufp->dstruct.firstfield;
3790 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
3791 field = dn_bufp->dunion.firstfield;
3792 else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3793 field = dn_bufp->dclass.memberlist;
3794 else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3795 field = dn_bufp->dtemplate.memberlist;
3796 else
3797 field.word = DNTTNIL;
3798
3799 while (field.word && field.word != DNTTNIL)
3800 {
3801 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
3802
3803 /* At this point "fieldp" may point to either a DNTT_TYPE_FIELD
3804 * or a DNTT_TYPE_GENFIELD record.
3805 */
3806 vtbl_offset = 0;
3807 static_member = 0;
3808 const_member = 0;
3809 volatile_member = 0;
3810
3811 if (fieldp->dblock.kind == DNTT_TYPE_GENFIELD)
3812 {
3813
3814 /* The type will be GENFIELD if the field is a method or
3815 * a static member (or some other cases -- see below)
3816 */
3817
3818 /* Follow a link to get to the record for the field. */
3819 fn_field = fieldp->dgenfield.field;
3820 fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3821
3822 /* Virtual funcs are indicated by a VFUNC which points to the
3823 * real entry
3824 */
3825 if (fn_fieldp->dblock.kind == DNTT_TYPE_VFUNC)
3826 {
3827 vtbl_offset = fn_fieldp->dvfunc.vtbl_offset;
3828 fn_field = fn_fieldp->dvfunc.funcptr;
3829 fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3830 }
3831
3832 /* A function's entry may be preceded by a modifier which
3833 * labels it static/constant/volatile.
3834 */
3835 if (fn_fieldp->dblock.kind == DNTT_TYPE_MODIFIER)
3836 {
3837 static_member = fn_fieldp->dmodifier.m_static;
3838 const_member = fn_fieldp->dmodifier.m_const;
3839 volatile_member = fn_fieldp->dmodifier.m_volatile;
3840 fn_field = fn_fieldp->dmodifier.type;
3841 fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3842 }
3843
3844 /* Check whether we have a method */
3845 if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
3846 (fn_fieldp->dblock.kind == DNTT_TYPE_FUNCTION) ||
3847 (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) ||
3848 (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_FUNCTION))
3849 {
3850 /* Method found */
3851
3852 short ix = 0;
3853
3854 /* Look up function type of method */
3855 memtype = hpread_type_lookup (fn_field, objfile);
3856
3857 /* Methods can be seen before classes in the SOM records.
3858 If we are processing this class because it's a parameter of a
3859 method, at this point the method's type is actually incomplete;
3860 we'll have to fix it up later; mark the class for this. */
3861
3862 if (TYPE_INCOMPLETE (memtype))
3863 {
3864 TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3865 if (fixup_class)
3866 warning ("Two classes to fix up for method?? Type information may be incorrect for some classes.");
3867 if (fixup_method)
3868 warning ("Two methods to be fixed up at once?? Type information may be incorrect for some classes.");
3869 fixup_class = type; /* remember this class has to be fixed up */
3870 fixup_method = memtype; /* remember the method type to be used in fixup */
3871 }
3872
3873 /* HP aCC generates operator names without the "operator" keyword, and
3874 generates null strings as names for operators that are
3875 user-defined type conversions to basic types (e.g. operator int ()).
3876 So try to reconstruct name as best as possible. */
3877
3878 method_name = (char *) (VT (objfile) + fn_fieldp->dfunc.name);
3879 method_alias = (char *) (VT (objfile) + fn_fieldp->dfunc.alias);
3880
3881 if (!method_name || /* no name */
3882 !*method_name || /* or null name */
3883 cplus_mangle_opname (method_name, DMGL_ANSI)) /* or name is an operator like "<" */
3884 {
3885 char *tmp_name = cplus_demangle (method_alias, DMGL_ANSI);
3886 char *op_string = strstr (tmp_name, "operator");
3887 method_name = xmalloc (strlen (op_string) + 1); /* don't overwrite VT! */
3888 strcpy (method_name, op_string);
3889 }
3890
3891 /* First check if a method of the same name has already been seen. */
3892 fn_p = fn_list;
3893 while (fn_p)
3894 {
cb137aa5 3895 if (DEPRECATED_STREQ (fn_p->field.name, method_name))
8af51c36
EZ
3896 break;
3897 fn_p = fn_p->next;
3898 }
3899
3900 /* If no such method was found, allocate a new entry in the list */
3901 if (!fn_p)
3902 {
3903 /* Get space to record this member function */
3904 /* Note: alloca used; this will disappear on routine exit */
3905 fn_new = (struct next_fn_field *) alloca (sizeof (struct next_fn_field));
3906 fn_new->next = fn_list;
3907 fn_list = fn_new;
3908
3909 /* Fill in the fields of the struct nextfield */
3910
3911 /* Record the (unmangled) method name */
3912 fn_list->field.name = method_name;
3913 /* Initial space for overloaded methods */
3914 /* Note: xmalloc is used; this will persist after this routine exits */
3915 fn_list->field.fn_fields = (struct fn_field *) xmalloc (5 * (sizeof (struct fn_field)));
3916 fn_list->field.length = 1; /* Init # of overloaded instances */
3917 fn_list->num_fn_fields = 5; /* # of entries for which space allocated */
3918 fn_p = fn_list;
3919 ix = 0; /* array index for fn_field */
3920 /* Bump the total count of the distinctly named methods */
3921 n_fn_fields++;
3922 }
3923 else
3924 /* Another overloaded instance of an already seen method name */
3925 {
3926 if (++(fn_p->field.length) > fn_p->num_fn_fields)
3927 {
3928 /* Increase space allocated for overloaded instances */
3929 fn_p->field.fn_fields
3930 = (struct fn_field *) xrealloc (fn_p->field.fn_fields,
3931 (fn_p->num_fn_fields + 5) * sizeof (struct fn_field));
3932 fn_p->num_fn_fields += 5;
3933 }
3934 ix = fn_p->field.length - 1; /* array index for fn_field */
3935 }
3936
3937 /* "physname" is intended to be the name of this overloaded instance. */
3938 if ((fn_fieldp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
3939 method_alias &&
3940 *method_alias) /* not a null string */
3941 fn_p->field.fn_fields[ix].physname = method_alias;
3942 else
3943 fn_p->field.fn_fields[ix].physname = method_name;
3944 /* What's expected here is the function type */
3945 /* But mark it as NULL if the method was incompletely processed
3946 We'll fix this up later when the method is fully processed */
3947 if (TYPE_INCOMPLETE (memtype))
ad2f7632 3948 fn_p->field.fn_fields[ix].type = NULL;
8af51c36 3949 else
ad2f7632 3950 fn_p->field.fn_fields[ix].type = memtype;
42725910 3951
8af51c36
EZ
3952 /* For virtual functions, fill in the voffset field with the
3953 * virtual table offset. (This is just copied over from the
3954 * SOM record; not sure if it is what GDB expects here...).
3955 * But if the function is a static method, set it to 1.
3956 *
3957 * Note that we have to add 1 because 1 indicates a static
3958 * method, and 0 indicates a non-static, non-virtual method */
3959
3960 if (static_member)
3961 fn_p->field.fn_fields[ix].voffset = VOFFSET_STATIC;
3962 else
3963 fn_p->field.fn_fields[ix].voffset = vtbl_offset ? vtbl_offset + 1 : 0;
3964
3965 /* Also fill in the fcontext field with the current
3966 * class. (The latter isn't quite right: should be the baseclass
3967 * that defines the virtual function... Note we do have
3968 * a variable "baseclass" that we could stuff into the fcontext
3969 * field, but "baseclass" isn't necessarily right either,
3970 * since the virtual function could have been defined more
3971 * than one level up).
3972 */
3973
3974 if (vtbl_offset != 0)
3975 fn_p->field.fn_fields[ix].fcontext = type;
3976 else
3977 fn_p->field.fn_fields[ix].fcontext = NULL;
3978
3979 /* Other random fields pertaining to this method */
3980 fn_p->field.fn_fields[ix].is_const = const_member;
3981 fn_p->field.fn_fields[ix].is_volatile = volatile_member; /* ?? */
3982 switch (fieldp->dgenfield.visibility)
3983 {
3984 case 1:
3985 fn_p->field.fn_fields[ix].is_protected = 1;
3986 fn_p->field.fn_fields[ix].is_private = 0;
3987 break;
3988 case 2:
3989 fn_p->field.fn_fields[ix].is_protected = 0;
3990 fn_p->field.fn_fields[ix].is_private = 1;
3991 break;
3992 default: /* public */
3993 fn_p->field.fn_fields[ix].is_protected = 0;
3994 fn_p->field.fn_fields[ix].is_private = 0;
3995 }
3996 fn_p->field.fn_fields[ix].is_stub = 0;
3997
3998 /* HP aCC emits both MEMFUNC and FUNCTION entries for a method;
3999 if the class points to the FUNCTION, there is usually separate
4000 code for the method; but if we have a MEMFUNC, the method has
4001 been inlined (and there is usually no FUNCTION entry)
4002 FIXME Not sure if this test is accurate. pai/1997-08-22 */
4003 if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
4004 (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC))
4005 fn_p->field.fn_fields[ix].is_inlined = 1;
4006 else
4007 fn_p->field.fn_fields[ix].is_inlined = 0;
4008
4009 fn_p->field.fn_fields[ix].dummy = 0;
4010
4011 /* Bump the total count of the member functions */
4012 n_fn_fields_total++;
4013
4014 }
4015 else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
4016 {
4017 /* This case is for static data members of classes */
4018
4019 /* pai:: FIXME -- check that "staticmem" bit is set */
4020
4021 /* Get space to record this static member */
4022 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4023 new->next = list;
4024 list = new;
4025
4026 list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
8af51c36
EZ
4027 SET_FIELD_PHYSNAME (list->field, 0); /* initialize to empty */
4028 memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
4029
4030 FIELD_TYPE (list->field) = memtype;
4031 list->attributes = 0;
4032 switch (fieldp->dgenfield.visibility)
4033 {
4034 case 1:
4035 B_SET (&(list->attributes), ATTR_PROTECT);
4036 break;
4037 case 2:
4038 B_SET (&(list->attributes), ATTR_PRIVATE);
4039 break;
4040 }
4041 nfields++;
4042 }
4043
4044 else if (fn_fieldp->dblock.kind == DNTT_TYPE_FIELD)
4045 {
4046 /* FIELDs follow GENFIELDs for fields of anonymous unions.
4047 Code below is replicated from the case for FIELDs further
4048 below, except that fieldp is replaced by fn_fieldp */
4049 if (!fn_fieldp->dfield.a_union)
4050 warning ("Debug info inconsistent: FIELD of anonymous union doesn't have a_union bit set");
4051 /* Get space to record the next field/data-member. */
4052 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4053 new->next = list;
4054 list = new;
4055
4056 list->field.name = VT (objfile) + fn_fieldp->dfield.name;
4057 FIELD_BITPOS (list->field) = fn_fieldp->dfield.bitoffset;
4058 if (fn_fieldp->dfield.bitlength % 8)
4059 list->field.bitsize = fn_fieldp->dfield.bitlength;
4060 else
4061 list->field.bitsize = 0;
4062
4063 memtype = hpread_type_lookup (fn_fieldp->dfield.type, objfile);
4064 list->field.type = memtype;
4065 list->attributes = 0;
4066 switch (fn_fieldp->dfield.visibility)
4067 {
4068 case 1:
4069 B_SET (&(list->attributes), ATTR_PROTECT);
4070 break;
4071 case 2:
4072 B_SET (&(list->attributes), ATTR_PRIVATE);
4073 break;
4074 }
4075 nfields++;
4076 }
4077 else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
4078 {
4079 /* Field of anonymous union; union is not inside a class */
4080 if (!fn_fieldp->dsvar.a_union)
4081 warning ("Debug info inconsistent: SVAR field in anonymous union doesn't have a_union bit set");
4082 /* Get space to record the next field/data-member. */
4083 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4084 new->next = list;
4085 list = new;
4086
4087 list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
4088 FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */
4089 FIELD_BITSIZE (list->field) = 0; /* use length from type */
01ad7f36 4090 FIELD_STATIC_KIND (list->field) = 0;
8af51c36
EZ
4091 memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
4092 list->field.type = memtype;
4093 list->attributes = 0;
4094 /* No info to set visibility -- always public */
4095 nfields++;
4096 }
4097 else if (fn_fieldp->dblock.kind == DNTT_TYPE_DVAR)
4098 {
4099 /* Field of anonymous union; union is not inside a class */
4100 if (!fn_fieldp->ddvar.a_union)
4101 warning ("Debug info inconsistent: DVAR field in anonymous union doesn't have a_union bit set");
4102 /* Get space to record the next field/data-member. */
4103 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4104 new->next = list;
4105 list = new;
4106
4107 list->field.name = VT (objfile) + fn_fieldp->ddvar.name;
4108 FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */
4109 FIELD_BITSIZE (list->field) = 0; /* use length from type */
01ad7f36 4110 FIELD_STATIC_KIND (list->field) = 0;
8af51c36
EZ
4111 memtype = hpread_type_lookup (fn_fieldp->ddvar.type, objfile);
4112 list->field.type = memtype;
4113 list->attributes = 0;
4114 /* No info to set visibility -- always public */
4115 nfields++;
4116 }
4117 else
4118 { /* Not a method, nor a static data member, nor an anon union field */
4119
4120 /* This case is for miscellaneous type entries (local enums,
4121 local function templates, etc.) that can be present
4122 inside a class. */
4123
4124 /* Enums -- will be handled by other code that takes care
4125 of DNTT_TYPE_ENUM; here we see only DNTT_TYPE_MEMENUM so
4126 it's not clear we could have handled them here at all. */
4127 /* FUNC_TEMPLATE: is handled by other code (?). */
4128 /* MEMACCESS: modified access for inherited member. Not
4129 sure what to do with this, ignoriing it at present. */
4130
4131 /* What other entries can appear following a GENFIELD which
4132 we do not handle above? (MODIFIER, VFUNC handled above.) */
4133
4134 if ((fn_fieldp->dblock.kind != DNTT_TYPE_MEMACCESS) &&
4135 (fn_fieldp->dblock.kind != DNTT_TYPE_MEMENUM) &&
4136 (fn_fieldp->dblock.kind != DNTT_TYPE_FUNC_TEMPLATE))
4137 warning ("Internal error: Unexpected debug record kind %d found following DNTT_GENFIELD",
4138 fn_fieldp->dblock.kind);
4139 }
4140 /* walk to the next FIELD or GENFIELD */
4141 field = fieldp->dgenfield.nextfield;
4142
4143 }
4144 else if (fieldp->dblock.kind == DNTT_TYPE_FIELD)
4145 {
4146
4147 /* Ordinary structure/union/class field */
4148 struct type *anon_union_type;
4149
4150 /* Get space to record the next field/data-member. */
4151 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4152 new->next = list;
4153 list = new;
4154
4155 list->field.name = VT (objfile) + fieldp->dfield.name;
4156
4157
9f9057da
MC
4158 /* A FIELD by itself (without a GENFIELD) can also be a static
4159 member. Mark it as static with a physname of NULL.
4160 fix_static_member_physnames will assign the physname later. */
8af51c36
EZ
4161 if (fieldp->dfield.staticmem)
4162 {
9f9057da
MC
4163 SET_FIELD_PHYSNAME (list->field, NULL);
4164 FIELD_BITPOS (list->field) = 0;
8af51c36
EZ
4165 FIELD_BITSIZE (list->field) = 0;
4166 }
4167 else
4168 /* Non-static data member */
4169 {
9f9057da 4170 FIELD_STATIC_KIND (list->field) = 0;
8af51c36
EZ
4171 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
4172 if (fieldp->dfield.bitlength % 8)
4173 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
4174 else
4175 FIELD_BITSIZE (list->field) = 0;
4176 }
4177
4178 memtype = hpread_type_lookup (fieldp->dfield.type, objfile);
4179 FIELD_TYPE (list->field) = memtype;
4180 list->attributes = 0;
4181 switch (fieldp->dfield.visibility)
4182 {
4183 case 1:
4184 B_SET (&(list->attributes), ATTR_PROTECT);
4185 break;
4186 case 2:
4187 B_SET (&(list->attributes), ATTR_PRIVATE);
4188 break;
4189 }
4190 nfields++;
4191
4192
4193 /* Note 1: First, we have to check if the current field is an anonymous
4194 union. If it is, then *its* fields are threaded along in the
4195 nextfield chain. :-( This was supposed to help debuggers, but is
4196 really just a nuisance since we deal with anonymous unions anyway by
4197 checking that the name is null. So anyway, we skip over the fields
4198 of the anonymous union. pai/1997-08-22 */
4199 /* Note 2: In addition, the bitoffsets for the fields of the anon union
4200 are relative to the enclosing struct, *NOT* relative to the anon
4201 union! This is an even bigger nuisance -- we have to go in and munge
4202 the anon union's type information appropriately. pai/1997-08-22 */
c906108c 4203
8af51c36
EZ
4204 /* Both tasks noted above are done by a separate function. This takes us
4205 to the next FIELD or GENFIELD, skipping anon unions, and recursively
4206 processing intermediate types. */
4207 field = hpread_get_next_skip_over_anon_unions (1, field, &fieldp, objfile);
4208
4209 }
c906108c 4210 else
c906108c 4211 {
8af51c36
EZ
4212 /* neither field nor genfield ?? is this possible?? */
4213 /* pai:: FIXME walk to the next -- how? */
4214 warning ("Internal error: unexpected DNTT kind %d encountered as field of struct",
4215 fieldp->dblock.kind);
4216 warning ("Skipping remaining fields of struct");
4217 break; /* get out of loop of fields */
c906108c 4218 }
8af51c36 4219 }
c906108c 4220
8af51c36
EZ
4221 /* If it's a template, read in the instantiation list */
4222 if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
4223 {
4224 ninstantiations = 0;
4225 field = dn_bufp->dtemplate.expansions;
4226 while (field.word && field.word != DNTTNIL)
4227 {
4228 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4229
4230 /* The expansions or nextexp should point to a tagdef */
4231 if (fieldp->dblock.kind != DNTT_TYPE_TAGDEF)
4232 break;
4233
4234 i_new = (struct next_instantiation *) alloca (sizeof (struct next_instantiation));
4235 i_new->next = i_list;
4236 i_list = i_new;
4237 i_list->t = hpread_type_lookup (field, objfile);
4238 ninstantiations++;
4239
4240 /* And the "type" field of that should point to a class */
4241 field = fieldp->dtag.type;
4242 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4243 if (fieldp->dblock.kind != DNTT_TYPE_CLASS)
4244 break;
4245
4246 /* Get the next expansion */
4247 field = fieldp->dclass.nextexp;
4248 }
4249 }
4250 TYPE_NINSTANTIATIONS (type) = ninstantiations;
4251 if (ninstantiations > 0)
4252 TYPE_INSTANTIATIONS (type) = (struct type **)
b99607ea 4253 obstack_alloc (&objfile->objfile_obstack, sizeof (struct type *) * ninstantiations);
8af51c36
EZ
4254 for (n = ninstantiations; i_list; i_list = i_list->next)
4255 {
4256 n -= 1;
4257 TYPE_INSTANTIATION (type, n) = i_list->t;
c906108c
SS
4258 }
4259
8af51c36
EZ
4260
4261 /* Copy the field-list to GDB's symbol table */
4262 TYPE_NFIELDS (type) = nfields;
4263 TYPE_N_BASECLASSES (type) = n_base_classes;
c906108c 4264 TYPE_FIELDS (type) = (struct field *)
b99607ea 4265 obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nfields);
8af51c36
EZ
4266 /* Copy the saved-up fields into the field vector. */
4267 for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
4268 {
4269 n -= 1;
4270 TYPE_FIELD (type, n) = tmp_list->field;
4271 }
c906108c 4272
8af51c36
EZ
4273 /* Copy the "function-field-list" (i.e., the list of member
4274 * functions in the class) to GDB's symbol table
4275 */
4276 TYPE_NFN_FIELDS (type) = n_fn_fields;
4277 TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total;
4278 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
b99607ea 4279 obstack_alloc (&objfile->objfile_obstack, sizeof (struct fn_fieldlist) * n_fn_fields);
8af51c36 4280 for (n = n_fn_fields; fn_list; fn_list = fn_list->next)
c906108c 4281 {
8af51c36
EZ
4282 n -= 1;
4283 TYPE_FN_FIELDLIST (type, n) = fn_list->field;
4284 }
4285
4286 /* pai:: FIXME -- perhaps each bitvector should be created individually */
4287 for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
4288 {
4289 n -= 1;
4290 if (tmp_list->attributes)
c906108c 4291 {
8af51c36
EZ
4292 need_bitvectors = 1;
4293 break;
c906108c 4294 }
c906108c 4295 }
c906108c 4296
8af51c36 4297 if (need_bitvectors)
c906108c 4298 {
8af51c36
EZ
4299 /* pai:: this step probably redundant */
4300 ALLOCATE_CPLUS_STRUCT_TYPE (type);
c906108c 4301
8af51c36
EZ
4302 TYPE_FIELD_VIRTUAL_BITS (type) =
4303 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4304 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), nfields);
c906108c 4305
8af51c36
EZ
4306 TYPE_FIELD_PRIVATE_BITS (type) =
4307 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4308 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
c906108c 4309
8af51c36
EZ
4310 TYPE_FIELD_PROTECTED_BITS (type) =
4311 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4312 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4313
4314 /* this field vector isn't actually used with HP aCC */
4315 TYPE_FIELD_IGNORE_BITS (type) =
4316 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4317 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4318
4319 while (nfields-- > 0)
4320 {
4321 if (B_TST (&(list->attributes), ATTR_VIRTUAL))
4322 SET_TYPE_FIELD_VIRTUAL (type, nfields);
4323 if (B_TST (&(list->attributes), ATTR_PRIVATE))
4324 SET_TYPE_FIELD_PRIVATE (type, nfields);
4325 if (B_TST (&(list->attributes), ATTR_PROTECT))
4326 SET_TYPE_FIELD_PROTECTED (type, nfields);
4327
4328 list = list->next;
4329 }
4330 }
4331 else
c906108c 4332 {
8af51c36
EZ
4333 TYPE_FIELD_VIRTUAL_BITS (type) = NULL;
4334 TYPE_FIELD_PROTECTED_BITS (type) = NULL;
4335 TYPE_FIELD_PRIVATE_BITS (type) = NULL;
c906108c 4336 }
8af51c36
EZ
4337
4338 if (has_vtable (type))
c906108c 4339 {
8af51c36
EZ
4340 /* Allocate space for class runtime information */
4341 TYPE_RUNTIME_PTR (type) = (struct runtime_info *) xmalloc (sizeof (struct runtime_info));
4342 /* Set flag for vtable */
4343 TYPE_VTABLE (type) = 1;
4344 /* The first non-virtual base class with a vtable. */
4345 TYPE_PRIMARY_BASE (type) = primary_base_class (type);
4346 /* The virtual base list. */
4347 TYPE_VIRTUAL_BASE_LIST (type) = virtual_base_list (type);
c906108c
SS
4348 }
4349 else
8af51c36 4350 TYPE_RUNTIME_PTR (type) = NULL;
c906108c 4351
8af51c36
EZ
4352 /* If this is a local type (C++ - declared inside a function), record file name & line # */
4353 if (hpread_get_scope_depth (dn_bufp, objfile, 1 /* no need for real depth */ ))
4354 {
4355 TYPE_LOCALTYPE_PTR (type) = (struct local_type_info *) xmalloc (sizeof (struct local_type_info));
4356 TYPE_LOCALTYPE_FILE (type) = (char *) xmalloc (strlen (current_subfile->name) + 1);
4357 strcpy (TYPE_LOCALTYPE_FILE (type), current_subfile->name);
4358 if (current_subfile->line_vector && (current_subfile->line_vector->nitems > 0))
4359 TYPE_LOCALTYPE_LINE (type) = current_subfile->line_vector->item[current_subfile->line_vector->nitems - 1].line;
4360 else
4361 TYPE_LOCALTYPE_LINE (type) = 0;
4362 }
4363 else
4364 TYPE_LOCALTYPE_PTR (type) = NULL;
c906108c 4365
8af51c36
EZ
4366 /* Clear the global saying what template we are in the middle of processing */
4367 current_template = NULL;
c906108c 4368
8af51c36
EZ
4369 return type;
4370}
c906108c 4371
8af51c36
EZ
4372/* Adjust the physnames for each static member of a struct
4373 or class type to be something like "A::x"; then various
4374 other pieces of code that do a lookup_symbol on the phyname
4375 work correctly.
4376 TYPE is a pointer to the struct/class type
4377 NAME is a char * (string) which is the class/struct name
4378 Void return */
c906108c 4379
8af51c36
EZ
4380static void
4381fix_static_member_physnames (struct type *type, char *class_name,
4382 struct objfile *objfile)
4383{
4384 int i;
c906108c 4385
8af51c36
EZ
4386 /* We fix the member names only for classes or structs */
4387 if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
4388 return;
4389
4390 for (i = 0; i < TYPE_NFIELDS (type); i++)
4391 if (TYPE_FIELD_STATIC (type, i))
4392 {
4393 if (TYPE_FIELD_STATIC_PHYSNAME (type, i))
4394 return; /* physnames are already set */
4395
0004e5a2 4396 SET_FIELD_PHYSNAME (TYPE_FIELDS (type)[i],
b99607ea 4397 obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
4398 strlen (class_name) + strlen (TYPE_FIELD_NAME (type, i)) + 3));
4399 strcpy (TYPE_FIELD_STATIC_PHYSNAME (type, i), class_name);
4400 strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), "::");
4401 strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), TYPE_FIELD_NAME (type, i));
4402 }
4403}
4404
4405/* Fix-up the type structure for a CLASS so that the type entry
4406 * for a method (previously marked with a null type in hpread_read_struct_type()
4407 * is set correctly to METHOD.
4408 * OBJFILE is as for other such functions.
4409 * Void return. */
4410
4411static void
4412fixup_class_method_type (struct type *class, struct type *method,
4413 struct objfile *objfile)
4414{
4415 int i, j, k;
4416
4417 if (!class || !method || !objfile)
4418 return;
4419
4420 /* Only for types that have methods */
4421 if ((TYPE_CODE (class) != TYPE_CODE_CLASS) &&
4422 (TYPE_CODE (class) != TYPE_CODE_UNION))
4423 return;
4424
4425 /* Loop over all methods and find the one marked with a NULL type */
4426 for (i = 0; i < TYPE_NFN_FIELDS (class); i++)
4427 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (class, i); j++)
4428 if (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) == NULL)
4429 {
4430 /* Set the method type */
4431 TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) = method;
8af51c36 4432
8af51c36
EZ
4433 /* Break out of both loops -- only one method to fix up in a class */
4434 goto finish;
4435 }
4436
4437finish:
4438 TYPE_FLAGS (class) &= ~TYPE_FLAG_INCOMPLETE;
4439}
4440
4441
4442/* If we're in the middle of processing a template, get a pointer
4443 * to the Nth template argument.
4444 * An example may make this clearer:
4445 * template <class T1, class T2> class q2 {
4446 * public:
4447 * T1 a;
4448 * T2 b;
4449 * };
4450 * The type for "a" will be "first template arg" and
4451 * the type for "b" will be "second template arg".
4452 * We need to look these up in order to fill in "a" and "b"'s type.
4453 * This is called from hpread_type_lookup().
4454 */
4455static struct type *
4456hpread_get_nth_template_arg (struct objfile *objfile, int n)
4457{
4458 if (current_template != NULL)
4459 return TYPE_TEMPLATE_ARG (current_template, n).type;
4460 else
4461 return lookup_fundamental_type (objfile, FT_TEMPLATE_ARG);
4462}
4463
4464/* Read in and internalize a TEMPL_ARG (template arg) symbol. */
4465
4466static struct type *
4467hpread_read_templ_arg_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4468 struct objfile *objfile, char *name)
4469{
4470 struct type *type;
4471
4472 /* See if it's something we've already deal with. */
4473 type = hpread_alloc_type (hp_type, objfile);
4474 if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE_ARG)
4475 return type;
4476
4477 /* Nope. Fill in the appropriate fields. */
4478 TYPE_CODE (type) = TYPE_CODE_TEMPLATE_ARG;
4479 TYPE_LENGTH (type) = 0;
4480 TYPE_NFIELDS (type) = 0;
4481 TYPE_NAME (type) = name;
c906108c
SS
4482 return type;
4483}
4484
4485/* Read in and internalize a set debug symbol. */
4486
4487static struct type *
fba45db2
KB
4488hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4489 struct objfile *objfile)
c906108c
SS
4490{
4491 struct type *type;
4492
4493 /* See if it's something we've already deal with. */
4494 type = hpread_alloc_type (hp_type, objfile);
4495 if (TYPE_CODE (type) == TYPE_CODE_SET)
4496 return type;
4497
4498 /* Nope. Fill in the appropriate fields. */
4499 TYPE_CODE (type) = TYPE_CODE_SET;
4500 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
4501 TYPE_NFIELDS (type) = 0;
4502 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
4503 objfile);
4504 return type;
4505}
4506
4507/* Read in and internalize an array debug symbol. */
4508
4509static struct type *
fba45db2
KB
4510hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4511 struct objfile *objfile)
c906108c
SS
4512{
4513 struct type *type;
c906108c 4514
8af51c36
EZ
4515 /* Allocate an array type symbol.
4516 * Why no check for already-read here, like in the other
4517 * hpread_read_xxx_type routines? Because it kept us
4518 * from properly determining the size of the array!
4519 */
c906108c
SS
4520 type = hpread_alloc_type (hp_type, objfile);
4521
4522 TYPE_CODE (type) = TYPE_CODE_ARRAY;
4523
8af51c36
EZ
4524 /* Although the hp-symtab.h does not *require* this to be the case,
4525 * GDB is assuming that "arrayisbytes" and "elemisbytes" be consistent.
4526 * I.e., express both array-length and element-length in bits,
4527 * or express both array-length and element-length in bytes.
4528 */
4529 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes) ||
4530 (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
4531 {
4532 warning ("error in hpread_array_type.\n");
4533 return NULL;
4534 }
c906108c
SS
4535 else if (dn_bufp->darray.arraylength == 0x7fffffff)
4536 {
4537 /* The HP debug format represents char foo[]; as an array with
8af51c36
EZ
4538 * length 0x7fffffff. Internally GDB wants to represent this
4539 * as an array of length zero.
4540 */
c5aa993b 4541 TYPE_LENGTH (type) = 0;
c906108c 4542 }
8af51c36
EZ
4543 else if (dn_bufp->darray.arrayisbytes)
4544 TYPE_LENGTH (type) = dn_bufp->darray.arraylength;
4545 else /* arraylength is in bits */
c906108c
SS
4546 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
4547
c906108c
SS
4548 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
4549 objfile);
8af51c36
EZ
4550
4551 /* The one "field" is used to store the subscript type */
4552 /* Since C and C++ multi-dimensional arrays are simply represented
4553 * as: array of array of ..., we only need one subscript-type
4554 * per array. This subscript type is typically a subrange of integer.
4555 * If this gets extended to support languages like Pascal, then
4556 * we need to fix this to represent multi-dimensional arrays properly.
4557 */
4558 TYPE_NFIELDS (type) = 1;
c906108c 4559 TYPE_FIELDS (type) = (struct field *)
b99607ea 4560 obstack_alloc (&objfile->objfile_obstack, sizeof (struct field));
c906108c
SS
4561 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
4562 objfile);
4563 return type;
4564}
4565
4566/* Read in and internalize a subrange debug symbol. */
4567static struct type *
fba45db2
KB
4568hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4569 struct objfile *objfile)
c906108c
SS
4570{
4571 struct type *type;
4572
4573 /* Is it something we've already dealt with. */
4574 type = hpread_alloc_type (hp_type, objfile);
4575 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4576 return type;
4577
4578 /* Nope, internalize it. */
4579 TYPE_CODE (type) = TYPE_CODE_RANGE;
4580 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
4581 TYPE_NFIELDS (type) = 2;
4582 TYPE_FIELDS (type)
b99607ea 4583 = (struct field *) obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
4584 2 * sizeof (struct field));
4585
4586 if (dn_bufp->dsubr.dyn_low)
4587 TYPE_FIELD_BITPOS (type, 0) = 0;
4588 else
4589 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
4590
4591 if (dn_bufp->dsubr.dyn_high)
4592 TYPE_FIELD_BITPOS (type, 1) = -1;
4593 else
4594 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
4595 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
4596 objfile);
4597 return type;
4598}
4599
8af51c36
EZ
4600/* struct type * hpread_type_lookup(hp_type, objfile)
4601 * Arguments:
4602 * hp_type: A pointer into the DNTT specifying what type we
4603 * are about to "look up"., or else [for fundamental types
4604 * like int, float, ...] an "immediate" structure describing
4605 * the type.
4606 * objfile: ?
4607 * Return value: A pointer to a "struct type" (representation of a
4608 * type in GDB's internal symbol table - see gdbtypes.h)
4609 * Routine description:
4610 * There are a variety of places when scanning the DNTT when we
4611 * need to interpret a "type" field. The simplest and most basic
4612 * example is when we're processing the symbol table record
4613 * for a data symbol (a SVAR or DVAR record). That has
4614 * a "type" field specifying the type of the data symbol. That
4615 * "type" field is either an "immediate" type specification (for the
4616 * fundamental types) or a DNTT pointer (for more complicated types).
4617 * For the more complicated types, we may or may not have already
4618 * processed the pointed-to type. (Multiple data symbols can of course
4619 * share the same type).
4620 * The job of hpread_type_lookup() is to process this "type" field.
4621 * Most of the real work is done in subroutines. Here we interpret
4622 * the immediate flag. If not immediate, chase the DNTT pointer to
4623 * find our way to the SOM record describing the type, switch on
4624 * the SOM kind, and then call an appropriate subroutine depending
4625 * on what kind of type we are constructing. (e.g., an array type,
4626 * a struct/class type, etc).
4627 */
c906108c 4628static struct type *
fba45db2 4629hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile)
c906108c
SS
4630{
4631 union dnttentry *dn_bufp;
8af51c36 4632 struct type *tmp_type;
c906108c
SS
4633
4634 /* First see if it's a simple builtin type. */
4635 if (hp_type.dntti.immediate)
8af51c36
EZ
4636 {
4637 /* If this is a template argument, the argument number is
4638 * encoded in the bitlength. All other cases, just return
4639 * GDB's representation of this fundamental type.
4640 */
4641 if (hp_type.dntti.type == HP_TYPE_TEMPLATE_ARG)
4642 return hpread_get_nth_template_arg (objfile, hp_type.dntti.bitlength);
4643 else
4644 return lookup_fundamental_type (objfile,
4645 hpread_type_translate (hp_type));
4646 }
c906108c
SS
4647
4648 /* Not a builtin type. We'll have to read it in. */
4649 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
4650 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
4651 else
8af51c36 4652 /* This is a fancy way of returning NULL */
c906108c
SS
4653 return lookup_fundamental_type (objfile, FT_VOID);
4654
4655 switch (dn_bufp->dblock.kind)
4656 {
4657 case DNTT_TYPE_SRCFILE:
4658 case DNTT_TYPE_MODULE:
c906108c
SS
4659 case DNTT_TYPE_ENTRY:
4660 case DNTT_TYPE_BEGIN:
4661 case DNTT_TYPE_END:
4662 case DNTT_TYPE_IMPORT:
4663 case DNTT_TYPE_LABEL:
c906108c
SS
4664 case DNTT_TYPE_FPARAM:
4665 case DNTT_TYPE_SVAR:
4666 case DNTT_TYPE_DVAR:
4667 case DNTT_TYPE_CONST:
8af51c36
EZ
4668 case DNTT_TYPE_MEMENUM:
4669 case DNTT_TYPE_VARIANT:
4670 case DNTT_TYPE_FILE:
4671 case DNTT_TYPE_WITH:
4672 case DNTT_TYPE_COMMON:
4673 case DNTT_TYPE_COBSTRUCT:
4674 case DNTT_TYPE_XREF:
4675 case DNTT_TYPE_SA:
4676 case DNTT_TYPE_MACRO:
4677 case DNTT_TYPE_BLOCKDATA:
4678 case DNTT_TYPE_CLASS_SCOPE:
4679 case DNTT_TYPE_MEMACCESS:
4680 case DNTT_TYPE_INHERITANCE:
4681 case DNTT_TYPE_OBJECT_ID:
4682 case DNTT_TYPE_FRIEND_CLASS:
4683 case DNTT_TYPE_FRIEND_FUNC:
4684 /* These are not types - something went wrong. */
4685 /* This is a fancy way of returning NULL */
c906108c
SS
4686 return lookup_fundamental_type (objfile, FT_VOID);
4687
8af51c36
EZ
4688 case DNTT_TYPE_FUNCTION:
4689 /* We wind up here when dealing with class member functions
4690 * (called from hpread_read_struct_type(), i.e. when processing
4691 * the class definition itself).
4692 */
4693 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4694
4695 case DNTT_TYPE_DOC_FUNCTION:
4696 return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
4697
c906108c
SS
4698 case DNTT_TYPE_TYPEDEF:
4699 {
8af51c36 4700 /* A typedef - chase it down by making a recursive call */
c906108c
SS
4701 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
4702 objfile);
c906108c 4703
8af51c36
EZ
4704 /* The following came from the base hpread.c that we inherited.
4705 * It is WRONG so I have commented it out. - RT
4706 *...
4707
4708 char *suffix;
4709 suffix = VT (objfile) + dn_bufp->dtype.name;
4710 TYPE_NAME (structtype) = suffix;
4711
4712 * ... further explanation ....
4713 *
4714 * What we have here is a typedef pointing to a typedef.
4715 * E.g.,
4716 * typedef int foo;
4717 * typedef foo fum;
4718 *
4719 * What we desire to build is (these are pictures
4720 * of "struct type"'s):
4721 *
4722 * +---------+ +----------+ +------------+
4723 * | typedef | | typedef | | fund. type |
4724 * | type| -> | type| -> | |
4725 * | "fum" | | "foo" | | "int" |
4726 * +---------+ +----------+ +------------+
4727 *
4728 * What this commented-out code is doing is smashing the
4729 * name of pointed-to-type to be the same as the pointed-from
4730 * type. So we wind up with something like:
4731 *
4732 * +---------+ +----------+ +------------+
4733 * | typedef | | typedef | | fund. type |
4734 * | type| -> | type| -> | |
4735 * | "fum" | | "fum" | | "fum" |
4736 * +---------+ +----------+ +------------+
4737 *
4738 */
4739
c906108c
SS
4740 return structtype;
4741 }
4742
4743 case DNTT_TYPE_TAGDEF:
4744 {
4745 /* Just a little different from above. We have to tack on
8af51c36
EZ
4746 * an identifier of some kind (struct, union, enum, class, etc).
4747 */
c906108c
SS
4748 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
4749 objfile);
4750 char *prefix, *suffix;
4751 suffix = VT (objfile) + dn_bufp->dtype.name;
4752
4753 /* Lookup the next type in the list. It should be a structure,
8af51c36
EZ
4754 * union, class, enum, or template type.
4755 * We will need to attach that to our name.
4756 */
c906108c
SS
4757 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
4758 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
4759 else
8af51c36 4760 {
23136709 4761 complaint (&symfile_complaints, "error in hpread_type_lookup().");
8af51c36
EZ
4762 return NULL;
4763 }
c906108c
SS
4764
4765 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
8af51c36
EZ
4766 {
4767 prefix = "struct ";
4768 }
c906108c 4769 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
8af51c36
EZ
4770 {
4771 prefix = "union ";
4772 }
4773 else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
4774 {
4775 /* Further field for CLASS saying how it was really declared */
4776 /* 0==class, 1==union, 2==struct */
4777 if (dn_bufp->dclass.class_decl == 0)
4778 prefix = "class ";
4779 else if (dn_bufp->dclass.class_decl == 1)
4780 prefix = "union ";
4781 else if (dn_bufp->dclass.class_decl == 2)
4782 prefix = "struct ";
4783 else
4784 prefix = "";
4785 }
4786 else if (dn_bufp->dblock.kind == DNTT_TYPE_ENUM)
4787 {
4788 prefix = "enum ";
4789 }
4790 else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
4791 {
4792 prefix = "template ";
4793 }
c906108c 4794 else
8af51c36
EZ
4795 {
4796 prefix = "";
4797 }
c906108c
SS
4798
4799 /* Build the correct name. */
0004e5a2 4800 TYPE_NAME (structtype)
b99607ea 4801 = (char *) obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
4802 strlen (prefix) + strlen (suffix) + 1);
4803 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
4804 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
4805 TYPE_TAG_NAME (structtype) = suffix;
4806
8af51c36
EZ
4807 /* For classes/structs, we have to set the static member "physnames"
4808 to point to strings like "Class::Member" */
4809 if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT)
4810 fix_static_member_physnames (structtype, suffix, objfile);
c906108c
SS
4811
4812 return structtype;
4813 }
8af51c36 4814
c906108c 4815 case DNTT_TYPE_POINTER:
8af51c36
EZ
4816 /* Pointer type - call a routine in gdbtypes.c that constructs
4817 * the appropriate GDB type.
4818 */
4819 return make_pointer_type (
4820 hpread_type_lookup (dn_bufp->dptr.pointsto,
4821 objfile),
4822 NULL);
4823
4824 case DNTT_TYPE_REFERENCE:
4825 /* C++ reference type - call a routine in gdbtypes.c that constructs
4826 * the appropriate GDB type.
4827 */
4828 return make_reference_type (
4829 hpread_type_lookup (dn_bufp->dreference.pointsto,
4830 objfile),
4831 NULL);
4832
c906108c
SS
4833 case DNTT_TYPE_ENUM:
4834 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
c906108c
SS
4835 case DNTT_TYPE_SET:
4836 return hpread_read_set_type (hp_type, dn_bufp, objfile);
4837 case DNTT_TYPE_SUBRANGE:
4838 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
4839 case DNTT_TYPE_ARRAY:
4840 return hpread_read_array_type (hp_type, dn_bufp, objfile);
4841 case DNTT_TYPE_STRUCT:
4842 case DNTT_TYPE_UNION:
4843 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4844 case DNTT_TYPE_FIELD:
4845 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
8af51c36 4846
c906108c 4847 case DNTT_TYPE_FUNCTYPE:
8af51c36
EZ
4848 /* Here we want to read the function SOMs and return a
4849 * type for it. We get here, for instance, when processing
4850 * pointer-to-function type.
4851 */
4852 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4853
4854 case DNTT_TYPE_PTRMEM:
4855 /* Declares a C++ pointer-to-data-member type.
4856 * The "pointsto" field defines the class,
4857 * while the "memtype" field defines the pointed-to-type.
4858 */
4859 {
4860 struct type *ptrmemtype;
4861 struct type *class_type;
4862 struct type *memtype;
4863 memtype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
4864 objfile),
4865 class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
4866 objfile),
4867 ptrmemtype = alloc_type (objfile);
4868 smash_to_member_type (ptrmemtype, class_type, memtype);
4869 return make_pointer_type (ptrmemtype, NULL);
4870 }
4871 break;
4872
4873 case DNTT_TYPE_PTRMEMFUNC:
4874 /* Defines a C++ pointer-to-function-member type.
4875 * The "pointsto" field defines the class,
4876 * while the "memtype" field defines the pointed-to-type.
4877 */
4878 {
4879 struct type *ptrmemtype;
4880 struct type *class_type;
4881 struct type *functype;
4882 struct type *retvaltype;
4883 int nargs;
4884 int i;
8af51c36
EZ
4885 class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
4886 objfile);
4887 functype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
4888 objfile);
4889 retvaltype = TYPE_TARGET_TYPE (functype);
4890 nargs = TYPE_NFIELDS (functype);
8af51c36 4891 ptrmemtype = alloc_type (objfile);
ad2f7632
DJ
4892
4893 smash_to_method_type (ptrmemtype, class_type, retvaltype,
4894 TYPE_FIELDS (functype),
4895 TYPE_NFIELDS (functype),
4896 0);
8af51c36
EZ
4897 return make_pointer_type (ptrmemtype, NULL);
4898 }
4899 break;
4900
4901 case DNTT_TYPE_CLASS:
4902 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4903
4904 case DNTT_TYPE_GENFIELD:
4905 /* Chase pointer from GENFIELD to FIELD, and make recursive
4906 * call on that.
4907 */
4908 return hpread_type_lookup (dn_bufp->dgenfield.field, objfile);
4909
4910 case DNTT_TYPE_VFUNC:
4911 /* C++ virtual function.
4912 * We get here in the course of processing a class type which
4913 * contains virtual functions. Just go through another level
4914 * of indirection to get to the pointed-to function SOM.
4915 */
4916 return hpread_type_lookup (dn_bufp->dvfunc.funcptr, objfile);
4917
4918 case DNTT_TYPE_MODIFIER:
4919 /* Check the modifiers and then just make a recursive call on
4920 * the "type" pointed to by the modifier DNTT.
4921 *
4922 * pai:: FIXME -- do we ever want to handle "m_duplicate" and
4923 * "m_void" modifiers? Is static_flag really needed here?
4924 * (m_static used for methods of classes, elsewhere).
4925 */
4926 tmp_type = make_cv_type (dn_bufp->dmodifier.m_const,
4927 dn_bufp->dmodifier.m_volatile,
4928 hpread_type_lookup (dn_bufp->dmodifier.type, objfile),
4929 0);
4930 return tmp_type;
4931
4932
4933 case DNTT_TYPE_MEMFUNC:
4934 /* Member function. Treat like a function.
4935 * I think we get here in the course of processing a
4936 * pointer-to-member-function type...
4937 */
4938 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4939
4940 case DNTT_TYPE_DOC_MEMFUNC:
4941 return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
4942
4943 case DNTT_TYPE_TEMPLATE:
4944 /* Template - sort of the header for a template definition,
4945 * which like a class, points to a member list and also points
4946 * to a TEMPLATE_ARG list of type-arguments.
4947 */
4948 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4949
4950 case DNTT_TYPE_TEMPLATE_ARG:
4951 {
4952 char *name;
4953 /* The TEMPLATE record points to an argument list of
4954 * TEMPLATE_ARG records, each of which describes one
4955 * of the type-arguments.
4956 */
4957 name = VT (objfile) + dn_bufp->dtempl_arg.name;
4958 return hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name);
4959 }
4960
4961 case DNTT_TYPE_FUNC_TEMPLATE:
4962 /* We wind up here when processing a TEMPLATE type,
4963 * if the template has member function(s).
4964 * Treat it like a FUNCTION.
4965 */
4966 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4967
4968 case DNTT_TYPE_LINK:
4969 /* The LINK record is used to link up templates with instantiations.
4970 * There is no type associated with the LINK record per se.
4971 */
4972 return lookup_fundamental_type (objfile, FT_VOID);
4973
4974 /* Also not yet handled... */
4975 /* case DNTT_TYPE_DYN_ARRAY_DESC: */
4976 /* case DNTT_TYPE_DESC_SUBRANGE: */
4977 /* case DNTT_TYPE_BEGIN_EXT: */
4978 /* case DNTT_TYPE_INLN: */
4979 /* case DNTT_TYPE_INLN_LIST: */
4980 /* case DNTT_TYPE_ALIAS: */
c906108c 4981 default:
8af51c36 4982 /* A fancy way of returning NULL */
c906108c
SS
4983 return lookup_fundamental_type (objfile, FT_VOID);
4984 }
4985}
4986
4987static sltpointer
fba45db2
KB
4988hpread_record_lines (struct subfile *subfile, sltpointer s_idx,
4989 sltpointer e_idx, struct objfile *objfile,
4990 CORE_ADDR offset)
c906108c
SS
4991{
4992 union sltentry *sl_bufp;
4993
4994 while (s_idx <= e_idx)
4995 {
4996 sl_bufp = hpread_get_slt (s_idx, objfile);
4997 /* Only record "normal" entries in the SLT. */
4998 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
4999 || sl_bufp->snorm.sltdesc == SLT_EXIT)
5000 record_line (subfile, sl_bufp->snorm.line,
5001 sl_bufp->snorm.address + offset);
8af51c36
EZ
5002 else if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
5003 record_line (subfile, sl_bufp->snormoff.line,
5004 sl_bufp->snormoff.address + offset);
c906108c
SS
5005 s_idx++;
5006 }
5007 return e_idx;
5008}
5009
8af51c36
EZ
5010/* Given a function "f" which is a member of a class, find
5011 * the classname that it is a member of. Used to construct
5012 * the name (e.g., "c::f") which GDB will put in the
5013 * "demangled name" field of the function's symbol.
5014 * Called from hpread_process_one_debug_symbol()
5015 * If "f" is not a member function, return NULL.
5016 */
f5479e9c 5017static char *
8af51c36
EZ
5018class_of (struct type *functype)
5019{
5020 struct type *first_param_type;
5021 char *first_param_name;
5022 struct type *pointed_to_type;
5023 char *class_name;
5024
5025 /* Check that the function has a first argument "this",
5026 * and that "this" is a pointer to a class. If not,
5027 * functype is not a member function, so return NULL.
5028 */
5029 if (TYPE_NFIELDS (functype) == 0)
5030 return NULL;
5031 first_param_name = TYPE_FIELD_NAME (functype, 0);
5032 if (first_param_name == NULL)
5033 return NULL; /* paranoia */
5034 if (strcmp (first_param_name, "this"))
5035 return NULL;
5036 first_param_type = TYPE_FIELD_TYPE (functype, 0);
5037 if (first_param_type == NULL)
5038 return NULL; /* paranoia */
5039 if (TYPE_CODE (first_param_type) != TYPE_CODE_PTR)
5040 return NULL;
5041
5042 /* Get the thing that "this" points to, check that
5043 * it's a class, and get its class name.
5044 */
5045 pointed_to_type = TYPE_TARGET_TYPE (first_param_type);
5046 if (pointed_to_type == NULL)
5047 return NULL; /* paranoia */
5048 if (TYPE_CODE (pointed_to_type) != TYPE_CODE_CLASS)
5049 return NULL;
5050 class_name = TYPE_NAME (pointed_to_type);
5051 if (class_name == NULL)
5052 return NULL; /* paranoia */
5053
5054 /* The class name may be of the form "class c", in which case
5055 * we want to strip off the leading "class ".
5056 */
5057 if (strncmp (class_name, "class ", 6) == 0)
5058 class_name += 6;
5059
5060 return class_name;
5061}
5062
5063/* Internalize one native debug symbol.
5064 * Called in a loop from hpread_expand_symtab().
5065 * Arguments:
5066 * dn_bufp:
5067 * name:
5068 * section_offsets:
5069 * objfile:
5070 * text_offset:
5071 * text_size:
5072 * filename:
5073 * index: Index of this symbol
5074 * at_module_boundary_p Pointer to boolean flag to control caller's loop.
5075 */
c906108c
SS
5076
5077static void
fba45db2
KB
5078hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name,
5079 struct section_offsets *section_offsets,
5080 struct objfile *objfile, CORE_ADDR text_offset,
8af51c36
EZ
5081 int text_size, char *filename, int index,
5082 int *at_module_boundary_p)
c906108c
SS
5083{
5084 unsigned long desc;
5085 int type;
5086 CORE_ADDR valu;
b8fbeb18 5087 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
8af51c36 5088 int data_offset = ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
c906108c
SS
5089 union dnttentry *dn_temp;
5090 dnttpointer hp_type;
5091 struct symbol *sym;
5092 struct context_stack *new;
8af51c36 5093 char *class_scope_name;
c906108c 5094
8af51c36 5095 /* Allocate one GDB debug symbol and fill in some default values. */
4a146b47 5096 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
5097 sizeof (struct symbol));
5098 memset (sym, 0, sizeof (struct symbol));
4a146b47 5099 DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->objfile_obstack);
c906108c 5100 SYMBOL_LANGUAGE (sym) = language_auto;
176620f1 5101 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
c906108c
SS
5102 SYMBOL_LINE (sym) = 0;
5103 SYMBOL_VALUE (sym) = 0;
5104 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5105
8af51c36
EZ
5106 /* Just a trick in case the SOM debug symbol is a type definition.
5107 * There are routines that are set up to build a GDB type symbol, given
5108 * a SOM dnttpointer. So we set up a dummy SOM dnttpointer "hp_type".
5109 * This allows us to call those same routines.
5110 */
c906108c
SS
5111 hp_type.dnttp.extension = 1;
5112 hp_type.dnttp.immediate = 0;
5113 hp_type.dnttp.global = 0;
5114 hp_type.dnttp.index = index;
5115
8af51c36
EZ
5116 /* This "type" is the type of SOM record.
5117 * Switch on SOM type.
5118 */
c906108c 5119 type = dn_bufp->dblock.kind;
c906108c
SS
5120 switch (type)
5121 {
5122 case DNTT_TYPE_SRCFILE:
8af51c36
EZ
5123 /* This type of symbol indicates from which source file or
5124 * include file any following data comes. It may indicate:
5125 *
5126 * o The start of an entirely new source file (and thus
5127 * a new module)
5128 *
5129 * o The start of a different source file due to #include
5130 *
5131 * o The end of an include file and the return to the original
5132 * file. Thus if "foo.c" includes "bar.h", we see first
5133 * a SRCFILE for foo.c, then one for bar.h, and then one for
5134 * foo.c again.
5135 *
5136 * If it indicates the start of a new module then we must
5137 * finish the symbol table of the previous module
5138 * (if any) and start accumulating a new symbol table.
5139 */
c906108c
SS
5140
5141 valu = text_offset;
5142 if (!last_source_file)
5143 {
8af51c36
EZ
5144 /*
5145 * A note on "last_source_file": this is a char* pointing
5146 * to the actual file name. "start_symtab" sets it,
5147 * "end_symtab" clears it.
5148 *
5149 * So if "last_source_file" is NULL, then either this is
5150 * the first record we are looking at, or a previous call
5151 * to "end_symtab()" was made to close out the previous
5152 * module. Since we're now quitting the scan loop when we
5153 * see a MODULE END record, we should never get here, except
5154 * in the case that we're not using the quick look-up tables
5155 * and have to use the old system as a fall-back.
5156 */
c906108c
SS
5157 start_symtab (name, NULL, valu);
5158 record_debugformat ("HP");
5159 SL_INDEX (objfile) = dn_bufp->dsfile.address;
5160 }
8af51c36
EZ
5161
5162 else
5163 {
5164 /* Either a new include file, or a SRCFILE record
5165 * saying we are back in the main source (or out of
5166 * a nested include file) again.
5167 */
5168 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5169 SL_INDEX (objfile),
5170 dn_bufp->dsfile.address,
5171 objfile, offset);
5172 }
5173
5174 /* A note on "start_subfile". This routine will check
5175 * the name we pass it and look for an existing subfile
5176 * of that name. There's thus only one sub-file for the
5177 * actual source (e.g. for "foo.c" in foo.c), despite the
5178 * fact that we'll see lots of SRCFILE entries for foo.c
5179 * inside foo.c.
5180 */
5181 start_subfile (name, NULL);
5182 break;
5183
5184 case DNTT_TYPE_MODULE:
5185 /*
5186 * We no longer ignore DNTT_TYPE_MODULE symbols. The module
5187 * represents the meaningful semantic structure of a compilation
5188 * unit. We expect to start the psymtab-to-symtab expansion
5189 * looking at a MODULE entry, and to end it at the corresponding
5190 * END MODULE entry.
5191 *
5192 *--Begin outdated comments
5193 *
5194 * This record signifies the start of a new source module
5195 * In C/C++ there is no explicit "module" construct in the language,
5196 * but each compilation unit is implicitly a module and they
5197 * do emit the DNTT_TYPE_MODULE records.
5198 * The end of the module is marked by a matching DNTT_TYPE_END record.
5199 *
5200 * The reason GDB gets away with ignoring the DNTT_TYPE_MODULE record
5201 * is it notices the DNTT_TYPE_END record for the previous
5202 * module (see comments under DNTT_TYPE_END case), and then treats
5203 * the next DNTT_TYPE_SRCFILE record as if it were the module-start record.
5204 * (i.e., it makes a start_symtab() call).
5205 * This scheme seems a little convoluted, but I'll leave it
5206 * alone on the principle "if it ain't broke don't fix
5207 * it". (RT).
5208 *
5209 *-- End outdated comments
5210 */
5211
5212 valu = text_offset;
5213 if (!last_source_file)
5214 {
5215 /* Start of a new module. We know this because "last_source_file"
5216 * is NULL, which can only happen the first time or if we just
5217 * made a call to end_symtab() to close out the previous module.
5218 */
5219 start_symtab (name, NULL, valu);
5220 SL_INDEX (objfile) = dn_bufp->dmodule.address;
5221 }
c906108c
SS
5222 else
5223 {
8af51c36
EZ
5224 /* This really shouldn't happen if we're using the quick
5225 * look-up tables, as it would mean we'd scanned past an
5226 * END MODULE entry. But if we're not using the tables,
5227 * we started the module on the SRCFILE entry, so it's ok.
5228 * For now, accept this.
5229 */
5230 /* warning( "Error expanding psymtab, missed module end, found entry for %s",
5231 * name );
5232 */
5233 *at_module_boundary_p = -1;
c906108c 5234 }
c5aa993b 5235
8af51c36 5236 start_subfile (name, NULL);
c906108c
SS
5237 break;
5238
5239 case DNTT_TYPE_FUNCTION:
5240 case DNTT_TYPE_ENTRY:
5241 /* A function or secondary entry point. */
5242 valu = dn_bufp->dfunc.lowaddr + offset;
8af51c36
EZ
5243
5244 /* Record lines up to this point. */
c906108c
SS
5245 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5246 SL_INDEX (objfile),
5247 dn_bufp->dfunc.address,
5248 objfile, offset);
c5aa993b 5249
c906108c
SS
5250 WITHIN_FUNCTION (objfile) = 1;
5251 CURRENT_FUNCTION_VALUE (objfile) = valu;
5252
5253 /* Stack must be empty now. */
5254 if (context_stack_depth != 0)
1fb309ea 5255 lbrac_unmatched_complaint (symnum);
c906108c
SS
5256 new = push_context (0, valu);
5257
8af51c36
EZ
5258 /* Built a type for the function. This includes processing
5259 * the symbol records for the function parameters.
5260 */
c906108c 5261 SYMBOL_CLASS (sym) = LOC_BLOCK;
8af51c36
EZ
5262 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1);
5263
1e698235
DJ
5264 /* All functions in C++ have prototypes. For C we don't have enough
5265 information in the debug info. */
3269bcfa
JB
5266 if (SYMBOL_LANGUAGE (sym) == language_cplus)
5267 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1e698235 5268
22abf04a 5269 /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name
8af51c36
EZ
5270 * (if any), which we get from the "alias" field of the SOM record
5271 * if that exists.
5272 */
5273 if ((dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
5274 dn_bufp->dfunc.alias && /* has an alias */
5275 *(char *) (VT (objfile) + dn_bufp->dfunc.alias)) /* not a null string */
22abf04a 5276 DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias;
8af51c36 5277 else
22abf04a 5278 DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
8af51c36
EZ
5279
5280 /* Special hack to get around HP compilers' insistence on
5281 * reporting "main" as "_MAIN_" for C/C++ */
22abf04a 5282 if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) &&
8af51c36 5283 (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0))
22abf04a 5284 DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
8af51c36
EZ
5285
5286 /* The SYMBOL_CPLUS_DEMANGLED_NAME field is expected to
5287 * be the demangled name.
5288 */
5289 if (dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
5290 {
5291 /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
5292 * calling the demangler in libiberty (cplus_demangle()) to
5293 * do the job. This generally does the job, even though
5294 * it's intended for the GNU compiler and not the aCC compiler
5295 * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
5296 * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
5297 * Generally, we don't want params when we display
5298 * a demangled name, but when I took out the DMGL_PARAMS,
5299 * some things broke, so I'm leaving it in here, and
5300 * working around the issue in stack.c. - RT
5301 */
4a146b47 5302 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->objfile_obstack);
22abf04a 5303 if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->dfunc.alias) &&
8af51c36
EZ
5304 (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
5305 {
5306
5307 /* Well, the symbol name is mangled, but the
5308 * demangler in libiberty failed so the demangled
5309 * field is still NULL. Try to
5310 * do the job ourselves based on the "name" field
5311 * in the SOM record. A complication here is that
5312 * the name field contains only the function name
5313 * (like "f"), whereas we want the class qualification
5314 * (as in "c::f"). Try to reconstruct that.
5315 */
5316 char *basename;
5317 char *classname;
5318 char *dem_name;
5319 basename = VT (objfile) + dn_bufp->dfunc.name;
5320 classname = class_of (SYMBOL_TYPE (sym));
5321 if (classname)
5322 {
5323 dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
5324 strcpy (dem_name, classname);
5325 strcat (dem_name, "::");
5326 strcat (dem_name, basename);
5327 SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
5328 SYMBOL_LANGUAGE (sym) = language_cplus;
5329 }
5330 }
5331 }
5332
5333 /* Add the function symbol to the list of symbols in this blockvector */
c906108c
SS
5334 if (dn_bufp->dfunc.global)
5335 add_symbol_to_list (sym, &global_symbols);
5336 else
5337 add_symbol_to_list (sym, &file_symbols);
5338 new->name = sym;
5339
8af51c36
EZ
5340 /* Search forward to the next BEGIN and also read
5341 * in the line info up to that point.
5342 * Not sure why this is needed.
5343 * In HP FORTRAN this code is harmful since there
5344 * may not be a BEGIN after the FUNCTION.
5345 * So I made it C/C++ specific. - RT
5346 */
5347 if (dn_bufp->dfunc.language == HP_LANGUAGE_C ||
5348 dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
c906108c 5349 {
8af51c36
EZ
5350 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
5351 {
5352 dn_bufp = hpread_get_lntt (++index, objfile);
5353 if (dn_bufp->dblock.extension)
5354 continue;
5355 }
5356 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5357 SL_INDEX (objfile),
5358 dn_bufp->dbegin.address,
5359 objfile, offset);
5360 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
c906108c 5361 }
8af51c36
EZ
5362 record_line (current_subfile, SYMBOL_LINE (sym), valu);
5363 break;
5364
5365 case DNTT_TYPE_DOC_FUNCTION:
5366 valu = dn_bufp->ddocfunc.lowaddr + offset;
5367
5368 /* Record lines up to this point. */
c906108c
SS
5369 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5370 SL_INDEX (objfile),
8af51c36 5371 dn_bufp->ddocfunc.address,
c906108c 5372 objfile, offset);
8af51c36
EZ
5373
5374 WITHIN_FUNCTION (objfile) = 1;
5375 CURRENT_FUNCTION_VALUE (objfile) = valu;
5376 /* Stack must be empty now. */
5377 if (context_stack_depth != 0)
1fb309ea 5378 lbrac_unmatched_complaint (symnum);
8af51c36
EZ
5379 new = push_context (0, valu);
5380
5381 /* Built a type for the function. This includes processing
5382 * the symbol records for the function parameters.
5383 */
5384 SYMBOL_CLASS (sym) = LOC_BLOCK;
5385 SYMBOL_TYPE (sym) = hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 1);
5386
22abf04a 5387 /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name
8af51c36
EZ
5388 * (if any), which we get from the "alias" field of the SOM record
5389 * if that exists.
5390 */
5391 if ((dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
5392 dn_bufp->ddocfunc.alias && /* has an alias */
5393 *(char *) (VT (objfile) + dn_bufp->ddocfunc.alias)) /* not a null string */
22abf04a 5394 DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.alias;
8af51c36 5395 else
22abf04a 5396 DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
8af51c36
EZ
5397
5398 /* Special hack to get around HP compilers' insistence on
5399 * reporting "main" as "_MAIN_" for C/C++ */
22abf04a 5400 if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) &&
8af51c36 5401 (strcmp (VT (objfile) + dn_bufp->ddocfunc.name, "main") == 0))
22abf04a 5402 DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
8af51c36
EZ
5403
5404 if (dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
5405 {
5406
5407 /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
5408 * calling the demangler in libiberty (cplus_demangle()) to
5409 * do the job. This generally does the job, even though
5410 * it's intended for the GNU compiler and not the aCC compiler
5411 * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
5412 * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
5413 * Generally, we don't want params when we display
5414 * a demangled name, but when I took out the DMGL_PARAMS,
5415 * some things broke, so I'm leaving it in here, and
5416 * working around the issue in stack.c. - RT
5417 */
4a146b47 5418 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->objfile_obstack);
8af51c36 5419
22abf04a 5420 if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->ddocfunc.alias) &&
8af51c36
EZ
5421 (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
5422 {
5423
5424 /* Well, the symbol name is mangled, but the
5425 * demangler in libiberty failed so the demangled
5426 * field is still NULL. Try to
5427 * do the job ourselves based on the "name" field
5428 * in the SOM record. A complication here is that
5429 * the name field contains only the function name
5430 * (like "f"), whereas we want the class qualification
5431 * (as in "c::f"). Try to reconstruct that.
5432 */
5433 char *basename;
5434 char *classname;
5435 char *dem_name;
5436 basename = VT (objfile) + dn_bufp->ddocfunc.name;
5437 classname = class_of (SYMBOL_TYPE (sym));
5438 if (classname)
5439 {
5440 dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
5441 strcpy (dem_name, classname);
5442 strcat (dem_name, "::");
5443 strcat (dem_name, basename);
5444 SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
5445 SYMBOL_LANGUAGE (sym) = language_cplus;
5446 }
5447 }
5448 }
5449
5450 /* Add the function symbol to the list of symbols in this blockvector */
5451 if (dn_bufp->ddocfunc.global)
5452 add_symbol_to_list (sym, &global_symbols);
5453 else
5454 add_symbol_to_list (sym, &file_symbols);
5455 new->name = sym;
5456
5457 /* Search forward to the next BEGIN and also read
5458 * in the line info up to that point.
5459 * Not sure why this is needed.
5460 * In HP FORTRAN this code is harmful since there
5461 * may not be a BEGIN after the FUNCTION.
5462 * So I made it C/C++ specific. - RT
5463 */
5464 if (dn_bufp->ddocfunc.language == HP_LANGUAGE_C ||
5465 dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
5466 {
5467 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
5468 {
5469 dn_bufp = hpread_get_lntt (++index, objfile);
5470 if (dn_bufp->dblock.extension)
5471 continue;
5472 }
5473 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5474 SL_INDEX (objfile),
5475 dn_bufp->dbegin.address,
5476 objfile, offset);
5477 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
5478 }
c906108c
SS
5479 record_line (current_subfile, SYMBOL_LINE (sym), valu);
5480 break;
5481
5482 case DNTT_TYPE_BEGIN:
8af51c36
EZ
5483 /* Begin a new scope. */
5484 if (context_stack_depth == 1 /* this means we're at function level */ &&
5485 context_stack[0].name != NULL /* this means it's a function */ &&
5486 context_stack[0].depth == 0 /* this means it's the first BEGIN
5487 we've seen after the FUNCTION */
5488 )
5489 {
5490 /* This is the first BEGIN after a FUNCTION.
5491 * We ignore this one, since HP compilers always insert
5492 * at least one BEGIN, i.e. it's:
5493 *
5494 * FUNCTION
5495 * argument symbols
5496 * BEGIN
5497 * local symbols
5498 * (possibly nested BEGIN ... END's if there are inner { } blocks)
5499 * END
5500 * END
5501 *
5502 * By ignoring this first BEGIN, the local symbols get treated
5503 * as belonging to the function scope, and "print func::local_sym"
5504 * works (which is what we want).
5505 */
5506
5507 /* All we do here is increase the depth count associated with
5508 * the FUNCTION entry in the context stack. This ensures that
5509 * the next BEGIN we see (if any), representing a real nested { }
5510 * block, will get processed.
5511 */
5512
5513 context_stack[0].depth++;
5514
5515 }
5516 else
5517 {
5518
5519 /* Record lines up to this SLT pointer. */
5520 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5521 SL_INDEX (objfile),
5522 dn_bufp->dbegin.address,
5523 objfile, offset);
5524 /* Calculate start address of new scope */
5525 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
5526 valu += offset; /* Relocate for dynamic loading */
5527 /* We use the scope start DNTT index as nesting depth identifier! */
5528 desc = hpread_get_scope_start (dn_bufp->dbegin.address, objfile);
5529 new = push_context (desc, valu);
5530 }
c906108c
SS
5531 break;
5532
5533 case DNTT_TYPE_END:
5534 /* End a scope. */
8af51c36
EZ
5535
5536 /* Valid end kinds are:
5537 * MODULE
5538 * FUNCTION
5539 * WITH
5540 * COMMON
5541 * BEGIN
5542 * CLASS_SCOPE
5543 */
5544
c906108c
SS
5545 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5546 SL_INDEX (objfile),
8af51c36 5547 dn_bufp->dend.address,
c906108c
SS
5548 objfile, offset);
5549 switch (dn_bufp->dend.endkind)
5550 {
5551 case DNTT_TYPE_MODULE:
8af51c36
EZ
5552 /* Ending a module ends the symbol table for that module.
5553 * Calling end_symtab() has the side effect of clearing the
5554 * last_source_file pointer, which in turn signals
5555 * process_one_debug_symbol() to treat the next DNTT_TYPE_SRCFILE
5556 * record as a module-begin.
5557 */
c906108c 5558 valu = text_offset + text_size + offset;
8af51c36
EZ
5559
5560 /* Tell our caller that we're done with expanding the
5561 * debug information for a module.
5562 */
5563 *at_module_boundary_p = 1;
5564
5565 /* Don't do this, as our caller will do it!
5566
5567 * (void) end_symtab (valu, objfile, 0);
5568 */
c906108c
SS
5569 break;
5570
5571 case DNTT_TYPE_FUNCTION:
5572 /* Ending a function, well, ends the function's scope. */
5573 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
5574 objfile);
5575 valu = dn_temp->dfunc.hiaddr + offset;
8af51c36
EZ
5576 /* Insert func params into local list */
5577 merge_symbol_lists (&param_symbols, &local_symbols);
c906108c
SS
5578 new = pop_context ();
5579 /* Make a block for the local symbols within. */
5580 finish_block (new->name, &local_symbols, new->old_blocks,
5581 new->start_addr, valu, objfile);
8af51c36
EZ
5582 WITHIN_FUNCTION (objfile) = 0; /* This may have to change for Pascal */
5583 local_symbols = new->locals;
5584 param_symbols = new->params;
c906108c 5585 break;
8af51c36 5586
c906108c 5587 case DNTT_TYPE_BEGIN:
8af51c36
EZ
5588 if (context_stack_depth == 1 &&
5589 context_stack[0].name != NULL &&
5590 context_stack[0].depth == 1)
5591 {
5592 /* This is the END corresponding to the
5593 * BEGIN which we ignored - see DNTT_TYPE_BEGIN case above.
5594 */
5595 context_stack[0].depth--;
5596 }
5597 else
5598 {
5599 /* Ending a local scope. */
5600 valu = hpread_get_location (dn_bufp->dend.address, objfile);
5601 /* Why in the hell is this needed? */
5602 valu += offset + 9; /* Relocate for dynamic loading */
5603 new = pop_context ();
5604 desc = dn_bufp->dend.beginscope.dnttp.index;
5605 if (desc != new->depth)
1fb309ea 5606 lbrac_mismatch_complaint (symnum);
8af51c36
EZ
5607
5608 /* Make a block for the local symbols within. */
5609 finish_block (new->name, &local_symbols, new->old_blocks,
5610 new->start_addr, valu, objfile);
5611 local_symbols = new->locals;
5612 param_symbols = new->params;
5613 }
5614 break;
5615
5616 case DNTT_TYPE_WITH:
5617 /* Since we ignore the DNTT_TYPE_WITH that starts the scope,
5618 * we can ignore the DNTT_TYPE_END that ends it.
5619 */
5620 break;
5621
5622 case DNTT_TYPE_COMMON:
5623 /* End a FORTRAN common block. We don't currently handle these */
23136709
KB
5624 complaint (&symfile_complaints,
5625 "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON/DNTT_TYPE_END.\n");
8af51c36
EZ
5626 break;
5627
5628 case DNTT_TYPE_CLASS_SCOPE:
5629
5630 /* pai: FIXME Not handling nested classes for now -- must
5631 * maintain a stack */
5632 class_scope_name = NULL;
5633
5634#if 0
5635 /* End a class scope */
c906108c
SS
5636 valu = hpread_get_location (dn_bufp->dend.address, objfile);
5637 /* Why in the hell is this needed? */
5638 valu += offset + 9; /* Relocate for dynamic loading */
5639 new = pop_context ();
5640 desc = dn_bufp->dend.beginscope.dnttp.index;
5641 if (desc != new->depth)
23136709 5642 lbrac_mismatch_complaint ((char *) symnum);
c906108c
SS
5643 /* Make a block for the local symbols within. */
5644 finish_block (new->name, &local_symbols, new->old_blocks,
5645 new->start_addr, valu, objfile);
5646 local_symbols = new->locals;
8af51c36
EZ
5647 param_symbols = new->params;
5648#endif
5649 break;
5650
5651 default:
23136709
KB
5652 complaint (&symfile_complaints,
5653 "internal error in hp-symtab-read.c: Unexpected DNTT_TYPE_END kind.");
c906108c
SS
5654 break;
5655 }
5656 break;
8af51c36
EZ
5657
5658 /* DNTT_TYPE_IMPORT is not handled */
5659
c906108c 5660 case DNTT_TYPE_LABEL:
176620f1 5661 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
c906108c 5662 break;
8af51c36 5663
c906108c
SS
5664 case DNTT_TYPE_FPARAM:
5665 /* Function parameters. */
8af51c36
EZ
5666 /* Note 1: This code was present in the 4.16 sources, and then
5667 removed, because fparams are handled in
5668 hpread_read_function_type(). However, while fparam symbols
5669 are indeed handled twice, this code here cannot be removed
5670 because then they don't get added to the local symbol list of
5671 the function's code block, which leads to a failure to look
5672 up locals, "this"-relative member names, etc. So I've put
5673 this code back in. pai/1997-07-21 */
5674 /* Note 2: To fix a defect, we stopped adding FPARAMS to local_symbols
5675 in hpread_read_function_type(), so FPARAMS had to be handled
5676 here. I changed the location to be the appropriate argument
5677 kinds rather than LOC_LOCAL. pai/1997-08-08 */
5678 /* Note 3: Well, the fix in Note 2 above broke argument printing
5679 in traceback frames, and further it makes assumptions about the
5680 order of the FPARAM entries from HP compilers (cc and aCC in particular
5681 generate them in reverse orders -- fixing one breaks for the other).
5682 So I've added code in hpread_read_function_type() to add fparams
5683 to a param_symbols list for the current context level. These are
5684 then merged into local_symbols when a function end is reached.
5685 pai/1997-08-11 */
5686
5687 break; /* do nothing; handled in hpread_read_function_type() */
5688
5689#if 0 /* Old code */
c906108c
SS
5690 if (dn_bufp->dfparam.regparam)
5691 SYMBOL_CLASS (sym) = LOC_REGISTER;
8af51c36
EZ
5692 else if (dn_bufp->dfparam.indirect)
5693 SYMBOL_CLASS (sym) = LOC_REF_ARG;
c906108c 5694 else
8af51c36 5695 SYMBOL_CLASS (sym) = LOC_ARG;
176620f1 5696 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
c906108c
SS
5697 if (dn_bufp->dfparam.copyparam)
5698 {
5699 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
5700#ifdef HPREAD_ADJUST_STACK_ADDRESS
5701 SYMBOL_VALUE (sym)
5702 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
5703#endif
5704 }
5705 else
5706 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
5707 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
8af51c36 5708 add_symbol_to_list (sym, &fparam_symbols);
c906108c 5709 break;
8af51c36
EZ
5710#endif
5711
c906108c
SS
5712 case DNTT_TYPE_SVAR:
5713 /* Static variables. */
5714 SYMBOL_CLASS (sym) = LOC_STATIC;
8af51c36
EZ
5715
5716 /* Note: There is a case that arises with globals in shared
5717 * libraries where we need to set the address to LOC_INDIRECT.
5718 * This case is if you have a global "g" in one library, and
5719 * it is referenced "extern <type> g;" in another library.
5720 * If we're processing the symbols for the referencing library,
5721 * we'll see a global "g", but in this case the address given
5722 * in the symbol table contains a pointer to the real "g".
5723 * We use the storage class LOC_INDIRECT to indicate this. RT
5724 */
22abf04a 5725 if (is_in_import_list (DEPRECATED_SYMBOL_NAME (sym), objfile))
8af51c36
EZ
5726 SYMBOL_CLASS (sym) = LOC_INDIRECT;
5727
5728 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + data_offset;
c906108c 5729 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
8af51c36 5730
c906108c
SS
5731 if (dn_bufp->dsvar.global)
5732 add_symbol_to_list (sym, &global_symbols);
8af51c36 5733
c906108c
SS
5734 else if (WITHIN_FUNCTION (objfile))
5735 add_symbol_to_list (sym, &local_symbols);
8af51c36 5736
c906108c
SS
5737 else
5738 add_symbol_to_list (sym, &file_symbols);
8af51c36
EZ
5739
5740 if (dn_bufp->dsvar.thread_specific)
5741 {
5742 /* Thread-local variable.
5743 */
407caf07 5744 SYMBOL_CLASS (sym) = LOC_HP_THREAD_LOCAL_STATIC;
8af51c36
EZ
5745 SYMBOL_BASEREG (sym) = CR27_REGNUM;
5746
5747 if (objfile->flags & OBJF_SHARED)
5748 {
5749 /*
5750 * This variable is not only thread local but
5751 * in a shared library.
5752 *
5753 * Alas, the shared lib structures are private
5754 * to "somsolib.c". But C lets us point to one.
5755 */
5756 struct so_list *so;
5757
5758 if (objfile->obj_private == NULL)
5759 error ("Internal error in reading shared library information.");
5760
5761 so = ((obj_private_data_t *) (objfile->obj_private))->so_info;
5762 if (so == NULL)
5763 error ("Internal error in reading shared library information.");
5764
5765 /* Thread-locals in shared libraries do NOT have the
5766 * standard offset ("data_offset"), so we re-calculate
5767 * where to look for this variable, using a call-back
5768 * to interpret the private shared-library data.
5769 */
5770 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location +
5771 so_lib_thread_start_addr (so);
5772 }
5773 }
c906108c 5774 break;
8af51c36 5775
c906108c
SS
5776 case DNTT_TYPE_DVAR:
5777 /* Dynamic variables. */
5778 if (dn_bufp->ddvar.regvar)
5779 SYMBOL_CLASS (sym) = LOC_REGISTER;
5780 else
5781 SYMBOL_CLASS (sym) = LOC_LOCAL;
8af51c36 5782
c906108c
SS
5783 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
5784#ifdef HPREAD_ADJUST_STACK_ADDRESS
5785 SYMBOL_VALUE (sym)
5786 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
5787#endif
5788 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
5789 if (dn_bufp->ddvar.global)
5790 add_symbol_to_list (sym, &global_symbols);
5791 else if (WITHIN_FUNCTION (objfile))
5792 add_symbol_to_list (sym, &local_symbols);
5793 else
5794 add_symbol_to_list (sym, &file_symbols);
5795 break;
8af51c36 5796
c906108c
SS
5797 case DNTT_TYPE_CONST:
5798 /* A constant (pascal?). */
5799 SYMBOL_CLASS (sym) = LOC_CONST;
5800 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
5801 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
5802 if (dn_bufp->dconst.global)
5803 add_symbol_to_list (sym, &global_symbols);
5804 else if (WITHIN_FUNCTION (objfile))
5805 add_symbol_to_list (sym, &local_symbols);
5806 else
5807 add_symbol_to_list (sym, &file_symbols);
5808 break;
8af51c36 5809
c906108c 5810 case DNTT_TYPE_TYPEDEF:
8af51c36 5811 /* A typedef. We do want to process these, since a name is
176620f1 5812 * added to the domain for the typedef'ed name.
8af51c36 5813 */
176620f1 5814 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
c906108c
SS
5815 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
5816 if (dn_bufp->dtype.global)
5817 add_symbol_to_list (sym, &global_symbols);
5818 else if (WITHIN_FUNCTION (objfile))
5819 add_symbol_to_list (sym, &local_symbols);
5820 else
5821 add_symbol_to_list (sym, &file_symbols);
5822 break;
8af51c36 5823
c906108c 5824 case DNTT_TYPE_TAGDEF:
8af51c36
EZ
5825 {
5826 int global = dn_bufp->dtag.global;
5827 /* Structure, union, enum, template, or class tag definition */
5828 /* We do want to process these, since a name is
176620f1 5829 * added to the domain for the tag name (and if C++ class,
8af51c36
EZ
5830 * for the typename also).
5831 */
176620f1 5832 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
8af51c36
EZ
5833
5834 /* The tag contains in its "type" field a pointer to the
5835 * DNTT_TYPE_STRUCT, DNTT_TYPE_UNION, DNTT_TYPE_ENUM,
5836 * DNTT_TYPE_CLASS or DNTT_TYPE_TEMPLATE
5837 * record that actually defines the type.
5838 */
5839 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
22abf04a
DC
5840 TYPE_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym);
5841 TYPE_TAG_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym);
8af51c36
EZ
5842 if (dn_bufp->dtag.global)
5843 add_symbol_to_list (sym, &global_symbols);
5844 else if (WITHIN_FUNCTION (objfile))
5845 add_symbol_to_list (sym, &local_symbols);
5846 else
5847 add_symbol_to_list (sym, &file_symbols);
5848
5849 /* If this is a C++ class, then we additionally
5850 * need to define a typedef for the
5851 * class type. E.g., so that the name "c" becomes visible as
5852 * a type name when the user says "class c { ... }".
5853 * In order to figure this out, we need to chase down the "type"
5854 * field to get to the DNTT_TYPE_CLASS record.
5855 *
5856 * We also add the typename for ENUM. Though this isn't
5857 * strictly correct, it is necessary because of the debug info
5858 * generated by the aCC compiler, in which we cannot
5859 * distinguish between:
5860 * enum e { ... };
5861 * and
5862 * typedef enum { ... } e;
5863 * I.e., the compiler emits the same debug info for the above
5864 * two cases, in both cases "e" appearing as a tagdef.
5865 * Therefore go ahead and generate the typename so that
5866 * "ptype e" will work in the above cases.
5867 *
5868 * We also add the typename for TEMPLATE, so as to allow "ptype t"
5869 * when "t" is a template name.
5870 */
5871 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
5872 dn_bufp = hpread_get_lntt (dn_bufp->dtag.type.dnttp.index, objfile);
5873 else
5874 {
23136709 5875 complaint (&symfile_complaints, "error processing class tagdef");
8af51c36
EZ
5876 return;
5877 }
5878 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
5879 dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
5880 dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
5881 {
5882 struct symbol *newsym;
5883
4a146b47 5884 newsym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
8af51c36
EZ
5885 sizeof (struct symbol));
5886 memset (newsym, 0, sizeof (struct symbol));
22abf04a 5887 DEPRECATED_SYMBOL_NAME (newsym) = name;
8af51c36 5888 SYMBOL_LANGUAGE (newsym) = language_auto;
176620f1 5889 SYMBOL_DOMAIN (newsym) = VAR_DOMAIN;
8af51c36
EZ
5890 SYMBOL_LINE (newsym) = 0;
5891 SYMBOL_VALUE (newsym) = 0;
5892 SYMBOL_CLASS (newsym) = LOC_TYPEDEF;
5893 SYMBOL_TYPE (newsym) = sym->type;
5894 if (global)
5895 add_symbol_to_list (newsym, &global_symbols);
5896 else if (WITHIN_FUNCTION (objfile))
5897 add_symbol_to_list (newsym, &local_symbols);
5898 else
5899 add_symbol_to_list (newsym, &file_symbols);
5900 }
5901 }
c906108c 5902 break;
8af51c36 5903
c906108c 5904 case DNTT_TYPE_POINTER:
8af51c36
EZ
5905 /* Declares a pointer type. Should not be necessary to do anything
5906 * with the type at this level; these are processed
5907 * at the hpread_type_lookup() level.
5908 */
c906108c 5909 break;
8af51c36 5910
c906108c 5911 case DNTT_TYPE_ENUM:
8af51c36
EZ
5912 /* Declares an enum type. Should not be necessary to do anything
5913 * with the type at this level; these are processed
5914 * at the hpread_type_lookup() level.
5915 */
c906108c 5916 break;
8af51c36 5917
c906108c 5918 case DNTT_TYPE_MEMENUM:
8af51c36
EZ
5919 /* Member of enum */
5920 /* Ignored at this level, but hpread_read_enum_type() will take
5921 * care of walking the list of enumeration members.
5922 */
c906108c 5923 break;
8af51c36 5924
c906108c 5925 case DNTT_TYPE_SET:
8af51c36
EZ
5926 /* Declares a set type. Should not be necessary to do anything
5927 * with the type at this level; these are processed
5928 * at the hpread_type_lookup() level.
5929 */
c906108c 5930 break;
8af51c36 5931
c906108c 5932 case DNTT_TYPE_SUBRANGE:
8af51c36
EZ
5933 /* Declares a subrange type. Should not be necessary to do anything
5934 * with the type at this level; these are processed
5935 * at the hpread_type_lookup() level.
5936 */
c906108c 5937 break;
8af51c36 5938
c906108c 5939 case DNTT_TYPE_ARRAY:
8af51c36
EZ
5940 /* Declares an array type. Should not be necessary to do anything
5941 * with the type at this level; these are processed
5942 * at the hpread_type_lookup() level.
5943 */
c906108c 5944 break;
8af51c36 5945
c906108c
SS
5946 case DNTT_TYPE_STRUCT:
5947 case DNTT_TYPE_UNION:
8af51c36
EZ
5948 /* Declares an struct/union type.
5949 * Should not be necessary to do anything
5950 * with the type at this level; these are processed
5951 * at the hpread_type_lookup() level.
5952 */
5953 break;
5954
5955 case DNTT_TYPE_FIELD:
5956 /* Structure/union/class field */
5957 /* Ignored at this level, but hpread_read_struct_type() will take
5958 * care of walking the list of structure/union/class members.
5959 */
5960 break;
5961
5962 /* DNTT_TYPE_VARIANT is not handled by GDB */
5963
5964 /* DNTT_TYPE_FILE is not handled by GDB */
5965
5966 case DNTT_TYPE_FUNCTYPE:
5967 /* Function type */
5968 /* Ignored at this level, handled within hpread_type_lookup() */
5969 break;
5970
5971 case DNTT_TYPE_WITH:
5972 /* This is emitted within methods to indicate "with <class>"
5973 * scoping rules (i.e., indicate that the class data members
5974 * are directly visible).
5975 * However, since GDB already infers this by looking at the
5976 * "this" argument, interpreting the DNTT_TYPE_WITH
5977 * symbol record is unnecessary.
5978 */
5979 break;
5980
5981 case DNTT_TYPE_COMMON:
5982 /* FORTRAN common. Not yet handled. */
23136709
KB
5983 complaint (&symfile_complaints,
5984 "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON.");
8af51c36
EZ
5985 break;
5986
5987 /* DNTT_TYPE_COBSTRUCT is not handled by GDB. */
5988 /* DNTT_TYPE_XREF is not handled by GDB. */
5989 /* DNTT_TYPE_SA is not handled by GDB. */
5990 /* DNTT_TYPE_MACRO is not handled by GDB */
5991
5992 case DNTT_TYPE_BLOCKDATA:
5993 /* Not sure what this is - part of FORTRAN support maybe?
5994 * Anyway, not yet handled.
5995 */
23136709
KB
5996 complaint (&symfile_complaints,
5997 "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_BLOCKDATA.");
8af51c36
EZ
5998 break;
5999
6000 case DNTT_TYPE_CLASS_SCOPE:
6001
6002
6003
6004 /* The compiler brackets member functions with a CLASS_SCOPE/END
6005 * pair of records, presumably to put them in a different scope
6006 * from the module scope where they are normally defined.
6007 * E.g., in the situation:
6008 * void f() { ... }
6009 * void c::f() { ...}
6010 * The member function "c::f" will be bracketed by a CLASS_SCOPE/END.
6011 * This causes "break f" at the module level to pick the
6012 * the file-level function f(), not the member function
6013 * (which needs to be referenced via "break c::f").
6014 *
6015 * Here we record the class name to generate the demangled names of
6016 * member functions later.
6017 *
6018 * FIXME Not being used now for anything -- cplus_demangle seems
6019 * enough for getting the class-qualified names of functions. We
6020 * may need this for handling nested classes and types. */
6021
6022 /* pai: FIXME Not handling nested classes for now -- need to
6023 * maintain a stack */
6024
6025 dn_temp = hpread_get_lntt (dn_bufp->dclass_scope.type.dnttp.index, objfile);
6026 if (dn_temp->dblock.kind == DNTT_TYPE_TAGDEF)
6027 class_scope_name = VT (objfile) + dn_temp->dtag.name;
6028 else
6029 class_scope_name = NULL;
6030
6031#if 0
6032
6033 /* Begin a new scope. */
6034 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
6035 SL_INDEX (objfile),
6036 dn_bufp->dclass_scope.address,
6037 objfile, offset);
6038 valu = hpread_get_location (dn_bufp->dclass_scope.address, objfile);
6039 valu += offset; /* Relocate for dynamic loading */
6040 desc = hpread_get_scope_start (dn_bufp->dclass_scope.address, objfile);
6041 /* We use the scope start DNTT index as the nesting depth identifier! */
6042 new = push_context (desc, valu);
6043#endif
6044 break;
6045
6046 case DNTT_TYPE_REFERENCE:
6047 /* Declares a C++ reference type. Should not be necessary to do anything
6048 * with the type at this level; these are processed
6049 * at the hpread_type_lookup() level.
6050 */
6051 break;
6052
6053 case DNTT_TYPE_PTRMEM:
6054 /* Declares a C++ pointer-to-data-member type. This does not
6055 * need to be handled at this level; being a type description it
6056 * is instead handled at the hpread_type_lookup() level.
6057 */
6058 break;
6059
6060 case DNTT_TYPE_PTRMEMFUNC:
6061 /* Declares a C++ pointer-to-function-member type. This does not
6062 * need to be handled at this level; being a type description it
6063 * is instead handled at the hpread_type_lookup() level.
6064 */
6065 break;
6066
6067 case DNTT_TYPE_CLASS:
6068 /* Declares a class type.
6069 * Should not be necessary to do anything
6070 * with the type at this level; these are processed
6071 * at the hpread_type_lookup() level.
6072 */
6073 break;
6074
6075 case DNTT_TYPE_GENFIELD:
6076 /* I believe this is used for class member functions */
6077 /* Ignored at this level, but hpread_read_struct_type() will take
6078 * care of walking the list of class members.
6079 */
6080 break;
6081
6082 case DNTT_TYPE_VFUNC:
6083 /* Virtual function */
6084 /* This does not have to be handled at this level; handled in
6085 * the course of processing class symbols.
6086 */
6087 break;
6088
6089 case DNTT_TYPE_MEMACCESS:
6090 /* DDE ignores this symbol table record.
6091 * It has something to do with "modified access" to class members.
6092 * I'll assume we can safely ignore it too.
6093 */
6094 break;
6095
6096 case DNTT_TYPE_INHERITANCE:
6097 /* These don't have to be handled here, since they are handled
6098 * within hpread_read_struct_type() in the process of constructing
6099 * a class type.
6100 */
6101 break;
6102
6103 case DNTT_TYPE_FRIEND_CLASS:
6104 case DNTT_TYPE_FRIEND_FUNC:
6105 /* These can safely be ignored, as GDB doesn't need this
6106 * info. DDE only uses it in "describe". We may later want
6107 * to extend GDB's "ptype" to give this info, but for now
6108 * it seems safe enough to ignore it.
6109 */
6110 break;
6111
6112 case DNTT_TYPE_MODIFIER:
6113 /* Intended to supply "modified access" to a type */
6114 /* From the way DDE handles this, it looks like it always
6115 * modifies a type. Therefore it is safe to ignore it at this
6116 * level, and handle it in hpread_type_lookup().
6117 */
6118 break;
6119
6120 case DNTT_TYPE_OBJECT_ID:
6121 /* Just ignore this - that's all DDE does */
6122 break;
6123
6124 case DNTT_TYPE_MEMFUNC:
6125 /* Member function */
6126 /* This does not have to be handled at this level; handled in
6127 * the course of processing class symbols.
6128 */
6129 break;
6130
6131 case DNTT_TYPE_DOC_MEMFUNC:
6132 /* Member function */
6133 /* This does not have to be handled at this level; handled in
6134 * the course of processing class symbols.
6135 */
6136 break;
6137
6138 case DNTT_TYPE_TEMPLATE:
6139 /* Template - sort of the header for a template definition,
6140 * which like a class, points to a member list and also points
6141 * to a TEMPLATE_ARG list of type-arguments.
6142 * We do not need to process TEMPLATE records at this level though.
6143 */
6144 break;
6145
6146 case DNTT_TYPE_TEMPLATE_ARG:
6147 /* The TEMPLATE record points to an argument list of
6148 * TEMPLATE_ARG records, each of which describes one
6149 * of the type-arguments.
6150 * We do not need to process TEMPLATE_ARG records at this level though.
6151 */
6152 break;
6153
6154 case DNTT_TYPE_FUNC_TEMPLATE:
6155 /* This will get emitted for member functions of templates.
6156 * But we don't need to process this record at this level though,
6157 * we will process it in the course of processing a TEMPLATE
6158 * record.
6159 */
6160 break;
6161
6162 case DNTT_TYPE_LINK:
6163 /* The LINK record is used to link up templates with instantiations. */
6164 /* It is not clear why this is needed, and furthermore aCC does
6165 * not appear to generate this, so I think we can safely ignore it. - RT
6166 */
c906108c 6167 break;
8af51c36
EZ
6168
6169 /* DNTT_TYPE_DYN_ARRAY_DESC is not handled by GDB */
6170 /* DNTT_TYPE_DESC_SUBRANGE is not handled by GDB */
6171 /* DNTT_TYPE_BEGIN_EXT is not handled by GDB */
6172 /* DNTT_TYPE_INLN is not handled by GDB */
6173 /* DNTT_TYPE_INLN_LIST is not handled by GDB */
6174 /* DNTT_TYPE_ALIAS is not handled by GDB */
6175
c906108c
SS
6176 default:
6177 break;
6178 }
6179}
8af51c36
EZ
6180
6181/* Get nesting depth for a DNTT entry.
6182 * DN_BUFP points to a DNTT entry.
6183 * OBJFILE is the object file.
6184 * REPORT_NESTED is a flag; if 0, real nesting depth is
6185 * reported, if it is 1, the function simply returns a
6186 * non-zero value if the nesting depth is anything > 0.
6187 *
6188 * Return value is an integer. 0 => not a local type / name
6189 * positive return => type or name is local to some
6190 * block or function.
6191 */
6192
6193
6194/* elz: ATTENTION: FIXME: NOTE: WARNING!!!!
6195 this function now returns 0 right away. It was taking too much time
6196 at start up. Now, though, the local types are not handled correctly.
6197 */
6198
6199
6200static int
6201hpread_get_scope_depth (union dnttentry *dn_bufp, struct objfile *objfile,
6202 int report_nested)
6203{
52f0bd74
AC
6204 int index;
6205 union dnttentry *dn_tmp;
6206 short depth = 0;
8af51c36
EZ
6207/****************************/
6208 return 0;
6209/****************************/
6210
6211 index = (((char *) dn_bufp) - LNTT (objfile)) / (sizeof (struct dntt_type_block));
6212
6213 while (--index >= 0)
6214 {
6215 dn_tmp = hpread_get_lntt (index, objfile);
6216 switch (dn_tmp->dblock.kind)
6217 {
6218 case DNTT_TYPE_MODULE:
6219 return depth;
6220 case DNTT_TYPE_END:
6221 /* index is signed int; dnttp.index is 29-bit unsigned int! */
6222 index = (int) dn_tmp->dend.beginscope.dnttp.index;
6223 break;
6224 case DNTT_TYPE_BEGIN:
6225 case DNTT_TYPE_FUNCTION:
6226 case DNTT_TYPE_DOC_FUNCTION:
6227 case DNTT_TYPE_WITH:
6228 case DNTT_TYPE_COMMON:
6229 case DNTT_TYPE_CLASS_SCOPE:
6230 depth++;
6231 if (report_nested)
6232 return 1;
6233 break;
6234 default:
6235 break;
6236 }
6237 }
6238 return depth;
6239}
6240
6241/* Adjust the bitoffsets for all fields of an anonymous union of
6242 type TYPE by negative BITS. This handles HP aCC's hideous habit
6243 of giving members of anonymous unions bit offsets relative to the
6244 enclosing structure instead of relative to the union itself. */
6245
6246static void
6247hpread_adjust_bitoffsets (struct type *type, int bits)
6248{
52f0bd74 6249 int i;
8af51c36
EZ
6250
6251 /* This is done only for unions; caller had better check that
6252 it is an anonymous one. */
6253 if (TYPE_CODE (type) != TYPE_CODE_UNION)
6254 return;
6255
6256 /* Adjust each field; since this is a union, there are no base
6257 classes. Also no static membes. Also, no need for recursion as
6258 the members of this union if themeselves structs or unions, have
6259 the correct bitoffsets; if an anonymous union is a member of this
6260 anonymous union, the code in hpread_read_struct_type() will
6261 adjust for that. */
6262
6263 for (i = 0; i < TYPE_NFIELDS (type); i++)
6264 TYPE_FIELD_BITPOS (type, i) -= bits;
6265}
6266
6267/* Because of quirks in HP compilers' treatment of anonymous unions inside
6268 classes, we have to chase through a chain of threaded FIELD entries.
6269 If we encounter an anonymous union in the chain, we must recursively skip over
6270 that too.
6271
6272 This function does a "next" in the chain of FIELD entries, but transparently
6273 skips over anonymous unions' fields (recursively).
6274
6275 Inputs are the number of times to do "next" at the top level, the dnttpointer
6276 (FIELD) and entry pointer (FIELDP) for the dntt record corresponding to it,
6277 and the ubiquitous objfile parameter. (Note: FIELDP is a **.) Return value
6278 is a dnttpointer for the new field after all the skipped ones */
6279
6280static dnttpointer
6281hpread_get_next_skip_over_anon_unions (int skip_fields, dnttpointer field,
6282 union dnttentry **fieldp,
6283 struct objfile *objfile)
6284{
6285 struct type *anon_type;
52f0bd74 6286 int i;
8af51c36
EZ
6287 int bitoffset;
6288 char *name;
6289
6290 for (i = 0; i < skip_fields; i++)
6291 {
6292 /* Get type of item we're looking at now; recursively processes the types
6293 of these intermediate items we skip over, so they aren't lost. */
6294 anon_type = hpread_type_lookup ((*fieldp)->dfield.type, objfile);
6295 anon_type = CHECK_TYPEDEF (anon_type);
6296 bitoffset = (*fieldp)->dfield.bitoffset;
6297 name = VT (objfile) + (*fieldp)->dfield.name;
6298 /* First skip over one item to avoid stack death on recursion */
6299 field = (*fieldp)->dfield.nextfield;
6300 *fieldp = hpread_get_lntt (field.dnttp.index, objfile);
6301 /* Do we have another anonymous union? If so, adjust the bitoffsets
6302 of its members and skip over its members. */
6303 if ((TYPE_CODE (anon_type) == TYPE_CODE_UNION) &&
cb137aa5 6304 (!name || DEPRECATED_STREQ (name, "")))
8af51c36
EZ
6305 {
6306 hpread_adjust_bitoffsets (anon_type, bitoffset);
6307 field = hpread_get_next_skip_over_anon_unions (TYPE_NFIELDS (anon_type), field, fieldp, objfile);
6308 }
6309 }
6310 return field;
6311}
This page took 0.610086 seconds and 4 git commands to generate.