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