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