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