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