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