Replace jumbo pattern match with gdb_expect_list().
[deliverable/binutils-gdb.git] / gdb / hp-psymtab-read.c
1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993, 1996, 1998, 1999 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support. */
23
24 /* Common include file for hp_symtab_read.c and hp_psymtab_read.c.
25 This has nested includes of a bunch of stuff. */
26 #include "hpread.h"
27 #include "demangle.h"
28
29 /* To generate dumping code, uncomment this define. The dumping
30 itself is controlled by routine-local statics called "dumping". */
31 /* #define DUMPING 1 */
32
33 /* To use the quick look-up tables, uncomment this define. */
34 #define QUICK_LOOK_UP 1
35
36 /* To call PXDB to process un-processed files, uncomment this define. */
37 #define USE_PXDB 1
38
39 /* Forward procedure declarations */
40
41 void hpread_symfile_init (struct objfile *);
42
43 void do_pxdb (bfd *);
44
45 void hpread_build_psymtabs (struct objfile *, int);
46
47 void hpread_symfile_finish (struct objfile *);
48
49 static union dnttentry *hpread_get_gntt (int, struct objfile *);
50
51 static unsigned long hpread_get_textlow (int, int, struct objfile *, int);
52
53 static struct partial_symtab *hpread_start_psymtab
54 (struct objfile *, char *, CORE_ADDR, int,
55 struct partial_symbol **, struct partial_symbol **);
56
57 static struct partial_symtab *hpread_end_psymtab
58 (struct partial_symtab *, char **, int, int, CORE_ADDR,
59 struct partial_symtab **, int);
60
61 /* End of forward routine declarations */
62
63 #ifdef USE_PXDB
64
65 /* NOTE use of system files! May not be portable. */
66
67 #define PXDB_SVR4 "/opt/langtools/bin/pxdb"
68 #define PXDB_BSD "/usr/bin/pxdb"
69
70 #include <stdlib.h>
71 #include <string.h>
72
73 /* check for the existance of a file, given its full pathname */
74 int
75 file_exists (filename)
76 char *filename;
77 {
78 if (filename)
79 return (access (filename, F_OK) == 0);
80 return 0;
81 }
82
83
84 /* Translate from the "hp_language" enumeration in hp-symtab.h
85 used in the debug info to gdb's generic enumeration in defs.h. */
86 static enum language
87 trans_lang (in_lang)
88 enum hp_language in_lang;
89 {
90 if (in_lang == HP_LANGUAGE_C)
91 return language_c;
92
93 else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
94 return language_cplus;
95
96 else if (in_lang == HP_LANGUAGE_FORTRAN)
97 return language_fortran;
98
99 else
100 return language_unknown;
101 }
102
103 static char main_string[] = "main";
104 \f
105 /* Call PXDB to process our file.
106
107 Approach copied from DDE's "dbgk_run_pxdb". Note: we
108 don't check for BSD location of pxdb, nor for existance
109 of pxdb itself, etc.
110
111 NOTE: uses system function and string functions directly.
112
113 Return value: 1 if ok, 0 if not */
114 int
115 hpread_call_pxdb (file_name)
116 char *file_name;
117 {
118 char *p;
119 int status;
120 int retval;
121
122 if (file_exists (PXDB_SVR4))
123 {
124 p = malloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
125 strcpy (p, PXDB_SVR4);
126 strcat (p, " ");
127 strcat (p, file_name);
128
129 warning ("File not processed by pxdb--about to process now.\n");
130 status = system (p);
131
132 retval = (status == 0);
133 }
134 else
135 {
136 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);
137
138 retval = 0;
139 }
140 return retval;
141 } /* hpread_call_pxdb */
142 \f
143
144 /* Return 1 if the file turns out to need pre-processing
145 by PXDB, and we have thus called PXDB to do this processing
146 and the file therefore needs to be re-loaded. Otherwise
147 return 0. */
148 int
149 hpread_pxdb_needed (sym_bfd)
150 bfd *sym_bfd;
151 {
152 asection *pinfo_section, *debug_section, *header_section;
153 unsigned int do_pxdb;
154 char *buf;
155 bfd_size_type header_section_size;
156
157 unsigned long tmp;
158 unsigned int pxdbed;
159
160 header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
161 if (!header_section)
162 {
163 return 0; /* No header at all, can't recover... */
164 }
165
166 debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
167 pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
168
169 if (pinfo_section && !debug_section)
170 {
171 /* Debug info with DOC, has different header format.
172 this only happens if the file was pxdbed and compiled optimized
173 otherwise the PINFO section is not there. */
174 header_section_size = bfd_section_size (objfile->obfd, header_section);
175
176 if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
177 {
178 buf = alloca (sizeof (DOC_info_PXDB_header));
179
180 if (!bfd_get_section_contents (sym_bfd,
181 header_section,
182 buf, 0,
183 header_section_size))
184 error ("bfd_get_section_contents\n");
185
186 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
187 pxdbed = (tmp >> 31) & 0x1;
188
189 if (!pxdbed)
190 error ("file debug header info invalid\n");
191 do_pxdb = 0;
192 }
193
194 else
195 error ("invalid $HEADER$ size in executable \n");
196 }
197
198 else
199 {
200
201 /* this can be three different cases:
202 1. pxdbed and not doc
203 - DEBUG and HEADER sections are there
204 - header is PXDB_header type
205 - pxdbed flag is set to 1
206
207 2. not pxdbed and doc
208 - DEBUG and HEADER sections are there
209 - header is DOC_info_header type
210 - pxdbed flag is set to 0
211
212 3. not pxdbed and not doc
213 - DEBUG and HEADER sections are there
214 - header is XDB_header type
215 - pxdbed flag is set to 0
216
217 NOTE: the pxdbed flag is meaningful also in the not
218 already pxdb processed version of the header,
219 because in case on non-already processed by pxdb files
220 that same bit in the header would be always zero.
221 Why? Because the bit is the leftmost bit of a word
222 which contains a 'length' which is always a positive value
223 so that bit is never set to 1 (otherwise it would be negative)
224
225 Given the above, we have two choices : either we ignore the
226 size of the header itself and just look at the pxdbed field,
227 or we check the size and then we (for safety and paranoia related
228 issues) check the bit.
229 The first solution is used by DDE, the second by PXDB itself.
230 I am using the second one here, because I already wrote it,
231 and it is the end of a long day.
232 Also, using the first approach would still involve size issues
233 because we need to read in the contents of the header section, and
234 give the correct amount of stuff we want to read to the
235 get_bfd_section_contents function. */
236
237 /* decide which case depending on the size of the header section.
238 The size is as defined in hp-symtab.h */
239
240 header_section_size = bfd_section_size (objfile->obfd, header_section);
241
242 if (header_section_size == (bfd_size_type) sizeof (PXDB_header)) /* pxdb and not doc */
243 {
244
245 buf = alloca (sizeof (PXDB_header));
246 if (!bfd_get_section_contents (sym_bfd,
247 header_section,
248 buf, 0,
249 header_section_size))
250 error ("bfd_get_section_contents\n");
251
252 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
253 pxdbed = (tmp >> 31) & 0x1;
254
255 if (pxdbed)
256 do_pxdb = 0;
257 else
258 error ("file debug header invalid\n");
259 }
260 else /*not pxdbed and doc OR not pxdbed and non doc */
261 do_pxdb = 1;
262 }
263
264 if (do_pxdb)
265 {
266 return 1;
267 }
268 else
269 {
270 return 0;
271 }
272 } /* hpread_pxdb_needed */
273
274 #endif
275
276 /* Check whether the file needs to be preprocessed by pxdb.
277 If so, call pxdb. */
278
279 void
280 do_pxdb (sym_bfd)
281 bfd *sym_bfd;
282 {
283 /* The following code is HP-specific. The "right" way of
284 doing this is unknown, but we bet would involve a target-
285 specific pre-file-load check using a generic mechanism. */
286
287 /* This code will not be executed if the file is not in SOM
288 format (i.e. if compiled with gcc) */
289 if (hpread_pxdb_needed (sym_bfd))
290 {
291 /*This file has not been pre-processed. Preprocess now */
292
293 if (hpread_call_pxdb (sym_bfd->filename))
294 {
295 /* The call above has changed the on-disk file,
296 we can close the file anyway, because the
297 symbols will be reread in when the target is run */
298 bfd_close (sym_bfd);
299 }
300 }
301 }
302 \f
303
304
305 #ifdef QUICK_LOOK_UP
306
307 /* Code to handle quick lookup-tables follows. */
308
309
310 /* Some useful macros */
311 #define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries)
312 #define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
313 #define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries)
314 #define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries)
315
316 #define FILE_START(i) (qFD[i].adrStart)
317 #define MODULE_START(i) (qMD[i].adrStart)
318 #define PROC_START(i) (qPD[i].adrStart)
319
320 #define FILE_END(i) (qFD[i].adrEnd)
321 #define MODULE_END(i) (qMD[i].adrEnd)
322 #define PROC_END(i) (qPD[i].adrEnd)
323
324 #define FILE_ISYM(i) (qFD[i].isym)
325 #define MODULE_ISYM(i) (qMD[i].isym)
326 #define PROC_ISYM(i) (qPD[i].isym)
327
328 #define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries)
329 #define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries)
330 #define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries)
331 #define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries)
332
333 #define CURR_FILE_START (qFD[curr_fd].adrStart)
334 #define CURR_MODULE_START (qMD[curr_md].adrStart)
335 #define CURR_PROC_START (qPD[curr_pd].adrStart)
336
337 #define CURR_FILE_END (qFD[curr_fd].adrEnd)
338 #define CURR_MODULE_END (qMD[curr_md].adrEnd)
339 #define CURR_PROC_END (qPD[curr_pd].adrEnd)
340
341 #define CURR_FILE_ISYM (qFD[curr_fd].isym)
342 #define CURR_MODULE_ISYM (qMD[curr_md].isym)
343 #define CURR_PROC_ISYM (qPD[curr_pd].isym)
344
345 #define TELL_OBJFILE \
346 do { \
347 if( !told_objfile ) { \
348 told_objfile = 1; \
349 warning ("\nIn object file \"%s\":\n", \
350 objfile->name); \
351 } \
352 } while (0)
353 \f
354
355
356 /* Keeping track of the start/end symbol table (LNTT) indices of
357 psymtabs created so far */
358
359 typedef struct
360 {
361 int start;
362 int end;
363 }
364 pst_syms_struct;
365
366 static pst_syms_struct *pst_syms_array = 0;
367
368 static pst_syms_count = 0;
369 static pst_syms_size = 0;
370
371 /* used by the TELL_OBJFILE macro */
372 static boolean told_objfile = 0;
373
374 /* Set up psymtab symbol index stuff */
375 static void
376 init_pst_syms ()
377 {
378 pst_syms_count = 0;
379 pst_syms_size = 20;
380 pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
381 }
382
383 /* Clean up psymtab symbol index stuff */
384 static void
385 clear_pst_syms ()
386 {
387 pst_syms_count = 0;
388 pst_syms_size = 0;
389 free (pst_syms_array);
390 pst_syms_array = 0;
391 }
392
393 /* Add information about latest psymtab to symbol index table */
394 static void
395 record_pst_syms (start_sym, end_sym)
396 int start_sym;
397 int end_sym;
398 {
399 if (++pst_syms_count > pst_syms_size)
400 {
401 pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
402 2 * pst_syms_size * sizeof (pst_syms_struct));
403 pst_syms_size *= 2;
404 }
405 pst_syms_array[pst_syms_count - 1].start = start_sym;
406 pst_syms_array[pst_syms_count - 1].end = end_sym;
407 }
408
409 /* Find a suitable symbol table index which can serve as the upper
410 bound of a psymtab that starts at INDEX
411
412 This scans backwards in the psymtab symbol index table to find a
413 "hole" in which the given index can fit. This is a heuristic!!
414 We don't search the entire table to check for multiple holes,
415 we don't care about overlaps, etc.
416
417 Return 0 => not found */
418 static int
419 find_next_pst_start (index)
420 int index;
421 {
422 int i;
423
424 for (i = pst_syms_count - 1; i >= 0; i--)
425 if (pst_syms_array[i].end <= index)
426 return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
427
428 if (pst_syms_array[0].start > index)
429 return pst_syms_array[0].start - 1;
430
431 return 0;
432 }
433 \f
434
435
436 /* Utility functions to find the ending symbol index for a psymtab */
437
438 /* Find the next file entry that begins beyond INDEX, and return
439 its starting symbol index - 1.
440 QFD is the file table, CURR_FD is the file entry from where to start,
441 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
442
443 Return 0 => not found */
444 static int
445 find_next_file_isym (index, qFD, curr_fd, pxdb_header_p)
446 int index;
447 quick_file_entry *qFD;
448 int curr_fd;
449 PXDB_header_ptr pxdb_header_p;
450 {
451 while (VALID_CURR_FILE)
452 {
453 if (CURR_FILE_ISYM >= index)
454 return CURR_FILE_ISYM - 1;
455 curr_fd++;
456 }
457 return 0;
458 }
459
460 /* Find the next procedure entry that begins beyond INDEX, and return
461 its starting symbol index - 1.
462 QPD is the procedure table, CURR_PD is the proc entry from where to start,
463 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
464
465 Return 0 => not found */
466 static int
467 find_next_proc_isym (index, qPD, curr_pd, pxdb_header_p)
468 int index;
469 quick_procedure_entry *qPD;
470 int curr_pd;
471 PXDB_header_ptr pxdb_header_p;
472 {
473 while (VALID_CURR_PROC)
474 {
475 if (CURR_PROC_ISYM >= index)
476 return CURR_PROC_ISYM - 1;
477 curr_pd++;
478 }
479 return 0;
480 }
481
482 /* Find the next module entry that begins beyond INDEX, and return
483 its starting symbol index - 1.
484 QMD is the module table, CURR_MD is the modue entry from where to start,
485 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
486
487 Return 0 => not found */
488 static int
489 find_next_module_isym (index, qMD, curr_md, pxdb_header_p)
490 int index;
491 quick_module_entry *qMD;
492 int curr_md;
493 PXDB_header_ptr pxdb_header_p;
494 {
495 while (VALID_CURR_MODULE)
496 {
497 if (CURR_MODULE_ISYM >= index)
498 return CURR_MODULE_ISYM - 1;
499 curr_md++;
500 }
501 return 0;
502 }
503
504 /* Scan and record partial symbols for all functions starting from index
505 pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
506 Other parameters are explained in comments below. */
507
508 /* This used to be inline in hpread_quick_traverse, but now that we do essentially the
509 same thing for two different cases (modules and module-less files), it's better
510 organized in a separate routine, although it does take lots of arguments. pai/1997-10-08 */
511
512 static int
513 scan_procs (curr_pd_p, qPD, max_procs, start_adr, end_adr, pst, vt_bits, objfile)
514 int *curr_pd_p; /* pointer to current proc index */
515 quick_procedure_entry *qPD; /* the procedure quick lookup table */
516 int max_procs; /* number of entries in proc. table */
517 CORE_ADDR start_adr; /* beginning of code range for current psymtab */
518 CORE_ADDR end_adr; /* end of code range for current psymtab */
519 struct partial_symtab *pst; /* current psymtab */
520 char *vt_bits; /* strings table of SOM debug space */
521 struct objfile *objfile; /* current object file */
522 {
523 union dnttentry *dn_bufp;
524 int symbol_count = 0; /* Total number of symbols in this psymtab */
525 int curr_pd = *curr_pd_p; /* Convenience variable -- avoid dereferencing pointer all the time */
526
527 #ifdef DUMPING
528 /* Turn this on for lots of debugging information in this routine */
529 static int dumping = 0;
530 #endif
531
532 #ifdef DUMPING
533 if (dumping)
534 {
535 printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
536 }
537 #endif
538
539 while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
540 {
541
542 char *rtn_name; /* mangled name */
543 char *rtn_dem_name; /* qualified demangled name */
544 char *class_name;
545 int class;
546
547 if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
548 vt_bits[(long) qPD[curr_pd].sbAlias]) /* not a null string */
549 {
550 /* Get mangled name for the procedure, and demangle it */
551 rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
552 rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
553 }
554 else
555 {
556 rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
557 rtn_dem_name = NULL;
558 }
559
560 /* Hack to get around HP C/C++ compilers' insistence on providing
561 "_MAIN_" as an alternate name for "main" */
562 if ((strcmp (rtn_name, "_MAIN_") == 0) &&
563 (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
564 rtn_dem_name = rtn_name = main_string;
565
566 #ifdef DUMPING
567 if (dumping)
568 {
569 printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
570 }
571 #endif
572
573 /* Check for module-spanning routines. */
574 if (CURR_PROC_END > end_adr)
575 {
576 TELL_OBJFILE;
577 warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
578 }
579
580 /* Add this routine symbol to the list in the objfile.
581 Unfortunately we have to go to the LNTT to determine the
582 correct list to put it on. An alternative (which the
583 code used to do) would be to not check and always throw
584 it on the "static" list. But if we go that route, then
585 symbol_lookup() needs to be tweaked a bit to account
586 for the fact that the function might not be found on
587 the correct list in the psymtab. - RT */
588 dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
589 if (dn_bufp->dfunc.global)
590 add_psymbol_with_dem_name_to_list (rtn_name,
591 strlen (rtn_name),
592 rtn_dem_name,
593 strlen (rtn_dem_name),
594 VAR_NAMESPACE,
595 LOC_BLOCK, /* "I am a routine" */
596 &objfile->global_psymbols,
597 (qPD[curr_pd].adrStart + /* Starting address of rtn */
598 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
599 0, /* core addr?? */
600 trans_lang ((enum hp_language) qPD[curr_pd].language),
601 objfile);
602 else
603 add_psymbol_with_dem_name_to_list (rtn_name,
604 strlen (rtn_name),
605 rtn_dem_name,
606 strlen (rtn_dem_name),
607 VAR_NAMESPACE,
608 LOC_BLOCK, /* "I am a routine" */
609 &objfile->static_psymbols,
610 (qPD[curr_pd].adrStart + /* Starting address of rtn */
611 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
612 0, /* core addr?? */
613 trans_lang ((enum hp_language) qPD[curr_pd].language),
614 objfile);
615
616 symbol_count++;
617 *curr_pd_p = ++curr_pd; /* bump up count & reflect in caller */
618 } /* loop over procedures */
619
620 #ifdef DUMPING
621 if (dumping)
622 {
623 if (symbol_count == 0)
624 printf ("Scan_procs: no symbols found!\n");
625 }
626 #endif
627
628 return symbol_count;
629 }
630
631
632 /* Traverse the quick look-up tables, building a set of psymtabs.
633
634 This constructs a psymtab for modules and files in the quick lookup
635 tables.
636
637 Mostly, modules correspond to compilation units, so we try to
638 create psymtabs that correspond to modules; however, in some cases
639 a file can result in a compiled object which does not have a module
640 entry for it, so in such cases we create a psymtab for the file. */
641
642 int
643 hpread_quick_traverse (objfile, gntt_bits, vt_bits, pxdb_header_p)
644 struct objfile *objfile; /* The object file descriptor */
645 char *gntt_bits; /* GNTT entries, loaded in from the file */
646 char *vt_bits; /* VT (string) entries ditto. */
647 PXDB_header_ptr pxdb_header_p; /* Pointer to pxdb header ditto */
648 {
649 struct partial_symtab *pst;
650
651 char *addr;
652
653 quick_procedure_entry *qPD;
654 quick_file_entry *qFD;
655 quick_module_entry *qMD;
656 quick_class_entry *qCD;
657
658 int idx;
659 int i;
660 CORE_ADDR start_adr; /* current psymtab's starting code addr */
661 CORE_ADDR end_adr; /* current psymtab's ending code addr */
662 CORE_ADDR next_mod_adr; /* next module's starting code addr */
663 int curr_pd; /* current procedure */
664 int curr_fd; /* current file */
665 int curr_md; /* current module */
666 int start_sym; /* current psymtab's starting symbol index */
667 int end_sym; /* current psymtab's ending symbol index */
668 int max_LNTT_sym_index;
669 int syms_in_pst;
670 B_TYPE *class_entered;
671
672 struct partial_symbol **global_syms; /* We'll be filling in the "global" */
673 struct partial_symbol **static_syms; /* and "static" tables in the objfile
674 as we go, so we need a pair of
675 current pointers. */
676
677 #ifdef DUMPING
678 /* Turn this on for lots of debugging information in this routine.
679 You get a blow-by-blow account of quick lookup table reading */
680 static int dumping = 0;
681 #endif
682
683 pst = (struct partial_symtab *) 0;
684
685 /* Clear out some globals */
686 init_pst_syms ();
687 told_objfile = 0;
688
689 /* Demangling style -- if EDG style already set, don't change it,
690 as HP style causes some problems with the KAI EDG compiler */
691 if (current_demangling_style != edg_demangling)
692 {
693 /* Otherwise, ensure that we are using HP style demangling */
694 set_demangling_style (HP_DEMANGLING_STYLE_STRING);
695 }
696
697 /* First we need to find the starting points of the quick
698 look-up tables in the GNTT. */
699
700 addr = gntt_bits;
701
702 qPD = (quick_procedure_entry_ptr) addr;
703 addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
704
705 #ifdef DUMPING
706 if (dumping)
707 {
708 printf ("\n Printing routines as we see them\n");
709 for (i = 0; VALID_PROC (i); i++)
710 {
711 idx = (long) qPD[i].sbProc;
712 printf ("%s %x..%x\n", &vt_bits[idx],
713 (int) PROC_START (i),
714 (int) PROC_END (i));
715 }
716 }
717 #endif
718
719 qFD = (quick_file_entry_ptr) addr;
720 addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
721
722 #ifdef DUMPING
723 if (dumping)
724 {
725 printf ("\n Printing files as we see them\n");
726 for (i = 0; VALID_FILE (i); i++)
727 {
728 idx = (long) qFD[i].sbFile;
729 printf ("%s %x..%x\n", &vt_bits[idx],
730 (int) FILE_START (i),
731 (int) FILE_END (i));
732 }
733 }
734 #endif
735
736 qMD = (quick_module_entry_ptr) addr;
737 addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
738
739 #ifdef DUMPING
740 if (dumping)
741 {
742 printf ("\n Printing modules as we see them\n");
743 for (i = 0; i < pxdb_header_p->md_entries; i++)
744 {
745 idx = (long) qMD[i].sbMod;
746 printf ("%s\n", &vt_bits[idx]);
747 }
748 }
749 #endif
750
751 qCD = (quick_class_entry_ptr) addr;
752 addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
753
754 #ifdef DUMPING
755 if (dumping)
756 {
757 printf ("\n Printing classes as we see them\n");
758 for (i = 0; VALID_CLASS (i); i++)
759 {
760 idx = (long) qCD[i].sbClass;
761 printf ("%s\n", &vt_bits[idx]);
762 }
763
764 printf ("\n Done with dump, on to build!\n");
765 }
766 #endif
767
768 /* We need this index only while hp-symtab-read.c expects
769 a byte offset to the end of the LNTT entries for a given
770 psymtab. Thus the need for it should go away someday.
771
772 When it goes away, then we won't have any need to load the
773 LNTT from the objfile at psymtab-time, and start-up will be
774 faster. To make that work, we'll need some way to create
775 a null pst for the "globals" pseudo-module. */
776 max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
777
778 /* Scan the module descriptors and make a psymtab for each.
779
780 We know the MDs, FDs and the PDs are in order by starting
781 address. We use that fact to traverse all three arrays in
782 parallel, knowing when the next PD is in a new file
783 and we need to create a new psymtab. */
784 curr_pd = 0; /* Current procedure entry */
785 curr_fd = 0; /* Current file entry */
786 curr_md = 0; /* Current module entry */
787
788 start_adr = 0; /* Current psymtab code range */
789 end_adr = 0;
790
791 start_sym = 0; /* Current psymtab symbol range */
792 end_sym = 0;
793
794 syms_in_pst = 0; /* Symbol count for psymtab */
795
796 /* Psts actually just have pointers into the objfile's
797 symbol table, not their own symbol tables. */
798 global_syms = objfile->global_psymbols.list;
799 static_syms = objfile->static_psymbols.list;
800
801
802 /* First skip over pseudo-entries with address 0. These represent inlined
803 routines and abstract (uninstantiated) template routines.
804 FIXME: These should be read in and available -- even if we can't set
805 breakpoints, etc., there's some information that can be presented
806 to the user. pai/1997-10-08 */
807
808 while (VALID_CURR_PROC && (CURR_PROC_START == 0))
809 curr_pd++;
810
811 /* Loop over files, modules, and procedures in code address order. Each
812 time we enter an iteration of this loop, curr_pd points to the first
813 unprocessed procedure, curr_fd points to the first unprocessed file, and
814 curr_md to the first unprocessed module. Each iteration of this loop
815 updates these as required -- any or all of them may be bumpd up
816 each time around. When we exit this loop, we are done with all files
817 and modules in the tables -- there may still be some procedures, however.
818
819 Note: This code used to loop only over module entries, under the assumption
820 that files can occur via inclusions and are thus unreliable, while a
821 compiled object always corresponds to a module. With CTTI in the HP aCC
822 compiler, it turns out that compiled objects may have only files and no
823 modules; so we have to loop over files and modules, creating psymtabs for
824 either as appropriate. Unfortunately there are some problems (notably:
825 1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
826 to the ending symbol indices of a module or a file) which make it quite hard
827 to do this correctly. Currently it uses a bunch of heuristics to start and
828 end psymtabs; they seem to work well with most objects generated by aCC, but
829 who knows when that will change... */
830
831 while (VALID_CURR_FILE || VALID_CURR_MODULE)
832 {
833
834 char *mod_name_string;
835 char *full_name_string;
836
837 /* First check for modules like "version.c", which have no code
838 in them but still have qMD entries. They also have no qFD or
839 qPD entries. Their start address is -1 and their end address
840 is 0. */
841 if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
842 {
843
844 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
845
846 #ifdef DUMPING
847 if (dumping)
848 printf ("Module with data only %s\n", mod_name_string);
849 #endif
850
851 /* We'll skip the rest (it makes error-checking easier), and
852 just make an empty pst. Right now empty psts are not put
853 in the pst chain, so all this is for naught, but later it
854 might help. */
855
856 pst = hpread_start_psymtab (objfile,
857 mod_name_string,
858 CURR_MODULE_START, /* Low text address: bogus! */
859 (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
860 /* ldsymoff */
861 global_syms,
862 static_syms);
863
864 pst = hpread_end_psymtab (pst,
865 NULL, /* psymtab_include_list */
866 0, /* includes_used */
867 end_sym * sizeof (struct dntt_type_block),
868 /* byte index in LNTT of end
869 = capping symbol offset
870 = LDSYMOFF of nextfile */
871 0, /* text high */
872 NULL, /* dependency_list */
873 0); /* dependencies_used */
874
875 global_syms = objfile->global_psymbols.next;
876 static_syms = objfile->static_psymbols.next;
877
878 curr_md++;
879 }
880 else if (VALID_CURR_MODULE &&
881 ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
882 (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
883 {
884 TELL_OBJFILE;
885 warning ("Module \"%s\" [0x%x] has non-standard addresses. It starts at 0x%x, ends at 0x%x, and will be skipped.",
886 mod_name_string, curr_md, start_adr, end_adr);
887 /* On to next module */
888 curr_md++;
889 }
890 else
891 {
892 /* First check if we are looking at a file with code in it
893 that does not overlap the current module's code range */
894
895 if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
896 {
897
898 /* Looking at file not corresponding to any module,
899 create a psymtab for it */
900 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
901 start_adr = CURR_FILE_START;
902 end_adr = CURR_FILE_END;
903 start_sym = CURR_FILE_ISYM;
904
905 /* Check if there are any procedures not handled until now, that
906 begin before the start address of this file, and if so, adjust
907 this module's start address to include them. This handles routines that
908 are in between file or module ranges for some reason (probably
909 indicates a compiler bug */
910
911 if (CURR_PROC_START < start_adr)
912 {
913 TELL_OBJFILE;
914 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
915 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
916 start_adr = CURR_PROC_START;
917 if (CURR_PROC_ISYM < start_sym)
918 start_sym = CURR_PROC_ISYM;
919 }
920
921 /* Sometimes (compiler bug -- COBOL) the module end address is higher
922 than the start address of the next module, so check for that and
923 adjust accordingly */
924
925 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
926 {
927 TELL_OBJFILE;
928 warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
929 full_name_string, curr_fd);
930 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
931 }
932 if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
933 {
934 TELL_OBJFILE;
935 warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
936 full_name_string, curr_fd);
937 end_adr = CURR_MODULE_START - 1; /* Is -4 (or -8 for 64-bit) better? */
938 }
939
940
941 #ifdef DUMPING
942 if (dumping)
943 {
944 printf ("Make new psymtab for file %s (%x to %x).\n",
945 full_name_string, start_adr, end_adr);
946 }
947 #endif
948 /* Create the basic psymtab, connecting it in the list
949 for this objfile and pointing its symbol entries
950 to the current end of the symbol areas in the objfile.
951
952 The "ldsymoff" parameter is the byte offset in the LNTT
953 of the first symbol in this file. Some day we should
954 turn this into an index (fix in hp-symtab-read.c as well).
955 And it's not even the right byte offset, as we're using
956 the size of a union! FIXME! */
957 pst = hpread_start_psymtab (objfile,
958 full_name_string,
959 start_adr, /* Low text address */
960 (start_sym * sizeof (struct dntt_type_block)),
961 /* ldsymoff */
962 global_syms,
963 static_syms);
964
965 /* Set up to only enter each class referenced in this module once. */
966 class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
967 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
968
969 /* Scan the procedure descriptors for procedures in the current
970 file, based on the starting addresses. */
971
972 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
973 start_adr, end_adr, pst, vt_bits, objfile);
974
975 /* Get ending symbol offset */
976
977 end_sym = 0;
978 /* First check for starting index before previous psymtab */
979 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
980 {
981 end_sym = find_next_pst_start (start_sym);
982 }
983 /* Look for next start index of a file or module, or procedure */
984 if (!end_sym)
985 {
986 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
987 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
988 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
989
990 if (next_file_isym && next_module_isym)
991 {
992 /* pick lower of next file or module start index */
993 end_sym = min (next_file_isym, next_module_isym);
994 }
995 else
996 {
997 /* one of them is zero, pick the other */
998 end_sym = max (next_file_isym, next_module_isym);
999 }
1000
1001 /* As a precaution, check next procedure index too */
1002 if (!end_sym)
1003 end_sym = next_proc_isym;
1004 else
1005 end_sym = min (end_sym, next_proc_isym);
1006 }
1007
1008 /* Couldn't find procedure, file, or module, use globals as default */
1009 if (!end_sym)
1010 end_sym = pxdb_header_p->globals;
1011
1012 #ifdef DUMPING
1013 if (dumping)
1014 {
1015 printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1016 }
1017 #endif
1018
1019 pst = hpread_end_psymtab (pst,
1020 NULL, /* psymtab_include_list */
1021 0, /* includes_used */
1022 end_sym * sizeof (struct dntt_type_block),
1023 /* byte index in LNTT of end
1024 = capping symbol offset
1025 = LDSYMOFF of nextfile */
1026 end_adr, /* text high */
1027 NULL, /* dependency_list */
1028 0); /* dependencies_used */
1029
1030 record_pst_syms (start_sym, end_sym);
1031
1032 if (NULL == pst)
1033 warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
1034
1035 #ifdef DUMPING
1036 if (dumping)
1037 {
1038 printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1039 full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1040 }
1041 #endif
1042 /* Prepare for the next psymtab. */
1043 global_syms = objfile->global_psymbols.next;
1044 static_syms = objfile->static_psymbols.next;
1045 free (class_entered);
1046
1047 curr_fd++;
1048 } /* Psymtab for file */
1049 else
1050 {
1051 /* We have a module for which we create a psymtab */
1052
1053 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1054
1055 /* We will include the code ranges of any files that happen to
1056 overlap with this module */
1057
1058 /* So, first pick the lower of the file's and module's start addresses */
1059 start_adr = CURR_MODULE_START;
1060 if (VALID_CURR_FILE)
1061 {
1062 if (CURR_FILE_START < CURR_MODULE_START)
1063 {
1064 TELL_OBJFILE;
1065 warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1066 &vt_bits[(long) qFD[curr_fd].sbFile],
1067 curr_fd, mod_name_string);
1068
1069 start_adr = CURR_FILE_START;
1070 }
1071 }
1072
1073 /* Also pick the lower of the file's and the module's start symbol indices */
1074 start_sym = CURR_MODULE_ISYM;
1075 if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1076 start_sym = CURR_FILE_ISYM;
1077
1078 /* For the end address, we scan through the files till we find one
1079 that overlaps the current module but ends beyond it; if no such file exists we
1080 simply use the module's start address.
1081 (Note, if file entries themselves overlap
1082 we take the longest overlapping extension beyond the end of the module...)
1083 We assume that modules never overlap. */
1084
1085 end_adr = CURR_MODULE_END;
1086
1087 if (VALID_CURR_FILE)
1088 {
1089 while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1090 {
1091
1092 #ifdef DUMPING
1093 if (dumping)
1094 printf ("Maybe skipping file %s which overlaps with module %s\n",
1095 &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1096 #endif
1097 if (CURR_FILE_END > end_adr)
1098 {
1099 TELL_OBJFILE;
1100 warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1101 &vt_bits[(long) qFD[curr_fd].sbFile],
1102 curr_fd, mod_name_string);
1103 end_adr = CURR_FILE_END;
1104 }
1105 curr_fd++;
1106 }
1107 curr_fd--; /* back up after going too far */
1108 }
1109
1110 /* Sometimes (compiler bug -- COBOL) the module end address is higher
1111 than the start address of the next module, so check for that and
1112 adjust accordingly */
1113
1114 if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1115 {
1116 TELL_OBJFILE;
1117 warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1118 mod_name_string, curr_md);
1119 end_adr = MODULE_START (curr_md + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1120 }
1121 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1122 {
1123 TELL_OBJFILE;
1124 warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1125 mod_name_string, curr_md);
1126 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1127 }
1128
1129 /* Use one file to get the full name for the module. This
1130 situation can arise if there is executable code in a #include
1131 file. Each file with code in it gets a qFD. Files which don't
1132 contribute code don't get a qFD, even if they include files
1133 which do, e.g.:
1134
1135 body.c: rtn.h:
1136 int x; int main() {
1137 #include "rtn.h" return x;
1138 }
1139
1140 There will a qFD for "rtn.h",and a qMD for "body.c",
1141 but no qMD for "rtn.h" or qFD for "body.c"!
1142
1143 We pick the name of the last file to overlap with this
1144 module. C convention is to put include files first. In a
1145 perfect world, we could check names and use the file whose full
1146 path name ends with the module name. */
1147
1148 if (VALID_CURR_FILE)
1149 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1150 else
1151 full_name_string = mod_name_string;
1152
1153 /* Check if there are any procedures not handled until now, that
1154 begin before the start address we have now, and if so, adjust
1155 this psymtab's start address to include them. This handles routines that
1156 are in between file or module ranges for some reason (probably
1157 indicates a compiler bug */
1158
1159 if (CURR_PROC_START < start_adr)
1160 {
1161 TELL_OBJFILE;
1162 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1163 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1164 start_adr = CURR_PROC_START;
1165 if (CURR_PROC_ISYM < start_sym)
1166 start_sym = CURR_PROC_ISYM;
1167 }
1168
1169 #ifdef DUMPING
1170 if (dumping)
1171 {
1172 printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1173 mod_name_string, start_adr, end_adr, full_name_string);
1174 }
1175 #endif
1176 /* Create the basic psymtab, connecting it in the list
1177 for this objfile and pointing its symbol entries
1178 to the current end of the symbol areas in the objfile.
1179
1180 The "ldsymoff" parameter is the byte offset in the LNTT
1181 of the first symbol in this file. Some day we should
1182 turn this into an index (fix in hp-symtab-read.c as well).
1183 And it's not even the right byte offset, as we're using
1184 the size of a union! FIXME! */
1185 pst = hpread_start_psymtab (objfile,
1186 full_name_string,
1187 start_adr, /* Low text address */
1188 (start_sym * sizeof (struct dntt_type_block)),
1189 /* ldsymoff */
1190 global_syms,
1191 static_syms);
1192
1193 /* Set up to only enter each class referenced in this module once. */
1194 class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
1195 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1196
1197 /* Scan the procedure descriptors for procedures in the current
1198 module, based on the starting addresses. */
1199
1200 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1201 start_adr, end_adr, pst, vt_bits, objfile);
1202
1203 /* Get ending symbol offset */
1204
1205 end_sym = 0;
1206 /* First check for starting index before previous psymtab */
1207 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1208 {
1209 end_sym = find_next_pst_start (start_sym);
1210 }
1211 /* Look for next start index of a file or module, or procedure */
1212 if (!end_sym)
1213 {
1214 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1215 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1216 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1217
1218 if (next_file_isym && next_module_isym)
1219 {
1220 /* pick lower of next file or module start index */
1221 end_sym = min (next_file_isym, next_module_isym);
1222 }
1223 else
1224 {
1225 /* one of them is zero, pick the other */
1226 end_sym = max (next_file_isym, next_module_isym);
1227 }
1228
1229 /* As a precaution, check next procedure index too */
1230 if (!end_sym)
1231 end_sym = next_proc_isym;
1232 else
1233 end_sym = min (end_sym, next_proc_isym);
1234 }
1235
1236 /* Couldn't find procedure, file, or module, use globals as default */
1237 if (!end_sym)
1238 end_sym = pxdb_header_p->globals;
1239
1240 #ifdef DUMPING
1241 if (dumping)
1242 {
1243 printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1244 }
1245 #endif
1246
1247 pst = hpread_end_psymtab (pst,
1248 NULL, /* psymtab_include_list */
1249 0, /* includes_used */
1250 end_sym * sizeof (struct dntt_type_block),
1251 /* byte index in LNTT of end
1252 = capping symbol offset
1253 = LDSYMOFF of nextfile */
1254 end_adr, /* text high */
1255 NULL, /* dependency_list */
1256 0); /* dependencies_used */
1257
1258 record_pst_syms (start_sym, end_sym);
1259
1260 if (NULL == pst)
1261 warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1262
1263 #ifdef DUMPING
1264 if (dumping)
1265 {
1266 printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1267 mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1268 }
1269 #endif
1270
1271 /* Prepare for the next psymtab. */
1272 global_syms = objfile->global_psymbols.next;
1273 static_syms = objfile->static_psymbols.next;
1274 free (class_entered);
1275
1276 curr_md++;
1277 curr_fd++;
1278 } /* psymtab for module */
1279 } /* psymtab for non-bogus file or module */
1280 } /* End of while loop over all files & modules */
1281
1282 /* There may be some routines after all files and modules -- these will get
1283 inserted in a separate new module of their own */
1284 if (VALID_CURR_PROC)
1285 {
1286 start_adr = CURR_PROC_START;
1287 end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1288 TELL_OBJFILE;
1289 warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1290 #ifdef DUMPING
1291 if (dumping)
1292 {
1293 printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1294 curr_pd, start_adr, end_adr);
1295 }
1296 #endif
1297 pst = hpread_start_psymtab (objfile,
1298 "orphans",
1299 start_adr, /* Low text address */
1300 (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1301 /* ldsymoff */
1302 global_syms,
1303 static_syms);
1304
1305 scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1306 start_adr, end_adr, pst, vt_bits, objfile);
1307
1308 pst = hpread_end_psymtab (pst,
1309 NULL, /* psymtab_include_list */
1310 0, /* includes_used */
1311 pxdb_header_p->globals * sizeof (struct dntt_type_block),
1312 /* byte index in LNTT of end
1313 = capping symbol offset
1314 = LDSYMOFF of nextfile */
1315 end_adr, /* text high */
1316 NULL, /* dependency_list */
1317 0); /* dependencies_used */
1318 }
1319
1320
1321 #ifdef NEVER_NEVER
1322 /* Now build psts for non-module things (in the tail of
1323 the LNTT, after the last END MODULE entry).
1324
1325 If null psts were kept on the chain, this would be
1326 a solution. FIXME */
1327 pst = hpread_start_psymtab (objfile,
1328 "globals",
1329 0,
1330 (pxdb_header_p->globals
1331 * sizeof (struct dntt_type_block)),
1332 objfile->global_psymbols.next,
1333 objfile->static_psymbols.next);
1334 hpread_end_psymtab (pst,
1335 NULL, 0,
1336 (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1337 0,
1338 NULL, 0);
1339 #endif
1340
1341 clear_pst_syms ();
1342
1343 return 1;
1344
1345 } /* End of hpread_quick_traverse. */
1346 \f
1347
1348 /* Get appropriate header, based on pxdb type.
1349 Return value: 1 if ok, 0 if not */
1350 int
1351 hpread_get_header (objfile, pxdb_header_p)
1352 struct objfile *objfile;
1353 PXDB_header_ptr pxdb_header_p;
1354 {
1355 asection *pinfo_section, *debug_section, *header_section;
1356
1357 #ifdef DUMPING
1358 /* Turn on for debugging information */
1359 static int dumping = 0;
1360 #endif
1361
1362 header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1363 if (!header_section)
1364 {
1365 /* We don't have either PINFO or DEBUG sections. But
1366 stuff like "libc.sl" has no debug info. There's no
1367 need to warn the user of this, as it may be ok. The
1368 caller will figure it out and issue any needed
1369 messages. */
1370 #ifdef DUMPING
1371 if (dumping)
1372 printf ("==No debug info at all for %s.\n", objfile->name);
1373 #endif
1374
1375 return 0;
1376 }
1377
1378 /* We would like either a $DEBUG$ or $PINFO$ section.
1379 Once we know which, we can understand the header
1380 data (which we have defined to suit the more common
1381 $DEBUG$ case). */
1382 debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1383 pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1384 if (debug_section)
1385 {
1386 /* The expected case: normal pxdb header. */
1387 bfd_get_section_contents (objfile->obfd, header_section,
1388 pxdb_header_p, 0, sizeof (PXDB_header));
1389
1390 if (!pxdb_header_p->pxdbed)
1391 {
1392 /* This shouldn't happen if we check in "symfile.c". */
1393 return 0;
1394 } /* DEBUG section */
1395 }
1396
1397 else if (pinfo_section)
1398 {
1399 /* The DOC case; we need to translate this into a
1400 regular header. */
1401 DOC_info_PXDB_header doc_header;
1402
1403 #ifdef DUMPING
1404 if (dumping)
1405 {
1406 printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1407 }
1408 #endif
1409
1410 bfd_get_section_contents (objfile->obfd,
1411 header_section,
1412 &doc_header, 0,
1413 sizeof (DOC_info_PXDB_header));
1414
1415 if (!doc_header.pxdbed)
1416 {
1417 /* This shouldn't happen if we check in "symfile.c". */
1418 warning ("File \"%s\" not processed by pxdb!", objfile->name);
1419 return 0;
1420 }
1421
1422 /* Copy relevent fields to standard header passed in. */
1423 pxdb_header_p->pd_entries = doc_header.pd_entries;
1424 pxdb_header_p->fd_entries = doc_header.fd_entries;
1425 pxdb_header_p->md_entries = doc_header.md_entries;
1426 pxdb_header_p->pxdbed = doc_header.pxdbed;
1427 pxdb_header_p->bighdr = doc_header.bighdr;
1428 pxdb_header_p->sa_header = doc_header.sa_header;
1429 pxdb_header_p->inlined = doc_header.inlined;
1430 pxdb_header_p->globals = doc_header.globals;
1431 pxdb_header_p->time = doc_header.time;
1432 pxdb_header_p->pg_entries = doc_header.pg_entries;
1433 pxdb_header_p->functions = doc_header.functions;
1434 pxdb_header_p->files = doc_header.files;
1435 pxdb_header_p->cd_entries = doc_header.cd_entries;
1436 pxdb_header_p->aa_entries = doc_header.aa_entries;
1437 pxdb_header_p->oi_entries = doc_header.oi_entries;
1438 pxdb_header_p->version = doc_header.version;
1439 } /* PINFO section */
1440
1441 else
1442 {
1443 #ifdef DUMPING
1444 if (dumping)
1445 printf ("==No debug info at all for %s.\n", objfile->name);
1446 #endif
1447
1448 return 0;
1449
1450 }
1451
1452 return 1;
1453 } /* End of hpread_get_header */
1454 #endif /* QUICK_LOOK_UP */
1455 \f
1456
1457 /* Initialization for reading native HP C debug symbols from OBJFILE.
1458
1459 Its only purpose in life is to set up the symbol reader's private
1460 per-objfile data structures, and read in the raw contents of the debug
1461 sections (attaching pointers to the debug info into the private data
1462 structures).
1463
1464 Since BFD doesn't know how to read debug symbols in a format-independent
1465 way (and may never do so...), we have to do it ourselves. Note we may
1466 be called on a file without native HP C debugging symbols.
1467
1468 FIXME, there should be a cleaner peephole into the BFD environment
1469 here. */
1470 void
1471 hpread_symfile_init (objfile)
1472 struct objfile *objfile;
1473 {
1474 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1475
1476 /* Allocate struct to keep track of the symfile */
1477 objfile->sym_private = (PTR)
1478 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
1479 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1480
1481 /* We haven't read in any types yet. */
1482 TYPE_VECTOR (objfile) = 0;
1483
1484 /* Read in data from the $GNTT$ subspace. */
1485 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1486 if (!gntt_section)
1487 return;
1488
1489 GNTT (objfile)
1490 = obstack_alloc (&objfile->symbol_obstack,
1491 bfd_section_size (objfile->obfd, gntt_section));
1492
1493 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1494 0, bfd_section_size (objfile->obfd, gntt_section));
1495
1496 GNTT_SYMCOUNT (objfile)
1497 = bfd_section_size (objfile->obfd, gntt_section)
1498 / sizeof (struct dntt_type_block);
1499
1500 /* Read in data from the $LNTT$ subspace. Also keep track of the number
1501 of LNTT symbols.
1502
1503 FIXME: this could be moved into the psymtab-to-symtab expansion
1504 code, and save startup time. At the moment this data is
1505 still used, though. We'd need a way to tell hp-symtab-read.c
1506 whether or not to load the LNTT. */
1507 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1508 if (!lntt_section)
1509 return;
1510
1511 LNTT (objfile)
1512 = obstack_alloc (&objfile->symbol_obstack,
1513 bfd_section_size (objfile->obfd, lntt_section));
1514
1515 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1516 0, bfd_section_size (objfile->obfd, lntt_section));
1517
1518 LNTT_SYMCOUNT (objfile)
1519 = bfd_section_size (objfile->obfd, lntt_section)
1520 / sizeof (struct dntt_type_block);
1521
1522 /* Read in data from the $SLT$ subspace. $SLT$ contains information
1523 on source line numbers. */
1524 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1525 if (!slt_section)
1526 return;
1527
1528 SLT (objfile) =
1529 obstack_alloc (&objfile->symbol_obstack,
1530 bfd_section_size (objfile->obfd, slt_section));
1531
1532 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1533 0, bfd_section_size (objfile->obfd, slt_section));
1534
1535 /* Read in data from the $VT$ subspace. $VT$ contains things like
1536 names and constants. Keep track of the number of symbols in the VT. */
1537 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1538 if (!vt_section)
1539 return;
1540
1541 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1542
1543 VT (objfile) =
1544 (char *) obstack_alloc (&objfile->symbol_obstack,
1545 VT_SIZE (objfile));
1546
1547 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1548 0, VT_SIZE (objfile));
1549 }
1550
1551 /* Scan and build partial symbols for a symbol file.
1552
1553 The minimal symbol table (either SOM or HP a.out) has already been
1554 read in; all we need to do is setup partial symbols based on the
1555 native debugging information.
1556
1557 Note that the minimal table is produced by the linker, and has
1558 only global routines in it; the psymtab is based on compiler-
1559 generated debug information and has non-global
1560 routines in it as well as files and class information.
1561
1562 We assume hpread_symfile_init has been called to initialize the
1563 symbol reader's private data structures.
1564
1565 MAINLINE is true if we are reading the main symbol table (as
1566 opposed to a shared lib or dynamically loaded file). */
1567
1568 void
1569 hpread_build_psymtabs (objfile, mainline)
1570 struct objfile *objfile;
1571 int mainline;
1572 {
1573
1574 #ifdef DUMPING
1575 /* Turn this on to get debugging output. */
1576 static int dumping = 0;
1577 #endif
1578
1579 char *namestring;
1580 int past_first_source_file = 0;
1581 struct cleanup *old_chain;
1582
1583 int hp_symnum, symcount, i;
1584 int scan_start = 0;
1585
1586 union dnttentry *dn_bufp;
1587 unsigned long valu;
1588 char *p;
1589 int texthigh = 0;
1590 int have_name = 0;
1591
1592 /* Current partial symtab */
1593 struct partial_symtab *pst;
1594
1595 /* List of current psymtab's include files */
1596 char **psymtab_include_list;
1597 int includes_allocated;
1598 int includes_used;
1599
1600 /* Index within current psymtab dependency list */
1601 struct partial_symtab **dependency_list;
1602 int dependencies_used, dependencies_allocated;
1603
1604 /* Just in case the stabs reader left turds lying around. */
1605 free_pending_blocks ();
1606 make_cleanup (really_free_pendings, 0);
1607
1608 pst = (struct partial_symtab *) 0;
1609
1610 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
1611 a number of problems with cross compilation and creating useless holes
1612 in the stack when we have to allocate new entries. FIXME. */
1613
1614 includes_allocated = 30;
1615 includes_used = 0;
1616 psymtab_include_list = (char **) alloca (includes_allocated *
1617 sizeof (char *));
1618
1619 dependencies_allocated = 30;
1620 dependencies_used = 0;
1621 dependency_list =
1622 (struct partial_symtab **) alloca (dependencies_allocated *
1623 sizeof (struct partial_symtab *));
1624
1625 old_chain = make_cleanup_free_objfile (objfile);
1626
1627 last_source_file = 0;
1628
1629 #ifdef QUICK_LOOK_UP
1630 {
1631 /* Begin code for new-style loading of quick look-up tables. */
1632
1633 /* elz: this checks whether the file has beeen processed by pxdb.
1634 If not we would like to try to read the psymbols in
1635 anyway, but it turns out to be not so easy. So this could
1636 actually be commented out, but I leave it in, just in case
1637 we decide to add support for non-pxdb-ed stuff in the future. */
1638 PXDB_header pxdb_header;
1639 int found_modules_in_program;
1640
1641 if (hpread_get_header (objfile, &pxdb_header))
1642 {
1643 /* Build a minimal table. No types, no global variables,
1644 no include files.... */
1645 #ifdef DUMPING
1646 if (dumping)
1647 printf ("\nNew method for %s\n", objfile->name);
1648 #endif
1649
1650 /* elz: quick_traverse returns true if it found
1651 some modules in the main source file, other
1652 than those in end.c
1653 In C and C++, all the files have MODULES entries
1654 in the LNTT, and the quick table traverse is all
1655 based on finding these MODULES entries. Without
1656 those it cannot work.
1657 It happens that F77 programs don't have MODULES
1658 so the quick traverse gets confused. F90 programs
1659 have modules, and the quick method still works.
1660 So, if modules (other than those in end.c) are
1661 not found we give up on the quick table stuff,
1662 and fall back on the slower method */
1663 found_modules_in_program = hpread_quick_traverse (objfile,
1664 GNTT (objfile),
1665 VT (objfile),
1666 &pxdb_header);
1667
1668 discard_cleanups (old_chain);
1669
1670 /* Set up to scan the global section of the LNTT.
1671
1672 This field is not always correct: if there are
1673 no globals, it will point to the last record in
1674 the regular LNTT, which is usually an END MODULE.
1675
1676 Since it might happen that there could be a file
1677 with just one global record, there's no way to
1678 tell other than by looking at the record, so that's
1679 done below. */
1680 if (found_modules_in_program)
1681 scan_start = pxdb_header.globals;
1682 }
1683 #ifdef DUMPING
1684 else
1685 {
1686 if (dumping)
1687 printf ("\nGoing on to old method for %s\n", objfile->name);
1688 }
1689 #endif
1690 }
1691 #endif /* QUICK_LOOK_UP */
1692
1693 /* Make two passes, one over the GNTT symbols, the other for the
1694 LNTT symbols.
1695
1696 JB comment: above isn't true--they only make one pass, over
1697 the LNTT. */
1698 for (i = 0; i < 1; i++)
1699 {
1700 int within_function = 0;
1701
1702 if (i)
1703 symcount = GNTT_SYMCOUNT (objfile);
1704 else
1705 symcount = LNTT_SYMCOUNT (objfile);
1706
1707
1708 for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1709 {
1710 QUIT;
1711 if (i)
1712 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1713 else
1714 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1715
1716 if (dn_bufp->dblock.extension)
1717 continue;
1718
1719 /* Only handle things which are necessary for minimal symbols.
1720 everything else is ignored. */
1721 switch (dn_bufp->dblock.kind)
1722 {
1723 case DNTT_TYPE_SRCFILE:
1724 {
1725 #ifdef QUICK_LOOK_UP
1726 if (scan_start == hp_symnum
1727 && symcount == hp_symnum + 1)
1728 {
1729 /* If there are NO globals in an executable,
1730 PXDB's index to the globals will point to
1731 the last record in the file, which
1732 could be this record. (this happened for F77 libraries)
1733 ignore it and be done! */
1734 continue;
1735 }
1736 #endif /* QUICK_LOOK_UP */
1737
1738 /* A source file of some kind. Note this may simply
1739 be an included file. */
1740 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1741
1742 /* Check if this is the source file we are already working
1743 with. */
1744 if (pst && !strcmp (namestring, pst->filename))
1745 continue;
1746
1747 /* Check if this is an include file, if so check if we have
1748 already seen it. Add it to the include list */
1749 p = strrchr (namestring, '.');
1750 if (!strcmp (p, ".h"))
1751 {
1752 int j, found;
1753
1754 found = 0;
1755 for (j = 0; j < includes_used; j++)
1756 if (!strcmp (namestring, psymtab_include_list[j]))
1757 {
1758 found = 1;
1759 break;
1760 }
1761 if (found)
1762 continue;
1763
1764 /* Add it to the list of includes seen so far and
1765 allocate more include space if necessary. */
1766 psymtab_include_list[includes_used++] = namestring;
1767 if (includes_used >= includes_allocated)
1768 {
1769 char **orig = psymtab_include_list;
1770
1771 psymtab_include_list = (char **)
1772 alloca ((includes_allocated *= 2) *
1773 sizeof (char *));
1774 memcpy ((PTR) psymtab_include_list, (PTR) orig,
1775 includes_used * sizeof (char *));
1776 }
1777 continue;
1778 }
1779
1780 if (pst)
1781 {
1782 if (!have_name)
1783 {
1784 pst->filename = (char *)
1785 obstack_alloc (&pst->objfile->psymbol_obstack,
1786 strlen (namestring) + 1);
1787 strcpy (pst->filename, namestring);
1788 have_name = 1;
1789 continue;
1790 }
1791 continue;
1792 }
1793
1794 /* This is a bonafide new source file.
1795 End the current partial symtab and start a new one. */
1796
1797 if (pst && past_first_source_file)
1798 {
1799 hpread_end_psymtab (pst, psymtab_include_list,
1800 includes_used,
1801 (hp_symnum
1802 * sizeof (struct dntt_type_block)),
1803 texthigh,
1804 dependency_list, dependencies_used);
1805 pst = (struct partial_symtab *) 0;
1806 includes_used = 0;
1807 dependencies_used = 0;
1808 }
1809 else
1810 past_first_source_file = 1;
1811
1812 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1813 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1814 pst = hpread_start_psymtab (objfile,
1815 namestring, valu,
1816 (hp_symnum
1817 * sizeof (struct dntt_type_block)),
1818 objfile->global_psymbols.next,
1819 objfile->static_psymbols.next);
1820 texthigh = valu;
1821 have_name = 1;
1822 continue;
1823 }
1824
1825 case DNTT_TYPE_MODULE:
1826 /* A source file. It's still unclear to me what the
1827 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
1828 is supposed to be. */
1829
1830 /* First end the previous psymtab */
1831 if (pst)
1832 {
1833 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
1834 ((hp_symnum - 1)
1835 * sizeof (struct dntt_type_block)),
1836 texthigh,
1837 dependency_list, dependencies_used);
1838 pst = (struct partial_symtab *) 0;
1839 includes_used = 0;
1840 dependencies_used = 0;
1841 have_name = 0;
1842 }
1843
1844 /* Now begin a new module and a new psymtab for it */
1845 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1846 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1847 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1848 if (!pst)
1849 {
1850 pst = hpread_start_psymtab (objfile,
1851 namestring, valu,
1852 (hp_symnum
1853 * sizeof (struct dntt_type_block)),
1854 objfile->global_psymbols.next,
1855 objfile->static_psymbols.next);
1856 texthigh = valu;
1857 have_name = 0;
1858 }
1859 continue;
1860
1861 case DNTT_TYPE_FUNCTION:
1862 case DNTT_TYPE_ENTRY:
1863 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
1864 a secondary entry point. */
1865 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
1866 SECT_OFF_TEXT (objfile));
1867 if (valu > texthigh)
1868 texthigh = valu;
1869 valu = dn_bufp->dfunc.lowaddr +
1870 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1871 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1872 if (dn_bufp->dfunc.global)
1873 add_psymbol_to_list (namestring, strlen (namestring),
1874 VAR_NAMESPACE, LOC_BLOCK,
1875 &objfile->global_psymbols, valu,
1876 0, language_unknown, objfile);
1877 else
1878 add_psymbol_to_list (namestring, strlen (namestring),
1879 VAR_NAMESPACE, LOC_BLOCK,
1880 &objfile->static_psymbols, valu,
1881 0, language_unknown, objfile);
1882 within_function = 1;
1883 continue;
1884
1885 case DNTT_TYPE_DOC_FUNCTION:
1886 valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (objfile->section_offsets,
1887 SECT_OFF_TEXT (objfile));
1888 if (valu > texthigh)
1889 texthigh = valu;
1890 valu = dn_bufp->ddocfunc.lowaddr +
1891 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1892 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1893 if (dn_bufp->ddocfunc.global)
1894 add_psymbol_to_list (namestring, strlen (namestring),
1895 VAR_NAMESPACE, LOC_BLOCK,
1896 &objfile->global_psymbols, valu,
1897 0, language_unknown, objfile);
1898 else
1899 add_psymbol_to_list (namestring, strlen (namestring),
1900 VAR_NAMESPACE, LOC_BLOCK,
1901 &objfile->static_psymbols, valu,
1902 0, language_unknown, objfile);
1903 within_function = 1;
1904 continue;
1905
1906 case DNTT_TYPE_BEGIN:
1907 case DNTT_TYPE_END:
1908 /* We don't check MODULE end here, because there can be
1909 symbols beyond the module end which properly belong to the
1910 current psymtab -- so we wait till the next MODULE start */
1911
1912
1913 #ifdef QUICK_LOOK_UP
1914 if (scan_start == hp_symnum
1915 && symcount == hp_symnum + 1)
1916 {
1917 /* If there are NO globals in an executable,
1918 PXDB's index to the globals will point to
1919 the last record in the file, which is
1920 probably an END MODULE, i.e. this record.
1921 ignore it and be done! */
1922 continue;
1923 }
1924 #endif /* QUICK_LOOK_UP */
1925
1926 /* Scope block begin/end. We only care about function
1927 and file blocks right now. */
1928
1929 if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
1930 (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
1931 within_function = 0;
1932 continue;
1933
1934 case DNTT_TYPE_SVAR:
1935 case DNTT_TYPE_DVAR:
1936 case DNTT_TYPE_TYPEDEF:
1937 case DNTT_TYPE_TAGDEF:
1938 {
1939 /* Variables, typedefs an the like. */
1940 enum address_class storage;
1941 namespace_enum namespace;
1942
1943 /* Don't add locals to the partial symbol table. */
1944 if (within_function
1945 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
1946 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
1947 continue;
1948
1949 /* TAGDEFs go into the structure namespace. */
1950 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
1951 namespace = STRUCT_NAMESPACE;
1952 else
1953 namespace = VAR_NAMESPACE;
1954
1955 /* What kind of "storage" does this use? */
1956 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
1957 storage = LOC_STATIC;
1958 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
1959 && dn_bufp->ddvar.regvar)
1960 storage = LOC_REGISTER;
1961 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
1962 storage = LOC_LOCAL;
1963 else
1964 storage = LOC_UNDEF;
1965
1966 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1967 if (!pst)
1968 {
1969 pst = hpread_start_psymtab (objfile,
1970 "globals", 0,
1971 (hp_symnum
1972 * sizeof (struct dntt_type_block)),
1973 objfile->global_psymbols.next,
1974 objfile->static_psymbols.next);
1975 }
1976
1977 /* Compute address of the data symbol */
1978 valu = dn_bufp->dsvar.location;
1979 /* Relocate in case it's in a shared library */
1980 if (storage == LOC_STATIC)
1981 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1982
1983 /* Luckily, dvar, svar, typedef, and tagdef all
1984 have their "global" bit in the same place, so it works
1985 (though it's bad programming practice) to reference
1986 "dsvar.global" even though we may be looking at
1987 any of the above four types. */
1988 if (dn_bufp->dsvar.global)
1989 {
1990 add_psymbol_to_list (namestring, strlen (namestring),
1991 namespace, storage,
1992 &objfile->global_psymbols,
1993 valu,
1994 0, language_unknown, objfile);
1995 }
1996 else
1997 {
1998 add_psymbol_to_list (namestring, strlen (namestring),
1999 namespace, storage,
2000 &objfile->static_psymbols,
2001 valu,
2002 0, language_unknown, objfile);
2003 }
2004
2005 /* For TAGDEF's, the above code added the tagname to the
2006 struct namespace. This will cause tag "t" to be found
2007 on a reference of the form "(struct t) x". But for
2008 C++ classes, "t" will also be a typename, which we
2009 want to find on a reference of the form "ptype t".
2010 Therefore, we also add "t" to the var namespace.
2011 Do the same for enum's due to the way aCC generates
2012 debug info for these (see more extended comment
2013 in hp-symtab-read.c).
2014 We do the same for templates, so that "ptype t"
2015 where "t" is a template also works. */
2016 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2017 dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2018 {
2019 int global = dn_bufp->dtag.global;
2020 /* Look ahead to see if it's a C++ class */
2021 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2022 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2023 dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2024 dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2025 {
2026 if (global)
2027 {
2028 add_psymbol_to_list (namestring, strlen (namestring),
2029 VAR_NAMESPACE, storage,
2030 &objfile->global_psymbols,
2031 dn_bufp->dsvar.location,
2032 0, language_unknown, objfile);
2033 }
2034 else
2035 {
2036 add_psymbol_to_list (namestring, strlen (namestring),
2037 VAR_NAMESPACE, storage,
2038 &objfile->static_psymbols,
2039 dn_bufp->dsvar.location,
2040 0, language_unknown, objfile);
2041 }
2042 }
2043 }
2044 }
2045 continue;
2046
2047 case DNTT_TYPE_MEMENUM:
2048 case DNTT_TYPE_CONST:
2049 /* Constants and members of enumerated types. */
2050 SET_NAMESTRING (dn_bufp, &namestring, objfile);
2051 if (!pst)
2052 {
2053 pst = hpread_start_psymtab (objfile,
2054 "globals", 0,
2055 (hp_symnum
2056 * sizeof (struct dntt_type_block)),
2057 objfile->global_psymbols.next,
2058 objfile->static_psymbols.next);
2059 }
2060 if (dn_bufp->dconst.global)
2061 add_psymbol_to_list (namestring, strlen (namestring),
2062 VAR_NAMESPACE, LOC_CONST,
2063 &objfile->global_psymbols, 0,
2064 0, language_unknown, objfile);
2065 else
2066 add_psymbol_to_list (namestring, strlen (namestring),
2067 VAR_NAMESPACE, LOC_CONST,
2068 &objfile->static_psymbols, 0,
2069 0, language_unknown, objfile);
2070 continue;
2071 default:
2072 continue;
2073 }
2074 }
2075 }
2076
2077 /* End any pending partial symbol table. */
2078 if (pst)
2079 {
2080 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2081 hp_symnum * sizeof (struct dntt_type_block),
2082 0, dependency_list, dependencies_used);
2083 }
2084
2085 discard_cleanups (old_chain);
2086 }
2087
2088 /* Perform any local cleanups required when we are done with a particular
2089 objfile. I.E, we are in the process of discarding all symbol information
2090 for an objfile, freeing up all memory held for it, and unlinking the
2091 objfile struct from the global list of known objfiles. */
2092
2093 void
2094 hpread_symfile_finish (objfile)
2095 struct objfile *objfile;
2096 {
2097 if (objfile->sym_private != NULL)
2098 {
2099 mfree (objfile->md, objfile->sym_private);
2100 }
2101 }
2102 \f
2103
2104 /* The remaining functions are all for internal use only. */
2105
2106 /* Various small functions to get entries in the debug symbol sections. */
2107
2108 union dnttentry *
2109 hpread_get_lntt (index, objfile)
2110 int index;
2111 struct objfile *objfile;
2112 {
2113 return (union dnttentry *)
2114 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2115 }
2116
2117 static union dnttentry *
2118 hpread_get_gntt (index, objfile)
2119 int index;
2120 struct objfile *objfile;
2121 {
2122 return (union dnttentry *)
2123 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2124 }
2125
2126 union sltentry *
2127 hpread_get_slt (index, objfile)
2128 int index;
2129 struct objfile *objfile;
2130 {
2131 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2132 }
2133
2134 /* Get the low address associated with some symbol (typically the start
2135 of a particular source file or module). Since that information is not
2136 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
2137 the existance of DNTT_TYPE_FUNCTION symbols. */
2138
2139 static unsigned long
2140 hpread_get_textlow (global, index, objfile, symcount)
2141 int global;
2142 int index;
2143 struct objfile *objfile;
2144 int symcount;
2145 {
2146 union dnttentry *dn_bufp;
2147 struct minimal_symbol *msymbol;
2148
2149 /* Look for a DNTT_TYPE_FUNCTION symbol. */
2150 if (index < symcount) /* symcount is the number of symbols in */
2151 { /* the dbinfo, LNTT table */
2152 do
2153 {
2154 if (global)
2155 dn_bufp = hpread_get_gntt (index++, objfile);
2156 else
2157 dn_bufp = hpread_get_lntt (index++, objfile);
2158 }
2159 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2160 && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2161 && dn_bufp->dblock.kind != DNTT_TYPE_END
2162 && index < symcount);
2163 }
2164
2165 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
2166 might happen when a sourcefile has no functions. */
2167 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2168 return 0;
2169
2170 /* Avoid going past the end of the LNTT file */
2171 if (index == symcount)
2172 return 0;
2173
2174 /* The minimal symbols are typically more accurate for some reason. */
2175 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2176 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2177 objfile);
2178 else /* must be a DNTT_TYPE_DOC_FUNCTION */
2179 msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2180 objfile);
2181
2182 if (msymbol)
2183 return SYMBOL_VALUE_ADDRESS (msymbol);
2184 else
2185 return dn_bufp->dfunc.lowaddr;
2186 }
2187
2188 /* Allocate and partially fill a partial symtab. It will be
2189 completely filled at the end of the symbol list.
2190
2191 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2192 is the address relative to which its symbols are (incremental) or 0
2193 (normal). */
2194
2195 static struct partial_symtab *
2196 hpread_start_psymtab (objfile,
2197 filename, textlow, ldsymoff, global_syms, static_syms)
2198 struct objfile *objfile;
2199 char *filename;
2200 CORE_ADDR textlow;
2201 int ldsymoff;
2202 struct partial_symbol **global_syms;
2203 struct partial_symbol **static_syms;
2204 {
2205 int offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2206 extern void hpread_psymtab_to_symtab ();
2207 struct partial_symtab *result =
2208 start_psymtab_common (objfile, objfile->section_offsets,
2209 filename, textlow, global_syms, static_syms);
2210
2211 result->textlow += offset;
2212 result->read_symtab_private = (char *)
2213 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2214 LDSYMOFF (result) = ldsymoff;
2215 result->read_symtab = hpread_psymtab_to_symtab;
2216
2217 return result;
2218 }
2219 \f
2220
2221 /* Close off the current usage of PST.
2222 Returns PST or NULL if the partial symtab was empty and thrown away.
2223
2224 capping_symbol_offset --Byte index in LNTT or GNTT of the
2225 last symbol processed during the build
2226 of the previous pst.
2227
2228 FIXME: List variables and peculiarities of same. */
2229
2230 static struct partial_symtab *
2231 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2232 capping_text, dependency_list, number_dependencies)
2233 struct partial_symtab *pst;
2234 char **include_list;
2235 int num_includes;
2236 int capping_symbol_offset;
2237 CORE_ADDR capping_text;
2238 struct partial_symtab **dependency_list;
2239 int number_dependencies;
2240 {
2241 int i;
2242 struct objfile *objfile = pst->objfile;
2243 int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
2244
2245 #ifdef DUMPING
2246 /* Turn on to see what kind of a psymtab we've built. */
2247 static int dumping = 0;
2248 #endif
2249
2250 if (capping_symbol_offset != -1)
2251 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2252 else
2253 LDSYMLEN (pst) = 0;
2254 pst->texthigh = capping_text + offset;
2255
2256 pst->n_global_syms =
2257 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2258 pst->n_static_syms =
2259 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2260
2261 #ifdef DUMPING
2262 if (dumping)
2263 {
2264 printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2265 pst->filename,
2266 LDSYMOFF (pst),
2267 LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2268 LDSYMLEN (pst),
2269 LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2270 pst->n_global_syms, pst->n_static_syms);
2271 }
2272 #endif
2273
2274 pst->number_of_dependencies = number_dependencies;
2275 if (number_dependencies)
2276 {
2277 pst->dependencies = (struct partial_symtab **)
2278 obstack_alloc (&objfile->psymbol_obstack,
2279 number_dependencies * sizeof (struct partial_symtab *));
2280 memcpy (pst->dependencies, dependency_list,
2281 number_dependencies * sizeof (struct partial_symtab *));
2282 }
2283 else
2284 pst->dependencies = 0;
2285
2286 for (i = 0; i < num_includes; i++)
2287 {
2288 struct partial_symtab *subpst =
2289 allocate_psymtab (include_list[i], objfile);
2290
2291 subpst->section_offsets = pst->section_offsets;
2292 subpst->read_symtab_private =
2293 (char *) obstack_alloc (&objfile->psymbol_obstack,
2294 sizeof (struct symloc));
2295 LDSYMOFF (subpst) =
2296 LDSYMLEN (subpst) =
2297 subpst->textlow =
2298 subpst->texthigh = 0;
2299
2300 /* We could save slight bits of space by only making one of these,
2301 shared by the entire set of include files. FIXME-someday. */
2302 subpst->dependencies = (struct partial_symtab **)
2303 obstack_alloc (&objfile->psymbol_obstack,
2304 sizeof (struct partial_symtab *));
2305 subpst->dependencies[0] = pst;
2306 subpst->number_of_dependencies = 1;
2307
2308 subpst->globals_offset =
2309 subpst->n_global_syms =
2310 subpst->statics_offset =
2311 subpst->n_static_syms = 0;
2312
2313 subpst->readin = 0;
2314 subpst->symtab = 0;
2315 subpst->read_symtab = pst->read_symtab;
2316 }
2317
2318 sort_pst_symbols (pst);
2319
2320 /* If there is already a psymtab or symtab for a file of this name, remove it.
2321 (If there is a symtab, more drastic things also happen.)
2322 This happens in VxWorks. */
2323 free_named_symtabs (pst->filename);
2324
2325 if (num_includes == 0
2326 && number_dependencies == 0
2327 && pst->n_global_syms == 0
2328 && pst->n_static_syms == 0)
2329 {
2330 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2331 it is on the obstack, but we can forget to chain it on the list.
2332 Empty psymtabs happen as a result of header files which don't have
2333 any symbols in them. There can be a lot of them. But this check
2334 is wrong, in that a psymtab with N_SLINE entries but nothing else
2335 is not empty, but we don't realize that. Fixing that without slowing
2336 things down might be tricky.
2337 It's also wrong if we're using the quick look-up tables, as
2338 we can get empty psymtabs from modules with no routines in
2339 them. */
2340
2341 discard_psymtab (pst);
2342
2343 /* Indicate that psymtab was thrown away. */
2344 pst = (struct partial_symtab *) NULL;
2345
2346 }
2347 return pst;
2348 }
2349
2350
2351 /* End of hp-psymtab-read.c */
2352
2353 /* Set indentation to 4 spaces for Emacs; this file is
2354 mostly non-GNU-ish in its style :-( */
2355 #if 0
2356 ***Local Variables:
2357 ***c - basic - offset:4
2358 *** End:
2359 #endif
This page took 0.102868 seconds and 4 git commands to generate.