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